Skip to content

Commit

Permalink
clean up manager
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarreif committed Nov 4, 2024
1 parent 1baddf2 commit 25e1572
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 16 deletions.
19 changes: 17 additions & 2 deletions crates/astria-auctioneer/src/auction/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::time::Duration;

use astria_core::generated::bundle::v1alpha1::GetBundleStreamResponse;
use astria_eyre::eyre;
use astria_core::primitive::v1::{
asset,
RollupId,
};
use tokio::sync::{
mpsc,
oneshot,
Expand All @@ -12,6 +14,7 @@ use super::{
Auction,
Handle,
Id,
SequencerKey,
};
use crate::Metrics;

Expand All @@ -28,6 +31,12 @@ pub(crate) struct Builder {
pub(crate) latency_margin: Duration,
/// The ID of the auction to be run
pub(crate) auction_id: Id,
/// The key used to sign sequencer transactions
pub(crate) sequencer_key: SequencerKey,
/// The denomination of the fee asset used in the sequencer transactions
pub(crate) fee_asset_denomination: asset::Denom,
/// The rollup ID used for `RollupDataSubmission` with the auction result
pub(crate) rollup_id: RollupId,
}

impl Builder {
Expand All @@ -39,6 +48,9 @@ impl Builder {
sequencer_abci_endpoint,
latency_margin,
auction_id,
fee_asset_denomination,
rollup_id,
sequencer_key,
} = self;

let (executed_block_tx, executed_block_rx) = oneshot::channel();
Expand All @@ -58,6 +70,9 @@ impl Builder {
new_bundles_rx,
auction_id,
latency_margin,
sequencer_key,
fee_asset_denomination,
rollup_id,
};

(
Expand Down
44 changes: 39 additions & 5 deletions crates/astria-auctioneer/src/auction/manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use std::collections::HashMap;

use astria_core::generated::bundle::v1alpha1::Bundle;
use astria_core::{
generated::bundle::v1alpha1::Bundle,
primitive::v1::{
asset,
RollupId,
},
};
use astria_eyre::eyre::{
self,
OptionExt as _,
Expand All @@ -15,36 +21,57 @@ use tracing::instrument;
use super::{
Handle,
Id,
SequencerKey,
};
use crate::flatten_result;

pub(crate) struct Builder {
pub(crate) metrics: &'static crate::Metrics,
pub(crate) shutdown_token: CancellationToken,

/// The gRPC endpoint for the sequencer service used by auctions.
pub(crate) sequencer_grpc_endpoint: String,
/// The ABCI endpoint for the sequencer service used by auctions.
pub(crate) sequencer_abci_endpoint: String,
/// 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,
/// 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,
}

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

Manager {
Ok(Manager {
metrics,
shutdown_token,
sequencer_grpc_endpoint,
sequencer_abci_endpoint,
latency_margin,
running_auctions: JoinMap::new(),
auction_handles: HashMap::new(),
}
sequencer_key,
fee_asset_denomination,
sequencer_chain_id,
rollup_id,
})
}
}

Expand All @@ -57,6 +84,10 @@ pub(crate) struct Manager {
running_auctions: JoinMap<Id, eyre::Result<()>>,
auction_handles: HashMap<Id, Handle>,
// TODO: hold the bundle stream here?
sequencer_key: SequencerKey,
fee_asset_denomination: asset::Denom,
sequencer_chain_id: String,
rollup_id: RollupId,
}

impl Manager {
Expand All @@ -69,6 +100,9 @@ impl Manager {
sequencer_abci_endpoint: self.sequencer_abci_endpoint.clone(),
latency_margin: self.latency_margin,
auction_id,
sequencer_key: self.sequencer_key.clone(),
fee_asset_denomination: self.fee_asset_denomination.clone(),
rollup_id: self.rollup_id,
}
.build();

Expand Down Expand Up @@ -104,7 +138,7 @@ impl Manager {
.wrap_err("failed to start processing bids")
}

pub(crate) fn try_send_bundle(&mut self, _bundle: Bundle) -> eyre::Result<()> {
pub(crate) fn try_send_bundle(&mut self, _auction_id: Id, _bundle: Bundle) -> eyre::Result<()> {
unimplemented!()
// try to get the handle for the appropriate auction
// try send into that auction
Expand Down
4 changes: 2 additions & 2 deletions crates/astria-auctioneer/src/auction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct Auction {
/// The key used to sign transactions on the sequencer
sequencer_key: SequencerKey,
/// Fee asset for submitting transactions
fee_asset: asset::Denom,
fee_asset_denomination: asset::Denom,
/// Rollup ID to submit the auction result to
rollup_id: RollupId,
}
Expand Down Expand Up @@ -201,7 +201,7 @@ impl Auction {
let transaction_body = auction_result
.wrap_err("")?
.ok_or_eyre("auction ended with no winning bid")?
.into_transaction_body(nonce, self.rollup_id, self.fee_asset.clone());
.into_transaction_body(nonce, self.rollup_id, self.fee_asset_denomination.clone());

let transaction = transaction_body.sign(self.sequencer_key.signing_key());

Expand Down
8 changes: 8 additions & 0 deletions crates/astria-auctioneer/src/auctioneer/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl Auctioneer {
latency_margin_ms,
rollup_grpc_endpoint,
rollup_id,
sequencer_chain_id,
sequencer_private_key_path,
sequencer_address_prefix,
fee_asset_denomination,
..
} = cfg;

Expand All @@ -64,6 +68,10 @@ impl Auctioneer {
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,
}
.build()
.wrap_err("failed to initialize the optimistic executor")?;
Expand Down
4 changes: 2 additions & 2 deletions crates/astria-auctioneer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ pub struct Config {
/// The file path for the private key used to sign sequencer transactions with the auction
/// results
pub sequencer_private_key_path: String,
// The fee asset denomination to use for the sequnecer transactions.
pub fee_asset_denomination: asset::Denom,
// The address prefix to use when constructing sequencer addresses using the signing key.
pub sequencer_address_prefix: String,
// The fee asset denomination to use for the sequnecer transactions.
pub fee_asset_denomination: asset::Denom,
/// The endpoint for the rollup gRPC service used for the optimistic execution and bundle
/// streams
pub rollup_grpc_endpoint: String,
Expand Down
39 changes: 36 additions & 3 deletions crates/astria-auctioneer/src/optimistic_executor/builder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
use std::time::Duration;

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

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

pub(crate) struct Builder {
pub(crate) metrics: &'static Metrics,
Expand All @@ -14,6 +24,15 @@ pub(crate) struct Builder {
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
Expand All @@ -32,8 +51,19 @@ impl Builder {
rollup_id,
rollup_grpc_endpoint,
latency_margin,
sequencer_private_key_path,
sequencer_address_prefix,
fee_asset_denomination,
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 rollup_id = RollupId::from_unhashed_bytes(&rollup_id);

Ok(Startup {
Expand All @@ -44,6 +74,9 @@ impl Builder {
rollup_id,
rollup_grpc_endpoint,
latency_margin,
sequencer_key,
fee_asset_denomination,
sequencer_chain_id,
})
}
}
20 changes: 18 additions & 2 deletions crates/astria-auctioneer/src/optimistic_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ mod builder;

use std::time::Duration;

use astria_core::primitive::v1::RollupId;
use astria_core::primitive::v1::{
asset,
RollupId,
};
use astria_eyre::eyre::{
self,
OptionExt,
Expand All @@ -28,6 +31,7 @@ use crate::{
optimistic_stream::OptimisticBlockStream,
},
sequencer_grpc_client::SequencerGrpcClient,
sequencer_key::SequencerKey,
};

pub(crate) struct Startup {
Expand All @@ -36,6 +40,9 @@ pub(crate) struct Startup {
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,
Expand All @@ -51,6 +58,9 @@ impl Startup {
rollup_id,
rollup_grpc_endpoint,
latency_margin,
sequencer_key,
fee_asset_denomination,
sequencer_chain_id,
} = self;

let sequencer_client = SequencerGrpcClient::new(&sequencer_grpc_endpoint)
Expand All @@ -73,14 +83,20 @@ 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();
.build()
.wrap_err("failed to initialize auction manager")?;

let optimistic_block = optimistic_blocks
.next()
Expand Down
1 change: 1 addition & 0 deletions crates/astria-auctioneer/src/sequencer_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use astria_eyre::eyre::{
Context,
};

#[derive(Clone)]
pub(crate) struct SequencerKey {
address: Address,
signing_key: SigningKey,
Expand Down

0 comments on commit 25e1572

Please sign in to comment.