Skip to content

Commit 128bd56

Browse files
committed
simulators/ethereum/engine: major refactor to allow blob RLP txs
1 parent e28b97c commit 128bd56

File tree

21 files changed

+916
-681
lines changed

21 files changed

+916
-681
lines changed

simulators/ethereum/engine/client/engine.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010

1111
"github.com/ethereum/go-ethereum/common"
1212
"github.com/ethereum/go-ethereum/core/types"
13-
14-
client_types "github.com/ethereum/hive/simulators/ethereum/engine/client/types"
13+
e_typ "github.com/ethereum/hive/simulators/ethereum/engine/types"
1514
)
1615

1716
type Eth interface {
@@ -20,8 +19,8 @@ type Eth interface {
2019
BlockNumber(ctx context.Context) (uint64, error)
2120
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
2221
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
23-
SendTransaction(ctx context.Context, tx *types.Transaction) error
24-
SendTransactions(ctx context.Context, txs []*types.Transaction) []error
22+
SendTransaction(ctx context.Context, tx e_typ.Transaction) error
23+
SendTransactions(ctx context.Context, txs ...e_typ.Transaction) []error
2524
StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
2625
StorageAtKeys(ctx context.Context, account common.Address, keys []common.Hash, blockNumber *big.Int) (map[common.Hash]*common.Hash, error)
2726
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
@@ -36,15 +35,15 @@ type Engine interface {
3635

3736
GetPayloadV1(ctx context.Context, payloadId *api.PayloadID) (api.ExecutableData, error)
3837
GetPayloadV2(ctx context.Context, payloadId *api.PayloadID) (api.ExecutableData, *big.Int, error)
39-
GetPayloadV3(ctx context.Context, payloadId *api.PayloadID) (api.ExecutableData, *big.Int, *api.BlobsBundle, error)
38+
GetPayloadV3(ctx context.Context, payloadId *api.PayloadID) (api.ExecutableData, *big.Int, *e_typ.BlobsBundle, error)
4039

4140
NewPayload(ctx context.Context, version int, payload interface{}, versionedHashes []common.Hash) (api.PayloadStatusV1, error)
42-
NewPayloadV1(ctx context.Context, payload *client_types.ExecutableDataV1) (api.PayloadStatusV1, error)
41+
NewPayloadV1(ctx context.Context, payload *e_typ.ExecutableDataV1) (api.PayloadStatusV1, error)
4342
NewPayloadV2(ctx context.Context, payload *api.ExecutableData) (api.PayloadStatusV1, error)
4443
NewPayloadV3(ctx context.Context, payload *api.ExecutableData, versionedHashes []common.Hash) (api.PayloadStatusV1, error)
4544

46-
GetPayloadBodiesByRangeV1(ctx context.Context, start uint64, count uint64) ([]*client_types.ExecutionPayloadBodyV1, error)
47-
GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*client_types.ExecutionPayloadBodyV1, error)
45+
GetPayloadBodiesByRangeV1(ctx context.Context, start uint64, count uint64) ([]*e_typ.ExecutionPayloadBodyV1, error)
46+
GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*e_typ.ExecutionPayloadBodyV1, error)
4847

4948
LatestForkchoiceSent() (fcState *api.ForkchoiceStateV1, pAttributes *api.PayloadAttributes)
5049
LatestNewPayloadSent() (payload *api.ExecutableData)

simulators/ethereum/engine/client/hive_rpc/hive_rpc.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"github.com/ethereum/go-ethereum/rpc"
2121
"github.com/ethereum/hive/hivesim"
2222
"github.com/ethereum/hive/simulators/ethereum/engine/client"
23-
client_types "github.com/ethereum/hive/simulators/ethereum/engine/client/types"
2423
"github.com/ethereum/hive/simulators/ethereum/engine/globals"
2524
"github.com/ethereum/hive/simulators/ethereum/engine/helper"
25+
e_typ "github.com/ethereum/hive/simulators/ethereum/engine/types"
2626
"github.com/golang-jwt/jwt/v4"
2727
"github.com/pkg/errors"
2828
)
@@ -37,6 +37,8 @@ type HiveRPCEngineStarter struct {
3737
JWTSecret []byte
3838
}
3939

