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

Backports sim_bundle improvements #407

Merged
merged 4 commits into from
Oct 11, 2023
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
5 changes: 5 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions bundle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ license = { workspace = true }
edition = { workspace = true }

[dependencies]
anchor-lang = { workspace = true }
itertools = { workspace = true }
log = { workspace = true }
serde = { workspace = true }
solana-ledger = { workspace = true }
solana-logger = { workspace = true }
solana-measure = { workspace = true }
solana-poh = { workspace = true }
solana-program-runtime = { workspace = true }
solana-runtime = { workspace = true }
solana-sdk = { workspace = true }
Expand Down
22 changes: 15 additions & 7 deletions bundle/src/bundle_execution.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
itertools::izip,
log::{debug, trace},
log::*,
solana_ledger::token_balances::collect_token_balances,
solana_measure::{measure::Measure, measure_us},
solana_program_runtime::timings::ExecuteTimings,
Expand Down Expand Up @@ -77,16 +77,24 @@ impl<'a> LoadAndExecuteBundleOutput<'a> {

#[derive(Clone, Debug, Error)]
pub enum LoadAndExecuteBundleError {
#[error("The bundle processing time was exceeded")]
#[error("Bundle execution timed out")]
ProcessingTimeExceeded(Duration),

#[error("A transaction in the bundle encountered a lock error")]
#[error(
"A transaction in the bundle encountered a lock error: [signature={:?}, transaction_error={:?}]",
signature,
transaction_error
)]
LockError {
signature: Signature,
transaction_error: TransactionError,
},

#[error("A transaction in the bundle failed to execute")]
#[error(
"A transaction in the bundle failed to execute: [signature={:?}, execution_result={:?}",
signature,
execution_result
)]
TransactionError {
signature: Signature,
// Box reduces the size between variants in the Error
Expand Down Expand Up @@ -318,7 +326,7 @@ pub fn load_and_execute_bundle<'a>(
});
saturating_add_assign!(metrics.collect_balances_us, collect_balances_us);

