Skip to content

feat: ctrl c ctrl v #1

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

Merged
merged 4 commits into from
Oct 28, 2024
Merged
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
26 changes: 26 additions & 0 deletions .github/workflows/ecr-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Docker ECR Push

on:
push:
branches: [main]
tags:
- v**
workflow_dispatch:


permissions:
packages: write
contents: read
id-token: write

# simplest example of using the rust-base action
jobs:
docker-ecr-push:
uses: init4tech/actions/.github/workflows/ecr-build-and-push.yml@main
with:
rust-binary-name: zenith-builder-example
environment: dev
secrets:
aws-ecr-repository: ${{ secrets.AWS_ECR_REPOSITORY }}
aws-eks-cluster: ${{ secrets.AWS_EKS_CLUSTER }}
aws-ecr-deployer-role-arn: ${{ secrets.AWS_ECR_DEPLOYER_ROLE_ARN }}
11 changes: 11 additions & 0 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Rust CI

on:
push:
branches: [main]
pull_request:

# simplest example of using the rust-base action
jobs:
rust-base:
uses: init4tech/actions/.github/workflows/rust-base.yml@main
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ Cargo.lock
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/

# Added by cargo

/target
48 changes: 48 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[package]
name = "zenith-builder-example"
version = "0.1.0"
description = "Zenith Builder Example"
Comment on lines +2 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this still be called the example builder? maybe it should just be the "default" builder :thonk:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think its fine b/c it is in essence still an example. won't be the default in the real world


edition = "2021"
rust-version = "1.81"
authors = ["init4"]
license = "Apache-2.0 OR MIT"
homepage = "https://github.com/init4tt/zenith"
repository = "https://github.com/init4tt/zenith"

[lib]
name = "builder"

[[bin]]
name = "zenith-builder-example"
path = "bin/builder.rs"

[dependencies]
zenith-types = { git = "https://github.com/init4tech/zenith-rs", branch = "main" }

alloy-primitives = { version = "=0.8.8", features = ["serde", "tiny-keccak"] }
alloy-sol-types = { version = "=0.8.8", features = ["json"] }
alloy-rlp = { version = "0.3.4" }

alloy = { version = "0.5.4", features = ["full", "json-rpc", "signer-aws"] }

aws-config = "1.1.7"
aws-sdk-kms = "1.15.0"

hex = { package = "const-hex", version = "1", default-features = false, features = [
"alloc",
] }
serde = { version = "1.0.197", features = ["derive"] }
tracing = "0.1.40"

axum = "0.7.5"
eyre = "0.6.12"
openssl = { version = "0.10", features = ["vendored"] }
reqwest = { version = "0.11.24", features = ["blocking", "json"] }
ruint = "1.12.1"
serde_json = "1.0"
thiserror = "1.0.58"
tokio = { version = "1.36.0", features = ["full", "macros", "rt-multi-thread"] }
tracing-subscriber = "0.3.18"
async-trait = "0.1.80"
oauth2 = "4.4.2"
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# syntax=docker/dockerfile:1.7-labs
### STAGE 0: Create base chef image for building
### cargo chef is used to speed up the build process by caching dependencies using docker
FROM --platform=$TARGETPLATFORM lukemathwalker/cargo-chef:latest-rust-latest as chef

RUN cargo install cargo-chef

WORKDIR /app

### Stage 1: cargo chef prepare
### Creates the recipe.json file which is a manifest of Cargo.toml files and
### the relevant Cargo.lock file
FROM chef as planner
COPY --exclude=target . .
RUN cargo chef prepare

### Stage 2: Build the project
### This stage builds the deps of the project (not the code) using cargo chef cook
### and then it copies the source code and builds the actual crates
### this takes advantage of docker layer caching to the max
FROM chef as builder
COPY --from=planner /app/recipe.json recipe.json
RUN apt-get update && apt-get -y upgrade && apt-get install -y gcc libclang-dev pkg-config libssl-dev
RUN rustup target add x86_64-unknown-linux-gnu
RUN rustup toolchain install stable-x86_64-unknown-linux-gnu

