Skip to content

Commit fe10a59

Browse files
authored
execution/stagedsync: remove unused test arg in StateStep and move MockSentry closer to PoS (#19010)
1 parent e423b87 commit fe10a59

38 files changed

+340
-854
lines changed

cmd/pics/state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func initialState1() error {
289289
// this code generates a log
290290
signer = types.MakeSigner(chain.AllProtocolChanges, 1, 0)
291291
)
292-
m := mock.MockWithGenesis(nil, gspec, key, false)
292+
m := mock.MockWithGenesis(nil, gspec, key)
293293
defer m.DB.Close()
294294

295295
contractBackend := backends.NewSimulatedBackendWithConfig(nil, gspec.Alloc, gspec.Config, gspec.GasLimit)
@@ -418,7 +418,7 @@ func initialState1() error {
418418
if err != nil {
419419
return err
420420
}
421-
m2 := mock.MockWithGenesis(nil, gspec, key, false)
421+
m2 := mock.MockWithGenesis(nil, gspec, key)
422422
defer m2.DB.Close()
423423

424424
if err = hexPalette(); err != nil {

cmd/rpcdaemon/rpcdaemontest/test_util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func CreateTestSentry(t *testing.T) (*mock.MockSentry, *blockgen.ChainPack, []*b
101101
GasLimit: 10000000,
102102
}
103103
)
104-
m := mock.MockWithGenesis(t, gspec, key, false)
104+
m := mock.MockWithGenesis(t, gspec, key)
105105

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

@@ -431,7 +431,7 @@ func CreateTestSentryForTraces(t *testing.T) *mock.MockSentry {
431431
},
432432
}
433433
)
434-
m := mock.MockWithGenesis(t, gspec, key, false)
434+
m := mock.MockWithGenesis(t, gspec, key)
435435
chain, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 1, func(i int, b *blockgen.BlockGen) {
436436
b.SetCoinbase(common.Address{1})
437437
// One transaction to AAAA
@@ -531,7 +531,7 @@ func CreateTestSentryForTracesCollision(t *testing.T) *mock.MockSentry {
531531
},
532532
},
533533
}
534-
m := mock.MockWithGenesis(t, gspec, key, false)
534+
m := mock.MockWithGenesis(t, gspec, key)
535535
chain, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 1, func(i int, b *blockgen.BlockGen) {
536536
b.SetCoinbase(common.Address{1})
537537
// One transaction to AA, to kill it

cmd/utils/flags.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,10 +1922,6 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
19221922
cfg.Snapshot.ChainName = chain
19231923
nodeConfig.Http.Snap = cfg.Snapshot
19241924

1925-
if ctx.Command.Name == "import" {
1926-
cfg.ImportMode = true
1927-
}
1928-
19291925
setEtherbase(ctx, cfg)
19301926
setGPO(ctx, &cfg.GPO)
19311927

db/snapshotsync/freezeblocks/dump_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func createDumpTestKV(t *testing.T, chainConfig *chain.Config, chainSize int) *m
277277
signer = types.LatestSigner(gspec.Config)
278278
)
279279

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

