From fd70b194749c20780b4987da86fbf3a4ee929e62 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Thu, 4 Apr 2024 09:57:37 +0200 Subject: [PATCH 1/4] beacon/blsync: proceed with empty finalized hash if proof is not expected soon --- beacon/blsync/block_sync.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/beacon/blsync/block_sync.go b/beacon/blsync/block_sync.go index ef852dfe996f..d3b62a2d4765 100755 --- a/beacon/blsync/block_sync.go +++ b/beacon/blsync/block_sync.go @@ -19,6 +19,7 @@ package blsync import ( "github.com/ethereum/go-ethereum/beacon/light/request" "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/common" "github.com/ethereum/go-ethereum/common/lru" @@ -117,15 +118,32 @@ func (s *beaconBlockSync) updateEventFeed() { if !ok { 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() headBlock, ok := s.recentBlocks.Get(validatedHead) if !ok { return } + + var finalizedHash common.Hash + if finality, ok := s.headTracker.ValidatedFinality(); ok { + if he, fe := head.Header.Epoch(), finality.Attested.Header.Epoch(); he == fe { + finalizedHash = finality.Finalized.PayloadHeader.BlockHash() + } else { + if he < fe { + return // finality proof arrived earlier, wait for head update + } + if he == fe+1 { + if parent, ok := s.recentBlocks.Get(head.Header.ParentRoot); !ok || + parent.Slot()/params.EpochLength == fe { + return // head is at first slot of next epoch, wait for finality update + //TODO trt to fetch finality update directly if subscription does not deliver + } + + } + } + } + headInfo := blockHeadInfo(headBlock) if headInfo == s.lastHeadInfo { return @@ -141,6 +159,6 @@ func (s *beaconBlockSync) updateEventFeed() { s.chainHeadFeed.Send(types.ChainHeadEvent{ BeaconHead: head.Header, Block: execBlock, - Finalized: finality.Finalized.PayloadHeader.BlockHash(), + Finalized: finalizedHash, }) } From 9de80ca574b7f41b4179149a901fdef676a61300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felf=C3=B6ldi=20Zsolt?= Date: Fri, 5 Apr 2024 11:52:50 +0200 Subject: [PATCH 2/4] Update beacon/blsync/block_sync.go Co-authored-by: Felix Lange --- beacon/blsync/block_sync.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/beacon/blsync/block_sync.go b/beacon/blsync/block_sync.go index d3b62a2d4765..64053c92f4e2 100755 --- a/beacon/blsync/block_sync.go +++ b/beacon/blsync/block_sync.go @@ -127,19 +127,18 @@ func (s *beaconBlockSync) updateEventFeed() { var finalizedHash common.Hash if finality, ok := s.headTracker.ValidatedFinality(); ok { - if he, fe := head.Header.Epoch(), finality.Attested.Header.Epoch(); he == fe { + he := head.Header.Epoch() + fe := finality.Attested.Header.Epoch() + switch { + case he == fe: finalizedHash = finality.Finalized.PayloadHeader.BlockHash() - } else { - if he < fe { - return // finality proof arrived earlier, wait for head update - } - if he == fe+1 { - if parent, ok := s.recentBlocks.Get(head.Header.ParentRoot); !ok || - parent.Slot()/params.EpochLength == fe { - return // head is at first slot of next epoch, wait for finality update - //TODO trt to fetch finality update directly if subscription does not deliver - } - + 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 trt to fetch finality update directly if subscription does not deliver } } } From fdfffbb3b2bfce2bb5c2ae07479898e83c308a1a Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Fri, 5 Apr 2024 11:59:26 +0200 Subject: [PATCH 3/4] beacon/blsync: fixed linter warning --- beacon/blsync/block_sync.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon/blsync/block_sync.go b/beacon/blsync/block_sync.go index 64053c92f4e2..23c3169fe053 100755 --- a/beacon/blsync/block_sync.go +++ b/beacon/blsync/block_sync.go @@ -135,7 +135,7 @@ func (s *beaconBlockSync) updateEventFeed() { case he < fe: return case he == fe+1: - parent, ok := s.recentBlocks.Get(head.Header.ParentRoot) + 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 trt to fetch finality update directly if subscription does not deliver From 22e075ff800c5c5fa2c3eeaeff0241ef27638f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felf=C3=B6ldi=20Zsolt?= Date: Mon, 8 Apr 2024 08:32:36 +0200 Subject: [PATCH 4/4] Update beacon/blsync/block_sync.go Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com> --- beacon/blsync/block_sync.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon/blsync/block_sync.go b/beacon/blsync/block_sync.go index 23c3169fe053..3ab156354dca 100755 --- a/beacon/blsync/block_sync.go +++ b/beacon/blsync/block_sync.go @@ -138,7 +138,7 @@ func (s *beaconBlockSync) updateEventFeed() { 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 trt to fetch finality update directly if subscription does not deliver + //TODO: try to fetch finality update directly if subscription does not deliver } } }