Skip to content

Commit

Permalink
feat!: Add support for standard ibc (#614)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Tsitrin <[email protected]>
  • Loading branch information
omritoptix and mtsitrin authored Dec 10, 2023
1 parent 4bd2530 commit 3be9ca6
Show file tree
Hide file tree
Showing 19 changed files with 322 additions and 216 deletions.
2 changes: 1 addition & 1 deletion cmd/config/init/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ var Hubs = map[string]config.HubData{
ID: LocalHubID,
RPC_URL: "http://localhost:36657",
ARCHIVE_RPC_URL: "http://localhost:36657",
GAS_PRICE: "0",
GAS_PRICE: "100000000",
},
}
74 changes: 74 additions & 0 deletions cmd/config/init/denom_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package initconfig

import (
"encoding/json"
"fmt"
"os"
"strings"
)

type BankDenomMetadata struct {
Base string `json:"base"`
DenomUnits []BankDenomUnitMetadata `json:"denom_units"`
Description string `json:"description"`
Display string `json:"display"`
Name string `json:"name"`
Symbol string `json:"symbol"`
}

type BankDenomUnitMetadata struct {
Aliases []string `json:"aliases"`
Denom string `json:"denom"`
Exponent uint `json:"exponent"`
}

func getBankDenomMetadata(denom string, decimals uint) string {
displayDenom := denom[1:]

metadata := []BankDenomMetadata{
{
Base: denom,
DenomUnits: []BankDenomUnitMetadata{
{
Aliases: []string{},
Denom: denom,
Exponent: 0,
},
{
Aliases: []string{},
Denom: displayDenom,
Exponent: decimals,
},
},
Description: fmt.Sprintf("Denom metadata for %s (%s)", displayDenom, denom),
Display: displayDenom,
Name: displayDenom,
Symbol: strings.ToUpper(displayDenom),
},
}

json, err := json.Marshal(metadata)
if err != nil {
return ""
}

return string(json)
}

func createTokenMetadaJSON(metadataPath string, denom string, decimals uint) error {
metadata := getBankDenomMetadata(denom, decimals)
if metadata == "" {
return fmt.Errorf("failed to generate token metadata")
}

file, err := os.Create(metadataPath)
if err != nil {
return err
}
_, err = file.WriteString(metadata)
if err != nil {
return err
}

return nil
}
48 changes: 8 additions & 40 deletions cmd/config/init/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/big"
"os"
"strconv"
"strings"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
Expand Down Expand Up @@ -57,6 +56,12 @@ func initializeRollappGenesis(initConfig config.RollappConfig) error {
if err != nil {
return err
}

err = createTokenMetadaJSON(filepath.Join(RollappConfigDir(initConfig.Home), "tokenmetadata.json"), initConfig.Denom, initConfig.Decimals)
if err != nil {
return err
}

return nil
}

Expand All @@ -70,25 +75,8 @@ type PathValue struct {
Value interface{}
}

type BankDenomMetadata struct {
Base string `json:"base"`
DenomUnits []BankDenomUnitMetadata `json:"denom_units"`
Description string `json:"description"`
Display string `json:"display"`
Name string `json:"name"`
Symbol string `json:"symbol"`
}

type BankDenomUnitMetadata struct {
Aliases []string `json:"aliases"`
Denom string `json:"denom"`
Exponent uint `json:"exponent"`
}

