Skip to content

Commit

Permalink
Get rid of ExecutionClientImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoximenes committed Jan 3, 2025
1 parent c7efe24 commit 7cbae44
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 115 deletions.
52 changes: 38 additions & 14 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,33 @@ func registerAPIs(currentNode *Node, stack *node.Node) {
stack.RegisterAPIs(apis)
}

func CreateNodeExecutionClient(
ctx context.Context,
stack *node.Node,
executionClient execution.ExecutionClient,
arbDb ethdb.Database,
configFetcher ConfigFetcher,
l2Config *params.ChainConfig,
l1client *ethclient.Client,
deployInfo *chaininfo.RollupAddresses,
txOptsValidator *bind.TransactOpts,
txOptsBatchPoster *bind.TransactOpts,
dataSigner signature.DataSignerFunc,
fatalErrChan chan error,
parentChainID *big.Int,
blobReader daprovider.BlobReader,
) (*Node, error) {
if executionClient == nil {
return nil, errors.New("execution client must be non-nil")
}
currentNode, err := createNodeImpl(ctx, stack, executionClient, nil, nil, nil, arbDb, configFetcher, l2Config, l1client, deployInfo, txOptsValidator, txOptsBatchPoster, dataSigner, fatalErrChan, parentChainID, blobReader)
if err != nil {
return nil, err
}
registerAPIs(currentNode, stack)
return currentNode, nil
}

