Skip to content

docs: update readme #103

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 7 commits into from
Jun 16, 2025
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
206 changes: 162 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,173 @@
# builder
# The Signet Block Builder

Our sample signet builder implementation.
The Builder simulates bundles and transactions against the latest chain state to create valid Signet rollup blocks and submits them to the configured host chain as an [EIP-4844 transaction](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4844.md).

## Development
Bundles are treated as Flashbots-style bundles, meaning that the Builder should respect transaction ordering, bundle atomicity, and the specified revertability.

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

### Requirements
## 🚀 System Design

The Builder orchestrates a series of asynchronous actors that work together to build blocks for every assigned slot.

1. **Env** - watches the latest host and rollup blocks to monitor gas rates and block updates.
2. **Cache** - polls bundle and transaction caches and adds them to the cache.
3. **Simulator** - simulates transactions and bundles against rollup state and block environment to build them into a cohesive block.
5. **Submit** - creates a blob transaction from the built block and sends it to Ethereum L1.
6. **Metrics** - records block and tx data over time.

```mermaid
%%{ init : { "theme" : "dark" } }%%
flowchart TD
%% ────────────── INITIALIZATION ──────────────
A0(["Start main"]) --> A1[Init tracing & logging]
A1 --> A2_BuilderConfig[Load BuilderConfig from env]

%% ────────────── CORE TASK SPAWNS ──────────────
subgraph Tasks_Spawned["Spawned Actors"]
EnvTaskActor["🔢 Env Task"] ==block_env==> CacheSystem
CacheSystem["🪏 Cache System"]
MetricsTaskActor["📏 Metrics Task"]
SubmitTaskActor["📡 Submit Task "]
SimulatorTaskActor["💾 Simulator Task"]
Quincey["🖊️ Quincey"]

SubmitTaskActor -.block hash.-> Quincey
Quincey -.block signature.-> SubmitTaskActor
end

%% ────────────── CONNECTIONS & DATA FLOW ──────────────
A2_BuilderConfig -.host_provider.-> MetricsTaskActor
A2_BuilderConfig -.host_provider.->SubmitTaskActor
A2_BuilderConfig -.ru_provider.-> SimulatorTaskActor
A2_BuilderConfig -.ru_provider.-> EnvTaskActor

- 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"
# trailing slash is required
TX_BROADCAST_URLS="http://tx.broadcast.url.here/,https://additional.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
A3["📥 Transactions &
📦 Bundles"] --> CacheSystem

EnvTaskActor ==block_env==> SimulatorTaskActor
CacheSystem ==sim_cache ==> SimulatorTaskActor
SubmitTaskActor ==tx receipt==> MetricsTaskActor
SimulatorTaskActor ==built block==> SubmitTaskActor

SubmitTaskActor ==>|"signet block (blob tx)"| C1["⛓️ Ethereum L1"]
```

## API
The block building loop waits until a new block has been received, and then kicks off the next attempt.

When the Builder receives a new block, it takes a reference to the transaction cache, calculates a simulation deadline for the current slot with a buffer of 1.5 seconds, and begins constructing a block for the current slot.

Transactions enter through the cache, and then they're sent to the simulator, where they're run against the latest chain state and block environment. If they're successfully applied, they're added to the block. If a transaction fails to be applied, it is simply ignored.

When the deadline is reached, the simulator is stopped, and all open simulation threads and cancelled. The block is then bundled with the block environment and the previous host header that it was simulated against, and passes all three along to the submit task.

### SignRequest
If no transactions in the cache are valid and the resulting block is empty, the submit task will ignore it.

Sign request example payload:
Finally, if it's non-empty, the submit task attempts to get a signature for the block, and if it fails due to a 403 error, it will skip the current slot and begin waiting for the next block.

