Skip to content

Commit

Permalink
Merge pull request #6162 from tasosbit/fnet3
Browse files Browse the repository at this point in the history
FNet3 proto
  • Loading branch information
cce authored Nov 8, 2024
2 parents a04f326 + fdec56b commit edd2ff6
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 13 deletions.
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 @@ import (

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 @@ var newWalletCmd = &cobra.Command{
}
}

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

// Confirm the password
fmt.Printf(infoPasswordConfirmation)
passwordConfirmation := ensurePassword()
if noPassword {
reportInfoln(infoSkipPassword)
} else {
// Fetch a password for the wallet
fmt.Printf(infoChoosePasswordPrompt, walletName)
walletPassword = ensurePassword()

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

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

// Create the wallet
Expand All @@ -134,7 +143,7 @@ var newWalletCmd = &cobra.Command{
}
reportInfof(infoCreatedWallet, walletName)

if !recoverWallet {
if !recoverWallet && !noPassword {
// Offer to print backup seed
fmt.Printf(infoBackupExplanation)
resp, err := reader.ReadString('\n')
Expand Down Expand Up @@ -200,6 +209,53 @@ var listWalletsCmd = &cobra.Command{
},
}

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()

client := ensureKmdClient(dataDir)

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

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

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

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

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

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

walletPassword := []byte{}

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

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

reportInfof(infoRenamedWallet, walletName, newWalletName)
},
}

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 @@ func (c *Client) CreateWallet(name []byte, password []byte, mdk crypto.MasterDer
return []byte(resp.Wallet.ID), nil
}

// RenameWallet renames a kmd wallet
func (c *Client) RenameWallet(wid []byte, name []byte, password []byte) error {
// Pull the list of all wallets from kmd
kmd, err := c.ensureKmdClient()
if err != nil {
return err
}

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

if err != nil {
return err
}

return nil
}

// 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

0 comments on commit edd2ff6

Please sign in to comment.