Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firehose EVM tracer addition #1344

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e73963a
Firehose tracer addition
maoueh Apr 10, 2024
aa512a8
Merge tag 'v5.1.2' into release/firehose
maoueh May 2, 2024
e6bdc65
Merge tag 'v5.2.0' into release/firehose
maoueh May 3, 2024
e05ef46
Firehose tracer addition
maoueh Apr 10, 2024
ad9f914
Merge tag 'v5.5.2' into feature/firehose-tracer
maoueh May 27, 2024
16f73c4
Merge branch 'feature/firehose-tracer' into release/firehose
maoueh May 27, 2024
cccdf48
Improved panic handling ensuring we always print a stack trace when F…
maoueh Jun 12, 2024
ab01128
Improved caller reporting when there is an invalid state
maoueh Jun 12, 2024
67bd0af
Fixed bug with system call not correctly wired leading to panics when…
maoueh Jun 12, 2024
8418897
The tracing in `precompiles/bank/bank.go` needs to use `GetEVMAddress…
maoueh Jun 13, 2024
ec72741
Merge tag 'v5.5.5' into feature/firehose-tracer
maoueh Jun 19, 2024
794b793
Merge remote-tracking branch 'origin/main' into feature/firehose-tracer
maoueh Jun 19, 2024
8fafa3d
Merge branch 'main' into feature/firehose-tracer
maoueh Jun 20, 2024
98994b7
Fix seidb default config value for KeepLastVersion
yzang2019 Jul 3, 2024
9612ef1
Fix unit test
yzang2019 Jul 3, 2024
9dd002e
Update go mod
yzang2019 Jul 3, 2024
6bad612
Add upgrade handler for v5.6.2
udpatil Jul 8, 2024
2cc7a28
Merge tag 'v5.6.2' into feature/firehose-tracer-at-latest-release-tag
maoueh Jul 9, 2024
8c44484
Merge branch 'feature/firehose-tracer-at-latest-release-tag' into fea…
maoueh Jul 9, 2024
23c925f
Merge remote-tracking branch 'origin/main' into feature/firehose-tracer
maoueh Jul 9, 2024
e7096af
Fixed a bug on parallel execution
maoueh Jul 9, 2024
ebbaa2e
Fixed missing handling of some system calls when running using the pa…
maoueh Jul 10, 2024
dbd9193
Fixed bug when re-ordering multiple system calls
maoueh Jul 10, 2024
8a8244d
Go mod tidy
maoueh Jul 10, 2024
53cecd5
Merge branch 'feature/firehose-tracer-at-latest-release-tag' into fea…
maoueh Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 79 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@ import (
"encoding/json"
"fmt"
"io"
"math/big"
"net/http"
"os"
"path/filepath"
"strings"
"sync"
"time"

ethcommon "github.com/ethereum/go-ethereum/common"
ethhexutil "github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"

"github.com/ethereum/go-ethereum/ethclient"
ethrpc "github.com/ethereum/go-ethereum/rpc"

"github.com/sei-protocol/sei-chain/app/antedecorators"
"github.com/sei-protocol/sei-chain/evmrpc"
"github.com/sei-protocol/sei-chain/precompiles"
Expand Down Expand Up @@ -129,6 +134,8 @@ import (
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
"github.com/sei-protocol/sei-chain/x/evm/querier"
"github.com/sei-protocol/sei-chain/x/evm/replay"
evmtracers "github.com/sei-protocol/sei-chain/x/evm/tracers"
"github.com/sei-protocol/sei-chain/x/evm/tracing"
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -381,6 +388,7 @@ type App struct {

encodingConfig appparams.EncodingConfig
evmRPCConfig evmrpc.Config
evmTracer *tracing.Hooks
lightInvarianceConfig LightInvarianceConfig
}

Expand Down Expand Up @@ -967,6 +975,15 @@ func New(
app.HardForkManager = upgrades.NewHardForkManager(app.ChainID)
app.HardForkManager.RegisterHandler(v0upgrade.NewHardForkUpgradeHandler(100_000, upgrades.ChainIDSeiHardForkTest, app.WasmKeeper))

if app.evmRPCConfig.LiveEVMTracer != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's put this config under either https://github.com/sei-protocol/sei-chain/blob/main/x/evm/querier/config.go or a new config section, since it's used in the actual processing and not an RPC-side thing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

...

[evm_tracing]
live_tracer = <name>

...

Does that sounds good?

chainConfig := evmtypes.DefaultChainConfig().EthereumConfig(app.EvmKeeper.ChainID(app.GetCheckCtx()))
evmTracer, err := evmtracers.NewBlockchainTracer(evmtracers.GlobalLiveTracerRegistry, app.evmRPCConfig.LiveEVMTracer, chainConfig)
if err != nil {
panic(fmt.Sprintf("error creating EVM tracer due to %s", err))
}
app.evmTracer = evmTracer
}

return app
}

Expand Down Expand Up @@ -1449,12 +1466,23 @@ func (app *App) ProcessTXsWithOCC(ctx sdk.Context, txs [][]byte, typedTxs []sdk.
wg.Add(1)
go func(txIndex int, tx []byte) {
defer wg.Done()

var txTracer sdk.TxTracer
if app.evmTracer != nil {
txTracer = app.evmTracer
if app.evmTracer.GetTxTracer != nil {
txTracer = app.evmTracer.GetTxTracer(absoluteTxIndices[txIndex])
}
}

deliverTxEntry := &sdk.DeliverTxEntry{
Request: abci.RequestDeliverTx{Tx: tx},
SdkTx: typedTxs[txIndex],
Checksum: sha256.Sum256(tx),
AbsoluteIndex: absoluteTxIndices[txIndex],
TxTracer: txTracer,
}

// get prefill estimate
estimatedWritesets, err := app.AccessControlKeeper.GenerateEstimatedWritesets(ctx, app.GetAnteDepGenerator(), txIndex, typedTxs[txIndex])
// if no error, then we assign the mapped writesets for prefill estimate
Expand Down Expand Up @@ -1515,12 +1543,17 @@ func (app *App) BuildDependenciesAndRunTxs(ctx sdk.Context, txs [][]byte, typedT
return app.ProcessBlockSynchronous(ctx, txs, typedTxs, absoluteTxIndices), ctx
}

func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequest, lastCommit abci.CommitInfo) ([]abci.Event, []*abci.ExecTxResult, abci.ResponseEndBlock, error) {
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) {
ctx = ctx.WithIsOCCEnabled(app.OccEnabled())

goCtx := app.decorateContextWithDexMemState(ctx.Context())
ctx = ctx.WithContext(goCtx)

events := []abci.Event{}
if app.evmTracer != nil {
ctx = evmtracers.SetCtxBlockchainTracer(ctx, app.evmTracer)
}

events = []abci.Event{}
beginBlockReq := abci.RequestBeginBlock{
Hash: req.GetHash(),
ByzantineValidators: utils.Map(req.GetByzantineValidators(), func(mis abci.Misbehavior) abci.Evidence {
Expand All @@ -1545,9 +1578,16 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
beginBlockResp := app.BeginBlock(ctx, beginBlockReq)
events = append(events, beginBlockResp.Events...)

txResults := make([]*abci.ExecTxResult, len(txs))
txResults = make([]*abci.ExecTxResult, len(txs))
typedTxs := app.DecodeTransactionsConcurrently(ctx, txs)

if app.evmTracer != nil {
header := ctx.BlockHeader()
app.evmTracer.OnSeiBlockStart(req.GetHash(), uint64(header.Size()), TmBlockHeaderToEVM(ctx, header, &app.EvmKeeper))
defer func() {
app.evmTracer.OnSeiBlockEnd(err)
}()
}
prioritizedTxs, otherTxs, prioritizedTypedTxs, otherTypedTxs, prioritizedIndices, otherIndices := app.PartitionPrioritizedTxs(ctx, txs, typedTxs)

// run the prioritized txs
Expand All @@ -1573,7 +1613,7 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
lazyWriteEvents := app.BankKeeper.WriteDeferredBalances(ctx)
events = append(events, lazyWriteEvents...)

endBlockResp := app.EndBlock(ctx, abci.RequestEndBlock{
endBlockResp = app.EndBlock(ctx, abci.RequestEndBlock{
Height: req.GetHeight(),
})

Expand Down Expand Up @@ -1901,3 +1941,38 @@ func init() {
// override max wasm size to 2MB
wasmtypes.MaxWasmSize = 2 * 1024 * 1024
}

func TmBlockHeaderToEVM(
ctx sdk.Context,
block tmproto.Header,
k *evmkeeper.Keeper,
) (header *ethtypes.Header) {
number := big.NewInt(block.Height)
lastHash := ethcommon.BytesToHash(block.LastBlockId.Hash)
appHash := ethcommon.BytesToHash(block.AppHash)
txHash := ethcommon.BytesToHash(block.DataHash)
resultHash := ethcommon.BytesToHash(block.LastResultsHash)
miner := ethcommon.BytesToAddress(block.ProposerAddress)
gasLimit, gasWanted := uint64(0), uint64(0)

header = &ethtypes.Header{
Number: number,
ParentHash: lastHash,
Nonce: ethtypes.BlockNonce{}, // inapplicable to Sei
MixDigest: ethcommon.Hash{}, // inapplicable to Sei
UncleHash: ethtypes.EmptyUncleHash, // inapplicable to Sei
Bloom: k.GetBlockBloom(ctx, block.Height),
Root: appHash,
Coinbase: miner,
Difficulty: big.NewInt(0), // inapplicable to Sei
Extra: ethhexutil.Bytes{}, // inapplicable to Sei
GasLimit: gasLimit,
GasUsed: gasWanted,
Time: uint64(block.Time.Unix()),
TxHash: txHash,
ReceiptHash: resultHash,
BaseFee: k.GetBaseFeePerGas(ctx).RoundInt().BigInt(),
}

return
}
4 changes: 2 additions & 2 deletions app/eth_replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
ethcore "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/tracing"
ethtracing "github.com/ethereum/go-ethereum/core/tracing"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
ethtests "github.com/ethereum/go-ethereum/tests"
Expand Down Expand Up @@ -85,7 +85,7 @@ func Replay(a *App) {
for _, w := range b.Withdrawals() {
amount := new(big.Int).SetUint64(w.Amount)
amount = amount.Mul(amount, big.NewInt(params.GWei))
s.AddBalance(w.Address, amount, tracing.BalanceIncreaseWithdrawal)
s.AddBalance(w.Address, amount, ethtracing.BalanceIncreaseWithdrawal)
}
_, _ = s.Finalize()
for _, tx := range b.Txs {
Expand Down
6 changes: 6 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/go:v1.31.0
out: pb
opt: paths=source_relative

13 changes: 13 additions & 0 deletions evmrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ type Config struct {

// test api enables certain override apis for integration test situations
EnableTestAPI bool `mapstructure:"enable_test_api"`

// The EVM tracer to use when doing node synchronization, applies to
// all block produced but traces only EVM transactions.
//
// Refer to x/evm/tracers/registry.go#GlobalLiveTracerRegistry for registered tracers.
LiveEVMTracer string `mapstructure:"live_evm_tracer"`
}

var DefaultConfig = Config{
Expand All @@ -109,6 +115,7 @@ var DefaultConfig = Config{
MaxBlocksForLog: 2000,
MaxSubscriptionsNewHead: 10000,
EnableTestAPI: false,
LiveEVMTracer: "",
}

const (
Expand All @@ -133,6 +140,7 @@ const (
flagMaxBlocksForLog = "evm.max_blocks_for_log"
flagMaxSubscriptionsNewHead = "evm.max_subscriptions_new_head"
flagEnableTestAPI = "evm.enable_test_api"
flagLiveEVMTracer = "evm.live_evm_tracer"
)

func ReadConfig(opts servertypes.AppOptions) (Config, error) {
Expand Down Expand Up @@ -243,5 +251,10 @@ func ReadConfig(opts servertypes.AppOptions) (Config, error) {
return cfg, err
}
}
if v := opts.Get(flagLiveEVMTracer); v != nil {
if cfg.LiveEVMTracer, err = cast.ToStringE(v); err != nil {
return cfg, err
}
}
return cfg, nil
}
8 changes: 7 additions & 1 deletion evmrpc/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package evmrpc_test

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -30,6 +31,7 @@ type opts struct {
maxBlocksForLog interface{}
maxSubscriptionsNewHead interface{}
enableTestAPI interface{}
liveEVMTracer interface{}
}

func (o *opts) Get(k string) interface{} {
Expand Down Expand Up @@ -96,7 +98,10 @@ func (o *opts) Get(k string) interface{} {
if k == "evm.enable_test_api" {
return o.enableTestAPI
}
panic("unknown key")
if k == "evm.live_evm_tracer" {
return o.liveEVMTracer
}
panic(fmt.Errorf("unknown key: %s", k))
}

func TestReadConfig(t *testing.T) {
Expand All @@ -122,6 +127,7 @@ func TestReadConfig(t *testing.T) {
1000,
10000,
false,
"",
}
_, err := evmrpc.ReadConfig(&goodOpts)
require.Nil(t, err)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,8 @@ github.com/stbenjam/no-sprintf-host-port v0.1.1/go.mod h1:TLhvtIvONRzdmkFiio4O8L
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
github.com/streamingfast/sei-cosmos v0.0.0-20240327153024-8e22d1da5334 h1:+4kXknHWASf4Qq0yo67kDmZcBDeSUxVICb34CDEY6Kw=
github.com/streamingfast/sei-cosmos v0.0.0-20240327153024-8e22d1da5334/go.mod h1:ib/gp0gCxN7FXUZ40j5+x8BeyoI7AcX+rTvf53JoDsY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
27 changes: 27 additions & 0 deletions pb/sf/ethereum/type/v2/type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package pbeth

import (
"encoding/hex"
"math/big"
"time"
)

var b0 = big.NewInt(0)

func (b *Block) PreviousID() string {
return hex.EncodeToString(b.Header.ParentHash)
}

func (b *Block) Time() time.Time {
return b.Header.Timestamp.AsTime()
}

func (m *BigInt) Native() *big.Int {
if m == nil {
return b0
}

z := new(big.Int)
z.SetBytes(m.Bytes)
return z
}
Loading