Skip to content

Commit b2ca58b

Browse files
authored
Merge pull request #1 from init4tech/swanny/new-day-new-repo
feat: ctrl c ctrl v
2 parents eb09673 + 3a65f15 commit b2ca58b

17 files changed

+1502
-2
lines changed

.github/workflows/ecr-cd.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Docker ECR Push
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags:
7+
- v**
8+
workflow_dispatch:
9+
10+
11+
permissions:
12+
packages: write
13+
contents: read
14+
id-token: write
15+
16+
# simplest example of using the rust-base action
17+
jobs:
18+
docker-ecr-push:
19+
uses: init4tech/actions/.github/workflows/ecr-build-and-push.yml@main
20+
with:
21+
rust-binary-name: zenith-builder-example
22+
environment: dev
23+
secrets:
24+
aws-ecr-repository: ${{ secrets.AWS_ECR_REPOSITORY }}
25+
aws-eks-cluster: ${{ secrets.AWS_EKS_CLUSTER }}
26+
aws-ecr-deployer-role-arn: ${{ secrets.AWS_ECR_DEPLOYER_ROLE_ARN }}

.github/workflows/rust-ci.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
# simplest example of using the rust-base action
9+
jobs:
10+
rust-base:
11+
uses: init4tech/actions/.github/workflows/rust-base.yml@main

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ Cargo.lock
1818
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
1919
# and can be added to the global gitignore or merged into this file. For a more nuclear
2020
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
21-
#.idea/
21+
#.idea/
22+
23+
# Added by cargo
24+
25+
/target

Cargo.toml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[package]
2+
name = "zenith-builder-example"
3+
version = "0.1.0"
4+
description = "Zenith Builder Example"
5+
6+
edition = "2021"
7+
rust-version = "1.81"
8+
authors = ["init4"]
9+
license = "Apache-2.0 OR MIT"
10+
homepage = "https://github.com/init4tt/zenith"
11+
repository = "https://github.com/init4tt/zenith"
12+
13+
[lib]
14+
name = "builder"
15+
16+
[[bin]]
17+
name = "zenith-builder-example"
18+
path = "bin/builder.rs"
19+
20+
[dependencies]
21+
zenith-types = { git = "https://github.com/init4tech/zenith-rs", branch = "main" }
22+
23+
alloy-primitives = { version = "=0.8.8", features = ["serde", "tiny-keccak"] }
24+
alloy-sol-types = { version = "=0.8.8", features = ["json"] }
25+
alloy-rlp = { version = "0.3.4" }
26+
27+
alloy = { version = "0.5.4", features = ["full", "json-rpc", "signer-aws"] }
28+
29+
aws-config = "1.1.7"
30+
aws-sdk-kms = "1.15.0"
31+
32+
hex = { package = "const-hex", version = "1", default-features = false, features = [
33+
"alloc",
34+
] }
35+
serde = { version = "1.0.197", features = ["derive"] }
36+
tracing = "0.1.40"
37+
38+
axum = "0.7.5"
39+
eyre = "0.6.12"
40+
openssl = { version = "0.10", features = ["vendored"] }
41+
reqwest = { version = "0.11.24", features = ["blocking", "json"] }
42+
ruint = "1.12.1"
43+
serde_json = "1.0"
44+
thiserror = "1.0.58"
45+
tokio = { version = "1.36.0", features = ["full", "macros", "rt-multi-thread"] }
46+
tracing-subscriber = "0.3.18"
47+
async-trait = "0.1.80"
48+
oauth2 = "4.4.2"

Dockerfile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# syntax=docker/dockerfile:1.7-labs
2+
### STAGE 0: Create base chef image for building
3+
### cargo chef is used to speed up the build process by caching dependencies using docker
4+
FROM --platform=$TARGETPLATFORM lukemathwalker/cargo-chef:latest-rust-latest as chef
5+
6+
RUN cargo install cargo-chef
7+
8+
WORKDIR /app
9+
10+
### Stage 1: cargo chef prepare
11+
### Creates the recipe.json file which is a manifest of Cargo.toml files and
12+
### the relevant Cargo.lock file
13+
FROM chef as planner
14+
COPY --exclude=target . .
15+
RUN cargo chef prepare
16+
17+
### Stage 2: Build the project
18+
### This stage builds the deps of the project (not the code) using cargo chef cook
19+
### and then it copies the source code and builds the actual crates
20+
### this takes advantage of docker layer caching to the max
21+
FROM chef as builder
22+
COPY --from=planner /app/recipe.json recipe.json
23+
RUN apt-get update && apt-get -y upgrade && apt-get install -y gcc libclang-dev pkg-config libssl-dev
24+
RUN rustup target add x86_64-unknown-linux-gnu
25+
RUN rustup toolchain install stable-x86_64-unknown-linux-gnu
26+
27+
RUN cargo chef cook --release --target x86_64-unknown-linux-gnu --recipe-path recipe.json --bin zenith-builder-example
28+
COPY --exclude=target . .
29+
30+
RUN cargo build --release --target x86_64-unknown-linux-gnu --bin zenith-builder-example
31+
32+
# Stage 3: Final image for running in the env
33+
FROM --platform=$TARGETPLATFORM debian:bookworm-slim
34+
RUN apt-get update && apt-get -y upgrade && apt-get install -y libssl-dev ca-certificates
35+
36+
COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/zenith-builder-example /usr/local/bin/zenith-builder-example
37+
38+
ENTRYPOINT [ "/usr/local/bin/zenith-builder-example" ]