func CreateNodeFullExecutionClient(
ctx context.Context,
stack *node.Node,
Expand Down Expand Up @@ -1198,26 +1225,23 @@ func CreateNodeFullExecutionClient(
}

func (n *Node) Start(ctx context.Context) error {
executionNode, isExecutionNode := n.ExecutionClient.(*gethexec.ExecutionNode)
executionClientImpl, isExecutionClientImpl := n.ExecutionClient.(*gethexec.ExecutionClientImpl)

var err error
if isExecutionNode {
err = executionNode.Initialize(ctx)
} else if isExecutionClientImpl {
err = executionClientImpl.Initialize(ctx)
execClient, ok := n.ExecutionClient.(*gethexec.ExecutionNode)
if !ok {
execClient = nil
}
if err != nil {
return fmt.Errorf("error initializing exec client: %w", err)
if execClient != nil {
err := execClient.Initialize(ctx)
if err != nil {
return fmt.Errorf("error initializing exec client: %w", err)
}
}

n.SyncMonitor.Initialize(n.InboxReader, n.TxStreamer, n.SeqCoordinator)
err = n.Stack.Start()
err := n.Stack.Start()
if err != nil {
return fmt.Errorf("error starting geth stack: %w", err)
}
if isExecutionNode {
executionNode.SetConsensusClient(n)
if execClient != nil {
execClient.SetConsensusClient(n)
}
err = n.ExecutionClient.Start(ctx)
if err != nil {
Expand Down
80 changes: 0 additions & 80 deletions execution/gethexec/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,83 +476,3 @@ func (n *ExecutionNode) Synced() bool {
func (n *ExecutionNode) FullSyncProgressMap() map[string]interface{} {
return n.SyncMonitor.FullSyncProgressMap()
}

// Used to check if only implementing ExecutionClient from FullExecutionClient interface is enough in some scenarios
type ExecutionClientImpl struct {
ExecutionNode *ExecutionNode
}

// ExecutionClient interface implementation
func (n *ExecutionClientImpl) DigestMessage(num arbutil.MessageIndex, msg *arbostypes.MessageWithMetadata, msgForPrefetch *arbostypes.MessageWithMetadata) containers.PromiseInterface[*execution.MessageResult] {
return n.ExecutionNode.DigestMessage(num, msg, msgForPrefetch)
}
func (n *ExecutionClientImpl) Reorg(count arbutil.MessageIndex, newMessages []arbostypes.MessageWithMetadataAndBlockHash, oldMessages []*arbostypes.MessageWithMetadata) containers.PromiseInterface[[]*execution.MessageResult] {
return n.ExecutionNode.Reorg(count, newMessages, oldMessages)
}
func (n *ExecutionClientImpl) HeadMessageNumber() containers.PromiseInterface[arbutil.MessageIndex] {
return n.ExecutionNode.HeadMessageNumber()
}
func (n *ExecutionClientImpl) ResultAtPos(pos arbutil.MessageIndex) containers.PromiseInterface[*execution.MessageResult] {
return n.ExecutionNode.ResultAtPos(pos)
}
func (n *ExecutionClientImpl) MarkFeedStart(to arbutil.MessageIndex) containers.PromiseInterface[struct{}] {
return n.ExecutionNode.MarkFeedStart(to)
}

// ExecutionRecorder interface implementation
func (n *ExecutionClientImpl) RecordBlockCreation(
ctx context.Context,
pos arbutil.MessageIndex,
msg *arbostypes.MessageWithMetadata,
) (*execution.RecordResult, error) {
panic("RecordBlockCreation not supported")
}
func (n *ExecutionClientImpl) MarkValid(pos arbutil.MessageIndex, resultHash common.Hash) {
panic("MarkValid not supported")
}
func (n *ExecutionClientImpl) PrepareForRecord(ctx context.Context, start, end arbutil.MessageIndex) error {
panic("PrepareForRecord not supported")
}

// ExecutionSequence interface implementation
func (n *ExecutionClientImpl) Pause() {
panic("Pause not supported")
}
func (n *ExecutionClientImpl) Activate() {
// panic("Activate not supported")
}
func (n *ExecutionClientImpl) ForwardTo(url string) error {
panic("ForwardTo not supported")
}
func (n *ExecutionClientImpl) SequenceDelayedMessage(message *arbostypes.L1IncomingMessage, delayedSeqNum uint64) error {
panic("SequenceDelayedMessage not supported")
}
func (n *ExecutionClientImpl) NextDelayedMessageNumber() (uint64, error) {
panic("NextDelayedMessageNumber not supported")
}
func (n *ExecutionClientImpl) Synced() bool {
panic("Synced not supported")
}
func (n *ExecutionClientImpl) FullSyncProgressMap() map[string]interface{} {
panic("FullSyncProgressMap not supported")
}

// Other funcs from FullExecutionClient
// not thread safe
func (n *ExecutionClientImpl) Start(ctx context.Context) error {
return n.ExecutionNode.Start(ctx)
}
func (n *ExecutionClientImpl) StopAndWait() {
n.ExecutionNode.StopAndWait()
}
func (n *ExecutionClientImpl) Maintenance() containers.PromiseInterface[struct{}] {
return n.ExecutionNode.Maintenance()
}
func (n *ExecutionClientImpl) ArbOSVersionForMessageNumber(messageNum arbutil.MessageIndex) (uint64, error) {
return n.ExecutionNode.ArbOSVersionForMessageNumber(messageNum)
}

// Not part of FullExecutionClient interface, but needed to start the node
func (n *ExecutionClientImpl) Initialize(ctx context.Context) error {
return n.ExecutionNode.Initialize(ctx)
}
28 changes: 13 additions & 15 deletions system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ import (
type info = *BlockchainTestInfo

type SecondNodeParams struct {
nodeConfig *arbnode.Config
execConfig *gethexec.Config
stackConfig *node.Config
dasConfig *das.DataAvailabilityConfig
initData *statetransfer.ArbosInitializationInfo
addresses *chaininfo.RollupAddresses
wasmCacheTag uint32
useExecutionClientImplAsFullExecutionClient bool
nodeConfig *arbnode.Config
execConfig *gethexec.Config
stackConfig *node.Config
dasConfig *das.DataAvailabilityConfig
initData *statetransfer.ArbosInitializationInfo
addresses *chaininfo.RollupAddresses
wasmCacheTag uint32
useExecutionClientOnly bool
}

type TestClient struct {
Expand Down Expand Up @@ -744,10 +744,8 @@ func build2ndNode(

testClient := NewTestClient(ctx)
testClient.Client, testClient.ConsensusNode =
Create2ndNodeWithConfig(t, ctx, firstNodeTestClient.ConsensusNode, parentChainTestClient.Stack, parentChainInfo, params.initData, params.nodeConfig, params.execConfig, params.stackConfig, valnodeConfig, params.addresses, initMessage, params.wasmCacheTag, params.useExecutionClientImplAsFullExecutionClient)
if !params.useExecutionClientImplAsFullExecutionClient {
testClient.ExecNode = getExecNode(t, testClient.ConsensusNode)
}
Create2ndNodeWithConfig(t, ctx, firstNodeTestClient.ConsensusNode, parentChainTestClient.Stack, parentChainInfo, params.initData, params.nodeConfig, params.execConfig, params.stackConfig, valnodeConfig, params.addresses, initMessage, params.wasmCacheTag, params.useExecutionClientOnly)
testClient.ExecNode = getExecNode(t, testClient.ConsensusNode)
testClient.cleanup = func() { testClient.ConsensusNode.StopAndWait() }
return testClient, func() { testClient.cleanup() }
}
Expand Down Expand Up @@ -1511,7 +1509,7 @@ func Create2ndNodeWithConfig(
addresses *chaininfo.RollupAddresses,
initMessage *arbostypes.ParsedInitMessage,
wasmCacheTag uint32,
useExecutionClientImplAsFullExecutionClient bool,
useExecutionClientOnly bool,
) (*ethclient.Client, *arbnode.Node) {
if nodeConfig == nil {
nodeConfig = arbnode.ConfigDefaultL1NonSequencerTest()
Expand Down Expand Up @@ -1559,8 +1557,8 @@ func Create2ndNodeWithConfig(
Require(t, err)

var currentNode *arbnode.Node
if useExecutionClientImplAsFullExecutionClient {
currentNode, err = arbnode.CreateNodeFullExecutionClient(ctx, chainStack, &gethexec.ExecutionClientImpl{ExecutionNode: currentExec}, &gethexec.ExecutionClientImpl{ExecutionNode: currentExec}, &gethexec.ExecutionClientImpl{ExecutionNode: currentExec}, &gethexec.ExecutionClientImpl{ExecutionNode: currentExec}, arbDb, NewFetcherFromConfig(nodeConfig), blockchain.Config(), parentChainClient, addresses, &validatorTxOpts, &sequencerTxOpts, dataSigner, feedErrChan, big.NewInt(1337), nil)
if useExecutionClientOnly {
currentNode, err = arbnode.CreateNodeExecutionClient(ctx, chainStack, currentExec, arbDb, NewFetcherFromConfig(nodeConfig), blockchain.Config(), parentChainClient, addresses, &validatorTxOpts, &sequencerTxOpts, dataSigner, feedErrChan, big.NewInt(1337), nil)
} else {
currentNode, err = arbnode.CreateNodeFullExecutionClient(ctx, chainStack, currentExec, currentExec, currentExec, currentExec, arbDb, NewFetcherFromConfig(nodeConfig), blockchain.Config(), parentChainClient, addresses, &validatorTxOpts, &sequencerTxOpts, dataSigner, feedErrChan, big.NewInt(1337), nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/offchainlabs/nitro/arbnode"
)

func TestExecutionClientImplAsFullExecutionClient(t *testing.T) {
func TestExecutionClientOnly(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -23,9 +23,9 @@ func TestExecutionClientImplAsFullExecutionClient(t *testing.T) {
defer cleanup()
seqTestClient := builder.L2

replicaConfig := arbnode.ConfigDefaultL1NonSequencerTest()
replicaTestClient, replicaCleanup := builder.Build2ndNode(t, &SecondNodeParams{nodeConfig: replicaConfig, useExecutionClientImplAsFullExecutionClient: true})
defer replicaCleanup()
replicaExecutionClientOnlyConfig := arbnode.ConfigDefaultL1NonSequencerTest()
replicaExecutionClientOnlyTestClient, replicaExecutionClientOnlyCleanup := builder.Build2ndNode(t, &SecondNodeParams{nodeConfig: replicaExecutionClientOnlyConfig, useExecutionClientOnly: true})
defer replicaExecutionClientOnlyCleanup()

builder.L2Info.GenerateAccount("User2")
for i := 0; i < 3; i++ {
Expand All @@ -34,11 +34,11 @@ func TestExecutionClientImplAsFullExecutionClient(t *testing.T) {
Require(t, err)
_, err = seqTestClient.EnsureTxSucceeded(tx)
Require(t, err)
_, err = WaitForTx(ctx, replicaTestClient.Client, tx.Hash(), time.Second*15)
_, err = WaitForTx(ctx, replicaExecutionClientOnlyTestClient.Client, tx.Hash(), time.Second*15)
Require(t, err)
}

replicaBalance, err := replicaTestClient.Client.BalanceAt(ctx, builder.L2Info.GetAddress("User2"), nil)
replicaBalance, err := replicaExecutionClientOnlyTestClient.Client.BalanceAt(ctx, builder.L2Info.GetAddress("User2"), nil)
Require(t, err)
if replicaBalance.Cmp(big.NewInt(3e12)) != 0 {
t.Fatal("Unexpected balance:", replicaBalance)
Expand Down

0 comments on commit 7cbae44

Please sign in to comment.