Skip to content
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

Fjord: Brotli op-e2e test #10531

Merged
merged 43 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a727046
wip
cody-wang-cb Apr 26, 2024
9e1673b
wip
cody-wang-cb Apr 30, 2024
e732b21
fix
cody-wang-cb May 1, 2024
6566283
fix
cody-wang-cb May 1, 2024
4eb83ea
fix
cody-wang-cb May 1, 2024
934ed5e
fix
cody-wang-cb May 1, 2024
ec984a3
address some of the bots comments
cody-wang-cb May 1, 2024
a5ba98e
use version bit of 1
cody-wang-cb May 2, 2024
940f2bc
fix lint
cody-wang-cb May 2, 2024
642933e
adding compression type
cody-wang-cb May 2, 2024
8bd2eb6
update batch reader
cody-wang-cb May 2, 2024
314e99d
abstract span channel compressor
cody-wang-cb May 3, 2024
fee3e44
test and singular batch compressor
cody-wang-cb May 5, 2024
633aae2
fix
cody-wang-cb May 5, 2024
bf3675a
lint
cody-wang-cb May 5, 2024
1efd338
move channel compressor as interface
cody-wang-cb May 7, 2024
42ade28
add base class
cody-wang-cb May 7, 2024
6e09caf
fix go mod
cody-wang-cb May 8, 2024
e5f7e6c
test fixes
May 8, 2024
1730bfc
Merge pull request #4 from roberto-bayardo/tmp
cody-wang-cb May 8, 2024
c5f28f3
address comments
cody-wang-cb May 9, 2024
aade67d
fix
cody-wang-cb May 9, 2024
c69be77
merge from develop
cody-wang-cb May 9, 2024
ca47d0f
fix
cody-wang-cb May 10, 2024
729616f
revert channel builder test
cody-wang-cb May 10, 2024
7aaa4ed
revert ratio compressor test
cody-wang-cb May 10, 2024
da699a9
add checks to accept brotli only post fjord
cody-wang-cb May 10, 2024
abdea7d
revemo unnecessary in test
cody-wang-cb May 10, 2024
3ad55be
Merge branch 'develop' into cody/brotli-impl
cody-wang-cb May 10, 2024
5f1b198
fix forge-std
cody-wang-cb May 10, 2024
7298161
gofmt
cody-wang-cb May 10, 2024
aa0823b
address comments
cody-wang-cb May 11, 2024
010ed14
remove methods in compressor
cody-wang-cb May 11, 2024
d508412
fix error msg
cody-wang-cb May 11, 2024
7ecd688
Merge branch 'develop' into cody/brotli-impl
cody-wang-cb May 13, 2024
be6629e
add compression algo flag to optional flags
cody-wang-cb May 13, 2024
eadc24e
add Clone() function
cody-wang-cb May 13, 2024
ade9cc1
brotli e2e test
cody-wang-cb May 14, 2024
cd1b893
merge from develop
cody-wang-cb May 14, 2024
760b8c9
fix fmt
cody-wang-cb May 14, 2024
4926e1c
fix comments
cody-wang-cb May 14, 2024
c687a5f
fix
cody-wang-cb May 14, 2024
dd5754b
update
cody-wang-cb May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions op-e2e/brotli_batcher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package op_e2e

import (
"context"
"crypto/ecdsa"
"math/big"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"

batcherFlags "github.com/ethereum-optimism/optimism/op-batcher/flags"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-service/client"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum-optimism/optimism/op-service/testlog"
)

func setupAliceAccount(t *testing.T, cfg SystemConfig, sys *System, ethPrivKey *ecdsa.PrivateKey) {
l1Client := sys.Clients["l1"]
l2Verif := sys.Clients["verifier"]

// Send Transaction & wait for success
fromAddr := cfg.Secrets.Addresses().Alice
log.Info("alice", "addr", fromAddr)

ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
startBalance, err := l2Verif.BalanceAt(ctx, fromAddr, nil)
require.NoError(t, err)

// Send deposit transaction
opts, err := bind.NewKeyedTransactorWithChainID(ethPrivKey, cfg.L1ChainIDBig())
require.NoError(t, err)
mintAmount := big.NewInt(1_000_000_000_000)
opts.Value = mintAmount
SendDepositTx(t, cfg, l1Client, l2Verif, opts, func(l2Opts *DepositTxOpts) {})

// Confirm balance
ctx, cancel = context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
endBalance, err := wait.ForBalanceChange(ctx, l2Verif, fromAddr, startBalance)
require.NoError(t, err)

diff := new(big.Int).Sub(endBalance, startBalance)
require.Equal(t, mintAmount, diff, "Did not get expected balance change")
}

