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

feat(thorchain): v50 support, update bank's genesis supply when adding bond module balance #1267

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions chain/thorchain/thornode.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
libclient "github.com/cometbft/cometbft/rpc/jsonrpc/client"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -357,7 +358,7 @@ func (tn *ChainNode) SetTestConfig(ctx context.Context) error {

// Enable public REST API
api["enable"] = true
api["swagger"] = false
api["swagger"] = true
api["address"] = "tcp://0.0.0.0:1317"
api["enabled-unsafe-cors"] = true

Expand Down Expand Up @@ -721,13 +722,13 @@ EOF

stdout, _, err := tn.Exec(ctx, command, tn.Chain.Config().Env)
if err != nil {
return err
return fmt.Errorf("create key sdtout:\n%s\n, error: %w", string(stdout), err)
}

if tn.Validator && tn.ValidatorMnemonic == "" {
var createKeyOutput map[string]string
if err := json.Unmarshal(stdout, &createKeyOutput); err != nil {
return err
return fmt.Errorf("unmarshal create key sdtout:\n%s\n, error: %w", string(stdout), err)
}

tn.ValidatorMnemonic = createKeyOutput["mnemonic"]
Expand Down Expand Up @@ -1071,7 +1072,7 @@ func (tn *ChainNode) AddBondModule(ctx context.Context) error {
Coins: []CoinBalance{
{
Denom: "rune",
Amount: fmt.Sprintf("%d0000000000000", tn.Chain.(*Thorchain).NumValidators),
Amount: fmt.Sprintf("%d00000000", tn.Chain.(*Thorchain).NumValidators),
},
},
}
Expand All @@ -1095,6 +1096,45 @@ func (tn *ChainNode) AddBondModule(ctx context.Context) error {
}
}

// Now update bank's supply with new balance if on v50
if tn.IsAboveSDK47(ctx) {
bankSupplyPath := "app_state.bank.supply"
splitPath = strings.Split(bankSupplyPath, ".")
path = make([]interface{}, len(splitPath))
for i, component := range splitPath {
if v, err := strconv.Atoi(component); err == nil {
path[i] = v
} else {
path[i] = component
}
}
supplyI, err := dyno.GetSlice(g, path...)
if err != nil {
return fmt.Errorf("failed to get key %s in genesis json", bankSupplyPath)
}

for i, coinI := range supplyI {
coin := coinI.(map[string]interface{})
if coin["denom"].(string) == "rune" {
originalAmount, ok := sdkmath.NewIntFromString(coin["amount"].(string))
if !ok {
return fmt.Errorf("failed to convert bank's supply of rune to sdk Int from string")
}
addAmount, ok := sdkmath.NewIntFromString(bondBalance.Coins[0].Amount)
if !ok {
return fmt.Errorf("failed to convert bond amount of rune to sdk Int from string")
}
coin["amount"] = originalAmount.Add(addAmount).String()
supplyI[i] = coin
break
}
}

if err := dyno.Set(g, supplyI, path...); err != nil {
return fmt.Errorf("failed to set bank's new supply")
}
}

genbz, err = json.Marshal(g)
if err != nil {
return fmt.Errorf("failed to marshal genesis bytes to json: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func ThorchainDefaultChainSpec(testName string, numVals int, numFn int, ethRoute
name := common.THORChain.String() // Must use this name for test
chainImage := ibc.NewDockerImage("thorchain", "local", "1025:1025")
genesisKVMods := []thorchain.GenesisKV{
thorchain.NewGenesisKV("app_state.bank.params.default_send_enabled", false), // disable bank module transfers
thorchain.NewGenesisKV("app_state.bank.params.default_send_enabled", true), // disable bank module transfers
thorchain.NewGenesisKV("app_state.thorchain.reserve", "22000000000000000"), // mint to reserve for mocknet (220M)
thorchain.NewGenesisKV("app_state.thorchain.chain_contracts", []ChainContract{
{
Expand Down
File renamed without changes.
File renamed without changes.
Loading