Skip to content

Commit

Permalink
Separate tx and key validity for goal account renewpartkey (#3286)
Browse files Browse the repository at this point in the history
Always use currentRound+proto.MaxTxnLife as last valid round for the
transaction when renewing instead of using the partkey validity period.

This fixes #3283
  • Loading branch information
Quentin Kniep authored Dec 15, 2021
1 parent 14e889e commit 8128167
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd/goal/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ var renewParticipationKeyCmd = &cobra.Command{
if roundLastValid <= (currentRound + proto.MaxTxnLife) {
reportErrorf(errLastRoundInvalid, currentRound)
}
txRoundLastValid := currentRound + proto.MaxTxnLife

// Make sure we don't already have a partkey valid for (or after) specified roundLastValid
parts, err := client.ListParticipationKeyFiles()
Expand All @@ -952,25 +953,25 @@ var renewParticipationKeyCmd = &cobra.Command{
}
}

err = generateAndRegisterPartKey(accountAddress, currentRound, roundLastValid, transactionFee, scLeaseBytes(cmd), keyDilution, walletName, dataDir, client)
err = generateAndRegisterPartKey(accountAddress, currentRound, roundLastValid, txRoundLastValid, transactionFee, scLeaseBytes(cmd), keyDilution, walletName, dataDir, client)
if err != nil {
reportErrorf(err.Error())
}
},
}

func generateAndRegisterPartKey(address string, currentRound, lastValidRound uint64, fee uint64, leaseBytes [32]byte, dilution uint64, wallet string, dataDir string, client libgoal.Client) error {
func generateAndRegisterPartKey(address string, currentRound, keyLastValidRound, txLastValidRound uint64, fee uint64, leaseBytes [32]byte, dilution uint64, wallet string, dataDir string, client libgoal.Client) error {
// Generate a participation keys database and install it
part, keyPath, err := client.GenParticipationKeysTo(address, currentRound, lastValidRound, dilution, "")
part, keyPath, err := client.GenParticipationKeysTo(address, currentRound, keyLastValidRound, dilution, "")
if err != nil {
return fmt.Errorf(errorRequestFail, err)
}
fmt.Printf(" Generated participation key for %s (Valid %d - %d)\n", address, currentRound, lastValidRound)
fmt.Printf(" Generated participation key for %s (Valid %d - %d)\n", address, currentRound, keyLastValidRound)

// Now register it as our new online participation key
goOnline := true
txFile := ""
err = changeAccountOnlineStatus(address, &part, goOnline, txFile, wallet, currentRound, lastValidRound, fee, leaseBytes, dataDir, client)
err = changeAccountOnlineStatus(address, &part, goOnline, txFile, wallet, currentRound, txLastValidRound, fee, leaseBytes, dataDir, client)
if err != nil {
os.Remove(keyPath)
fmt.Fprintf(os.Stderr, " Error registering keys - deleting newly-generated key file: %s\n", keyPath)
Expand Down Expand Up @@ -1027,6 +1028,7 @@ func renewPartKeysInDir(dataDir string, lastValidRound uint64, fee uint64, lease
if lastValidRound <= (currentRound + proto.MaxTxnLife) {
return fmt.Errorf(errLastRoundInvalid, currentRound)
}
txLastValidRound := currentRound + proto.MaxTxnLife

var anyErrors bool

Expand All @@ -1046,7 +1048,7 @@ func renewPartKeysInDir(dataDir string, lastValidRound uint64, fee uint64, lease
}

address := renewPart.Address().String()
err = generateAndRegisterPartKey(address, currentRound, lastValidRound, fee, leaseBytes, dilution, wallet, dataDir, client)
err = generateAndRegisterPartKey(address, currentRound, lastValidRound, txLastValidRound, fee, leaseBytes, dilution, wallet, dataDir, client)
if err != nil {
fmt.Fprintf(os.Stderr, " Error renewing part key for account %s: %v\n", address, err)
anyErrors = true
Expand Down

0 comments on commit 8128167

Please sign in to comment.