Skip to content

Commit

Permalink
chore: update to rust v1.79.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dancoombs committed Jun 27, 2024
1 parent e06ca61 commit 355a108
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
toolchain: 1.75.0
toolchain: 1.79.0
- name: Install toolchain (nightly)
run: rustup toolchain add nightly --component rustfmt --profile minimal
- uses: Swatinem/rust-cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
toolchain: 1.75.0
toolchain: 1.79.0

- name: Install toolchain (nightly)
run: rustup toolchain add nightly --component rustfmt --profile minimal
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resolver = "2"
[workspace.package]
version = "0.3.0"
edition = "2021"
rust-version = "1.75"
rust-version = "1.79"
license = "MIT OR Apache-2.0"
repository = "https://github.com/alchemyplatform/rundler"

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Adapted from https://github.com/paradigmxyz/reth/blob/main/Dockerfile
# syntax=docker/dockerfile:1.4

FROM --platform=$TARGETPLATFORM rust:1.75.0 AS chef-builder
FROM --platform=$TARGETPLATFORM rust:1.79.0 AS chef-builder

# Install system dependencies
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
Expand Down
7 changes: 0 additions & 7 deletions bin/rundler/src/cli/node/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use std::fmt::Display;

use ethers::types::Address;
use rundler_builder::BuilderEvent;
use rundler_pool::PoolEvent;

Expand All @@ -23,12 +22,6 @@ pub enum Event {
BuilderEvent(BuilderEvent),
}

#[derive(Clone, Debug)]
pub struct WithEntryPoint<T> {
pub entry_point: Address,
pub event: T,
}

impl From<PoolEvent> for Event {
fn from(event: PoolEvent) -> Self {
Self::PoolEvent(event)
Expand Down
54 changes: 3 additions & 51 deletions crates/builder/src/sender/bloxroute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
// 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::Arc, time::Duration};
use std::sync::Arc;

use anyhow::Context;
use ethers::{
middleware::SignerMiddleware,
providers::{JsonRpcClient, Middleware, Provider},
types::{
transaction::eip2718::TypedTransaction, Address, Bytes, TransactionReceipt, TxHash, H256,
U256,
},
types::{transaction::eip2718::TypedTransaction, Address, Bytes, TxHash, H256, U256},
utils::hex,
};
use ethers_signers::Signer;
Expand All @@ -32,7 +29,6 @@ use rundler_sim::ExpectedStorage;
use rundler_types::GasFees;
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
use tokio::time;
use tonic::async_trait;

use super::{
Expand All @@ -46,9 +42,7 @@ where
S: Signer + 'static,
{
provider: SignerMiddleware<Arc<Provider<C>>, S>,
raw_provider: Arc<Provider<C>>,
client: PolygonBloxrouteClient,
poll_interval: Duration,
}

#[async_trait]
Expand Down Expand Up @@ -107,15 +101,6 @@ where
.unwrap_or(TxStatus::Pending))
}

async fn wait_until_mined(&self, tx_hash: H256) -> Result<Option<TransactionReceipt>> {
Ok(Self::wait_until_mined_no_drop(
tx_hash,
Arc::clone(&self.raw_provider),
self.poll_interval,
)
.await?)
}

fn address(&self) -> Address {
self.provider.address()
}
Expand All @@ -126,45 +111,12 @@ where
C: JsonRpcClient + 'static,
S: Signer + 'static,
{
pub(crate) fn new(
provider: Arc<Provider<C>>,
signer: S,
poll_interval: Duration,
auth_header: &str,
) -> Result<Self> {
pub(crate) fn new(provider: Arc<Provider<C>>, signer: S, auth_header: &str) -> Result<Self> {
Ok(Self {
provider: SignerMiddleware::new(Arc::clone(&provider), signer),
raw_provider: provider,
client: PolygonBloxrouteClient::new(auth_header)?,
poll_interval,
})
}

async fn wait_until_mined_no_drop(
tx_hash: H256,
provider: Arc<Provider<C>>,
poll_interval: Duration,
) -> Result<Option<TransactionReceipt>> {
loop {
let tx = provider
.get_transaction(tx_hash)
.await
.context("provider should return transaction status")?;

match tx.and_then(|tx| tx.block_number) {
None => {}
Some(_) => {
let receipt = provider
.get_transaction_receipt(tx_hash)
.await
.context("provider should return transaction receipt")?;
return Ok(receipt);
}
}

time::sleep(poll_interval).await;
}
}
}

struct PolygonBloxrouteClient {
Expand Down
140 changes: 3 additions & 137 deletions crates/builder/src/sender/flashbots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,16 @@

// Adapted from https://github.com/onbjerg/ethers-flashbots and
// https://github.com/gakonst/ethers-rs/blob/master/ethers-providers/src/toolbox/pending_transaction.rs
use std::{
future::Future,
pin::Pin,
str::FromStr,
sync::Arc,
task::{Context as TaskContext, Poll},
};
use std::{str::FromStr, sync::Arc};

use anyhow::{anyhow, Context};
use ethers::{
middleware::SignerMiddleware,
providers::{interval, JsonRpcClient, Middleware, Provider},
types::{
transaction::eip2718::TypedTransaction, Address, Bytes, TransactionReceipt, H256, U256, U64,
},
providers::{JsonRpcClient, Middleware, Provider},
types::{transaction::eip2718::TypedTransaction, Address, Bytes, H256, U256, U64},
utils,
};
use ethers_signers::Signer;
use futures_timer::Delay;
use futures_util::{Stream, StreamExt, TryFutureExt};
use pin_project::pin_project;
use reqwest::{
header::{HeaderMap, HeaderValue, CONTENT_TYPE},
Client, Response,
Expand Down Expand Up @@ -131,17 +120,6 @@ where
})
}

async fn wait_until_mined(&self, tx_hash: H256) -> Result<Option<TransactionReceipt>> {
Ok(
PendingFlashbotsTransaction::new(
tx_hash,
self.provider.inner(),
&self.flashbots_client,
)
.await?,
)
}

fn address(&self) -> Address {
self.provider.address()
}
Expand Down Expand Up @@ -384,118 +362,6 @@ where
}
}

