-
Notifications
You must be signed in to change notification settings - Fork 199
/
interface.go
86 lines (76 loc) · 3.24 KB
/
interface.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package trie
import (
"context"
"io"
"sync"
"time"
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/hashing"
"github.com/ElrondNetwork/elrond-go-core/marshal"
"github.com/ElrondNetwork/elrond-go/common"
)
type node interface {
getHash() []byte
setHash() error
setGivenHash([]byte)
setHashConcurrent(wg *sync.WaitGroup, c chan error)
setRootHash() error
getCollapsed() (node, error) // a collapsed node is a node that instead of the children holds the children hashes
isCollapsed() bool
isPosCollapsed(pos int) bool
isDirty() bool
getEncodedNode() ([]byte, error)
resolveCollapsed(pos byte, db common.DBWriteCacher) error
hashNode() ([]byte, error)
hashChildren() error
tryGet(key []byte, db common.DBWriteCacher) ([]byte, error)
getNext(key []byte, db common.DBWriteCacher) (node, []byte, error)
insert(n *leafNode, db common.DBWriteCacher) (node, [][]byte, error)
delete(key []byte, db common.DBWriteCacher) (bool, node, [][]byte, error)
reduceNode(pos int) (node, bool, error)
isEmptyOrNil() error
print(writer io.Writer, index int, db common.DBWriteCacher)
getDirtyHashes(common.ModifiedHashes) error
getChildren(db common.DBWriteCacher) ([]node, error)
isValid() bool
setDirty(bool)
loadChildren(func([]byte) (node, error)) ([][]byte, []node, error)
getAllLeavesOnChannel(chan core.KeyValueHolder, []byte, common.DBWriteCacher, marshal.Marshalizer, chan struct{}) error
getAllHashes(db common.DBWriteCacher) ([][]byte, error)
getNextHashAndKey([]byte) (bool, []byte, []byte)
getNumNodes() common.NumNodesDTO
getValue() []byte
commitDirty(level byte, maxTrieLevelInMemory uint, originDb common.DBWriteCacher, targetDb common.DBWriteCacher) error
commitCheckpoint(originDb common.DBWriteCacher, targetDb common.DBWriteCacher, checkpointHashes CheckpointHashesHolder, leavesChan chan core.KeyValueHolder, ctx context.Context) error
commitSnapshot(originDb common.DBWriteCacher, targetDb common.DBWriteCacher, leavesChan chan core.KeyValueHolder, ctx context.Context) error
getMarshalizer() marshal.Marshalizer
setMarshalizer(marshal.Marshalizer)
getHasher() hashing.Hasher
setHasher(hashing.Hasher)
sizeInBytes() int
IsInterfaceNil() bool
}
type snapshotNode interface {
commitCheckpoint(originDb common.DBWriteCacher, targetDb common.DBWriteCacher, checkpointHashes CheckpointHashesHolder, leavesChan chan core.KeyValueHolder, ctx context.Context) error
commitSnapshot(originDb common.DBWriteCacher, targetDb common.DBWriteCacher, leavesChan chan core.KeyValueHolder, ctx context.Context) error
}
// RequestHandler defines the methods through which request to data can be made
type RequestHandler interface {
RequestTrieNodes(destShardID uint32, hashes [][]byte, topic string)
RequestInterval() time.Duration
IsInterfaceNil() bool
}
// CheckpointHashesHolder is used to hold the hashes that need to be committed in the future state checkpoint
type CheckpointHashesHolder interface {
Put(rootHash []byte, hashes common.ModifiedHashes) bool
RemoveCommitted(lastCommittedRootHash []byte)
Remove(hash []byte)
ShouldCommit(hash []byte) bool
IsInterfaceNil() bool
}
// TimeoutHandler is able to tell if a timeout has occurred
type TimeoutHandler interface {
ResetWatchdog()
IsTimeout() bool
IsInterfaceNil() bool
}