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

feat: allow to sequence_sender to work as Banana or Elderberry #16

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
467f15f
wip
joanestebanr Jul 17, 2024
684aef5
remove IsValidium from seqSender code
joanestebanr Jul 17, 2024
d82fbc4
remove unused file
joanestebanr Jul 17, 2024
83b2418
renamed
joanestebanr Jul 17, 2024
43d8bcd
wip
joanestebanr Jul 17, 2024
187efc6
add errors
joanestebanr Jul 18, 2024
9925aa8
revert multi-fork for etherman and remove wrappers for contracts
joanestebanr Jul 19, 2024
eca9e9d
add elderberry validium
joanestebanr Jul 22, 2024
e18eb66
wip-elderberry validium
joanestebanr Jul 22, 2024
6dd5417
add translator to override DAC members URLs
joanestebanr Jul 22, 2024
c32bf7a
add auto-config kurtosis environment
joanestebanr Jul 23, 2024
b9e4e02
fix bugs, fix kurtosis config
joanestebanr Jul 23, 2024
037e705
maxbatchesforL1=0 -> disabled
joanestebanr Jul 23, 2024
ff9407a
wip
joanestebanr Jul 24, 2024
c0634c2
fix script
joanestebanr Jul 24, 2024
fc95005
add e2e test
joanestebanr Jul 24, 2024
3f2c709
comments on PR
joanestebanr Jul 24, 2024
b024837
wip
joanestebanr Jul 24, 2024
8b7ac7d
wip
joanestebanr Jul 24, 2024
a152f31
wip
joanestebanr Jul 24, 2024
55b6d3d
wip
joanestebanr Jul 24, 2024
98eba40
add verify batches check
joanestebanr Jul 24, 2024
852d339
placeholder for testing GHaction
joanestebanr Jul 25, 2024
1ae1696
Merge pull request #20 from 0xPolygon/feature/ghaction-test-main
joanestebanr Jul 25, 2024
953f6ff
test
joanestebanr Jul 25, 2024
8e9482b
wip
joanestebanr Jul 25, 2024
85c3852
add workflow_dispatch
joanestebanr Jul 25, 2024
8b8cffc
wip
joanestebanr Jul 25, 2024
f256553
Merge pull request #21 from 0xPolygon/feature/ghaction-test-main
joanestebanr Jul 25, 2024
6735d80
Merge branch 'main' into feature/seq_sender-multi-fork
joanestebanr Jul 25, 2024
e8901a3
wip
joanestebanr Jul 25, 2024
b75e72c
wip
joanestebanr Jul 25, 2024
4a413a1
wip
joanestebanr Jul 25, 2024
62f3fed
wip
joanestebanr Jul 25, 2024
b0a99e3
wip
joanestebanr Jul 25, 2024
95f46fb
wip
joanestebanr Jul 25, 2024
9c28cc1
wip
joanestebanr Jul 25, 2024
b2dd6a0
disabled datacommitte test because PUSH0 is not supported by geth sim…
joanestebanr Jul 25, 2024
ab3a462
wip
joanestebanr Jul 25, 2024
1fc99d7
PR comments
joanestebanr Jul 25, 2024
06aa68c
Update dataavailability/datacommittee/datacommittee.go
joanestebanr Jul 25, 2024
af1640d
PR comments
joanestebanr Jul 25, 2024
4979588
Update Makefile
joanestebanr Jul 25, 2024
19dab0c
Update dataavailability/datacommittee/datacommittee_test.go
joanestebanr Jul 25, 2024
f499b7f
Update test/scripts/config_kurtosis_for_local_run.sh
joanestebanr Jul 25, 2024
f1085b6
PR comments
joanestebanr Jul 25, 2024
fddefb1
Update test/config/test.kurtosis_template.toml
joanestebanr Jul 25, 2024
95799d6
PR comments
joanestebanr Jul 25, 2024
f34765f
PR comments
joanestebanr Jul 25, 2024
14eb4fa
PR comments
joanestebanr Jul 25, 2024
8adc59e
PR comments
joanestebanr Jul 25, 2024
9c2e662
PR comments
joanestebanr Jul 25, 2024
e3c3a59
Update cmd/run.go
joanestebanr Jul 25, 2024
098b503
PR comments
joanestebanr Jul 25, 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
67 changes: 67 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Test e2e
on:
push:
branches:
- '**'
workflow_dispatch: {}


