Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/cargo/webpki-0.22.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dancoombs authored Oct 10, 2023
2 parents 653e4f2 + 440c096 commit d1d9191
Show file tree
Hide file tree
Showing 26 changed files with 351 additions and 115 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/compliance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
push:
branches:
- main
pull_request:

name: compliance
jobs:
compliance:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: recursive
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
cache-dependency-path: test/spec-tests/bundler-spec-tests/@account-abstraction/yarn.lock
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Setup PDM
uses: pdm-project/setup-pdm@v3
with:
cache: true
cache-dependency-path: '**/pdm.lock'
- name: Run spec tests
run: ./test/spec-tests/ci/run-spec-tests.sh
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"crates/*",
]
default-members = ["bin/rundler"]
resolver = "2"

[workspace.package]
version = "0.1.0-beta"
Expand Down
1 change: 1 addition & 0 deletions crates/builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mockall = {workspace = true, optional = true }
mockall.workspace = true
rundler-pool = { path = "../pool", features = ["test-utils"] }
rundler-provider = { path = "../provider", features = ["test-utils"] }
rundler-sim = { path = "../sim", features = ["test-utils"] }

[build-dependencies]
tonic-build.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/builder/proto/builder/builder.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ message DebugSendBundleNowResponse {
}
message DebugSendBundleNowSuccess {
bytes transaction_hash = 1;
uint64 block_number = 2;
}

