@@ -112,20 +112,20 @@ type Downloader struct {
112
112
syncStatsLock sync.RWMutex // Lock protecting the sync stats fields
113
113
114
114
// Callbacks
115
- hasHeader headerCheckFn // Checks if a header is present in the chain
116
- hasBlock blockCheckFn // Checks if a block is present in the chain
117
- getHeader headerRetrievalFn // Retrieves a header from the chain
118
- getBlock blockRetrievalFn // Retrieves a block from the chain
119
- headHeader headHeaderRetrievalFn // Retrieves the head header from the chain
120
- headBlock headBlockRetrievalFn // Retrieves the head block from the chain
121
- headFastBlock headFastBlockRetrievalFn // Retrieves the head fast-sync block from the chain
122
- commitHeadBlock headBlockCommitterFn // Commits a manually assembled block as the chain head
123
- getTd tdRetrievalFn // Retrieves the TD of a block from the chain
124
- insertHeaders headerChainInsertFn // Injects a batch of headers into the chain
125
- insertBlocks blockChainInsertFn // Injects a batch of blocks into the chain
126
- insertReceipts receiptChainInsertFn // Injects a batch of blocks and their receipts into the chain
127
- rollback chainRollbackFn // Removes a batch of recently added chain links
128
- dropPeer peerDropFn // Drops a peer for misbehaving
115
+ hasHeader headerCheckFn // Checks if a header is present in the chain
116
+ hasBlockAndState blockAndStateCheckFn // Checks if a block and associated state is present in the chain
117
+ getHeader headerRetrievalFn // Retrieves a header from the chain
118
+ getBlock blockRetrievalFn // Retrieves a block from the chain
119
+ headHeader headHeaderRetrievalFn // Retrieves the head header from the chain
120
+ headBlock headBlockRetrievalFn // Retrieves the head block from the chain
121
+ headFastBlock headFastBlockRetrievalFn // Retrieves the head fast-sync block from the chain
122
+ commitHeadBlock headBlockCommitterFn // Commits a manually assembled block as the chain head
123
+ getTd tdRetrievalFn // Retrieves the TD of a block from the chain
124
+ insertHeaders headerChainInsertFn // Injects a batch of headers into the chain
125
+ insertBlocks blockChainInsertFn // Injects a batch of blocks into the chain
126
+ insertReceipts receiptChainInsertFn // Injects a batch of blocks and their receipts into the chain
127
+ rollback chainRollbackFn // Removes a batch of recently added chain links
128
+ dropPeer peerDropFn // Drops a peer for misbehaving
129
129
130
130
// Status
131
131
synchroniseMock func (id string , hash common.Hash ) error // Replacement for synchronise during testing
@@ -156,41 +156,41 @@ type Downloader struct {
156
156
}
157
157
158
158
// New creates a new downloader to fetch hashes and blocks from remote peers.
159
- func New (stateDb ethdb.Database , mux * event.TypeMux , hasHeader headerCheckFn , hasBlock blockCheckFn , getHeader headerRetrievalFn ,
160
- getBlock blockRetrievalFn , headHeader headHeaderRetrievalFn , headBlock headBlockRetrievalFn , headFastBlock headFastBlockRetrievalFn ,
161
- commitHeadBlock headBlockCommitterFn , getTd tdRetrievalFn , insertHeaders headerChainInsertFn , insertBlocks blockChainInsertFn ,
162
- insertReceipts receiptChainInsertFn , rollback chainRollbackFn , dropPeer peerDropFn ) * Downloader {
159
+ func New (stateDb ethdb.Database , mux * event.TypeMux , hasHeader headerCheckFn , hasBlockAndState blockAndStateCheckFn ,
160
+ getHeader headerRetrievalFn , getBlock blockRetrievalFn , headHeader headHeaderRetrievalFn , headBlock headBlockRetrievalFn ,
161
+ headFastBlock headFastBlockRetrievalFn , commitHeadBlock headBlockCommitterFn , getTd tdRetrievalFn , insertHeaders headerChainInsertFn ,
162
+ insertBlocks blockChainInsertFn , insertReceipts receiptChainInsertFn , rollback chainRollbackFn , dropPeer peerDropFn ) * Downloader {
163
163
164
164
return & Downloader {
165
- mode : FullSync ,
166
- mux : mux ,
167
- queue : newQueue (stateDb ),
168
- peers : newPeerSet (),
169
- hasHeader : hasHeader ,
170
- hasBlock : hasBlock ,
171
- getHeader : getHeader ,
172
- getBlock : getBlock ,
173
- headHeader : headHeader ,
174
- headBlock : headBlock ,
175
- headFastBlock : headFastBlock ,
176
- commitHeadBlock : commitHeadBlock ,
177
- getTd : getTd ,
178
- insertHeaders : insertHeaders ,
179
- insertBlocks : insertBlocks ,
180
- insertReceipts : insertReceipts ,
181
- rollback : rollback ,
182
- dropPeer : dropPeer ,
183
- newPeerCh : make (chan * peer , 1 ),
184
- hashCh : make (chan dataPack , 1 ),
185
- blockCh : make (chan dataPack , 1 ),
186
- headerCh : make (chan dataPack , 1 ),
187
- bodyCh : make (chan dataPack , 1 ),
188
- receiptCh : make (chan dataPack , 1 ),
189
- stateCh : make (chan dataPack , 1 ),
190
- blockWakeCh : make (chan bool , 1 ),
191
- bodyWakeCh : make (chan bool , 1 ),
192
- receiptWakeCh : make (chan bool , 1 ),
193
- stateWakeCh : make (chan bool , 1 ),
165
+ mode : FullSync ,
166
+ mux : mux ,
167
+ queue : newQueue (stateDb ),
168
+ peers : newPeerSet (),
169
+ hasHeader : hasHeader ,
170
+ hasBlockAndState : hasBlockAndState ,
171
+ getHeader : getHeader ,
172
+ getBlock : getBlock ,
173
+ headHeader : headHeader ,
174
+ headBlock : headBlock ,
175
+ headFastBlock : headFastBlock ,
176
+ commitHeadBlock : commitHeadBlock ,
177
+ getTd : getTd ,
178
+ insertHeaders : insertHeaders ,
179
+ insertBlocks : insertBlocks ,
180
+ insertReceipts : insertReceipts ,
181
+ rollback : rollback ,
182
+ dropPeer : dropPeer ,
183
+ newPeerCh : make (chan * peer , 1 ),
184
+ hashCh : make (chan dataPack , 1 ),
185
+ blockCh : make (chan dataPack , 1 ),
186
+ headerCh : make (chan dataPack , 1 ),
187
+ bodyCh : make (chan dataPack , 1 ),
188
+ receiptCh : make (chan dataPack , 1 ),
189
+ stateCh : make (chan dataPack , 1 ),
190
+ blockWakeCh : make (chan bool , 1 ),
191
+ bodyWakeCh : make (chan bool , 1 ),
192
+ receiptWakeCh : make (chan bool , 1 ),
193
+ stateWakeCh : make (chan bool , 1 ),
194
194
}
195
195
}
196
196
@@ -564,7 +564,7 @@ func (d *Downloader) findAncestor61(p *peer) (uint64, error) {
564
564
// Check if a common ancestor was found
565
565
finished = true
566
566
for i := len (hashes ) - 1 ; i >= 0 ; i -- {
567
- if d .hasBlock (hashes [i ]) {
567
+ if d .hasBlockAndState (hashes [i ]) {
568
568
number , hash = uint64 (from )+ uint64 (i ), hashes [i ]
569
569
break
570
570
}
@@ -620,11 +620,11 @@ func (d *Downloader) findAncestor61(p *peer) (uint64, error) {
620
620
arrived = true
621
621
622
622
// Modify the search interval based on the response
623
- block := d .getBlock (hashes [0 ])
624
- if block == nil {
623
+ if ! d .hasBlockAndState (hashes [0 ]) {
625
624
end = check
626
625
break
627
626
}
627
+ block := d .getBlock (hashes [0 ]) // this doesn't check state, hence the above explicit check
628
628
if block .NumberU64 () != check {
629
629
glog .V (logger .Debug ).Infof ("%v: non requested hash #%d [%x…], instead of #%d" , p , block .NumberU64 (), block .Hash ().Bytes ()[:4 ], check )
630
630
return 0 , errBadPeer
@@ -989,7 +989,7 @@ func (d *Downloader) findAncestor(p *peer) (uint64, error) {
989
989
// Check if a common ancestor was found
990
990
finished = true
991
991
for i := len (headers ) - 1 ; i >= 0 ; i -- {
992
- if (d .mode != LightSync && d .hasBlock (headers [i ].Hash ())) || (d .mode == LightSync && d .hasHeader (headers [i ].Hash ())) {
992
+ if (d .mode != LightSync && d .hasBlockAndState (headers [i ].Hash ())) || (d .mode == LightSync && d .hasHeader (headers [i ].Hash ())) {
993
993
number , hash = headers [i ].Number .Uint64 (), headers [i ].Hash ()
994
994
break
995
995
}
@@ -1045,7 +1045,7 @@ func (d *Downloader) findAncestor(p *peer) (uint64, error) {
1045
1045
arrived = true
1046
1046
1047
1047
// Modify the search interval based on the response
1048
- if (d .mode == FullSync && ! d .hasBlock (headers [0 ].Hash ())) || (d .mode != FullSync && ! d .hasHeader (headers [0 ].Hash ())) {
1048
+ if (d .mode == FullSync && ! d .hasBlockAndState (headers [0 ].Hash ())) || (d .mode != FullSync && ! d .hasHeader (headers [0 ].Hash ())) {
1049
1049
end = check
1050
1050
break
1051
1051
}
0 commit comments