Skip to content

Commit

Permalink
PR feedback, no magic number.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Sep 25, 2023
1 parent 9f7a7c5 commit 6f07de0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
4 changes: 2 additions & 2 deletions daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2511,9 +2511,9 @@
},
{
"name": "initialize",
"description": "When set to `true`, catchup will only be used to initialize the node. This means it will only run a fast catchup that advances the round by at least 1 million rounds.",
"description": "Specify a number of blocks which the ledger must be advanced by in order to start the catchup. This is useful for simplifying tools which support fast catchup, they can run the catchup unconditionally and the node will skip the catchup if it is not needed.",
"in": "query",
"type": "boolean"
"type": "integer"
}
],
"responses": {
Expand Down
4 changes: 2 additions & 2 deletions daemon/algod/api/algod.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4304,11 +4304,11 @@
"x-algorand-format": "Catchpoint String"
},
{
"description": "When set to `true`, catchup will only be used to initialize the node. This means it will only run a fast catchup that advances the round by at least 1 million rounds.",
"description": "Specify a number of blocks which the ledger must be advanced by in order to start the catchup. This is useful for simplifying tools which support fast catchup, they can run the catchup unconditionally and the node will skip the catchup if it is not needed.",
"in": "query",
"name": "initialize",
"schema": {
"type": "boolean"
"type": "integer"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions daemon/algod/api/server/v2/generated/model/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions daemon/algod/api/server/v2/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ const MaxTealSourceBytes = 200_000
// become quite large, so we allow up to 1MB
const MaxTealDryrunBytes = 1_000_000

// MinRoundsToInitialize is the minimum number of rounds that a catchup must
// advance the node in order for it to be considered an initializing event.
const MinRoundsToInitialize = 1_000_000

// WaitForBlockTimeout is the timeout for the WaitForBlock endpoint.
var WaitForBlockTimeout = 1 * time.Minute

Expand Down Expand Up @@ -1397,16 +1393,16 @@ func (v2 *Handlers) getPendingTransactions(ctx echo.Context, max *uint64, format
}

// startCatchup Given a catchpoint, it starts catching up to this catchpoint
func (v2 *Handlers) startCatchup(ctx echo.Context, catchpoint string, initializeOnly bool) error {
func (v2 *Handlers) startCatchup(ctx echo.Context, catchpoint string, initializeRounds uint64) error {
catchpointRound, _, err := ledgercore.ParseCatchpointLabel(catchpoint)
if err != nil {
return badRequest(ctx, err, errFailedToParseCatchpoint, v2.Log)
}

if initializeOnly {
if initializeRounds > 0 {
ledgerRound := v2.Node.LedgerForAPI().Latest()
if catchpointRound < (ledgerRound + MinRoundsToInitialize) {
v2.Log.Infof("Skipping catchup. Catchpoint round %d is not %d rounds ahead of the current round %d so it is not considered an initializing event.", catchpointRound, MinRoundsToInitialize, ledgerRound)
if catchpointRound < (ledgerRound + basics.Round(initializeRounds)) {
v2.Log.Infof("Skipping catchup. Catchpoint round %d is not %d rounds ahead of the current round %d so it is not considered an initializing event.", catchpointRound, initializeRounds, ledgerRound)
return ctx.JSON(http.StatusOK, model.CatchpointStartResponse{
CatchupMessage: errCatchpointWouldNotInitialize,
})
Expand Down
18 changes: 10 additions & 8 deletions daemon/algod/api/server/v2/test/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1308,10 +1308,10 @@ func TestSimulateTransactionMultipleGroups(t *testing.T) {
}

func startCatchupTest(t *testing.T, catchpoint string, nodeError error, expectedCode int) {
startCatchupTestFull(t, catchpoint, nodeError, expectedCode, false, "")
startCatchupTestFull(t, catchpoint, nodeError, expectedCode, 0, "")
}

func startCatchupTestFull(t *testing.T, catchpoint string, nodeError error, expectedCode int, initOnly bool, response string) {
func startCatchupTestFull(t *testing.T, catchpoint string, nodeError error, expectedCode int, initRounds uint64, response string) {
numAccounts := 1
numTransactions := 1
offlineAccounts := true
Expand All @@ -1325,8 +1325,8 @@ func startCatchupTestFull(t *testing.T, catchpoint string, nodeError error, expe
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
var err error
if initOnly {
err = handler.StartCatchup(c, catchpoint, model.StartCatchupParams{Initialize: &initOnly})
if initRounds != 0 {
err = handler.StartCatchup(c, catchpoint, model.StartCatchupParams{Initialize: &initRounds})
} else {
err = handler.StartCatchup(c, catchpoint, model.StartCatchupParams{})
}
Expand All @@ -1341,11 +1341,13 @@ func TestStartCatchupInit(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

tooSmallCatchpoint := fmt.Sprintf("%d#DVFRZUYHEFKRLK5N6DNJRR4IABEVN2D6H76F3ZSEPIE6MKXMQWQA", v2.MinRoundsToInitialize-1)
startCatchupTestFull(t, tooSmallCatchpoint, nil, 200, true, "the node has already been initialized")
minRoundsToInitialize := uint64(1_000_000)

catchpointOK := fmt.Sprintf("%d#DVFRZUYHEFKRLK5N6DNJRR4IABEVN2D6H76F3ZSEPIE6MKXMQWQA", v2.MinRoundsToInitialize)
startCatchupTestFull(t, catchpointOK, nil, 201, true, catchpointOK)
tooSmallCatchpoint := fmt.Sprintf("%d#DVFRZUYHEFKRLK5N6DNJRR4IABEVN2D6H76F3ZSEPIE6MKXMQWQA", minRoundsToInitialize-1)
startCatchupTestFull(t, tooSmallCatchpoint, nil, 200, minRoundsToInitialize, "the node has already been initialized")

catchpointOK := fmt.Sprintf("%d#DVFRZUYHEFKRLK5N6DNJRR4IABEVN2D6H76F3ZSEPIE6MKXMQWQA", minRoundsToInitialize)
startCatchupTestFull(t, catchpointOK, nil, 201, minRoundsToInitialize, catchpointOK)
}

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

0 comments on commit 6f07de0

Please # to comment.