Skip to content

Commit f87acd0

Browse files
committed
Merge pull request #2 from streamingfast/stepd/prevent-finalized-stall-on-syncing
do not advertise firehose finalized block when syncing behind beacon finalized block (release geth-v1.10.23-fh2.2)
2 parents e7f3686 + 7451334 commit f87acd0

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

core/state_processor.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,15 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
143143
td = new(big.Int).Add(difficulty, ptd)
144144
}
145145

146-
firehoseContext.EndBlock(block, p.bc.CurrentFinalizedBlock(), td)
146+
finalizedBlock := p.bc.CurrentFinalizedBlock()
147+
148+
if finalizedBlock != nil && firehose.SyncingBehindFinalized() {
149+
// if beaconFinalizedBlockNum is in the future, the 'finalizedBlock' will not progress until we reach it.
150+
// we don't want to advertise a super old finalizedBlock when reprocessing.
151+
finalizedBlock = nil
152+
}
153+
154+
firehoseContext.EndBlock(block, finalizedBlock, td)
147155
}
148156

149157
return receipts, allLogs, *usedGas, nil

eth/catalyst/api.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/ethereum/go-ethereum/core/types"
3434
"github.com/ethereum/go-ethereum/eth"
3535
"github.com/ethereum/go-ethereum/eth/downloader"
36+
"github.com/ethereum/go-ethereum/firehose"
3637
"github.com/ethereum/go-ethereum/log"
3738
"github.com/ethereum/go-ethereum/node"
3839
"github.com/ethereum/go-ethereum/rpc"
@@ -190,12 +191,26 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV1(update beacon.ForkchoiceStateV1, pa
190191
merger.ReachTTD()
191192
api.eth.Downloader().Cancel()
192193
}
194+
195+
if firehose.Enabled {
196+
if update.FinalizedBlockHash != (common.Hash{}) {
197+
if finalBlock := api.eth.BlockChain().GetBlockByHash(update.FinalizedBlockHash); finalBlock == nil {
198+
// advertised finalized block is in the future, we are syncing
199+
firehose.SetSyncingBehindFinalized(true)
200+
}
201+
}
202+
}
203+
193204
log.Info("Forkchoice requested sync to new head", "number", header.Number, "hash", header.Hash())
194205
if err := api.eth.Downloader().BeaconSync(api.eth.SyncMode(), header); err != nil {
195206
return beacon.STATUS_SYNCING, err
196207
}
197208
return beacon.STATUS_SYNCING, nil
198209
}
210+
211+
if firehose.Enabled {
212+
firehose.SetSyncingBehindFinalized(false)
213+
}
199214
// Block is known locally, just sanity check that the beacon client does not
200215
// attempt to push us back to before the merge.
201216
if block.Difficulty().BitLen() > 0 || block.NumberU64() == 0 {

firehose/types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@ package firehose
22

33
import (
44
"math/big"
5+
"sync/atomic"
56

67
"github.com/golang-collections/collections/stack"
78
)
89

910
var EmptyValue = new(big.Int)
1011

12+
var behindFinalized int32
13+
14+
func SyncingBehindFinalized() bool {
15+
return atomic.LoadInt32(&behindFinalized) != 0
16+
}
17+
18+
func SetSyncingBehindFinalized(behind bool) {
19+
if behind {
20+
atomic.StoreInt32(&behindFinalized, 1)
21+
} else {
22+
atomic.StoreInt32(&behindFinalized, 0)
23+
}
24+
}
25+
1126
type logItem = map[string]interface{}
1227

1328
type ExtendedStack struct {

0 commit comments

Comments
 (0)