Skip to content

Commit

Permalink
feat: bundler conformance to latest specs, handle reputation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 committed Oct 13, 2023
1 parent 502194d commit e7e3300
Show file tree
Hide file tree
Showing 40 changed files with 1,193 additions and 403 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
- uses: actions/checkout@v3
with:
repository: eth-infinitism/bundler-spec-tests
ref: 'e193753db1910fb6d0ee2661d96a8d8f79d6c7d8'
ref: 'bbd61f21e95ed1290678fcbfd9551b1502c81fe9'
submodules: true
- uses: actions/checkout@v3
with:
Expand All @@ -94,7 +94,7 @@ jobs:

- run: pip install jq yq

- run: pdm install && git submodule update --init --recursive && cd @account-abstraction && yarn && yarn compile && cd ../spec && yarn && yarn build
- run: pdm install && git submodule update --init --recursive && cd @account-abstraction && git fetch --all --tags && git checkout tags/v0.6.0 -b v0.6.0 && yarn && yarn compile && cd ../spec && yarn && yarn build

- uses: actions/download-artifact@v3
with:
Expand Down
46 changes: 44 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ make lint
make test
```

Official [bundler spec tests](https://github.com/eth-infinitism/bundler-spec-tests) developed by the [eth-infinitism](https://github.com/eth-infinitism/) team are also included in the repo's CI pipeline (commit: [e193753db1910fb6d0ee2661d96a8d8f79d6c7d8](https://github.com/eth-infinitism/bundler-spec-tests/tree/e193753db1910fb6d0ee2661d96a8d8f79d6c7d8)). You can find more information on how to run tests [here](https://github.com/eth-infinitism/bundler-spec-tests). Make sure your contribution doesn't break the tests!
Official [bundler spec tests](https://github.com/eth-infinitism/bundler-spec-tests) developed by the [eth-infinitism](https://github.com/eth-infinitism/) team are also included in the repo's CI pipeline (commit: [bbd61f21e95ed1290678fcbfd9551b1502c81fe9](https://github.com/eth-infinitism/bundler-spec-tests/tree/bbd61f21e95ed1290678fcbfd9551b1502c81fe9)). You can find more information on how to run tests [here](https://github.com/eth-infinitism/bundler-spec-tests). Make sure your contribution doesn't break the tests!

## Contact

Expand Down
1 change: 0 additions & 1 deletion bin/silius/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ where
chain_id,
args.max_verification_gas,
args.min_stake,
args.min_unstake_delay,
args.min_priority_fee_per_gas,
args.whitelist,
args.uopool_mode,
Expand Down
4 changes: 0 additions & 4 deletions bin/silius/src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ pub struct UoPoolArgs {
#[clap(long, value_parser=parse_u256, default_value = "1")]
pub min_stake: U256,

/// Minimum unstake delay for entities.
#[clap(long, value_parser=parse_u256, default_value = "0")]
pub min_unstake_delay: U256,

/// Minimum priority fee per gas.
#[clap(long, value_parser=parse_u256, default_value = "0")]
pub min_priority_fee_per_gas: U256,
Expand Down
15 changes: 5 additions & 10 deletions crates/grpc/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::uopool::{GAS_INCREASE_PERC, MAX_UOS_PER_UNSTAKED_SENDER};
use ethers::{
providers::Middleware,
types::{Address, H256, U256},
Expand All @@ -7,9 +6,12 @@ use eyre::format_err;
use futures_util::StreamExt;
use silius_contracts::EntryPoint;
use silius_primitives::{
consts::reputation::{
BAN_SLACK, MIN_INCLUSION_RATE_DENOMINATOR, MIN_UNSTAKE_DELAY, THROTTLING_SLACK,
},
get_address,
provider::BlockStream,
reputation::{ReputationEntry, BAN_SLACK, MIN_INCLUSION_RATE_DENOMINATOR, THROTTLING_SLACK},
reputation::ReputationEntry,
Chain, UserOperation,
};
use silius_uopool::{
Expand All @@ -35,7 +37,6 @@ where
chain: Chain,
max_verification_gas: U256,
min_stake: U256,
min_unstake_delay: U256,
min_priority_fee_per_gas: U256,
whitelist: Vec<Address>,
mempool: MempoolBox<VecUo, VecCh, P, E>,
Expand All @@ -57,7 +58,6 @@ where
chain: Chain,
max_verification_gas: U256,
min_stake: U256,
min_unstake_delay: U256,
min_priority_fee_per_gas: U256,
whitelist: Vec<Address>,
mempool: P,
Expand All @@ -73,7 +73,7 @@ where
THROTTLING_SLACK,
BAN_SLACK,
min_stake,
min_unstake_delay,
MIN_UNSTAKE_DELAY.into(),
);
for addr in whitelist.iter() {
reputation.add_whitelist(addr);
Expand All @@ -86,7 +86,6 @@ where
chain,
max_verification_gas,
min_stake,
min_unstake_delay,
min_priority_fee_per_gas,
whitelist,
mempool,
Expand Down Expand Up @@ -199,17 +198,13 @@ where
self.chain,
self.max_verification_gas,
self.min_priority_fee_per_gas,
MAX_UOS_PER_UNSTAKED_SENDER,
GAS_INCREASE_PERC.into(),
)
} else {
StandardUserOperationValidator::new_canonical(
entry_point.clone(),
self.chain,
self.max_verification_gas,
self.min_priority_fee_per_gas,
MAX_UOS_PER_UNSTAKED_SENDER,
GAS_INCREASE_PERC.into(),
)
};

Expand Down
20 changes: 20 additions & 0 deletions crates/grpc/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ pub mod types {
Self::from(value.0)
}
}

impl From<silius_primitives::reputation::StakeInfo> for StakeInfo {
fn from(value: silius_primitives::reputation::StakeInfo) -> Self {
Self {
address: Some(value.address.into()),
stake: value.stake.as_u64(),
unstake_delay: value.unstake_delay.as_u64(),
}
}
}

impl From<StakeInfo> for silius_primitives::reputation::StakeInfo {
fn from(value: StakeInfo) -> Self {
Self {
address: value.address.unwrap_or_default().into(),
stake: value.stake.into(),
unstake_delay: value.unstake_delay.into(),
}
}
}
}

pub mod uopool {
Expand Down
6 changes: 6 additions & 0 deletions crates/grpc/src/protos/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ message Log{
H256 transaction_hash = 8;
PbU256 log_index = 9;
}

message StakeInfo {
H160 address = 1;
uint64 stake = 2;
uint64 unstake_delay = 3;
}
13 changes: 13 additions & 0 deletions crates/grpc/src/protos/uopool/uopool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ message GetUserOperationReceiptResponse{
string reason = 10;
}

message GetStakeInfoRequest {
types.H160 addr = 1;
types.H160 ep = 2;
}

message GetStakeInfoResponse {
types.StakeInfo info = 1;
bool is_staked = 2;
}

service UoPool {
rpc Add(AddRequest) returns (AddResponse);
rpc Remove(RemoveRequest) returns (google.protobuf.Empty);
Expand All @@ -112,9 +122,12 @@ service UoPool {
rpc GetSortedUserOperations(GetSortedRequest) returns (GetSortedResponse);
rpc GetUserOperationByHash(UserOperationHashRequest) returns (GetUserOperationByHashResponse);
rpc GetUserOperationReceipt(UserOperationHashRequest) returns (GetUserOperationReceiptResponse);
rpc GetStakeInfo(GetStakeInfoRequest) returns (GetStakeInfoResponse);

// debug
rpc GetAll(GetAllRequest) returns (GetAllResponse);
rpc ClearMempool(google.protobuf.Empty) returns (google.protobuf.Empty);
rpc ClearReputation(google.protobuf.Empty) returns (google.protobuf.Empty);
rpc Clear(google.protobuf.Empty) returns (google.protobuf.Empty);
rpc GetAllReputation(GetAllReputationRequest) returns (GetAllReputationResponse);
rpc SetReputation(SetReputationRequest) returns (SetReputationResponse);
Expand Down
51 changes: 35 additions & 16 deletions crates/grpc/src/uopool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ use std::fmt::{Debug, Display};
use std::{net::SocketAddr, sync::Arc, time::Duration};
use tonic::{Code, Request, Response, Status};

pub const MAX_UOS_PER_UNSTAKED_SENDER: usize = 4;
pub const GAS_INCREASE_PERC: u64 = 10;

type StandardUserPool<M, P, R, E> =
UserOperationPool<M, StandardUserOperationValidator<M, P, R, E>, P, R, E>;

Expand Down Expand Up @@ -81,17 +78,7 @@ where

let res = {
let uopool = self.get_uopool(&ep)?;
match uopool.validate_user_operation(&uo).await {
Ok(res) => res,
Err(err) => {
return Ok(Response::new(AddResponse {
res: AddResult::NotAdded as i32,
data: serde_json::to_string(&err).map_err(|err| {
Status::internal(format!("Failed to serialize error: {err}"))
})?,
}))
}
}
uopool.validate_user_operation(&uo).await
};

let mut uopool = self.get_uopool(&ep)?;
Expand Down Expand Up @@ -279,6 +266,20 @@ where
}))
}

async fn clear_mempool(&self, _req: Request<()>) -> Result<Response<()>, Status> {
self.uopools.iter_mut().for_each(|uopool| {
uopool.uopool().clear_mempool();
});
Ok(Response::new(()))
}

async fn clear_reputation(&self, _req: Request<()>) -> Result<Response<()>, Status> {
self.uopools.iter_mut().for_each(|uopool| {
uopool.uopool().clear_reputation();
});
Ok(Response::new(()))
}

async fn clear(&self, _req: Request<()>) -> Result<Response<()>, Status> {
self.uopools.iter_mut().for_each(|uopool| {
uopool.uopool().clear();
Expand Down Expand Up @@ -322,6 +323,26 @@ where

Ok(res)
}

async fn get_stake_info(
&self,
req: Request<GetStakeInfoRequest>,
) -> Result<Response<GetStakeInfoResponse>, Status> {
let req = req.into_inner();

let ep = parse_addr(req.ep)?;
let addr = parse_addr(req.addr)?;
let uopool = self.get_uopool(&ep)?;

let res = uopool
.get_stake_info(&addr)
.await
.map_err(|e| tonic::Status::internal(format!("Get stake info internal error: {e}")))?;
Ok(Response::new(GetStakeInfoResponse {
info: Some(res.stake_info.into()),
is_staked: res.is_staked,
}))
}
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -334,7 +355,6 @@ pub async fn uopool_service_run<M>(
chain: Chain,
max_verification_gas: U256,
min_stake: U256,
min_unstake_delay: U256,
min_priority_fee_per_gas: U256,
whitelist: Vec<Address>,
upool_mode: UoPoolMode,
Expand Down Expand Up @@ -363,7 +383,6 @@ where
chain,
max_verification_gas,
min_stake,
min_unstake_delay,
min_priority_fee_per_gas,
whitelist.clone(),
DatabaseMempool::new(env.clone()),
Expand Down
1 change: 1 addition & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ futures-util = { workspace = true }
lazy_static = "1.4.0"
rustc-hex = "^2.0.1"
serde = "1"
serde-hex = "0.1.0"
serde_json = { workspace = true }
ssz_rs = "0.8.0"
ssz_rs_derive = "0.8.0"
Expand Down
Loading

0 comments on commit e7e3300

Please sign in to comment.