func TestBrotliBatcherFjord(t *testing.T) {
InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg.DataAvailabilityType = batcherFlags.BlobsType

genesisActivation := hexutil.Uint64(0)
cfg.DeployConfig.L1CancunTimeOffset = &genesisActivation
cfg.DeployConfig.L2GenesisDeltaTimeOffset = &genesisActivation
cfg.DeployConfig.L2GenesisEcotoneTimeOffset = &genesisActivation
cfg.DeployConfig.L2GenesisFjordTimeOffset = &genesisActivation

// set up batcher to use brotli
sys, err := cfg.Start(t, SystemConfigOption{"compressionAlgo", "brotli", nil})
require.Nil(t, err, "Error starting up system")
defer sys.Close()

log := testlog.Logger(t, log.LevelInfo)
log.Info("genesis", "l2", sys.RollupConfig.Genesis.L2, "l1", sys.RollupConfig.Genesis.L1, "l2_time", sys.RollupConfig.Genesis.L2Time)

l2Seq := sys.Clients["sequencer"]
l2Verif := sys.Clients["verifier"]

// Transactor Account and set up the account
ethPrivKey := cfg.Secrets.Alice
setupAliceAccount(t, cfg, sys, ethPrivKey)

// Submit TX to L2 sequencer node
receipt := SendL2Tx(t, cfg, l2Seq, ethPrivKey, func(opts *TxOpts) {
opts.Value = big.NewInt(1_000_000_000)
opts.Nonce = 1 // Already have deposit
opts.ToAddr = &common.Address{0xff, 0xff}
opts.Gas, err = core.IntrinsicGas(opts.Data, nil, false, true, true, false)
require.NoError(t, err)
opts.VerifyOnClients(l2Verif)
})

// Verify blocks match after batch submission on verifiers and sequencers
verifBlock, err := l2Verif.BlockByNumber(context.Background(), receipt.BlockNumber)
require.NoError(t, err)
require.Equal(t, verifBlock.Hash(), receipt.BlockHash, "must be same block")
seqBlock, err := l2Seq.BlockByNumber(context.Background(), receipt.BlockNumber)
require.NoError(t, err)
require.Equal(t, seqBlock.Hash(), receipt.BlockHash, "must be same block")
require.Equal(t, verifBlock.NumberU64(), seqBlock.NumberU64(), "Verifier and sequencer blocks not the same after including a batch tx")
require.Equal(t, verifBlock.ParentHash(), seqBlock.ParentHash(), "Verifier and sequencer blocks parent hashes not the same after including a batch tx")
require.Equal(t, verifBlock.Hash(), seqBlock.Hash(), "Verifier and sequencer blocks not the same after including a batch tx")

rollupRPCClient, err := rpc.DialContext(context.Background(), sys.RollupNodes["sequencer"].HTTPEndpoint())
require.NoError(t, err)
rollupClient := sources.NewRollupClient(client.NewBaseRPCClient(rollupRPCClient))
// basic check that sync status works
seqStatus, err := rollupClient.SyncStatus(context.Background())
require.NoError(t, err)
require.LessOrEqual(t, seqBlock.NumberU64(), seqStatus.UnsafeL2.Number)

// quick check that the batch submitter works
require.Eventually(t, func() bool {
// wait for chain to be marked as "safe" (i.e. confirm batch-submission works)
stat, err := rollupClient.SyncStatus(context.Background())
require.NoError(t, err)
return stat.SafeL2.Number >= receipt.BlockNumber.Uint64()
}, time.Second*20, time.Second, "expected L2 to be batch-submitted and labeled as safe")

// check that the L2 tx is still canonical
// safe and canonical => the block was batched successfully with brotli
seqBlock, err = l2Seq.BlockByNumber(context.Background(), receipt.BlockNumber)
require.NoError(t, err)
require.Equal(t, seqBlock.Hash(), receipt.BlockHash, "receipt block must match canonical block at tx inclusion height")
}
9 changes: 8 additions & 1 deletion op-e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,13 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste
if batcherTargetNumFrames == 0 {
batcherTargetNumFrames = 1
}

var compressionAlgo derive.CompressionAlgo = derive.Zlib
// if opt has brotli key, set the compression algo as brotli
if _, ok := opts.Get("compressionAlgo", "brotli"); ok {
compressionAlgo = derive.Brotli10
}

batcherCLIConfig := &bss.CLIConfig{
L1EthRpc: sys.EthInstances["l1"].WSEndpoint(),
L2EthRpc: sys.EthInstances["sequencer"].WSEndpoint(),
Expand All @@ -845,7 +852,7 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste
Stopped: sys.Cfg.DisableBatcher, // Batch submitter may be enabled later
BatchType: batchType,
DataAvailabilityType: sys.Cfg.DataAvailabilityType,
CompressionAlgo: derive.Zlib,
CompressionAlgo: compressionAlgo,
}
// Batch Submitter
batcher, err := bss.BatcherServiceFromCLIConfig(context.Background(), "0.0.1", batcherCLIConfig, sys.Cfg.Loggers["batcher"])
Expand Down