Skip to content

Commit

Permalink
perf: optimize traces (#107)
Browse files Browse the repository at this point in the history
* refactor: remove unused storage traces  (#819)

* fix(traces): deletion proof apply wrong storage value from structLogger (#838)

* fix issue caused by unmatching storage value

---------

Co-authored-by: HAOYUatHZ <HAOYUatHZ@users.noreply.github.com>
Co-authored-by: Péter Garamvölgyi <peter@scroll.io>

---------

Co-authored-by: Ömer Faruk Irmak <omerfirmak@gmail.com>
Co-authored-by: Ho <noelwei@gmail.com>
Co-authored-by: HAOYUatHZ <HAOYUatHZ@users.noreply.github.com>
Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
  • Loading branch information
5 people committed Jun 26, 2024
1 parent 7bcb18d commit a5adda6
Show file tree
Hide file tree
Showing 14 changed files with 9 additions and 1,483 deletions.
7 changes: 0 additions & 7 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/scroll-tech/go-ethereum/accounts/usbwallet"
"github.com/scroll-tech/go-ethereum/cmd/utils"
"github.com/scroll-tech/go-ethereum/eth/ethconfig"
"github.com/scroll-tech/go-ethereum/internal/debug"
"github.com/scroll-tech/go-ethereum/internal/ethapi"
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/metrics"
Expand Down Expand Up @@ -148,7 +147,6 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
if ctx.GlobalIsSet(utils.EthStatsURLFlag.Name) {
cfg.Ethstats.URL = ctx.GlobalString(utils.EthStatsURLFlag.Name)
}
applyTraceConfig(ctx, &cfg.Eth)
applyMetricConfig(ctx, &cfg)

return stack, cfg
Expand Down Expand Up @@ -206,11 +204,6 @@ func dumpConfig(ctx *cli.Context) error {
return nil
}

func applyTraceConfig(ctx *cli.Context, cfg *ethconfig.Config) {
subCfg := debug.ConfigTrace(ctx)
cfg.MPTWitness = subCfg.MPTWitness
}

func applyMetricConfig(ctx *cli.Context, cfg *gethConfig) {
if ctx.GlobalIsSet(utils.MetricsEnabledFlag.Name) {
cfg.Metrics.Enabled = ctx.GlobalBool(utils.MetricsEnabledFlag.Name)
Expand Down
3 changes: 0 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"github.com/scroll-tech/go-ethereum/metrics"
"github.com/scroll-tech/go-ethereum/params"
"github.com/scroll-tech/go-ethereum/trie"
"github.com/scroll-tech/go-ethereum/trie/zkproof"
)

var (
Expand Down Expand Up @@ -134,7 +133,6 @@ type CacheConfig struct {
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
SnapshotLimit int // Memory allowance (MB) to use for caching snapshot entries in memory
Preimages bool // Whether to store preimage of trie key to the disk
MPTWitness int // How to generate witness data for mpt circuit, 0: nothing, 1: natural

SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it
}
Expand All @@ -147,7 +145,6 @@ var defaultCacheConfig = &CacheConfig{
TrieTimeLimit: 5 * time.Minute,
SnapshotLimit: 256,
SnapshotWait: true,
MPTWitness: int(zkproof.MPTWitnessNothing),
}

// BlockChain represents the canonical chain given a database with a genesis
Expand Down
14 changes: 6 additions & 8 deletions core/types/l2trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type BlockTrace struct {
StorageTrace *StorageTrace `json:"storageTrace"`
TxStorageTraces []*StorageTrace `json:"txStorageTraces,omitempty"`
ExecutionResults []*ExecutionResult `json:"executionResults"`
MPTWitness *json.RawMessage `json:"mptwitness,omitempty"`
WithdrawTrieRoot common.Hash `json:"withdraw_trie_root,omitempty"`
SequencerSetVerifyHash common.Hash `json:"sequencer_set_verify_hash,omitempty"`
StartL1QueueIndex uint64 `json:"startL1QueueIndex"`
Expand Down Expand Up @@ -132,13 +131,12 @@ type ExtraData struct {
}

type AccountWrapper struct {
Address common.Address `json:"address"`
Nonce uint64 `json:"nonce"`
Balance *hexutil.Big `json:"balance"`
KeccakCodeHash common.Hash `json:"keccakCodeHash,omitempty"`
PoseidonCodeHash common.Hash `json:"poseidonCodeHash,omitempty"`
CodeSize uint64 `json:"codeSize"`
Storage *StorageWrapper `json:"storage,omitempty"` // StorageWrapper can be empty if irrelated to storage operation
Address common.Address `json:"address"`
Nonce uint64 `json:"nonce"`
Balance *hexutil.Big `json:"balance"`
KeccakCodeHash common.Hash `json:"keccakCodeHash,omitempty"`
PoseidonCodeHash common.Hash `json:"poseidonCodeHash,omitempty"`
CodeSize uint64 `json:"codeSize"`
}

// StorageWrapper while key & value can also be retrieved from StructLogRes.Storage,
Expand Down
4 changes: 0 additions & 4 deletions core/vm/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ func (l *StructLogger) CaptureState(pc uint64, op OpCode, gas, cost uint64, scop
if !l.cfg.DisableStorage {
structLog.Storage = l.storage[contractAddress].Copy()
}

if err := traceStorage(l, scope, structLog.getOrInitExtraData()); err != nil {
log.Error("Failed to trace data", "opcode", op.String(), "err", err)
}
}
if l.cfg.EnableReturnData {
structLog.ReturnData.Write(rData)
Expand Down
27 changes: 0 additions & 27 deletions core/vm/logger_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ func traceContractCode(l *StructLogger, scope *ScopeContext, extraData *types.Ex
return nil
}

// traceStorage get contract's storage at storage_address
func traceStorage(l *StructLogger, scope *ScopeContext, extraData *types.ExtraData) error {
if scope.Stack.len() == 0 {
return nil
}
key := common.Hash(scope.Stack.peek().Bytes32())
storage := getWrappedAccountForStorage(l, scope.Contract.Address(), key)
extraData.StateList = append(extraData.StateList, storage)

return nil
}

// traceContractAccount gets the contract's account
func traceContractAccount(l *StructLogger, scope *ScopeContext, extraData *types.ExtraData) error {
// Get account state.
Expand Down Expand Up @@ -113,21 +101,6 @@ func getWrappedAccountForAddr(l *StructLogger, address common.Address) *types.Ac
}
}

func getWrappedAccountForStorage(l *StructLogger, address common.Address, key common.Hash) *types.AccountWrapper {
return &types.AccountWrapper{
Address: address,
Nonce: l.env.StateDB.GetNonce(address),
Balance: (*hexutil.Big)(l.env.StateDB.GetBalance(address)),
KeccakCodeHash: l.env.StateDB.GetKeccakCodeHash(address),
PoseidonCodeHash: l.env.StateDB.GetPoseidonCodeHash(address),
CodeSize: l.env.StateDB.GetCodeSize(address),
Storage: &types.StorageWrapper{
Key: key.String(),
Value: l.env.StateDB.GetState(address, key).String(),
},
}
}

func getCodeForAddr(l *StructLogger, address common.Address) []byte {
return l.env.StateDB.GetCode(address)
}
1 change: 0 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
TrieTimeLimit: config.TrieTimeout,
SnapshotLimit: config.SnapshotCache,
Preimages: config.Preimages,
MPTWitness: config.MPTWitness,
}
)
// TODO (MariusVanDerWijden) get rid of shouldPreserve in a follow-up PR
Expand Down
3 changes: 0 additions & 3 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ type Config struct {
// Arrow Glacier block override (TODO: remove after the fork)
OverrideArrowGlacier *big.Int `toml:",omitempty"`

// Trace option
MPTWitness int

// Check circuit capacity in block validator
CheckCircuitCapacity bool

Expand Down
6 changes: 0 additions & 6 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions internal/debug/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ var (
Name: "trace",
Usage: "Write execution trace to the given file",
}
// mpt witness settings
mptWitnessFlag = cli.IntFlag{
Name: "trace.mptwitness",
Usage: "Output witness for mpt circuit with Specified order (default = no output, 1 = by executing order",
Value: 0,
}
)

// Flags holds all command-line flags required for debugging.
Expand All @@ -136,7 +130,6 @@ var Flags = []cli.Flag{
blockprofilerateFlag,
cpuprofileFlag,
traceFlag,
mptWitnessFlag,
}

var glogger *log.GlogHandler
Expand All @@ -150,14 +143,11 @@ func init() {
// TraceConfig export options about trace
type TraceConfig struct {
TracePath string
// Trace option
MPTWitness int
}

func ConfigTrace(ctx *cli.Context) *TraceConfig {
cfg := new(TraceConfig)
cfg.TracePath = ctx.GlobalString(traceFlag.Name)
cfg.MPTWitness = ctx.GlobalInt(mptWitnessFlag.Name)

return cfg
}
Expand Down
Loading

0 comments on commit a5adda6

Please sign in to comment.