Skip to content

Commit

Permalink
perf: opt bridge exec
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoieh committed Dec 16, 2024
1 parent f187a76 commit 1d15b20
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())

Expand Down

0 comments on commit 1d15b20

Please sign in to comment.