diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..8ceea3d --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,133 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement writing an +email to leo@flashbots.net or contacting elopio#8526 in +[Discord](https://discord.com/invite/7hvTycdNcK). +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations \ No newline at end of file diff --git a/README.md b/README.md index 58b40fd..2f09e31 100644 --- a/README.md +++ b/README.md @@ -1,87 +1,110 @@ -# rblib — Rust SDK for Ethereum Block Builders - -> [!WARNING] -> This library is early alpha software under active and rapid development. Breaking changes are expected, APIs may shift, and stability is not guaranteed. No official support is provided at this stage; however, early adopters are encouraged to open issues for bugs, feedback, or feature requests. Your input will help shape the roadmap. +# rblib — A Modular Rust SDK for Ethereum Block Building [](https://github.com/flashbots/rblib/actions/workflows/sanity.yaml) +> [\!WARNING] +> This library is **alpha software** under active development. Breaking changes are expected, APIs are not yet stable, and no official support is provided. Early adopters are encouraged to open issues for bugs and feedback to help shape the project's direction. + + + + +**rblib** is a high-performance, modular Rust SDK for constructing Ethereum-compatible block builders. Built on top of the [Reth](https://github.com/paradigmxyz/reth) execution engine, it provides robust, platform-agnostic primitives and declarative workflows designed for both L1 and L2 applications. -**rblib** is a Rust SDK for building Ethereum-compatible block builders using the [Reth](https://github.com/paradigmxyz/reth) execution engine. It provides two independent, platform-agnostic APIs: +----- -- **Payload API** — Flexible primitives for constructing and inspecting block payloads. -- **Pipelines API** — Declarative workflows for block building, suitable for both L1 and L2 scenarios. +## Core Philosophy -Out-of-the-box support is provided for both `Ethereum` and `Optimism` platforms via the `Platform` trait. +`rblib` is designed for sophisticated engineering teams who require granular control and composability in their block-building logic. Our philosophy centers on three key principles: ---- + * **Modularity:** Core components are decoupled. Use the low-level Payload API for fine-grained control, or compose high-level Pipelines for declarative workflows. + * **Performance:** By leveraging Reth and a zero-copy design for payload state, `rblib` is built for high-throughput, latency-sensitive environments. + * **Extensibility:** A clean `Platform` trait abstraction allows for seamless extension to support custom EVM-based chains (L2s, app-chains) without forking the core logic. -## Payload Building API +----- -Located in `src/payload`, this API offers a composable interface for building block payloads through a series of checkpoints. It can be used standalone, without the pipeline system. +## Key Features -### Checkpoints + * **Composable Payload API:** A flexible, low-level API for constructing and inspecting block payloads via immutable `Checkpoint` transformations. + * **Declarative Pipelines API:** A high-level, composable system for defining block-building workflows (e.g., ordering, revert protection) as reusable `Step`s. + * **Platform-Agnostic Design:** Out-of-the-box support for `Ethereum` and `Optimism`, with a clear interface for adding new platforms. + * **Integrated Testing Framework:** A rich test suite with utilities for multi-platform testing, local Reth nodes, and isolated component tests. -A `Checkpoint
` is an atomic unit of payload mutation—think of it as a state transformation (e.g., applying a transaction or bundle). Checkpoints are cheap to copy, discard, and fork, making it easy to explore alternative payload constructions. +----- -Each checkpoint: +## Getting Started + +Add `rblib` to your project's dependencies: + +```bash +cargo add rblib +``` -- Tracks its entire history back to the block’s initial state. -- Implements `DatabaseRef`, acting as a chain state provider rooted at the parent block plus all mutations in its history. +----- -Common algorithms for building and inspecting checkpoints are available in `src/payload/ext/checkpoint.rs`. +## Core Concepts -#### Example: Building and Forking Payloads +`rblib` is split into two primary APIs that can be used independently or together. + +### 1\. The Payload API + +Located in `rblib::payload` (see `src/payload`), this API provides the foundational primitives for block construction. It enables exploring many different payload variations efficiently. + +#### Checkpoints + +A `Checkpoint
` is an immutable snapshot of a payload's state after a mutation (e.g., applying a transaction or bundle). Checkpoints are cheap to clone and fork, making it trivial to explore alternative block constructions from a common state. Each checkpoint retains the history of its parent, allowing it to act as a `DatabaseRef` for the chain state at that specific point. Common algorithms for inspecting checkpoints are available in `src/payload/ext/checkpoint.rs`.
+
+**Example: Building and Forking a Payload**
```rust
use rblib::{*, test_utils::*};
let ctx = BlockContext:: ` represents a linear sequence of checkpoints—useful for analyzing or manipulating parts of a payload.
+A `Span ` is a view over a linear sequence of checkpoints, useful for analyzing or manipulating a specific portion of a payload's history.
```rust
use rblib::payload::*;
-let all_history = checkpoint.history();
-let all_gas = all_history.gas_used();
+let full_history = checkpoint.history();
+let total_gas = full_history.gas_used();
-let sub_span = all_history.skip(2).take(4);
+// Analyze a sub-section of the payload
+let sub_span = full_history.skip(2).take(4);
let sub_gas = sub_span.gas_used();
```
-### Platform Agnostic
-
-The Payload API works with any type implementing the `Platform` trait.
+### 2\. The Pipelines API
----
+Located in `rblib::pipelines` (see `src/pipelines/`), this API uses the Payload API to create declarative, reusable block-building workflows. It is particularly powerful for L2s, where standardized logic can be composed and customized.
-## Pipelines API
+Pipelines are built from **Steps** (`src/pipelines/step.rs`) and control-flow components (`src/pipelines/mod.rs`). A rich library of common, reusable steps is provided in `src/pipelines/steps/`.
-Located in `src/pipelines/`, this API builds on the Payload API to provide a declarative, composable workflow for block building. It’s especially useful for L2 builders, where common logic can be reused and customized.
+**Example: A Minimal Builder Pipeline**
-### Example: Minimal Builder Pipeline
+This example defines a pipeline that loops over a set of ordering and protection steps before finalizing the block.
```rust
use rblib::*;
fn main() {
+ // Define a reusable pipeline workflow
let pipeline = Pipeline:: ` implements methods like `step()`, `before_job()`, and `after_job()`. Common steps include transaction ordering, revert protection, and more.
-- **Pipelines** (`src/pipelines/mod.rs`): Compose steps and control-flow components using a builder pattern (`.with_step()`, `.with_prologue()`, `.with_epilogue()`).
-- **Common Steps Library** (`src/pipelines/steps/`): A collection of well-tested reusable payload building steps commonly used in most block builders.
+## Platform Abstraction
----
+Chain-specific logic (e.g., transaction types, block validation rules) is abstracted via the `Platform` trait (`src/platform/mod.rs`). This allows the core building logic to remain generic while providing concrete implementations for `Ethereum` and `Optimism`.
-## Platform Abstraction Layer
+To support a custom chain, implement the `Platform` trait. See `examples/custom-platform.rs` for a practical example.
-Chain-specific logic is separated via the `Platform` trait (`src/platform/mod.rs`). You can customize platforms for different EVMs, block structures, or transaction types. See `examples/custom-platform.rs` for extending Optimism with custom bundles.
+-----
-Default implementations for `Ethereum` and `Optimism` are included.
+## Examples and Integration
----
+`Pipeline::into_service()` is the primary entry point for converting a pipeline into a Reth-compatible `PayloadServiceBuilder`. For complete integration examples, see the `examples/` directory and the reference builder implementation in `bin/flashblocks/src/main.rs`.
-## Testing Infrastructure
+-----
+## Development & Testing
+
+The project includes a comprehensive testing infrastructure to ensure reliability.
+
+ * **Run all tests:**
+ ```bash
+ cargo test
+ ```
+ * **Run a specific test with verbose logging:**
+ ```bash
+ TEST_TRACE=on cargo test smoke::all_transactions_included_ethereum
+ ```
- **Multi-Platform Testing**: Use `#[rblib_test(Ethereum, Optimism, YourCustomPlatform)]` to run tests across platforms.
- **Local Test Nodes**: `LocalNode ` (`src/test_utils/node.rs`) provides full Reth nodes for integration testing.
- **Step Testing**: `OneStep ` (`src/test_utils/step.rs`) enables isolated step testing.
- **Funded Accounts**: Use `FundedAccounts::by_address()` or `.with_random_funded_signer()` for test transactions.
- **Mocks**: Mocking utilities are available for types like `BlockContext` and `PayloadAttributes`.
----
-
-## Development Commands
-
-Run all tests:
-
-```bash
-cargo test
-```
-
-Debug a specific test with logs:
-
-```bash
-TEST_TRACE=on cargo test smoke::all_transactions_included_ethereum
-```
-
----
-
-## Integration with Reth
-
-- `Pipeline::into_service()` converts pipelines to `PayloadServiceBuilder`.
-- Platform-specific `build_payload()` methods use Reth’s native builders.
-
-See `examples/` and `bin/flashblocks/src/main.rs` for integration examples.
----
+-----
## Contributing
-Contributions, issues, and feature requests are welcome. Please see the codebase and examples for guidance on extending platforms, steps, or pipelines.
+Contributions are welcome. Please feel free to open an issue to discuss a bug, feature request, or design question. Pull requests should be focused and include relevant tests.
- ## License
+## License
-The code in this project is free software under the [MIT License](/LICENSE).
+This project is licensed under the [MIT License](/LICENSE).
----
+-----
-Made with ☀️ by the ⚡🤖 collective.
+Made with ☀️ by the ⚡🤖 collective.
\ No newline at end of file
diff --git a/assets/rblib_chip.png b/assets/rblib_chip.png
new file mode 100644
index 0000000..7dfd329
Binary files /dev/null and b/assets/rblib_chip.png differ