-
Notifications
You must be signed in to change notification settings - Fork 202
/
validatorAccountsSyncer.go
56 lines (45 loc) · 1.55 KB
/
validatorAccountsSyncer.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
package syncer
import (
"context"
"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/data"
"github.com/ElrondNetwork/elrond-go/process/factory"
)
type validatorAccountsSyncer struct {
*baseAccountsSyncer
}
// ArgsNewValidatorAccountsSyncer defines the arguments needed for the new account syncer
type ArgsNewValidatorAccountsSyncer struct {
ArgsNewBaseAccountsSyncer
}
// NewValidatorAccountsSyncer creates a validator account syncer
func NewValidatorAccountsSyncer(args ArgsNewValidatorAccountsSyncer) (*validatorAccountsSyncer, error) {
err := checkArgs(args.ArgsNewBaseAccountsSyncer)
if err != nil {
return nil, err
}
b := &baseAccountsSyncer{
hasher: args.Hasher,
marshalizer: args.Marshalizer,
trieSyncers: make(map[string]data.TrieSyncer),
dataTries: make(map[string]data.Trie),
trieStorageManager: args.TrieStorageManager,
requestHandler: args.RequestHandler,
waitTime: args.WaitTime,
shardId: core.MetachainShardId,
cacher: args.Cacher,
rootHash: nil,
}
u := &validatorAccountsSyncer{
baseAccountsSyncer: b,
}
return u, nil
}
// SyncAccounts will launch the syncing method to gather all the data needed for validatorAccounts - it is a blocking method
func (v *validatorAccountsSyncer) SyncAccounts(rootHash []byte) error {
v.mutex.Lock()
defer v.mutex.Unlock()
ctx, cancel := context.WithTimeout(context.Background(), v.waitTime)
defer cancel()
return v.syncMainTrie(rootHash, factory.ValidatorTrieNodesTopic, ctx)
}