@@ -179,21 +179,7 @@ func (sync *synchronizerState) syncEpoch(syncEpoch uint64) bool {
179179 return false
180180 }
181181
182- // load epoch validators
183- var firstBlock * BlockInfo
184- lastSlot = firstSlot + (utils .Config .Chain .Config .SlotsPerEpoch ) - 1
185- for slot := firstSlot ; slot <= lastSlot ; slot ++ {
186- if sync .cachedBlocks [slot ] != nil {
187- firstBlock = sync .cachedBlocks [slot ][0 ]
188- break
189- }
190- }
191- if firstBlock == nil {
192- // TODO: How to handle a epoch without any blocks?
193- synclogger .Errorf ("Syncing epoch %v without any block is not supported" , syncEpoch )
194- return true
195- }
196-
182+ // load epoch stats
197183 epochStats := EpochStats {
198184 Assignments : epochAssignments ,
199185 Validators : & EpochValidators {
@@ -202,11 +188,9 @@ func (sync *synchronizerState) syncEpoch(syncEpoch uint64) bool {
202188 ValidatorBalances : make (map [uint64 ]uint64 ),
203189 },
204190 }
205-
206- // load epoch stats
207191 epochValidators , err := sync .indexer .rpcClient .GetStateValidators (epochAssignments .DependendState )
208192 if err != nil {
209- logger .Errorf ("Error fetching epoch %v/%v validators: %v" , syncEpoch , firstBlock . Header . Data . Header . Message . Slot , err )
193+ logger .Errorf ("Error fetching epoch %v validators (state : %v): %v " , syncEpoch , epochAssignments . DependendState , err )
210194 } else {
211195 for idx := 0 ; idx < len (epochValidators .Data ); idx ++ {
212196 validator := epochValidators .Data [idx ]
@@ -224,11 +208,22 @@ func (sync *synchronizerState) syncEpoch(syncEpoch uint64) bool {
224208 }
225209
226210 // process epoch vote aggregations
211+ var firstBlock * BlockInfo
212+ lastSlot = firstSlot + (utils .Config .Chain .Config .SlotsPerEpoch ) - 1
213+ for slot := firstSlot ; slot <= lastSlot ; slot ++ {
214+ if sync .cachedBlocks [slot ] != nil {
215+ firstBlock = sync .cachedBlocks [slot ][0 ]
216+ break
217+ }
218+ }
219+
227220 var targetRoot []byte
228- if uint64 (firstBlock .Header .Data .Header .Message .Slot ) == firstSlot {
229- targetRoot = firstBlock .Header .Data .Root
230- } else {
231- targetRoot = firstBlock .Header .Data .Header .Message .ParentRoot
221+ if firstBlock != nil {
222+ if uint64 (firstBlock .Header .Data .Header .Message .Slot ) == firstSlot {
223+ targetRoot = firstBlock .Header .Data .Root
224+ } else {
225+ targetRoot = firstBlock .Header .Data .Header .Message .ParentRoot
226+ }
232227 }
233228 epochVotes := aggregateEpochVotes (sync .cachedBlocks , syncEpoch , & epochStats , targetRoot , false )
234229
0 commit comments