Skip to content

Commit

Permalink
feat(thorchain): v50 support, update bank's genesis supply when addin…
Browse files Browse the repository at this point in the history
…g bond module balance (#1267)
  • Loading branch information
misko9 authored Sep 25, 2024
1 parent cea56bb commit 84fb92b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
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
File renamed without changes.
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.

0 comments on commit 84fb92b

Please sign in to comment.