forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 14
op-batcher: bound every Espresso network call and drop the streamer on stop #500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
philippecamacho
wants to merge
2
commits into
espresso/batcher
Choose a base branch
from
493-bound-espresso-network-calls
base: espresso/batcher
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package batcher | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| espressoCommon "github.com/EspressoSystems/espresso-network/sdks/go/types" | ||
| ) | ||
|
|
||
| // EspressoSubmitClient is the slice of the Espresso SDK client consumed by the | ||
| // transaction submitter and its workers. Narrowed from the SDK's full | ||
| // EspressoClient so the per-call deadline wrapper below only has to cover | ||
| // methods that are actually called (the full interface includes streaming | ||
| // endpoints, which a per-call deadline would break). | ||
| type EspressoSubmitClient interface { | ||
| SubmitTransaction(ctx context.Context, tx espressoCommon.Transaction) (*espressoCommon.TaggedBase64, error) | ||
| FetchTransactionByHash(ctx context.Context, hash *espressoCommon.TaggedBase64) (espressoCommon.TransactionQueryData, error) | ||
| FetchLatestBlockHeight(ctx context.Context) (uint64, error) | ||
| } | ||
|
|
||
| // boundedEspressoClient enforces a per-call deadline on every Espresso SDK | ||
| // call. The SDK issues plain HTTP requests with no client-side timeout, and the | ||
| // submit/verify workers otherwise call it with their long-lived loop contexts — | ||
| // a black-holed connection would hold a worker forever, and with every worker | ||
| // wedged, submission stays stopped even after the endpoint recovers. | ||
| type boundedEspressoClient struct { | ||
| inner EspressoSubmitClient | ||
| timeout time.Duration | ||
| } | ||
|
|
||
| func newBoundedEspressoClient(inner EspressoSubmitClient, timeout time.Duration) *boundedEspressoClient { | ||
| return &boundedEspressoClient{inner: inner, timeout: timeout} | ||
| } | ||
|
|
||
| func (c *boundedEspressoClient) SubmitTransaction(ctx context.Context, tx espressoCommon.Transaction) (*espressoCommon.TaggedBase64, error) { | ||
| ctx, cancel := context.WithTimeout(ctx, c.timeout) | ||
| defer cancel() | ||
| return c.inner.SubmitTransaction(ctx, tx) | ||
| } | ||
|
|
||
| func (c *boundedEspressoClient) FetchTransactionByHash(ctx context.Context, hash *espressoCommon.TaggedBase64) (espressoCommon.TransactionQueryData, error) { | ||
| ctx, cancel := context.WithTimeout(ctx, c.timeout) | ||
| defer cancel() | ||
| return c.inner.FetchTransactionByHash(ctx, hash) | ||
| } | ||
|
|
||
| func (c *boundedEspressoClient) FetchLatestBlockHeight(ctx context.Context) (uint64, error) { | ||
| ctx, cancel := context.WithTimeout(ctx, c.timeout) | ||
| defer cancel() | ||
| return c.inner.FetchLatestBlockHeight(ctx) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package batcher | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| espressoCommon "github.com/EspressoSystems/espresso-network/sdks/go/types" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // blockingEspressoClient hangs every call until its context is cancelled, | ||
| // modeling the SDK's timeout-less HTTP client on a black-holed connection. | ||
| type blockingEspressoClient struct{} | ||
|
|
||
| func (blockingEspressoClient) SubmitTransaction(ctx context.Context, tx espressoCommon.Transaction) (*espressoCommon.TaggedBase64, error) { | ||
| <-ctx.Done() | ||
| return nil, ctx.Err() | ||
| } | ||
|
|
||
| func (blockingEspressoClient) FetchTransactionByHash(ctx context.Context, hash *espressoCommon.TaggedBase64) (espressoCommon.TransactionQueryData, error) { | ||
| <-ctx.Done() | ||
| return espressoCommon.TransactionQueryData{}, ctx.Err() | ||
| } | ||
|
|
||
| func (blockingEspressoClient) FetchLatestBlockHeight(ctx context.Context) (uint64, error) { | ||
| <-ctx.Done() | ||
| return 0, ctx.Err() | ||
| } | ||
|
|
||
| // TestBoundedEspressoClientAppliesDeadline pins that every wrapped method | ||
| // carries a per-call deadline even when the caller's context has none (as the | ||
| // workers' long-lived loop contexts do not). | ||
| func TestBoundedEspressoClientAppliesDeadline(t *testing.T) { | ||
| c := newBoundedEspressoClient(blockingEspressoClient{}, 10*time.Millisecond) | ||
|
|
||
| _, err := c.SubmitTransaction(context.Background(), espressoCommon.Transaction{}) | ||
| require.ErrorIs(t, err, context.DeadlineExceeded) | ||
|
|
||
| _, err = c.FetchTransactionByHash(context.Background(), nil) | ||
| require.ErrorIs(t, err, context.DeadlineExceeded) | ||
|
|
||
| _, err = c.FetchLatestBlockHeight(context.Background()) | ||
| require.ErrorIs(t, err, context.DeadlineExceeded) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package batcher | ||
|
|
||
| import ( | ||
| "context" | ||
| "sync" | ||
| "testing" | ||
|
|
||
| espressoStreamers "github.com/EspressoSystems/espresso-streamers/op" | ||
| "github.com/ethereum/go-ethereum/log" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-service/testlog" | ||
| ) | ||
|
|
||
| // startedSubmitter returns a BatchSubmitter in the state StartBatchSubmitting | ||
| // leaves it in right after taking ownership (running, fresh contexts, empty | ||
| // waitgroup) with a streamer attached. A zero-value Streamer is safe here: | ||
| // Stop() on it is a no-op (nil cancel), and these tests only exercise | ||
| // teardown, never the streamer itself. | ||
| func startedSubmitter(t *testing.T) *BatchSubmitter { | ||
| l := &BatchSubmitter{} | ||
| l.Log = testlog.Logger(t, log.LevelDebug) | ||
| l.running = true | ||
| l.shutdownCtx, l.cancelShutdownCtx = context.WithCancel(context.Background()) | ||
| l.killCtx, l.cancelKillCtx = context.WithCancel(context.Background()) | ||
| l.wg = &sync.WaitGroup{} | ||
| l.espressoStreamer = &espressoStreamers.Streamer{} | ||
| return l | ||
| } | ||
|
|
||
| // TestStopBatchSubmittingDropsStreamer pins that a stopped run's streamer does | ||
| // not survive into the next start; see teardownEspressoStreamer for why. | ||
| func TestStopBatchSubmittingDropsStreamer(t *testing.T) { | ||
| l := startedSubmitter(t) | ||
| require.NoError(t, l.StopBatchSubmitting(context.Background())) | ||
| require.Nil(t, l.espressoStreamer) | ||
| require.False(t, l.running) | ||
| } | ||
|
|
||
| // TestRollbackFailedStartDropsStreamer pins the same invariant for a start | ||
| // that constructed a streamer and then failed. | ||
| func TestRollbackFailedStartDropsStreamer(t *testing.T) { | ||
| l := startedSubmitter(t) | ||
| l.rollbackFailedStart() | ||
| require.Nil(t, l.espressoStreamer) | ||
| require.False(t, l.running) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: other than the config naming implies, this technically won't set the individual network-timeout (http.Client.Timeout), but the overall multinode submit timeout. Still I believe it's okay to leave this as is for now.