Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion simulators/eth2/common/clients/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@ import (
"github.com/ethereum/hive/simulators/eth2/common/spoofing/proxy"
"github.com/ethereum/hive/simulators/eth2/common/utils"
"github.com/golang-jwt/jwt/v4"
spoof "github.com/rauljordan/engine-proxy/proxy"
)

const (
PortUserRPC = 8545
PortEngineRPC = 8551
)

var AllEngineCallsLog = []string{
"engine_forkchoiceUpdatedV1",
"engine_forkchoiceUpdatedV2",
"engine_getPayloadV1",
"engine_getPayloadV2",
"engine_newPayloadV1",
"engine_newPayloadV2",
}

type ExecutionClient struct {
T *hivesim.T
HiveClient *hivesim.Client
Expand All @@ -37,6 +47,8 @@ type ExecutionClient struct {
proxyPort int
subnet string
ttd *big.Int
clientIndex int
logEngineCalls bool

engineRpcClient *rpc.Client
ethRpcClient *rpc.Client
Expand All @@ -47,9 +59,11 @@ func NewExecutionClient(
t *hivesim.T,
eth1Def *hivesim.ClientDefinition,
optionsGenerator func() ([]hivesim.StartOption, error),
clientIndex int,
proxyPort int,
subnet string,
ttd *big.Int,
logEngineCalls bool,
) *ExecutionClient {
return &ExecutionClient{
T: t,
Expand All @@ -59,6 +73,8 @@ func NewExecutionClient(
proxy: new(*proxy.Proxy),
subnet: subnet,
ttd: ttd,
clientIndex: clientIndex,
logEngineCalls: logEngineCalls,
}
}

Expand Down Expand Up @@ -142,12 +158,33 @@ func (en *ExecutionClient) Start(extraOptions ...hivesim.StartOption) error {
panic(err)
}

*en.proxy = proxy.NewProxy(
proxy := proxy.NewProxy(
net.ParseIP(simIP),
en.proxyPort,
dest,
secret,
)
if en.logEngineCalls {
logCallback := func(res []byte, req []byte) *spoof.Spoof {
en.T.Logf(
"DEBUG: execution client %d, request: %s",
en.clientIndex,
req,
)
en.T.Logf(
"DEBUG: execution client %d, response: %s",
en.clientIndex,
res,
)
return nil
}
for _, c := range AllEngineCallsLog {
proxy.AddResponseCallback(c, logCallback)
}
}

*en.proxy = proxy

return nil
}

Expand Down
7 changes: 4 additions & 3 deletions simulators/eth2/common/testnet/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

type Environment struct {
Clients *clients.ClientDefinitionsByRole
Keys []*consensus_config.KeyDetails
Secrets *[]blsu.SecretKey
Clients *clients.ClientDefinitionsByRole
Keys []*consensus_config.KeyDetails
Secrets *[]blsu.SecretKey
LogEngineCalls bool
}
3 changes: 3 additions & 0 deletions simulators/eth2/common/testnet/prepared_testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func (p *PreparedTestnet) prepareExecutionNode(
executionIndex int,
chain []*types.Block,
subnet string,
logEngineCalls bool,
) *clients.ExecutionClient {
testnet.Logf(
"Preparing execution node: %s (%s)",
Expand Down Expand Up @@ -394,9 +395,11 @@ func (p *PreparedTestnet) prepareExecutionNode(
testnet.T,
eth1Def,
optionsGenerator,
executionIndex,
clients.PortEngineRPC+executionIndex,
subnet,
ttd,
logEngineCalls,
)
}

Expand Down
1 change: 1 addition & 0 deletions simulators/eth2/common/testnet/running_testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func StartTestnet(
nodeIndex,
node.Chain,
node.ExecutionSubnet,
env.LogEngineCalls,
)

if node.ConsensusClient != "" {
Expand Down