Skip to content

Commit 7209273

Browse files
authored
Merge pull request #2 from oraichain/feat/move-test-prepare-v050
Feat/move test prepare v050
2 parents 5fe3251 + 8ccfa31 commit 7209273

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3011
-613
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.swl
66
*.swm
77
*.swn
8+
*.txt
89
.vscode
910
.idea
1011

@@ -46,4 +47,4 @@ dependency-graph.png
4647
*.out
4748
*.synctex.gz
4849

49-
.oraid
50+
.oraid

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ifeq ($(OS),Windows_NT)
8383
$(error oraid server not supported. Use "make build-windows-client" for client)
8484
exit 1
8585
else
86-
go build -mod=readonly $(BUILD_FLAGS) -o build/oraid ./cmd/wasmd
86+
go build -mod=readonly $(BUILD_FLAGS) -o build/oraid ./cmd/wasmd && mv build/oraid $(GOPATH)/bin/oraid
8787
endif
8888

8989
build-windows-client: go.sum

app/ante.go

+33-19
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,51 @@ import (
1010
"cosmossdk.io/log"
1111
circuitante "cosmossdk.io/x/circuit/ante"
1212
circuitkeeper "cosmossdk.io/x/circuit/keeper"
13+
globalfeekeeper "github.com/CosmosContracts/juno/v18/x/globalfee/keeper"
1314
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
1415
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
1516
"github.com/cosmos/ibc-go/v8/modules/core/keeper"
1617

1718
sdk "github.com/cosmos/cosmos-sdk/types"
1819
"github.com/cosmos/cosmos-sdk/x/auth/ante"
20+
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
1921

2022
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
2123
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
2224

2325
"github.com/cosmos/cosmos-sdk/types/tx/signing"
2426

2527
storetypes "cosmossdk.io/store/types"
28+
globalfeeante "github.com/CosmosContracts/juno/v18/x/globalfee/ante"
2629
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
2730
evmante "github.com/evmos/ethermint/app/ante"
2831
"github.com/evmos/ethermint/crypto/ethsecp256k1"
2932
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
30-
emvtypes "github.com/evmos/ethermint/x/evm/types"
33+
evmtypes "github.com/evmos/ethermint/x/evm/types"
3134
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
3235
)
3336

37+
const maxBypassMinFeeMsgGasUsage = 1_000_000
38+
3439
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
3540
// channel keeper.
3641
type HandlerOptions struct {
3742
ante.HandlerOptions
38-
AccountKeeper emvtypes.AccountKeeper
43+
AccountKeeper evmtypes.AccountKeeper
3944
IBCKeeper *keeper.Keeper
4045
EvmKeeper *evmkeeper.Keeper
46+
GlobalFeeKeeper globalfeekeeper.Keeper
47+
StakingKeeper stakingkeeper.Keeper
4148
FeeMarketKeeper feemarketkeeper.Keeper
4249
WasmConfig *wasmTypes.WasmConfig
4350
WasmKeeper *wasmkeeper.Keeper
4451
TXCounterStoreService corestoretypes.KVStoreService
4552
TxCounterStoreKey storetypes.StoreKey
4653
MaxTxGasWanted uint64
4754
CircuitKeeper *circuitkeeper.Keeper
55+
BankKeeper evmtypes.BankKeeper
56+
DisabledAuthzMsgs []string
57+
BypassMinFeeMsgTypes []string
4858
}
4959

