Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FNet3 proto #6162

Merged
merged 10 commits into from
Nov 8, 2024
2 changes: 1 addition & 1 deletion buildnumber.dat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
228814
228833
4 changes: 4 additions & 0 deletions cmd/goal/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,24 @@ const (
infoPasswordConfirmation = "Please confirm the password: "
infoCreatingWallet = "Creating wallet..."
infoCreatedWallet = "Created wallet '%s'"
infoSkipPassword = "Skipping password prompt"
infoBackupExplanation = "Your new wallet has a backup phrase that can be used for recovery.\nKeeping this backup phrase safe is extremely important.\nWould you like to see it now? (Y/n): "
infoPrintedBackupPhrase = "Your backup phrase is printed below.\nKeep this information safe -- never share it with anyone!"
infoBackupPhrase = "\n%s"
infoNoWallets = "No wallets found. You can create a wallet with `goal wallet new`"
infoRenamedWallet = "Renamed wallet '%s' to '%s'"
errorCouldntCreateWallet = "Couldn't create wallet: %s"
errorCouldntInitializeWallet = "Couldn't initialize wallet: %s"
errorCouldntExportMDK = "Couldn't export master derivation key: %s"
errorCouldntMakeMnemonic = "Couldn't make mnemonic: %s"
errorCouldntListWallets = "Couldn't list wallets: %s"
errorCouldntFindWallet = "Couldn't find wallet: %s"
errorPasswordConfirmation = "Password confirmation did not match"
errorBadMnemonic = "Problem with mnemonic: %s"
errorBadRecoveredKey = "Recovered invalid key"
errorFailedToReadResponse = "Couldn't read response: %s"
errorFailedToReadPassword = "Couldn't read password: %s"
errorCouldntRenameWallet = "Couldn't rename wallet: %s"

// Commands
infoPasswordPrompt = "Please enter the password for wallet '%s': "
Expand Down
76 changes: 66 additions & 10 deletions cmd/goal/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@

var (
recoverWallet bool
noPassword bool
defaultWalletName string
)

func init() {
walletCmd.AddCommand(newWalletCmd)
walletCmd.AddCommand(listWalletsCmd)
walletCmd.AddCommand(renameWalletCmd)

// Default wallet to use when -w not specified
walletCmd.Flags().StringVarP(&defaultWalletName, "default", "f", "", "Set the wallet with this name to be the default wallet")

// Should we recover the wallet?
newWalletCmd.Flags().BoolVarP(&recoverWallet, "recover", "r", false, "Recover the wallet from the backup mnemonic provided at wallet creation (NOT the mnemonic provided by goal account export or by algokey). Regenerate accounts in the wallet with `goal account new`")
newWalletCmd.Flags().BoolVarP(&noPassword, "non-interactive", "n", false, "Create the new wallet without prompting for password or displaying the seed phrase")
}

var walletCmd = &cobra.Command{
Expand Down Expand Up @@ -113,17 +116,23 @@
}
}

// Fetch a password for the wallet
fmt.Printf(infoChoosePasswordPrompt, walletName)
walletPassword := ensurePassword()
walletPassword := []byte{}

Check warning on line 119 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L119

Added line #L119 was not covered by tests

// Confirm the password
fmt.Printf(infoPasswordConfirmation)
passwordConfirmation := ensurePassword()
if noPassword {
reportInfoln(infoSkipPassword)
} else {

Check warning on line 123 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L121-L123

Added lines #L121 - L123 were not covered by tests
// Fetch a password for the wallet
fmt.Printf(infoChoosePasswordPrompt, walletName)
walletPassword = ensurePassword()

Check warning on line 126 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L125-L126

Added lines #L125 - L126 were not covered by tests

// Check the password confirmation
if !bytes.Equal(walletPassword, passwordConfirmation) {
reportErrorln(errorPasswordConfirmation)
// Confirm the password
fmt.Print(infoPasswordConfirmation)
passwordConfirmation := ensurePassword()

Check warning on line 130 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L129-L130

Added lines #L129 - L130 were not covered by tests

// Check the password confirmation
if !bytes.Equal(walletPassword, passwordConfirmation) {
reportErrorln(errorPasswordConfirmation)

Check warning on line 134 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L133-L134

Added lines #L133 - L134 were not covered by tests
}
}

// Create the wallet
Expand All @@ -134,7 +143,7 @@
}
reportInfof(infoCreatedWallet, walletName)

