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

Enable debug API through cmd flag, build docker image with CI #73

Merged
merged 6 commits into from
Mar 13, 2023
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
44 changes: 44 additions & 0 deletions .github/workflows/publish_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
push:
branches:
- main

name: Create and publish a Docker image

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: latest
labels: org.opencontainers.image.source=https://github.com/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN make build
# run
FROM frolvlad/alpine-glibc

COPY --from=builder /aa-bundler/target/debug/bundler /usr/local/bin/bundler
COPY --from=builder /aa-bundler/target/release/bundler /usr/local/bin/bundler

EXPOSE 3000

Expand Down
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
build:
cargo build
cargo build --release

run-bundler:
cargo run -- --eth-client-address http://127.0.0.1:8545 --mnemonic-file ${HOME}/.aa-bundler/0x129D197b2a989C6798601A49D89a4AEC822A17a3 --beneficiary 0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990 --gas-factor 600 --min-balance 1 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --helper 0x0000000000000000000000000000000000000000 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000
cargo run --release -- --eth-client-address http://127.0.0.1:8545 --mnemonic-file ${HOME}/.aa-bundler/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --gas-factor 600 --min-balance 1 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000

run-bundler-uopool:
cargo run --bin bundler-uopool -- --eth-client-address http://127.0.0.1:8545 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000
cargo run --release --bin bundler-uopool -- --eth-client-address http://127.0.0.1:8545 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000

run-bundler-rpc:
cargo run --bin bundler-rpc
cargo run --release --bin bundler-rpc

run-create-wallet:
cargo run --bin create-wallet -- --output-path ${HOME}/.aa-bundler
cargo run --release --bin create-wallet -- --output-path ${HOME}/.aa-bundler

run-bundler-debug:
cargo run --release -- --eth-client-address http://127.0.0.1:8545 --mnemonic-file ${HOME}/.aa-bundler/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --gas-factor 600 --min-balance 1 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000 --rpc-api eth,debug

fetch-thirdparty:
git submodule update --init
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ make setup-thirdparty
Create wallet for bundler:

```bash
cargo run --bin create-wallet -- --output-path ${HOME}/.aa-bundler --chain-id 5
cargo run --release --bin create-wallet -- --output-path ${HOME}/.aa-bundler --chain-id 5
```

Run bundler (with user operation pool and JSON-RPC API):

```bash
cargo run -- --eth-client-address http://127.0.0.1:8545 --mnemonic-file ${HOME}/.aa-bundler/0x129D197b2a989C6798601A49D89a4AEC822A17a3 --beneficiary 0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990 --gas-factor 600 --min-balance 1 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --helper 0x0000000000000000000000000000000000000000 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000
cargo run --release -- --eth-client-address http://127.0.0.1:8545 --mnemonic-file ${HOME}/.aa-bundler/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --gas-factor 600 --min-balance 1 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000
```

Run only user operation pool:

```bash
cargo run --bin bundler-uopool -- --eth-client-address http://127.0.0.1:8545 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000
cargo run --release --bin bundler-uopool -- --eth-client-address http://127.0.0.1:8545 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000
```

Run only JSON-RPC API:

```bash
cargo run --bin bundler-rpc
cargo run --release --bin bundler-rpc
```
34 changes: 19 additions & 15 deletions bin/bundler-rpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use jsonrpsee::{core::server::rpc_module::Methods, server::ServerBuilder, tracing::info};
use std::future::pending;
use std::{collections::HashSet, future::pending};

