-
Notifications
You must be signed in to change notification settings - Fork 266
refactor(cmd/testnetify): add multi-account support #2012
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,12 +41,13 @@ type ConsAddress struct { | |
| } | ||
|
|
||
| type TestnetValidator struct { | ||
| Moniker string `json:"moniker"` | ||
| Operator AccAddress `json:"operator"` | ||
| Bonded bool `json:"bonded"` | ||
| Commission stakingtypes.Commission `json:"commission"` | ||
| MinSelfDelegation sdk.Int `json:"min_self_delegation"` | ||
| Home string `json:"home"` | ||
| Moniker string `json:"moniker"` | ||
| Operator AccAddress `json:"operator"` | ||
| Status stakingtypes.BondStatus `json:"status"` | ||
| Commission stakingtypes.Commission `json:"commission"` | ||
| MinSelfDelegation sdk.Int `json:"min_self_delegation"` | ||
| Home string `json:"home"` | ||
| Delegations []akash.TestnetDelegation `json:"delegations"` | ||
|
|
||
| privValidator *pvm.FilePV | ||
| pubKey crypto.PubKey | ||
|
|
@@ -59,7 +60,7 @@ type TestnetValidators []TestnetValidator | |
| type TestnetConfig struct { | ||
| ChainID string `json:"chain_id"` | ||
| Validators TestnetValidators `json:"validators"` | ||
| Accounts []sdk.AccAddress `json:"accounts"` | ||
| Accounts []akash.TestnetAccount `json:"accounts"` | ||
| Gov akash.TestnetGovConfig `json:"gov"` | ||
|
Comment on lines
+63
to
64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bech32 JSON parsing gap for Accounts/Delegations (sdk.AccAddress). cfg.Accounts uses app.TestnetAccount, which has sdk.AccAddress. Without a custom UnmarshalJSON, JSON expects base64, not bech32. Same for Delegations’ Address field. This will confuse users and likely break config loading. Two viable fixes (pick one):
I can draft the UnmarshalJSON implementations in app/testnet.go if you prefer. Would you like that? 🤖 Prompt for AI Agents |
||
| upgrade akash.TestnetUpgrade | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ package testnetify | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||
| "bufio" | ||||||||||||||||||||||||||||||||||||||||||
| "encoding/hex" | ||||||||||||||||||||||||||||||||||||||||||
| "encoding/json" | ||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||
| "io" | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -13,6 +14,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| "github.com/cosmos/cosmos-sdk/client" | ||||||||||||||||||||||||||||||||||||||||||
| "github.com/cosmos/cosmos-sdk/client/flags" | ||||||||||||||||||||||||||||||||||||||||||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||||||||||||||||||||||||||||||||||||||||||
| "github.com/spf13/cobra" | ||||||||||||||||||||||||||||||||||||||||||
| "github.com/tendermint/tendermint/crypto/tmhash" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -29,6 +31,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||||
| "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" | ||||||||||||||||||||||||||||||||||||||||||
| sdksrv "github.com/cosmos/cosmos-sdk/server" | ||||||||||||||||||||||||||||||||||||||||||
| "github.com/cosmos/cosmos-sdk/server/types" | ||||||||||||||||||||||||||||||||||||||||||
| sdktypes "github.com/cosmos/cosmos-sdk/types" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| akash "github.com/akash-network/node/app" | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -114,6 +117,17 @@ you want to test the upgrade handler itself. | |||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| for i, acc := range cfg.Accounts { | ||||||||||||||||||||||||||||||||||||||||||
| if len(acc.Balances) > 0 { | ||||||||||||||||||||||||||||||||||||||||||
| cfg.Accounts[i].Balances = sdk.NewCoins(acc.Balances...) | ||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||
| cfg.Accounts[i].Balances = sdk.NewCoins( | ||||||||||||||||||||||||||||||||||||||||||
| sdk.NewInt64Coin("uakt", 10000000000000), | ||||||||||||||||||||||||||||||||||||||||||
| sdk.NewInt64Coin("ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84", 1000000000000), // axlUSDC | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+120
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix type mismatch when assigning balances. cfg.Accounts[i].Balances is []sdk.Coin, while sdk.NewCoins(...) returns sdk.Coins. Use an explicit conversion to avoid compile-time type errors. Apply this diff: for i, acc := range cfg.Accounts {
if len(acc.Balances) > 0 {
- cfg.Accounts[i].Balances = sdk.NewCoins(acc.Balances...)
+ cfg.Accounts[i].Balances = []sdk.Coin(sdk.NewCoins(acc.Balances...))
} else {
- cfg.Accounts[i].Balances = sdk.NewCoins(
- sdk.NewInt64Coin("uakt", 1000000000000),
- sdk.NewInt64Coin("ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84", 1000000000000), // axlUSDC
- )
+ cfg.Accounts[i].Balances = []sdk.Coin(sdk.NewCoins(
+ sdk.NewInt64Coin("uakt", 1000000000000),
+ sdk.NewInt64Coin("ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84", 1000000000000), // axlUSDC
+ ))
}
}Optional: standardize on sdk.Coins in TestnetAccount to avoid future conversions. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| sctx.Logger.Info(fmt.Sprintf("loaded config from %s", cfgFilePath)) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if name, _ := cmd.Flags().GetString(KeyTestnetTriggerUpgrade); name != "" { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -296,7 +310,7 @@ func testnetify(sctx *sdksrv.Context, tcfg TestnetConfig, testnetAppCreator type | |||||||||||||||||||||||||||||||||||||||||
| return nil, node.ErrSaveGenesisDocHash{Err: err} | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| state, stateStore, _, err := node.LoadStateFromDBOrGenesisDocProvider(stateDB, genDocProvider, "") | ||||||||||||||||||||||||||||||||||||||||||
| state, stateStore, _, err := node.LoadStateFromDBOrGenesisDocProvider(stateDB, genDocProvider, hex.EncodeToString(updatedChecksum)) | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -346,6 +360,8 @@ func testnetify(sctx *sdksrv.Context, tcfg TestnetConfig, testnetAppCreator type | |||||||||||||||||||||||||||||||||||||||||
| Moniker: val.Moniker, | ||||||||||||||||||||||||||||||||||||||||||
| Commission: val.Commission, | ||||||||||||||||||||||||||||||||||||||||||
| MinSelfDelegation: val.MinSelfDelegation, | ||||||||||||||||||||||||||||||||||||||||||
| Status: val.Status, | ||||||||||||||||||||||||||||||||||||||||||
| Delegations: val.Delegations, | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| tcfg.Validators[i].privValidator = privValidator | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -447,15 +463,20 @@ func testnetify(sctx *sdksrv.Context, tcfg TestnetConfig, testnetAppCreator type | |||||||||||||||||||||||||||||||||||||||||
| Signature: voteProto.Signature, | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| var vp int64 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| for _, del := range val.Delegations { | ||||||||||||||||||||||||||||||||||||||||||
| vp += del.Amount.Amount.Quo(sdktypes.DefaultPowerReduction).Int64() | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| newValidators = append(newValidators, &cmttypes.Validator{ | ||||||||||||||||||||||||||||||||||||||||||
| Address: val.validatorAddress, | ||||||||||||||||||||||||||||||||||||||||||
| PubKey: val.pubKey, | ||||||||||||||||||||||||||||||||||||||||||
| VotingPower: 900000000000000, | ||||||||||||||||||||||||||||||||||||||||||
| VotingPower: vp, | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
472
to
475
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make VotingPower conversion int64‑safe (avoid overflow/negative). Tokens may exceed int64 or be negative; clamp or normalize before assigning to Validator.VotingPower. Apply this diff (and add @@
- newValidators = append(newValidators, &cmttypes.Validator{
- Address: val.validatorAddress,
- PubKey: val.pubKey,
- VotingPower: val.Tokens.Int64(),
- })
+ // Ensure int64-safe voting power
+ var vp int64
+ if val.Tokens.IsNegative() {
+ vp = 0
+ } else if val.Tokens.BigInt().BitLen() >= 63 {
+ vp = math.MaxInt64
+ } else {
+ vp = val.Tokens.Int64()
+ }
+ newValidators = append(newValidators, &cmttypes.Validator{
+ Address: val.validatorAddress,
+ PubKey: val.pubKey,
+ VotingPower: vp,
+ })
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // Replace all valSets in state to be the valSet with just our validator. | ||||||||||||||||||||||||||||||||||||||||||
| // and set the very first validator as proposer | ||||||||||||||||||||||||||||||||||||||||||
| // and set the very first validator as a proposer | ||||||||||||||||||||||||||||||||||||||||||
| newValSet := &cmttypes.ValidatorSet{ | ||||||||||||||||||||||||||||||||||||||||||
| Validators: newValidators, | ||||||||||||||||||||||||||||||||||||||||||
| Proposer: newValidators[0], | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use sdk.Coins for Balances to match bank APIs.
Bank.MintCoins/SendCoinsFromModuleToAccount accept sdk.Coins. Using []sdk.Coin here causes friction and type mismatches elsewhere.
type TestnetAccount struct { Address sdk.AccAddress `json:"address"` - Balances []sdk.Coin `json:"balances"` + Balances sdk.Coins `json:"balances"` }📝 Committable suggestion