40+
var _ client.EngineStarter = (*HiveRPCEngineStarter)(nil)
41+
4042
func (s HiveRPCEngineStarter) StartClient(T *hivesim.T, testContext context.Context, genesis *core.Genesis, ClientParams hivesim.Params, ClientFiles hivesim.Params, bootClients ...client.EngineClient) (client.EngineClient, error) {
4143
var (
4244
clientType = s.ClientType
@@ -166,6 +168,8 @@ type HiveRPCEngineClient struct {
166168
accTxInfoMap map[common.Address]*AccountTransactionInfo
167169
}
168170

171+
var _ client.EngineClient = (*HiveRPCEngineClient)(nil)
172+
169173
// NewClient creates a engine client that uses the given RPC client.
170174
func NewHiveRPCEngineClient(h *hivesim.Client, enginePort int, ethPort int, jwtSecretBytes []byte, ttd *big.Int, transport http.RoundTripper) *HiveRPCEngineClient {
171175
// Prepare HTTP Client
@@ -358,11 +362,11 @@ func (ec *HiveRPCEngineClient) ForkchoiceUpdatedV2(ctx context.Context, fcState
358362

359363
// Get Payload API Calls
360364

361-
func (ec *HiveRPCEngineClient) GetPayload(ctx context.Context, version int, payloadId *api.PayloadID) (api.ExecutableData, *big.Int, *api.BlobsBundle, error) {
365+
func (ec *HiveRPCEngineClient) GetPayload(ctx context.Context, version int, payloadId *api.PayloadID) (api.ExecutableData, *big.Int, *e_typ.BlobsBundle, error) {
362366
var (
363367
executableData api.ExecutableData
364368
blockValue *big.Int
365-
blobsBundle *api.BlobsBundle
369+
blobsBundle *e_typ.BlobsBundle
366370
err error
367371
rpcString = fmt.Sprintf("engine_getPayloadV%d", version)
368372
)
@@ -372,7 +376,7 @@ func (ec *HiveRPCEngineClient) GetPayload(ctx context.Context, version int, payl
372376
}
373377

374378
if version >= 2 {
375-
var response api.ExecutionPayloadEnvelope
379+
var response e_typ.ExecutionPayloadEnvelope
376380
err = ec.c.CallContext(ctx, &response, rpcString, payloadId)
377381
if response.ExecutionPayload != nil {
378382
executableData = *response.ExecutionPayload
@@ -396,14 +400,14 @@ func (ec *HiveRPCEngineClient) GetPayloadV2(ctx context.Context, payloadId *api.
396400
return ed, bv, err
397401
}
398402

399-
func (ec *HiveRPCEngineClient) GetPayloadV3(ctx context.Context, payloadId *api.PayloadID) (api.ExecutableData, *big.Int, *api.BlobsBundle, error) {
403+
func (ec *HiveRPCEngineClient) GetPayloadV3(ctx context.Context, payloadId *api.PayloadID) (api.ExecutableData, *big.Int, *e_typ.BlobsBundle, error) {
400404
return ec.GetPayload(ctx, 3, payloadId)
401405
}
402406

403407
// Get Payload Bodies API Calls
404-
func (ec *HiveRPCEngineClient) GetPayloadBodiesByRangeV1(ctx context.Context, start uint64, count uint64) ([]*client_types.ExecutionPayloadBodyV1, error) {
408+
func (ec *HiveRPCEngineClient) GetPayloadBodiesByRangeV1(ctx context.Context, start uint64, count uint64) ([]*e_typ.ExecutionPayloadBodyV1, error) {
405409
var (
406-
result []*client_types.ExecutionPayloadBodyV1
410+
result []*e_typ.ExecutionPayloadBodyV1
407411
err error
408412
)
409413
if err = ec.PrepareDefaultAuthCallToken(); err != nil {
@@ -414,9 +418,9 @@ func (ec *HiveRPCEngineClient) GetPayloadBodiesByRangeV1(ctx context.Context, st
414418
return result, err
415419
}
416420

417-
func (ec *HiveRPCEngineClient) GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*client_types.ExecutionPayloadBodyV1, error) {
421+
func (ec *HiveRPCEngineClient) GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*e_typ.ExecutionPayloadBodyV1, error) {
418422
var (
419-
result []*client_types.ExecutionPayloadBodyV1
423+
result []*e_typ.ExecutionPayloadBodyV1
420424
err error
421425
)
422426
if err = ec.PrepareDefaultAuthCallToken(); err != nil {
@@ -428,9 +432,9 @@ func (ec *HiveRPCEngineClient) GetPayloadBodiesByHashV1(ctx context.Context, has
428432
}
429433

430434
// Get Blob Bundle API Calls
431-
func (ec *HiveRPCEngineClient) GetBlobsBundleV1(ctx context.Context, payloadId *api.PayloadID) (*api.BlobsBundle, error) {
435+
func (ec *HiveRPCEngineClient) GetBlobsBundleV1(ctx context.Context, payloadId *api.PayloadID) (*e_typ.BlobsBundle, error) {
432436
var (
433-
result api.BlobsBundle
437+
result e_typ.BlobsBundle
434438
err error
435439
)
436440
if err = ec.PrepareDefaultAuthCallToken(); err != nil {
@@ -456,7 +460,7 @@ func (ec *HiveRPCEngineClient) NewPayload(ctx context.Context, version int, payl
456460
return result, err
457461
}
458462

459-
func (ec *HiveRPCEngineClient) NewPayloadV1(ctx context.Context, payload *client_types.ExecutableDataV1) (api.PayloadStatusV1, error) {
463+
func (ec *HiveRPCEngineClient) NewPayloadV1(ctx context.Context, payload *e_typ.ExecutableDataV1) (api.PayloadStatusV1, error) {
460464
ed := payload.ToExecutableData()
461465
ec.latestPayloadSent = &ed
462466
return ec.NewPayload(ctx, 1, payload, nil)
@@ -553,7 +557,15 @@ func (ec *HiveRPCEngineClient) UpdateNonce(testCtx context.Context, account comm
553557
return nil
554558
}
555559

556-
func (ec *HiveRPCEngineClient) SendTransactions(ctx context.Context, txs []*types.Transaction) []error {
560+
func (ec *HiveRPCEngineClient) SendTransaction(ctx context.Context, tx e_typ.Transaction) error {
561+
data, err := tx.MarshalBinary()
562+
if err != nil {
563+
return err
564+
}
565+
return ec.cEth.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(data))
566+
}
567+
568+
func (ec *HiveRPCEngineClient) SendTransactions(ctx context.Context, txs ...e_typ.Transaction) []error {
557569
reqs := make([]rpc.BatchElem, len(txs))
558570
hashes := make([]common.Hash, len(txs))
559571
for i := range reqs {

simulators/ethereum/engine/client/node/node.go

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ import (
3636
"github.com/ethereum/go-ethereum/rpc"
3737
"github.com/ethereum/hive/hivesim"
3838
"github.com/ethereum/hive/simulators/ethereum/engine/client"
39-
client_types "github.com/ethereum/hive/simulators/ethereum/engine/client/types"
4039
"github.com/ethereum/hive/simulators/ethereum/engine/globals"
4140
"github.com/ethereum/hive/simulators/ethereum/engine/helper"
41+
e_typ "github.com/ethereum/hive/simulators/ethereum/engine/types"
4242
)
4343

4444
type GethNodeTestConfiguration struct {
@@ -206,6 +206,8 @@ type GethNode struct {
206206
config GethNodeTestConfiguration
207207
}
208208

209+
var _ client.EngineClient = (*GethNode)(nil)
210+
209211
func newNode(config GethNodeTestConfiguration, bootnodes []string, genesis *core.Genesis) (*GethNode, error) {
210212
// Define the basic configurations for the Ethereum node
211213
datadir, _ := os.MkdirTemp("", "")
@@ -234,14 +236,14 @@ func restart(startConfig GethNodeTestConfiguration, bootnodes []string, datadir
234236
return nil, err
235237
}
236238
econfig := &ethconfig.Config{
237-
Genesis: genesis,
238-
NetworkId: genesis.Config.ChainID.Uint64(),
239-
SyncMode: downloader.FullSync,
240-
DatabaseCache: 256,
241-
DatabaseHandles: 256,
242-
TxPool: txpool.DefaultConfig,
243-
GPO: ethconfig.Defaults.GPO,
244-
Ethash: ethconfig.Defaults.Ethash,
239+
Genesis: genesis,
240+
NetworkId: genesis.Config.ChainID.Uint64(),
241+
SyncMode: downloader.FullSync,
242+
DatabaseCache: 256,
243+
DatabaseHandles: 256,
244+
TxPool: txpool.DefaultConfig,
245+
GPO: ethconfig.Defaults.GPO,
246+
// Ethash: ethconfig.Defaults.Ethash,
245247
Miner: ethconfig.Defaults.Miner,
246248
LightServ: 100,
247249
LightPeers: int(startConfig.MaxPeers.Int64()) - 1,
@@ -288,18 +290,20 @@ func restart(startConfig GethNodeTestConfiguration, bootnodes []string, datadir
288290
}
289291

290292
g.running, g.closing = context.WithCancel(context.Background())
291-
if startConfig.PoWMiner || startConfig.Ethash {
292-
// Create the ethash consensus module
293-
ethashConfig := ethconfig.Defaults.Ethash
294-
ethashConfig.PowMode = ethash.ModeNormal
295-
ethashConfig.CacheDir = "/ethash"
296-
ethashConfig.DatasetDir = ethashConfig.CacheDir
297-
g.ethashEngine = ethash.New(ethashConfig, nil, false)
298-
}
299-
if startConfig.PoWMiner {
300-
// Enable mining
301-
go g.EnablePoWMining()
302-
}
293+
/*
294+
if startConfig.PoWMiner || startConfig.Ethash {
295+
// Create the ethash consensus module
296+
ethashConfig := ethconfig.Defaults.Ethash
297+
ethashConfig.PowMode = ethash.ModeNormal
298+
ethashConfig.CacheDir = "/ethash"
299+
ethashConfig.DatasetDir = ethashConfig.CacheDir
300+
g.ethashEngine = ethash.New(ethashConfig, nil, false)
301+
}
302+
if startConfig.PoWMiner {
303+
// Enable mining
304+
go g.EnablePoWMining()
305+
}
306+
*/
303307

304308
// Start thread to monitor the amount of gossiped blocks this node receives
305309
go g.SubscribeP2PEvents()
@@ -457,7 +461,7 @@ func (n *GethNode) PoWMiningLoop() {
457461
// Modify the sealed block if necessary
458462
if n.config.BlockModifier != nil {
459463
sealVerifier := func(h *types.Header) bool {
460-
return n.ethashEngine.VerifyHeader(n.eth.BlockChain(), h, true) == nil
464+
return n.ethashEngine.VerifyHeader(n.eth.BlockChain(), h) == nil
461465
}
462466
b, err = n.config.BlockModifier.ModifySealedBlock(sealVerifier, b)
463467
if err != nil {
@@ -616,7 +620,7 @@ func (v *validator) ValidateState(block *types.Block, state *state.StateDB, rece
616620

617621
type processor struct{}
618622

619-
func (p *processor) Process(block *types.Block, excessDataGas *big.Int, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) {
623+
func (p *processor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) {
620624
return types.Receipts{}, []*types.Log{}, 21000, nil
621625
}
622626

@@ -656,7 +660,7 @@ func (n *GethNode) SetBlock(block *types.Block, parentNumber uint64, parentRoot
656660
}
657661
statedb.StartPrefetcher("chain")
658662
var failedProcessing bool
659-
receipts, _, _, err := n.eth.BlockChain().Processor().Process(block, n.eth.BlockChain().CurrentBlock().ExcessDataGas, statedb, *n.eth.BlockChain().GetVMConfig())
663+
receipts, _, _, err := n.eth.BlockChain().Processor().Process(block, statedb, *n.eth.BlockChain().GetVMConfig())
660664
if err != nil {
661665
failedProcessing = true
662666
}
@@ -698,7 +702,7 @@ func (n *GethNode) SetBlock(block *types.Block, parentNumber uint64, parentRoot
698702
func (n *GethNode) NewPayload(ctx context.Context, version int, pl interface{}, vh []common.Hash) (beacon.PayloadStatusV1, error) {
699703
switch version {
700704
case 1:
701-
if c, ok := pl.(*client_types.ExecutableDataV1); ok {
705+
if c, ok := pl.(*e_typ.ExecutableDataV1); ok {
702706
return n.NewPayloadV1(ctx, c)
703707
} else {
704708
return beacon.PayloadStatusV1{}, fmt.Errorf("wrong type %T", pl)
@@ -719,7 +723,7 @@ func (n *GethNode) NewPayload(ctx context.Context, version int, pl interface{},
719723
return beacon.PayloadStatusV1{}, fmt.Errorf("unknown version %d", version)
720724
}
721725

722-
func (n *GethNode) NewPayloadV1(ctx context.Context, pl *client_types.ExecutableDataV1) (beacon.PayloadStatusV1, error) {
726+
func (n *GethNode) NewPayloadV1(ctx context.Context, pl *e_typ.ExecutableDataV1) (beacon.PayloadStatusV1, error) {
723727
ed := pl.ToExecutableData()
724728
n.latestPayloadSent = &ed
725729
resp, err := n.api.NewPayloadV1(ed)
@@ -783,23 +787,23 @@ func (n *GethNode) GetPayloadV2(ctx context.Context, payloadId *beacon.PayloadID
783787
return *p.ExecutionPayload, p.BlockValue, err
784788
}
785789

786-
func (n *GethNode) GetPayloadV3(ctx context.Context, payloadId *beacon.PayloadID) (beacon.ExecutableData, *big.Int, *beacon.BlobsBundle, error) {
790+
func (n *GethNode) GetPayloadV3(ctx context.Context, payloadId *beacon.PayloadID) (beacon.ExecutableData, *big.Int, *e_typ.BlobsBundle, error) {
787791
p, err := n.api.GetPayloadV3(*payloadId)
788792
if p == nil || err != nil {
789793
return beacon.ExecutableData{}, nil, nil, err
790794
}
791-
return *p.ExecutionPayload, p.BlockValue, p.BlobsBundle, err
795+
return *p.ExecutionPayload, p.BlockValue, nil, err
792796
}
793797

794-
func (n *GethNode) GetPayloadBodiesByRangeV1(ctx context.Context, start uint64, count uint64) ([]*client_types.ExecutionPayloadBodyV1, error) {
798+
func (n *GethNode) GetPayloadBodiesByRangeV1(ctx context.Context, start uint64, count uint64) ([]*e_typ.ExecutionPayloadBodyV1, error) {
795799
return nil, fmt.Errorf("not implemented")
796800
}
797801

798-
func (n *GethNode) GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*client_types.ExecutionPayloadBodyV1, error) {
802+
func (n *GethNode) GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*e_typ.ExecutionPayloadBodyV1, error) {
799803
return nil, fmt.Errorf("not implemented")
800804
}
801805

802-
func (n *GethNode) GetBlobsBundleV1(ctx context.Context, payloadId *beacon.PayloadID) (*beacon.BlobsBundle, error) {
806+
func (n *GethNode) GetBlobsBundleV1(ctx context.Context, payloadId *beacon.PayloadID) (*e_typ.BlobsBundle, error) {
803807
return nil, fmt.Errorf("not implemented")
804808
}
805809

@@ -860,16 +864,24 @@ func (n *GethNode) HeaderByNumber(ctx context.Context, number *big.Int) (*types.
860864
return b.Header(), err
861865
}
862866

863-
func (n *GethNode) SendTransaction(ctx context.Context, tx *types.Transaction) error {
864-
return n.eth.APIBackend.SendTx(ctx, tx)
867+
func (n *GethNode) SendTransaction(ctx context.Context, tx e_typ.Transaction) error {
868+
if v, ok := tx.(*types.Transaction); ok {
869+
return n.eth.APIBackend.SendTx(ctx, v)
870+
}
871+
return fmt.Errorf("invalid transaction type")
865872
}
866873

867-
func (n *GethNode) SendTransactions(ctx context.Context, txs []*types.Transaction) []error {
874+
func (n *GethNode) SendTransactions(ctx context.Context, txs ...e_typ.Transaction) []error {
868875
for _, tx := range txs {
869-
err := n.eth.APIBackend.SendTx(ctx, tx)
870-
if err != nil {
871-
return []error{err}
876+
if v, ok := tx.(*types.Transaction); ok {
877+
err := n.eth.APIBackend.SendTx(ctx, v)
878+
if err != nil {
879+
return []error{err}
880+
}
881+
} else {
882+
return []error{fmt.Errorf("invalid transaction type")}
872883
}
884+
873885
}
874886
return nil
875887
}

simulators/ethereum/engine/clmock/clmock.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111

1212
api "github.com/ethereum/go-ethereum/beacon/engine"
1313
"github.com/ethereum/hive/simulators/ethereum/engine/client"
14-
client_types "github.com/ethereum/hive/simulators/ethereum/engine/client/types"
1514
"github.com/ethereum/hive/simulators/ethereum/engine/globals"
1615
"github.com/ethereum/hive/simulators/ethereum/engine/helper"
16+
e_typ "github.com/ethereum/hive/simulators/ethereum/engine/types"
1717

1818
"github.com/ethereum/go-ethereum/common"
1919
"github.com/ethereum/go-ethereum/core/types"
@@ -91,7 +91,7 @@ type CLMocker struct {
9191
LatestHeader *types.Header
9292
LatestPayloadBuilt api.ExecutableData
9393
LatestBlockValue *big.Int
94-
LatestBlobBundle *api.BlobsBundle
94+
LatestBlobBundle *e_typ.BlobsBundle
9595
LatestPayloadAttributes api.PayloadAttributes
9696
LatestExecutedPayload api.ExecutableData
9797
LatestForkchoice api.ForkchoiceStateV1
@@ -642,7 +642,7 @@ func (cl *CLMocker) BroadcastNewPayload(payload *api.ExecutableData, versionedHa
642642
} else if isShanghai(payload.Timestamp, cl.ShanghaiTimestamp) {
643643
execPayloadResp, err = ec.NewPayloadV2(ctx, payload)
644644
} else {
645-
edv1 := &client_types.ExecutableDataV1{}
645+
edv1 := &e_typ.ExecutableDataV1{}
646646
edv1.FromExecutableData(payload)
647647
execPayloadResp, err = ec.NewPayloadV1(ctx, edv1)
648648
}

0 commit comments

Comments
 (0)