forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat(batcher): altda->ethda failover #24
Open
samlaf
wants to merge
2
commits into
feat--multiframe-altda-channel
Choose a base branch
from
feat--op-batcher-altda-failover-to-ethda
base: feat--multiframe-altda-channel
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -105,12 +105,16 @@ func (d *AltDADisabled) AdvanceL1Origin(ctx context.Context, l1 L1Fetcher, block | |
} | ||
|
||
// FakeDAServer is a fake DA server for e2e tests. | ||
// It is a small wrapper around DAServer that allows for setting request latencies, | ||
// to mimic a DA service with slow responses (eg. eigenDA with 10 min batching interval). | ||
// It is a small wrapper around DAServer that allows for setting: | ||
// - request latencies, to mimic a DA service with slow responses | ||
// (eg. eigenDA with 10 min batching interval). | ||
// - response status codes, to mimic a DA service that is down. | ||
type FakeDAServer struct { | ||
*DAServer | ||
putRequestLatency time.Duration | ||
getRequestLatency time.Duration | ||
// next failoverCount Put requests will return 503 status code for failover testing | ||
failoverCount uint64 | ||
} | ||
|
||
func NewFakeDAServer(host string, port int, log log.Logger) *FakeDAServer { | ||
|
@@ -130,6 +134,10 @@ func (s *FakeDAServer) HandleGet(w http.ResponseWriter, r *http.Request) { | |
|
||
func (s *FakeDAServer) HandlePut(w http.ResponseWriter, r *http.Request) { | ||
time.Sleep(s.putRequestLatency) | ||
if s.failoverCount > 0 { | ||
w.WriteHeader(http.StatusServiceUnavailable) | ||
s.failoverCount-- | ||
} | ||
s.DAServer.HandlePut(w, r) | ||
} | ||
|
||
|
@@ -154,6 +162,11 @@ func (s *FakeDAServer) SetGetRequestLatency(latency time.Duration) { | |
s.getRequestLatency = latency | ||
} | ||
|
||
// SetResponseStatusForNRequests sets the next n Put requests to return 503 status code. | ||
func (s *FakeDAServer) SetPutFailoverForNRequests(n uint64) { | ||
s.failoverCount = uint64(n) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary typecast |
||
} | ||
|
||
type MemStore struct { | ||
db map[string][]byte | ||
lock sync.RWMutex | ||
|
This file contains 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 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 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 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 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 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 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 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 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,84 @@ | ||
package altda | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
op_e2e "github.com/ethereum-optimism/optimism/op-e2e" | ||
"github.com/ethereum-optimism/optimism/op-node/rollup/derive/params" | ||
"github.com/ethereum/go-ethereum/log" | ||
|
||
"github.com/ethereum-optimism/optimism/op-batcher/flags" | ||
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/geth" | ||
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/transactions" | ||
"github.com/ethereum-optimism/optimism/op-e2e/system/e2esys" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestBatcher_FailoverToEthDA_FallbackToAltDA tests that the batcher will failover to ethDA | ||
// if the da-server returns 503. It also tests that the batcher successfully returns to normal | ||
// behavior of posting batches to altda once it becomes available again | ||
// (i.e. the da-server doesn't return 503 anymore). | ||
func TestBatcher_FailoverToEthDA_FallbackToAltDA(t *testing.T) { | ||
op_e2e.InitParallel(t) | ||
|
||
nChannelsFailover := uint64(2) | ||
|
||
cfg := e2esys.DefaultSystemConfig(t, e2esys.WithLogLevel(log.LevelCrit)) | ||
cfg.DeployConfig.UseAltDA = true | ||
cfg.DeployConfig.DACommitmentType = "GenericCommitment" | ||
cfg.DeployConfig.DAChallengeWindow = 16 | ||
cfg.DeployConfig.DAResolveWindow = 16 | ||
cfg.DeployConfig.DABondSize = 1000000 | ||
cfg.DeployConfig.DAResolverRefundPercentage = 0 | ||
// With these settings, the batcher will post a single commitment per L1 block, | ||
// so it's easy to trigger failover and observe the commitment changing on the next L1 block. | ||
cfg.BatcherMaxPendingTransactions = 1 // no limit on parallel txs | ||
cfg.BatcherMaxConcurrentDARequest = 1 | ||
cfg.BatcherBatchType = 0 | ||
// We make channels as small as possible, such that they contain a single commitment. | ||
// This is because failover to ethDA happens on a per-channel basis (each new channel is sent to altDA first). | ||
// Hence, we can quickly observe the failover (to ethda) and fallback (to altda) behavior. | ||
// cfg.BatcherMaxL1TxSizeBytes = 1200 | ||
// currently altda commitments can only be sent as calldata | ||
cfg.DataAvailabilityType = flags.CalldataType | ||
|
||
sys, err := cfg.Start(t) | ||
require.NoError(t, err, "Error starting up system") | ||
defer sys.Close() | ||
l1Client := sys.NodeClient("l1") | ||
|
||
startBlockL1, err := geth.WaitForBlockWithTxFromSender(cfg.DeployConfig.BatchSenderAddress, l1Client, 10) | ||
require.NoError(t, err) | ||
|
||
// Simulate altda server returning 503 | ||
sys.FakeAltDAServer.SetPutFailoverForNRequests(nChannelsFailover) | ||
|
||
countEthDACommitment := uint64(0) | ||
|
||
// There is some nondeterministic timing behavior that affects whether the batcher has already | ||
// posted batches before seeing the abvoe SetPutFailoverForNRequests behavior change. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. abvoe -> above |
||
// Most likely, sequence of blocks will be: altDA, ethDA, ethDA, altDA, altDA, altDA. | ||
// 2 ethDA are expected (and checked for) because nChannelsFailover=2, so da-server will return 503 for 2 requests only, | ||
// and the batcher always tries altda first for a new channel, and failsover to ethDA only if altda returns 503. | ||
for blockNumL1 := startBlockL1.NumberU64(); blockNumL1 < startBlockL1.NumberU64()+6; blockNumL1++ { | ||
blockL1, err := geth.WaitForBlock(big.NewInt(0).SetUint64(blockNumL1), l1Client) | ||
require.NoError(t, err) | ||
batcherTxs, err := transactions.TransactionsBySender(blockL1, cfg.DeployConfig.BatchSenderAddress) | ||
require.NoError(t, err) | ||
require.Equal(t, 1, len(batcherTxs)) // sanity check: ensure BatcherMaxPendingTransactions=1 is working | ||
batcherTx := batcherTxs[0] | ||
if batcherTx.Data()[0] == 1 { | ||
t.Log("blockL1", blockNumL1, "batcherTxType", "altda") | ||
} else if batcherTx.Data()[0] == 0 { | ||
t.Log("blockL1", blockNumL1, "batcherTxType", "ethda") | ||
} else { | ||
t.Fatalf("unexpected batcherTxType: %v", batcherTx.Data()[0]) | ||
} | ||
if batcherTx.Data()[0] == byte(params.DerivationVersion0) { | ||
countEthDACommitment++ | ||
} | ||
} | ||
require.Equal(t, nChannelsFailover, countEthDACommitment, "Expected %v ethDA commitments, got %v", nChannelsFailover, countEthDACommitment) | ||
|
||
} |
This file contains 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
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.
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.
should you return in this if block, instead of continuing to call
HandlePut
?