282282
// Generate testing blocks
283283
chain, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, chainSize, func(i int, b *blockgen.BlockGen) {

execution/abi/bind/backends/simulated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func NewSimulatedBackendWithConfig(t *testing.T, alloc types.GenesisAlloc, confi
105105
genesis := types.Genesis{Config: config, GasLimit: gasLimit, Alloc: alloc}
106106
engine := ethash.NewFaker()
107107
//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)
108-
m := mock.MockWithGenesisEngine(t, &genesis, engine, false)
108+
m := mock.MockWithGenesisEngine(t, &genesis, engine)
109109

110110
backend := &SimulatedBackend{
111111
m: m,

execution/execmodule/ethereum_execution_test.go

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package execmodule_test
1818

1919
import (
20+
"bytes"
2021
"context"
2122
"encoding/binary"
2223
"errors"
@@ -37,11 +38,14 @@ import (
3738
"github.com/erigontech/erigon/execution/commitment/commitmentdb"
3839
"github.com/erigontech/erigon/execution/execmodule"
3940
eth1utils "github.com/erigontech/erigon/execution/execmodule/moduleutil"
41+
"github.com/erigontech/erigon/execution/protocol/params"
4042
"github.com/erigontech/erigon/execution/tests/blockgen"
4143
"github.com/erigontech/erigon/execution/tests/mock"
4244
"github.com/erigontech/erigon/execution/types"
4345
"github.com/erigontech/erigon/node/gointerfaces"
4446
"github.com/erigontech/erigon/node/gointerfaces/executionproto"
47+
"github.com/erigontech/erigon/node/gointerfaces/txpoolproto"
48+
"github.com/erigontech/erigon/node/gointerfaces/typesproto"
4549
)
4650

4751
func TestValidateChainWithLastTxNumOfBlockAtStepBoundary(t *testing.T) {
@@ -61,7 +65,7 @@ func TestValidateChainWithLastTxNumOfBlockAtStepBoundary(t *testing.T) {
6165
},
6266
}
6367
stepSize := uint64(5) // 2 for block 0 (0,1) and 3 for block 1 (2,3,4)
64-
m := mock.MockWithGenesis(t, genesis, privKey, false, mock.WithStepSize(stepSize))
68+
m := mock.MockWithGenesis(t, genesis, privKey, mock.WithStepSize(stepSize))
6569
chainPack, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 1, func(i int, b *blockgen.BlockGen) {
6670
tx, err := types.SignTx(
6771
types.NewTransaction(0, senderAddr, uint256.NewInt(0), 50000, uint256.NewInt(m.Genesis.BaseFee().Uint64()), nil),
@@ -130,7 +134,7 @@ func TestValidateChainAndUpdateForkChoiceWithSideForksThatGoBackAndForwardInHeig
130134
senderAddr2: {Balance: new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)},
131135
},
132136
}
133-
m := mock.MockWithGenesis(t, genesis, privKey, false)
137+
m := mock.MockWithGenesis(t, genesis, privKey)
134138
longerFork, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 2, func(i int, b *blockgen.BlockGen) {
135139
tx, err := types.SignTx(
136140
types.NewTransaction(uint64(i), senderAddr, uint256.NewInt(1_000), 50000, uint256.NewInt(m.Genesis.BaseFee().Uint64()), nil),
@@ -171,6 +175,61 @@ func TestValidateChainAndUpdateForkChoiceWithSideForksThatGoBackAndForwardInHeig
171175
require.NoError(t, err)
172176
}
173177

178+
func TestAssembleBlock(t *testing.T) {
179+
if testing.Short() {
180+
t.Skip("skipping test in short mode")
181+
}
182+
t.Parallel()
183+
ctx := t.Context()
184+
m := mock.MockWithTxPoolOsaka(t)
185+
exec := m.Eth1ExecutionService
186+
txpool := m.TxPoolGrpcServer
187+
chainPack, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 1, func(i int, gen *blockgen.BlockGen) {
188+
// In block 1, addr1 sends addr2 some ether.
189+
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)
190+
require.NoError(t, err)
191+
gen.AddTx(tx)
192+
})
193+
require.NoError(t, err)
194+
err = m.InsertChain(chainPack)
195+
require.NoError(t, err)
196+
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)
197+
require.NoError(t, err)
198+
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)
199+
require.NoError(t, err)
200+
rlpTxs := make([][]byte, 2)
201+
for i, tx := range []types.Transaction{tx2, tx3} {
202+
var buf bytes.Buffer
203+
err = tx.EncodeRLP(&buf)
204+
require.NoError(t, err)
205+
rlpTxs[i] = buf.Bytes()
206+
}
207+
r, err := txpool.Add(ctx, &txpoolproto.AddRequest{
208+
RlpTxs: rlpTxs,
209+
})
210+
require.NoError(t, err)
211+
require.Len(t, r.Errors, 2)
212+
for _, err := range r.Errors {
213+
require.Equal(t, "success", err)
214+
}
215+
require.Len(t, r.Imported, 2)
216+
for _, res := range r.Imported {
217+
require.Equal(t, txpoolproto.ImportResult_SUCCESS, res)
218+
}
219+
payloadId, err := assembleBlock(ctx, exec, &executionproto.AssembleBlockRequest{
220+
ParentHash: gointerfaces.ConvertHashToH256(chainPack.TopBlock.Hash()),
221+
Timestamp: chainPack.TopBlock.Header().Time + 1,
222+
PrevRandao: gointerfaces.ConvertHashToH256(chainPack.TopBlock.Header().MixDigest),
223+
SuggestedFeeRecipient: gointerfaces.ConvertAddressToH160(common.Address{1}),
224+
Withdrawals: make([]*typesproto.Withdrawal, 0),
225+
})
226+
require.NoError(t, err)
227+
blockData, err := getAssembledBlock(ctx, exec, payloadId)
228+
require.NoError(t, err)
229+
require.Equal(t, uint64(2), blockData.ExecutionPayload.BlockNumber)
230+
require.Len(t, blockData.ExecutionPayload.Transactions, 2)
231+
}
232+
174233
func insertBlocks(ctx context.Context, exec *execmodule.EthereumExecutionModule, chainPack *blockgen.ChainPack) (*executionproto.InsertionResult, error) {
175234
blocks := make([]*executionproto.Block, len(chainPack.Blocks))
176235
for i, b := range chainPack.Blocks {
@@ -242,6 +301,32 @@ func insertValidateAndUfc1By1(ctx context.Context, exec *execmodule.EthereumExec
242301
return nil
243302
}
244303

304+
func assembleBlock(ctx context.Context, exec *execmodule.EthereumExecutionModule, req *executionproto.AssembleBlockRequest) (uint64, error) {
305+
return retryBusy(ctx, func() (uint64, executionproto.ExecutionStatus, error) {
306+
r, err := exec.AssembleBlock(ctx, req)
307+
if err != nil {
308+
return 0, 0, err
309+
}
310+
if r.Busy {
311+
return 0, executionproto.ExecutionStatus_Busy, nil
312+
}
313+
return r.Id, executionproto.ExecutionStatus_Success, nil
314+
})
315+
}
316+
317+
func getAssembledBlock(ctx context.Context, exe *execmodule.EthereumExecutionModule, payloadId uint64) (*executionproto.AssembledBlockData, error) {
318+
return retryBusy(ctx, func() (*executionproto.AssembledBlockData, executionproto.ExecutionStatus, error) {
319+
br, err := exe.GetAssembledBlock(ctx, &executionproto.GetAssembledBlockRequest{Id: payloadId})
320+
if err != nil {
321+
return nil, 0, err
322+
}
323+
if br.Busy {
324+
return nil, executionproto.ExecutionStatus_Busy, nil
325+
}
326+
return br.Data, executionproto.ExecutionStatus_Success, nil
327+
})
328+
}
329+
245330
func retryBusy[T any](ctx context.Context, f func() (T, executionproto.ExecutionStatus, error)) (T, error) {
246331
ctx, cancel := context.WithTimeout(ctx, time.Minute)
247332
defer cancel()

execution/protocol/rules/aura/aura_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestEmptyBlock(t *testing.T) {
5656
auraDB := memdb.NewTestDB(t, dbcfg.ChainDB)
5757
engine, err := aura.NewAuRa(chainConfig.Aura, auraDB)
5858
require.NoError(err)
59-
m := mock.MockWithGenesisEngine(t, genesis, engine, false)
59+
m := mock.MockWithGenesisEngine(t, genesis, engine)
6060

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

9999
difficlty, _ := new(big.Int).SetString("340282366920938463463374607431768211454", 10)
100100
//Populate a sample valid header for a Pre-merge block

execution/protocol/rules/clique/clique_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestReimportMirroredState(t *testing.T) {
6464
Config: chainspec.AllCliqueProtocolChanges,
6565
}
6666
copy(genspec.ExtraData[clique.ExtraVanity:], addr[:])
67-
m := mock.MockWithGenesisEngine(t, genspec, engine, false)
67+
m := mock.MockWithGenesisEngine(t, genspec, engine)
6868

6969
// Generate a batch of blocks, each properly signed
7070
getHeader := func(hash common.Hash, number uint64) (h *types.Header, err error) {

execution/protocol/rules/clique/snapshot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ func TestClique(t *testing.T) {
438438
engine := clique.New(&config, chainspec.CliqueSnapshot, cliqueDB, log.New())
439439
engine.FakeDiff = true
440440
// Create a pristine blockchain with the genesis injected
441-
m := mock.MockWithGenesisEngine(t, genesis, engine, false)
441+
m := mock.MockWithGenesisEngine(t, genesis, engine)
442442

443443
chain, err := blockgen.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, len(tt.votes), func(j int, gen *blockgen.BlockGen) {
444444
// Cast the vote contained in this block

execution/rlp/rlp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func getBlock(tb testing.TB, transactions int, uncles int, dataSize int, tmpDir
5353
Alloc: types.GenesisAlloc{address: {Balance: funds}},
5454
}
5555
)
56-
m := mock.MockWithGenesis(tb, gspec, key, false)
56+
m := mock.MockWithGenesis(tb, gspec, key)
5757
genesis := m.Genesis
5858
db := m.DB
5959

0 commit comments

Comments
 (0)