@@ -12,6 +12,7 @@ import (
12
12
"github.com/sei-protocol/sei-chain/precompiles/wasmd"
13
13
14
14
"github.com/cosmos/cosmos-sdk/baseapp"
15
+ "github.com/cosmos/cosmos-sdk/client"
15
16
sdk "github.com/cosmos/cosmos-sdk/types"
16
17
"github.com/ethereum/go-ethereum/accounts/abi"
17
18
"github.com/ethereum/go-ethereum/common"
@@ -31,6 +32,7 @@ import (
31
32
"github.com/sei-protocol/sei-chain/x/evm/keeper"
32
33
"github.com/sei-protocol/sei-chain/x/evm/state"
33
34
"github.com/sei-protocol/sei-chain/x/evm/types"
35
+ "github.com/sei-protocol/sei-chain/x/evm/types/ethtx"
34
36
abci "github.com/tendermint/tendermint/abci/types"
35
37
rpcclient "github.com/tendermint/tendermint/rpc/client"
36
38
"github.com/tendermint/tendermint/rpc/coretypes"
@@ -48,15 +50,15 @@ type SimulationAPI struct {
48
50
func NewSimulationAPI (
49
51
ctxProvider func (int64 ) sdk.Context ,
50
52
keeper * keeper.Keeper ,
51
- txDecoder sdk. TxDecoder ,
53
+ txConfig client. TxConfig ,
52
54
tmClient rpcclient.Client ,
53
55
config * SimulateConfig ,
54
56
app * baseapp.BaseApp ,
55
57
antehandler sdk.AnteHandler ,
56
58
connectionType ConnectionType ,
57
59
) * SimulationAPI {
58
60
return & SimulationAPI {
59
- backend : NewBackend (ctxProvider , keeper , txDecoder , tmClient , config , app , antehandler ),
61
+ backend : NewBackend (ctxProvider , keeper , txConfig , tmClient , config , app , antehandler ),
60
62
connectionType : connectionType ,
61
63
}
62
64
}
@@ -178,19 +180,19 @@ var _ tracers.Backend = (*Backend)(nil)
178
180
type Backend struct {
179
181
* eth.EthAPIBackend
180
182
ctxProvider func (int64 ) sdk.Context
181
- txDecoder sdk. TxDecoder
183
+ txConfig client. TxConfig
182
184
keeper * keeper.Keeper
183
185
tmClient rpcclient.Client
184
186
config * SimulateConfig
185
187
app * baseapp.BaseApp
186
188
antehandler sdk.AnteHandler
187
189
}
188
190
189
- func NewBackend (ctxProvider func (int64 ) sdk.Context , keeper * keeper.Keeper , txDecoder sdk. TxDecoder , tmClient rpcclient.Client , config * SimulateConfig , app * baseapp.BaseApp , antehandler sdk.AnteHandler ) * Backend {
191
+ func NewBackend (ctxProvider func (int64 ) sdk.Context , keeper * keeper.Keeper , txConfig client. TxConfig , tmClient rpcclient.Client , config * SimulateConfig , app * baseapp.BaseApp , antehandler sdk.AnteHandler ) * Backend {
190
192
return & Backend {
191
193
ctxProvider : ctxProvider ,
192
194
keeper : keeper ,
193
- txDecoder : txDecoder ,
195
+ txConfig : txConfig ,
194
196
tmClient : tmClient ,
195
197
config : config ,
196
198
app : app ,
@@ -224,7 +226,7 @@ func (b *Backend) GetTransaction(ctx context.Context, txHash common.Hash) (tx *e
224
226
}
225
227
txIndex := hexutil .Uint (receipt .TransactionIndex )
226
228
tmTx := block .Block .Txs [int (txIndex )]
227
- tx = getEthTxForTxBz (tmTx , b .txDecoder )
229
+ tx = getEthTxForTxBz (tmTx , b .txConfig . TxDecoder () )
228
230
blockHash = common .BytesToHash (block .Block .Header .Hash ().Bytes ())
229
231
return tx , blockHash , uint64 (txHeight ), uint64 (txIndex ), nil
230
232
}
@@ -262,7 +264,7 @@ func (b Backend) BlockByNumber(ctx context.Context, bn rpc.BlockNumber) (*ethtyp
262
264
}
263
265
var txs []* ethtypes.Transaction
264
266
for i := range blockRes .TxsResults {
265
- decoded , err := b .txDecoder (tmBlock .Block .Txs [i ])
267
+ decoded , err := b .txConfig . TxDecoder () (tmBlock .Block .Txs [i ])
266
268
if err != nil {
267
269
return nil , err
268
270
}
@@ -347,17 +349,11 @@ func (b *Backend) StateAtTransaction(ctx context.Context, block *ethtypes.Block,
347
349
return nil , vm.BlockContext {}, nil , emptyRelease , err
348
350
}
349
351
for idx , tx := range tmBlock .Block .Txs {
350
- sdkTx , err := b .txDecoder (tx )
352
+ sdkTx , err := b .txConfig . TxDecoder () (tx )
351
353
if err != nil {
352
354
panic (err )
353
355
}
354
356
if idx == txIndex {
355
- // Only run antehandlers as Geth will perform the actual execution
356
- newCtx , err := b .antehandler (sdkCtx , sdkTx , false )
357
- if err != nil {
358
- return nil , vm.BlockContext {}, nil , emptyRelease , fmt .Errorf ("transaction failed ante handler due to %s" , err )
359
- }
360
- sdkCtx = newCtx
361
357
var evmMsg * types.MsgEVMTransaction
362
358
if msgs := sdkTx .GetMsgs (); len (msgs ) != 1 {
363
359
return nil , vm.BlockContext {}, nil , emptyRelease , fmt .Errorf ("cannot replay non-EVM transaction %d at block %d" , idx , blockNumber )
@@ -446,6 +442,38 @@ func (b *Backend) GetCustomPrecompiles(h int64) map[common.Address]vm.Precompile
446
442
return b .keeper .CustomPrecompiles (b .ctxProvider (h ))
447
443
}
448
444
445
+ func (b * Backend ) PrepareTx (statedb vm.StateDB , tx * ethtypes.Transaction ) error {
446
+ if noSignatureSet (tx ) {
447
+ // skip ante if no signature is set
448
+ return nil
449
+ }
450
+ typedStateDB := statedb .(* state.DBImpl )
451
+ txData , err := ethtx .NewTxDataFromTx (tx )
452
+ if err != nil {
453
+ return fmt .Errorf ("transaction cannot be converted to TxData due to %s" , err )
454
+ }
455
+ msg , err := types .NewMsgEVMTransaction (txData )
456
+ if err != nil {
457
+ return fmt .Errorf ("transaction cannot be converted to MsgEVMTransaction due to %s" , err )
458
+ }
459
+ tb := b .txConfig .NewTxBuilder ()
460
+ _ = tb .SetMsgs (msg )
461
+ newCtx , err := b .antehandler (typedStateDB .Ctx (), tb .GetTx (), false )
462
+ if err != nil {
463
+ return fmt .Errorf ("transaction failed ante handler due to %s" , err )
464
+ }
465
+ typedStateDB .WithCtx (newCtx )
466
+ return nil
467
+ }
468
+
469
+ func noSignatureSet (tx * ethtypes.Transaction ) bool {
470
+ isBigIntEmpty := func (b * big.Int ) bool {
471
+ return b == nil || b .Cmp (utils .Big0 ) == 0 || b .Cmp (& big.Int {}) == 0
472
+ }
473
+ v , r , s := tx .RawSignatureValues ()
474
+ return isBigIntEmpty (v ) && isBigIntEmpty (r ) && isBigIntEmpty (s )
475
+ }
476
+
449
477
type Engine struct {
450
478
* ethash.Ethash
451
479
ctxProvider func (int64 ) sdk.Context
0 commit comments