jobs:
test-e2e:
strategy:
fail-fast: false
matrix:
go-version: [ 1.21.x ]
goarch: [ "amd64" ]
e2e-group: [ "elderberry-validium", "elderberry-rollup" ]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
env:
GOARCH: ${{ matrix.goarch }}

- name: Build Docker
run: make build-docker

# this is better to get the action in
- name: Install kurtosis
shell: bash
run: |
echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
sudo apt update
sudo apt install kurtosis-cli=0.90.1
kurtosis version

- name: Disable kurtosis analytics
shell: bash
run: kurtosis analytics disable

- name: Install yq
shell: bash
run: |
pip3 install yq
yq --version

- name: Install foundry
uses: foundry-rs/foundry-toolchain@v1

- name: checkout kurtosis-cdk
uses: actions/checkout@v4
with:
repository: 0xPolygon/kurtosis-cdk
ref: jesteban/cdk-seq_sender
joanestebanr marked this conversation as resolved.
Show resolved Hide resolved
path: "ext/kurtosis-cdk"

- name: Link kurtosis-cdk folder
shell: bash
run: mkdir -p /tmp/cdk/ && ln -s $GITHUB_WORKSPACE/ext/kurtosis-cdk /tmp/cdk/kurtosis-cdk-jesteban_cdk-seq_sender_

- name: Test
run: make test-e2e-${{ matrix.e2e-group }}
working-directory: test
20 changes: 20 additions & 0 deletions .github/workflows/test-unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test Unittest
on:
push:
branches:
- '**'
workflow_dispatch: {}


jobs:
test-unittest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v3

