Skip to content

Commit 8f8db4d

Browse files
authored
Merge pull request #28 from 0glabs/handle_ws_new_txn
save suggestion gas price in memory
2 parents c133a46 + 4ac18da commit 8f8db4d

8 files changed

Lines changed: 59 additions & 59 deletions

File tree

app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ type EthermintApp struct {
248248

249249
// Ethermint keepers
250250
EvmKeeper *evmkeeper.Keeper
251-
FeeMarketKeeper feemarketkeeper.Keeper
251+
FeeMarketKeeper *feemarketkeeper.Keeper
252252

253253
// the module manager
254254
mm *module.Manager

x/feemarket/genesis.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
// InitGenesis initializes genesis state based on exported genesis
2828
func InitGenesis(
2929
ctx sdk.Context,
30-
k keeper.Keeper,
30+
k *keeper.Keeper,
3131
data types.GenesisState,
3232
) []abci.ValidatorUpdate {
3333
err := k.SetParams(ctx, data.Params)
@@ -41,7 +41,7 @@ func InitGenesis(
4141
}
4242

4343
// ExportGenesis exports genesis state of the fee market module
44-
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
44+
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *types.GenesisState {
4545
return &types.GenesisState{
4646
Params: k.GetParams(ctx),
4747
BlockGas: k.GetBlockGasWanted(ctx),

x/feemarket/keeper/abci.go

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (k *Keeper) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) { //nolint:
102102
k.foundSuggestionGasPrice(ctx)
103103
}
104104

105-
func (k Keeper) foundSuggestionGasPrice(ctx sdk.Context) {
105+
func (k *Keeper) foundSuggestionGasPrice(ctx sdk.Context) {
106106
logger := k.Logger(ctx)
107107
var maxBlockGas uint64
108108
if b := ctx.ConsensusParams().Block; b != nil {
@@ -153,30 +153,37 @@ func (k Keeper) foundSuggestionGasPrice(ctx sdk.Context) {
153153
}
154154
}
155155
}
156-
} else {
157-
// ignore multisig case now
158-
if fee, ok := memTx.(sdk.FeeTx); ok {
159-
if len(sigs) == 1 {
160-
signer := sdk.AccAddress(sigs[0].PubKey.Address()).String()
161-
162-
if _, exists := txnInfoMap[signer]; !exists {
163-
txnInfoMap[signer] = make([]*txnInfo, 0, 16)
164-
}
165-
166-
evmGasPrice, err := utilCosmosDemonGasPriceToEvmDemonGasPrice(fee.GetFee())
167-
168-
if err == nil {
169-
txnInfoMap[signer] = append(txnInfoMap[signer], &txnInfo{
170-
gasPrice: evmGasPrice,
171-
gasLimit: utilCosmosDemonGasLimitToEvmDemonGasLimit(fee.GetGas()),
172-
nonce: sigs[0].Sequence,
173-
sender: signer,
174-
})
175-
}
176-
}
177-
} else {
178-
logger.Error("unknown type of memTx: ", "type", reflect.TypeOf(memTx))
179-
}
156+
// ignore cosmos txn case now
157+
// } else {
158+
// // ignore multisig case now
159+
// if fee, ok := memTx.(sdk.FeeTx); ok {
160+
// feeCoins := fee.GetFee()
161+
// if len(feeCoins) != 0 {
162+
// if len(sigs) == 1 {
163+
// signer := sdk.AccAddress(sigs[0].PubKey.Address()).String()
164+
165+
// if _, exists := txnInfoMap[signer]; !exists {
166+
// txnInfoMap[signer] = make([]*txnInfo, 0, 16)
167+
// }
168+
169+
// gasPrice := sdk.NewDecCoinsFromCoins(fee.GetFee()...).QuoDec(math.LegacyNewDec(int64(fee.GetGas())))
170+
171+
// evmGasPrice, err := utilCosmosDemonGasPriceToEvmDemonGasPrice(gasPrice)
172+
// evmGasLimit := utilCosmosDemonGasLimitToEvmDemonGasLimit(fee.GetGas())
173+
174+
// if err == nil {
175+
// txnInfoMap[signer] = append(txnInfoMap[signer], &txnInfo{
176+
// gasPrice: evmGasPrice,
177+
// gasLimit: evmGasLimit,
178+
// nonce: sigs[0].Sequence,
179+
// sender: signer,
180+
// })
181+
// }
182+
// }
183+
// }
184+
// } else {
185+
// logger.Error("unknown type of memTx: ", "type", reflect.TypeOf(memTx))
186+
// }
180187
}
181188

182189
iterator = iterator.Next()
@@ -246,13 +253,12 @@ func (k Keeper) foundSuggestionGasPrice(ctx sdk.Context) {
246253
}
247254
}
248255

249-
func utilCosmosDemonGasPriceToEvmDemonGasPrice(gasGroup sdk.Coins) (*big.Int, error) {
256+
func utilCosmosDemonGasPriceToEvmDemonGasPrice(gasGroup sdk.DecCoins) (*big.Int, error) {
250257
gasPrice := big.NewInt(0)
251258
for _, coin := range gasGroup {
252259
if coin.Denom == GasDenom {
253-
thisGasPrice := big.NewInt(0).SetUint64(coin.Amount.Uint64())
254-
thisGasPrice = thisGasPrice.Mul(thisGasPrice, big.NewInt(0).SetInt64(GasDenomConversionMultiplier))
255-
gasPrice = gasPrice.Add(gasPrice, thisGasPrice)
260+
thisGasPrice := coin.Amount.MulRoundUp(sdk.NewDec(GasDenomConversionMultiplier))
261+
gasPrice = gasPrice.Add(gasPrice, thisGasPrice.TruncateInt().BigInt())
256262
} else {
257263
return big.NewInt(0), fmt.Errorf("invalid denom: %s", coin.Denom)
258264
}

x/feemarket/keeper/grpc_query.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
"github.com/evmos/ethermint/x/feemarket/types"
2525
)
2626

27-
var _ types.QueryServer = Keeper{}
27+
var _ types.QueryServer = &Keeper{}
2828

2929
// Params implements the Query/Params gRPC method
30-
func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
30+
func (k *Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
3131
ctx := sdk.UnwrapSDKContext(c)
3232
params := k.GetParams(ctx)
3333

@@ -37,7 +37,7 @@ func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.Q
3737
}
3838

3939
// BaseFee implements the Query/BaseFee gRPC method
40-
func (k Keeper) BaseFee(c context.Context, _ *types.QueryBaseFeeRequest) (*types.QueryBaseFeeResponse, error) {
40+
func (k *Keeper) BaseFee(c context.Context, _ *types.QueryBaseFeeRequest) (*types.QueryBaseFeeResponse, error) {
4141
ctx := sdk.UnwrapSDKContext(c)
4242

4343
res := &types.QueryBaseFeeResponse{}
@@ -52,7 +52,7 @@ func (k Keeper) BaseFee(c context.Context, _ *types.QueryBaseFeeRequest) (*types
5252
}
5353

5454
// BlockGas implements the Query/BlockGas gRPC method
55-
func (k Keeper) BlockGas(c context.Context, _ *types.QueryBlockGasRequest) (*types.QueryBlockGasResponse, error) {
55+
func (k *Keeper) BlockGas(c context.Context, _ *types.QueryBlockGasRequest) (*types.QueryBlockGasResponse, error) {
5656
ctx := sdk.UnwrapSDKContext(c)
5757
gas := k.GetBlockGasWanted(ctx)
5858

@@ -61,7 +61,7 @@ func (k Keeper) BlockGas(c context.Context, _ *types.QueryBlockGasRequest) (*typ
6161
}, nil
6262
}
6363

64-
func (k Keeper) SuggestionGasPrice(c context.Context, _ *types.QuerySuggestionGasPriceRequest) (*types.QuerySuggestionGasPriceResponse, error) {
64+
func (k *Keeper) SuggestionGasPrice(c context.Context, _ *types.QuerySuggestionGasPriceRequest) (*types.QuerySuggestionGasPriceResponse, error) {
6565
ctx := sdk.UnwrapSDKContext(c)
6666
gas := k.GetSuggestionGasPrice(ctx)
6767

x/feemarket/keeper/keeper.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func NewKeeper(
5555
storeKey, transientKey storetypes.StoreKey,
5656
ss paramstypes.Subspace,
5757
mempool mempool.Mempool,
58-
) Keeper {
58+
) *Keeper {
5959
// ensure authority account is correctly formatted
6060
if err := sdk.VerifyAddressFormat(authority); err != nil {
6161
panic(err)
@@ -65,7 +65,7 @@ func NewKeeper(
6565
ss = ss.WithKeyTable(types.ParamKeyTable())
6666
}
6767

68-
return Keeper{
68+
return &Keeper{
6969
cdc: cdc,
7070
storeKey: storeKey,
7171
authority: authority,
@@ -141,18 +141,14 @@ func (k Keeper) GetBaseFeeV1(ctx sdk.Context) *big.Int {
141141
return new(big.Int).SetBytes(bz)
142142
}
143143

144-
func (k Keeper) SetSuggestionGasPrice(ctx sdk.Context, gas *big.Int) {
145-
store := ctx.KVStore(k.storeKey)
146-
gasBz := gas.Bytes()
147-
store.Set(types.KeyPrefixSuggestionGasPrice, gasBz)
144+
func (k *Keeper) SetSuggestionGasPrice(ctx sdk.Context, gas *big.Int) {
145+
logger := k.Logger(ctx)
146+
k.suggestionGasPrice = big.NewInt(0).Set(gas)
147+
logger.Debug("set suggestion gas price: ", "value", k.suggestionGasPrice.String())
148148
}
149149

150-
func (k Keeper) GetSuggestionGasPrice(ctx sdk.Context) *big.Int {
151-
store := ctx.KVStore(k.storeKey)
152-
bz := store.Get(types.KeyPrefixSuggestionGasPrice)
153-
if len(bz) == 0 {
154-
return big.NewInt(0)
155-
}
156-
157-
return new(big.Int).SetBytes(bz)
150+
func (k *Keeper) GetSuggestionGasPrice(ctx sdk.Context) *big.Int {
151+
logger := k.Logger(ctx)
152+
logger.Debug("get suggestion gas price: ", "value", k.suggestionGasPrice.String())
153+
return k.suggestionGasPrice
158154
}

x/feemarket/keeper/migrations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import (
2323

2424
// Migrator is a struct for handling in-place store migrations.
2525
type Migrator struct {
26-
keeper Keeper
26+
keeper *Keeper
2727
legacySubspace types.Subspace
2828
}
2929

3030
// NewMigrator returns a new Migrator.
31-
func NewMigrator(keeper Keeper, legacySubspace types.Subspace) Migrator {
31+
func NewMigrator(keeper *Keeper, legacySubspace types.Subspace) Migrator {
3232
return Migrator{
3333
keeper: keeper,
3434
legacySubspace: legacySubspace,

x/feemarket/module.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry)
111111
// AppModule implements an application module for the fee market module.
112112
type AppModule struct {
113113
AppModuleBasic
114-
keeper keeper.Keeper
114+
keeper *keeper.Keeper
115115
// legacySubspace is used solely for migration of x/params managed parameters
116116
legacySubspace types.Subspace
117117
}
118118

119119
// NewAppModule creates a new AppModule object
120-
func NewAppModule(k keeper.Keeper, ss types.Subspace) AppModule {
120+
func NewAppModule(k *keeper.Keeper, ss types.Subspace) AppModule {
121121
return AppModule{
122122
AppModuleBasic: AppModuleBasic{},
123123
keeper: k,
@@ -138,7 +138,7 @@ func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
138138
// module-specific GRPC queries and handle the upgrade store migration for the module.
139139
func (am AppModule) RegisterServices(cfg module.Configurator) {
140140
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
141-
types.RegisterMsgServer(cfg.MsgServer(), &am.keeper)
141+
types.RegisterMsgServer(cfg.MsgServer(), am.keeper)
142142

143143
m := keeper.NewMigrator(am.keeper, am.legacySubspace)
144144
if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {

x/feemarket/types/keys.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const (
3535
const (
3636
prefixBlockGasWanted = iota + 1
3737
deprecatedPrefixBaseFee // unused
38-
prefixSuggestionGasPrice
3938
)
4039

4140
const (
@@ -44,8 +43,7 @@ const (
4443

4544
// KVStore key prefixes
4645
var (
47-
KeyPrefixBlockGasWanted = []byte{prefixBlockGasWanted}
48-
KeyPrefixSuggestionGasPrice = []byte{prefixSuggestionGasPrice}
46+
KeyPrefixBlockGasWanted = []byte{prefixBlockGasWanted}
4947
)
5048

5149
// Transient Store key prefixes

0 commit comments

Comments
 (0)