Conversation
claravanstaden
left a comment
There was a problem hiding this comment.
Few minor comments, but it looks great! Nice work.
| if checkpointSlot > lastFinalizedHeaderState.BeaconSlot { | ||
| checkpointSlot = lastFinalizedHeaderState.BeaconSlot | ||
| } |
There was a problem hiding this comment.
Please add a comment here to explain why this check.
Co-authored-by: Clara van Staden <claravanstaden64@gmail.com>
Co-authored-by: Clara van Staden <claravanstaden64@gmail.com>
| err = beaconHeader.SyncExecutionHeader(ctx, *blockHeader.ParentBeaconRoot) | ||
| if err == header.ErrBeaconHeaderNotFinalized { | ||
| logger.Warn("beacon header not finalized, just skipped") | ||
| continue | ||
| } |
There was a problem hiding this comment.
Just scan from the last block number and wait to continue until the execution header for that event log is finalized.
claravanstaden
left a comment
There was a problem hiding this comment.
Almost there! Looks great 😄
| if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+8192 { | ||
| return beaconState, nil | ||
| } | ||
| return beaconState, fmt.Errorf("Can't find checkpoint on chain for slot %d", slot) |
There was a problem hiding this comment.
| return beaconState, fmt.Errorf("Can't find checkpoint on chain for slot %d", slot) | |
| return beaconState, fmt.Errorf("find checkpoint on chain for slot %d", slot) |
The error message is appended continuously, like here https://github.com/Snowfork/snowbridge/pull/1154/files#diff-92cc554d5b7218e7576839ca25a3b71ae0bbfa8200552beaf703a95a1a0da2a3R292, so simplify and lowercase the error message.
| return beaconRoot, nil | ||
| } | ||
|
|
||
| func (wr *ParachainWriter) FindCheckPointBackward(slot uint64) (state.FinalizedHeader, error) { |
There was a problem hiding this comment.
| func (wr *ParachainWriter) FindCheckPointBackward(slot uint64) (state.FinalizedHeader, error) { | |
| func (wr *ParachainWriter) FindCheckPoint(slot uint64) (state.FinalizedHeader, error) { |
| if beaconState.BeaconSlot < slot { | ||
| break | ||
| } | ||
| if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+8192 { |
There was a problem hiding this comment.
Should rather use SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD here. Please also add code comments explaining this line and the one above, it's not clear to me what these 2 checks check.
There was a problem hiding this comment.
It's to backward to find check point(slot<beaconState.BeaconSlot<slot+8192)
For the first check beaconState.BeaconSlot < slot which means there is no valid checkpoint on chain so just exit the loop.
For the second check if beaconState.BeaconSlot > slot && beaconState.BeaconSlot < slot+8192 which means we find that so exit the loop.
| return checkpoint, ErrBeaconHeaderNotFinalized | ||
| } | ||
| if checkpointSlot < lastFinalizedHeaderState.BeaconSlot { | ||
| log.WithFields(log.Fields{"calculatedCheckpointSlot": checkpointSlot, "lastFinalizedSlot": lastFinalizedHeaderState.BeaconSlot}).Info("fetch checkpoint on chain backward from history") |
There was a problem hiding this comment.
| log.WithFields(log.Fields{"calculatedCheckpointSlot": checkpointSlot, "lastFinalizedSlot": lastFinalizedHeaderState.BeaconSlot}).Info("fetch checkpoint on chain backward from history") | |
| log.WithFields(log.Fields{"calculatedCheckpointSlot": checkpointSlot, "lastFinalizedSlot": lastFinalizedHeaderState.BeaconSlot}).Info("fetch closest checkpoint on chain") |
| } | ||
| err = h.writer.WriteToParachainAndWatch(ctx, "EthereumBeaconClient.submit_execution_header", headerUpdate) | ||
| if err != nil { | ||
| return fmt.Errorf("submit_execution_header: %w", err) |
There was a problem hiding this comment.
| return fmt.Errorf("submit_execution_header: %w", err) | |
| return fmt.Errorf("submit execution header : %w", err) |
Requires: Snowfork/polkadot-sdk#123