use aa_bundler::{
rpc::{
Expand All @@ -22,6 +22,9 @@ pub struct Opt {

#[clap(long, default_value = "127.0.0.1:3001")]
pub uopool_grpc_listen_address: String,

#[clap(long, value_delimiter=',', default_value = "eth", value_parser = ["eth", "debug"])]
pub rpc_api: Vec<String>,
}

#[tokio::main]
Expand All @@ -38,20 +41,21 @@ async fn main() -> Result<()> {
let uopool_grpc_client =
UoPoolClient::connect(format!("http://{}", opt.uopool_grpc_listen_address)).await?;

#[cfg(debug_assertions)]
api.merge(
DebugApiServerImpl {
uopool_grpc_client: uopool_grpc_client.clone(),
}
.into_rpc(),
)?;
api.merge(
EthApiServerImpl {
call_gas_limit: 100_000_000,
uopool_grpc_client,
}
.into_rpc(),
)?;
let rpc_api: HashSet<String> = HashSet::from_iter(opt.rpc_api.iter().cloned());

if rpc_api.contains("eth") {
api.merge(
EthApiServerImpl {
call_gas_limit: 100_000_000,
uopool_grpc_client: uopool_grpc_client.clone(),
}
.into_rpc(),
)?;
}

if rpc_api.contains("debug") {
api.merge(DebugApiServerImpl { uopool_grpc_client }.into_rpc())?;
}

let _jsonrpc_server_handle = jsonrpc_server.start(api.clone())?;
info!("JSON-RPC server listening on {}", opt.rpc_listen_address);
Expand Down
35 changes: 20 additions & 15 deletions bin/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ethers::{
};
use expanded_pathbuf::ExpandedPathBuf;
use jsonrpsee::{core::server::rpc_module::Methods, server::ServerBuilder, tracing::info};
use std::{future::pending, panic, sync::Arc};
use std::{collections::HashSet, future::pending, panic, sync::Arc};

#[derive(Parser)]
#[clap(
Expand Down Expand Up @@ -45,6 +45,9 @@ pub struct Opt {
#[clap(long, default_value = "127.0.0.1:3000")]
pub rpc_listen_address: String,

#[clap(long, value_delimiter=',', default_value = "eth", value_parser = ["eth", "debug"])]
pub rpc_api: Vec<String>,

// execution client rpc endpoint
#[clap(long, default_value = "http://127.0.0.1:8545")]
pub eth_client_address: String,
Expand Down Expand Up @@ -125,20 +128,22 @@ fn main() -> Result<()> {

let mut api = Methods::new();

#[cfg(debug_assertions)]
api.merge(
DebugApiServerImpl {
uopool_grpc_client: uopool_grpc_client.clone(),
}
.into_rpc(),
)?;
api.merge(
EthApiServerImpl {
call_gas_limit: 100_000_000,
uopool_grpc_client,
}
.into_rpc(),
)?;
let rpc_api: HashSet<String> =
HashSet::from_iter(opt.rpc_api.iter().cloned());

if rpc_api.contains("eth") {
api.merge(
EthApiServerImpl {
call_gas_limit: 100_000_000,
uopool_grpc_client: uopool_grpc_client.clone(),
}
.into_rpc(),
)?;
}

if rpc_api.contains("debug") {
api.merge(DebugApiServerImpl { uopool_grpc_client }.into_rpc())?;
}

let _jsonrpc_server_handle = jsonrpc_server.start(api.clone())?;
info!("JSON-RPC server listening on {}", opt.rpc_listen_address);
Expand Down
2 changes: 1 addition & 1 deletion bundler-spec-test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '2'
services:
bundler:
image: ghcr.io/vid201/aa-bundler:latest
command: --rpc-listen-address 0.0.0.0:3000 --eth-client-address http://geth-dev:8545 --mnemonic-file /root/${BUNDLER_ACCOUNT} --beneficiary 0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990 --gas-factor 600 --min-balance 1 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --helper 0x0000000000000000000000000000000000000000 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000
command: --rpc-listen-address 0.0.0.0:3000 --eth-client-address http://geth-dev:8545 --mnemonic-file /root/${BUNDLER_ACCOUNT} --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --gas-factor 600 --min-balance 1 --entry-points 0x0576a174D229E3cFA37253523E645A78A0C91B57 --min-stake 1 --min-unstake-delay 0 --min-priority-fee-per-gas 0 --max-verification-gas 1500000 --rpc-api eth,debug
ports: [ '3000:3000' ]
volumes:
- ./keys:/root
Expand Down
6 changes: 0 additions & 6 deletions src/bundler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ pub struct BundlerOpts {
#[clap(long, value_parser=parse_u256)]
pub min_balance: U256,

#[clap(long, value_parser=parse_address)]
pub helper: Address,

#[clap(long, default_value = "127.0.0.1:3002")]
pub bundler_grpc_listen_address: String,

Expand Down Expand Up @@ -143,8 +140,6 @@ mod tests {
"600",
"--min-balance",
"1",
"--helper",
"0x0000000000000000000000000000000000000000",
"--bundler-grpc-listen-address",
"127.0.0.1:3002",
"--bundle-interval",
Expand All @@ -156,7 +151,6 @@ mod tests {
.unwrap(),
gas_factor: U256::from(600),
min_balance: U256::from(1),
helper: Address::from([0; 20]),
bundler_grpc_listen_address: String::from("127.0.0.1:3002"),
bundle_interval: 10,
},
Expand Down
2 changes: 0 additions & 2 deletions src/rpc/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ use async_trait::async_trait;
use ethers::types::Address;
use jsonrpsee::core::RpcResult;

#[cfg(debug_assertions)]
pub struct DebugApiServerImpl {
pub uopool_grpc_client: UoPoolClient<tonic::transport::Channel>,
}

#[cfg(debug_assertions)]
#[async_trait]
impl DebugApiServer for DebugApiServerImpl {
async fn clear_state(&self) -> RpcResult<()> {
Expand Down
1 change: 0 additions & 1 deletion src/rpc/debug_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::types::{reputation::ReputationEntry, user_operation::UserOperation};
use ethers::types::Address;
use jsonrpsee::{core::RpcResult, proc_macros::rpc};

#[cfg(debug_assertions)]
#[rpc(server, namespace = "debug_bundler")]
pub trait DebugApi {
#[method(name = "clearState")]
Expand Down
2 changes: 0 additions & 2 deletions src/uopool/database_mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ impl<E: EnvironmentKind> Mempool for DatabaseMempool<E> {
.map_err(DBError::DBInternalError)
}

#[cfg(debug_assertions)]
fn get_all(&self) -> Self::UserOperations {
self.env
.tx()
Expand All @@ -196,7 +195,6 @@ impl<E: EnvironmentKind> Mempool for DatabaseMempool<E> {
.unwrap_or_else(|_| vec![])
}

#[cfg(debug_assertions)]
fn clear(&mut self) {
self.env
.tx_mut()
Expand Down
2 changes: 0 additions & 2 deletions src/uopool/memory_mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,10 @@ impl Mempool for MemoryMempool {
Ok(user_operations)
}

#[cfg(debug_assertions)]
fn get_all(&self) -> Self::UserOperations {
self.user_operations.values().cloned().collect()
}

#[cfg(debug_assertions)]
fn clear(&mut self) {
self.user_operations.clear();
self.user_operations_by_sender.clear();
Expand Down
3 changes: 0 additions & 3 deletions src/uopool/memory_reputation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,16 @@ impl Reputation for MemoryReputation {
Ok(())
}

#[cfg(debug_assertions)]
fn set(&mut self, reputation_entries: Self::ReputationEntries) {
for reputation in reputation_entries {
self.entities.insert(reputation.address, reputation);
}
}

#[cfg(debug_assertions)]
fn get_all(&self) -> Self::ReputationEntries {
self.entities.values().cloned().collect()
}

#[cfg(debug_assertions)]
fn clear(&mut self) {
self.entities.clear();
}
Expand Down
9 changes: 0 additions & 9 deletions src/uopool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ pub trait Mempool: Debug {
fn remove(&mut self, user_operation_hash: &UserOperationHash) -> Result<(), Self::Error>;
// Get UserOperations sorted by max_priority_fee_per_gas without dup sender
fn get_sorted(&self) -> Result<Self::UserOperations, Self::Error>;

#[cfg(debug_assertions)]
fn get_all(&self) -> Self::UserOperations;

#[cfg(debug_assertions)]
fn clear(&mut self);
}

Expand Down Expand Up @@ -111,13 +107,8 @@ pub trait Reputation: Debug {
}
}

#[cfg(debug_assertions)]
fn set(&mut self, reputation_entries: Self::ReputationEntries);

#[cfg(debug_assertions)]
fn get_all(&self) -> Self::ReputationEntries;

#[cfg(debug_assertions)]
fn clear(&mut self);
}

Expand Down
4 changes: 0 additions & 4 deletions src/uopool/services/uopool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ where
}
}

#[cfg(debug_assertions)]
async fn get_all(
&self,
request: tonic::Request<GetAllRequest>,
Expand Down Expand Up @@ -452,7 +451,6 @@ where
Err(tonic::Status::invalid_argument("missing entry point"))
}

#[cfg(debug_assertions)]
async fn clear(
&self,
_request: tonic::Request<()>,
Expand All @@ -470,7 +468,6 @@ where
}))
}

#[cfg(debug_assertions)]
async fn get_all_reputation(
&self,
request: tonic::Request<GetAllReputationRequest>,
Expand Down Expand Up @@ -500,7 +497,6 @@ where
Err(tonic::Status::invalid_argument("missing entry point"))
}

#[cfg(debug_assertions)]
async fn set_reputation(
&self,
request: tonic::Request<SetReputationRequest>,
Expand Down