Skip to content
Merged
4 changes: 2 additions & 2 deletions cmd/pics/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func initialState1() error {
// this code generates a log
signer = types.MakeSigner(chain.AllProtocolChanges, 1, 0)
)
m := mock.MockWithGenesis(nil, gspec, key, false)
m := mock.MockWithGenesis(nil, gspec, key)
defer m.DB.Close()

contractBackend := backends.NewSimulatedBackendWithConfig(nil, gspec.Alloc, gspec.Config, gspec.GasLimit)
Expand Down Expand Up @@ -418,7 +418,7 @@ func initialState1() error {
if err != nil {
return err
}
m2 := mock.MockWithGenesis(nil, gspec, key, false)
m2 := mock.MockWithGenesis(nil, gspec, key)
defer m2.DB.Close()

if err = hexPalette(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpcdaemon/rpcdaemontest/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func CreateTestSentry(t *testing.T) (*mock.MockSentry, *blockgen.ChainPack, []*b
GasLimit: 10000000,
}
)
m := mock.MockWithGenesis(t, gspec, key, false)
m := mock.MockWithGenesis(t, gspec, key)

contractBackend := backends.NewSimulatedBackendWithConfig(t, gspec.Alloc, gspec.Config, gspec.GasLimit)

Expand Down Expand Up @@ -431,7 +431,7 @@ func CreateTestSentryForTraces(t *testing.T) *mock.MockSentry {
},
}
)
m := mock.MockWithGenesis(t, gspec, key, false)
m := mock.MockWithGenesis(t, gspec, key)
chain, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 1, func(i int, b *blockgen.BlockGen) {
b.SetCoinbase(common.Address{1})
// One transaction to AAAA
Expand Down Expand Up @@ -531,7 +531,7 @@ func CreateTestSentryForTracesCollision(t *testing.T) *mock.MockSentry {
},
},
}
m := mock.MockWithGenesis(t, gspec, key, false)
m := mock.MockWithGenesis(t, gspec, key)
chain, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 1, func(i int, b *blockgen.BlockGen) {
b.SetCoinbase(common.Address{1})
// One transaction to AA, to kill it
Expand Down
4 changes: 0 additions & 4 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1922,10 +1922,6 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
cfg.Snapshot.ChainName = chain
nodeConfig.Http.Snap = cfg.Snapshot

if ctx.Command.Name == "import" {
cfg.ImportMode = true
}

setEtherbase(ctx, cfg)
setGPO(ctx, &cfg.GPO)

Expand Down
2 changes: 1 addition & 1 deletion db/snapshotsync/freezeblocks/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func createDumpTestKV(t *testing.T, chainConfig *chain.Config, chainSize int) *m
signer = types.LatestSigner(gspec.Config)
)

m := mock.MockWithGenesisPruneMode(t, gspec, key, chainSize, prune.DefaultMode, false)
m := mock.MockWithGenesisPruneMode(t, gspec, key, chainSize, prune.DefaultMode)

