Skip to content

Commit 336b529

Browse files
zsfelfoldifjllightclient
authored andcommitted
beacon/blsync: proceed with empty finalized hash if proof is not expected soon (ethereum#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 <[email protected]> * beacon/blsync: fixed linter warning * Update beacon/blsync/block_sync.go Co-authored-by: lightclient <[email protected]> --------- Co-authored-by: Felix Lange <[email protected]> Co-authored-by: lightclient <[email protected]>
1 parent ffd50ff commit 336b529

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

beacon/blsync/block_sync.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package blsync
1919
import (
2020
"github.com/ethereum/go-ethereum/beacon/light/request"
2121
"github.com/ethereum/go-ethereum/beacon/light/sync"
22+
"github.com/ethereum/go-ethereum/beacon/params"
2223
"github.com/ethereum/go-ethereum/beacon/types"
2324
"github.com/ethereum/go-ethereum/common"
2425
"github.com/ethereum/go-ethereum/common/lru"
@@ -117,15 +118,31 @@ func (s *beaconBlockSync) updateEventFeed() {
117118
if !ok {
118119
return
119120
}
120-
finality, ok := s.headTracker.ValidatedFinality() //TODO fetch directly if subscription does not deliver
121-
if !ok || head.Header.Epoch() != finality.Attested.Header.Epoch() {
122-
return
123-
}
121+
124122
validatedHead := head.Header.Hash()
125123
headBlock, ok := s.recentBlocks.Get(validatedHead)
126124
if !ok {
127125
return
128126
}
127+
128+
var finalizedHash common.Hash
129+
if finality, ok := s.headTracker.ValidatedFinality(); ok {
130+
he := head.Header.Epoch()
131+
fe := finality.Attested.Header.Epoch()
132+
switch {
133+
case he == fe:
134+
finalizedHash = finality.Finalized.PayloadHeader.BlockHash()
135+
case he < fe:
136+
return
137+
case he == fe+1:
138+
parent, ok := s.recentBlocks.Get(head.Header.ParentRoot)
139+
if !ok || parent.Slot()/params.EpochLength == fe {
140+
return // head is at first slot of next epoch, wait for finality update
141+
//TODO: try to fetch finality update directly if subscription does not deliver
142+
}
143+
}
144+
}
145+
129146
headInfo := blockHeadInfo(headBlock)
130147
if headInfo == s.lastHeadInfo {
131148
return
@@ -141,6 +158,6 @@ func (s *beaconBlockSync) updateEventFeed() {
141158
s.chainHeadFeed.Send(types.ChainHeadEvent{
142159
BeaconHead: head.Header,
143160
Block: execBlock,
144-
Finalized: finality.Finalized.PayloadHeader.BlockHash(),
161+
Finalized: finalizedHash,
145162
})
146163
}

0 commit comments

Comments
 (0)