Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix finality slot #216

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,12 @@ func (m *ApiService) handleStatus(w http.ResponseWriter, req *http.Request) {
consInSync = true
}

finality, err := m.Onchain.ConsensusClient.Finality(context.Background(), &eth2.FinalityOpts{
State: "finalized",
})
finality, err := m.Onchain.FinalizedBeaconBlockHeader(apiRetryOpts...)
if err != nil {
m.respondError(w, http.StatusInternalServerError, "could not get consensus latest finalized slot: "+err.Error())
}

finalizedEpoch := uint64(finality.Data.Finalized.Epoch)
finalizedSlot := finalizedEpoch * constants.SlotsInEpoch
finalizedSlot := uint64(finality.Header.Message.Slot)

oracleSync := false
if m.oracle.State().LatestProcessedSlot-finalizedSlot == 0 {
Expand All @@ -451,7 +448,7 @@ func (m *ApiService) handleStatus(w http.ResponseWriter, req *http.Request) {
IsOracleInSync: oracleSync,
LatestProcessedSlot: m.oracle.State().LatestProcessedSlot,
LatestProcessedBlock: m.oracle.State().LatestProcessedBlock,
LatestFinalizedEpoch: finalizedEpoch,
LatestFinalizedEpoch: finalizedSlot / 32,
LatestFinalizedSlot: finalizedSlot,
OracleHeadDistance: finalizedSlot - m.oracle.State().LatestProcessedSlot,
NextCheckpointSlot: onchainSlot + m.cfg.CheckPointSizeInSlots,
Expand Down Expand Up @@ -1194,14 +1191,16 @@ func (m *ApiService) OracleReady(maxSlotsBehind uint64) bool {
// otherwise the oracle wont be able to reply, since from time to time its normal that it fall behind sync
// since it has to process the new epochs that keep arriving.

finality, err := m.Onchain.ConsensusClient.Finality(context.Background(), &eth2.FinalityOpts{
State: "finalized",
})
finality, err := m.Onchain.FinalizedBeaconBlockHeader(apiRetryOpts...)
if err != nil {
return false
}

finalizedSlot := uint64(finality.Header.Message.Slot)
if err != nil {
return false
}

finalizedSlot := uint64(finality.Data.Finalized.Epoch) * constants.SlotsInEpoch
slotsFromFinalized := finalizedSlot - m.oracle.State().LatestProcessedSlot

// Use this if we want full in sync to latest finalized
Expand Down
Loading