Skip to content

Commit

Permalink
e3: cumulative gas used: as a domain (#12012)
Browse files Browse the repository at this point in the history
- removed `appendable`
- used `domain` to store `cumulativeGasUsed`/`fistLogIndex` data


Took on disk:
eth-mainnet: `idx/*rec* 2.6G`, `history/*rec* 14G`
bor-mainnet: `idx/*rec* 6.6G`, `history/*rec* 32GG`
not perfect but acceptable
  • Loading branch information
AskAlexSharov authored Sep 24, 2024
1 parent 2b873ff commit 0c91895
Show file tree
Hide file tree
Showing 74 changed files with 1,002 additions and 2,847 deletions.
5 changes: 1 addition & 4 deletions cmd/evm/staterunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ import (
"github.com/erigontech/erigon-lib/common/datadir"
"github.com/erigontech/erigon-lib/config3"
"github.com/erigontech/erigon-lib/kv/mdbx"
"github.com/erigontech/erigon-lib/kv/rawdbv3"
"github.com/erigontech/erigon-lib/kv/temporal"
"github.com/erigontech/erigon-lib/log/v3"
libstate "github.com/erigontech/erigon-lib/state"

"github.com/erigontech/erigon/core/rawdb"
"github.com/erigontech/erigon/core/state"
"github.com/erigontech/erigon/core/vm"
"github.com/erigontech/erigon/eth/tracers/logger"
Expand Down Expand Up @@ -144,8 +142,7 @@ func aggregateResultsFromStateTests(
MustOpen()
defer _db.Close()

cr := rawdb.NewCanonicalReader(rawdbv3.TxNums)
agg, err := libstate.NewAggregator(context.Background(), dirs, config3.HistoryV3AggregationStep, _db, cr, log.New())
agg, err := libstate.NewAggregator(context.Background(), dirs, config3.HistoryV3AggregationStep, _db, log.New())
if err != nil {
return nil, err
}
Expand Down
64 changes: 4 additions & 60 deletions cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,71 +1131,15 @@ func stageCustomTrace(db kv.RwDB, ctx context.Context, logger log.Logger) error
var batchSize datasize.ByteSize
must(batchSize.UnmarshalText([]byte(batchSizeStr)))

s := stage(sync, nil, db, stages.CustomTrace)

logger.Info("Stage", "name", s.ID, "progress", s.BlockNumber)
chainConfig, pm := fromdb.ChainConfig(db), fromdb.PruneMode(db)
if pruneTo > 0 {
pm.History = prune.Distance(s.BlockNumber - pruneTo)
}

syncCfg := ethconfig.Defaults.Sync
syncCfg.ExecWorkerCount = int(workers)
syncCfg.ReconWorkerCount = int(reconWorkers)

genesis := core.GenesisBlockByChainName(chain)
br, _ := blocksIO(db, logger)
cfg := stagedsync.StageCustomTraceCfg(db, pm, dirs, br, chainConfig, engine, genesis, &syncCfg)

if unwind > 0 {
if err := db.View(ctx, func(tx kv.Tx) error {
blockNumWithCommitment, ok, err := tx.(libstate.HasAggTx).AggTx().(*libstate.AggregatorRoTx).CanUnwindBeforeBlockNum(s.BlockNumber-unwind, tx)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("too deep unwind requested: %d, minimum allowed: %d", s.BlockNumber-unwind, blockNumWithCommitment)
}
unwind = s.BlockNumber - blockNumWithCommitment
return nil
}); err != nil {
return err
}
}

var tx kv.RwTx //nil - means lower-level code (each stage) will manage transactions
if noCommit {
var err error
tx, err = db.BeginRw(ctx)
if err != nil {
return err
}
defer tx.Rollback()
}
txc := wrap.TxContainer{Tx: tx}

if unwind > 0 {
u := sync.NewUnwindState(stages.CustomTrace, s.BlockNumber-unwind, s.BlockNumber, true, false)
err := stagedsync.UnwindCustomTrace(u, s, txc, cfg, ctx, logger)
if err != nil {
return err
}
return nil
}

if pruneTo > 0 {
p, err := sync.PruneStageState(stages.CustomTrace, s.BlockNumber, tx, db, true)
if err != nil {
return err
}
err = stagedsync.PruneCustomTrace(p, tx, cfg, ctx, logger)
if err != nil {
return err
}
return nil
}

err := stagedsync.SpawnCustomTrace(s, txc, cfg, ctx, block, logger)
err := stagedsync.SpawnCustomTrace(cfg, ctx, logger)
if err != nil {
return err
}
Expand Down Expand Up @@ -1334,8 +1278,8 @@ func allSnapshots(ctx context.Context, db kv.RoDB, logger log.Logger) (*freezebl
var err error
blockReader := freezeblocks.NewBlockReader(_allSnapshotsSingleton, _allBorSnapshotsSingleton)

cr := rawdb.NewCanonicalReader(rawdbv3.TxNums.WithCustomReadTxNumFunc(freezeblocks.ReadTxNumFuncFromBlockReader(ctx, blockReader)))
_aggSingleton, err = libstate.NewAggregator(ctx, dirs, config3.HistoryV3AggregationStep, db, cr, logger)
txNums := rawdbv3.TxNums.WithCustomReadTxNumFunc(freezeblocks.ReadTxNumFuncFromBlockReader(ctx, blockReader))
_aggSingleton, err = libstate.NewAggregator(ctx, dirs, config3.HistoryV3AggregationStep, db, logger)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -1386,7 +1330,7 @@ func allSnapshots(ctx context.Context, db kv.RoDB, logger log.Logger) (*freezebl
ac := _aggSingleton.BeginFilesRo()
defer ac.Close()
ac.LogStats(tx, func(endTxNumMinimax uint64) (uint64, error) {
_, histBlockNumProgress, err := rawdbv3.TxNums.WithCustomReadTxNumFunc(freezeblocks.ReadTxNumFuncFromBlockReader(ctx, blockReader)).FindBlockNum(tx, endTxNumMinimax)
_, histBlockNumProgress, err := txNums.FindBlockNum(tx, endTxNumMinimax)
return histBlockNumProgress, err
})
return nil
Expand Down
3 changes: 1 addition & 2 deletions cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
blockReader = freezeblocks.NewBlockReader(allSnapshots, allBorSnapshots)
txNumsReader := rawdbv3.TxNums.WithCustomReadTxNumFunc(freezeblocks.ReadTxNumFuncFromBlockReader(ctx, blockReader))

cr := rawdb.NewCanonicalReader(txNumsReader)
agg, err := libstate.NewAggregator(ctx, cfg.Dirs, config3.HistoryV3AggregationStep, db, cr, logger)
agg, err := libstate.NewAggregator(ctx, cfg.Dirs, config3.HistoryV3AggregationStep, db, logger)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, fmt.Errorf("create aggregator: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/rpcdaemon/test.http
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Content-Type: application/json
}

###
# 6250464, 6250465, 6250470, 7250471

POST 127.0.0.1:8545
Content-Type: application/json
Expand All @@ -222,8 +223,8 @@ Content-Type: application/json
"method": "eth_getLogs",
"params": [
{
"fromBlock": "0x14ADC0",
"toBlock": "0x14AEC0"
"fromBlock": "0x6EA227",
"toBlock": "0x6EA227"
}
],
"id": 537758
Expand Down
Loading

0 comments on commit 0c91895

Please sign in to comment.