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

WIP: Polygon PoS Connector #135

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by Cargo
**/target

# Unneeded artifacts
**/.DS_Store

# The cache for docker container dependency
.cargo
.github

# Environment
.git
Lohann marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ members = [
"chains/polkadot/config",
"chains/polkadot/server",
"chains/polkadot/tx",
"chains/polygon-pos/config",
"chains/polygon-pos/server",
"chains/polygon-pos/tx",
"rosetta-cli",
"rosetta-client",
"rosetta-core",
Expand Down
53 changes: 31 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,13 @@ This repo contains the following modules:

## Getting started

<!--This section needs to be refined -->

To get started with the Rosetta SDK, you must ensure you have [installed the latest version of Docker](https://www.docker.com/get-started/).\
Run the following command to download chain-connectors:

```
$ git clone https://github.com/Analog-Labs/chain-connectors.git
```

You can also download the latest pre-built Docker image release from GitHub by running the following command:

```
curl -sSfL https://raw.githubusercontent.com/Analog-Labs/chain-connectors/master/install.sh | sh -s
```

After cloning this repo, simply run the following command:

```
make build-local
```
To get started with the Rosetta SDK, ensure you have the latest version of [Rust](https://rustup.rs/) and [Docker](https://www.docker.com/get-started/) installed.

### Connector deployment

<!-- This section needs to describe how operators will deploy their connectors.-->
<!--I am assuming here is where we initiate the rosetta-server and rosetta-client.-->

### Install CLI tools

Install the CLI tools by running the commands below:

```
Expand Down Expand Up @@ -138,6 +117,36 @@ You can override the default URL in rosetta-cli and rosetta-wallet with the “

Create a new tag, push to master and use it to create a new github release.

## Building Docker Images

### 1. Install dependencies

The docker images requires musl for cross-compilation, so you need to install the following dependencies:

#### 1.1 MacOS

if you're on macos, install [musl-cross](https://github.com/FiloSottile/homebrew-musl-cross) for enable musl-target cross-compilation:

```shell
brew install filosottile/musl-cross/musl-cross --with-aarch64
```

#### 1.2 Debian/Ubuntu

if you're on debian/ubuntu, install [musl-tools](https://packages.debian.org/sid/musl-tools) for enable musl-target cross-compilation:

```shell
apt-get install musl-tools
```

#### 2. Build Docker Images

After install the dependencies, simply run the following command:

```shell
./build_connectors.sh
```

## Contributing

You can contribute to this repo in a number of ways, including:
Expand Down
121 changes: 101 additions & 20 deletions build_connectors.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,101 @@
#!/bin/sh
cargo build -p rosetta-server-bitcoin --target x86_64-unknown-linux-musl --release
mkdir -p target/release/bitcoin/bin
cp target/x86_64-unknown-linux-musl/release/rosetta-server-bitcoin target/release/bitcoin/bin
docker build target/release/bitcoin -f chains/bitcoin/Dockerfile -t analoglabs/connector-bitcoin

cargo build -p rosetta-server-ethereum --target x86_64-unknown-linux-musl --release
mkdir -p target/release/ethereum/bin
cp target/x86_64-unknown-linux-musl/release/rosetta-server-ethereum target/release/ethereum/bin
docker build target/release/ethereum -f chains/ethereum/Dockerfile -t analoglabs/connector-ethereum

cargo build -p rosetta-server-polkadot --target x86_64-unknown-linux-musl --release
mkdir -p target/release/polkadot/bin
cp target/x86_64-unknown-linux-musl/release/rosetta-server-polkadot target/release/polkadot/bin
docker build target/release/polkadot -f chains/polkadot/Dockerfile -t analoglabs/connector-polkadot

cargo build -p rosetta-server-astar --target x86_64-unknown-linux-musl --release
mkdir -p target/release/astar/bin
cp target/x86_64-unknown-linux-musl/release/rosetta-server-astar target/release/astar/bin
docker build target/release/astar -f chains/astar/Dockerfile -t analoglabs/connector-astar
#!/usr/bin/env bash
set -e

# Check for 'git' and abort if it is not available.
git --version > /dev/null 2>&1 || { echo >&2 "ERROR - requires 'git' to get commit hash and tag."; exit 1; }

REGISTRY_PATH="${REGISTRY_PATH:-docker.io/analoglabs}"
VCS_REF="$(git rev-parse HEAD)"
IMAGE_TAG="$(git describe --tags | sed 's/^v//')"

# Check for 'uname' and abort if it is not available.
uname -v > /dev/null 2>&1 || { echo >&2 "ERROR - requires 'uname' to identify the platform."; exit 1; }

# Check for 'docker' and abort if it is not running.
docker info > /dev/null 2>&1 || { echo >&2 "ERROR - requires 'docker', please start docker and try again."; exit 1; }

# Check for 'rustup' and abort if it is not available.
rustup -V > /dev/null 2>&1 || { echo >&2 "ERROR - requires 'rustup' for compile the binaries"; exit 1; }

# Detect host architecture
case "$(uname -m)" in
x86_64)
rustTarget='x86_64-unknown-linux-musl'
muslLinker='x86_64-linux-musl-gcc'
;;
arm64|aarch64)
rustTarget='aarch64-unknown-linux-musl'
muslLinker='aarch64-linux-musl-gcc'
;;
*)
echo >&2 "ERROR - unsupported architecture: $(uname -m)"
exit 1
;;
esac

# Check if the musl linker is installed
"$muslLinker" --version > /dev/null 2>&1 || { echo >&2 "ERROR - requires '$muslLinker' linker for compile"; exit 1; }

# Check if the rust target is installed
if ! rustup target list | grep -q "$rustTarget"; then
echo "Installing the musl target with rustup '$rustTarget'"
rustup target add "$rustTarget"
fi

# Build all Connectors
cargo build \
-p rosetta-server-bitcoin \
-p rosetta-server-polkadot \
-p rosetta-server-ethereum \
-p rosetta-server-astar \
--target "$rustTarget" \
--config "target.$rustTarget.linker='$muslLinker'" \
--config "env.CC_$rustTarget='$muslLinker'" \
--release

# Move binaries
mkdir -p target/release/{bitcoin,ethereum,polkadot,astar}/bin
cp "target/$rustTarget/release/rosetta-server-bitcoin" target/release/bitcoin/bin
cp "target/$rustTarget/release/rosetta-server-ethereum" target/release/ethereum/bin
cp "target/$rustTarget/release/rosetta-server-polkadot" target/release/polkadot/bin
cp "target/$rustTarget/release/rosetta-server-astar" target/release/astar/bin

# Build Bitcoin Connector
docker build target/release/bitcoin \
--build-arg "REGISTRY_PATH=$REGISTRY_PATH" \
--build-arg "VCS_REF=$VCS_REF" \
--build-arg "BUILD_DATE=$(date +%Y%m%d)" \
--build-arg "IMAGE_VERSION=$IMAGE_TAG" \
-f chains/bitcoin/Dockerfile \
-t "analoglabs/connector-bitcoin:$IMAGE_TAG" \
-t analoglabs/connector-bitcoin:latest

# Build Ethereum Connector
docker build target/release/ethereum \
--build-arg "REGISTRY_PATH=$REGISTRY_PATH" \
--build-arg "VCS_REF=$VCS_REF" \
--build-arg "BUILD_DATE=$(date +%Y%m%d)" \
--build-arg "IMAGE_VERSION=$IMAGE_TAG" \
-f chains/ethereum/Dockerfile \
-t "analoglabs/connector-ethereum:$IMAGE_TAG" \
-t analoglabs/connector-ethereum

# Build Polkadot Connector
docker build target/release/polkadot \
--build-arg "REGISTRY_PATH=$REGISTRY_PATH" \
--build-arg "VCS_REF=$VCS_REF" \
--build-arg "BUILD_DATE=$(date +%Y%m%d)" \
--build-arg "IMAGE_VERSION=$IMAGE_TAG" \
-f chains/polkadot/Dockerfile \
-t "analoglabs/connector-polkadot:$IMAGE_TAG" \
-t analoglabs/connector-polkadot

# Build Astar Connector
docker build target/release/astar \
--build-arg "REGISTRY_PATH=$REGISTRY_PATH" \
--build-arg "VCS_REF=$VCS_REF" \
--build-arg "BUILD_DATE=$(date +%Y%m%d)" \
--build-arg "IMAGE_VERSION=$IMAGE_TAG" \
-f chains/astar/Dockerfile \
-t "analoglabs/connector-astar:$IMAGE_TAG" \
-t analoglabs/connector-astar
12 changes: 12 additions & 0 deletions chains/astar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
FROM scratch

# metadata
LABEL summary="Analog’s connectors for astar parachain" \
name="${REGISTRY_PATH}/connector-astar" \
version="${IMAGE_VERSION}" \
description="Astar chain connector" \
one.analog.image.vendor="Analog One Foundation" \
one.analog.image.source="https://github.com/Analog-Labs/chain-connectors/blob/${VCS_REF}/\
chains/astar/Dockerfile" \
one.analog.image.revision="${VCS_REF}" \
one.analog.image.created="${BUILD_DATE}"

COPY bin/rosetta-server-astar rosetta-server-astar
ENTRYPOINT ["/rosetta-server-astar"]
12 changes: 12 additions & 0 deletions chains/bitcoin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
FROM scratch

# metadata
LABEL summary="Analog’s connectors for bitcoin network" \
name="${REGISTRY_PATH}/connector-bitcoin" \
version="${IMAGE_VERSION}" \
description="Bitcoin chain connector" \
one.analog.image.vendor="Analog One Foundation" \
one.analog.image.source="https://github.com/Analog-Labs/chain-connectors/blob/${VCS_REF}/\
chains/bitcoin/Dockerfile" \
one.analog.image.revision="${VCS_REF}" \
one.analog.image.created="${BUILD_DATE}"

COPY bin/rosetta-server-bitcoin rosetta-server-bitcoin
ENTRYPOINT ["/rosetta-server-bitcoin"]
12 changes: 12 additions & 0 deletions chains/ethereum/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
FROM scratch

# metadata
LABEL summary="Analog’s connectors for ethereum network" \
name="${REGISTRY_PATH}/connector-ethereum" \
version="${IMAGE_VERSION}" \
description="Ethereum chain connector" \
one.analog.image.vendor="Analog One Foundation" \
one.analog.image.source="https://github.com/Analog-Labs/chain-connectors/blob/${VCS_REF}/\
chains/ethereum/Dockerfile" \
one.analog.image.revision="${VCS_REF}" \
one.analog.image.created="${BUILD_DATE}"

COPY bin/rosetta-server-ethereum rosetta-server-ethereum
ENTRYPOINT ["/rosetta-server-ethereum"]
12 changes: 12 additions & 0 deletions chains/polkadot/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
FROM scratch

# metadata
LABEL summary="Analog’s connectors for polkadot network" \
name="${REGISTRY_PATH}/connector-polkadot" \
version="${IMAGE_VERSION}" \
description="Polkadot chain connector" \
one.analog.image.vendor="Analog One Foundation" \
one.analog.image.source="https://github.com/Analog-Labs/chain-connectors/blob/${VCS_REF}/\
chains/polkadot/Dockerfile" \
one.analog.image.revision="${VCS_REF}" \
one.analog.image.created="${BUILD_DATE}"

COPY bin/rosetta-server-polkadot rosetta-server-polkadot
ENTRYPOINT ["/rosetta-server-polkadot"]
15 changes: 15 additions & 0 deletions chains/polygon-pos/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM scratch

# metadata
LABEL summary="Analog’s connectors for polygon network" \
name="${REGISTRY_PATH}/connector-polygon" \
version="${IMAGE_VERSION}" \
description="Polygon PoS chain connector" \
one.analog.image.vendor="Analog One Foundation" \
one.analog.image.source="https://github.com/Analog-Labs/chain-connectors/blob/${VCS_REF}/\
chains/polygon-pos/Dockerfile" \
one.analog.image.revision="${VCS_REF}" \
one.analog.image.created="${BUILD_DATE}"

COPY bin/rosetta-server-polygon-pos rosetta-server-polygon-pos
ENTRYPOINT ["/rosetta-server-polygon-pos"]
12 changes: 12 additions & 0 deletions chains/polygon-pos/config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "rosetta-config-polygon-pos"
version = "0.4.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/analog-labs/chain-connectors"
description = "Polygon configuration."

[dependencies]
anyhow = "1.0.69"
rosetta-core = { version = "0.4.0", path = "../../../rosetta-core" }
serde = { version = "1.0.153", features = ["derive"] }
54 changes: 54 additions & 0 deletions chains/polygon-pos/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use anyhow::Result;
use rosetta_core::crypto::address::AddressFormat;
use rosetta_core::crypto::Algorithm;
use rosetta_core::BlockchainConfig;
use serde::{Deserialize, Serialize};
use std::sync::Arc;

pub fn config(network: &str) -> Result<BlockchainConfig> {
anyhow::ensure!(network == "dev");
Ok(BlockchainConfig {
blockchain: "polygon-pos",
network: "dev",
algorithm: Algorithm::EcdsaRecoverableSecp256k1,
address_format: AddressFormat::Eip55,
coin: 1, // TODO: What this coin field means? is it the BIP44 id?
Lohann marked this conversation as resolved.
Show resolved Hide resolved
bip44: true,
utxo: false,
currency_unit: "wei",
currency_symbol: "MATIC",
currency_decimals: 18,
node_port: 8545,
node_image: "ethereum/client-go:v1.10.26", // TODO: use polygon image
node_command: Arc::new(|_network, port| {
vec![
"--dev".into(),
"--ipcdisable".into(),
"--http".into(),
"--http.addr=0.0.0.0".into(),
format!("--http.port={port}"),
"--http.vhosts=*".into(),
"--http.api=eth,debug,admin,txpool,web3".into(),
]
}),
node_additional_ports: &[],
connector_port: 8081,
testnet: network == "dev",
})
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PolygonMetadataParams {
pub destination: Vec<u8>,
pub amount: [u64; 4],
pub data: Vec<u8>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct PolygonMetadata {
pub chain_id: u64,
pub nonce: u64,
pub max_priority_fee_per_gas: [u64; 4],
pub max_fee_per_gas: [u64; 4],
pub gas_limit: [u64; 4],
}
27 changes: 27 additions & 0 deletions chains/polygon-pos/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "rosetta-server-polygon-pos"
version = "0.4.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/analog-labs/chain-connectors"
description = "Polygon rosetta server."

[dependencies]
anyhow = "1.0.69"
async-std = { version = "1.12.0", features = ["tokio1"] }
async-trait = "0.1.66"
ethabi = "18.0.0"
ethers = "2.0.2"
hex = "0.4.3"
rosetta-config-polygon-pos = { version = "0.4.0", path = "../config" }
rosetta-server = { version = "0.4.0", path = "../../../rosetta-server" }
serde = "1.0.153"
serde_json = "1.0.94"
tokio = { version = "1.26.0", features = ["rt-multi-thread", "macros"] }

[dev-dependencies]
ethers-solc = "2.0.1"
rosetta-client = { version = "0.4.0", path = "../../../rosetta-client" }
rosetta-docker = { version = "0.4.0", path = "../../../rosetta-docker" }
rosetta-server = { version = "0.4.0", path = "../../../rosetta-server", features = ["tests"] }
sha3 = "0.10.6"
Loading