if !recoverWallet {
if !recoverWallet && !noPassword {

Check warning on line 146 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L146

Added line #L146 was not covered by tests
// Offer to print backup seed
fmt.Printf(infoBackupExplanation)
resp, err := reader.ReadString('\n')
Expand Down Expand Up @@ -200,6 +209,53 @@
},
}

var renameWalletCmd = &cobra.Command{
Use: "rename [wallet name] [new wallet name]",
Short: "Rename wallet",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
dataDir := datadir.EnsureSingleDataDir()

Check warning on line 217 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L216-L217

Added lines #L216 - L217 were not covered by tests

client := ensureKmdClient(dataDir)

Check warning on line 219 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L219

Added line #L219 was not covered by tests

walletName := []byte(args[0])
newWalletName := []byte(args[1])

Check warning on line 222 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L221-L222

Added lines #L221 - L222 were not covered by tests

wid, duplicate, err := client.FindWalletIDByName(walletName)

Check warning on line 224 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L224

Added line #L224 was not covered by tests

if wid == nil {
reportErrorf(errorCouldntFindWallet, string(walletName))

Check warning on line 227 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L226-L227

Added lines #L226 - L227 were not covered by tests
}

if err != nil {
reportErrorf(errorCouldntRenameWallet, err)

Check warning on line 231 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L230-L231

Added lines #L230 - L231 were not covered by tests
}

if duplicate {
reportErrorf(errorCouldntRenameWallet, "Multiple wallets by the same name are not supported")

Check warning on line 235 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L234-L235

Added lines #L234 - L235 were not covered by tests
}

if bytes.Equal(walletName, newWalletName) {
reportErrorf(errorCouldntRenameWallet, "new name is identical to current name")

Check warning on line 239 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L238-L239

Added lines #L238 - L239 were not covered by tests
}

walletPassword := []byte{}

Check warning on line 242 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L242

Added line #L242 was not covered by tests

// if wallet is encrypted, fetch the password
if !client.WalletIsUnencrypted(wid) {
fmt.Printf(infoPasswordPrompt, walletName)
walletPassword = ensurePassword()

Check warning on line 247 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L245-L247

Added lines #L245 - L247 were not covered by tests
}

err = client.RenameWallet(wid, newWalletName, walletPassword)
if err != nil {
reportErrorf(errorCouldntRenameWallet, err)

Check warning on line 252 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L250-L252

Added lines #L250 - L252 were not covered by tests
}

reportInfof(infoRenamedWallet, walletName, newWalletName)

Check warning on line 255 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L255

Added line #L255 was not covered by tests
},
}

