e3: release some e4 parts (#7628)

This commit is contained in:
Alex Sharov 2023-06-02 10:35:26 +07:00 committed by GitHub
parent d56d867b4f
commit 5fb31ae95f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 41 additions and 30 deletions

View File

@ -77,7 +77,7 @@ type SimulatedBackend struct {
pendingHeader *types.Header
gasPool *core.GasPool
pendingBlock *types.Block // Currently pending block that will be imported on request
pendingReader *state.PlainStateReader
pendingReader state.StateReader
pendingReaderTx kv.Tx
pendingState *state.IntraBlockState // Currently pending state that will be the active on request
@ -184,6 +184,7 @@ func (b *SimulatedBackend) emptyPendingBlock() {
panic(err)
}
b.pendingReaderTx = tx
if ethconfig.EnableHistoryV4InTest {
panic("implement me")
//b.pendingReader = state.NewReaderV4(b.pendingReaderTx.(kv.TemporalTx))
@ -562,7 +563,7 @@ func (b *SimulatedBackend) CallContract(ctx context.Context, call ethereum.CallM
}
var res *core.ExecutionResult
if err := b.m.DB.View(context.Background(), func(tx kv.Tx) (err error) {
s := state.New(state.NewPlainStateReader(tx))
s := state.New(b.m.NewStateReader(tx))
res, err = b.callContract(ctx, call, b.pendingBlock, s)
if err != nil {
return err

View File

@ -3,6 +3,7 @@ package initial_state
import (
_ "embed"
"fmt"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/erigon/cl/clparams"

View File

@ -3,6 +3,7 @@ package shuffling
import (
"encoding/binary"
"fmt"
"github.com/ledgerwatch/erigon/cl/phase1/core/state/raw"
"github.com/ledgerwatch/erigon/cl/utils"

View File

@ -3,6 +3,7 @@ package transition
import (
"bytes"
"fmt"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/Giulio2002/bls"

View File

@ -1,12 +1,13 @@
package consensus_tests
import (
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
transition2 "github.com/ledgerwatch/erigon/cl/phase1/core/transition"
"io/fs"
"os"
"testing"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
transition2 "github.com/ledgerwatch/erigon/cl/phase1/core/transition"
"github.com/ledgerwatch/erigon/spectest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

View File

@ -2,10 +2,11 @@ package consensus_tests
import (
"fmt"
"github.com/ledgerwatch/erigon/cl/phase1/core/transition"
"io/fs"
"testing"
"github.com/ledgerwatch/erigon/cl/phase1/core/transition"
"github.com/ledgerwatch/erigon/spectest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

View File

@ -2,10 +2,11 @@ package consensus_tests
import (
"fmt"
"github.com/ledgerwatch/erigon/cl/phase1/core/transition"
"io/fs"
"testing"
"github.com/ledgerwatch/erigon/cl/phase1/core/transition"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/spectest"

View File

@ -5,10 +5,11 @@
package spectest
import (
"github.com/ledgerwatch/erigon/cl/spectest/consensus_tests"
"os"
"testing"
"github.com/ledgerwatch/erigon/cl/spectest/consensus_tests"
"github.com/ledgerwatch/erigon/spectest"
)

View File

@ -61,11 +61,9 @@ import (
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/rawdb/blockio"
"github.com/ledgerwatch/erigon/core/state/historyv2read"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon/core/systemcontracts"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/types/accounts"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/eth/ethconfig"
@ -272,7 +270,7 @@ func NewBackend(stack *node.Node, config *ethconfig.Config, logger log.Logger) (
backend.chainConfig = chainConfig
if config.HistoryV3 {
backend.chainDB, err = temporal.New(backend.chainDB, backend.agg, accounts.ConvertV3toV2, historyv2read.RestoreCodeHash, accounts.DecodeIncarnationFromStorage, systemcontracts.SystemContractCodeLookup[chainConfig.ChainName])
backend.chainDB, err = temporal.New(backend.chainDB, backend.agg, systemcontracts.SystemContractCodeLookup[chainConfig.ChainName])
if err != nil {
return nil, err
}

View File

@ -6,20 +6,20 @@ import (
proto_downloader "github.com/ledgerwatch/erigon-lib/gointerfaces/downloader"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/state"
"github.com/ledgerwatch/erigon/core/rawdb/blockio"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/log/v3"
"github.com/ledgerwatch/erigon/cmd/sentry/sentry"
"github.com/ledgerwatch/erigon/consensus"
"github.com/ledgerwatch/erigon/core/rawdb/blockio"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/eth/stagedsync"
"github.com/ledgerwatch/erigon/ethdb/prune"
"github.com/ledgerwatch/erigon/p2p"
"github.com/ledgerwatch/erigon/turbo/engineapi"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/erigon/turbo/shards"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
"github.com/ledgerwatch/log/v3"
)
func nullStage(firstCycle bool, badBlockUnwind bool, s *stagedsync.StageState, u stagedsync.Unwinder, tx kv.RwTx, logger log.Logger) error {

View File

@ -8,16 +8,14 @@ import (
"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/core/state/historyv2read"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon/core/systemcontracts"
"github.com/ledgerwatch/erigon/core/types/accounts"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"
"github.com/torquem-ch/mdbx-go/mdbx"
"golang.org/x/sync/semaphore"
"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"
@ -92,7 +90,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, accounts.ConvertV3toV2, historyv2read.RestoreCodeHash, accounts.DecodeIncarnationFromStorage, systemcontracts.SystemContractCodeLookup[chain])
tdb, err := temporal.New(db, agg, systemcontracts.SystemContractCodeLookup[chain])
if err != nil {
return nil, err
}

View File

@ -900,7 +900,6 @@ func stageSenders(db kv.RwDB, ctx context.Context, logger log.Logger) error {
}
func stageExec(db kv.RwDB, ctx context.Context, logger log.Logger) error {
chainConfig, historyV3, pm := fromdb.ChainConfig(db), kvcfg.HistoryV3.FromDB(db), fromdb.PruneMode(db)
dirs := datadir.New(datadirCli)
engine, vmConfig, sync, _, _ := newSync(ctx, db, nil /* miningConfig */, logger)
must(sync.SetCurrentStage(stages.Execution))
@ -927,6 +926,7 @@ func stageExec(db kv.RwDB, ctx context.Context, logger log.Logger) error {
s := stage(sync, nil, db, stages.Execution)
logger.Info("Stage", "name", s.ID, "progress", s.BlockNumber)
chainConfig, historyV3, pm := fromdb.ChainConfig(db), kvcfg.HistoryV3.FromDB(db), fromdb.PruneMode(db)
if pruneTo > 0 {
pm.History = prune.Distance(s.BlockNumber - pruneTo)
pm.Receipts = prune.Distance(s.BlockNumber - pruneTo)

View File

@ -20,10 +20,8 @@ import (
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon-lib/kv/rawdbv3"
libstate "github.com/ledgerwatch/erigon-lib/state"
"github.com/ledgerwatch/erigon/core/state/historyv2read"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon/core/systemcontracts"
"github.com/ledgerwatch/erigon/core/types/accounts"
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/rpc/rpccfg"
"github.com/ledgerwatch/erigon/turbo/debug"
@ -398,7 +396,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, accounts.ConvertV3toV2, historyv2read.RestoreCodeHash, accounts.DecodeIncarnationFromStorage, systemcontracts.SystemContractCodeLookup[cc.ChainName])
db, err = temporal.New(rwKv, agg, systemcontracts.SystemContractCodeLookup[cc.ChainName])
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, err
}

View File

@ -61,20 +61,21 @@ import (
// 1. Application - rely on TemporalDB (Ex: ExecutionLayer) or just DB (Ex: TxPool, Sentry, Downloader).
type tRestoreCodeHash func(tx kv.Getter, key, v []byte, force *common.Hash) ([]byte, error)
type tConvertV3toV2 func(v []byte) ([]byte, error)
type tConvertAccount func(v []byte) ([]byte, error)
type tParseIncarnation func(v []byte) (uint64, error)
type DB struct {
kv.RwDB
agg *state.AggregatorV3
convertV3toV2 tConvertV3toV2
convertV3toV2 tConvertAccount
convertV2toV3 tConvertAccount
restoreCodeHash tRestoreCodeHash
parseInc tParseIncarnation
systemContractLookup map[common.Address][]common.CodeRecord
}
func New(db kv.RwDB, agg *state.AggregatorV3, cb1 tConvertV3toV2, cb2 tRestoreCodeHash, cb3 tParseIncarnation, systemContractLookup map[common.Address][]common.CodeRecord) (*DB, error) {
func New(db kv.RwDB, agg *state.AggregatorV3, systemContractLookup map[common.Address][]common.CodeRecord) (*DB, error) {
if !kvcfg.HistoryV3.FromDB(db) {
panic("not supported")
}
@ -95,7 +96,11 @@ func New(db kv.RwDB, agg *state.AggregatorV3, cb1 tConvertV3toV2, cb2 tRestoreCo
}
}
return &DB{RwDB: db, agg: agg, convertV3toV2: cb1, restoreCodeHash: cb2, parseInc: cb3, systemContractLookup: systemContractLookup}, nil
return &DB{RwDB: db, agg: agg,
convertV3toV2: accounts.ConvertV3toV2, convertV2toV3: accounts.ConvertV2toV3,
restoreCodeHash: historyv2read.RestoreCodeHash, parseInc: accounts.DecodeIncarnationFromStorage,
systemContractLookup: systemContractLookup,
}, nil
}
func (db *DB) Agg() *state.AggregatorV3 { return db.agg }
func (db *DB) InternalDB() kv.RwDB { return db.RwDB }
@ -408,6 +413,12 @@ func (tx *Tx) HistoryGet(name kv.History, key []byte, ts uint64) (v []byte, ok b
if err != nil {
return nil, false, err
}
if len(v) > 0 {
v, err = tx.db.convertV2toV3(v)
if err != nil {
return nil, false, err
}
}
return v, true, nil
case StorageHistory:
return tx.aggCtx.ReadAccountStorageNoStateWithRecent2(key, ts, tx.MdbxTx)
@ -504,7 +515,7 @@ func NewTestDB(tb testing.TB, ctx context.Context, dirs datadir.Dirs, gspec *typ
sc = systemcontracts.SystemContractCodeLookup[gspec.Config.ChainName]
}
db, err = New(db, agg, accounts.ConvertV3toV2, historyv2read.RestoreCodeHash, accounts.DecodeIncarnationFromStorage, sc)
db, err = New(db, agg, sc)
if err != nil {
panic(err)
}

View File

@ -84,11 +84,9 @@ import (
"github.com/ledgerwatch/erigon/consensus/merge"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state/historyv2read"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon/core/systemcontracts"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/types/accounts"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/eth/ethconfig"
@ -307,7 +305,7 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
}
if config.HistoryV3 {
backend.chainDB, err = temporal.New(backend.chainDB, agg, accounts.ConvertV3toV2, historyv2read.RestoreCodeHash, accounts.DecodeIncarnationFromStorage, systemcontracts.SystemContractCodeLookup[chainConfig.ChainName])
backend.chainDB, err = temporal.New(backend.chainDB, agg, systemcontracts.SystemContractCodeLookup[chainConfig.ChainName])
if err != nil {
return nil, err
}