Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(block-producer): instrument mempool #578

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/block-producer/src/batch_builder/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use miden_objects::{
};
use tracing::instrument;

use crate::errors::BuildBatchError;
use crate::{errors::BuildBatchError, COMPONENT};

// BATCH ID
// ================================================================================================
Expand Down Expand Up @@ -114,7 +114,7 @@ impl TransactionBatch {
/// - There are duplicated output notes or unauthenticated notes found across all transactions
/// in the batch.
/// - Hashes for corresponding input notes and output notes don't match.
#[instrument(target = "miden-block-producer", name = "new_batch", skip_all, err)]
#[instrument(target = COMPONENT, name = "new_batch", skip_all, err)]
pub fn new<'a, I>(
txs: impl IntoIterator<Item = &'a ProvenTransaction, IntoIter = I>,
found_unauthenticated_notes: NoteAuthenticationInfo,
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/batch_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl WorkerPool {
Ok(())
}

#[instrument(target = "miden-block-producer", skip_all, err, fields(batch_id))]
#[instrument(target = COMPONENT, skip_all, err, fields(batch_id))]
fn build_batch(
txs: Vec<AuthenticatedTransaction>,
) -> Result<TransactionBatch, BuildBatchError> {
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/block_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl BlockBuilder {
}
}

#[instrument(target = "miden-block-producer", skip_all, err)]
#[instrument(target = COMPONENT, skip_all, err)]
async fn build_block(&self, batches: &[TransactionBatch]) -> Result<(), BuildBlockError> {
info!(
target: COMPONENT,
Expand Down
10 changes: 9 additions & 1 deletion crates/block-producer/src/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use miden_objects::{
MAX_ACCOUNTS_PER_BATCH, MAX_INPUT_NOTES_PER_BATCH, MAX_OUTPUT_NOTES_PER_BATCH,
};
use tokio::sync::Mutex;
use tracing::instrument;
use transaction_graph::TransactionGraph;

use crate::{
batch_builder::batch::{BatchId, TransactionBatch},
domain::transaction::AuthenticatedTransaction,
errors::AddTransactionError,
SERVER_MAX_BATCHES_PER_BLOCK, SERVER_MAX_TXS_PER_BATCH,
COMPONENT, SERVER_MAX_BATCHES_PER_BLOCK, SERVER_MAX_TXS_PER_BATCH,
};

mod batch_graph;
Expand Down Expand Up @@ -215,6 +216,7 @@ impl Mempool {
/// # Errors
///
/// Returns an error if the transaction's initial conditions don't match the current state.
#[instrument(target = COMPONENT, skip_all, fields(tx=%transaction.id()))]
pub fn add_transaction(
&mut self,
transaction: AuthenticatedTransaction,
Expand All @@ -234,6 +236,7 @@ impl Mempool {
/// Transactions are returned in a valid execution ordering.
///
/// Returns `None` if no transactions are available.
#[instrument(target = COMPONENT, skip_all)]
pub fn select_batch(&mut self) -> Option<(BatchId, Vec<AuthenticatedTransaction>)> {
let (batch, parents) = self.transactions.select_batch(self.batch_budget);
if batch.is_empty() {
Expand All @@ -249,6 +252,7 @@ impl Mempool {
/// Drops the failed batch and all of its descendants.
///
/// Transactions are placed back in the queue.
#[instrument(target = COMPONENT, skip_all, fields(batch))]
pub fn batch_failed(&mut self, batch: BatchId) {
// Batch may already have been removed as part of a parent batches failure.
if !self.batches.contains(&batch) {
Expand All @@ -272,6 +276,7 @@ impl Mempool {
}

/// Marks a batch as proven if it exists.
#[instrument(target = COMPONENT, skip_all, fields(batch=%batch.id()))]
pub fn batch_proved(&mut self, batch: TransactionBatch) {
// Batch may have been removed as part of a parent batches failure.
if !self.batches.contains(&batch.id()) {
Expand All @@ -290,6 +295,7 @@ impl Mempool {
/// # Panics
///
/// Panics if there is already a block in flight.
#[instrument(target = COMPONENT, skip_all)]
pub fn select_block(&mut self) -> (BlockNumber, Vec<TransactionBatch>) {
assert!(self.block_in_progress.is_none(), "Cannot have two blocks inflight.");

Expand All @@ -304,6 +310,7 @@ impl Mempool {
/// # Panics
///
/// Panics if blocks are completed out-of-order or if there is no block in flight.
#[instrument(target = COMPONENT, skip_all, fields(block_number))]
pub fn block_committed(&mut self, block_number: BlockNumber) {
assert_eq!(block_number, self.chain_tip.next(), "Blocks must be submitted sequentially");

Expand All @@ -326,6 +333,7 @@ impl Mempool {
///
/// Panics if there is no block in flight or if the block number does not match the current
/// inflight block.
#[instrument(target = COMPONENT, skip_all, fields(block_number))]
pub fn block_failed(&mut self, block_number: BlockNumber) {
assert_eq!(block_number, self.chain_tip.next(), "Blocks must be submitted sequentially");

Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/server/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
BB: BatchBuilder,
{
#[instrument(
target = "miden-block-producer",
target = COMPONENT,
name = "block_producer:submit_proven_transaction",
skip_all,
err
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl BlockProducerRpcServer {
}

#[instrument(
target = "miden-block-producer",
target = COMPONENT,
name = "block_producer:submit_proven_transaction",
skip_all,
err
Expand Down
6 changes: 3 additions & 3 deletions crates/block-producer/src/state_view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<S> ApplyBlock for DefaultStateView<S>
where
S: Store,
{
#[instrument(target = "miden-block-producer", skip_all, err)]
#[instrument(target = COMPONENT, skip_all, err)]
async fn apply_block(&self, block: &Block) -> Result<(), ApplyBlockError> {
self.store.apply_block(block).await?;

Expand Down Expand Up @@ -179,7 +179,7 @@ where
/// - all notes in `tx_notes_not_in_store` are currently in flight
///
/// The account state is not verified as it is performed by [InflightAccountStates].
#[instrument(target = "miden-block-producer", skip_all, err)]
#[instrument(target = COMPONENT, skip_all, err)]
fn ensure_in_flight_constraints(
candidate_tx: &ProvenTransaction,
accounts_in_flight: &InflightAccountStates,
Expand Down Expand Up @@ -225,7 +225,7 @@ fn ensure_in_flight_constraints(
/// - input notes must not be already consumed
///
/// Returns a list of unauthenticated input notes that were not found in the store.
#[instrument(target = "miden-block-producer", skip_all, err)]
#[instrument(target = COMPONENT, skip_all, err)]
fn ensure_tx_inputs_constraints(
candidate_tx: &ProvenTransaction,
tx_inputs: TransactionInputs,
Expand Down
8 changes: 4 additions & 4 deletions crates/block-producer/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl StoreClient {
}

/// Returns the latest block's header from the store.
#[instrument(target = "miden-block-producer", skip_all, err)]
#[instrument(target = COMPONENT, skip_all, err)]
pub async fn latest_header(&self) -> Result<BlockHeader, StoreError> {
let response = self
.inner
Expand All @@ -146,7 +146,7 @@ impl StoreClient {
BlockHeader::try_from(response).map_err(Into::into)
}

#[instrument(target = "miden-block-producer", skip_all, err)]
#[instrument(target = COMPONENT, skip_all, err)]
pub async fn get_tx_inputs(
&self,
proven_tx: &ProvenTransaction,
Expand Down Expand Up @@ -183,7 +183,7 @@ impl StoreClient {
Ok(tx_inputs)
}

#[instrument(target = "miden-block-producer", skip_all, err)]
#[instrument(target = COMPONENT, skip_all, err)]
pub async fn get_block_inputs(
&self,
updated_accounts: impl Iterator<Item = AccountId> + Send,
Expand All @@ -201,7 +201,7 @@ impl StoreClient {
store_response.try_into().map_err(Into::into)
}

#[instrument(target = "miden-block-producer", skip_all, err)]
#[instrument(target = COMPONENT, skip_all, err)]
pub async fn apply_block(&self, block: &Block) -> Result<(), StoreError> {
let request = tonic::Request::new(ApplyBlockRequest { block: block.to_bytes() });

Expand Down
22 changes: 11 additions & 11 deletions crates/rpc/src/server/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl RpcApi {
#[tonic::async_trait]
impl api_server::Api for RpcApi {
#[instrument(
target = "miden-rpc",
target = COMPONENT,
name = "rpc:check_nullifiers",
skip_all,
ret(level = "debug"),
Expand All @@ -82,7 +82,7 @@ impl api_server::Api for RpcApi {
}

#[instrument(
target = "miden-rpc",
target = COMPONENT,
name = "rpc:check_nullifiers_by_prefix",
skip_all,
ret(level = "debug"),
Expand All @@ -98,7 +98,7 @@ impl api_server::Api for RpcApi {
}

#[instrument(
target = "miden-rpc",
target = COMPONENT,
name = "rpc:get_block_header_by_number",
skip_all,
ret(level = "debug"),
Expand All @@ -114,7 +114,7 @@ impl api_server::Api for RpcApi {
}

#[instrument(
target = "miden-rpc",
target = COMPONENT,
name = "rpc:sync_state",
skip_all,
ret(level = "debug"),
Expand All @@ -130,7 +130,7 @@ impl api_server::Api for RpcApi {
}

#[instrument(
target = "miden-rpc",
target = COMPONENT,
name = "rpc:sync_notes",
skip_all,
ret(level = "debug"),
Expand All @@ -146,7 +146,7 @@ impl api_server::Api for RpcApi {
}

#[instrument(
target = "miden-rpc",
target = COMPONENT,
name = "rpc:get_notes_by_id",
skip_all,
ret(level = "debug"),
Expand All @@ -167,7 +167,7 @@ impl api_server::Api for RpcApi {
self.store.clone().get_notes_by_id(request).await
}

#[instrument(target = "miden-rpc", name = "rpc:submit_proven_transaction", skip_all, err)]
#[instrument(target = COMPONENT, name = "rpc:submit_proven_transaction", skip_all, err)]
async fn submit_proven_transaction(
&self,
request: Request<SubmitProvenTransactionRequest>,
Expand All @@ -190,7 +190,7 @@ impl api_server::Api for RpcApi {

/// Returns details for public (public) account by id.
#[instrument(
target = "miden-rpc",
target = COMPONENT,
name = "rpc:get_account_details",
skip_all,
ret(level = "debug"),
Expand All @@ -214,7 +214,7 @@ impl api_server::Api for RpcApi {
}

#[instrument(
target = "miden-rpc",
target = COMPONENT,
name = "rpc:get_block_by_number",
skip_all,
ret(level = "debug"),
Expand All @@ -232,7 +232,7 @@ impl api_server::Api for RpcApi {
}

#[instrument(
target = "miden-rpc",
target = COMPONENT,
name = "rpc:get_account_state_delta",
skip_all,
ret(level = "debug"),
Expand All @@ -250,7 +250,7 @@ impl api_server::Api for RpcApi {
}

#[instrument(
target = "miden-rpc",
target = COMPONENT,
name = "rpc:get_account_proofs",
skip_all,
ret(level = "debug"),
Expand Down
2 changes: 1 addition & 1 deletion crates/store/src/db/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn up(s: &'static str) -> M<'static> {
const DB_MIGRATION_HASH_FIELD: &str = "db-migration-hash";
const DB_SCHEMA_VERSION_FIELD: &str = "db-schema-version";

#[instrument(target = "miden-store", skip_all, err)]
#[instrument(target = COMPONENT, skip_all, err)]
pub fn apply_migrations(conn: &mut Connection) -> super::Result<()> {
let version_before = MIGRATIONS.current_version(conn)?;

Expand Down
Loading
Loading