mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
e4: small tests preparations (#7220)
This commit is contained in:
parent
97eccd913c
commit
04b5c0c67b
@ -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
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -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,6 +176,13 @@ func WriteGenesisState(g *types.Genesis, tx kv.RwTx, tmpDir string) (*types.Bloc
|
||||
if 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
|
||||
@ -185,22 +193,24 @@ func WriteGenesisState(g *types.Genesis, tx kv.RwTx, tmpDir string) (*types.Bloc
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
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 := blockWriter.WriteHistory(); err != nil {
|
||||
if err := csw.WriteHistory(); err != nil {
|
||||
return nil, statedb, fmt.Errorf("cannot write history: %w", err)
|
||||
}
|
||||
}
|
||||
return block, statedb, nil
|
||||
}
|
||||
func MustCommitGenesis(g *types.Genesis, db kv.RwDB, tmpDir string) *types.Block {
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user