Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not advertise firehose finalized block when syncing behind beacon finalized block #2

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,15 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
td = new(big.Int).Add(difficulty, ptd)
}

firehoseContext.EndBlock(block, p.bc.CurrentFinalizedBlock(), td)
finalizedBlock := p.bc.CurrentFinalizedBlock()

if finalizedBlock != nil && firehose.SyncingBehindFinalized() {
// if beaconFinalizedBlockNum is in the future, the 'finalizedBlock' will not progress until we reach it.
// we don't want to advertise a super old finalizedBlock when reprocessing.
finalizedBlock = nil
}

firehoseContext.EndBlock(block, finalizedBlock, td)
}

return receipts, allLogs, *usedGas, nil
Expand Down
15 changes: 15 additions & 0 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/firehose"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -190,12 +191,26 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV1(update beacon.ForkchoiceStateV1, pa
merger.ReachTTD()
api.eth.Downloader().Cancel()
}

if firehose.Enabled {
if update.FinalizedBlockHash != (common.Hash{}) {
if finalBlock := api.eth.BlockChain().GetBlockByHash(update.FinalizedBlockHash); finalBlock == nil {
// advertised finalized block is in the future, we are syncing
firehose.SetSyncingBehindFinalized(true)
}
}
}

log.Info("Forkchoice requested sync to new head", "number", header.Number, "hash", header.Hash())
if err := api.eth.Downloader().BeaconSync(api.eth.SyncMode(), header); err != nil {
return beacon.STATUS_SYNCING, err
}
return beacon.STATUS_SYNCING, nil
}

if firehose.Enabled {
firehose.SetSyncingBehindFinalized(false)
}
// Block is known locally, just sanity check that the beacon client does not
// attempt to push us back to before the merge.
if block.Difficulty().BitLen() > 0 || block.NumberU64() == 0 {
Expand Down
15 changes: 15 additions & 0 deletions firehose/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@ package firehose

import (
"math/big"
"sync/atomic"

"github.com/golang-collections/collections/stack"
)

var EmptyValue = new(big.Int)

var behindFinalized int32

func SyncingBehindFinalized() bool {
return atomic.LoadInt32(&behindFinalized) != 0
}

func SetSyncingBehindFinalized(behind bool) {
if behind {
atomic.StoreInt32(&behindFinalized, 1)
} else {
atomic.StoreInt32(&behindFinalized, 0)
}
}

type logItem = map[string]interface{}

type ExtendedStack struct {
Expand Down