Skip to content

Commit

Permalink
Allow catchpoints on the exact target round
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos committed Apr 18, 2024
1 parent 3357b40 commit 33b4941
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 2 additions & 4 deletions conduit/plugins/importers/algod/algod_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ func getMissingCatchpointLabel(URL string, nextRound uint64) (string, error) {
if err != nil {
return "", err
}
// TODO: Change >= to > after go-algorand#5352 is fixed.
if uint64(round) >= nextRound {
if uint64(round) > nextRound {
break
}
label = line
Expand All @@ -204,8 +203,7 @@ func getMissingCatchpointLabel(URL string, nextRound uint64) (string, error) {
// is detected.
func checkRounds(logger *logrus.Logger, catchpointRound, nodeRound, targetRound uint64) (bool, error) {
// Make sure catchpoint round is not in the future
// TODO: Change < to <= after go-algorand#5352 is fixed.
canCatchup := catchpointRound < targetRound
canCatchup := catchpointRound <= targetRound
mustCatchup := targetRound < nodeRound
shouldCatchup := nodeRound < catchpointRound

Expand Down
19 changes: 18 additions & 1 deletion conduit/plugins/importers/algod/algod_importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ func Test_checkRounds(t *testing.T) {
wantLogLevel: logrus.InfoLevel,
wantLogMsg: "Catchup required, node round ahead of target round. Node round 5000, target round 1002, catchpoint round 1000.",
},
{
name: "Catchup required. Success. Edgecase where catchpoint round is equal to target round.",
args: args{
catchpointRound: 1000,
nodeRound: 5000,
targetRound: 1000,
},
want: true,
wantErr: assert.NoError,
wantLogLevel: logrus.InfoLevel,
wantLogMsg: "Catchup required, node round ahead of target round. Node round 5000, target round 1000, catchpoint round 1000.",
},
{
name: "Catchup required. Error.",
args: args{
Expand All @@ -130,8 +142,8 @@ func Test_checkRounds(t *testing.T) {

// Write 1 line to the log.
require.Len(t, hook.Entries, 1)
require.Equal(t, tt.wantLogLevel, hook.Entries[0].Level)
require.Equal(t, tt.wantLogMsg, hook.Entries[0].Message)
require.Equal(t, tt.wantLogLevel, hook.Entries[0].Level)

// Check the error
if !tt.wantErr(t, err, fmt.Sprintf("checkRounds(-, %v, %v, %v)", tt.args.catchpointRound, tt.args.nodeRound, tt.args.targetRound)) {
Expand Down Expand Up @@ -796,6 +808,11 @@ func TestGetMissingCatchpointLabel(t *testing.T) {
require.NoError(t, err)
// closest without going over
require.Equal(t, "1100#abcd", label)

label, err = getMissingCatchpointLabel(ts.URL, 1000)
require.NoError(t, err)
// returns the exact match
require.Equal(t, "1000#abcd", label)
}

func TestGetMissingCatchpointLabelError(t *testing.T) {
Expand Down

0 comments on commit 33b4941

Please sign in to comment.