Skip to content

Commit

Permalink
evm: to use temporal db. remove historyV3 flag from db (#10305)
Browse files Browse the repository at this point in the history
for #10298
---------
Co-authored-by: awskii <[email protected]>
  • Loading branch information
AskAlexSharov authored May 14, 2024
1 parent 68a7e41 commit 0eadfc3
Show file tree
Hide file tree
Showing 82 changed files with 975 additions and 2,798 deletions.
8 changes: 1 addition & 7 deletions cmd/devnet/services/polygon/proofgenerator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon-lib/kv/memdb"
"github.com/ledgerwatch/erigon/accounts/abi/bind"
"github.com/ledgerwatch/erigon/cmd/devnet/blocks"
Expand Down Expand Up @@ -145,12 +144,7 @@ func (rg *requestGenerator) GetTransactionReceipt(ctx context.Context, hash libc
}
defer tx.Rollback()

historyV3, err := kvcfg.HistoryV3.Enabled(tx)
if err != nil {
panic(err)
}

_, _, _, ibs, _, err := transactions.ComputeTxEnv(ctx, engine, block, chainConfig, reader, tx, 0, historyV3)
_, _, _, ibs, _, err := transactions.ComputeTxEnv(ctx, engine, block, chainConfig, reader, tx, 0)

if err != nil {
return nil, err
Expand Down
5 changes: 1 addition & 4 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"

"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/math"
"github.com/ledgerwatch/erigon/consensus/ethash"
Expand Down Expand Up @@ -78,8 +76,7 @@ type stEnvMarshaling struct {

func MakePreState(chainRules *chain.Rules, tx kv.RwTx, accounts types.GenesisAlloc) (state.StateReader, *state.PlainStateWriter) {
var blockNr uint64 = 0
histV3, _ := kvcfg.HistoryV3.Enabled(tx)
stateReader, stateWriter := rpchelper.NewLatestStateReader(tx, histV3), state.NewPlainStateWriter(tx, tx, blockNr)
stateReader, stateWriter := rpchelper.NewLatestStateReader(tx), state.NewPlainStateWriter(tx, tx, blockNr)
statedb := state.New(stateReader) //ibs
for addr, a := range accounts {
statedb.SetCode(addr, a.Code)
Expand Down
9 changes: 2 additions & 7 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/common/length"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon/common/math"
"github.com/ledgerwatch/erigon/consensus/ethash"
"github.com/ledgerwatch/erigon/consensus/merge"
Expand Down Expand Up @@ -294,7 +293,7 @@ func Main(ctx *cli.Context) error {
return h
}

_, db, _ := temporaltest.NewTestDB(nil, datadir.New(""))
db, _ := temporaltest.NewTestDB(nil, datadir.New(""))
defer db.Close()

tx, err := db.BeginRw(context.Background())
Expand Down Expand Up @@ -331,11 +330,7 @@ func Main(ctx *cli.Context) error {
body, _ := rlp.EncodeToBytes(txs)
collector := make(Alloc)

historyV3, err := kvcfg.HistoryV3.Enabled(tx)
if err != nil {
return err
}
dumper := state.NewDumper(tx, prestate.Env.Number, historyV3)
dumper := state.NewDumper(tx, prestate.Env.Number, true)
dumper.DumpToCollector(collector, false, false, libcommon.Address{}, 0)
return dispatchOutput(ctx, baseDir, result, collector, body)
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
libcommon "github.com/ledgerwatch/erigon-lib/common"
common2 "github.com/ledgerwatch/erigon-lib/common/dbg"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon-lib/kv/memdb"
"github.com/ledgerwatch/erigon/cmd/utils/flags"
"github.com/ledgerwatch/erigon/core/types"
Expand Down Expand Up @@ -301,11 +300,7 @@ func runCmd(ctx *cli.Context) error {
fmt.Println("Could not commit state: ", err)
os.Exit(1)
}
historyV3, err := kvcfg.HistoryV3.Enabled(tx)
if err != nil {
return err
}
fmt.Println(string(state.NewDumper(tx, 0, historyV3).DefaultDump()))
fmt.Println(string(state.NewDumper(tx, 0, true).DefaultDump()))
}

if memProfilePath := ctx.String(MemProfileFlag.Name); memProfilePath != "" {
Expand Down
23 changes: 20 additions & 3 deletions cmd/evm/staterunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import (
"github.com/c2h5oh/datasize"
mdbx2 "github.com/erigontech/mdbx-go/mdbx"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/config3"
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
"github.com/ledgerwatch/erigon-lib/kv/temporal"
libstate "github.com/ledgerwatch/erigon-lib/state"
"github.com/ledgerwatch/log/v3"
"github.com/urfave/cli/v2"

Expand Down Expand Up @@ -122,16 +126,29 @@ func runStateTest(fname string, cfg vm.Config, jsonOut bool) error {
func aggregateResultsFromStateTests(
stateTests map[string]tests.StateTest, cfg vm.Config,
jsonOut bool) ([]StatetestResult, error) {
dirs := datadir.New(filepath.Join(os.TempDir(), "erigon-statetest"))
//this DB is shared. means:
// - faster sequential tests: don't need create/delete db
// - less parallelism: multiple processes can open same DB but only 1 can create rw-transaction (other will wait when 1-st finish)
db := mdbx.NewMDBX(log.New()).
Path(filepath.Join(os.TempDir(), "erigon-statetest")).
_db := mdbx.NewMDBX(log.New()).
Path(dirs.Chaindata).
Flags(func(u uint) uint {
return u | mdbx2.UtterlyNoSync | mdbx2.NoMetaSync | mdbx2.LifoReclaim | mdbx2.NoMemInit
return u | mdbx2.UtterlyNoSync | mdbx2.NoMetaSync | mdbx2.NoMemInit | mdbx2.WriteMap
}).
GrowthStep(1 * datasize.MB).
MustOpen()
defer _db.Close()

agg, err := libstate.NewAggregator(context.Background(), dirs, config3.HistoryV3AggregationStep, _db, log.New())
if err != nil {
return nil, err
}
defer agg.Close()

db, err := temporal.New(_db, agg)
if err != nil {
return nil, err
}
defer db.Close()

tx, txErr := db.BeginRw(context.Background())
Expand Down
10 changes: 1 addition & 9 deletions cmd/hack/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/common/length"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
"github.com/ledgerwatch/erigon-lib/kv/temporal/historyv2"
"github.com/ledgerwatch/erigon-lib/recsplit"
Expand Down Expand Up @@ -132,15 +131,8 @@ func printCurrentBlockNumber(chaindata string) {
}

func blocksIO(db kv.RoDB) (services.FullBlockReader, *blockio.BlockWriter) {
var histV3 bool
if err := db.View(context.Background(), func(tx kv.Tx) error {
histV3, _ = kvcfg.HistoryV3.Enabled(tx)
return nil
}); err != nil {
panic(err)
}
br := freezeblocks.NewBlockReader(freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{Enabled: false}, "", 0, log.New()), nil /* BorSnapshots */)
bw := blockio.NewBlockWriter(histV3)
bw := blockio.NewBlockWriter()
return br, bw
}

Expand Down
14 changes: 0 additions & 14 deletions cmd/hack/tool/fromdb/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon/cmd/hack/tool"
"github.com/ledgerwatch/erigon/ethdb/prune"
)
Expand Down Expand Up @@ -35,16 +34,3 @@ func PruneMode(db kv.RoDB) (pm prune.Mode) {
}
return
}
func HistV3(db kv.RoDB) (enabled bool) {
if err := db.View(context.Background(), func(tx kv.Tx) error {
var err error
enabled, err = kvcfg.HistoryV3.Enabled(tx)
if err != nil {
return err
}
return nil
}); err != nil {
panic(err)
}
return
}
7 changes: 1 addition & 6 deletions cmd/integration/commands/reset_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon-lib/kv/rawdbv3"
"github.com/ledgerwatch/erigon-lib/state"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/freezeblocks"
Expand Down Expand Up @@ -123,14 +122,10 @@ func printStages(tx kv.Tx, snapshots *freezeblocks.RoSnapshots, borSn *freezeblo
fmt.Fprintf(w, "prune distance: %s\n\n", pm.String())
fmt.Fprintf(w, "blocks.v2: %t, segments=%d, indices=%d\n", snapshots.Cfg().Enabled, snapshots.SegmentsMax(), snapshots.IndicesMax())
fmt.Fprintf(w, "blocks.bor.v2: segments=%d, indices=%d\n\n", borSn.SegmentsMax(), borSn.IndicesMax())
h3, err := kvcfg.HistoryV3.Enabled(tx)
if err != nil {
return err
}

_, lastBlockInHistSnap, _ := rawdbv3.TxNums.FindBlockNum(tx, agg.EndTxNumMinimax())
_lb, _lt, _ := rawdbv3.TxNums.Last(tx)
fmt.Fprintf(w, "history.v3: %t, idx steps: %.02f, lastBlockInSnap=%d, TxNums_Index(%d,%d), filesAmount: %d\n\n", h3, rawdbhelpers.IdxStepsCountV3(tx), lastBlockInHistSnap, _lb, _lt, agg.FilesAmount())
fmt.Fprintf(w, "state.history: idx steps: %.02f, lastBlockInSnap=%d, TxNums_Index(%d,%d), filesAmount: %d\n\n", rawdbhelpers.IdxStepsCountV3(tx), lastBlockInHistSnap, _lb, _lt, agg.FilesAmount())
s1, err := tx.ReadSequence(kv.EthTx)
if err != nil {
return err
Expand Down
22 changes: 4 additions & 18 deletions cmd/integration/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"golang.org/x/sync/semaphore"

"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
kv2 "github.com/ledgerwatch/erigon-lib/kv/mdbx"

"github.com/ledgerwatch/erigon/cmd/utils"
Expand Down Expand Up @@ -92,25 +91,12 @@ func openDB(opts kv2.MdbxOpts, applyMigrations bool, logger log.Logger) (kv.RwDB
}

if opts.GetLabel() == kv.ChainDB {
var h3 bool
var err error
if err := db.View(context.Background(), func(tx kv.Tx) error {
h3, err = kvcfg.HistoryV3.Enabled(tx)
if err != nil {
return err
}
return nil
}); err != nil {
_, _, agg := allSnapshots(context.Background(), db, logger)
tdb, err := temporal.New(db, agg)
if err != nil {
return nil, err
}
if h3 {
_, _, agg := allSnapshots(context.Background(), db, logger)
tdb, err := temporal.New(db, agg)
if err != nil {
return nil, err
}
db = tdb
}
db = tdb
}

return db, nil
Expand Down
Loading

0 comments on commit 0eadfc3

Please sign in to comment.