mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
e4: step 1 to run tests (#7209)
This commit is contained in:
parent
f541f616e6
commit
592ec1ee0d
@ -32,6 +32,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
state2 "github.com/ledgerwatch/erigon-lib/state"
|
||||
types2 "github.com/ledgerwatch/erigon-lib/types"
|
||||
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
ethereum "github.com/ledgerwatch/erigon"
|
||||
@ -179,6 +180,20 @@ 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()
|
||||
*/
|
||||
}
|
||||
b.pendingReader = state.NewPlainStateReader(olddb.NewObjectDatabase(b.m.DB))
|
||||
b.pendingState = state.New(b.pendingReader)
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ func CreateTestSentry(t *testing.T) (*stages.MockSentry, *core.ChainPack, []*cor
|
||||
)
|
||||
m := stages.MockWithGenesis(t, gspec, key, false)
|
||||
|
||||
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
|
||||
contractBackend := backends.NewTestSimulatedBackendWithConfig(t, gspec.Alloc, gspec.Config, gspec.GasLimit)
|
||||
defer contractBackend.Close()
|
||||
|
||||
// Generate empty chain to have some orphaned blocks for tests
|
||||
|
@ -523,10 +523,6 @@ type StateWriterV4 struct {
|
||||
w *libstate.Aggregator
|
||||
}
|
||||
|
||||
func NewStateWriterV4(w *libstate.Aggregator) {
|
||||
|
||||
}
|
||||
|
||||
func (rw *StateReaderV4) ReadAccountData(address libcommon.Address) (*accounts.Account, error) {
|
||||
enc, err := rw.ac.ReadAccountData(address.Bytes(), rw.roTx)
|
||||
if err != nil {
|
||||
|
@ -24,9 +24,8 @@ 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/eth/ethconfig"
|
||||
|
||||
"github.com/ledgerwatch/erigon/core/systemcontracts"
|
||||
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
|
||||
@ -434,8 +433,19 @@ func GenerateChain(config *chain.Config, parent *types.Block, engine consensus.E
|
||||
for i := 0; i < n; i++ {
|
||||
var stateReader state.StateReader
|
||||
var stateWriter state.StateWriter
|
||||
if ethconfig.EnableHistoryV4InTest {
|
||||
|
||||
if ethconfig.EnableHistoryV4InTest {
|
||||
panic("implent me")
|
||||
/*
|
||||
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()
|
||||
*/
|
||||
} else {
|
||||
stateReader = state.NewPlainStateReader(tx)
|
||||
stateWriter = state.NewPlainStateWriter(tx, nil, parent.NumberU64()+uint64(i)+1)
|
||||
@ -445,6 +455,19 @@ func GenerateChain(config *chain.Config, parent *types.Block, engine consensus.E
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("generating block %d: %w", i, err)
|
||||
}
|
||||
/*
|
||||
if ethconfig.EnableHistoryV4InTest {
|
||||
logEvery := time.NewTicker(20 * time.Second)
|
||||
defer logEvery.Stop()
|
||||
if err := rs.Flush(context.Background(), tx, "", logEvery); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//if err := rs.ApplyHistory(txTask, agg); err != nil {
|
||||
// return resultSize, outputTxNum, conflicts, processedBlockNum, fmt.Errorf("StateV3.Apply: %w", err)
|
||||
//}
|
||||
}
|
||||
*/
|
||||
headers[i] = block.Header()
|
||||
blocks[i] = block
|
||||
receipts[i] = receipt
|
||||
|
@ -71,6 +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) BeginTemporalRo(ctx context.Context) (kv.TemporalTx, error) {
|
||||
kvTx, err := db.RwDB.BeginRo(ctx)
|
||||
|
@ -1,4 +1,4 @@
|
||||
//go:build !erigon3 && !erigon4
|
||||
//go:build !erigon3 && !e3 && !erigon4 && !e4
|
||||
|
||||
package ethconfig
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//go:build erigon3
|
||||
//go:build erigon3 || e3
|
||||
|
||||
package ethconfig
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//go:build erigon4
|
||||
//go:build erigon4 || e4
|
||||
|
||||
package ethconfig
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
||||
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
|
||||
)
|
||||
|
||||
@ -109,6 +110,7 @@ func DefaultStages(ctx context.Context, snapshots SnapshotsCfg, headers HeadersC
|
||||
{
|
||||
ID: stages.HashState,
|
||||
Description: "Hash the key in the state",
|
||||
Disabled: bodies.historyV3 && ethconfig.EnableHistoryV4InTest,
|
||||
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx, quiet bool) error {
|
||||
return SpawnHashStateStage(s, tx, hashState, ctx, quiet)
|
||||
},
|
||||
@ -122,6 +124,7 @@ func DefaultStages(ctx context.Context, snapshots SnapshotsCfg, headers HeadersC
|
||||
{
|
||||
ID: stages.IntermediateHashes,
|
||||
Description: "Generate intermediate hashes and computing state root",
|
||||
Disabled: bodies.historyV3 && ethconfig.EnableHistoryV4InTest,
|
||||
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx, quiet bool) error {
|
||||
if exec.chainConfig.IsPrague(0) {
|
||||
_, err := SpawnVerkleTrie(s, u, tx, trieCfg, ctx)
|
||||
|
@ -9,12 +9,11 @@ import (
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
state2 "github.com/ledgerwatch/erigon-lib/state"
|
||||
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/ledgerwatch/erigon/core/state"
|
||||
"github.com/ledgerwatch/erigon/core/types/accounts"
|
||||
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -51,13 +50,42 @@ func compareDomain(t *testing.T, agg *state2.AggregatorV3, db1, db2 kv.Tx, bucke
|
||||
ac.DeprecatedLatestAcc(db1.(kv.RwTx), func(k, v []byte) {
|
||||
bucket1[string(k)] = v
|
||||
})
|
||||
|
||||
require.True(t, len(bucket1) > 0)
|
||||
bucket2 := make(map[string][]byte)
|
||||
ac.DeprecatedLatestAcc(db2.(kv.RwTx), func(k, v []byte) {
|
||||
bucket2[string(k)] = v
|
||||
})
|
||||
assert.Equalf(t, bucket1, bucket2, "bucket %q", bucketName)
|
||||
|
||||
assert.Equalf(t, bucket1 , bucket2 , "bucket %q", bucketName)
|
||||
bucket1 = make(map[string][]byte)
|
||||
ac.DeprecatedLatestSt(db1.(kv.RwTx), func(k, v []byte) {
|
||||
bucket1[string(k)] = v
|
||||
})
|
||||
bucket2 = make(map[string][]byte)
|
||||
ac.DeprecatedLatestSt(db2.(kv.RwTx), func(k, v []byte) {
|
||||
bucket2[string(k)] = v
|
||||
})
|
||||
assert.Equalf(t, bucket1, bucket2, "bucket %q", bucketName)
|
||||
case kv.PlainContractCode:
|
||||
bucket1 := make(map[string][]byte)
|
||||
ac.DeprecatedLatestCode(db1.(kv.RwTx), func(k, v []byte) {
|
||||
bucket1[string(k)] = v
|
||||
})
|
||||
bucket2 := make(map[string][]byte)
|
||||
ac.DeprecatedLatestCode(db2.(kv.RwTx), func(k, v []byte) {
|
||||
bucket2[string(k)] = v
|
||||
})
|
||||
assert.Equalf(t, bucket1, bucket2, "bucket %q", bucketName)
|
||||
|
||||
bucket1 = make(map[string][]byte)
|
||||
ac.DeprecatedLatestSt(db1.(kv.RwTx), func(k, v []byte) {
|
||||
bucket1[string(k)] = v
|
||||
})
|
||||
bucket2 = make(map[string][]byte)
|
||||
ac.DeprecatedLatestSt(db2.(kv.RwTx), func(k, v []byte) {
|
||||
bucket2[string(k)] = v
|
||||
})
|
||||
assert.Equalf(t, bucket1, bucket2, "bucket %q", bucketName)
|
||||
default:
|
||||
panic(bucketName)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user