type PinBoxFut<'a, T> = Pin<Box<dyn Future<Output = anyhow::Result<T>> + Send + 'a>>;

enum PendingFlashbotsTxState<'a> {
InitialDelay(Pin<Box<Delay>>),
PausedGettingTx,
GettingTx(PinBoxFut<'a, FlashbotsAPIResponse>),
PausedGettingReceipt,
GettingReceipt(PinBoxFut<'a, Option<TransactionReceipt>>),
Completed,
}

#[pin_project]
struct PendingFlashbotsTransaction<'a, P, S> {
tx_hash: H256,
provider: &'a Provider<P>,
client: &'a FlashbotsClient<S>,
state: PendingFlashbotsTxState<'a>,
interval: Box<dyn Stream<Item = ()> + Send + Unpin>,
}

impl<'a, P: JsonRpcClient, S> PendingFlashbotsTransaction<'a, P, S> {
fn new(tx_hash: H256, provider: &'a Provider<P>, client: &'a FlashbotsClient<S>) -> Self {
let delay = Box::pin(Delay::new(provider.get_interval()));

Self {
tx_hash,
provider,
client,
state: PendingFlashbotsTxState::InitialDelay(delay),
interval: Box::new(interval(provider.get_interval())),
}
}
}

impl<'a, P: JsonRpcClient, S: Send + Sync> Future for PendingFlashbotsTransaction<'a, P, S> {
type Output = anyhow::Result<Option<TransactionReceipt>>;

fn poll(self: Pin<&mut Self>, ctx: &mut TaskContext<'_>) -> Poll<Self::Output> {
let this = self.project();

match this.state {
PendingFlashbotsTxState::InitialDelay(fut) => {
futures_util::ready!(fut.as_mut().poll(ctx));
let status_fut = Box::pin(this.client.status(*this.tx_hash));
*this.state = PendingFlashbotsTxState::GettingTx(status_fut);
ctx.waker().wake_by_ref();
return Poll::Pending;
}
PendingFlashbotsTxState::PausedGettingTx => {
let _ready = futures_util::ready!(this.interval.poll_next_unpin(ctx));
let status_fut = Box::pin(this.client.status(*this.tx_hash));
*this.state = PendingFlashbotsTxState::GettingTx(status_fut);
ctx.waker().wake_by_ref();
return Poll::Pending;
}
PendingFlashbotsTxState::GettingTx(fut) => {
let status = futures_util::ready!(fut.as_mut().poll(ctx))?;
tracing::debug!("Transaction:status {:?}:{:?}", *this.tx_hash, status.status);
match status.status {
FlashbotsAPITransactionStatus::Pending => {
*this.state = PendingFlashbotsTxState::PausedGettingTx;
ctx.waker().wake_by_ref();
}
FlashbotsAPITransactionStatus::Included => {
let receipt_fut = Box::pin(
this.provider
.get_transaction_receipt(*this.tx_hash)
.map_err(|e| anyhow::anyhow!("failed to get receipt: {:?}", e)),
);
*this.state = PendingFlashbotsTxState::GettingReceipt(receipt_fut);
ctx.waker().wake_by_ref();
}
FlashbotsAPITransactionStatus::Cancelled => {
return Poll::Ready(Ok(None));
}
FlashbotsAPITransactionStatus::Failed
| FlashbotsAPITransactionStatus::Unknown => {
return Poll::Ready(Err(anyhow::anyhow!(
"transaction failed with status {:?}",
status.status
)));
}
}
}
PendingFlashbotsTxState::PausedGettingReceipt => {
let _ready = futures_util::ready!(this.interval.poll_next_unpin(ctx));
let fut = Box::pin(
this.provider
.get_transaction_receipt(*this.tx_hash)
.map_err(|e| anyhow::anyhow!("failed to get receipt: {:?}", e)),
);
*this.state = PendingFlashbotsTxState::GettingReceipt(fut);
ctx.waker().wake_by_ref();
}
PendingFlashbotsTxState::GettingReceipt(fut) => {
if let Some(receipt) = futures_util::ready!(fut.as_mut().poll(ctx))? {
*this.state = PendingFlashbotsTxState::Completed;
return Poll::Ready(Ok(Some(receipt)));
} else {
*this.state = PendingFlashbotsTxState::PausedGettingReceipt;
ctx.waker().wake_by_ref();
}
}
PendingFlashbotsTxState::Completed => {
panic!("polled pending flashbots transaction future after completion")
}
}

Poll::Pending
}
}

