beacon/blsync: proceed with empty finalized hash if proof is not expected soon (#29449)

* beacon/blsync: proceed with empty finalized hash if proof is not expected soon

* Update beacon/blsync/block_sync.go

Co-authored-by: Felix Lange <fjl@twurst.com>

* beacon/blsync: fixed linter warning

* Update beacon/blsync/block_sync.go

Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
This commit is contained in:
Felföldi Zsolt 2024-04-17 17:07:28 +02:00 committed by GitHub
parent 1e9bf2a09e
commit 0da69e84c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -19,6 +19,7 @@ package blsync
import ( import (
"github.com/ethereum/go-ethereum/beacon/light/request" "github.com/ethereum/go-ethereum/beacon/light/request"
"github.com/ethereum/go-ethereum/beacon/light/sync" "github.com/ethereum/go-ethereum/beacon/light/sync"
"github.com/ethereum/go-ethereum/beacon/params"
"github.com/ethereum/go-ethereum/beacon/types" "github.com/ethereum/go-ethereum/beacon/types"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/lru" "github.com/ethereum/go-ethereum/common/lru"
@ -117,15 +118,31 @@ func (s *beaconBlockSync) updateEventFeed() {
if !ok { if !ok {
return return
} }
finality, ok := s.headTracker.ValidatedFinality() //TODO fetch directly if subscription does not deliver
if !ok || head.Header.Epoch() != finality.Attested.Header.Epoch() {
return
}
validatedHead := head.Header.Hash() validatedHead := head.Header.Hash()
headBlock, ok := s.recentBlocks.Get(validatedHead) headBlock, ok := s.recentBlocks.Get(validatedHead)
if !ok { if !ok {
return return
} }
var finalizedHash common.Hash
if finality, ok := s.headTracker.ValidatedFinality(); ok {
he := head.Header.Epoch()
fe := finality.Attested.Header.Epoch()
switch {
case he == fe:
finalizedHash = finality.Finalized.PayloadHeader.BlockHash()
case he < fe:
return
case he == fe+1:
parent, ok := s.recentBlocks.Get(head.Header.ParentRoot)
if !ok || parent.Slot()/params.EpochLength == fe {
return // head is at first slot of next epoch, wait for finality update
//TODO: try to fetch finality update directly if subscription does not deliver
}
}
}
headInfo := blockHeadInfo(headBlock) headInfo := blockHeadInfo(headBlock)
if headInfo == s.lastHeadInfo { if headInfo == s.lastHeadInfo {
return return
@ -141,6 +158,6 @@ func (s *beaconBlockSync) updateEventFeed() {
s.chainHeadFeed.Send(types.ChainHeadEvent{ s.chainHeadFeed.Send(types.ChainHeadEvent{
BeaconHead: head.Header, BeaconHead: head.Header,
Block: execBlock, Block: execBlock,
Finalized: finality.Finalized.PayloadHeader.BlockHash(), Finalized: finalizedHash,
}) })
} }