eth/catalyst: trigger beacon sync directly with provided chain head (#26489)

This commit is contained in:
rjl493456442 2023-01-13 15:13:27 +08:00 committed by GitHub
parent d379e3f605
commit a21e963ac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,9 +20,9 @@ import (
"sync" "sync"
"time" "time"
"github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
) )
@ -50,10 +50,7 @@ func RegisterFullSyncTester(stack *node.Node, backend *eth.Ethereum, block *type
return cl, nil return cl, nil
} }
// Start launches the full-sync tester by spinning up a background thread // Start launches the beacon sync with provided sync target.
// for keeping firing NewPayload-UpdateForkChoice combos with the provided
// target block, it may or may not trigger the beacon sync depends on if
// there are protocol peers connected.
func (tester *FullSyncTester) Start() error { func (tester *FullSyncTester) Start() error {
tester.wg.Add(1) tester.wg.Add(1)
go func() { go func() {
@ -70,19 +67,19 @@ func (tester *FullSyncTester) Start() error {
continue continue
} }
// Short circuit in case the target block is already stored // Short circuit in case the target block is already stored
// locally. // locally. TODO(somehow terminate the node stack if target
// is reached).
if tester.api.eth.BlockChain().HasBlock(tester.block.Hash(), tester.block.NumberU64()) { if tester.api.eth.BlockChain().HasBlock(tester.block.Hash(), tester.block.NumberU64()) {
log.Info("Full-sync target reached", "number", tester.block.NumberU64(), "hash", tester.block.Hash()) log.Info("Full-sync target reached", "number", tester.block.NumberU64(), "hash", tester.block.Hash())
return return
} }
// Shoot out consensus events in order to trigger syncing. // Trigger beacon sync with the provided block header as
data := beacon.BlockToExecutableData(tester.block) // trusted chain head.
tester.api.NewPayloadV1(*data) err := tester.api.eth.Downloader().BeaconSync(downloader.FullSync, tester.block.Header())
tester.api.ForkchoiceUpdatedV1(beacon.ForkchoiceStateV1{ if err != nil {
HeadBlockHash: tester.block.Hash(), log.Info("Failed to beacon sync", "err", err)
SafeBlockHash: tester.block.Hash(), }
FinalizedBlockHash: tester.block.Hash(),
}, nil)
case <-tester.closed: case <-tester.closed:
return return
} }