From 33b494116d694f6de709a5a4c7f23470939baeca Mon Sep 17 00:00:00 2001 From: Jason Paulos Date: Thu, 18 Apr 2024 16:43:42 -0400 Subject: [PATCH] Allow catchpoints on the exact target round --- .../plugins/importers/algod/algod_importer.go | 6 ++---- .../importers/algod/algod_importer_test.go | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/conduit/plugins/importers/algod/algod_importer.go b/conduit/plugins/importers/algod/algod_importer.go index c26cb4d1..2c52aaf6 100644 --- a/conduit/plugins/importers/algod/algod_importer.go +++ b/conduit/plugins/importers/algod/algod_importer.go @@ -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 @@ -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 diff --git a/conduit/plugins/importers/algod/algod_importer_test.go b/conduit/plugins/importers/algod/algod_importer_test.go index 00c07a9e..93d645c6 100644 --- a/conduit/plugins/importers/algod/algod_importer_test.go +++ b/conduit/plugins/importers/algod/algod_importer_test.go @@ -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{ @@ -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)) { @@ -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) {