Skip to content
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