Skip to content

Commit

Permalink
chore: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoieh committed Oct 21, 2024
1 parent 4386b9a commit f8f0200
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
}

// Async verify header if minerMode
asyncItNextCh := make(chan error)
asyncItNextCh := make(chan error, 1)
if minerMode {
go func() {
_, err := it.next()
Expand Down Expand Up @@ -1940,12 +1940,14 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)

vstart := time.Now()
// Async validate if minerMode
asyncValidateStateCh := make(chan error)
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 {
panic(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, 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()))
followupInterrupt.Store(true)
return 0, err
}
go func() {
asyncValidateStateCh <- bc.validator.ValidateState(block, statedb, receipts, usedGas, true)
Expand Down Expand Up @@ -1990,6 +1992,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
}
followupInterrupt.Store(true)
if err != nil {
if minerMode {
return 0, err
}
return it.index, err
}
if minerMode {
Expand Down
7 changes: 6 additions & 1 deletion eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
forkchoiceUpdateHeadsTimer = metrics.NewRegisteredTimer("api/engine/forkchoiceUpdate/heads", nil)
getPayloadTimer = metrics.NewRegisteredTimer("api/engine/get/payload", nil)
newPayloadTimer = metrics.NewRegisteredTimer("api/engine/new/payload", nil)
sealPayloadTimer = metrics.NewRegisteredTimer("api/engine/seal/payload", nil)
)

// Register adds the engine API to the full node.
Expand Down Expand Up @@ -711,6 +712,10 @@ func (api *ConsensusAPI) OpSealPayloadV3(payloadID engine.PayloadID, update engi

func (api *ConsensusAPI) opSealPayload(payloadID engine.PayloadID, update engine.ForkchoiceStateV1, needPayload bool, version string) (engine.OpSealPayloadResponse, error) {
start := time.Now()
defer func() {
sealPayloadTimer.UpdateSince(start)
log.Debug("sealPayloadTimer", "duration", common.PrettyDuration(time.Since(start)), "payloadID", payloadID)
}()
var payloadEnvelope *engine.ExecutionPayloadEnvelope
var err error
if version == "V2" {
Expand Down Expand Up @@ -745,7 +750,7 @@ func (api *ConsensusAPI) opSealPayload(payloadID engine.PayloadID, update engine
return engine.OpSealPayloadResponse{ErrStage: engine.ForkchoiceUpdatedStage, PayloadStatus: updateResponse.PayloadStatus}, err
}

log.Info("perf-trace opSealPayload succeed", "duration", common.PrettyDuration(time.Since(start)), "hash", payloadEnvelope.ExecutionPayload.BlockHash, "number", payloadEnvelope.ExecutionPayload.Number, "id", payloadID, "payloadStatus", updateResponse.PayloadStatus)
log.Info("opSealPayload succeed", "hash", payloadEnvelope.ExecutionPayload.BlockHash, "number", payloadEnvelope.ExecutionPayload.Number, "id", payloadID, "payloadStatus", updateResponse.PayloadStatus)
if needPayload {
return engine.OpSealPayloadResponse{PayloadStatus: updateResponse.PayloadStatus, Payload: payloadEnvelope}, nil
} else {
Expand Down

0 comments on commit f8f0200

Please sign in to comment.