func printWallets(dataDir string, wallets []kmdapi.APIV1Wallet) {
accountList := makeAccountsList(dataDir)
defaultWalletID := string(accountList.getDefaultWalletID())
Expand Down
24 changes: 22 additions & 2 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1561,15 +1561,35 @@ func initConsensusProtocols() {

// vFNetX are like vAlphaX but for AF's FNet
// vFnet1
vFnet1 := vFuture
vFnet1 := v39
vFnet1.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{}
vFnet1.LogicSigVersion = 11 // When moving this to a release, put a new higher LogicSigVersion here
vFnet1.Payouts.Enabled = true
vFnet1.Payouts.Percent = 75
vFnet1.Payouts.GoOnlineFee = 2_000_000 // 2 algos
vFnet1.Payouts.MinBalance = 30_000_000_000 // 30,000 algos
vFnet1.Payouts.MaxBalance = 70_000_000_000_000 // 70M algos
vFnet1.Payouts.MaxMarkAbsent = 32
vFnet1.Payouts.ChallengeInterval = 1000
vFnet1.Payouts.ChallengeGracePeriod = 200
vFnet1.Payouts.ChallengeBits = 5
vFnet1.Bonus.BaseAmount = 10_000_000 // 10 Algos
vFnet1.Bonus.DecayInterval = 250_000 // .99^(10.8/0.25) ~ .648. So 35% decay per year
vFnet1.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{}
Consensus[protocol.ConsensusVFnet1] = vFnet1

// vFnet2 guards against a future change in block opcodes that the fnet1 client did not support. No change in parameters
vFnet2 := vFuture
vFnet2 := vFnet1
vFnet2.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{}
Consensus[protocol.ConsensusVFnet2] = vFnet2
vFnet1.ApprovedUpgrades[protocol.ConsensusVFnet2] = 10000

// vFnet3 disabled challenges - without heartbeats, participating accounts are being evicted
vFnet3 := vFnet2
vFnet3.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{}
vFnet3.Payouts.ChallengeInterval = 0
Consensus[protocol.ConsensusVFnet3] = vFnet3
vFnet2.ApprovedUpgrades[protocol.ConsensusVFnet3] = 10000
}

// Global defines global Algorand protocol parameters which should not be overridden.
Expand Down
11 changes: 11 additions & 0 deletions daemon/kmd/client/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ func (kcl KMDClient) CreateWallet(walletName []byte, walletDriverName string, wa
return
}

// RenameWallet wraps kmdapi.APIV1POSTWalletRenameRequest
func (kcl KMDClient) RenameWallet(walletID []byte, newWalletName []byte, walletPassword []byte) (resp kmdapi.APIV1POSTWalletRenameResponse, err error) {
req := kmdapi.APIV1POSTWalletRenameRequest{
WalletID: string(walletID),
NewWalletName: string(newWalletName),
WalletPassword: string(walletPassword),
}
err = kcl.DoV1Request(req, &resp)
return
}

// InitWallet wraps kmdapi.APIV1POSTWalletInitRequest
func (kcl KMDClient) InitWallet(walletID []byte, walletPassword []byte) (resp kmdapi.APIV1POSTWalletInitResponse, err error) {
req := kmdapi.APIV1POSTWalletInitRequest{
Expand Down
18 changes: 18 additions & 0 deletions libgoal/wallets.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@
return []byte(resp.Wallet.ID), nil
}

// RenameWallet renames a kmd wallet
func (c *Client) RenameWallet(wid []byte, name []byte, password []byte) error {

Check warning on line 49 in libgoal/wallets.go

View check run for this annotation

Codecov / codecov/patch

libgoal/wallets.go#L49

Added line #L49 was not covered by tests
// Pull the list of all wallets from kmd
kmd, err := c.ensureKmdClient()
if err != nil {
return err

Check warning on line 53 in libgoal/wallets.go

View check run for this annotation

Codecov / codecov/patch

libgoal/wallets.go#L51-L53

Added lines #L51 - L53 were not covered by tests
}

// Rename the wallet
_, err = kmd.RenameWallet(wid, name, password)

Check warning on line 57 in libgoal/wallets.go

View check run for this annotation

Codecov / codecov/patch

libgoal/wallets.go#L57

Added line #L57 was not covered by tests

if err != nil {
return err

Check warning on line 60 in libgoal/wallets.go

View check run for this annotation

Codecov / codecov/patch

libgoal/wallets.go#L59-L60

Added lines #L59 - L60 were not covered by tests
}

return nil

Check warning on line 63 in libgoal/wallets.go

View check run for this annotation

Codecov / codecov/patch

libgoal/wallets.go#L63

Added line #L63 was not covered by tests
}

// GetWalletHandleToken inits the wallet with the given id, returning a wallet handle token
func (c *Client) GetWalletHandleToken(wid, pw []byte) ([]byte, error) {
kmd, err := c.ensureKmdClient()
Expand Down
3 changes: 3 additions & 0 deletions protocol/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ const ConsensusVFnet1 = ConsensusVersion("fnet1")
// ConsensusVFnet2 uses the same parameters as Future/incentives.
const ConsensusVFnet2 = ConsensusVersion("fnet2")

// ConsensusVFnet3 disables challenges - without heartbeats, participating accounts are being evicted
const ConsensusVFnet3 = ConsensusVersion("fnet3")

// !!! ********************* !!!
// !!! *** Please update ConsensusCurrentVersion when adding new protocol versions *** !!!
// !!! ********************* !!!
Expand Down
Loading