@@ -7,14 +7,19 @@ import (
7
7
"encoding/json"
8
8
"fmt"
9
9
"io"
10
+ "math/big"
10
11
"os"
11
12
"path/filepath"
12
13
"strings"
13
14
"sync"
14
15
"time"
15
16
17
+ ethcommon "github.com/ethereum/go-ethereum/common"
18
+ ethhexutil "github.com/ethereum/go-ethereum/common/hexutil"
19
+ ethtypes "github.com/ethereum/go-ethereum/core/types"
16
20
"github.com/ethereum/go-ethereum/ethclient"
17
21
ethrpc "github.com/ethereum/go-ethereum/rpc"
22
+
18
23
"github.com/sei-protocol/sei-chain/app/antedecorators"
19
24
"github.com/sei-protocol/sei-chain/evmrpc"
20
25
"github.com/sei-protocol/sei-chain/precompiles"
@@ -126,6 +131,8 @@ import (
126
131
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
127
132
"github.com/sei-protocol/sei-chain/x/evm/querier"
128
133
"github.com/sei-protocol/sei-chain/x/evm/replay"
134
+ evmtracers "github.com/sei-protocol/sei-chain/x/evm/tracers"
135
+ "github.com/sei-protocol/sei-chain/x/evm/tracing"
129
136
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
130
137
"github.com/spf13/cast"
131
138
abci "github.com/tendermint/tendermint/abci/types"
@@ -375,6 +382,7 @@ type App struct {
375
382
376
383
encodingConfig appparams.EncodingConfig
377
384
evmRPCConfig evmrpc.Config
385
+ evmTracer * tracing.Hooks
378
386
}
379
387
380
388
// New returns a reference to an initialized blockchain app
@@ -622,6 +630,15 @@ func New(
622
630
app .EvmKeeper .EthClient = ethclient .NewClient (rpcclient )
623
631
}
624
632
633
+ if app .evmRPCConfig .LiveEVMTracer != "" {
634
+ chainConfig := evmtypes .DefaultChainConfig ().EthereumConfig (app .EvmKeeper .ChainID ())
635
+ evmTracer , err := evmtracers .NewBlockchainTracer (evmtracers .GlobalLiveTracerRegistry , app .evmRPCConfig .LiveEVMTracer , chainConfig )
636
+ if err != nil {
637
+ panic (fmt .Sprintf ("error creating EVM tracer due to %s" , err ))
638
+ }
639
+ app .evmTracer = evmTracer
640
+ }
641
+
625
642
customDependencyGenerators := aclmapping .NewCustomDependencyGenerator ()
626
643
aclOpts = append (aclOpts , aclkeeper .WithResourceTypeToStoreKeyMap (aclutils .ResourceTypeToStoreKeyMap ))
627
644
aclOpts = append (aclOpts , aclkeeper .WithDependencyGeneratorMappings (customDependencyGenerators .GetCustomDependencyGenerators (app .EvmKeeper )))
@@ -1416,12 +1433,23 @@ func (app *App) ProcessTXsWithOCC(ctx sdk.Context, txs [][]byte, typedTxs []sdk.
1416
1433
wg .Add (1 )
1417
1434
go func (txIndex int , tx []byte ) {
1418
1435
defer wg .Done ()
1436
+
1437
+ var txTracer sdk.TxTracer
1438
+ if app .evmTracer != nil {
1439
+ txTracer = app .evmTracer
1440
+ if app .evmTracer .GetTxTracer != nil {
1441
+ txTracer = app .evmTracer .GetTxTracer (absoluteTxIndices [txIndex ])
1442
+ }
1443
+ }
1444
+
1419
1445
deliverTxEntry := & sdk.DeliverTxEntry {
1420
1446
Request : abci.RequestDeliverTx {Tx : tx },
1421
1447
SdkTx : typedTxs [txIndex ],
1422
1448
Checksum : sha256 .Sum256 (tx ),
1423
1449
AbsoluteIndex : absoluteTxIndices [txIndex ],
1450
+ TxTracer : txTracer ,
1424
1451
}
1452
+
1425
1453
// get prefill estimate
1426
1454
estimatedWritesets , err := app .AccessControlKeeper .GenerateEstimatedWritesets (ctx , app .GetAnteDepGenerator (), txIndex , typedTxs [txIndex ])
1427
1455
// if no error, then we assign the mapped writesets for prefill estimate
@@ -1482,12 +1510,17 @@ func (app *App) BuildDependenciesAndRunTxs(ctx sdk.Context, txs [][]byte, typedT
1482
1510
return app .ProcessBlockSynchronous (ctx , txs , typedTxs , absoluteTxIndices ), ctx
1483
1511
}
1484
1512
1485
- func (app * App ) ProcessBlock (ctx sdk.Context , txs [][]byte , req BlockProcessRequest , lastCommit abci.CommitInfo ) ([]abci.Event , []* abci.ExecTxResult , abci.ResponseEndBlock , error ) {
1513
+ func (app * App ) ProcessBlock (ctx sdk.Context , txs [][]byte , req BlockProcessRequest , lastCommit abci.CommitInfo ) (events []abci.Event , txResults []* abci.ExecTxResult , endBlockResp abci.ResponseEndBlock , err error ) {
1486
1514
ctx = ctx .WithIsOCCEnabled (app .OccEnabled ())
1515
+
1487
1516
goCtx := app .decorateContextWithDexMemState (ctx .Context ())
1488
1517
ctx = ctx .WithContext (goCtx )
1489
1518
1490
- events := []abci.Event {}
1519
+ if app .evmTracer != nil {
1520
+ ctx = evmtracers .SetCtxBlockchainTracer (ctx , app .evmTracer )
1521
+ }
1522
+
1523
+ events = []abci.Event {}
1491
1524
beginBlockReq := abci.RequestBeginBlock {
1492
1525
Hash : req .GetHash (),
1493
1526
ByzantineValidators : utils .Map (req .GetByzantineValidators (), func (mis abci.Misbehavior ) abci.Evidence {
@@ -1512,9 +1545,16 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
1512
1545
beginBlockResp := app .BeginBlock (ctx , beginBlockReq )
1513
1546
events = append (events , beginBlockResp .Events ... )
1514
1547
1515
- txResults : = make ([]* abci.ExecTxResult , len (txs ))
1548
+ txResults = make ([]* abci.ExecTxResult , len (txs ))
1516
1549
typedTxs := app .DecodeTransactionsConcurrently (ctx , txs )
1517
1550
1551
+ if app .evmTracer != nil {
1552
+ header := ctx .BlockHeader ()
1553
+ app .evmTracer .OnSeiBlockStart (req .GetHash (), uint64 (header .Size ()), TmBlockHeaderToEVM (ctx , header , & app .EvmKeeper ))
1554
+ defer func () {
1555
+ app .evmTracer .OnSeiBlockEnd (err )
1556
+ }()
1557
+ }
1518
1558
prioritizedTxs , otherTxs , prioritizedTypedTxs , otherTypedTxs , prioritizedIndices , otherIndices := app .PartitionPrioritizedTxs (ctx , txs , typedTxs )
1519
1559
1520
1560
// run the prioritized txs
@@ -1540,7 +1580,7 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
1540
1580
lazyWriteEvents := app .BankKeeper .WriteDeferredBalances (ctx )
1541
1581
events = append (events , lazyWriteEvents ... )
1542
1582
1543
- endBlockResp : = app .EndBlock (ctx , abci.RequestEndBlock {
1583
+ endBlockResp = app .EndBlock (ctx , abci.RequestEndBlock {
1544
1584
Height : req .GetHeight (),
1545
1585
})
1546
1586
@@ -1851,3 +1891,38 @@ func init() {
1851
1891
// override max wasm size to 2MB
1852
1892
wasmtypes .MaxWasmSize = 2 * 1024 * 1024
1853
1893
}
1894
+
1895
+ func TmBlockHeaderToEVM (
1896
+ ctx sdk.Context ,
1897
+ block tmproto.Header ,
1898
+ k * evmkeeper.Keeper ,
1899
+ ) (header * ethtypes.Header ) {
1900
+ number := big .NewInt (block .Height )
1901
+ lastHash := ethcommon .BytesToHash (block .LastBlockId .Hash )
1902
+ appHash := ethcommon .BytesToHash (block .AppHash )
1903
+ txHash := ethcommon .BytesToHash (block .DataHash )
1904
+ resultHash := ethcommon .BytesToHash (block .LastResultsHash )
1905
+ miner := ethcommon .BytesToAddress (block .ProposerAddress )
1906
+ gasLimit , gasWanted := uint64 (0 ), uint64 (0 )
1907
+
1908
+ header = & ethtypes.Header {
1909
+ Number : number ,
1910
+ ParentHash : lastHash ,
1911
+ Nonce : ethtypes.BlockNonce {}, // inapplicable to Sei
1912
+ MixDigest : ethcommon.Hash {}, // inapplicable to Sei
1913
+ UncleHash : ethtypes .EmptyUncleHash , // inapplicable to Sei
1914
+ Bloom : k .GetBlockBloom (ctx , block .Height ),
1915
+ Root : appHash ,
1916
+ Coinbase : miner ,
1917
+ Difficulty : big .NewInt (0 ), // inapplicable to Sei
1918
+ Extra : ethhexutil.Bytes {}, // inapplicable to Sei
1919
+ GasLimit : gasLimit ,
1920
+ GasUsed : gasWanted ,
1921
+ Time : uint64 (block .Time .Unix ()),
1922
+ TxHash : txHash ,
1923
+ ReceiptHash : resultHash ,
1924
+ BaseFee : k .GetBaseFeePerGas (ctx ).RoundInt ().BigInt (),
1925
+ }
1926
+
1927
+ return
1928
+ }
0 commit comments