From 046b264100afbf9a9b8b8892675e9741c0d507b1 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:33:25 +0100 Subject: [PATCH] feat: add tools --- .github/workflows/test-e2e-multi_pp.yml | 4 + Dockerfile | 4 +- Makefile | 6 +- crates/cdk/versions.json | 8 +- test/bats/pp-multi/bridge-l2_to_l2-e2e.bats | 12 +- test/helpers/lxly-bridge-test.bash | 3 + .../aggsender_find_imported_bridge.go | 112 ++++++++++++++++++ version.go | 2 +- 8 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 tools/aggsender_find_imported_bridge/aggsender_find_imported_bridge.go diff --git a/.github/workflows/test-e2e-multi_pp.yml b/.github/workflows/test-e2e-multi_pp.yml index 1d25fbf7..72c7140d 100644 --- a/.github/workflows/test-e2e-multi_pp.yml +++ b/.github/workflows/test-e2e-multi_pp.yml @@ -27,10 +27,14 @@ jobs: go-version: ${{ matrix.go-version }} env: GOARCH: ${{ matrix.goarch }} + - name: Build Docker run: make build-docker + - name: Build Tools + run: make build-tools + - name: Checkout kurtosis-cdk uses: actions/checkout@v4 with: diff --git a/Dockerfile b/Dockerfile index 22e36595..fe0cf433 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ RUN go mod download # BUILD BINARY COPY . . -RUN make build-go +RUN make build-go build-tools # BUILD RUST BIN FROM --platform=${BUILDPLATFORM} rust:slim-bookworm AS chef @@ -46,4 +46,6 @@ RUN apt-get update && apt-get install -y ca-certificates sqlite3 procps libssl-d COPY --from=builder /app/target/release/cdk /usr/local/bin/ COPY --from=build /go/src/github.com/0xPolygon/cdk/target/cdk-node /usr/local/bin/ +EXPOSE 5576/tcp + CMD ["/bin/sh", "-c", "cdk"] diff --git a/Makefile b/Makefile index 2adb0c40..fad3c395 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ install-linter: check-go check-curl generate-code-from-proto: check-protoc .PHONY: build -build: build-rust build-go ## Builds the binaries locally into ./target +build: build-rust build-go build-tools## Builds the binaries locally into ./target .PHONY: build-rust build-rust: @@ -66,6 +66,10 @@ build-rust: build-go: $(GOENVVARS) go build -ldflags "all=$(LDFLAGS)" -o $(GOBIN)/$(GOBINARY) $(GOCMD) +.PHONY: build-tools +build-tools: ## Builds the tools + $(GOENVVARS) go build -o $(GOBIN)/aggsender_find_imported_bridge ./tools/aggsender_find_imported_bridge + .PHONY: build-docker build-docker: ## Builds a docker image with the cdk binary docker build -t cdk -f ./Dockerfile . diff --git a/crates/cdk/versions.json b/crates/cdk/versions.json index d2612714..fe782279 100644 --- a/crates/cdk/versions.json +++ b/crates/cdk/versions.json @@ -1,13 +1,13 @@ { "agglayer_image": "ghcr.io/agglayer/agglayer:0.2.0-rc.17", "cdk_erigon_node_image": "hermeznetwork/cdk-erigon:v2.60.0", - "cdk_node_image": "ghcr.io/0xpolygon/cdk:0.4.0", + "cdk_node_image": "ghcr.io/0xpolygon/cdk:0.5.0-beta10", "cdk_validium_node_image": "0xpolygon/cdk-validium-node:0.7.0-cdk", "zkevm_bridge_proxy_image": "haproxy:3.1-bookworm", - "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC2", + "zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC3", "zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network", - "zkevm_contracts_image": "leovct/zkevm-contracts:v8.0.0-fork.12", - "zkevm_da_image": "0xpolygon/cdk-data-availability:0.0.10", + "zkevm_contracts_image": "leovct/zkevm-contracts:v8.0.0-fork.12-patch.1", + "zkevm_da_image": "0xpolygon/cdk-data-availability:0.0.11", "zkevm_node_image": "hermeznetwork/zkevm-node:v0.7.3", "zkevm_pool_manager_image": "hermeznetwork/zkevm-pool-manager:v0.1.2", "zkevm_prover_image": "hermeznetwork/zkevm-prover:v8.0.0-RC14-fork.12", diff --git a/test/bats/pp-multi/bridge-l2_to_l2-e2e.bats b/test/bats/pp-multi/bridge-l2_to_l2-e2e.bats index 5f8842ae..dd6ff574 100644 --- a/test/bats/pp-multi/bridge-l2_to_l2-e2e.bats +++ b/test/bats/pp-multi/bridge-l2_to_l2-e2e.bats @@ -55,9 +55,10 @@ setup() { bridge_asset "$native_token_addr" "$l2_pp2_url" echo "=== Running LxLy claim L2(PP2) to L2(PP1) for: $bridge_tx_hash" >&3 - run claim_tx_hash "$timeout" "$bridge_tx_hash" "$destination_addr" "$l2_pp1_url" "$l2_pp2b_url" - assert_success - + claim_tx_hash "$timeout" "$bridge_tx_hash" "$destination_addr" "$l2_pp1_url" "$l2_pp2b_url" + echo "... deposit $global_index" + global_index_pp2_to_pp1=$global_index + # Now a need to do a bridge on L2(PP1) to trigger a certificate: ether_value=${ETHER_VALUE:-"0.0100000054"} amount=$(cast to-wei $ether_value ether) @@ -69,4 +70,9 @@ setup() { echo "=== Running LxLy claim L2(PP1) to L1 for $bridge_tx_hash" >&3 run claim_tx_hash "$timeout" "$bridge_tx_hash" "$destination_addr" "$l1_rpc_url" "$l2_pp1b_url" assert_success + + echo "=== Check if deposit is in a settled certificate" + + aggsender_pp1_url=http://localhost:5576/ + ../../../../target/aggsender_find_imported_bridge $aggsender_pp1_url $global_index_pp2_to_pp1 } diff --git a/test/helpers/lxly-bridge-test.bash b/test/helpers/lxly-bridge-test.bash index 10c53683..fd171d37 100644 --- a/test/helpers/lxly-bridge-test.bash +++ b/test/helpers/lxly-bridge-test.bash @@ -133,6 +133,8 @@ function claim() { # This function is used to claim a concrete tx hash # global vars: # - destination_addr +# export: +# - global_index function claim_tx_hash() { local timeout="$1" @@ -216,6 +218,7 @@ function claim_tx_hash() { fi done echo "....[$(date '+%Y-%m-%d %H:%M:%S')] claimed" >&3 + export global_index=$(jq '.global_index' $current_deposit) # clean up temp files rm $current_deposit rm $current_proof diff --git a/tools/aggsender_find_imported_bridge/aggsender_find_imported_bridge.go b/tools/aggsender_find_imported_bridge/aggsender_find_imported_bridge.go new file mode 100644 index 00000000..aa2581a1 --- /dev/null +++ b/tools/aggsender_find_imported_bridge/aggsender_find_imported_bridge.go @@ -0,0 +1,112 @@ +package main + +import ( + "encoding/json" + "fmt" + "math/big" + "os" + + "github.com/0xPolygon/cdk/agglayer" + "github.com/0xPolygon/cdk/aggsender/rpcclient" + "github.com/0xPolygon/cdk/aggsender/types" + "github.com/0xPolygon/cdk/bridgesync" + "github.com/0xPolygon/cdk/log" +) + +const ( + errLevelUnexpected = 1 + errLevelWrongParams = 2 + errLevelComms = 3 + errLevelNotFound = 4 + errLevelFoundButNotSettled = 5 +) + +func unmarshalGlobalIndex(globalIndex string) (*agglayer.GlobalIndex, error) { + var globalIndexParsed agglayer.GlobalIndex + // First try if it's already decomposed + err := json.Unmarshal([]byte(globalIndex), &globalIndexParsed) + if err != nil { + bigInt := new(big.Int) + _, ok := bigInt.SetString(globalIndex, 10) + if !ok { + return nil, fmt.Errorf("invalid global index: %v", globalIndex) + } + mainnetFlag, rollupIndex, leafIndex, err := bridgesync.DecodeGlobalIndex(bigInt) + if err != nil { + return nil, fmt.Errorf("invalid global index, fail to decode: %v", globalIndex) + } + globalIndexParsed.MainnetFlag = mainnetFlag + globalIndexParsed.RollupIndex = rollupIndex + globalIndexParsed.LeafIndex = leafIndex + } + return &globalIndexParsed, nil +} + +// This function find out the certificate for a deposit +// It use the aggsender RPC +func certContainsGlobalIndex(cert *types.CertificateInfo, globalIndex *agglayer.GlobalIndex) (bool, error) { + if cert == nil { + return false, nil + } + var certSigned agglayer.SignedCertificate + err := json.Unmarshal([]byte(cert.SignedCertificate), &certSigned) + if err != nil { + return false, err + } + for _, importedBridge := range certSigned.ImportedBridgeExits { + if *importedBridge.GlobalIndex == *globalIndex { + return true, nil + } + + } + return false, nil +} + +func main() { + aggsenderRPC := os.Args[1] + globalIndex := os.Args[2] + decodedGlobalIndex, err := unmarshalGlobalIndex(globalIndex) + if err != nil { + log.Errorf("Error unmarshalGlobalIndex: %v", err) + os.Exit(errLevelWrongParams) + } + aggsenderClient := rpcclient.NewClient(aggsenderRPC) + // Get first certificate + cert, err := aggsenderClient.GetCertificateHeaderPerHeight(nil) + if err != nil { + log.Errorf("Error: %v", err) + os.Exit(errLevelComms) + } + currentHeight := cert.Height + for cert != nil { + found, err := certContainsGlobalIndex(cert, decodedGlobalIndex) + if err != nil { + log.Errorf("Error: %v", err) + os.Exit(1) + } + if found { + log.Infof("Found certificate for global index: %v", globalIndex) + if cert.Status.IsSettled() { + log.Infof("Certificate is settled") + os.Exit(0) + } + log.Errorf("Certificate is not settled") + os.Exit(errLevelFoundButNotSettled) + } else { + log.Debugf("Certificate not found for global index: %v", globalIndex) + } + // We have check the oldest cert + if currentHeight == 0 { + log.Errorf("Checked all certs and it's not found") + os.Exit(errLevelNotFound) + } + log.Infof("Checking previous certificate, height: %v", currentHeight) + cert, err = aggsenderClient.GetCertificateHeaderPerHeight(¤tHeight) + if err != nil { + log.Errorf("Error: %v", err) + os.Exit(errLevelComms) + } + currentHeight-- + } + +} diff --git a/version.go b/version.go index 7fd8171a..ee8fce05 100644 --- a/version.go +++ b/version.go @@ -25,7 +25,7 @@ func PrintVersion(w io.Writer) { } type FullVersion struct { - Version string `json:"version"` + Version string GitRev string GitBranch string BuildDate string