fn deserialize_u64<'de, D>(deserializer: D) -> std::result::Result<U64, D::Error>
where
D: de::Deserializer<'de>,
Expand Down
20 changes: 6 additions & 14 deletions crates/builder/src/sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
mod bloxroute;
mod flashbots;
mod raw;
use std::{sync::Arc, time::Duration};
use std::sync::Arc;

use anyhow::Context;
use async_trait::async_trait;
Expand All @@ -24,8 +24,8 @@ use ethers::{
prelude::SignerMiddleware,
providers::{JsonRpcClient, Middleware, Provider, ProviderError},
types::{
transaction::eip2718::TypedTransaction, Address, Bytes, Eip1559TransactionRequest,
TransactionReceipt, H256, U256,
transaction::eip2718::TypedTransaction, Address, Bytes, Eip1559TransactionRequest, H256,
U256,
},
};
use ethers_signers::{LocalWallet, Signer};
Expand Down Expand Up @@ -99,8 +99,6 @@ pub(crate) trait TransactionSender: Send + Sync + 'static {

async fn get_transaction_status(&self, tx_hash: H256) -> Result<TxStatus>;

async fn wait_until_mined(&self, tx_hash: H256) -> Result<Option<TransactionReceipt>>;

fn address(&self) -> Address;
}

Expand Down Expand Up @@ -178,7 +176,6 @@ impl TransactionSenderArgs {
rpc_provider: Arc<Provider<C>>,
submit_provider: Option<Arc<Provider<C>>>,
signer: S,
eth_poll_interval: Duration,
) -> std::result::Result<TransactionSenderEnum<C, S, LocalWallet>, SenderConstructorErrors>
{
let sender = match self {
Expand Down Expand Up @@ -213,14 +210,9 @@ impl TransactionSenderArgs {
args.status_url,
)?)
}
Self::Bloxroute(args) => {
TransactionSenderEnum::PolygonBloxroute(PolygonBloxrouteTransactionSender::new(
rpc_provider,
signer,
eth_poll_interval,
&args.header,
)?)
}
Self::Bloxroute(args) => TransactionSenderEnum::PolygonBloxroute(
PolygonBloxrouteTransactionSender::new(rpc_provider, signer, &args.header)?,
),
};
Ok(sender)
}
Expand Down
Loading

0 comments on commit 355a108

Please sign in to comment.