Skip to content

Commit

Permalink
Add initialize option to 'goal node catchup'.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Sep 25, 2023
1 parent 17871a3 commit 1d6ad73
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
62 changes: 35 additions & 27 deletions cmd/goal/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var newNodeFullConfig bool
var watchMillisecond uint64
var abortCatchup bool
var fastCatchupForce bool
var initializeCatchup uint64

const catchpointURL = "https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/%s/latest.catchpoint"

Expand Down Expand Up @@ -116,6 +117,7 @@ func init() {

catchupCmd.Flags().BoolVarP(&abortCatchup, "abort", "x", false, "Aborts the current catchup process")
catchupCmd.Flags().BoolVar(&fastCatchupForce, "force", false, "Forces fast catchup with implicit catchpoint to start without a consent prompt")
catchupCmd.Flags().Uint64VarP(&initializeCatchup, "initialize", "i", 0, "Catchup only if the catchpoint would advance the node by at least the specified number of rounds")

}

Expand Down Expand Up @@ -161,9 +163,24 @@ var catchupCmd = &cobra.Command{
Example: "goal node catchup 6500000#1234567890ABCDEF01234567890ABCDEF0\tStart catching up to round 6500000 with the provided catchpoint\ngoal node catchup --abort\t\t\t\t\tAbort the current catchup",
Args: catchpointCmdArgument,
Run: func(cmd *cobra.Command, args []string) {
var catchpoint string
// assume first positional parameter is the catchpoint
if len(args) != 0 {
catchpoint = args[0]
}
datadir.OnDataDirs(func(dataDir string) {
if !abortCatchup && len(args) == 0 {
client := ensureAlgodClient(dataDir)
client := ensureAlgodClient(dataDir)

if abortCatchup {
err := client.AbortCatchup()
if err != nil {
reportErrorf(errorNodeStatus, err)
}
return
}

// lookup missing catchpoint
if catchpoint == "" {
vers, err := client.AlgodVersions()
if err != nil {
reportErrorf(errorNodeStatus, err)
Expand All @@ -174,18 +191,24 @@ var catchupCmd = &cobra.Command{
if err != nil {
reportErrorf(errorCatchpointLabelMissing, errorUnableToLookupCatchpointLabel, err.Error())
}
args = append(args, label)
if !fastCatchupForce {
fmt.Printf(nodeConfirmImplicitCatchpoint, label)
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
text = strings.Replace(text, "\n", "", -1)
if text != "yes" {
reportErrorf(errorAbortedPerUserRequest)
}
catchpoint = label
}

if !fastCatchupForce {
fmt.Printf(nodeConfirmImplicitCatchpoint, catchpoint)
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
text = strings.Replace(text, "\n", "", -1)
if text != "yes" {
reportErrorf(errorAbortedPerUserRequest)
}
}
catchup(dataDir, args)

resp, err := client.Catchup(catchpoint, initializeCatchup)
if err != nil {
reportErrorf(errorNodeStatus, err)
}
reportInfof("node response: %s", resp.CatchupMessage)
})
},
}
Expand Down Expand Up @@ -718,21 +741,6 @@ var createCmd = &cobra.Command{
},
}

func catchup(dataDir string, args []string) {
client := ensureAlgodClient(datadir.EnsureSingleDataDir())
if abortCatchup {
err := client.AbortCatchup()
if err != nil {
reportErrorf(errorNodeStatus, err)
}
return
}
err := client.Catchup(args[0])
if err != nil {
reportErrorf(errorNodeStatus, err)
}
}

// verifyPeerDialArg verifies that the peers provided in peerDial are valid peers.
func verifyPeerDialArg() bool {
if peerDial == "" {
Expand Down
8 changes: 6 additions & 2 deletions daemon/algod/api/client/restClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ type accountInformationParams struct {
Exclude string `url:"exclude"`
}

type catchupParams struct {
Initialize uint64 `url:"initialize"`
}

// PendingTransactionsByAddr returns all the pending transactions for an addr.
func (client RestClient) PendingTransactionsByAddr(addr string, max uint64) (response model.PendingTransactionsResponse, err error) {
err = client.get(&response, fmt.Sprintf("/v2/accounts/%s/transactions/pending", addr), pendingTransactionsByAddrParams{max})
Expand Down Expand Up @@ -575,8 +579,8 @@ func (client RestClient) AbortCatchup(catchpointLabel string) (response model.Ca
}

// Catchup start catching up to the give catchpoint label
func (client RestClient) Catchup(catchpointLabel string) (response model.CatchpointStartResponse, err error) {
err = client.submitForm(&response, fmt.Sprintf("/v2/catchup/%s", catchpointLabel), nil, nil, "POST", false, true, false)
func (client RestClient) Catchup(catchpointLabel string, initializeRounds uint64) (response model.CatchpointStartResponse, err error) {
err = client.submitForm(&response, fmt.Sprintf("/v2/catchup/%s", catchpointLabel), catchupParams{Initialize: initializeRounds}, nil, "POST", false, true, false)
return
}

Expand Down
10 changes: 3 additions & 7 deletions libgoal/libgoal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,16 +1131,12 @@ func (c *Client) AbortCatchup() error {
}

// Catchup start catching up to the give catchpoint label.
func (c *Client) Catchup(catchpointLabel string) error {
func (c *Client) Catchup(catchpointLabel string, initialize uint64) (model.CatchpointStartResponse, error) {
algod, err := c.ensureAlgodClient()
if err != nil {
return err
return model.CatchpointStartResponse{}, err
}
_, err = algod.Catchup(catchpointLabel)
if err != nil {
return err
}
return nil
return algod.Catchup(catchpointLabel, initialize)
}

const defaultAppIdx = 1380011588
Expand Down

0 comments on commit 1d6ad73

Please sign in to comment.