// Generate testing blocks
chain, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, chainSize, func(i int, b *blockgen.BlockGen) {
Expand Down
2 changes: 1 addition & 1 deletion execution/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func NewSimulatedBackendWithConfig(t *testing.T, alloc types.GenesisAlloc, confi
genesis := types.Genesis{Config: config, GasLimit: gasLimit, Alloc: alloc}
engine := ethash.NewFaker()
//SimulatedBackend - it's remote blockchain node. This is reason why it has own `MockSentry` and own `DB` (even if external unit-test have one already)
m := mock.MockWithGenesisEngine(t, &genesis, engine, false)
m := mock.MockWithGenesisEngine(t, &genesis, engine)

backend := &SimulatedBackend{
m: m,
Expand Down
89 changes: 87 additions & 2 deletions execution/execmodule/ethereum_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package execmodule_test

import (
"bytes"
"context"
"encoding/binary"
"errors"
Expand All @@ -37,11 +38,14 @@ import (
"github.com/erigontech/erigon/execution/commitment/commitmentdb"
"github.com/erigontech/erigon/execution/execmodule"
eth1utils "github.com/erigontech/erigon/execution/execmodule/moduleutil"
"github.com/erigontech/erigon/execution/protocol/params"
"github.com/erigontech/erigon/execution/tests/blockgen"
"github.com/erigontech/erigon/execution/tests/mock"
"github.com/erigontech/erigon/execution/types"
"github.com/erigontech/erigon/node/gointerfaces"
"github.com/erigontech/erigon/node/gointerfaces/executionproto"
"github.com/erigontech/erigon/node/gointerfaces/txpoolproto"
"github.com/erigontech/erigon/node/gointerfaces/typesproto"
)

func TestValidateChainWithLastTxNumOfBlockAtStepBoundary(t *testing.T) {
Expand All @@ -61,7 +65,7 @@ func TestValidateChainWithLastTxNumOfBlockAtStepBoundary(t *testing.T) {
},
}
stepSize := uint64(5) // 2 for block 0 (0,1) and 3 for block 1 (2,3,4)
m := mock.MockWithGenesis(t, genesis, privKey, false, mock.WithStepSize(stepSize))
m := mock.MockWithGenesis(t, genesis, privKey, mock.WithStepSize(stepSize))
chainPack, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 1, func(i int, b *blockgen.BlockGen) {
tx, err := types.SignTx(
types.NewTransaction(0, senderAddr, uint256.NewInt(0), 50000, uint256.NewInt(m.Genesis.BaseFee().Uint64()), nil),
Expand Down Expand Up @@ -130,7 +134,7 @@ func TestValidateChainAndUpdateForkChoiceWithSideForksThatGoBackAndForwardInHeig
senderAddr2: {Balance: new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)},
},
}
m := mock.MockWithGenesis(t, genesis, privKey, false)
m := mock.MockWithGenesis(t, genesis, privKey)
longerFork, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 2, func(i int, b *blockgen.BlockGen) {
tx, err := types.SignTx(
types.NewTransaction(uint64(i), senderAddr, uint256.NewInt(1_000), 50000, uint256.NewInt(m.Genesis.BaseFee().Uint64()), nil),
Expand Down Expand Up @@ -171,6 +175,61 @@ func TestValidateChainAndUpdateForkChoiceWithSideForksThatGoBackAndForwardInHeig
require.NoError(t, err)
}

func TestAssembleBlock(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
t.Parallel()
ctx := t.Context()
m := mock.MockWithTxPoolOsaka(t)
exec := m.Eth1ExecutionService
txpool := m.TxPoolGrpcServer
chainPack, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 1, func(i int, gen *blockgen.BlockGen) {
// In block 1, addr1 sends addr2 some ether.
tx, err := types.SignTx(types.NewTransaction(gen.TxNonce(m.Address), common.Address{1}, uint256.NewInt(10_000), params.TxGas, uint256.NewInt(m.Genesis.BaseFee().Uint64()), nil), *types.LatestSignerForChainID(m.ChainConfig.ChainID), m.Key)
require.NoError(t, err)
gen.AddTx(tx)
})
require.NoError(t, err)
err = m.InsertChain(chainPack)
require.NoError(t, err)
tx2, err := types.SignTx(types.NewTransaction(1, common.Address{1}, uint256.NewInt(10_000), params.TxGas, uint256.NewInt(chainPack.TopBlock.BaseFee().Uint64()), nil), *types.LatestSignerForChainID(m.ChainConfig.ChainID), m.Key)
require.NoError(t, err)
tx3, err := types.SignTx(types.NewTransaction(2, common.Address{1}, uint256.NewInt(10_000), params.TxGas, uint256.NewInt(chainPack.TopBlock.BaseFee().Uint64()), nil), *types.LatestSignerForChainID(m.ChainConfig.ChainID), m.Key)
require.NoError(t, err)
rlpTxs := make([][]byte, 2)
for i, tx := range []types.Transaction{tx2, tx3} {
var buf bytes.Buffer
err = tx.EncodeRLP(&buf)
require.NoError(t, err)
rlpTxs[i] = buf.Bytes()
}
r, err := txpool.Add(ctx, &txpoolproto.AddRequest{
RlpTxs: rlpTxs,
})
require.NoError(t, err)
require.Len(t, r.Errors, 2)
for _, err := range r.Errors {
require.Equal(t, "success", err)
}
require.Len(t, r.Imported, 2)
for _, res := range r.Imported {
require.Equal(t, txpoolproto.ImportResult_SUCCESS, res)
}
payloadId, err := assembleBlock(ctx, exec, &executionproto.AssembleBlockRequest{
ParentHash: gointerfaces.ConvertHashToH256(chainPack.TopBlock.Hash()),
Timestamp: chainPack.TopBlock.Header().Time + 1,
PrevRandao: gointerfaces.ConvertHashToH256(chainPack.TopBlock.Header().MixDigest),
SuggestedFeeRecipient: gointerfaces.ConvertAddressToH160(common.Address{1}),
Withdrawals: make([]*typesproto.Withdrawal, 0),
})
require.NoError(t, err)
blockData, err := getAssembledBlock(ctx, exec, payloadId)
require.NoError(t, err)
require.Equal(t, uint64(2), blockData.ExecutionPayload.BlockNumber)
require.Len(t, blockData.ExecutionPayload.Transactions, 2)
}

func insertBlocks(ctx context.Context, exec *execmodule.EthereumExecutionModule, chainPack *blockgen.ChainPack) (*executionproto.InsertionResult, error) {
blocks := make([]*executionproto.Block, len(chainPack.Blocks))
for i, b := range chainPack.Blocks {
Expand Down Expand Up @@ -242,6 +301,32 @@ func insertValidateAndUfc1By1(ctx context.Context, exec *execmodule.EthereumExec
return nil
}

func assembleBlock(ctx context.Context, exec *execmodule.EthereumExecutionModule, req *executionproto.AssembleBlockRequest) (uint64, error) {
return retryBusy(ctx, func() (uint64, executionproto.ExecutionStatus, error) {
r, err := exec.AssembleBlock(ctx, req)
if err != nil {
return 0, 0, err
}
if r.Busy {
return 0, executionproto.ExecutionStatus_Busy, nil
}
return r.Id, executionproto.ExecutionStatus_Success, nil
})
}

func getAssembledBlock(ctx context.Context, exe *execmodule.EthereumExecutionModule, payloadId uint64) (*executionproto.AssembledBlockData, error) {
return retryBusy(ctx, func() (*executionproto.AssembledBlockData, executionproto.ExecutionStatus, error) {
br, err := exe.GetAssembledBlock(ctx, &executionproto.GetAssembledBlockRequest{Id: payloadId})
if err != nil {
return nil, 0, err
}
if br.Busy {
return nil, executionproto.ExecutionStatus_Busy, nil
}
return br.Data, executionproto.ExecutionStatus_Success, nil
})
}

func retryBusy[T any](ctx context.Context, f func() (T, executionproto.ExecutionStatus, error)) (T, error) {
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions execution/protocol/rules/aura/aura_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestEmptyBlock(t *testing.T) {
auraDB := memdb.NewTestDB(t, dbcfg.ChainDB)
engine, err := aura.NewAuRa(chainConfig.Aura, auraDB)
require.NoError(err)
m := mock.MockWithGenesisEngine(t, genesis, engine, false)
m := mock.MockWithGenesisEngine(t, genesis, engine)

time := uint64(1539016985)
header := builder.MakeEmptyHeader(genesisBlock.Header(), chainConfig, time, nil)
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestAuRaSkipGasLimit(t *testing.T) {
auraDB := memdb.NewTestDB(t, dbcfg.ChainDB)
engine, err := aura.NewAuRa(chainConfig.Aura, auraDB)
require.NoError(err)
m := mock.MockWithGenesisEngine(t, genesis, engine, false)
m := mock.MockWithGenesisEngine(t, genesis, engine)

difficlty, _ := new(big.Int).SetString("340282366920938463463374607431768211454", 10)
//Populate a sample valid header for a Pre-merge block
Expand Down
2 changes: 1 addition & 1 deletion execution/protocol/rules/clique/clique_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestReimportMirroredState(t *testing.T) {
Config: chainspec.AllCliqueProtocolChanges,
}
copy(genspec.ExtraData[clique.ExtraVanity:], addr[:])
m := mock.MockWithGenesisEngine(t, genspec, engine, false)
m := mock.MockWithGenesisEngine(t, genspec, engine)

// Generate a batch of blocks, each properly signed
getHeader := func(hash common.Hash, number uint64) (h *types.Header, err error) {
Expand Down
2 changes: 1 addition & 1 deletion execution/protocol/rules/clique/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func TestClique(t *testing.T) {
engine := clique.New(&config, chainspec.CliqueSnapshot, cliqueDB, log.New())
engine.FakeDiff = true
// Create a pristine blockchain with the genesis injected
m := mock.MockWithGenesisEngine(t, genesis, engine, false)
m := mock.MockWithGenesisEngine(t, genesis, engine)

chain, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, len(tt.votes), func(j int, gen *blockgen.BlockGen) {
// Cast the vote contained in this block
Expand Down
2 changes: 1 addition & 1 deletion execution/rlp/rlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func getBlock(tb testing.TB, transactions int, uncles int, dataSize int, tmpDir
Alloc: types.GenesisAlloc{address: {Balance: funds}},
}
)
m := mock.MockWithGenesis(tb, gspec, key, false)
m := mock.MockWithGenesis(tb, gspec, key)
genesis := m.Genesis
db := m.DB

Expand Down
12 changes: 6 additions & 6 deletions execution/stagedsync/default_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
"github.com/erigontech/erigon/execution/stagedsync/stages"
)

func DefaultStages(ctx context.Context,
func DefaultStages(
ctx context.Context,
snapshots SnapshotsCfg,
headers HeadersCfg,
blockHashCfg BlockHashesCfg,
Expand All @@ -36,7 +37,6 @@ func DefaultStages(ctx context.Context,
exec ExecuteBlockCfg,
txLookup TxLookupCfg,
finish FinishCfg,
test bool,
) []*Stage {
return []*Stage{
{
Expand All @@ -62,10 +62,10 @@ func DefaultStages(ctx context.Context,
if badBlockUnwind {
return nil
}
return SpawnStageHeaders(s, u, ctx, tx, headers, test, logger)
return SpawnStageHeaders(s, u, ctx, tx, headers, logger)
},
Unwind: func(u *UnwindState, s *StageState, sd *execctx.SharedDomains, tx kv.TemporalRwTx, logger log.Logger) error {
return HeadersUnwind(ctx, u, s, tx, headers, test)
return HeadersUnwind(ctx, u, s, tx, headers)
},
Prune: func(ctx context.Context, p *PruneState, tx kv.RwTx, timeout time.Duration, logger log.Logger) error {
return nil
Expand All @@ -88,7 +88,7 @@ func DefaultStages(ctx context.Context,
ID: stages.Bodies,
Description: "Download block bodies",
Forward: func(badBlockUnwind bool, s *StageState, u Unwinder, sd *execctx.SharedDomains, tx kv.TemporalRwTx, logger log.Logger) error {
return BodiesForward(s, u, ctx, tx, bodies, test, logger)
return BodiesForward(s, u, ctx, tx, bodies, logger)
},
Unwind: func(u *UnwindState, s *StageState, sd *execctx.SharedDomains, tx kv.TemporalRwTx, logger log.Logger) error {
return UnwindBodiesStage(u, tx, bodies)
Expand Down Expand Up @@ -288,7 +288,7 @@ func StateStages(ctx context.Context, headers HeadersCfg, bodies BodiesCfg, bloc
return nil
},
Unwind: func(u *UnwindState, s *StageState, sd *execctx.SharedDomains, tx kv.TemporalRwTx, logger log.Logger) error {
return HeadersUnwind(ctx, u, s, tx, headers, false)
return HeadersUnwind(ctx, u, s, tx, headers)
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion execution/stagedsync/headerdownload/header_algo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestSideChainInsert(t *testing.T) {
address: {Balance: funds},
},
}
m := mock.MockWithGenesis(t, gspec, key, false)
m := mock.MockWithGenesis(t, gspec, key)
db := m.DB
genesis := m.Genesis
tx, err := db.BeginRw(context.Background())
Expand Down
6 changes: 1 addition & 5 deletions execution/stagedsync/stage_bodies.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func StageBodiesCfg(bd *bodydownload.BodyDownload,
}

// BodiesForward progresses Bodies stage in the forward direction
func BodiesForward(s *StageState, u Unwinder, ctx context.Context, tx kv.RwTx, cfg BodiesCfg, test bool, logger log.Logger) error {
func BodiesForward(s *StageState, u Unwinder, ctx context.Context, tx kv.RwTx, cfg BodiesCfg, logger log.Logger) error {
var doUpdate bool

startTime := time.Now()
Expand Down Expand Up @@ -257,10 +257,6 @@ func BodiesForward(s *StageState, u Unwinder, ctx context.Context, tx kv.RwTx, c
if bodyProgress == headerProgress {
return true, nil
}
if test {
stopped = true
return true, nil
}
firstCycle := s.CurrentSyncCycle.IsInitialCycle
if !firstCycle && s.BlockNumber > 0 && noProgressCount >= 5 {
return true, nil
Expand Down
Loading
Loading