/
tools_verifier.go
109 lines (93 loc) · 2.57 KB
/
tools_verifier.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package pool
import (
"fmt"
"github.com/go-errors/errors"
"github.com/vitelabs/go-vite/common/types"
"github.com/vitelabs/go-vite/ledger"
"github.com/vitelabs/go-vite/log15"
"github.com/vitelabs/go-vite/verifier"
)
type verifyTask interface {
done(c chainDb) bool
requests() []fetchRequest
}
type sverifier interface {
VerifyNetSb(block *ledger.SnapshotBlock) error
VerifyReferred(block *ledger.SnapshotBlock) *verifier.SnapshotBlockVerifyStat
}
type snapshotVerifier struct {
v sverifier
}
func (sV *snapshotVerifier) verifySnapshotData(block *ledger.SnapshotBlock) error {
if err := sV.v.VerifyNetSb(block); err != nil {
return err
}
return nil
}
func (sV *snapshotVerifier) verifySnapshot(block *snapshotPoolBlock) *poolSnapshotVerifyStat {
result := &poolSnapshotVerifyStat{}
stat := sV.v.VerifyReferred(block.block)
result.results = stat.Results()
result.result = stat.VerifyResult()
result.msg = stat.ErrMsg()
return result
}
type accountVerifier struct {
v verifier.Verifier
log log15.Logger
}
func (accV *accountVerifier) verifyAccountData(b *ledger.AccountBlock) error {
if err := accV.v.VerifyNetAccountBlock(b); err != nil {
return err
}
return nil
}
/**
if b is contract send block, result must be FAIL.
*/
func (accV *accountVerifier) verifyAccount(b *accountPoolBlock, latest *ledger.SnapshotBlock) *poolAccountVerifyStat {
result := &poolAccountVerifyStat{}
// todo how to fix for stat
task, blocks, err := accV.v.VerifyPoolAccountBlock(b.block, latest)
if err != nil {
result.err = err
result.result = verifier.FAIL
return result
}
if task != nil {
result.result = verifier.PENDING
result.taskList = task
return result
}
//result.stat =
if blocks != nil {
result.block = newAccountPoolBlock(blocks.AccountBlock, blocks.VmDb, b.v, b.source)
result.result = verifier.SUCCESS
return result
}
result.result = verifier.FAIL
msg := fmt.Sprintf("error verify result. %s-%s-%d", b.block.AccountAddress, b.Hash(), b.Height())
result.err = errors.New(msg)
return result
}
type poolSnapshotVerifyStat struct {
results map[types.Address]verifier.VerifyResult
result verifier.VerifyResult
task verifyTask
msg string
}
func (stat *poolSnapshotVerifyStat) verifyResult() verifier.VerifyResult {
return stat.result
}
func (stat *poolSnapshotVerifyStat) errMsg() string {
return stat.msg
}
type poolAccountVerifyStat struct {
block *accountPoolBlock
result verifier.VerifyResult
taskList *verifier.AccBlockPendingTask
err error
}
func (stat *poolAccountVerifyStat) verifyResult() verifier.VerifyResult {
return stat.result
}