message DebugSetBundlingModeRequest {
Expand Down
31 changes: 14 additions & 17 deletions crates/builder/src/bundle_proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ use crate::emit::{BuilderEvent, OpRejectionReason, SkipReason};

/// A user op must be valid for at least this long into the future to be included.
const TIME_RANGE_BUFFER: Duration = Duration::from_secs(60);
/// Entrypoint requires a buffer over the user operation gas limits in the bundle transaction
const BUNDLE_TRANSACTION_GAS_OVERHEAD_BUFFER: u64 = 5000;
/// Extra buffer percent to add on the bundle transaction gas estimate to be sure it will be enough
const BUNDLE_TRANSACTION_GAS_OVERHEAD_PERCENT: u64 = 5;

Expand Down Expand Up @@ -538,7 +536,7 @@ where
let mut gas_left = U256::from(self.settings.max_bundle_gas);
let mut ops_in_bundle = Vec::new();
for op in ops {
let gas = gas::user_operation_gas_limit(&op.uo, self.settings.chain_id);
let gas = gas::user_operation_gas_limit(&op.uo, self.settings.chain_id, false);
if gas_left < gas {
self.emit(BuilderEvent::skipped_op(
self.builder_index,
Expand Down Expand Up @@ -739,10 +737,7 @@ impl ProposalContext {
}

fn get_total_gas_limit(&self, chain_id: u64) -> U256 {
self.iter_ops()
.map(|op| gas::user_operation_gas_limit(op, chain_id))
.fold(U256::zero(), |acc, c| acc + c)
+ BUNDLE_TRANSACTION_GAS_OVERHEAD_BUFFER
gas::bundle_gas_limit(self.iter_ops(), chain_id)
}

fn iter_ops_with_simulations(&self) -> impl Iterator<Item = &OpWithSimulation> + '_ {
Expand All @@ -762,7 +757,7 @@ mod tests {
use ethers::{types::H160, utils::parse_units};
use rundler_pool::MockPoolServer;
use rundler_provider::{AggregatorSimOut, MockEntryPoint, MockProvider};
use rundler_sim::{MockSimulator, SimulationViolation};
use rundler_sim::{gas::GasOverheads, MockSimulator, SimulationViolation};
use rundler_types::ValidTimeRange;

use super::*;
Expand All @@ -782,11 +777,13 @@ mod tests {
}])
.await;

let ov = GasOverheads::default();
let expected_gas = math::increase_by_percent(
op.pre_verification_gas
+ op.verification_gas_limit * 2
+ op.call_gas_limit
+ BUNDLE_TRANSACTION_GAS_OVERHEAD_BUFFER,
+ ov.bundle_transaction_gas_buffer
+ ov.transaction_gas_overhead,
BUNDLE_TRANSACTION_GAS_OVERHEAD_PERCENT,
);

Expand Down Expand Up @@ -909,7 +906,7 @@ mod tests {
let max_priority_fee_per_gas = U256::from(50);
let op1 = op_with_sender_and_fees(address(1), 2054.into(), 54.into());
let op2 = op_with_sender_and_fees(address(2), 2055.into(), 55.into());
let bundle = make_bundle(
let bundle = mock_make_bundle(
vec![
MockOp {
op: op1.clone(),
Expand Down Expand Up @@ -943,7 +940,7 @@ mod tests {
let max_priority_fee_per_gas = U256::from(50);
let op1 = op_with_sender_and_fees(address(1), 1054.into(), 55.into());
let op2 = op_with_sender_and_fees(address(2), 1055.into(), 55.into());
let bundle = make_bundle(
let bundle = mock_make_bundle(
vec![
MockOp {
op: op1.clone(),
Expand Down Expand Up @@ -993,7 +990,7 @@ mod tests {
let op_b_aggregated_sig = 21;
let aggregator_a_signature = 101;
let aggregator_b_signature = 102;
let bundle = make_bundle(
let bundle = mock_make_bundle(
vec![
MockOp {
op: unaggregated_op.clone(),
Expand Down Expand Up @@ -1098,7 +1095,7 @@ mod tests {
let op6 = op_with_sender_factory(address(6), address(4));
let deposit = parse_units("1", "ether").unwrap().into();

let bundle = make_bundle(
let bundle = mock_make_bundle(
vec![
MockOp {
op: op1.clone(),
Expand Down Expand Up @@ -1159,7 +1156,7 @@ mod tests {
let op4 = op_with_sender_call_gas_limit(address(4), U256::from(10_000_000));
let deposit = parse_units("1", "ether").unwrap().into();

let bundle = make_bundle(
let bundle = mock_make_bundle(
vec![
MockOp {
op: op1.clone(),
Expand Down Expand Up @@ -1198,7 +1195,7 @@ mod tests {
assert_eq!(
bundle.gas_estimate,
U256::from(math::increase_by_percent(
10_000_000 + BUNDLE_TRANSACTION_GAS_OVERHEAD_BUFFER,
10_000_000 + 5_000 + 21_000,
BUNDLE_TRANSACTION_GAS_OVERHEAD_PERCENT
))
);
Expand All @@ -1216,7 +1213,7 @@ mod tests {
}

async fn simple_make_bundle(mock_ops: Vec<MockOp>) -> Bundle {
make_bundle(
mock_make_bundle(
mock_ops,
vec![],
vec![HandleOpsOut::Success],
Expand All @@ -1227,7 +1224,7 @@ mod tests {
.await
}

async fn make_bundle(
async fn mock_make_bundle(
mock_ops: Vec<MockOp>,
mock_aggregators: Vec<MockAggregator>,
mock_handle_ops_call_results: Vec<HandleOpsOut>,
Expand Down
70 changes: 32 additions & 38 deletions crates/builder/src/bundle_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
// You should have received a copy of the GNU General Public License along with Rundler.
// If not, see https://www.gnu.org/licenses/.

use std::{
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
time::Duration,
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};

use anyhow::{bail, Context};
Expand All @@ -31,7 +28,6 @@ use rundler_utils::emit::WithEntryPoint;
use tokio::{
join,
sync::{broadcast, mpsc, oneshot},
time,
};
use tracing::{error, info, trace, warn};

Expand Down Expand Up @@ -65,7 +61,6 @@ where
send_bundle_receiver: mpsc::Receiver<SendBundleRequest>,
chain_id: u64,
beneficiary: Address,
eth_poll_interval: Duration,
proposer: P,
entry_point: E,
transaction_tracker: T,
Expand Down Expand Up @@ -141,44 +136,45 @@ where

loop {
let mut send_bundle_response: Option<oneshot::Sender<SendBundleResult>> = None;
let mut last_block = None;

if self.manual_bundling_mode.load(Ordering::Relaxed) {
tokio::select! {
Some(r) = self.send_bundle_receiver.recv() => {
send_bundle_response = Some(r.responder);
}
_ = time::sleep(self.eth_poll_interval) => {
continue;
}
if let Some(r) = self.send_bundle_receiver.recv().await {
send_bundle_response = Some(r.responder);
} else {
error!("Bundle stream closed in manual mode");
bail!("Bundle stream closed in manual mode");
}
}
} else {
// Wait for new block. Block number doesn't matter as the pool will only notify of new blocks
// after the pool has updated its state. The bundle will be formed using the latest pool state
// and can land in the next block
last_block = rx.recv().await;

// Wait for new block. Block number doesn't matter as the pool will only notify of new blocks
// after the pool has updated its state. The bundle will be formed using the latest pool state
// and can land in the next block
let mut last_block = match rx.recv().await {
Some(b) => b,
None => {
if last_block.is_none() {
error!("Block stream closed");
bail!("Block stream closed");
}
};
// Consume any other blocks that may have been buffered up
loop {
match rx.try_recv() {
Ok(b) => {
last_block = b;
}
Err(mpsc::error::TryRecvError::Empty) => {
break;
}
Err(mpsc::error::TryRecvError::Disconnected) => {
error!("Block stream closed");
bail!("Block stream closed");
// Consume any other blocks that may have been buffered up
loop {
match rx.try_recv() {
Ok(b) => {
last_block = Some(b);
}
Err(mpsc::error::TryRecvError::Empty) => {
break;
}
Err(mpsc::error::TryRecvError::Disconnected) => {
error!("Block stream closed");
bail!("Block stream closed");
}
}
}
}

// Wait for new block. Block number doesn't matter as the pool will only notify of new blocks
// after the pool has updated its state. The bundle will be formed using the latest pool state
// and can land in the next block
self.check_for_and_log_transaction_update().await;
let result = self.send_bundle_with_increasing_gas_fees().await;
match &result {
Expand All @@ -192,7 +188,7 @@ where
} else {
info!("Bundle with hash {tx_hash:?} landed in block {block_number} after increasing gas fees {attempt_number} time(s)");
}
SendBundleResult::NoOperationsInitially => trace!("No ops to send at block {}", last_block.block_number),
SendBundleResult::NoOperationsInitially => trace!("No ops to send at block {}", last_block.unwrap_or_default().block_number),
SendBundleResult::NoOperationsAfterFeeIncreases {
initial_op_count,
attempt_number,
Expand Down Expand Up @@ -227,7 +223,6 @@ where
send_bundle_receiver: mpsc::Receiver<SendBundleRequest>,
chain_id: u64,
beneficiary: Address,
eth_poll_interval: Duration,
proposer: P,
entry_point: E,
transaction_tracker: T,
Expand All @@ -241,7 +236,6 @@ where
send_bundle_receiver,
chain_id,
beneficiary,
eth_poll_interval,
proposer,
entry_point,
transaction_tracker,
Expand Down
10 changes: 5 additions & 5 deletions crates/builder/src/server/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ impl BuilderServer for LocalBuilderHandle {
}
}

async fn debug_send_bundle_now(&self) -> BuilderResult<H256> {
async fn debug_send_bundle_now(&self) -> BuilderResult<(H256, u64)> {
let req = ServerRequestKind::DebugSendBundleNow;
let resp = self.send(req).await?;
match resp {
ServerResponse::DebugSendBundleNow { hash } => Ok(hash),
ServerResponse::DebugSendBundleNow { hash, block_number } => Ok((hash, block_number)),
_ => Err(BuilderServerError::UnexpectedResponse),
}
}
Expand Down Expand Up @@ -197,8 +197,8 @@ impl LocalBuilderServerRunner {
};

match result {
SendBundleResult::Success { tx_hash, .. } => {
Ok(ServerResponse::DebugSendBundleNow { hash: tx_hash })
SendBundleResult::Success { tx_hash, block_number, .. } => {
Ok(ServerResponse::DebugSendBundleNow { hash: tx_hash, block_number })
},
SendBundleResult::NoOperationsInitially => {
Err(anyhow::anyhow!("no ops to send").into())
Expand Down Expand Up @@ -242,6 +242,6 @@ struct ServerRequest {
#[derive(Clone, Debug)]
enum ServerResponse {
GetSupportedEntryPoints { entry_points: Vec<Address> },
DebugSendBundleNow { hash: H256 },
DebugSendBundleNow { hash: H256, block_number: u64 },
DebugSetBundlingMode,
}
2 changes: 1 addition & 1 deletion crates/builder/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub trait BuilderServer: Send + Sync + 'static {
/// Trigger the builder to send a bundle now, used for debugging.
///
/// Bundling mode must be set to `Manual`, or this will error
async fn debug_send_bundle_now(&self) -> BuilderResult<H256>;
async fn debug_send_bundle_now(&self) -> BuilderResult<(H256, u64)>;

/// Set the bundling mode
async fn debug_set_bundling_mode(&self, mode: BundlingMode) -> BuilderResult<()>;
Expand Down
4 changes: 2 additions & 2 deletions crates/builder/src/server/remote/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl BuilderServer for RemoteBuilderClient {
.collect::<Result<_, ConversionError>>()?)
}

async fn debug_send_bundle_now(&self) -> BuilderResult<H256> {
async fn debug_send_bundle_now(&self) -> BuilderResult<(H256, u64)> {
let res = self
.grpc_client
.clone()
Expand All @@ -80,7 +80,7 @@ impl BuilderServer for RemoteBuilderClient {

match res {
Some(debug_send_bundle_now_response::Result::Success(s)) => {
Ok(H256::from_slice(&s.transaction_hash))
Ok((H256::from_slice(&s.transaction_hash), s.block_number))
}
Some(debug_send_bundle_now_response::Result::Failure(f)) => Err(f.try_into()?),
None => Err(BuilderServerError::Other(anyhow::anyhow!(
Expand Down
Loading

0 comments on commit d1d9191

Please sign in to comment.