@@ -19,6 +19,7 @@ package blsync
19
19
import (
20
20
"github.com/ethereum/go-ethereum/beacon/light/request"
21
21
"github.com/ethereum/go-ethereum/beacon/light/sync"
22
+ "github.com/ethereum/go-ethereum/beacon/params"
22
23
"github.com/ethereum/go-ethereum/beacon/types"
23
24
"github.com/ethereum/go-ethereum/common"
24
25
"github.com/ethereum/go-ethereum/common/lru"
@@ -117,15 +118,31 @@ func (s *beaconBlockSync) updateEventFeed() {
117
118
if ! ok {
118
119
return
119
120
}
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
+
124
122
validatedHead := head .Header .Hash ()
125
123
headBlock , ok := s .recentBlocks .Get (validatedHead )
126
124
if ! ok {
127
125
return
128
126
}
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
+
129
146
headInfo := blockHeadInfo (headBlock )
130
147
if headInfo == s .lastHeadInfo {
131
148
return
@@ -141,6 +158,6 @@ func (s *beaconBlockSync) updateEventFeed() {
141
158
s .chainHeadFeed .Send (types.ChainHeadEvent {
142
159
BeaconHead : head .Header ,
143
160
Block : execBlock ,
144
- Finalized : finality . Finalized . PayloadHeader . BlockHash () ,
161
+ Finalized : finalizedHash ,
145
162
})
146
163
}
0 commit comments