e4: small tests preparations (#7220)

This commit is contained in:
Alex Sharov 2023-03-31 09:19:56 +07:00 committed by GitHub
parent 97eccd913c
commit 04b5c0c67b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 31 deletions

View File

@ -179,20 +179,6 @@ func (b *SimulatedBackend) emptyPendingBlock() {
b.pendingReceipts = chain.Receipts[0]
b.pendingHeader = chain.Headers[0]
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit)
if ethconfig.EnableHistoryV4InTest {
panic("implement domain state reader")
/*
agg := db.(*temporal.DB).GetAgg()
agg.SetTx(tx)
rs := state.NewStateV3("", agg.BufferedDomains())
stateWriter = state.NewStateWriterV3(rs)
r := state.NewStateReaderV3(rs)
r.SetTx(tx)
stateReader = r
defer agg.StartUnbufferedWrites().FinishWrites()
*/
}
if b.pendingReaderTx != nil {
b.pendingReaderTx.Rollback()
}
@ -201,7 +187,12 @@ func (b *SimulatedBackend) emptyPendingBlock() {
panic(err)
}
b.pendingReaderTx = tx
b.pendingReader = state.NewPlainStateReader(b.pendingReaderTx)
if ethconfig.EnableHistoryV4InTest {
panic("implement me")
//b.pendingReader = state.NewReaderV4(b.pendingReaderTx.(kv.TemporalTx))
} else {
b.pendingReader = state.NewPlainStateReader(b.pendingReaderTx)
}
b.pendingState = state.New(b.pendingReader)
}

View File

@ -40,6 +40,7 @@ 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/params/networkname"
"github.com/ledgerwatch/erigon/turbo/trie"
@ -175,31 +176,40 @@ func WriteGenesisState(g *types.Genesis, tx kv.RwTx, tmpDir string) (*types.Bloc
if err != nil {
return nil, nil, err
}
for addr, account := range g.Alloc {
if len(account.Code) > 0 || len(account.Storage) > 0 {
// Special case for weird tests - inaccessible storage
var b [8]byte
binary.BigEndian.PutUint64(b[:], state.FirstContractIncarnation)
if err := tx.Put(kv.IncarnationMap, addr[:], b[:]); err != nil {
return nil, nil, err
var stateWriter state.StateWriter
if ethconfig.EnableHistoryV4InTest {
panic("implement me")
//tx.(*temporal.Tx).Agg().SetTxNum(0)
//stateWriter = state.NewWriterV4(tx.(kv.TemporalTx))
//defer tx.(*temporal.Tx).Agg().StartUnbufferedWrites().FinishWrites()
} else {
for addr, account := range g.Alloc {
if len(account.Code) > 0 || len(account.Storage) > 0 {
// Special case for weird tests - inaccessible storage
var b [8]byte
binary.BigEndian.PutUint64(b[:], state.FirstContractIncarnation)
if err := tx.Put(kv.IncarnationMap, addr[:], b[:]); err != nil {
return nil, nil, err
}
}
}
stateWriter = state.NewPlainStateWriter(tx, tx, 0)
}
if block.Number().Sign() != 0 {
return nil, statedb, fmt.Errorf("can't commit genesis block with number > 0")
}
blockWriter := state.NewPlainStateWriter(tx, tx, 0)
if err := statedb.CommitBlock(&chain.Rules{}, blockWriter); err != nil {
if err := statedb.CommitBlock(&chain.Rules{}, stateWriter); err != nil {
return nil, statedb, fmt.Errorf("cannot write state: %w", err)
}
if err := blockWriter.WriteChangeSets(); err != nil {
return nil, statedb, fmt.Errorf("cannot write change sets: %w", err)
}
if err := blockWriter.WriteHistory(); err != nil {
return nil, statedb, fmt.Errorf("cannot write history: %w", err)
if csw, ok := stateWriter.(state.WriterWithChangeSets); ok {
if err := csw.WriteChangeSets(); err != nil {
return nil, statedb, fmt.Errorf("cannot write change sets: %w", err)
}
if err := csw.WriteHistory(); err != nil {
return nil, statedb, fmt.Errorf("cannot write history: %w", err)
}
}
return block, statedb, nil
}

View File

@ -71,7 +71,7 @@ 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
}
func (db *DB) GetAgg() *state.AggregatorV3 { return db.agg }
func (db *DB) Agg() *state.AggregatorV3 { return db.agg }
func (db *DB) BeginTemporalRo(ctx context.Context) (kv.TemporalTx, error) {
kvTx, err := db.RwDB.BeginRo(ctx)
@ -162,6 +162,8 @@ type Tx struct {
resourcesToClose []kv.Closer
}
func (tx *Tx) AggCtx() *state.AggregatorV3Context { return tx.agg }
func (tx *Tx) Agg() *state.AggregatorV3 { return tx.db.agg }
func (tx *Tx) Rollback() {
for _, closer := range tx.resourcesToClose {
closer.Close()