From 1d15b20860dcaf0b321752f3a4713fd610017e6c Mon Sep 17 00:00:00 2001 From: bnoieh <135800952+bnoieh@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:46:02 +0800 Subject: [PATCH] perf: opt bridge exec --- core/blockchain.go | 66 +++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 50050deeb..977b58f5a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1682,14 +1682,14 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) return 0, nil } - minerMode := false - if len(chain) == 1 { - block := chain[0] - _, receiptExist := bc.miningReceiptsCache.Get(block.Hash()) - _, logExist := bc.miningTxLogsCache.Get(block.Hash()) - _, stateExist := bc.miningStateCache.Get(block.Hash()) - minerMode = receiptExist && logExist && stateExist - } + minerMode := true + // if len(chain) == 1 { + // block := chain[0] + // _, receiptExist := bc.miningReceiptsCache.Get(block.Hash()) + // _, logExist := bc.miningTxLogsCache.Get(block.Hash()) + // _, stateExist := bc.miningStateCache.Get(block.Hash()) + // minerMode = receiptExist && logExist && stateExist + // } // Start a parallel signature recovery (signer will fluke on fork transition, minimal perf loss) SenderCacher.RecoverFromBlocks(types.MakeSigner(bc.chainConfig, chain[0].Number(), chain[0].Time()), chain) @@ -1941,26 +1941,26 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) vstart := time.Now() // Async validate if minerMode - asyncValidateStateCh := make(chan error, 1) - if minerMode { - header := block.Header() - // Can not validate root concurrently - if root := statedb.IntermediateRoot(bc.chainConfig.IsEIP158(header.Number)); header.Root != root { - err := fmt.Errorf("self mined block(hash: %x number %v) verify root err(mined: %x expected: %x) dberr: %w", block.Hash(), block.NumberU64(), header.Root, root, statedb.Error()) - bc.reportBlock(block, receipts, err) - followupInterrupt.Store(true) - return it.index, err - } - go func() { - asyncValidateStateCh <- bc.validator.ValidateState(block, statedb, receipts, usedGas, true) - }() - } else { - if err := bc.validator.ValidateState(block, statedb, receipts, usedGas, false); err != nil { - bc.reportBlock(block, receipts, err) - followupInterrupt.Store(true) - return it.index, err - } - } + // asyncValidateStateCh := make(chan error, 1) + // if minerMode { + // header := block.Header() + // // Can not validate root concurrently + // if root := statedb.IntermediateRoot(bc.chainConfig.IsEIP158(header.Number)); header.Root != root { + // err := fmt.Errorf("self mined block(hash: %x number %v) verify root err(mined: %x expected: %x) dberr: %w", block.Hash(), block.NumberU64(), header.Root, root, statedb.Error()) + // bc.reportBlock(block, receipts, err) + // followupInterrupt.Store(true) + // return it.index, err + // } + // go func() { + // asyncValidateStateCh <- bc.validator.ValidateState(block, statedb, receipts, usedGas, true) + // }() + // } else { + // if err := bc.validator.ValidateState(block, statedb, receipts, usedGas, false); err != nil { + // bc.reportBlock(block, receipts, err) + // followupInterrupt.Store(true) + // return it.index, err + // } + // } vtime := time.Since(vstart) proctime := time.Since(start) // processing + validation @@ -1998,11 +1998,11 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) if err != nil { return it.index, err } - if minerMode { - if err := <-asyncValidateStateCh; err != nil { - panic(fmt.Errorf("self mined block(hash: %x number %v) async verify state err: %w", block.Hash(), block.NumberU64(), err)) - } - } + // if minerMode { + // if err := <-asyncValidateStateCh; err != nil { + // panic(fmt.Errorf("self mined block(hash: %x number %v) async verify state err: %w", block.Hash(), block.NumberU64(), err)) + // } + // } bc.CacheBlock(block.Hash(), block) log.Info("perf-trace insertChain debug2", "duration", common.PrettyDuration(time.Since(wstart)), "hash", block.Hash())