Skip to content

Commit

Permalink
feat: dynamic gas price, keeper implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
piux2 committed Sep 24, 2024
1 parent 9897b66 commit cb8cc2f
Show file tree
Hide file tree
Showing 24 changed files with 939 additions and 108 deletions.
8 changes: 4 additions & 4 deletions gno.land/cmd/gnoland/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@ func generateGenesisFile(genesisFile string, pk crypto.PubKey, c *startCfg) erro
genesisTxs = append(pkgsTxs, genesisTxs...)

// Construct genesis AppState.
gen.AppState = gnoland.GnoGenesisState{
Balances: balances,
Txs: genesisTxs,
}
defaultGenState := gnoland.DefaultGenState()
defaultGenState.Balances = balances
defaultGenState.Txs = genesisTxs
gen.AppState = defaultGenState

// Write genesis state
if err := gen.SaveAs(genesisFile); err != nil {
Expand Down
18 changes: 9 additions & 9 deletions gno.land/pkg/gnoclient/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestCallSingle_Integration(t *testing.T) {

// Make Tx config
baseCfg := BaseTxCfg{
GasFee: ugnot.ValueString(10000),
GasFee: ugnot.ValueString(800000),
GasWanted: 8000000,
AccountNumber: 0,
SequenceNumber: 0,
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestCallMultiple_Integration(t *testing.T) {

// Make Tx config
baseCfg := BaseTxCfg{
GasFee: ugnot.ValueString(10000),
GasFee: ugnot.ValueString(800000),
GasWanted: 8000000,
AccountNumber: 0,
SequenceNumber: 0,
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestSendSingle_Integration(t *testing.T) {

// Make Tx config
baseCfg := BaseTxCfg{
GasFee: ugnot.ValueString(10000),
GasFee: ugnot.ValueString(800000),
GasWanted: 8000000,
AccountNumber: 0,
SequenceNumber: 0,
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestSendMultiple_Integration(t *testing.T) {

// Make Tx config
baseCfg := BaseTxCfg{
GasFee: ugnot.ValueString(10000),
GasFee: ugnot.ValueString(800000),
GasWanted: 8000000,
AccountNumber: 0,
SequenceNumber: 0,
Expand Down Expand Up @@ -290,7 +290,7 @@ func TestRunSingle_Integration(t *testing.T) {

// Make Tx config
baseCfg := BaseTxCfg{
GasFee: ugnot.ValueString(10000),
GasFee: ugnot.ValueString(800000),
GasWanted: 8000000,
AccountNumber: 0,
SequenceNumber: 0,
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestRunMultiple_Integration(t *testing.T) {

// Make Tx config
baseCfg := BaseTxCfg{
GasFee: ugnot.ValueString(10000),
GasFee: ugnot.ValueString(800000),
GasWanted: 8000000,
AccountNumber: 0,
SequenceNumber: 0,
Expand Down Expand Up @@ -451,7 +451,7 @@ func TestAddPackageSingle_Integration(t *testing.T) {

// Make Tx config
baseCfg := BaseTxCfg{
GasFee: ugnot.ValueString(10000),
GasFee: ugnot.ValueString(800000),
GasWanted: 8000000,
AccountNumber: 0,
SequenceNumber: 0,
Expand Down Expand Up @@ -536,7 +536,7 @@ func TestAddPackageMultiple_Integration(t *testing.T) {

// Make Tx config
baseCfg := BaseTxCfg{
GasFee: ugnot.ValueString(10000),
GasFee: ugnot.ValueString(800000),
GasWanted: 8000000,
AccountNumber: 0,
SequenceNumber: 0,
Expand All @@ -556,7 +556,7 @@ func Echo(str string) string {
body2 := `package hello
func Hello(str string) string {
return "Hello " + str + "!"
return "Hello " + str + "!"
}`

caller, err := client.Signer.Info()
Expand Down
34 changes: 30 additions & 4 deletions gno.land/pkg/gnoland/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/gnolang/gno/tm2/pkg/sdk"
"github.com/gnolang/gno/tm2/pkg/sdk/auth"
"github.com/gnolang/gno/tm2/pkg/sdk/bank"
"github.com/gnolang/gno/tm2/pkg/sdk/params"
"github.com/gnolang/gno/tm2/pkg/std"
"github.com/gnolang/gno/tm2/pkg/store"
"github.com/gnolang/gno/tm2/pkg/store/dbadapter"
Expand Down Expand Up @@ -86,14 +87,16 @@ func NewAppWithOptions(cfg *AppOptions) (abci.Application, error) {
baseApp.MountStoreWithDB(baseKey, dbadapter.StoreConstructor, cfg.DB)

// Construct keepers.
acctKpr := auth.NewAccountKeeper(mainKey, ProtoGnoAccount)
paramsKpr := params.NewKeeper(mainKey, nil)
acctKpr := auth.NewAccountKeeper(mainKey, paramsKpr, ProtoGnoAccount)
gpKpr := auth.NewGasPriceKeeper(mainKey)
bankKpr := bank.NewBankKeeper(acctKpr)
vmk := vm.NewVMKeeper(baseKey, mainKey, acctKpr, bankKpr, cfg.MaxCycles)

// Set InitChainer
icc := cfg.InitChainerConfig
icc.baseApp = baseApp
icc.acctKpr, icc.bankKpr, icc.vmKpr = acctKpr, bankKpr, vmk
icc.acctKpr, icc.bankKpr, icc.vmKpr, icc.gpKpr = acctKpr, bankKpr, vmk, gpKpr
baseApp.SetInitChainer(icc.InitChainer)

// Set AnteHandler
Expand All @@ -107,9 +110,11 @@ func NewAppWithOptions(cfg *AppOptions) (abci.Application, error) {
func(ctx sdk.Context, tx std.Tx, simulate bool) (
newCtx sdk.Context, res sdk.Result, abort bool,
) {
// Add last gas price in the context
ctx = ctx.WithValue(auth.GasPriceContextKey{}, gpKpr.LastGasPrice(ctx))

// Override auth params.
ctx = ctx.
WithValue(auth.AuthParamsContextKey{}, auth.DefaultParams())
ctx = ctx.WithValue(auth.AuthParamsContextKey{}, acctKpr.GetParams(ctx))
// Continue on with default auth ante handler.
newCtx, res, abort = authAnteHandler(ctx, tx, simulate)
return
Expand Down Expand Up @@ -140,6 +145,8 @@ func NewAppWithOptions(cfg *AppOptions) (abci.Application, error) {
baseApp.SetEndBlocker(
EndBlocker(
c,
acctKpr,
gpKpr,
vmk,
baseApp,
),
Expand Down Expand Up @@ -229,6 +236,7 @@ type InitChainerConfig struct {
vmKpr vm.VMKeeperI
acctKpr auth.AccountKeeperI
bankKpr bank.BankKeeperI
gpKpr auth.GasPriceKeeperI
}

// InitChainer is the function that can be used as a [sdk.InitChainer].
Expand Down Expand Up @@ -286,6 +294,10 @@ func (cfg InitChainerConfig) loadAppState(ctx sdk.Context, appState any) ([]abci
if !ok {
return nil, fmt.Errorf("invalid AppState of type %T", appState)
}
cfg.acctKpr.InitGenesis(ctx, state.Auth)
params := cfg.acctKpr.GetParams(ctx)
ctx = ctx.WithValue(auth.AuthParamsContextKey{}, params)
auth.InitChainer(ctx, cfg.gpKpr.(auth.GasPriceKeeper), params.InitialGasPrice)

// Parse and set genesis state balances
for _, bal := range state.Balances {
Expand Down Expand Up @@ -335,19 +347,33 @@ type endBlockerApp interface {
// validator set changes
func EndBlocker(
collector *collector[validatorUpdate],
acctKpr auth.AccountKeeperI,
gpKpr auth.GasPriceKeeperI,
vmk vm.VMKeeperI,
app endBlockerApp,
) func(
ctx sdk.Context,
req abci.RequestEndBlock,
) abci.ResponseEndBlock {
return func(ctx sdk.Context, _ abci.RequestEndBlock) abci.ResponseEndBlock {
// set the auth params value in the ctx. The EndBlocker will use InitialGasPrice in
// the params to calculate the updated gas price.
if acctKpr != nil {
ctx = ctx.WithValue(auth.AuthParamsContextKey{}, acctKpr.GetParams(ctx))
}
if acctKpr != nil && gpKpr != nil {
auth.EndBlocker(ctx, gpKpr.(auth.GasPriceKeeper))
}
// Check if there was a valset change
if len(collector.getEvents()) == 0 {
// No valset updates
return abci.ResponseEndBlock{}
}

if vmk == nil {
return abci.ResponseEndBlock{}
}

// Run the VM to get the updates from the chain
response, err := vmk.QueryEval(
ctx,
Expand Down
Loading

0 comments on commit cb8cc2f

Please sign in to comment.