```json
{
"hostBlockNumber": "0x0",
"hostChainId": "0x1",
"ruChainId": "0x2",
"gasLimit": "0x5",
"ruRewardAddress": "0x0606060606060606060606060606060606060606",
"contents": "0x0707070707070707070707070707070707070707070707070707070707070707"
}
---

## ⚙️ Configuration

The Builder is configured via environment variables. The following values are supported for configuration.

| Key | Required | Description |
| ------------------------- | -------- | ------------------------------------------------------------------- |
| `HOST_CHAIN_ID` | Yes | Host-chain ID (e.g. `3151908`) |
| `RU_CHAIN_ID` | Yes | Rollup-chain ID (e.g. `14174`) |
| `TX_POOL_URL` | Yes | Transaction pool URL (must end with `/`) |
| `HOST_RPC_URL` | Yes | RPC endpoint for the host chain |
| `RU_RPC_URL` | Yes | RPC endpoint for the rollup chain |
| `TX_BROADCAST_URLS` | No | Additional endpoints for blob txs (comma-separated, slash required) |
| `ZENITH_ADDRESS` | Yes | Zenith contract address |
| `BUILDER_HELPER_ADDRESS` | Yes | Builder helper contract address |
| `QUINCEY_URL` | Yes | Remote sequencer signing endpoint |
| `BUILDER_PORT` | Yes | HTTP port for the Builder (default: `8080`) |
| `SEQUENCER_KEY` | Yes | AWS KMS key ID _or_ local private key for sequencer signing |
| `BUILDER_KEY` | Yes | AWS KMS key ID _or_ local private key for builder signing |
| `BUILDER_REWARDS_ADDRESS` | Yes | Address receiving builder rewards |
| `ROLLUP_BLOCK_GAS_LIMIT` | No | Override for block gas limit |
| `CONCURRENCY_LIMIT` | Yes | Max concurrent tasks the simulator uses |
| `SLOT_OFFSET` | Yes | Slot timing offset in seconds |
| `SLOT_DURATION` | Yes | Slot duration in seconds |
| `START_TIMESTAMP` | Yes | UNIX timestamp for slot 0 |

---

## 💾 EVM Behavior

### 🗿 Inherited Header Values

`PREVRANDAO` is set to a random byte string for each block.

```rust
// `src/tasks/env.rs`
prevrandao: Some(B256::random()),
```

`TIMESTAMP` - Block timestamps are set to the same value as the current Ethereum block.

Blob gas values `excess_blob_gas` and `blob_gasprice` are also set to 0 for all Signet blocks.

### 🔢 Disabled Opcodes

`BLOBHASH` - EIP-4844 is not supported on Signet.
`BLOBBASEFEE` - EIP4844 is not supported.

## ⛽ Transaction Submission

When a completed, non-empty Signet block is received by the Submit task, it prepares the block data into a blob transaction and submits it to the network.

If it fails, it will retry up to 3 times with a 12.5% bump on each retry.

The previous header's basefee is tracked through the build loop and used for gas estimation purposes in the Submit Task.

---

## 📤 Transaction Sender

A binary (`bin/submit-transaction.rs`) for continously sending very small transactions for testing block construction.

The following values are available for configuring the transaction sender:

| Key | Required | Description |
| ------------------- | -------- | ------------------------------------------------ |
| `RPC_URL` | Yes | RPC endpoint used for sending the transaction |
| `RECIPIENT_ADDRESS` | Yes | Address to which the transaction is sent |
| `SLEEP_TIME` | No | Optional delay (in seconds) between transactions |
| `SIGNER_CHAIN_ID` | Yes | Chain ID used for signing |
| `SIGNER_KEY` | Yes | Signing key used to sign the transaction |

The transaction submitter is located at `bin/submit_transaction.rs`.

Run the transaction submitter with `cargo run --bin transaction-submitter`

---

## 🛠️ Development

### Requirements

- **Rust** ≥ 1.85
- **AWS CLI**
- A private key or AWS KMS key for signing transactions

---

## ✅ Testing

1. Build the Docker image:
```bash
docker build -t builder:latest .
```
2. Push to your container registry:
```bash
docker push <registry>/builder:latest
```
3. Update your deployment manifests with the new image.
4. Verify expected behavior in your target network.
- This should typically include sending a test transaction and verifying it is simulated and built into a block.

## 🪪 License

This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).
53 changes: 27 additions & 26 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,47 +55,65 @@ pub type HostProvider = FillProvider<
/// chain.
#[derive(Debug, Clone, FromEnv)]
pub struct BuilderConfig {
/// The chain ID of the host chain
/// The chain ID of the host chain.
#[from_env(var = "HOST_CHAIN_ID", desc = "The chain ID of the host chain")]
pub host_chain_id: u64,
/// The chain ID of the rollup chain

/// The chain ID of the rollup chain.
#[from_env(var = "RU_CHAIN_ID", desc = "The chain ID of the rollup chain")]
pub ru_chain_id: u64,

/// URL for Host RPC node.
#[from_env(var = "HOST_RPC_URL", desc = "URL for Host RPC node", infallible)]
pub host_rpc_url: Cow<'static, str>,

/// URL for the Rollup RPC node.
#[from_env(var = "ROLLUP_RPC_URL", desc = "URL for Rollup RPC node", infallible)]
pub ru_rpc_url: Cow<'static, str>,
/// Additional RPC URLs to which to broadcast transactions.
/// NOTE: should not include the host_rpc_url value

/// URL of the tx pool to poll for incoming transactions.
#[from_env(
var = "TX_POOL_URL",
desc = "URL of the tx pool to poll for incoming transactions",
infallible
)]
pub tx_pool_url: Cow<'static, str>,

/// Additional RPC URLs to which the builder should broadcast transactions.
/// * Should not include the `HOST_RPC_URL` value, as that is already sent to by default.
/// * Setting this can incur `already known` errors.
#[from_env(
var = "TX_BROADCAST_URLS",
desc = "Additional RPC URLs to which the builder broadcasts transactions",
infallible,
optional
)]
pub tx_broadcast_urls: Vec<Cow<'static, str>>,
/// address of the Zenith contract on Host.

/// Address of the Zenith contract on Host.
#[from_env(var = "ZENITH_ADDRESS", desc = "address of the Zenith contract on Host")]
pub zenith_address: Address,
/// address of the Builder Helper contract on Host.

/// Address of the Builder Helper contract on Host.
#[from_env(
var = "BUILDER_HELPER_ADDRESS",
desc = "address of the Builder Helper contract on Host"
)]
pub builder_helper_address: Address,

/// URL for remote Quincey Sequencer server to sign blocks.
/// Disregarded if a sequencer_signer is configured.
/// NB: Disregarded if a sequencer_signer is configured.
#[from_env(
var = "QUINCEY_URL",
desc = "URL for remote Quincey Sequencer server to sign blocks",
infallible
)]
pub quincey_url: Cow<'static, str>,

/// Port for the Builder server.
#[from_env(var = "BUILDER_PORT", desc = "Port for the Builder server")]
pub builder_port: u16,

/// Key to access Sequencer Wallet - AWS Key ID _OR_ local private key.
/// Set IFF using local Sequencer signing instead of remote Quincey signing.
#[from_env(
Expand All @@ -105,43 +123,26 @@ pub struct BuilderConfig {
optional
)]
pub sequencer_key: Option<String>,

/// Key to access Builder transaction submission wallet - AWS Key ID _OR_ local private key.
#[from_env(
var = "BUILDER_KEY",
desc = "Key to access Builder transaction submission wallet - AWS Key ID _OR_ local private key",
infallible
)]
pub builder_key: String,
/// Buffer in seconds in which the `submitBlock` transaction must confirm on the Host chain.
#[from_env(
var = "BLOCK_CONFIRMATION_BUFFER",
desc = "Buffer in seconds in which the `submitBlock` transaction must confirm on the Host chain"
)]
pub block_confirmation_buffer: u64,

/// Address on Rollup to which Builder will receive user transaction fees.
#[from_env(
var = "BUILDER_REWARDS_ADDRESS",
desc = "Address on Rollup to which Builder will receive user transaction fees"
)]
pub builder_rewards_address: Address,

/// Gas limit for RU block.
/// NOTE: a "smart" builder would determine this programmatically by simulating the block.
#[from_env(var = "ROLLUP_BLOCK_GAS_LIMIT", desc = "Gas limit for RU block")]
pub rollup_block_gas_limit: u64,
/// URL of the tx pool to poll for incoming transactions.
#[from_env(
var = "TX_POOL_URL",
desc = "URL of the tx pool to poll for incoming transactions",
infallible
)]
pub tx_pool_url: Cow<'static, str>,
/// Duration in seconds transactions can live in the tx-pool cache.
#[from_env(
var = "TX_POOL_CACHE_DURATION",
desc = "Duration in seconds transactions can live in the tx-pool cache"
)]
pub tx_pool_cache_duration: u64,

/// Oauth2 configuration for the builder to connect to init4 services.
pub oauth: OAuthConfig,
Expand Down
2 changes: 0 additions & 2 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ pub fn setup_test_config() -> Result<BuilderConfig> {
builder_port: 8080,
sequencer_key: None,
builder_key: "0000000000000000000000000000000000000000000000000000000000000000".into(),
block_confirmation_buffer: 1,
builder_rewards_address: Address::default(),
rollup_block_gas_limit: 3_000_000_000,
tx_pool_url: "http://localhost:9000/".into(),
tx_pool_cache_duration: 5,
oauth: OAuthConfig {
oauth_client_id: "some_client_id".into(),
oauth_client_secret: "some_client_secret".into(),
Expand Down