- name: Launch unittest
run: make test
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ RUN cd /src && make build
# CONTAINER FOR RUNNING BINARY
FROM alpine:3.18.4
COPY --from=build /src/dist/cdk /app/cdk
RUN apk update && apk add postgresql15-client
RUN mkdir /app/data && apk update && apk add postgresql15-client
EXPOSE 8123
CMD ["/bin/sh", "-c", "/app/cdk run"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ stop: ## Stops all services

.PHONY: test
test:
go test -count=1 -short -race -p 1 -timeout 60s ./...
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=../coverage.out -coverpkg ./... -timeout 200s ./...

.PHONY: install-linter
install-linter: ## Installs the linter
Expand Down
57 changes: 47 additions & 10 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ import (
"github.com/0xPolygon/cdk/dataavailability"
"github.com/0xPolygon/cdk/dataavailability/datacommittee"
"github.com/0xPolygon/cdk/etherman"
ethermanconfig "github.com/0xPolygon/cdk/etherman/config"
"github.com/0xPolygon/cdk/etherman/contracts"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/sequencesender"
"github.com/0xPolygon/cdk/sequencesender/txbuilder"
"github.com/0xPolygon/cdk/state"
"github.com/0xPolygon/cdk/state/pgstatestorage"
"github.com/0xPolygon/cdk/translator"
ethtxman "github.com/0xPolygonHermez/zkevm-ethtx-manager/etherman"
"github.com/0xPolygonHermez/zkevm-ethtx-manager/etherman/etherscan"
"github.com/jackc/pgx/v4/pgxpool"
Expand Down Expand Up @@ -111,7 +115,7 @@ func createAggregator(ctx context.Context, c config.Config, runMigrations bool)
}

func createSequenceSender(cfg config.Config) *sequencesender.SequenceSender {
ethman, err := etherman.NewClient(etherman.Config{
ethman, err := etherman.NewClient(ethermanconfig.Config{
EthermanConfig: ethtxman.Config{
URL: cfg.SequenceSender.EthTxManager.Etherman.URL,
MultiGasProvider: cfg.SequenceSender.EthTxManager.Etherman.MultiGasProvider,
Expand All @@ -122,10 +126,9 @@ func createSequenceSender(cfg config.Config) *sequencesender.SequenceSender {
},
HTTPHeaders: cfg.SequenceSender.EthTxManager.Etherman.HTTPHeaders,
},
IsValidiumMode: cfg.SequenceSender.IsValidiumMode,
}, cfg.NetworkConfig.L1Config)
}, cfg.NetworkConfig.L1Config, cfg.Common)
if err != nil {
log.Fatal(err)
log.Fatalf("Failed to create etherman. Err: %w, ", err)
}

auth, _, err := ethman.LoadAuthFromKeyStore(cfg.SequenceSender.PrivateKey.Path, cfg.SequenceSender.PrivateKey.Password)
Expand All @@ -134,23 +137,56 @@ func createSequenceSender(cfg config.Config) *sequencesender.SequenceSender {
}
cfg.SequenceSender.SenderAddress = auth.From

da, err := newDataAvailability(cfg, ethman)
txBuilder, err := newTxBuilder(cfg, ethman)
if err != nil {
log.Fatal(err)
}

seqSender, err := sequencesender.New(cfg.SequenceSender, ethman, da)
seqSender, err := sequencesender.New(cfg.SequenceSender, ethman, txBuilder)
if err != nil {
log.Fatal(err)
}

return seqSender
}

func newTxBuilder(cfg config.Config, ethman *etherman.Client) (txbuilder.TxBuilder, error) {
auth, _, err := ethman.LoadAuthFromKeyStore(cfg.SequenceSender.PrivateKey.Path, cfg.SequenceSender.PrivateKey.Password)
if err != nil {
log.Fatal(err)
}
da, err := newDataAvailability(cfg, ethman)
if err != nil {
log.Fatal(err)
}
var txBuilder txbuilder.TxBuilder

switch contracts.VersionType(cfg.Common.ContractVersions) {
case contracts.VersionBanana:
if cfg.Common.IsValidiumMode {
txBuilder = txbuilder.NewTxBuilderBananaValidium(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, da, *auth, auth.From, cfg.SequenceSender.MaxBatchesForL1)
} else {
txBuilder = txbuilder.NewTxBuilderBananaZKEVM(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, *auth, auth.From, cfg.SequenceSender.MaxTxSizeForL1)
}
case contracts.VersionElderberry:
if cfg.Common.IsValidiumMode {
txBuilder = txbuilder.NewTxBuilderElderberryValidium(ethman.Contracts.Elderberry.Rollup, da, *auth, auth.From, cfg.SequenceSender.MaxBatchesForL1)
} else {
txBuilder = txbuilder.NewTxBuilderElderberryZKEVM(ethman.Contracts.Elderberry.Rollup, *auth, auth.From, cfg.SequenceSender.MaxTxSizeForL1)
}
default:
err = fmt.Errorf("unknown contract version: %s", cfg.Common.ContractVersions)
}

return txBuilder, err
}

func newDataAvailability(c config.Config, etherman *etherman.Client) (*dataavailability.DataAvailability, error) {
if !c.SequenceSender.IsValidiumMode {
if !c.Common.IsValidiumMode {
return nil, nil
}
translator := translator.NewTranslatorImpl()
log.Infof("Translator rules: %v", c.Common.Translator)
translator.AddConfigRules(c.Common.Translator)

// Backend specific config
daProtocolName, err := etherman.GetDAProtocolName()
Expand Down Expand Up @@ -178,6 +214,7 @@ func newDataAvailability(c config.Config, etherman *etherman.Client) (*dataavail
dacAddr,
pk,
dataCommitteeClient.NewFactory(),
translator,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -209,10 +246,10 @@ func runMigrations(c db.Config, name string) {
}

func newEtherman(c config.Config) (*etherman.Client, error) {
config := etherman.Config{
config := ethermanconfig.Config{
URL: c.Aggregator.EthTxManager.Etherman.URL,
}
return etherman.NewClient(config, c.NetworkConfig.L1Config)
return etherman.NewClient(config, c.NetworkConfig.L1Config, c.Common)
}

func logVersion() {
Expand Down
11 changes: 11 additions & 0 deletions common/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package common

import "github.com/0xPolygon/cdk/translator"

type Config struct {
// IsValidiumMode has the value true if the sequence sender is running in validium mode.
IsValidiumMode bool `mapstructure:"IsValidiumMode"`
// Contract Versions: elderberry, banana
ContractVersions string `mapstructure:"ContractVersions"`
Translator translator.Config `mapstructure:"Translator"`
}
8 changes: 6 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"strings"

"github.com/0xPolygon/cdk/aggregator"
"github.com/0xPolygon/cdk/etherman"
"github.com/0xPolygon/cdk/common"
ethermanconfig "github.com/0xPolygon/cdk/etherman/config"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/sequencesender"
"github.com/0xPolygonHermez/zkevm-ethtx-manager/ethtxmanager"
Expand Down Expand Up @@ -55,7 +56,7 @@ You could find some examples:
*/
type Config struct {
// Configuration of the etherman (client for access L1)
Etherman etherman.Config
Etherman ethermanconfig.Config
// Configuration for ethereum transaction manager
EthTxManager ethtxmanager.Config
// Configuration of the aggregator
Expand All @@ -66,6 +67,9 @@ type Config struct {
NetworkConfig NetworkConfig
// Configuration of the sequence sender service
SequenceSender sequencesender.Config

// Common Config that affects all the services
Common common.Config
}

// Default parses the default configuration values.
Expand Down
5 changes: 4 additions & 1 deletion config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ const DefaultValues = `
ForkUpgradeBatchNumber = 0
ForkUpgradeNewForkId = 0

[Common]
IsValidiumMode = false
ContractVersions = "banana"

[Log]
Environment = "development" # "production" or "development"
Level = "info"
Outputs = ["stderr"]

[SequenceSender]
IsValidiumMode = false
WaitPeriodSendSequence = "15s"
LastBatchVirtualizationTimeMaxWaitPeriod = "10s"
L1BlockTimestampMargin = "30s"
Expand Down
6 changes: 3 additions & 3 deletions config/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"os"

"github.com/0xPolygon/cdk/etherman"
ethermanconfig "github.com/0xPolygon/cdk/etherman/config"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/state"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -17,7 +17,7 @@ import (
// NetworkConfig is the configuration struct for the different environments
type NetworkConfig struct {
// L1: Configuration related to L1
L1Config etherman.L1Config `json:"l1Config"`
L1Config ethermanconfig.L1Config `json:"l1Config"`
// L1: Genesis of the rollup, first block number and root
Genesis state.Genesis
}
Expand Down Expand Up @@ -48,7 +48,7 @@ type GenesisFromJSON struct {
// L2: List of states contracts used to populate merkle tree at initial state
Genesis []genesisAccountFromJSON `json:"genesis"`
// L1: configuration of the network
L1Config etherman.L1Config
L1Config ethermanconfig.L1Config
}

type genesisAccountFromJSON struct {
Expand Down
4 changes: 4 additions & 0 deletions dataavailability/dataavailability.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ func New(backend DABackender) (*DataAvailability, error) {
func (d *DataAvailability) PostSequence(ctx context.Context, sequenceBanana etherman.SequenceBanana) ([]byte, error) {
return d.backend.PostSequence(ctx, sequenceBanana)
}

func (d *DataAvailability) PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error) {
return d.backend.PostSequenceElderberry(ctx, batchesData)
}
Loading
Loading