Skip to content

Commit

Permalink
move manager construction to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarreif committed Nov 4, 2024
1 parent 9defec5 commit 22baca2
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 95 deletions.
23 changes: 19 additions & 4 deletions crates/astria-auctioneer/src/auction/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use tokio_util::{
task::JoinMap,
};
use tonic::transport::Endpoint;
use tracing::instrument;
use tracing::{
info,
instrument,
};

use super::{
Bundle,
Expand All @@ -38,13 +41,15 @@ pub(crate) struct Builder {
/// The amount of time to run the auction timer for.
pub(crate) latency_margin: std::time::Duration,
/// The private key used to sign sequencer transactions.
pub(crate) sequencer_key: SequencerKey,
pub(crate) sequencer_private_key_path: String,
/// The prefix for the address used to sign sequencer transactions
pub(crate) sequencer_address_prefix: String,
/// The denomination of the fee asset used in the sequencer transactions
pub(crate) fee_asset_denomination: asset::Denom,
/// The chain ID for sequencer transactions
pub(crate) sequencer_chain_id: String,
/// The rollup ID for the `RollupDataSubmission`s with auction results
pub(crate) rollup_id: RollupId,
pub(crate) rollup_id: String,
}

impl Builder {
Expand All @@ -57,10 +62,18 @@ impl Builder {
latency_margin,
fee_asset_denomination,
rollup_id,
sequencer_key,
sequencer_private_key_path,
sequencer_address_prefix,
sequencer_chain_id,
} = self;

let sequencer_key = SequencerKey::builder()
.path(sequencer_private_key_path)
.prefix(sequencer_address_prefix)
.try_build()
.wrap_err("failed to load sequencer private key")?;
info!(address = %sequencer_key.address(), "loaded sequencer signer");

let sequencer_grpc_uri: tonic::transport::Uri = sequencer_grpc_endpoint
.parse()
.wrap_err("failed to parse sequencer grpc endpoint as URI")?;
Expand All @@ -71,6 +84,8 @@ impl Builder {
sequencer_client::HttpClient::new(sequencer_abci_endpoint.as_str())
.wrap_err("failed constructing sequencer abci client")?;

let rollup_id = RollupId::from_unhashed_bytes(&rollup_id);

Ok(Manager {
metrics,
shutdown_token,
Expand Down
21 changes: 16 additions & 5 deletions crates/astria-auctioneer/src/auctioneer/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use tracing::{
};

use crate::{
auction,
flatten_result,
optimistic_executor,
Config,
Expand Down Expand Up @@ -60,21 +61,31 @@ impl Auctioneer {

let mut tasks = JoinMap::new();

let optimistic_executor = optimistic_executor::Builder {
let auctions = auction::manager::Builder {
metrics,
shutdown_token: shutdown_token.clone(),
sequencer_grpc_endpoint,
sequencer_grpc_endpoint: sequencer_grpc_endpoint.clone(),
sequencer_abci_endpoint,
rollup_id,
rollup_grpc_endpoint,
latency_margin: Duration::from_millis(latency_margin_ms),
sequencer_private_key_path,
sequencer_address_prefix,
fee_asset_denomination,
sequencer_chain_id,
rollup_id: rollup_id.clone(),
}
.build()
.wrap_err("failed to initialize the optimistic executor")?;
.wrap_err("failed to initialize auction manager")?;

let optimistic_executor = optimistic_executor::Builder {
metrics,
shutdown_token: shutdown_token.clone(),
sequencer_grpc_endpoint,
rollup_id,
rollup_grpc_endpoint,
auctions,
}
.build();

tasks.spawn(Self::OPTIMISTIC_EXECUTOR, async {
optimistic_executor
.startup()
Expand Down
15 changes: 6 additions & 9 deletions crates/astria-auctioneer/src/optimistic_block_client.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use std::time::Duration;

use astria_core::{
generated::{
primitive::v1::Address,
sequencerblock::optimisticblock::v1alpha1::{
optimistic_block_service_client::OptimisticBlockServiceClient,
GetBlockCommitmentStreamRequest,
GetBlockCommitmentStreamResponse,
GetOptimisticBlockStreamRequest,
GetOptimisticBlockStreamResponse,
},
generated::sequencerblock::optimisticblock::v1alpha1::{
optimistic_block_service_client::OptimisticBlockServiceClient,
GetBlockCommitmentStreamRequest,
GetBlockCommitmentStreamResponse,
GetOptimisticBlockStreamRequest,
GetOptimisticBlockStreamResponse,
},
primitive::v1::RollupId,
};
Expand Down
13 changes: 6 additions & 7 deletions crates/astria-auctioneer/src/optimistic_execution_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::time::Duration;
use astria_core::{
generated::bundle::v1alpha1::{
optimistic_execution_service_client::OptimisticExecutionServiceClient,
ExecuteOptimisticBlockStreamRequest,
ExecuteOptimisticBlockStreamResponse,
},
primitive::v1::RollupId,
Expand All @@ -12,18 +11,14 @@ use astria_eyre::eyre::{
self,
Context,
};
use futures::Stream;
use tokio::sync::mpsc;
use tokio_stream::{
wrappers::ReceiverStream,
StreamExt as _,
};
use tonic::transport::{
Channel,
Endpoint,
Uri,
};
use tracing::{
instrument,
warn,
Instrument,
Span,
Expand All @@ -33,7 +28,6 @@ use tryhard::backoff_strategies::ExponentialBackoff;
use crate::block::{
self,
executed_stream::make_execution_requests_stream,
Optimistic,
};

pub(crate) struct OptimisticExecutionClient {
Expand All @@ -57,6 +51,11 @@ impl OptimisticExecutionClient {
})
}

#[instrument(skip_all, fields(
uri = %self.uri,
%rollup_id,
err,
))]
pub(crate) async fn execute_optimistic_block_stream(
&mut self,
rollup_id: RollupId,
Expand Down
53 changes: 9 additions & 44 deletions crates/astria-auctioneer/src/optimistic_executor/builder.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
use std::time::Duration;

use astria_core::primitive::v1::{
asset,
RollupId,
};
use astria_eyre::{
eyre,
eyre::WrapErr as _,
};
use astria_core::primitive::v1::RollupId;
use tokio_util::sync::CancellationToken;
use tracing::info;

use super::Startup;
use crate::{
sequencer_key::SequencerKey,
auction,
Metrics,
};

Expand All @@ -22,61 +12,36 @@ pub(crate) struct Builder {
pub(crate) shutdown_token: CancellationToken,
/// The endpoint for the sequencer gRPC service used for the optimistic block stream
pub(crate) sequencer_grpc_endpoint: String,
/// The endpoint for the sequencer ABCI service used to submit the auction winner transaction
pub(crate) sequencer_abci_endpoint: String,
/// The file path for the private key used to sign sequencer transactions with the auction
/// results
pub(crate) sequencer_private_key_path: String,
/// The prefix for the address used to sign sequencer transactions
pub(crate) sequencer_address_prefix: String,
/// The denomination of the fee asset used in the sequencer transactions
pub(crate) fee_asset_denomination: asset::Denom,
/// The chain ID for sequencer transactions
pub(crate) sequencer_chain_id: String,
/// The rollup ID for the filtered optimistic block stream
pub(crate) rollup_id: String,
/// The endpoint for the rollup's optimistic execution gRPC service
pub(crate) rollup_grpc_endpoint: String,
/// The amount of time to wait after a commit before closing the auction
pub(crate) latency_margin: Duration,
/// Manager for ongoing auctions
pub(crate) auctions: auction::Manager,
}

impl Builder {
pub(crate) fn build(self) -> eyre::Result<Startup> {
pub(crate) fn build(self) -> Startup {
let Self {
metrics,
shutdown_token,
sequencer_grpc_endpoint,
sequencer_abci_endpoint,
rollup_id,
rollup_grpc_endpoint,
latency_margin,
sequencer_private_key_path,
sequencer_address_prefix,
fee_asset_denomination,
sequencer_chain_id,
auctions,
} = self;

let sequencer_key = SequencerKey::builder()
.path(sequencer_private_key_path)
.prefix(sequencer_address_prefix)
.try_build()
.wrap_err("failed to load sequencer private key")?;
info!(address = %sequencer_key.address(), "loaded sequencer signer");

let rollup_id = RollupId::from_unhashed_bytes(&rollup_id);

Ok(Startup {
Startup {
metrics,
shutdown_token,
sequencer_grpc_endpoint,
sequencer_abci_endpoint,
rollup_id,
rollup_grpc_endpoint,
latency_margin,
sequencer_key,
fee_asset_denomination,
sequencer_chain_id,
})
auctions,
}
}
}
28 changes: 2 additions & 26 deletions crates/astria-auctioneer/src/optimistic_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,16 @@ use crate::{
BundleStream,
},
optimistic_block_client::OptimisticBlockClient,
sequencer_key::SequencerKey,
};

pub(crate) struct Startup {
#[allow(dead_code)]
metrics: &'static crate::Metrics,
shutdown_token: CancellationToken,
sequencer_grpc_endpoint: String,
sequencer_abci_endpoint: String,
sequencer_key: SequencerKey,
fee_asset_denomination: asset::Denom,
sequencer_chain_id: String,
rollup_id: RollupId,
rollup_grpc_endpoint: String,
latency_margin: Duration,
auctions: auction::Manager,
}

impl Startup {
Expand All @@ -58,13 +53,9 @@ impl Startup {
metrics,
shutdown_token,
sequencer_grpc_endpoint,
sequencer_abci_endpoint,
rollup_id,
rollup_grpc_endpoint,
latency_margin,
sequencer_key,
fee_asset_denomination,
sequencer_chain_id,
auctions,
} = self;

let sequencer_client = OptimisticBlockClient::new(&sequencer_grpc_endpoint)
Expand All @@ -90,21 +81,6 @@ impl Startup {
// let bundle_stream = BundleServiceClient::new(bundle_service_grpc_url)
// .wrap_err("failed to initialize bundle service grpc client")?;

// TODO: should i construct this in `Auctioneer::new()` instead of here?
let auctions = auction::manager::Builder {
metrics,
shutdown_token: shutdown_token.clone(),
sequencer_grpc_endpoint,
sequencer_abci_endpoint,
latency_margin,
sequencer_key,
fee_asset_denomination: fee_asset_denomination.clone(),
sequencer_chain_id,
rollup_id,
}
.build()
.wrap_err("failed to initialize auction manager")?;

let optimistic_block = optimistic_blocks
.next()
.await
Expand Down

0 comments on commit 22baca2

Please sign in to comment.