@@ -1277,6 +1277,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
1277
1277
}
1278
1278
// writeLive writes blockchain and corresponding receipt chain into active store.
1279
1279
writeLive := func (blockChain types.Blocks , receiptChain []types.Receipts ) (int , error ) {
1280
+ skipPresenceCheck := false
1280
1281
batch := bc .db .NewBatch ()
1281
1282
for i , block := range blockChain {
1282
1283
// Short circuit insertion if shutting down or processing failed
@@ -1287,9 +1288,17 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
1287
1288
if ! bc .HasHeader (block .Hash (), block .NumberU64 ()) {
1288
1289
return i , fmt .Errorf ("containing header #%d [%x…] unknown" , block .Number (), block .Hash ().Bytes ()[:4 ])
1289
1290
}
1290
- if bc .HasBlock (block .Hash (), block .NumberU64 ()) {
1291
- stats .ignored ++
1292
- continue
1291
+ if ! skipPresenceCheck {
1292
+ // Ignore if the entire data is already known
1293
+ if bc .HasBlock (block .Hash (), block .NumberU64 ()) {
1294
+ stats .ignored ++
1295
+ continue
1296
+ } else {
1297
+ // If block N is not present, neither are the later blocks.
1298
+ // This should be true, but if we are mistaken, the shortcut
1299
+ // here will only cause overwriting of some existing data
1300
+ skipPresenceCheck = true
1301
+ }
1293
1302
}
1294
1303
// Write all the data out into the database
1295
1304
rawdb .WriteBody (batch , block .Hash (), block .NumberU64 (), block .Body ())
0 commit comments