Skip to content

Commit

Permalink
Catalyst modifications for bolt
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinlesceller committed Aug 16, 2023
1 parent 75c6402 commit 7453990
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/blockcypher/go-ethereum/beacon/engine"
"github.com/blockcypher/go-ethereum/common"
"github.com/blockcypher/go-ethereum/common/hexutil"
"github.com/blockcypher/go-ethereum/core/rawdb"
"github.com/blockcypher/go-ethereum/core/types"
"github.com/blockcypher/go-ethereum/eth"
"github.com/blockcypher/go-ethereum/eth/downloader"
Expand Down Expand Up @@ -286,7 +285,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
PayloadID: id,
}
}
if rawdb.ReadCanonicalHash(api.eth.ChainDb(), block.NumberU64()) != update.HeadBlockHash {
if api.eth.BlockChain().GetHeaderByNumber(block.NumberU64()).Hash() != update.HeadBlockHash {
// Block is not canonical, set head.
if latestValid, err := api.eth.BlockChain().SetCanonical(block); err != nil {
return engine.ForkChoiceResponse{PayloadStatus: engine.PayloadStatusV1{Status: engine.INVALID, LatestValidHash: &latestValid}}, err
Expand Down Expand Up @@ -314,7 +313,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
if finalBlock == nil {
log.Warn("Final block not available in database", "hash", update.FinalizedBlockHash)
return engine.STATUS_INVALID, engine.InvalidForkChoiceState.With(errors.New("final block not available in database"))
} else if rawdb.ReadCanonicalHash(api.eth.ChainDb(), finalBlock.NumberU64()) != update.FinalizedBlockHash {
} else if api.eth.BlockChain().GetHeaderByNumber(finalBlock.NumberU64()).Hash() != update.FinalizedBlockHash {
log.Warn("Final block not in canonical chain", "number", block.NumberU64(), "hash", update.HeadBlockHash)
return engine.STATUS_INVALID, engine.InvalidForkChoiceState.With(errors.New("final block not in canonical chain"))
}
Expand All @@ -328,7 +327,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
log.Warn("Safe block not available in database")
return engine.STATUS_INVALID, engine.InvalidForkChoiceState.With(errors.New("safe block not available in database"))
}
if rawdb.ReadCanonicalHash(api.eth.ChainDb(), safeBlock.NumberU64()) != update.SafeBlockHash {
if api.eth.BlockChain().GetHeaderByNumber(safeBlock.NumberU64()).Hash() != update.SafeBlockHash {
log.Warn("Safe block not in canonical chain")
return engine.STATUS_INVALID, engine.InvalidForkChoiceState.With(errors.New("safe block not in canonical chain"))
}
Expand Down Expand Up @@ -544,6 +543,13 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe
if err := api.eth.BlockChain().InsertBlockWithoutSetHead(block); err != nil {
log.Warn("NewPayloadV1: inserting block failed", "error", err)

if err.Error() == "Not locked" {
// we are stil working on the previous block
// we want to retry later
time.Sleep(5 * time.Second)
return api.NewPayloadV1(params)
}

api.invalidLock.Lock()
api.invalidBlocksHits[block.Hash()] = 1
api.invalidTipsets[block.Hash()] = block.Header()
Expand All @@ -567,6 +573,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe
// be called by the newpayload command when the block seems to be ok, but some
// prerequisite prevents it from being processed (e.g. no parent, or snap sync).
func (api *ConsensusAPI) delayPayloadImport(block *types.Block) (engine.PayloadStatusV1, error) {
return engine.PayloadStatusV1{Status: engine.SYNCING}, errors.New("delayPayloadImport is not supported for bolt")
// Sanity check that this block's parent is not on a previously invalidated
// chain. If it is, mark the block as invalid too.
if res := api.checkInvalidAncestor(block.ParentHash(), block.Hash()); res != nil {
Expand Down

0 comments on commit 7453990

Please sign in to comment.