RUN cargo chef cook --release --target x86_64-unknown-linux-gnu --recipe-path recipe.json --bin zenith-builder-example
COPY --exclude=target . .

RUN cargo build --release --target x86_64-unknown-linux-gnu --bin zenith-builder-example

# Stage 3: Final image for running in the env
FROM --platform=$TARGETPLATFORM debian:bookworm-slim
RUN apt-get update && apt-get -y upgrade && apt-get install -y libssl-dev ca-certificates

COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/zenith-builder-example /usr/local/bin/zenith-builder-example

ENTRYPOINT [ "/usr/local/bin/zenith-builder-example" ]
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
# builder
# builder

Our sample signet builder implementation.

## Development

This crate contains an example block builder in the Signet ecosystem.

### Requirements

- Rust 1.81.0
- Cargo [Lambda](https://www.cargo-lambda.info/)
- AWS CLI and credentials

### Environment

The following environment variables are exposed to configure the Builder:

```bash
# Builder Configs
HOST_CHAIN_ID="17000" # Holesky Testnet
RU_CHAIN_ID="17001"
HOST_RPC_URL="http://host.url.here"
ZENITH_ADDRESS="ZENITH_ADDRESS_HERE"
QUINCEY_URL="http://signer.url.here"
BUILDER_PORT="8080"
BUILDER_KEY="YOUR_BUILDER_KEY_HERE"
INCOMING_TRANSACTIONS_BUFFER="10"
BLOCK_CONFIRMATION_BUFFER="10"
BUILDER_REWARDS_ADDRESS="BUILDER_REWARDS_ADDRESS_HERE"
ROLLUP_BLOCK_GAS_LIMIT="30000000"
# Transaction Pool Configs
TX_POOL_URL="http://pool.url.here/" # trailing slash is required
TX_POOL_POLL_INTERVAL="5" # seconds
TX_POOL_CACHE_DURATION="600" # seconds
```

## API

### SignRequest

Sign request example payload:

```json
{
"hostBlockNumber": "0x0",
"hostChainId": "0x1",
"ruChainId": "0x2",
"gasLimit": "0x5",
"ruRewardAddress": "0x0606060606060606060606060606060606060606",
"contents": "0x0707070707070707070707070707070707070707070707070707070707070707"
}
```
62 changes: 62 additions & 0 deletions bin/builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#![allow(dead_code)]

use builder::config::BuilderConfig;
use builder::service::serve_builder_with_span;
use builder::tasks::tx_poller::TxPoller;

use tokio::select;

#[tokio::main]
async fn main() -> eyre::Result<()> {
tracing_subscriber::fmt::try_init().unwrap();
let span = tracing::info_span!("zenith-builder");

let config = BuilderConfig::load_from_env()?;
let provider = config.connect_provider().await?;

tracing::debug!(
rpc_url = config.host_rpc_url.as_ref(),
"instantiated provider"
);

let sequencer_signer = config.connect_sequencer_signer().await?;
let zenith = config.connect_zenith(provider.clone());

let port = config.builder_port;

let tx_poller = TxPoller::new(&config);
let builder = builder::tasks::block::BlockBuilder::new(&config);

let submit = builder::tasks::submit::SubmitTask {
provider,
zenith,
client: reqwest::Client::new(),
sequencer_signer,
config,
};

let (submit_channel, submit_jh) = submit.spawn();
let (build_channel, build_jh) = builder.spawn(submit_channel);
let tx_poller_jh = tx_poller.spawn(build_channel.clone());

let server = serve_builder_with_span(build_channel, ([0, 0, 0, 0], port), span);

select! {
_ = submit_jh => {
tracing::info!("submit finished");
},
_ = build_jh => {
tracing::info!("build finished");
}
_ = server => {
tracing::info!("server finished");
}
_ = tx_poller_jh => {
tracing::info!("tx_poller finished");
}
}

tracing::info!("shutting down");

Ok(())
}
Loading