forked from initia-labs/opinit-bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
52 lines (47 loc) · 1.17 KB
/
db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package executor
import (
"fmt"
"github.com/initia-labs/opinit-bots/node"
"github.com/initia-labs/opinit-bots/types"
"github.com/pkg/errors"
)
func ResetHeights(db types.DB) error {
dbs := []types.DB{
db.WithPrefix([]byte(types.HostName)),
db.WithPrefix([]byte(types.ChildName)),
db.WithPrefix([]byte(types.BatchName)),
}
for _, db := range dbs {
if err := node.DeleteSyncInfo(db); err != nil {
return err
}
if err := node.DeletePendingTxs(db); err != nil {
return err
}
if err := node.DeleteProcessedMsgs(db); err != nil {
return err
}
fmt.Printf("reset height to 0 for node %s\n", string(db.GetPrefix()))
}
return nil
}
func ResetHeight(db types.DB, nodeName string) error {
if nodeName != types.HostName &&
nodeName != types.ChildName &&
nodeName != types.BatchName {
return errors.New("unknown node name")
}
nodeDB := db.WithPrefix([]byte(nodeName))
err := node.DeleteSyncInfo(nodeDB)
if err != nil {
return err
}
if err := node.DeletePendingTxs(db); err != nil {
return err
}
if err := node.DeleteProcessedMsgs(db); err != nil {
return err
}
fmt.Printf("reset height to 0 for node %s\n", string(nodeDB.GetPrefix()))
return nil
}