README.md

+53-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,53 @@
1-
# builder
1+
# builder
2+
3+
Our sample signet builder implementation.
4+
5+
## Development
6+
7+
This crate contains an example block builder in the Signet ecosystem.
8+
9+
### Requirements
10+
11+
- Rust 1.81.0
12+
- Cargo [Lambda](https://www.cargo-lambda.info/)
13+
- AWS CLI and credentials
14+
15+
### Environment
16+
17+
The following environment variables are exposed to configure the Builder:
18+
19+
```bash
20+
# Builder Configs
21+
HOST_CHAIN_ID="17000" # Holesky Testnet
22+
RU_CHAIN_ID="17001"
23+
HOST_RPC_URL="http://host.url.here"
24+
ZENITH_ADDRESS="ZENITH_ADDRESS_HERE"
25+
QUINCEY_URL="http://signer.url.here"
26+
BUILDER_PORT="8080"
27+
BUILDER_KEY="YOUR_BUILDER_KEY_HERE"
28+
INCOMING_TRANSACTIONS_BUFFER="10"
29+
BLOCK_CONFIRMATION_BUFFER="10"
30+
BUILDER_REWARDS_ADDRESS="BUILDER_REWARDS_ADDRESS_HERE"
31+
ROLLUP_BLOCK_GAS_LIMIT="30000000"
32+
# Transaction Pool Configs
33+
TX_POOL_URL="http://pool.url.here/" # trailing slash is required
34+
TX_POOL_POLL_INTERVAL="5" # seconds
35+
TX_POOL_CACHE_DURATION="600" # seconds
36+
```
37+
38+
## API
39+
40+
### SignRequest
41+
42+
Sign request example payload:
43+
44+
```json
45+
{
46+
"hostBlockNumber": "0x0",
47+
"hostChainId": "0x1",
48+
"ruChainId": "0x2",
49+
"gasLimit": "0x5",
50+
"ruRewardAddress": "0x0606060606060606060606060606060606060606",
51+
"contents": "0x0707070707070707070707070707070707070707070707070707070707070707"
52+
}
53+
```

bin/builder.rs

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#![allow(dead_code)]
2+
3+
use builder::config::BuilderConfig;
4+
use builder::service::serve_builder_with_span;
5+
use builder::tasks::tx_poller::TxPoller;
6+
7+
use tokio::select;
8+
9+
#[tokio::main]
10+
async fn main() -> eyre::Result<()> {
11+
tracing_subscriber::fmt::try_init().unwrap();
12+
let span = tracing::info_span!("zenith-builder");
13+
14+
let config = BuilderConfig::load_from_env()?;
15+
let provider = config.connect_provider().await?;
16+
17+
tracing::debug!(
18+
rpc_url = config.host_rpc_url.as_ref(),
19+
"instantiated provider"
20+
);
21+
22+
let sequencer_signer = config.connect_sequencer_signer().await?;
23+
let zenith = config.connect_zenith(provider.clone());
24+
25+
let port = config.builder_port;
26+
27+
let tx_poller = TxPoller::new(&config);
28+
let builder = builder::tasks::block::BlockBuilder::new(&config);
29+
30+
let submit = builder::tasks::submit::SubmitTask {
31+
provider,
32+
zenith,
33+
client: reqwest::Client::new(),
34+
sequencer_signer,
35+
config,
36+
};
37+
38+
let (submit_channel, submit_jh) = submit.spawn();
39+
let (build_channel, build_jh) = builder.spawn(submit_channel);
40+
let tx_poller_jh = tx_poller.spawn(build_channel.clone());
41+
42+
let server = serve_builder_with_span(build_channel, ([0, 0, 0, 0], port), span);
43+
44+
select! {
45+
_ = submit_jh => {
46+
tracing::info!("submit finished");
47+
},
48+
_ = build_jh => {
49+
tracing::info!("build finished");
50+
}
51+
_ = server => {
52+
tracing::info!("server finished");
53+
}
54+
_ = tx_poller_jh => {
55+
tracing::info!("tx_poller finished");
56+
}
57+
}
58+
59+
tracing::info!("shutting down");
60+
61+
Ok(())
62+
}

0 commit comments

Comments
 (0)