5060
func (options *HandlerOptions) Validate() error {
@@ -103,9 +113,19 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
103113
anteHandler = newEthAnteHandler(options)
104114
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
105115
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
106-
anteHandler = newCosmosAnteHandler(cosmosHandlerOptions{
107-
HandlerOptions: options,
108-
isEIP712: true,
116+
anteHandler = evmante.NewLegacyCosmosAnteHandlerEip712(evmante.HandlerOptions{
117+
AccountKeeper: options.AccountKeeper,
118+
BankKeeper: options.BankKeeper,
119+
SignModeHandler: options.SignModeHandler,
120+
FeegrantKeeper: options.FeegrantKeeper,
121+
SigGasConsumer: options.SigGasConsumer,
122+
IBCKeeper: options.IBCKeeper,
123+
EvmKeeper: options.EvmKeeper,
124+
FeeMarketKeeper: options.FeeMarketKeeper,
125+
MaxTxGasWanted: options.MaxTxGasWanted,
126+
ExtensionOptionChecker: options.ExtensionOptionChecker,
127+
TxFeeChecker: options.TxFeeChecker,
128+
DisabledAuthzMsgs: options.DisabledAuthzMsgs,
109129
})
110130
default:
111131
return ctx, errorsmod.Wrapf(
@@ -121,10 +141,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
121141
// handle as totally normal Cosmos SDK tx
122142
switch tx.(type) {
123143
case sdk.Tx:
124-
anteHandler = newCosmosAnteHandler(cosmosHandlerOptions{
125-
HandlerOptions: options,
126-
isEIP712: false,
127-
})
144+
anteHandler = newCosmosAnteHandler(options)
128145
default:
129146
return ctx, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx)
130147
}
@@ -133,16 +150,10 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
133150
}, nil
134151
}
135152

136-
// cosmosHandlerOptions extends HandlerOptions to provide some Cosmos specific configurations
137-
type cosmosHandlerOptions struct {
138-
HandlerOptions
139-
isEIP712 bool
140-
}
141-
142153
// NewAnteHandler returns an AnteHandler that checks and increments sequence
143154
// numbers, checks signatures & account numbers, and deducts fees from the first
144155
// signer.
145-
func newCosmosAnteHandler(options cosmosHandlerOptions) sdk.AnteHandler {
156+
func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
146157

147158
var sigGasConsumer = options.SigGasConsumer
148159
if sigGasConsumer == nil {
@@ -161,8 +172,11 @@ func newCosmosAnteHandler(options cosmosHandlerOptions) sdk.AnteHandler {
161172
ante.NewTxTimeoutHeightDecorator(),
162173
ante.NewValidateMemoDecorator(options.AccountKeeper),
163174
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
164-
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
165-
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
175+
// nil so that it only checks with the min gas price of the chain, not the custom fee checker. For cosmos messages, the default tx fee checker is enough
176+
globalfeeante.NewFeeDecorator(options.BypassMinFeeMsgTypes, options.GlobalFeeKeeper, options.StakingKeeper, maxBypassMinFeeMsgGasUsage),
177+
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, nil),
178+
// we use evmante.NewSetPubKeyDecorator so that for eth_secp256k1 accs, we can validate the signer using the evm-cosmos mapping logic
179+
evmante.NewSetPubKeyDecorator(options.AccountKeeper, options.EvmKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
166180
ante.NewValidateSigCountDecorator(options.AccountKeeper),
167181
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
168182
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
@@ -182,7 +196,7 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
182196
evmante.NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper),
183197
evmante.NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted),
184198
evmante.NewCanTransferDecorator(options.EvmKeeper),
185-
evmante.NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator.
199+
evmante.NewEthIncrementSenderSequenceDecorator(options.AccountKeeper, options.EvmKeeper), // innermost AnteDecorator.
186200
)
187201
}
188202

app/app.go

