Skip to content

Commit

Permalink
chore(evm-reader): adjust 'mostRecentBlock' mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Aug 28, 2024
1 parent 099e940 commit 6701812
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
20 changes: 10 additions & 10 deletions internal/evmreader/evmreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (r *EvmReader) checkForNewInputs(ctx context.Context) error {
lastProcessedBlock = r.inputBoxDeploymentBlock - 1
}

currentMostRecentFinalizedHeader, err := r.fetchMostRecentHeader(
mostRecentHeader, err := r.fetchMostRecentHeader(
ctx,
r.defaultBlock,
)
Expand All @@ -198,42 +198,42 @@ func (r *EvmReader) checkForNewInputs(ctx context.Context) error {
"error", err)
continue
}
currentMostRecentFinalizedBlockNumber := currentMostRecentFinalizedHeader.Number.Uint64()
mostRecentBlockNumber := mostRecentHeader.Number.Uint64()

if currentMostRecentFinalizedBlockNumber > lastProcessedBlock {
if mostRecentBlockNumber > lastProcessedBlock {

slog.Info("Checking inputs for applications",
"apps", appAddresses,
"last processed block", lastProcessedBlock,
"most recent block", currentMostRecentFinalizedBlockNumber,
"most recent block", mostRecentBlockNumber,
)

err = r.readAndStoreInputs(ctx,
lastProcessedBlock+1,
currentMostRecentFinalizedBlockNumber,
mostRecentBlockNumber,
apps,
)
if err != nil {
slog.Error("Error reading inputs",
"apps", appAddresses,
"last processed block", lastProcessedBlock,
"most recent block", currentMostRecentFinalizedBlockNumber,
"most recent block", mostRecentBlockNumber,
"error", err,
)
continue
}
} else if currentMostRecentFinalizedBlockNumber < lastProcessedBlock {
} else if mostRecentBlockNumber < lastProcessedBlock {
slog.Warn(
"Current most recent block is lower than the last processed one",
"Most recent block is lower than the last processed one",
"apps", appAddresses,
"last processed block", lastProcessedBlock,
"most recent block", currentMostRecentFinalizedBlockNumber,
"most recent block", mostRecentBlockNumber,
)
} else {
slog.Info("Already checked the most recent blocks",
"apps", appAddresses,
"last processed block", lastProcessedBlock,
"most recent block", currentMostRecentFinalizedBlockNumber,
"most recent block", mostRecentBlockNumber,
)
}
}
Expand Down
24 changes: 10 additions & 14 deletions internal/evmreader/evmreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ func (s *EvmReaderSuite) TestItReadsInputsFromNewBlocks() {
// Prepare sequence of inputs
s.inputBox.Unset("RetrieveInputs")
events_0 := []inputbox.InputBoxInputAdded{inputAddedEvent0}
currentMostRecentFinalizedBlockNumber_0 := uint64(0x11)
mostRecentBlockNumber_0 := uint64(0x11)
retrieveInputsOpts_0 := bind.FilterOpts{
Context: s.ctx,
Start: 0x10,
End: &currentMostRecentFinalizedBlockNumber_0,
End: &mostRecentBlockNumber_0,
}
s.inputBox.On(
"RetrieveInputs",
Expand All @@ -237,11 +237,11 @@ func (s *EvmReaderSuite) TestItReadsInputsFromNewBlocks() {
).Return(events_0, nil)

events_1 := []inputbox.InputBoxInputAdded{inputAddedEvent1}
currentMostRecentFinalizedBlockNumber_1 := uint64(0x12)
mostRecentBlockNumber_1 := uint64(0x12)
retrieveInputsOpts_1 := bind.FilterOpts{
Context: s.ctx,
Start: 0x12,
End: &currentMostRecentFinalizedBlockNumber_1,
End: &mostRecentBlockNumber_1,
}
s.inputBox.On(
"RetrieveInputs",
Expand Down Expand Up @@ -411,11 +411,11 @@ func (s *EvmReaderSuite) TestItUpdatesLastProcessedBlockWhenThereIsNoInputs() {
// Prepare sequence of inputs
s.inputBox.Unset("RetrieveInputs")
events_0 := []inputbox.InputBoxInputAdded{}
currentMostRecentFinalizedBlockNumber_0 := uint64(0x11)
mostRecentBlockNumber_0 := uint64(0x11)
retrieveInputsOpts_0 := bind.FilterOpts{
Context: s.ctx,
Start: 0x10,
End: &currentMostRecentFinalizedBlockNumber_0,
End: &mostRecentBlockNumber_0,
}
s.inputBox.On(
"RetrieveInputs",
Expand All @@ -425,11 +425,11 @@ func (s *EvmReaderSuite) TestItUpdatesLastProcessedBlockWhenThereIsNoInputs() {
).Return(events_0, nil)

events_1 := []inputbox.InputBoxInputAdded{}
currentMostRecentFinalizedBlockNumber_1 := uint64(0x12)
mostRecentBlockNumber_1 := uint64(0x12)
retrieveInputsOpts_1 := bind.FilterOpts{
Context: s.ctx,
Start: 0x12,
End: &currentMostRecentFinalizedBlockNumber_1,
End: &mostRecentBlockNumber_1,
}
s.inputBox.On(
"RetrieveInputs",
Expand Down Expand Up @@ -491,11 +491,11 @@ func (s *EvmReaderSuite) TestItReadsMultipleInputsFromSingleNewBlock() {
// Prepare sequence of inputs
s.inputBox.Unset("RetrieveInputs")
events_2 := []inputbox.InputBoxInputAdded{inputAddedEvent2, inputAddedEvent3}
currentMostRecentFinalizedBlockNumber_2 := uint64(0x13)
mostRecentBlockNumber_2 := uint64(0x13)
retrieveInputsOpts_2 := bind.FilterOpts{
Context: s.ctx,
Start: 0x13,
End: &currentMostRecentFinalizedBlockNumber_2,
End: &mostRecentBlockNumber_2,
}
s.inputBox.On(
"RetrieveInputs",
Expand Down Expand Up @@ -753,10 +753,6 @@ type MockRepository struct {
func newMockRepository() *MockRepository {
repo := &MockRepository{}

repo.On("GetMostRecentlyFinalizedBlock",
mock.Anything,
mock.Anything).Return(uint64(0), nil)

repo.On("StoreEpochAndInputsTransaction",
mock.Anything,
mock.Anything,
Expand Down

0 comments on commit 6701812

Please sign in to comment.