let end = max(
let end = min(
chunk_start.saturating_add(batch.sanitized_transactions().len()),
pre_execution_accounts.len(),
);
Expand Down Expand Up @@ -495,7 +503,7 @@ mod tests {
solana_ledger::genesis_utils::create_genesis_config,
solana_runtime::{bank::Bank, genesis_utils::GenesisConfigInfo},
solana_sdk::{
bundle::{derive_bundle_id_from_sanizited_transactions, SanitizedBundle},
bundle::{derive_bundle_id_from_sanitized_transactions, SanitizedBundle},
clock::MAX_PROCESSING_AGE,
pubkey::Pubkey,
signature::{Keypair, Signer},
Expand Down Expand Up @@ -525,7 +533,7 @@ mod tests {
.map(|tx| SanitizedTransaction::try_from_legacy_transaction(tx.clone()).unwrap())
.collect();

let bundle_id = derive_bundle_id_from_sanizited_transactions(&transactions);
let bundle_id = derive_bundle_id_from_sanitized_transactions(&transactions);

SanitizedBundle {
transactions,
Expand Down
59 changes: 59 additions & 0 deletions bundle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
use {
crate::bundle_execution::LoadAndExecuteBundleError,
anchor_lang::error::Error,
serde::{Deserialize, Serialize},
solana_poh::poh_recorder::PohRecorderError,
solana_sdk::pubkey::Pubkey,
thiserror::Error,
};

pub mod bundle_execution;

#[derive(Error, Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum TipError {
#[error("account is missing from bank: {0}")]
AccountMissing(Pubkey),

#[error("Anchor error: {0}")]
AnchorError(String),

#[error("Lock error")]
LockError,

#[error("Error executing initialize programs")]
InitializeProgramsError,

#[error("Error cranking tip programs")]
CrankTipError,
}

impl From<anchor_lang::error::Error> for TipError {
fn from(anchor_err: Error) -> Self {
match anchor_err {
Error::AnchorError(e) => Self::AnchorError(e.error_msg),
Error::ProgramError(e) => Self::AnchorError(e.to_string()),
}
}
}

pub type BundleExecutionResult<T> = Result<T, BundleExecutionError>;

#[derive(Error, Debug, Clone)]
pub enum BundleExecutionError {
#[error("The bank has hit the max allotted time for processing transactions")]
BankProcessingTimeLimitReached,

#[error("The bundle exceeds the cost model")]
ExceedsCostModel,

#[error("Runtime error while executing the bundle: {0}")]
TransactionFailure(#[from] LoadAndExecuteBundleError),

#[error("Error locking bundle because a transaction is malformed")]
LockError,

#[error("PoH record error: {0}")]
PohRecordError(#[from] PohRecorderError),

#[error("Tip payment error {0}")]
TipError(#[from] TipError),
}
3 changes: 3 additions & 0 deletions ci/check-crates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ printf "%s\n" "${files[@]}"
error_count=0
for file in "${files[@]}"; do
read -r crate_name package_publish workspace < <(toml get "$file" . | jq -r '(.package.name | tostring)+" "+(.package.publish | tostring)+" "+(.workspace | tostring)')
if [ "$crate_name" == "solana-bundle" ]; then
continue
fi
echo "=== $crate_name ($file) ==="

if [[ $package_publish = 'false' ]]; then
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ matches = { workspace = true }
raptorq = { workspace = true }
serde_json = { workspace = true }
serial_test = { workspace = true }
solana-bundle = { workspace = true }
solana-logger = { workspace = true }
solana-program-runtime = { workspace = true }
solana-program-test = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion core/src/bundle_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ mod bundle_packet_receiver;
mod bundle_reserved_space_manager;
pub(crate) mod bundle_stage_leader_metrics;
mod committer;
pub mod result;

const MAX_BUNDLE_RETRY_DURATION: Duration = Duration::from_millis(10);
const SLOT_BOUNDARY_CHECK_PERIOD: Duration = Duration::from_millis(10);
Expand Down
24 changes: 14 additions & 10 deletions core/src/bundle_stage/bundle_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ use {
bundle_reserved_space_manager::BundleReservedSpaceManager,
bundle_stage_leader_metrics::BundleStageLeaderMetrics,
committer::Committer,
result::{BundleExecutionError, BundleExecutionResult},
},
consensus_cache_updater::ConsensusCacheUpdater,
immutable_deserialized_bundle::ImmutableDeserializedBundle,
leader_slot_banking_stage_metrics::ProcessTransactionsSummary,
leader_slot_banking_stage_timing_metrics::LeaderExecuteAndCommitTimings,
proxy::block_engine_stage::BlockBuilderFeeInfo,
qos_service::QosService,
tip_manager::{TipManager, TipPaymentError},
tip_manager::TipManager,
unprocessed_transaction_storage::UnprocessedTransactionStorage,
},
solana_bundle::bundle_execution::{load_and_execute_bundle, BundleExecutionMetrics},
solana_bundle::{
bundle_execution::{load_and_execute_bundle, BundleExecutionMetrics},
BundleExecutionError, BundleExecutionResult, TipError,
},
solana_gossip::cluster_info::ClusterInfo,
solana_measure::{measure, measure_us},
solana_poh::poh_recorder::{BankStart, RecordTransactionsSummary, TransactionRecorder},
Expand Down Expand Up @@ -246,7 +248,9 @@ impl BundleConsumer {
.increment_process_packets_transactions_us(measure);
r
}
Err(e) => Err(e.into()),
Err(_) => {
Err(BundleExecutionError::LockError)
}
})
.collect::<Vec<_>>());

Expand Down Expand Up @@ -283,7 +287,7 @@ impl BundleConsumer {
&bank_start.bank_creation_time,
bank_start.working_bank.ns_per_slot,
) {
return Err(BundleExecutionError::BankProcessingDone);
return Err(BundleExecutionError::BankProcessingTimeLimitReached);
}

if Self::bundle_touches_tip_pdas(
Expand Down Expand Up @@ -364,7 +368,7 @@ impl BundleConsumer {

let locked_init_tip_programs_bundle = bundle_account_locker
.prepare_locked_bundle(&bundle, &bank_start.working_bank)
.map_err(|_| BundleExecutionError::TipError(TipPaymentError::LockError))?;
.map_err(|_| BundleExecutionError::TipError(TipError::LockError))?;

Self::update_qos_and_execute_record_commit_bundle(
committer,
Expand All @@ -386,7 +390,7 @@ impl BundleConsumer {
locked_init_tip_programs_bundle.sanitized_bundle().bundle_id,
e
);
BundleExecutionError::TipError(TipPaymentError::InitializeProgramsError)
BundleExecutionError::TipError(TipError::InitializeProgramsError)
})?;

bundle_stage_leader_metrics
Expand Down Expand Up @@ -417,7 +421,7 @@ impl BundleConsumer {

let locked_tip_crank_bundle = bundle_account_locker
.prepare_locked_bundle(&bundle, &bank_start.working_bank)
.map_err(|_| BundleExecutionError::TipError(TipPaymentError::LockError))?;
.map_err(|_| BundleExecutionError::TipError(TipError::LockError))?;

Self::update_qos_and_execute_record_commit_bundle(
committer,
Expand All @@ -439,7 +443,7 @@ impl BundleConsumer {
locked_tip_crank_bundle.sanitized_bundle().bundle_id,
e
);
BundleExecutionError::TipError(TipPaymentError::CrankTipError)
BundleExecutionError::TipError(TipError::CrankTipError)
})?;

bundle_stage_leader_metrics
Expand Down Expand Up @@ -555,7 +559,7 @@ impl BundleConsumer {
.accumulate_process_transactions_summary(&ProcessTransactionsSummary {
reached_max_poh_height: matches!(
result.result,
Err(BundleExecutionError::BankProcessingDone)
Err(BundleExecutionError::BankProcessingTimeLimitReached)
| Err(BundleExecutionError::PohRecordError(_))
),
transactions_attempted_execution_count: sanitized_bundle.transactions.len(),
Expand Down
23 changes: 7 additions & 16 deletions core/src/bundle_stage/bundle_packet_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,11 @@ impl BundleReceiver {
mod tests {
use {
super::*,
crate::{
bundle_stage::{
bundle_account_locker::BundleAccountLockerError, result::BundleExecutionError,
},
tip_manager::TipPaymentError,
},
crossbeam_channel::unbounded,
rand::{thread_rng, RngCore},
solana_bundle::bundle_execution::LoadAndExecuteBundleError,
solana_bundle::{
bundle_execution::LoadAndExecuteBundleError, BundleExecutionError, TipError,
},
solana_ledger::genesis_utils::create_genesis_config,
solana_perf::packet::PacketBatch,
solana_poh::poh_recorder::PohRecorderError,
Expand Down Expand Up @@ -474,7 +470,7 @@ mod tests {
let mut results = vec![Ok(()); bundles_to_process.len()];

(bank_processing_done_index..bundles_to_process.len()).for_each(|index| {
results[index] = Err(BundleExecutionError::BankProcessingDone);
results[index] = Err(BundleExecutionError::BankProcessingTimeLimitReached);
});
results
}
Expand Down Expand Up @@ -538,7 +534,7 @@ mod tests {
|bundles_to_process, _stats| {
assert_bundles_same(&bundles, bundles_to_process);
vec![
Err(BundleExecutionError::ExecutionError(
Err(BundleExecutionError::TransactionFailure(
LoadAndExecuteBundleError::ProcessingTimeExceeded(Duration::from_secs(1)),
));
bundles_to_process.len()
Expand Down Expand Up @@ -591,7 +587,7 @@ mod tests {
|bundles_to_process, _stats| {
assert_bundles_same(&bundles, bundles_to_process);
vec![
Err(BundleExecutionError::TipError(TipPaymentError::LockError));
Err(BundleExecutionError::TipError(TipError::LockError));
bundles_to_process.len()
]
}
Expand Down Expand Up @@ -640,12 +636,7 @@ mod tests {
&mut bundle_stage_leader_metrics,
&HashSet::default(),
|bundles_to_process, _stats| {
vec![
Err(BundleExecutionError::LockError(
BundleAccountLockerError::LockingError
));
bundles_to_process.len()
]
vec![Err(BundleExecutionError::LockError); bundles_to_process.len()]
}
));
assert_eq!(bundle_storage.unprocessed_bundles_len(), 0);
Expand Down
15 changes: 7 additions & 8 deletions core/src/bundle_stage/bundle_stage_leader_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use {
crate::{
bundle_stage::result::BundleExecutionError,
immutable_deserialized_bundle::DeserializedBundleError,
leader_slot_banking_stage_metrics::{self, LeaderSlotMetricsTracker},
},
solana_bundle::bundle_execution::LoadAndExecuteBundleError,
solana_bundle::{bundle_execution::LoadAndExecuteBundleError, BundleExecutionError},
solana_poh::poh_recorder::BankStart,
solana_sdk::{bundle::SanitizedBundle, clock::Slot, saturating_add_assign},
};
Expand Down Expand Up @@ -215,29 +214,29 @@ impl BundleStageStatsMetricsTracker {
saturating_add_assign!(bundle_stage_metrics.execution_results_ok, 1);
}
Err(BundleExecutionError::PohRecordError(_))
| Err(BundleExecutionError::BankProcessingDone) => {
| Err(BundleExecutionError::BankProcessingTimeLimitReached) => {
saturating_add_assign!(
bundle_stage_metrics.execution_results_poh_max_height,
1
);
}
Err(BundleExecutionError::ExecutionError(
Err(BundleExecutionError::TransactionFailure(
LoadAndExecuteBundleError::ProcessingTimeExceeded(_),
)) => {
saturating_add_assign!(bundle_stage_metrics.num_execution_timeouts, 1);
}
Err(BundleExecutionError::ExecutionError(
Err(BundleExecutionError::TransactionFailure(
LoadAndExecuteBundleError::TransactionError { .. },
)) => {
saturating_add_assign!(
bundle_stage_metrics.execution_results_transaction_failures,
1
);
}
Err(BundleExecutionError::ExecutionError(
Err(BundleExecutionError::TransactionFailure(
LoadAndExecuteBundleError::LockError { .. },
))
| Err(BundleExecutionError::LockError(_)) => {
| Err(BundleExecutionError::LockError) => {
saturating_add_assign!(bundle_stage_metrics.num_lock_errors, 1);
}
Err(BundleExecutionError::ExceedsCostModel) => {
Expand All @@ -249,7 +248,7 @@ impl BundleStageStatsMetricsTracker {
Err(BundleExecutionError::TipError(_)) => {
saturating_add_assign!(bundle_stage_metrics.execution_results_tip_errors, 1);
}
Err(BundleExecutionError::ExecutionError(
Err(BundleExecutionError::TransactionFailure(
LoadAndExecuteBundleError::InvalidPreOrPostAccounts,
)) => {
saturating_add_assign!(bundle_stage_metrics.bad_argument, 1);
Expand Down
Loading