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

feat: add testdata #3

Merged
merged 4 commits into from
Apr 6, 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
79 changes: 79 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Cargo Build & Test

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_LOG: info

jobs:
build_and_test:
name: Rust project - latest
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
- beta
- nightly

services:
postgres:
image: postgres

env:
POSTGRES_PASSWORD: password
POSTGRES_USER: root
POSTGRES_DB: state

options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- uses: actions/checkout@v2
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- name: Cargo test
run: cargo test --release --verbose

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- name: Install Dependencies
run: sudo apt install protobuf-compiler
- run: rustup component add clippy
- run: cargo clippy --all-targets -- -D warnings
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CARGO = cargo

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
CARGO += --config 'build.rustdocflags = ["-C", "link-args=-framework CoreFoundation -framework Security"]'
endif

help: ## Display this help screen
@grep -h \
-E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

clippy: ## Run clippy checks over all workspace members and formatted correctly
@cargo check
@cargo fmt --all -- --check
@cargo clippy --all-targets -- -D warnings --no-deps

fix: ## Automatically apply lint suggestions. This flag implies `--no-deps` and `--all-targets`
@cargo clippy --fix

test: ## Run tests for all the workspace members
@cargo test --release --all

.PHONY: clippy fmt test
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
* Init the chain and run the RPC-only node

```
reth init --datadir /tmp/chain
rm -rf /tmp/chain
reth init --datadir /tmp/chain --chain testdata/chain.json
RUST_LOG="info" reth node -d --chain testdata/chain.json --datadir /tmp/chain --auto-mine --http --http.port 8546 --http.api admin,debug,eth,net,trace,txpool,web3,rpc,reth,ots,eth-call-bundle

RUST_LOG="rpc::eth=trace" RETH_DB_PATH=/tmp/chain cargo run -r
```

Expand All @@ -15,3 +18,10 @@ curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","metho
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eigenrpc_getBlockByNumber","params":[0],"id": 10}' 127.0.0.1:8545
```

You can also use [cast](https://github.com/foundry-rs/foundry/releases).

```
cast rpc eigenrpc_customMethod

cast rpc eigenrpc_getBlockByNumber 0
```
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
large-error-threshold = 1000
11 changes: 5 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use alloy_chains::Chain;
use reth_node_builder::{
components::{ComponentsBuilder, PayloadServiceBuilder},
node::NodeTypes,
BuilderContext, FullNodeTypes, Node, NodeBuilder, PayloadBuilderConfig,
BuilderContext, FullNodeTypes, Node, PayloadBuilderConfig,
};
use reth_primitives::revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg};
use reth_primitives::ChainSpecBuilder;
use reth_primitives::{Address, ChainSpec, Genesis, Header, Withdrawals, B256};
use reth_primitives::{Address, ChainSpec, Header, Withdrawals, B256};
use std::sync::Arc;

use reth_basic_payload_builder::{
Expand All @@ -22,7 +21,6 @@ use reth_node_api::{
use reth_node_core::rpc::builder::{
RethRpcModule, RpcModuleBuilder, RpcServerConfig, TransportRpcModuleConfig,
};
use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig};
use reth_provider::test_utils::TestCanonStateSubscriptions;
use reth_provider::{
providers::{BlockchainProvider, ProviderFactory},
Expand Down Expand Up @@ -52,6 +50,7 @@ use serde::{Deserialize, Serialize};
use std::convert::Infallible;
use thiserror::Error;

mod prover;
mod rpc;
use crate::rpc::EigenRpcExtApiServer;

Expand Down Expand Up @@ -335,7 +334,7 @@ where
async fn main() -> eyre::Result<()> {
let _guard = RethTracer::new().init()?;

let tasks = TaskManager::current();
let _tasks = TaskManager::current();

// create optimism genesis with canyon at block 2
//let spec = ChainSpec::builder()
Expand Down Expand Up @@ -372,7 +371,7 @@ async fn main() -> eyre::Result<()> {
let server_args =
RpcServerConfig::http(Default::default()).with_http_address("0.0.0.0:8545".parse()?);
println!("Node started");
let handle = server_args.start(server).await?;
let _handle = server_args.start(server).await?;
futures::future::pending::<()>().await;
Ok(())

Expand Down
6 changes: 6 additions & 0 deletions src/prover.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! The Client of Eigen Proof Network
//! A standalone process is needed to finish:
//! 1) Get the Latest block that not proved, check if current node need to prove it. If so, submit
//! the proof generation request to proof network;
//! 2) Keep polling if the task is finished.
//! 3) If the task is finished, update the status into proof database, hence the extended RPC module will fetch this and return it to SDK.
11 changes: 10 additions & 1 deletion src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Reth block related imports
use reth_primitives::Block;
use reth_primitives::{Block, B256};
use reth_provider::BlockReaderIdExt;

// Rpc related imports
Expand All @@ -16,6 +16,8 @@ pub trait EigenRpcExtApi {
fn custom_methhod(&self) -> EthResult<Option<Block>>;
#[method(name = "getBlockByNumber")]
fn get_block_by_number(&self, block_no: u64) -> EthResult<Option<Block>>;
#[method(name = "traceTransaction")]
fn trace_transaction(&self, hash: B256) -> EthResult<Option<()>>;
}

/// The type that implements `EigenRpc` rpc namespace trait
Expand All @@ -40,4 +42,11 @@ where
let block = self.provider.block_by_number(block_no)?;
Ok(block)
}

// TODO return the pre and post data for zkvm
fn trace_transaction(&self, _hash: B256) -> EthResult<Option<()>> {
println!("{:?}", _hash);
//let traces = self.provider.trace
Ok(Some(()))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"360f77a557873d91241bf912fcc25d84"},"ciphertext":"38fd05917cfb90e60a275bde426dac36b92428124b9a38d2801b52e38873bb31","kdf":"scrypt","kdfparams":{"dklen":32,"n":8192,"p":1,"r":8,"salt":"610187a40bfc915fe3b7890905f74667d8b399e7db21fac0b93161cbd27cc479"},"mac":"80221f1794b86b3430a5a98fc58a20e1dced667472c9771d2a531554bf4de6be"},"id":"78f3c32e-a270-47a1-8180-0a7b607c28b6","version":3}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"04bfb66fce1bb39650f34a717364805e"},"ciphertext":"f8a53136b7e3e0933f1908c5e527efccc13acd18a6bb8bd7225107e8f2af41bc","kdf":"scrypt","kdfparams":{"dklen":32,"n":8192,"p":1,"r":8,"salt":"ac9a154a193f7c91470ff4347332041e6dc325d1ec9c9e64c90e017064cb58fe"},"mac":"9fa479c5157f0ec2291922f9be6b70b0825eb6dff5bc708231c94b734fdc7eb3"},"id":"e0f3ae90-75ec-428e-a938-a25deeb3a665","version":3}
37 changes: 37 additions & 0 deletions testdata/chain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"nonce": "0x42",
"timestamp": "0x0",
"extraData": "0x5343",
"gasLimit": "0x1388",
"difficulty": "0x400000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"0x540ea708597d8e46CB33BE43139452d8c9583686": {
"balance": "0x4a47e3c12448f4ad000000"
},
"0x6831Fb06762332dCa543C0F2b5795692d896E3D4": {
"balance": "0x4a47e3c12448f4ad000000"
}
},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"config": {
"ethash": {},
"chainId": 12345,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"terminalTotalDifficulty": 0,
"terminalTotalDifficultyPassed": true,
"shanghaiTime": 0
}
}
Loading