diff options
author | gary rong <garyrong0905@gmail.com> | 2019-07-03 16:19:15 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-07-03 16:19:15 +0800 |
commit | ca6c8c2af443e99497cd49b6b122094ad08205b7 (patch) | |
tree | 9b8512e77d939f18d000a507c8b49fc3c6313ab9 /core | |
parent | 802074cba9f23b2e404c2e542cc696547d0017dd (diff) | |
download | go-tangerine-ca6c8c2af443e99497cd49b6b122094ad08205b7.tar go-tangerine-ca6c8c2af443e99497cd49b6b122094ad08205b7.tar.gz go-tangerine-ca6c8c2af443e99497cd49b6b122094ad08205b7.tar.bz2 go-tangerine-ca6c8c2af443e99497cd49b6b122094ad08205b7.tar.lz go-tangerine-ca6c8c2af443e99497cd49b6b122094ad08205b7.tar.xz go-tangerine-ca6c8c2af443e99497cd49b6b122094ad08205b7.tar.zst go-tangerine-ca6c8c2af443e99497cd49b6b122094ad08205b7.zip |
core: fix receipt insertion (#19764)
Diffstat (limited to 'core')
-rw-r--r-- | core/blockchain.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index a1f3b68c5..b4c1716a9 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -930,6 +930,8 @@ func (bc *BlockChain) truncateAncient(head uint64) error { // InsertReceiptChain attempts to complete an already existing header chain with // transaction and receipt data. func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain []types.Receipts, ancientLimit uint64) (int, error) { + // We don't require the chainMu here since we want to maximize the + // concurrency of header insertion and receipt insertion. bc.wg.Add(1) defer bc.wg.Done() @@ -962,19 +964,21 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [ // updateHead updates the head fast sync block if the inserted blocks are better // and returns a indicator whether the inserted blocks are canonical. updateHead := func(head *types.Block) bool { - var isCanonical bool bc.chainmu.Lock() - if td := bc.GetTd(head.Hash(), head.NumberU64()); td != nil { // Rewind may have occurred, skip in that case - currentFastBlock := bc.CurrentFastBlock() + + // Rewind may have occurred, skip in that case. + if bc.CurrentHeader().Number.Cmp(head.Number()) >= 0 { + currentFastBlock, td := bc.CurrentFastBlock(), bc.GetTd(head.Hash(), head.NumberU64()) if bc.GetTd(currentFastBlock.Hash(), currentFastBlock.NumberU64()).Cmp(td) < 0 { rawdb.WriteHeadFastBlockHash(bc.db, head.Hash()) bc.currentFastBlock.Store(head) headFastBlockGauge.Update(int64(head.NumberU64())) - isCanonical = true + bc.chainmu.Unlock() + return true } } bc.chainmu.Unlock() - return isCanonical + return false } // writeAncient writes blockchain and corresponding receipt chain into ancient store. // |