From 483c082d2eae839c4a55061264d1972c2acc62e4 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 2 Jan 2025 21:01:28 -0300 Subject: [PATCH] ExecutionClient.Start and ExecutionClient.StopAndWait return promises --- arbnode/inbox_test.go | 8 ++++---- arbnode/node.go | 7 +++++-- execution/gethexec/node.go | 14 ++++++++------ execution/interface.go | 4 ++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/arbnode/inbox_test.go b/arbnode/inbox_test.go index 0c8f00a3d4..2207e47b4e 100644 --- a/arbnode/inbox_test.go +++ b/arbnode/inbox_test.go @@ -90,12 +90,12 @@ func (w *execClientWrapper) ResultAtPos(pos arbutil.MessageIndex) containers.Pro return containers.NewReadyPromise(w.ExecutionEngine.ResultAtPos(pos)) } -func (w *execClientWrapper) Start(ctx context.Context) error { - return nil +func (w *execClientWrapper) Start(ctx context.Context) containers.PromiseInterface[struct{}] { + return containers.NewReadyPromise(struct{}{}, nil) } -func (w *execClientWrapper) StopAndWait() { - return +func (w *execClientWrapper) StopAndWait() containers.PromiseInterface[struct{}] { + return containers.NewReadyPromise(struct{}{}, nil) } func NewTransactionStreamerForTest(t *testing.T, ownerAddress common.Address) (*gethexec.ExecutionEngine, *TransactionStreamer, ethdb.Database, *core.BlockChain) { diff --git a/arbnode/node.go b/arbnode/node.go index b5742524c9..a0f8f02e6c 100644 --- a/arbnode/node.go +++ b/arbnode/node.go @@ -1243,7 +1243,7 @@ func (n *Node) Start(ctx context.Context) error { if execClient != nil { execClient.SetConsensusClient(n) } - err = n.ExecutionClient.Start(ctx) + _, err = n.ExecutionClient.Start(ctx).Await(ctx) if err != nil { return fmt.Errorf("error starting exec client: %w", err) } @@ -1414,7 +1414,10 @@ func (n *Node) StopAndWait() { n.DASLifecycleManager.StopAndWaitUntil(2 * time.Second) } if n.ExecutionClient != nil { - n.ExecutionClient.StopAndWait() + _, err := n.ExecutionClient.StopAndWait().Await(n.ctx) + if err != nil { + log.Error("error stopping execution client", "err", err) + } } if err := n.Stack.Close(); err != nil { log.Error("error on stack close", "err", err) diff --git a/execution/gethexec/node.go b/execution/gethexec/node.go index 5b78a73c73..9ee0bcc896 100644 --- a/execution/gethexec/node.go +++ b/execution/gethexec/node.go @@ -347,9 +347,9 @@ func (n *ExecutionNode) Initialize(ctx context.Context) error { } // not thread safe -func (n *ExecutionNode) Start(ctx context.Context) error { +func (n *ExecutionNode) Start(ctx context.Context) containers.PromiseInterface[struct{}] { if n.started.Swap(true) { - return errors.New("already started") + return containers.NewReadyPromise(struct{}{}, errors.New("already started")) } // TODO after separation // err := n.Stack.Start() @@ -359,17 +359,17 @@ func (n *ExecutionNode) Start(ctx context.Context) error { n.ExecEngine.Start(ctx) err := n.TxPublisher.Start(ctx) if err != nil { - return fmt.Errorf("error starting transaction puiblisher: %w", err) + return containers.NewReadyPromise(struct{}{}, fmt.Errorf("error starting transaction puiblisher: %w", err)) } if n.ParentChainReader != nil { n.ParentChainReader.Start(ctx) } - return nil + return containers.NewReadyPromise(struct{}{}, nil) } -func (n *ExecutionNode) StopAndWait() { +func (n *ExecutionNode) StopAndWait() containers.PromiseInterface[struct{}] { if !n.started.Load() { - return + return containers.NewReadyPromise(struct{}{}, nil) } // TODO after separation // n.Stack.StopRPC() // does nothing if not running @@ -391,6 +391,8 @@ func (n *ExecutionNode) StopAndWait() { // if err := n.Stack.Close(); err != nil { // log.Error("error on stak close", "err", err) // } + + return containers.NewReadyPromise(struct{}{}, nil) } func (n *ExecutionNode) DigestMessage(num arbutil.MessageIndex, msg *arbostypes.MessageWithMetadata, msgForPrefetch *arbostypes.MessageWithMetadata) containers.PromiseInterface[*execution.MessageResult] { diff --git a/execution/interface.go b/execution/interface.go index 51de32a685..dcf6fec72a 100644 --- a/execution/interface.go +++ b/execution/interface.go @@ -37,8 +37,8 @@ type ExecutionClient interface { Maintenance() containers.PromiseInterface[struct{}] - Start(ctx context.Context) error - StopAndWait() + Start(ctx context.Context) containers.PromiseInterface[struct{}] + StopAndWait() containers.PromiseInterface[struct{}] } // needed for validators / stakers