@@ -131,6 +131,12 @@ func (s *Service) sendStateFeedOnBlock(cfg *postBlockProcessConfig) {
131
131
}
132
132
133
133
func (s * Service ) processLightClientUpdates (cfg * postBlockProcessConfig ) {
134
+ if err := s .processLightClientUpdate (cfg ); err != nil {
135
+ log .WithError (err ).Error ("Failed to process light client update" )
136
+ }
137
+ if err := s .processLightClientBootstrap (cfg ); err != nil {
138
+ log .WithError (err ).Error ("Failed to process light client bootstrap" )
139
+ }
134
140
if err := s .processLightClientOptimisticUpdate (cfg .ctx , cfg .roblock , cfg .postState ); err != nil {
135
141
log .WithError (err ).Error ("Failed to process light client optimistic update" )
136
142
}
@@ -139,38 +145,33 @@ func (s *Service) processLightClientUpdates(cfg *postBlockProcessConfig) {
139
145
}
140
146
}
141
147
142
- // saveLightClientUpdate saves the light client update for this block
148
+ // processLightClientUpdate saves the light client update for this block
143
149
// if it's better than the already saved one, when feature flag is enabled.
144
- func (s * Service ) saveLightClientUpdate (cfg * postBlockProcessConfig ) {
150
+ func (s * Service ) processLightClientUpdate (cfg * postBlockProcessConfig ) error {
145
151
attestedRoot := cfg .roblock .Block ().ParentRoot ()
146
152
attestedBlock , err := s .getBlock (cfg .ctx , attestedRoot )
147
153
if err != nil {
148
- log .WithError (err ).Errorf ("Saving light client update failed: Could not get attested block for root %#x" , attestedRoot )
149
- return
154
+ return errors .Wrapf (err , "could not get attested block for root %#x" , attestedRoot )
150
155
}
151
156
if attestedBlock == nil || attestedBlock .IsNil () {
152
- log .Error ("Saving light client update failed: Attested block is nil" )
153
- return
157
+ return errors .New ("attested block is nil" )
154
158
}
155
159
attestedState , err := s .cfg .StateGen .StateByRoot (cfg .ctx , attestedRoot )
156
160
if err != nil {
157
- log .WithError (err ).Errorf ("Saving light client update failed: Could not get attested state for root %#x" , attestedRoot )
158
- return
161
+ return errors .Wrapf (err , "could not get attested state for root %#x" , attestedRoot )
159
162
}
160
163
if attestedState == nil || attestedState .IsNil () {
161
- log .Error ("Saving light client update failed: Attested state is nil" )
162
- return
164
+ return errors .New ("attested state is nil" )
163
165
}
164
166
165
167
finalizedRoot := attestedState .FinalizedCheckpoint ().Root
166
168
finalizedBlock , err := s .getBlock (cfg .ctx , [32 ]byte (finalizedRoot ))
167
169
if err != nil {
168
170
if errors .Is (err , errBlockNotFoundInCacheOrDB ) {
169
- log .Debugf ("Skipping saving light client update: Finalized block is nil for root %#x" , finalizedRoot )
170
- } else {
171
- log .WithError (err ).Errorf ("Saving light client update failed: Could not get finalized block for root %#x" , finalizedRoot )
171
+ log .Debugf ("Skipping saving light client update because finalized block is nil for root %#x" , finalizedRoot )
172
+ return nil
172
173
}
173
- return
174
+ return errors . Wrapf ( err , "could not get finalized block for root %#x" , finalizedRoot )
174
175
}
175
176
176
177
update , err := lightclient .NewLightClientUpdateFromBeaconState (
@@ -183,57 +184,52 @@ func (s *Service) saveLightClientUpdate(cfg *postBlockProcessConfig) {
183
184
finalizedBlock ,
184
185
)
185
186
if err != nil {
186
- log .WithError (err ).Error ("Saving light client update failed: Could not create light client update" )
187
- return
187
+ return errors .Wrapf (err , "could not create light client update" )
188
188
}
189
189
190
190
period := slots .SyncCommitteePeriod (slots .ToEpoch (attestedState .Slot ()))
191
191
192
192
oldUpdate , err := s .cfg .BeaconDB .LightClientUpdate (cfg .ctx , period )
193
193
if err != nil {
194
- log .WithError (err ).Error ("Saving light client update failed: Could not get current light client update" )
195
- return
194
+ return errors .Wrapf (err , "could not get current light client update" )
196
195
}
197
196
198
197
if oldUpdate == nil {
199
198
if err := s .cfg .BeaconDB .SaveLightClientUpdate (cfg .ctx , period , update ); err != nil {
200
- log .WithError (err ).Error ("Saving light client update failed: Could not save light client update" )
201
- } else {
202
- log .WithField ("period" , period ).Debug ("Saving light client update: Saved new update" )
199
+ return errors .Wrapf (err , "could not save light client update" )
203
200
}
204
- return
201
+ log .WithField ("period" , period ).Debug ("Saved new light client update" )
202
+ return nil
205
203
}
206
204
207
205
isNewUpdateBetter , err := lightclient .IsBetterUpdate (update , oldUpdate )
208
206
if err != nil {
209
- log .WithError (err ).Error ("Saving light client update failed: Could not compare light client updates" )
210
- return
207
+ return errors .Wrapf (err , "could not compare light client updates" )
211
208
}
212
209
213
210
if isNewUpdateBetter {
214
211
if err := s .cfg .BeaconDB .SaveLightClientUpdate (cfg .ctx , period , update ); err != nil {
215
- log .WithError (err ).Error ("Saving light client update failed: Could not save light client update" )
216
- } else {
217
- log .WithField ("period" , period ).Debug ("Saving light client update: Saved new update" )
212
+ return errors .Wrapf (err , "could not save light client update" )
218
213
}
219
- } else {
220
- log . WithField ( "period" , period ). Debug ( "Saving light client update: New update is not better than the current one. Skipping save." )
214
+ log . WithField ( "period" , period ). Debug ( "Saved new light client update" )
215
+ return nil
221
216
}
217
+ log .WithField ("period" , period ).Debug ("New light client update is not better than the current one, skipping save" )
218
+ return nil
222
219
}
223
220
224
- // saveLightClientBootstrap saves a light client bootstrap for this block
221
+ // processLightClientBootstrap saves a light client bootstrap for this block
225
222
// when feature flag is enabled.
226
- func (s * Service ) saveLightClientBootstrap (cfg * postBlockProcessConfig ) {
223
+ func (s * Service ) processLightClientBootstrap (cfg * postBlockProcessConfig ) error {
227
224
blockRoot := cfg .roblock .Root ()
228
225
bootstrap , err := lightclient .NewLightClientBootstrapFromBeaconState (cfg .ctx , s .CurrentSlot (), cfg .postState , cfg .roblock )
229
226
if err != nil {
230
- log .WithError (err ).Error ("Saving light client bootstrap failed: Could not create light client bootstrap" )
231
- return
227
+ return errors .Wrapf (err , "could not create light client bootstrap" )
232
228
}
233
- err = s .cfg .BeaconDB .SaveLightClientBootstrap (cfg .ctx , blockRoot [:], bootstrap )
234
- if err != nil {
235
- log .WithError (err ).Error ("Saving light client bootstrap failed: Could not save light client bootstrap in DB" )
229
+ if err := s .cfg .BeaconDB .SaveLightClientBootstrap (cfg .ctx , blockRoot [:], bootstrap ); err != nil {
230
+ return errors .Wrapf (err , "could not save light client bootstrap" )
236
231
}
232
+ return nil
237
233
}
238
234
239
235
func (s * Service ) processLightClientFinalityUpdate (
0 commit comments