Skip to content
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
11 changes: 11 additions & 0 deletions magicblock-aperture/src/requests/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ impl HttpDispatcher {
)
}

fn simulate_transaction_context(
signature: Signature,
remote_account_claims: Arc<AtomicU64>,
) -> AccountFetchContext {
AccountFetchContext::new_with_claims_counter(
AccountFetchEntrypoint::SimulateTransaction(signature),
AccountFetchReason::RequestedAccount,
remote_account_claims,
)
}

/// Fetches an account's data from the `AccountsDb` filling it in from chain
/// as needed.
#[instrument(skip_all)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl HttpDispatcher {
.inspect_err(|err| {
debug!(error = ?err, "Failed to prepare transaction to simulate")
})?;
let fetch_context = Self::send_transaction_context(
let fetch_context = Self::simulate_transaction_context(
*transaction.txn.signature(),
remote_account_claims.clone(),
);
Expand Down
27 changes: 27 additions & 0 deletions magicblock-metrics/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,9 @@ mod fetch_context_metric_tests {
);
let undelegating_context = AccountFetchContext::rpc_get_account()
.with_reason(AccountFetchReason::UndelegatingRefresh);
let simulation_context = AccountFetchContext::simulate_transaction(
solana_signature::Signature::from([1u8; 64]),
);

let action_labels = &[
"rpc_get_account",
Expand Down Expand Up @@ -1725,5 +1728,29 @@ mod fetch_context_metric_tests {
),
before_undelegating + 1
);

let simulation_labels = &[
"simulate_transaction",
"requested_account",
"fetch_cloner",
"owned",
];
let before_simulation = counter_value(
&CHAINLINK_PENDING_FETCH_ACCOUNTS_TOTAL,
simulation_labels,
);
inc_chainlink_pending_fetch_accounts_with_context(
simulation_context,
ChainlinkPendingFetchLayer::FetchCloner,
ChainlinkPendingFetchOutcome::Owned,
1,
);
assert_eq!(
counter_value(
&CHAINLINK_PENDING_FETCH_ACCOUNTS_TOTAL,
simulation_labels,
),
before_simulation + 1
);
}
}
39 changes: 35 additions & 4 deletions magicblock-metrics/src/metrics/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub enum AccountFetchEntrypoint {
RpcGetAccount,
RpcGetMultipleAccounts,
SendTransaction(Signature),
SimulateTransaction(Signature),
Comment thread
GabrielePicco marked this conversation as resolved.
SubscriptionUpdate,
ProjectAta,
Internal,
Expand All @@ -99,6 +100,7 @@ impl AccountFetchEntrypoint {
Self::RpcGetAccount => "rpc_get_account",
Self::RpcGetMultipleAccounts => "rpc_get_multiple_accounts",
Self::SendTransaction(_) => "send_transaction",
Self::SimulateTransaction(_) => "simulate_transaction",
Self::SubscriptionUpdate => "subscription_update",
Self::ProjectAta => "project_ata",
Self::Internal => "internal",
Expand All @@ -107,7 +109,9 @@ impl AccountFetchEntrypoint {

pub fn signature(&self) -> Option<&Signature> {
match self {
Self::SendTransaction(sig) => Some(sig),
Self::SendTransaction(sig) | Self::SimulateTransaction(sig) => {
Some(sig)
}
_ => None,
}
}
Expand Down Expand Up @@ -226,6 +230,13 @@ impl AccountFetchContext {
)
}

pub fn simulate_transaction(signature: Signature) -> Self {
Self::new(
AccountFetchEntrypoint::SimulateTransaction(signature),
AccountFetchReason::RequestedAccount,
)
}

pub fn subscription_update(reason: AccountFetchReason) -> Self {
Self::new(AccountFetchEntrypoint::SubscriptionUpdate, reason)
}
Expand Down Expand Up @@ -264,6 +275,7 @@ impl AccountFetchContext {
AccountFetchEntrypoint::RpcGetAccount
| AccountFetchEntrypoint::RpcGetMultipleAccounts
| AccountFetchEntrypoint::SendTransaction(_)
| AccountFetchEntrypoint::SimulateTransaction(_)
)
}

Expand Down Expand Up @@ -888,6 +900,10 @@ mod tests {
AccountFetchEntrypoint::SendTransaction(signature),
"send_transaction",
),
(
AccountFetchEntrypoint::SimulateTransaction(signature),
"simulate_transaction",
),
(
AccountFetchEntrypoint::SubscriptionUpdate,
"subscription_update",
Expand Down Expand Up @@ -942,11 +958,15 @@ mod tests {
}

#[test]
fn account_fetch_context_signature_is_only_for_send_transaction() {
fn account_fetch_context_signature_is_for_transaction_entrypoints() {
let signature = Signature::from([1u8; 64]);
let send_context = AccountFetchContext::send_transaction(signature);
assert_eq!(send_context.signature(), Some(&signature));
assert_eq!(send_context.entrypoint().signature(), Some(&signature));
let simulate_context =
AccountFetchContext::simulate_transaction(signature);
for context in [&send_context, &simulate_context] {
assert_eq!(context.signature(), Some(&signature));
assert_eq!(context.entrypoint().signature(), Some(&signature));
}

let contexts = [
AccountFetchContext::rpc_get_account(),
Expand All @@ -963,4 +983,15 @@ mod tests {
assert_eq!(context.entrypoint().signature(), None);
}
}

#[test]
fn simulation_requested_accounts_count_remote_account_claims() {
let context = AccountFetchContext::simulate_transaction(
Signature::from([1u8; 64]),
);
assert!(context.should_count_remote_account_claims());
assert!(!context
.with_reason(AccountFetchReason::ProgramData)
.should_count_remote_account_claims());
}
}
Loading