Skip to content

Commit

Permalink
Merge pull request #263 from ethereum-optimism/11-13-chore_reduce_fla…
Browse files Browse the repository at this point in the history
…ke_on_ci

chore: reduce flake on CI
  • Loading branch information
jakim929 authored Nov 13, 2024
2 parents 5d08fc0 + 7eef368 commit 8b73f1f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 58 deletions.
1 change: 0 additions & 1 deletion admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type AdminServer struct {
cancel context.CancelFunc
wg sync.WaitGroup

rpcServer *rpc.Server
networkConfig *config.NetworkConfig

port uint64
Expand Down
61 changes: 23 additions & 38 deletions admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum-optimism/supersim/config"
"github.com/ethereum-optimism/supersim/genesis"
"github.com/ethereum-optimism/supersim/testutils"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -38,15 +39,6 @@ func TestAdminServerBasicFunctionality(t *testing.T) {
require.Equal(t, "OK", string(body))

require.NoError(t, adminServer.Stop(context.Background()))

// Add a small delay to ensure the server has fully stopped
time.Sleep(100 * time.Millisecond)

resp, err = http.Get(fmt.Sprintf("%s/ready", adminServer.Endpoint()))
if err == nil {
resp.Body.Close()
}
require.Error(t, err)
}

func TestGetL1AddressesRPC(t *testing.T) {
Expand All @@ -59,38 +51,31 @@ func TestGetL1AddressesRPC(t *testing.T) {

require.NoError(t, adminServer.Start(ctx))

var client *rpc.Client
waitErr := testutils.WaitForWithTimeout(context.Background(), 500*time.Millisecond, 10*time.Second, func() (bool, error) {
// Dial the RPC server
client, err := rpc.Dial(adminServer.Endpoint())
require.NoError(t, err)

var addresses map[string]string
chainID := uint64(902)
err = client.CallContext(context.Background(), &addresses, "admin_getL1Addresses", chainID)

require.NoError(t, err)

expectedAddresses := map[string]string{
"AddressManager": "0x90D0B458313d3A207ccc688370eE76B75200EadA",
"L1CrossDomainMessengerProxy": "0xeCA0f912b4bd255f3851951caE5775CC9400aA3B",
"L1ERC721BridgeProxy": "0xdC0917C61A4CD589B29b6464257d564C0abeBB2a",
"L1StandardBridgeProxy": "0x67B2aB287a32bB9ACe84F6a5A30A62597b10AdE9",
"L2OutputOracleProxy": "0x0000000000000000000000000000000000000000",
"OptimismMintableERC20FactoryProxy": "0xd4E933aa1f37A755135d7623488a383f8208CC7c",
"OptimismPortalProxy": "0x35e67BC631C327b60C6A39Cff6b03a8adBB19c2D",
"ProxyAdmin": "0x0000000000000000000000000000000000000000",
"SuperchainConfig": "0x0000000000000000000000000000000000000000",
"SystemConfigProxy": "0xFb295Aa436F23BE2Bd17678Adf1232bdec02FED1",
}

for key, expectedValue := range expectedAddresses {
if addresses[key] != expectedValue {
return false, nil
}
newClient, err := rpc.Dial(adminServer.Endpoint())
if err != nil {
return false, err
}

client = newClient
return true, nil
})

assert.NoError(t, waitErr)

var addresses map[string]string
chainID := genesis.GeneratedGenesisDeployment.L2s[1].ChainID
err := client.CallContext(context.Background(), &addresses, "admin_getL1Addresses", chainID)
require.NoError(t, err)

registryAddresses := genesis.GeneratedGenesisDeployment.L2s[1].RegistryAddressList()
assert.Equal(t, registryAddresses.AddressManager.String(), addresses["AddressManager"])
assert.Equal(t, registryAddresses.L1CrossDomainMessengerProxy.String(), addresses["L1CrossDomainMessengerProxy"])
assert.Equal(t, registryAddresses.L1ERC721BridgeProxy.String(), addresses["L1ERC721BridgeProxy"])
assert.Equal(t, registryAddresses.L1StandardBridgeProxy.String(), addresses["L1StandardBridgeProxy"])
assert.Equal(t, registryAddresses.L2OutputOracleProxy.String(), addresses["L2OutputOracleProxy"])
assert.Equal(t, registryAddresses.OptimismMintableERC20FactoryProxy.String(), addresses["OptimismMintableERC20FactoryProxy"])
assert.Equal(t, registryAddresses.OptimismPortalProxy.String(), addresses["OptimismPortalProxy"])
assert.Equal(t, registryAddresses.ProxyAdmin.String(), addresses["ProxyAdmin"])
assert.Equal(t, registryAddresses.SuperchainConfig.String(), addresses["SuperchainConfig"])
assert.Equal(t, registryAddresses.SystemConfigProxy.String(), addresses["SystemConfigProxy"])
}
22 changes: 19 additions & 3 deletions interop/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"time"

"github.com/ethereum-optimism/optimism/op-chain-ops/devkeys"
"github.com/ethereum-optimism/optimism/op-service/predeploys"
Expand Down Expand Up @@ -91,9 +92,9 @@ func (r *L2ToL2MessageRelayer) Start(indexer *L2ToL2MessageIndexer, clients map[
close(sentMessageCh)
return nil
case sentMessage := <-sentMessageCh:
if _, err := l2tol2CDM.RelayMessage(transactor, *sentMessage.Identifier(), sentMessage.MessagePayload()); err != nil {
r.logger.Debug("failed to relay message", "err", err)
return fmt.Errorf("failed to relay message: %w", err)
if err := r.relayMessageWithRetry(l2tol2CDM, transactor, sentMessage, 5); err != nil {
r.logger.Debug("failed to relay message after retries", "err", err)
return err
}
}
}
Expand All @@ -107,3 +108,18 @@ func (r *L2ToL2MessageRelayer) Start(indexer *L2ToL2MessageIndexer, clients map[
func (r *L2ToL2MessageRelayer) Stop(ctx context.Context) {
r.tasksCancel()
}

func (r *L2ToL2MessageRelayer) relayMessageWithRetry(l2tol2CDM *bindings.L2ToL2CrossDomainMessengerTransactor, transactor *bind.TransactOpts, sentMessage *L2ToL2MessageStoreEntry, maxRetries int) error {
for attempt := 0; attempt < maxRetries; attempt++ {
if _, err := l2tol2CDM.RelayMessage(transactor, *sentMessage.Identifier(), sentMessage.MessagePayload()); err != nil {
r.logger.Debug("failed to relay message", "err", err, "attempt", attempt+1, "maxRetries", maxRetries)
if attempt == maxRetries-1 {
return fmt.Errorf("failed to relay message after %d attempts: %w", maxRetries, err)
}
time.Sleep(time.Second * time.Duration(1<<attempt))
continue
}
return nil
}
return nil
}
6 changes: 2 additions & 4 deletions opsimulator/opsimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,14 @@ func (opSim *OpSimulator) checkInteropInvariants(ctx context.Context, logs []typ
}

if opSim.interopDelay != 0 {
// Add time check after getting the initiating message block header
header, err := opSim.ethClient.HeaderByNumber(ctx, nil)
if err != nil {
return fmt.Errorf("failed to fetch executing block header: %w", err)
}

// Check if at least 5 seconds have passed
if header.Time < identifierBlockHeader.Time+opSim.interopDelay {
return fmt.Errorf("not enough time has passed since initiating message (need 5s, got %ds)",
header.Time-identifierBlockHeader.Time)
return fmt.Errorf("not enough time has passed since initiating message (need %ds, got %ds)",
opSim.interopDelay, header.Time-identifierBlockHeader.Time)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion supersim.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *Supersim) ConfigAsString() string {

fmt.Fprintln(&b, "Supersim Config")
fmt.Fprintln(&b, "-----------------------")
fmt.Fprintf(&b, s.adminServer.ConfigAsString())
fmt.Fprintln(&b, s.adminServer.ConfigAsString())

fmt.Fprintln(&b, "Chain Configuration")
fmt.Fprintln(&b, "-----------------------")
Expand Down
17 changes: 6 additions & 11 deletions supersim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,6 @@ func TestAutoRelaySimpleStorageCallSucceeds(t *testing.T) {
}

func TestAutoRelaySuperchainWETHTransferSucceeds(t *testing.T) {
t.Parallel()

testSuite := createInteropTestSuite(t, config.CLIConfig{InteropAutoRelay: true})
privateKey, err := testSuite.DevKeys.Secret(devkeys.UserKey(0))
Expand Down Expand Up @@ -909,8 +908,6 @@ func TestForkAutoRelaySuperchainWETHTransferSucceeds(t *testing.T) {
}

func TestInteropInvariantSucceedsWithDelay(t *testing.T) {
t.Parallel()

testSuite := createInteropTestSuite(t, config.CLIConfig{
InteropDelay: 2, // 2 second delay
})
Expand Down Expand Up @@ -969,14 +966,11 @@ func TestInteropInvariantSucceedsWithDelay(t *testing.T) {
}

func TestInteropInvariantFailsWhenDelayTimeNotPassed(t *testing.T) {
t.Parallel()

testSuite := createInteropTestSuite(t, config.CLIConfig{
InteropDelay: 5,
})
privateKey, err := testSuite.DevKeys.Secret(devkeys.UserKey(0))
require.NoError(t, err)
fromAddress := crypto.PubkeyToAddress(privateKey.PublicKey)

l2ToL2CrossDomainMessenger, err := bindings.NewL2ToL2CrossDomainMessenger(predeploys.L2toL2CrossDomainMessengerAddr, testSuite.SourceEthClient)
require.NoError(t, err)
Expand All @@ -996,9 +990,6 @@ func TestInteropInvariantFailsWhenDelayTimeNotPassed(t *testing.T) {
require.NoError(t, err)
require.True(t, initiatingMessageTxReceipt.Status == 1, "initiating message transaction failed")

// Try to execute immediately without waiting for delay time
crossL2Inbox, err := bindings.NewCrossL2Inbox(predeploys.CrossL2InboxAddr, testSuite.DestEthClient)
require.NoError(t, err)
initiatingMessageBlockHeader, err := testSuite.SourceEthClient.HeaderByNumber(context.Background(), initiatingMessageTxReceipt.BlockNumber)
require.NoError(t, err)
initiatingMessageLog := initiatingMessageTxReceipt.Logs[0]
Expand All @@ -1012,8 +1003,12 @@ func TestInteropInvariantFailsWhenDelayTimeNotPassed(t *testing.T) {
transactor, err := bind.NewKeyedTransactorWithChainID(privateKey, testSuite.DestChainID)
require.NoError(t, err)

l2tol2CDM, err := bindings.NewL2ToL2CrossDomainMessengerTransactor(predeploys.L2toL2CrossDomainMessengerAddr, testSuite.DestEthClient)
require.NoError(t, err)

_, err = l2tol2CDM.RelayMessage(transactor, identifier, interop.ExecutingMessagePayloadBytes(initiatingMessageLog))

// Should fail because the delay time hasn't passed
_, err = crossL2Inbox.ExecuteMessage(transactor, identifier, fromAddress, initiatingMessageLog.Data)
require.Error(t, err)
require.Contains(t, err.Error(), "delay time not passed")
require.Contains(t, err.Error(), "not enough time has passed since initiating message")
}

0 comments on commit 8b73f1f

Please sign in to comment.