@@ -62,35 +62,25 @@ func NewVerifyManager(blockchain *BlockChain, peers verifyPeers, allowInsecure b
62
62
if block == nil {
63
63
return nil , ErrCurrentBlockNotFound
64
64
}
65
- number := block .Number ()
66
- for i := maxForkHeight ; i >= 0 ; i -- {
67
- if new (big.Int ).Sub (number , big .NewInt (int64 (i ))).Cmp (common .Big0 ) <= 0 {
68
- continue
69
- }
70
- oldBlock := blockchain .GetBlockByNumber (number .Uint64 () - uint64 (i ))
71
- if oldBlock == nil {
72
- return nil , fmt .Errorf ("block is nil, number: %d" , number )
73
- }
74
-
75
- // rewind to last non verified block
76
- blockchain .SetHead (oldBlock .NumberU64 ())
77
- block = oldBlock
78
- break
79
- }
80
65
81
- number = block .Number ()
82
- for i := maxForkHeight ; i >= 0 ; i -- {
83
- if new (big.Int ).Sub (number , big .NewInt (int64 (i ))).Cmp (common .Big0 ) <= 0 {
84
- continue
85
- }
86
- oldBlock := blockchain .GetBlockByNumber (number .Uint64 () - uint64 (i ))
87
- if oldBlock == nil {
88
- return nil , fmt .Errorf ("block is nil, number: %d" , number )
66
+ // rewind to last non verified block
67
+ number := new (big.Int ).Sub (block .Number (), big .NewInt (int64 (maxForkHeight )))
68
+ if number .Cmp (common .Big0 ) < 0 {
69
+ blockchain .SetHead (0 )
70
+ } else {
71
+ numberU64 := number .Uint64 ()
72
+ blockchain .SetHead (numberU64 )
73
+ block := blockchain .GetBlockByNumber (numberU64 )
74
+ for i := 0 ; i < maxForkHeight ; i ++ {
75
+ // When inserting a block,
76
+ // the block before 11 blocks will be verified,
77
+ // so the parent block of 11-22 will directly write the verification information.
78
+ verifiedCache .Add (block .Hash (), true )
79
+ block = blockchain .GetBlockByHash (block .ParentHash ())
80
+ if block == nil {
81
+ return nil , fmt .Errorf ("block is nil, number: %d" , number )
82
+ }
89
83
}
90
- // When inserting a block,
91
- // the block before 11 blocks will be verified,
92
- // so the parent block of 11-22 will directly write the verification information.
93
- verifiedCache .Add (oldBlock .Hash (), true )
94
84
}
95
85
96
86
vm := & remoteVerifyManager {
0 commit comments