File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import (
1818
1919const (
2020 chainsyncCursorKey = "chainsync_cursor"
21+ fingerprintKey = "config_fingerprint"
2122)
2223
2324type State struct {
@@ -39,6 +40,45 @@ func (s *State) Load() error {
3940 }
4041 s .db = db
4142 //defer db.Close()
43+ if err := s .compareFingerprint (); err != nil {
44+ return err
45+ }
46+ return nil
47+ }
48+
49+ func (s * State ) compareFingerprint () error {
50+ cfg := config .GetConfig ()
51+ fingerprint := fmt .Sprintf (
52+ "network=%s,network-magic=%d" ,
53+ cfg .Indexer .Network ,
54+ cfg .Indexer .NetworkMagic ,
55+ )
56+ err := s .db .Update (func (txn * badger.Txn ) error {
57+ item , err := txn .Get ([]byte (fingerprintKey ))
58+ if err != nil {
59+ if err == badger .ErrKeyNotFound {
60+ if err := txn .Set ([]byte (fingerprintKey ), []byte (fingerprint )); err != nil {
61+ return err
62+ }
63+ return nil
64+ } else {
65+ return err
66+ }
67+ }
68+ err = item .Value (func (v []byte ) error {
69+ if string (v ) != fingerprint {
70+ return fmt .Errorf ("config fingerprint in DB doesn't match current config: %s" , v )
71+ }
72+ return nil
73+ })
74+ if err != nil {
75+ return err
76+ }
77+ return nil
78+ })
79+ if err != nil {
80+ return err
81+ }
4282 return nil
4383}
4484
You can’t perform that action at this time.
0 commit comments