Skip to content

Commit

Permalink
move temporal package to erigon-lib (#10015)
Browse files Browse the repository at this point in the history
Co-authored-by: awskii <artem.tsskiy@gmail.com>
  • Loading branch information
AskAlexSharov and awskii authored Apr 22, 2024
1 parent 8f0582b commit ab361e4
Show file tree
Hide file tree
Showing 36 changed files with 228 additions and 268 deletions.
4 changes: 2 additions & 2 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon-lib/kv/temporal/temporaltest"
"github.com/ledgerwatch/log/v3"
"github.com/urfave/cli/v2"

Expand Down Expand Up @@ -294,7 +294,7 @@ func Main(ctx *cli.Context) error {
return h
}

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

tx, err := db.BeginRw(context.Background())
Expand Down
5 changes: 2 additions & 3 deletions cmd/integration/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"

"github.com/ledgerwatch/erigon-lib/kv/temporal"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"
"golang.org/x/sync/semaphore"
Expand All @@ -16,8 +17,6 @@ import (
kv2 "github.com/ledgerwatch/erigon-lib/kv/mdbx"

"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon/core/systemcontracts"
"github.com/ledgerwatch/erigon/migrations"
"github.com/ledgerwatch/erigon/turbo/debug"
"github.com/ledgerwatch/erigon/turbo/logging"
Expand Down Expand Up @@ -106,7 +105,7 @@ func openDB(opts kv2.MdbxOpts, applyMigrations bool, logger log.Logger) (kv.RwDB
}
if h3 {
_, _, agg := allSnapshots(context.Background(), db, logger)
tdb, err := temporal.New(db, agg, systemcontracts.SystemContractCodeLookup[chain])
tdb, err := temporal.New(db, agg)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/c2h5oh/datasize"
"github.com/erigontech/mdbx-go/mdbx"
lru "github.com/hashicorp/golang-lru/arc/v2"
"github.com/ledgerwatch/erigon-lib/config3"
"github.com/ledgerwatch/log/v3"
"github.com/ledgerwatch/secp256k1"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -1459,7 +1460,7 @@ func allSnapshots(ctx context.Context, db kv.RoDB, logger log.Logger) (*freezebl
_allBorSnapshotsSingleton = freezeblocks.NewBorRoSnapshots(snapCfg, dirs.Snap, 0, logger)

var err error
_aggSingleton, err = libstate.NewAggregator(ctx, dirs.SnapHistory, dirs.Tmp, ethconfig.HistoryV3AggregationStep, db, logger)
_aggSingleton, err = libstate.NewAggregator(ctx, dirs.SnapHistory, dirs.Tmp, config3.HistoryV3AggregationStep, db, logger)
if err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"strings"
"time"

"github.com/ledgerwatch/erigon-lib/config3"
"github.com/ledgerwatch/erigon-lib/kv/temporal"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"
"golang.org/x/sync/semaphore"
Expand Down Expand Up @@ -51,8 +53,6 @@ import (
"github.com/ledgerwatch/erigon/consensus/ethash"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon/core/systemcontracts"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/node"
Expand Down Expand Up @@ -384,7 +384,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
allSnapshots.LogStat("remote")
allBorSnapshots.LogStat("remote")

if agg, err = libstate.NewAggregator(ctx, cfg.Dirs.SnapHistory, cfg.Dirs.Tmp, ethconfig.HistoryV3AggregationStep, db, logger); err != nil {
if agg, err = libstate.NewAggregator(ctx, cfg.Dirs.SnapHistory, cfg.Dirs.Tmp, config3.HistoryV3AggregationStep, db, logger); err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("create aggregator: %w", err)
}
_ = agg.OpenFolder()
Expand Down Expand Up @@ -439,7 +439,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
})
if histV3Enabled {
logger.Info("HistoryV3", "enable", histV3Enabled)
db, err = temporal.New(rwKv, agg, systemcontracts.SystemContractCodeLookup[cc.ChainName])
db, err = temporal.New(rwKv, agg)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/length"
"github.com/ledgerwatch/erigon-lib/config3"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/log/v3"

Expand All @@ -34,7 +35,6 @@ import (
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rlp"
"github.com/ledgerwatch/erigon/turbo/trie"
Expand Down Expand Up @@ -316,7 +316,7 @@ func GenerateChain(config *chain.Config, parent *types.Block, engine consensus.E

var stateReader state.StateReader
var stateWriter state.StateWriter
if ethconfig.EnableHistoryV4InTest {
if config3.EnableHistoryV4InTest {
panic("implement me")
//agg := tx.(*temporal.Tx).Agg()
//sd := agg.SharedDomains()
Expand All @@ -332,7 +332,7 @@ func GenerateChain(config *chain.Config, parent *types.Block, engine consensus.E
}
txNum := -1
setBlockNum := func(blockNum uint64) {
if ethconfig.EnableHistoryV4InTest {
if config3.EnableHistoryV4InTest {
panic("implement me")
//stateReader.(*state.StateReaderV4).SetBlockNum(blockNum)
//stateWriter.(*state.StateWriterV4).SetBlockNum(blockNum)
Expand All @@ -343,7 +343,7 @@ func GenerateChain(config *chain.Config, parent *types.Block, engine consensus.E
}
txNumIncrement := func() {
txNum++
if ethconfig.EnableHistoryV4InTest {
if config3.EnableHistoryV4InTest {
panic("implement me")
//tx.(*temporal.Tx).Agg().SetTxNum(uint64(txNum))
//stateReader.(*state.StateReaderV4).SetTxNum(uint64(txNum))
Expand Down Expand Up @@ -386,7 +386,7 @@ func GenerateChain(config *chain.Config, parent *types.Block, engine consensus.E
}

var err error
b.header.Root, err = CalcHashRootForTests(tx, b.header, ethconfig.EnableHistoryV4InTest)
b.header.Root, err = CalcHashRootForTests(tx, b.header, config3.EnableHistoryV4InTest)
if err != nil {
return nil, nil, fmt.Errorf("call to CalcTrieRoot: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/temporal/temporaltest"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon/turbo/rpchelper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -26,7 +26,7 @@ import (
func TestGenesisBlockHashes(t *testing.T) {
t.Parallel()
logger := log.New()
_, db, _ := temporal.NewTestDB(t, datadir.New(t.TempDir()), nil)
_, db, _ := temporaltest.NewTestDB(t, datadir.New(t.TempDir()))
check := func(network string) {
genesis := core.GenesisBlockByChainName(network)
tx, err := db.BeginRw(context.Background())
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestGenesisBlockRoots(t *testing.T) {
func TestCommitGenesisIdempotency(t *testing.T) {
t.Parallel()
logger := log.New()
_, db, _ := temporal.NewTestDB(t, datadir.New(t.TempDir()), nil)
_, db, _ := temporaltest.NewTestDB(t, datadir.New(t.TempDir()))
tx, err := db.BeginRw(context.Background())
require.NoError(t, err)
defer tx.Rollback()
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestAllocConstructor(t *testing.T) {
},
}

historyV3, db, _ := temporal.NewTestDB(t, datadir.New(t.TempDir()), nil)
historyV3, db, _ := temporaltest.NewTestDB(t, datadir.New(t.TempDir()))
_, _, err := core.CommitGenesisBlock(db, genSpec, "", logger)
require.NoError(err)

Expand Down
4 changes: 2 additions & 2 deletions core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/c2h5oh/datasize"
"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/config3"
"github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"

Expand All @@ -47,7 +48,6 @@ import (
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/trie"
)
Expand Down Expand Up @@ -191,7 +191,7 @@ func WriteGenesisState(g *types.Genesis, tx kv.RwTx, tmpDir string, logger log.L
}

var stateWriter state.StateWriter
if ethconfig.EnableHistoryV4InTest {
if config3.EnableHistoryV4InTest {
panic("implement me")
//tx.(*temporal.Tx).Agg().SetTxNum(0)
//stateWriter = state.NewWriterV4(tx.(kv.TemporalTx))
Expand Down
4 changes: 2 additions & 2 deletions core/rawdb/rawdbhelpers/rawdbhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package rawdbhelpers
import (
"encoding/binary"

"github.com/ledgerwatch/erigon-lib/config3"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/eth/ethconfig"
)

func IdxStepsCountV3(tx kv.Tx) float64 {
Expand All @@ -14,7 +14,7 @@ func IdxStepsCountV3(tx kv.Tx) float64 {
fstTxNum := binary.BigEndian.Uint64(fst)
lstTxNum := binary.BigEndian.Uint64(lst)

return float64(lstTxNum-fstTxNum) / float64(ethconfig.HistoryV3AggregationStep)
return float64(lstTxNum-fstTxNum) / float64(config3.HistoryV3AggregationStep)
}
return 0
}
4 changes: 2 additions & 2 deletions core/rlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon-lib/kv/temporal/temporaltest"
"github.com/ledgerwatch/log/v3"
"golang.org/x/crypto/sha3"

Expand All @@ -37,7 +37,7 @@ import (
)

func getBlock(tb testing.TB, transactions int, uncles int, dataSize int, tmpDir string, logger log.Logger) *types.Block {
_, db, _ := temporal.NewTestDB(tb, datadir.New(tmpDir), nil)
_, db, _ := temporaltest.NewTestDB(tb, datadir.New(tmpDir))
var (
aa = libcommon.HexToAddress("0x000000000000000000000000000000000000aaaa")
// Generate a canonical chain to act as the main dataset
Expand Down
4 changes: 2 additions & 2 deletions core/state/history_reader_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"

"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/config3"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/core/types/accounts"
"github.com/ledgerwatch/erigon/eth/ethconfig"
)

// HistoryReaderV3 Implements StateReader and StateWriter
Expand Down Expand Up @@ -51,7 +51,7 @@ func (hr *HistoryReaderV3) ReadAccountData(address common.Address) (*accounts.Ac

func (hr *HistoryReaderV3) ReadAccountStorage(address common.Address, incarnation uint64, key *common.Hash) ([]byte, error) {
var acc []byte
if ethconfig.EnableHistoryV4InTest {
if config3.EnableHistoryV4InTest {
acc = address.Bytes()
} else {
acc = make([]byte, 20+8)
Expand Down
2 changes: 1 addition & 1 deletion core/state/rw_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"unsafe"

"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/kv/temporal"
"github.com/ledgerwatch/log/v3"
btree2 "github.com/tidwall/btree"

Expand All @@ -24,7 +25,6 @@ import (
"github.com/ledgerwatch/erigon-lib/metrics"
libstate "github.com/ledgerwatch/erigon-lib/state"
"github.com/ledgerwatch/erigon/cmd/state/exec22"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon/core/types/accounts"
"github.com/ledgerwatch/erigon/turbo/shards"
)
Expand Down
4 changes: 2 additions & 2 deletions core/vm/gas_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (
"testing"

"github.com/ledgerwatch/erigon-lib/common/hexutil"
"github.com/ledgerwatch/erigon-lib/kv/temporal/temporaltest"

"github.com/holiman/uint256"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/kv/memdb"

"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon/core/vm/evmtypes"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/rpchelper"
Expand Down Expand Up @@ -141,7 +141,7 @@ var createGasTests = []struct {

func TestCreateGas(t *testing.T) {
t.Parallel()
_, db, _ := temporal.NewTestDB(t, datadir.New(t.TempDir()), nil)
_, db, _ := temporaltest.NewTestDB(t, datadir.New(t.TempDir()))
for i, tt := range createGasTests {
address := libcommon.BytesToAddress([]byte("contract"))

Expand Down
4 changes: 4 additions & 0 deletions erigon-lib/config3/config3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package config3

// AggregationStep number of transactions in smallest static file
const HistoryV3AggregationStep = 3_125_000 // 100M / 32
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build !erigon3 && !e3 && !erigon4 && !e4

package ethconfig
package config3

const EnableHistoryV3InTest = false
const EnableHistoryV4InTest = false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build erigon3 || e3

package ethconfig
package config3

const EnableHistoryV3InTest = true
const EnableHistoryV4InTest = false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build erigon4 || e4

package ethconfig
package config3

const EnableHistoryV3InTest = true
const EnableHistoryV4InTest = true
Loading

0 comments on commit ab361e4

Please sign in to comment.