// TODO(#130): fix to support epochs
func getDefaultGenesisParams(denom string, decimals uint) []PathValue {
displayDenom := denom[1:]

return []PathValue{
{"app_state.mint.params.mint_denom", denom},
{"app_state.staking.params.bond_denom", denom},
Expand All @@ -101,27 +89,7 @@ func getDefaultGenesisParams(denom string, decimals uint) []PathValue {
{"app_state.distribution.params.community_tax", "0.00002"},
{"app_state.gov.voting_params.voting_period", "300s"},
{"app_state.staking.params.unbonding_time", "3628800s"},
{"app_state.bank.denom_metadata", []BankDenomMetadata{
{
Base: denom,
DenomUnits: []BankDenomUnitMetadata{
{
Aliases: []string{},
Denom: denom,
Exponent: 0,
},
{
Aliases: []string{},
Denom: displayDenom,
Exponent: decimals,
},
},
Description: fmt.Sprintf("Denom metadata for %s (%s)", displayDenom, denom),
Display: displayDenom,
Name: displayDenom,
Symbol: strings.ToUpper(displayDenom),
},
}},
{"app_state.bank.denom_metadata", getBankDenomMetadata(denom, decimals)},
}
}

Expand Down Expand Up @@ -171,7 +139,7 @@ func generateGenesisTx(initConfig config.RollappConfig) error {
func registerSequencerAsGoverner(initConfig config.RollappConfig) error {
totalSupply, err := strconv.Atoi(initConfig.TokenSupply)
if err != nil {
return fmt.Errorf("Error converting string to integer: %w", err)
return fmt.Errorf("error converting string to integer: %w", err)
}
// Convert to token supply with decimals
stakedSupply := big.NewInt(int64(totalSupply / totalSupplyToStakingRatio))
Expand Down
32 changes: 15 additions & 17 deletions cmd/config/init/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package initconfig

import (
"encoding/json"
"github.com/dymensionxyz/roller/relayer"
"os"
"os/exec"
"path/filepath"

"github.com/dymensionxyz/roller/relayer"

"github.com/dymensionxyz/roller/config"

"github.com/dymensionxyz/roller/cmd/consts"
Expand All @@ -17,24 +18,23 @@ type RelayerFileChainConfig struct {
Value RelayerFileChainConfigValue `json:"value"`
}
type RelayerFileChainConfigValue struct {
Key string `json:"key"`
ChainID string `json:"chain-id"`
RpcAddr string `json:"rpc-addr"`
AccountPrefix string `json:"account-prefix"`
KeyringBackend string `json:"keyring-backend"`
GasAdjustment float64 `json:"gas-adjustment"`
GasPrices string `json:"gas-prices"`
Debug bool `json:"debug"`
Timeout string `json:"timeout"`
OutputFormat string `json:"output-format"`
SignMode string `json:"sign-mode"`
ClientType string `json:"client-type"`
Key string `json:"key"`
ChainID string `json:"chain-id"`
RpcAddr string `json:"rpc-addr"`
AccountPrefix string `json:"account-prefix"`
KeyringBackend string `json:"keyring-backend"`
GasAdjustment float64 `json:"gas-adjustment"`
GasPrices string `json:"gas-prices"`
Debug bool `json:"debug"`
Timeout string `json:"timeout"`
OutputFormat string `json:"output-format"`
SignMode string `json:"sign-mode"`
ExtraCodecs []string `json:"extra-codecs"`
}

type RelayerChainConfig struct {
ChainConfig relayer.ChainConfig
GasPrices string
ClientType string
KeyName string
}

Expand Down Expand Up @@ -65,7 +65,7 @@ func getRelayerFileChainConfig(relayerChainConfig RelayerChainConfig) RelayerFil
Timeout: "10s",
OutputFormat: "json",
SignMode: "direct",
ClientType: relayerChainConfig.ClientType,
ExtraCodecs: []string{"ethermint"},
},
}
}
Expand All @@ -91,14 +91,12 @@ func addChainsConfig(rollappConfig relayer.ChainConfig, hubConfig relayer.ChainC
relayerRollappConfig := getRelayerFileChainConfig(RelayerChainConfig{
ChainConfig: rollappConfig,
GasPrices: rollappConfig.GasPrices + rollappConfig.Denom,
ClientType: "01-dymint",
KeyName: consts.KeysIds.RollappRelayer,
})

relayerHubConfig := getRelayerFileChainConfig(RelayerChainConfig{
ChainConfig: hubConfig,
GasPrices: hubConfig.GasPrices + hubConfig.Denom,
ClientType: "07-tendermint",
KeyName: consts.KeysIds.HubRelayer,
})

Expand Down
2 changes: 1 addition & 1 deletion cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var Hubs = map[string]config.HubData{
ID: LocalHubID,
RPC_URL: "http://localhost:36657",
ARCHIVE_RPC_URL: "http://localhost:36657",
GAS_PRICE: "0",
GAS_PRICE: "100000000",
},
// TODO: Add mainnet hub data
MainnetHubName: FroopylandHubData,
Expand Down
6 changes: 5 additions & 1 deletion cmd/da-light-client/start/start.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package start

import (
"context"
"errors"
"fmt"

Expand Down Expand Up @@ -52,7 +53,10 @@ func Cmd() *cobra.Command {

logFilePath := utils.GetDALogFilePath(rollappConfig.Home)
LCEndpoint = damanager.GetLightNodeEndpoint()
utils.RunBashCmdAsync(startDALCCmd, printOutput, parseError, utils.WithLogging(logFilePath))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go utils.RunBashCmdAsync(ctx, startDALCCmd, printOutput, parseError, utils.WithLogging(logFilePath))
select {}
},
}

Expand Down
1 change: 1 addition & 0 deletions cmd/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var migrationsRegistry = []VersionMigrator{
&VersionMigratorV0112{},
&VersionMigratorV0113{},
&VersionMigratorV0118{},
&VersionMigratorV1000{},
}

func Cmd() *cobra.Command {
Expand Down
40 changes: 40 additions & 0 deletions cmd/migrate/v1_0_00.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package migrate

import (
"fmt"
"os/exec"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
"github.com/dymensionxyz/roller/relayer"
)

type VersionMigratorV1000 struct{}

func (v *VersionMigratorV1000) ShouldMigrate(prevVersion VersionData) bool {
return prevVersion.Major < 1
}

func (v *VersionMigratorV1000) PerformMigration(rlpCfg config.RollappConfig) error {
fmt.Println("💈 Migrating Rollapp key...")
migrateRollappKeyCmd := exec.Command(consts.Executables.RollappEVM, "keys", "migrate", "--home", rlpCfg.Home+"/relayer/keys/"+rlpCfg.RollappID, "--keyring-backend", "test")
out, err := utils.ExecBashCommandWithStdout(migrateRollappKeyCmd)
if err != nil {
return err
}
fmt.Println(out.String())
fmt.Println("💈 Migrating Hub key...")
migrateHubKeyCmd := exec.Command(consts.Executables.Dymension, "keys", "migrate", "--home", rlpCfg.Home+"/relayer/keys/"+rlpCfg.HubData.ID, "--keyring-backend", "test")
out, err = utils.ExecBashCommandWithStdout(migrateHubKeyCmd)
if err != nil {
return err
}
fmt.Println(out.String())
fmt.Println("💈 Updating relayer configuration to match new relayer key...")
if err := relayer.UpdateRlyConfigValue(rlpCfg, []string{"chains", rlpCfg.RollappID, "value", "extra-codecs"}, []string{"ethermint"}); err != nil {
return err
}
return nil

}
9 changes: 1 addition & 8 deletions cmd/relayer/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,9 @@ func Start() *cobra.Command {
_, err := rly.CreateIBCChannel(override, logFileOption, seq)
utils.PrettifyErrorIfExists(err)
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

updateClientsCmd := rly.GetUpdateClientsCmd()
utils.RunCommandEvery(ctx, updateClientsCmd.Path, updateClientsCmd.Args[1:], 3600, logFileOption)
relayPacketsCmd := rly.GetRelayPacketsCmd()
utils.RunCommandEvery(ctx, relayPacketsCmd.Path, relayPacketsCmd.Args[1:], 5, logFileOption)
relayAcksCmd := rly.GetRelayAcksCmd()
utils.RunCommandEvery(ctx, relayAcksCmd.Path, relayAcksCmd.Args[1:], 5, logFileOption)
go utils.RunBashCmdAsync(ctx, rly.GetStartCmd(), func() {}, func(errMessage string) string { return errMessage }, logFileOption)
fmt.Printf("💈 The relayer is running successfully on you local machine! Channels: src, %s <-> %s, dst",
rly.SrcChannel, rly.DstChannel)

Expand Down
9 changes: 7 additions & 2 deletions cmd/sequencer/start/start.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package sequnecer_start

import (
"context"
"fmt"
"github.com/dymensionxyz/roller/sequencer"
"math/big"
"path/filepath"

"github.com/dymensionxyz/roller/sequencer"

"strings"

"github.com/dymensionxyz/roller/cmd/consts"
Expand Down Expand Up @@ -38,10 +40,13 @@ func StartCmd() *cobra.Command {
utils.PrintInsufficientBalancesIfAny(sequencerInsufficientAddrs, rollappConfig)
seq := sequencer.GetInstance(rollappConfig)
startRollappCmd := seq.GetStartCmd()
utils.RunBashCmdAsync(startRollappCmd, func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go utils.RunBashCmdAsync(ctx, startRollappCmd, func() {
printOutput(rollappConfig)
}, parseError,
utils.WithLogging(utils.GetSequencerLogPath(rollappConfig)))
select {}
},
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/tx/register/bash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
)

func getRegisterRollappCmd(rollappConfig config.RollappConfig) *exec.Cmd {
tokenMetadataPath := filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp, "config", "tokenmetadata.json")
cmdArgs := []string{
"tx", "rollapp", "create-rollapp", rollappConfig.RollappID, "stamp1", "genesis-path/1", "3", "3", `{"Addresses":[]}`,
"tx", "rollapp", "create-rollapp", rollappConfig.RollappID, "3", `{"Addresses":[]}`, tokenMetadataPath,
}
cmdArgs = append(cmdArgs, getCommonDymdTxFlags(rollappConfig)...)
return exec.Command(
Expand Down
Loading

0 comments on commit 3be9ca6

Please sign in to comment.