Skip to content

Commit

Permalink
feat: fetch min gas price from params (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Dec 17, 2024
1 parent fa58737 commit 03c2dae
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/config/init/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func InitializeRollappConfig(
}

// TODO: refactor
as, err := genesisutils.GetGenesisAppState(initConfig.Home)
as, err := genesisutils.GetAppStateFromGenesisFile(initConfig.Home)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
DefaultFee = 2000000000000000000 // 2
DefaultTxFee = 10000000000000000 // 0.01
MinOperationalAmount = "5000000000000000000" // 5, is checked on every rollapp process interaction ( start, restart )
DefaultMinGasPrice = "2000000000"
)

var InternalBinsDir = fmt.Sprintf("%s/roller_bins", binsDir)
Expand Down
2 changes: 1 addition & 1 deletion cmd/relayer/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func getDrsVersionFromGenesis(
return "", err
}

as, err := genesis.GetDrsVersionFromGenesis(home)
as, err := genesis.GetAppStateFromGenesisFile(home)
if err != nil {
pterm.Error.Println("failed to get genesis app state: ", err)
return "", err
Expand Down
9 changes: 0 additions & 9 deletions cmd/rollapp/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,4 @@ func PrintInitOutput(
fmt.Println()
}
keys.PrintAddressesWithTitle(addresses)

if rollappConfig.HubData.ID != consts.MockHubID {
pterm.DefaultSection.WithIndentCharacter("🔔").
Println("Please fund the addresses below to register and run the rollapp.")
fa := initconfig.FormatAddresses(rollappConfig, addresses)
for _, v := range fa {
v.Print(keys.WithName())
}
}
}
21 changes: 20 additions & 1 deletion sequencer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"strings"

toml "github.com/pelletier/go-toml"
"github.com/pterm/pterm"

"github.com/dymensionxyz/roller/cmd/consts"
datalayer "github.com/dymensionxyz/roller/data_layer"
"github.com/dymensionxyz/roller/data_layer/celestia"
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"github.com/dymensionxyz/roller/utils/genesis"
"github.com/dymensionxyz/roller/utils/roller"
"github.com/dymensionxyz/roller/utils/sequencer"
)
Expand Down Expand Up @@ -97,7 +99,24 @@ func SetAppConfig(rlpCfg roller.RollappConfig) error {
return fmt.Errorf("failed to load %s: %v", appConfigFilePath, err)
}

appCfg.Set("minimum-gas-prices", "2000000000"+rlpCfg.BaseDenom)
as, err := genesis.GetAppStateFromGenesisFile(rlpCfg.Home)
if err != nil {
return err
}

var minimumGasPrice string
if as.FeeMarket != nil && as.FeeMarket.Params != nil && as.FeeMarket.Params.MinGasPrice != "" {
pterm.Info.Println("applying feemarket gas price")
minimumGasPrice = as.FeeMarket.Params.MinGasPrice
} else if len(as.RollappParams.Params.MinGasPrices) > 0 {
pterm.Info.Println("applying rollappparam gas price")
minimumGasPrice = as.RollappParams.Params.MinGasPrices[0].Amount.String()
} else {
pterm.Info.Println("applying default gas price")
minimumGasPrice = consts.DefaultMinGasPrice
}

appCfg.Set("minimum-gas-prices", fmt.Sprintf("%s%s", minimumGasPrice, rlpCfg.BaseDenom))
appCfg.Set("gas-adjustment", 1.3)
appCfg.Set("api.enable", true)
appCfg.Set("api.enabled-unsafe-cors", true)
Expand Down
29 changes: 26 additions & 3 deletions utils/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/cometbft/cometbft/types"
comettypes "github.com/cometbft/cometbft/types"
cosmossdktypes "github.com/cosmos/cosmos-sdk/types"
"github.com/pterm/pterm"

"github.com/dymensionxyz/roller/cmd/consts"
Expand All @@ -28,6 +29,21 @@ import (
type AppState struct {
Bank Bank `json:"bank"`
RollappParams RollappParams `json:"rollappparams"`
FeeMarket *FeeMarket `json:"feemarket"`
}

type FeeMarket struct {
Params *FeeMarketParams `json:"params"`
}

type FeeMarketParams struct {
BaseFee string `json:"base_fee"`
BaseFeeChangeDenominator int `json:"base_fee_change_denominator"`
ElasticityMultiplier int `json:"elasticity_multiplier"`
EnableHeight string `json:"enable_height"`
MinGasMultiplier string `json:"min_gas_multiplier"`
MinGasPrice string `json:"min_gas_price"`
NoBaseFee bool `json:"no_base_fee"`
}

type Bank struct {
Expand All @@ -36,8 +52,9 @@ type Bank struct {

type RollappParams struct {
Params struct {
Da string `json:"da"`
DrsVersion int `json:"drs_version"`
Da string `json:"da"`
DrsVersion int `json:"drs_version"`
MinGasPrices cosmossdktypes.DecCoins `json:"min_gas_prices"`
} `json:"params"`
}

Expand All @@ -59,6 +76,9 @@ func DownloadGenesis(home, genesisUrl string) error {
return nil
}

// GetGenesisAppState function retrieves the genesis file content using comet's
// native function, the problem here is that it takes time due to json.rawMessage
// for the app state itself
func GetGenesisAppState(home string) (*AppState, error) {
genesis, err := comettypes.GenesisDocFromFile(GetGenesisFilePath(home))
if err != nil {
Expand All @@ -75,7 +95,10 @@ func GetGenesisAppState(home string) (*AppState, error) {
return &as, err
}

func GetDrsVersionFromGenesis(home string) (*AppState, error) {
// GetAppStateFromGenesisFile function is a more minimalistic version of
// GetGenesisAppState, it only retrieves the relevant genesis information
// by unmarshalling bytes into the custom struct
func GetAppStateFromGenesisFile(home string) (*AppState, error) {
genesisFile, err := os.Open(GetGenesisFilePath(home))
if err != nil {
return nil, fmt.Errorf("error opening file: %v", err)
Expand Down

0 comments on commit 03c2dae

Please sign in to comment.