forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP test(altda): add test for altda->ethda failover
- Loading branch information
Showing
6 changed files
with
138 additions
and
18 deletions.
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
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,86 @@ | ||
package altda | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
"testing" | ||
|
||
op_e2e "github.com/ethereum-optimism/optimism/op-e2e" | ||
"github.com/ethereum-optimism/optimism/op-node/rollup/derive" | ||
"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" | ||
) | ||
|
||
func TestBatcherFailoverToEthDA(t *testing.T) { | ||
op_e2e.InitParallel(t) | ||
|
||
cfg := e2esys.DefaultSystemConfig(t, e2esys.WithLogLevel(log.LevelCrit)) | ||
cfg.DeployConfig.UseAltDA = true | ||
// 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 | ||
// 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") | ||
// l2Seq := sys.NodeClient("sequencer") | ||
|
||
blockNumL1 := int64(0) | ||
// Wait for the first L1 block with a batcher tx to be mined | ||
// TODO: create an e2eutils function for this: WaitForBlockWithTxFromSender | ||
for { | ||
fmt.Printf("Waiting for L1 block %d\n", blockNumL1) | ||
blockL1, err := geth.WaitForBlock(big.NewInt(blockNumL1), l1Client) | ||
fmt.Println("received block", blockL1.Number().Int64()) | ||
require.NoError(t, err) | ||
batcherTxCount, err := transactions.TransactionsBySenderCount(blockL1, cfg.DeployConfig.BatchSenderAddress) | ||
require.NoError(t, err) | ||
if batcherTxCount > 0 { | ||
break | ||
} | ||
blockNumL1++ | ||
} | ||
|
||
blockL1, err := geth.WaitForBlock(big.NewInt(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 | ||
fmt.Printf("L1 Block %d: %d txs / %d from batcher\n", blockNumL1, len(blockL1.Transactions()), len(batcherTxs)) | ||
batcherTx := batcherTxs[0] | ||
fmt.Printf(" tx size: %d / data size: %d / first byte: %d\n", batcherTx.Size(), len(batcherTx.Data()), batcherTx.Data()[0]) | ||
require.Equal(t, byte(derive.DerivationVersion1), batcherTx.Data()[0]) | ||
|
||
// Simulate altda server returning 503 | ||
// sys.FakeAltDAServer.SetResponseStatus(http.StatusServiceUnavailable) | ||
sys.BatchSubmitter.BatcherConfig.UseAltDA = false | ||
|
||
seenEthDACommitment := false | ||
// 3 is arbitrary, but should be enough to see the commitment change | ||
// TODO: enable logs on batcher and figure out why this isn't working | ||
for i := int64(0); i < 3; i++ { | ||
blockL1, err = geth.WaitForBlock(big.NewInt(blockNumL1+1+i), 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 | ||
fmt.Printf("L1 Block %d: %d txs / %d from batcher\n", blockNumL1, len(blockL1.Transactions()), len(batcherTxs)) | ||
batcherTx = batcherTxs[0] | ||
fmt.Printf(" tx size: %d / data size: %d / first byte: %d\n", batcherTx.Size(), len(batcherTx.Data()), batcherTx.Data()[0]) | ||
if batcherTx.Data()[0] == byte(derive.DerivationVersion0) { | ||
seenEthDACommitment = true | ||
} | ||
} | ||
require.True(t, seenEthDACommitment, "Expected to see EthDA commitment within 3 blocks after failover") | ||
|
||
} |
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