Skip to content

Commit

Permalink
feat: add tools
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Dec 18, 2024
1 parent 2bae855 commit 046b264
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test-e2e-multi_pp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 .
Expand Down
8 changes: 4 additions & 4 deletions crates/cdk/versions.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 9 additions & 3 deletions test/bats/pp-multi/bridge-l2_to_l2-e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions test/helpers/lxly-bridge-test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
112 changes: 112 additions & 0 deletions tools/aggsender_find_imported_bridge/aggsender_find_imported_bridge.go
Original file line number Diff line number Diff line change
@@ -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)

Check failure on line 30 in tools/aggsender_find_imported_bridge/aggsender_find_imported_bridge.go

View workflow job for this annotation

GitHub Actions / lint

Magic number: 10, in <argument> detected (mnd)
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
}

}

Check failure on line 61 in tools/aggsender_find_imported_bridge/aggsender_find_imported_bridge.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
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(&currentHeight)
if err != nil {
log.Errorf("Error: %v", err)
os.Exit(errLevelComms)
}
currentHeight--
}

}

Check failure on line 112 in tools/aggsender_find_imported_bridge/aggsender_find_imported_bridge.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func PrintVersion(w io.Writer) {
}

type FullVersion struct {
Version string `json:"version"`
Version string
GitRev string
GitBranch string
BuildDate string
Expand Down

0 comments on commit 046b264

Please sign in to comment.