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 (
18
18
19
19
const (
20
20
chainsyncCursorKey = "chainsync_cursor"
21
+ fingerprintKey = "config_fingerprint"
21
22
)
22
23
23
24
type State struct {
@@ -39,6 +40,45 @@ func (s *State) Load() error {
39
40
}
40
41
s .db = db
41
42
//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
+ }
42
82
return nil
43
83
}
44
84
You can’t perform that action at this time.
0 commit comments