+43-12
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import (
4848
"github.com/cosmos/cosmos-sdk/server/api"
4949
"github.com/cosmos/cosmos-sdk/server/config"
5050
servertypes "github.com/cosmos/cosmos-sdk/server/types"
51-
"github.com/cosmos/cosmos-sdk/std"
5251
sdk "github.com/cosmos/cosmos-sdk/types"
5352
"github.com/cosmos/cosmos-sdk/types/module"
5453
"github.com/cosmos/cosmos-sdk/types/msgservice"
@@ -153,7 +152,9 @@ import (
153152

154153
simappparams "cosmossdk.io/simapp/params"
155154
evmv1 "github.com/evmos/ethermint/api/ethermint/evm/v1"
155+
evmante "github.com/evmos/ethermint/app/ante"
156156
"github.com/evmos/ethermint/ethereum/eip712"
157+
etherminttypes "github.com/evmos/ethermint/types"
157158
"github.com/evmos/ethermint/x/evm"
158159
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
159160
evmtypes "github.com/evmos/ethermint/x/evm/types"
@@ -163,9 +164,15 @@ import (
163164
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
164165
protov2 "google.golang.org/protobuf/proto"
165166

167+
appconfig "github.com/CosmWasm/wasmd/cmd/config"
168+
enccodec "github.com/evmos/ethermint/encoding/codec"
166169
"github.com/evmos/ethermint/x/erc20"
167170
erc20keeper "github.com/evmos/ethermint/x/erc20/keeper"
168171
erc20types "github.com/evmos/ethermint/x/erc20/types"
172+
173+
"github.com/CosmosContracts/juno/v18/x/globalfee"
174+
globalfeekeeper "github.com/CosmosContracts/juno/v18/x/globalfee/keeper"
175+
globalfeetypes "github.com/CosmosContracts/juno/v18/x/globalfee/types"
169176
)
170177

171178
const appName = "WasmApp"
@@ -285,6 +292,7 @@ type WasmApp struct {
285292
EvmKeeper *evmkeeper.Keeper
286293
Erc20Keeper erc20keeper.Keeper
287294
FeeMarketKeeper feemarketkeeper.Keeper
295+
GlobalFeeKeeper globalfeekeeper.Keeper
288296

289297
// Middleware wrapper
290298
Ics20WasmHooks *ibchooks.WasmHooks
@@ -347,10 +355,6 @@ func NewWasmApp(
347355

348356
eip712.SetEncodingConfig(encodingConfig)
349357

350-
std.RegisterLegacyAminoCodec(legacyAmino)
351-
std.RegisterInterfaces(interfaceRegistry)
352-
clockkeeper.RegisterProposalTypes()
353-
354358
// Below we could construct and set an application specific mempool and
355359
// ABCI 1.0 PrepareProposal and ProcessProposal handlers. These defaults are
356360
// already set in the SDK's BaseApp, this shows an example of how to override
@@ -399,7 +403,7 @@ func NewWasmApp(
399403
// non sdk store keys
400404
capabilitytypes.StoreKey, ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey,
401405
wasmtypes.StoreKey, icahosttypes.StoreKey,
402-
icacontrollertypes.StoreKey, clocktypes.StoreKey, ibchookstypes.StoreKey, packetforwardtypes.StoreKey, tokenfactorytypes.StoreKey,
406+
icacontrollertypes.StoreKey, clocktypes.StoreKey, globalfeetypes.StoreKey, ibchookstypes.StoreKey, packetforwardtypes.StoreKey, tokenfactorytypes.StoreKey,
403407
evmtypes.StoreKey, feemarkettypes.StoreKey, erc20types.StoreKey,
404408
)
405409

@@ -607,9 +611,10 @@ func NewWasmApp(
607611

608612
evmSs := app.GetSubspace(evmtypes.ModuleName)
609613
tracer := cast.ToString(appOpts.Get(srvflags.EVMTracer))
614+
evmBankKeeper := evmkeeper.NewEvmBankKeeperWithDenoms(app.BankKeeper, app.AccountKeeper, appconfig.EvmDenom, appconfig.CosmosDenom)
610615
app.EvmKeeper = evmkeeper.NewKeeper(
611616
appCodec, runtime.NewKVStoreService(keys[evmtypes.StoreKey]), tkeys[evmtypes.TransientKey], Authority,
612-
app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper,
617+
app.AccountKeeper, evmBankKeeper, app.StakingKeeper, app.FeeMarketKeeper,
613618
nil, geth.NewEVM, tracer, evmSs,
614619
)
615620

@@ -626,7 +631,6 @@ func NewWasmApp(
626631
govRouter := govv1beta1.NewRouter()
627632
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
628633
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
629-
AddRoute(clocktypes.RouterKey, clockkeeper.NewClockProposalHandler(app.ClockKeeper)).
630634
AddRoute(erc20types.RouterKey, erc20.NewErc20ProposalHandler(&app.Erc20Keeper))
631635
govConfig := govtypes.DefaultConfig()
632636
/*
@@ -754,6 +758,7 @@ func NewWasmApp(
754758
}
755759

756760
wasmOpts = append(bindings.RegisterCustomPlugins(&app.BankKeeper, &app.TokenFactoryKeeper), wasmOpts...)
761+
wasmOpts = append(RegisterStargateQueries(*bApp.GRPCQueryRouter(), appCodec), wasmOpts...)
757762

758763
// The last arguments can contain custom message handlers, and custom query handlers,
759764
// if we want to allow any custom callbacks
@@ -783,6 +788,13 @@ func NewWasmApp(
783788
app.keys[clocktypes.StoreKey],
784789
appCodec,
785790
*app.ContractKeeper,
791+
AuthorityAddr,
792+
)
793+
794+
app.GlobalFeeKeeper = globalfeekeeper.NewKeeper(
795+
appCodec,
796+
app.keys[globalfeetypes.StoreKey],
797+
AuthorityAddr,
786798
)
787799

788800
app.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper(
@@ -883,6 +895,7 @@ func NewWasmApp(
883895
// sdk
884896
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
885897
clock.NewAppModule(appCodec, app.ClockKeeper),
898+
globalfee.NewAppModule(appCodec, app.GlobalFeeKeeper),
886899
ibchooks.NewAppModule(app.AccountKeeper),
887900
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)),
888901
tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
@@ -912,9 +925,13 @@ func NewWasmApp(
912925
evmtypes.ModuleName: evm.AppModuleBasic{},
913926
feemarkettypes.ModuleName: feemarket.AppModuleBasic{},
914927
erc20types.ModuleName: erc20.AppModuleBasic{},
928+
globalfee.ModuleName: globalfee.AppModuleBasic{},
915929
})
916930
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
917931
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
932+
enccodec.RegisterLegacyAminoCodec(legacyAmino)
933+
enccodec.RegisterInterfaces(interfaceRegistry)
934+
clocktypes.RegisterInterfaces(interfaceRegistry)
918935

919936
// NOTE: upgrade module is required to be prioritized
920937
app.ModuleManager.SetOrderPreBlockers(
@@ -943,6 +960,7 @@ func NewWasmApp(
943960
clocktypes.ModuleName,
944961
ibchookstypes.ModuleName,
945962
packetforwardtypes.ModuleName,
963+
globalfee.ModuleName,
946964
tokenfactorytypes.ModuleName,
947965
feemarkettypes.ModuleName,
948966
evmtypes.ModuleName,
@@ -966,6 +984,7 @@ func NewWasmApp(
966984
clocktypes.ModuleName,
967985
ibchookstypes.ModuleName,
968986
packetforwardtypes.ModuleName,
987+
globalfee.ModuleName,
969988
tokenfactorytypes.ModuleName,
970989
feemarkettypes.ModuleName,
971990
evmtypes.ModuleName,
@@ -998,6 +1017,7 @@ func NewWasmApp(
9981017
clocktypes.ModuleName,
9991018
ibchookstypes.ModuleName,
10001019
packetforwardtypes.ModuleName,
1020+
globalfee.ModuleName,
10011021
tokenfactorytypes.ModuleName,
10021022
feemarkettypes.ModuleName,
10031023
evmtypes.ModuleName,
@@ -1119,19 +1139,29 @@ func (app *WasmApp) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtype
11191139
anteHandler, err := NewAnteHandler(
11201140
HandlerOptions{
11211141
HandlerOptions: ante.HandlerOptions{
1122-
BankKeeper: app.BankKeeper,
1123-
SignModeHandler: txConfig.SignModeHandler(),
1124-
FeegrantKeeper: app.FeeGrantKeeper,
1125-
SigGasConsumer: DefaultSigGasConsumer,
1142+
SignModeHandler: txConfig.SignModeHandler(),
1143+
FeegrantKeeper: app.FeeGrantKeeper,
1144+
SigGasConsumer: DefaultSigGasConsumer,
1145+
ExtensionOptionChecker: etherminttypes.HasDynamicFeeExtensionOption,
1146+
TxFeeChecker: evmante.NewDynamicFeeChecker(app.EvmKeeper),
11261147
},
11271148
AccountKeeper: app.AccountKeeper,
1149+
BankKeeper: app.BankKeeper,
11281150
IBCKeeper: app.IBCKeeper,
11291151
EvmKeeper: app.EvmKeeper,
1152+
StakingKeeper: *app.StakingKeeper,
1153+
GlobalFeeKeeper: app.GlobalFeeKeeper,
11301154
FeeMarketKeeper: app.FeeMarketKeeper,
11311155
WasmConfig: &wasmConfig,
11321156
WasmKeeper: &app.WasmKeeper,
11331157
TXCounterStoreService: runtime.NewKVStoreService(txCounterStoreKey),
11341158
CircuitKeeper: &app.CircuitKeeper,
1159+
DisabledAuthzMsgs: []string{
1160+
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
1161+
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}),
1162+
sdk.MsgTypeURL(&vestingtypes.MsgCreatePermanentLockedAccount{}),
1163+
sdk.MsgTypeURL(&vestingtypes.MsgCreatePeriodicVestingAccount{}),
1164+
},
11351165
},
11361166
)
11371167
if err != nil {
@@ -1382,6 +1412,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
13821412

13831413
paramsKeeper.Subspace(wasmtypes.ModuleName)
13841414
paramsKeeper.Subspace(clocktypes.ModuleName)
1415+
paramsKeeper.Subspace(globalfeetypes.ModuleName)
13851416
paramsKeeper.Subspace(ibchookstypes.ModuleName)
13861417
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
13871418
paramsKeeper.Subspace(tokenfactorytypes.ModuleName)

0 commit comments

Comments
 (0)