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
2 changes: 1 addition & 1 deletion ledger/src/scan_state/transaction_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4187,7 +4187,7 @@ pub mod zkapp_command {
.find(|(id, _)| account_id == id)
.map(|(_, key)| key.clone())
})
.ok_or_else(|| "verification key not found in cache".to_string())
.ok_or_else(|| format!("verification key not found in cache: {:?}", vk_hash))
})?;
if !is_failed {
for (account_id, vk) in cmd.extract_vks() {
Expand Down
18 changes: 11 additions & 7 deletions ledger/src/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum TransactionPoolErrors {
/// Invalid transactions, rejeceted diffs, etc...
#[error("Transaction pool errors: {0:?}")]
BatchedErrors(Vec<TransactionError>),
#[error("{0:?}")]
LoadingVK(String),
/// Errors that should panic the node (bugs in implementation)
#[error("Unexpected error: {0}")]
Unexpected(String),
Expand Down Expand Up @@ -996,7 +998,7 @@ impl IndexedPool {
consumed
};

match by_sender.state.as_mut() {
match by_sender.state.clone() {
None => {
if current_nonce != cmd_applicable_at_nonce {
return Err(CommandError::InvalidNonce {
Expand All @@ -1020,7 +1022,7 @@ impl IndexedPool {

Ok((cmd.clone(), Self::make_queue()))
}
Some((queued_cmds, reserved_currency)) => {
Some((mut queued_cmds, reserved_currency)) => {
assert!(!queued_cmds.is_empty());
let queue_applicable_at_nonce = {
let first = queued_cmds.front().unwrap();
Expand All @@ -1031,14 +1033,14 @@ impl IndexedPool {
last.data.forget_check().expected_target_nonce()
};
if queue_target_nonce == cmd_applicable_at_nonce {
*reserved_currency = consumed
.checked_add(reserved_currency)
let reserved_currency = consumed
.checked_add(&reserved_currency)
.ok_or(CommandError::Overflow)?;

if *reserved_currency > balance.to_amount() {
if reserved_currency > balance.to_amount() {
return Err(CommandError::InsufficientFunds {
balance,
consumed: *reserved_currency,
consumed: reserved_currency,
});
}

Expand All @@ -1050,6 +1052,8 @@ impl IndexedPool {
add_to_applicable_by_fee: false,
});

by_sender.state = Some((queued_cmds, reserved_currency));

Ok((cmd.clone(), Self::make_queue()))
} else if queue_applicable_at_nonce == current_nonce {
if !cmd_applicable_at_nonce
Expand Down Expand Up @@ -2161,7 +2165,7 @@ impl TransactionPool {

from_unapplied_sequence::Cache::new(merged)
})
.map_err(TransactionPoolErrors::Unexpected)?;
.map_err(TransactionPoolErrors::LoadingVK)?;

let diff = diff
.into_iter()
Expand Down
45 changes: 27 additions & 18 deletions node/src/transaction_pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,20 @@ impl TransactionPoolState {
id
}

#[allow(dead_code)]
fn save_actions(state: &mut crate::Substate<Self>) {
let substate = state.get_substate_mut().unwrap();
if substate.file.is_none() {
let mut file = std::fs::File::create("/tmp/pool.bin").unwrap();
postcard::to_io(&state.get_state(), &mut file).unwrap();
let substate = state.get_substate_mut().unwrap();
substate.file = Some(file);
}
}

pub fn reducer(mut state: crate::Substate<Self>, action: &TransactionPoolAction) {
// Uncoment following block to save actions to `/tmp/pool.bin`
// {
// let substate = state.get_substate_mut().unwrap();
// if substate.file.is_none() {
// let mut file = std::fs::File::create("/tmp/pool.bin").unwrap();
// postcard::to_io(&state.get_state(), &mut file).unwrap();
// let substate = state.get_substate_mut().unwrap();
// substate.file = Some(file);
// }
// }
// Uncoment following line to save actions to `/tmp/pool.bin`
// Self::save_actions(&mut state);

let substate = state.get_substate_mut().unwrap();
if let Some(file) = substate.file.as_mut() {
Expand Down Expand Up @@ -182,11 +185,9 @@ impl TransactionPoolState {
from_rpc: *from_rpc,
});
}
Err(e) => match e {
TransactionPoolErrors::BatchedErrors(errors) => {
Err(e) => {
let dispatch_errors = |errors: Vec<String>| {
let dispatcher = state.into_dispatcher();
let errors: Vec<_> =
errors.into_iter().map(|e| e.to_string()).collect();
dispatcher.push(TransactionPoolAction::VerifyError {
errors: errors.clone(),
});
Expand All @@ -196,11 +197,19 @@ impl TransactionPoolState {
errors,
})
}
};
match e {
TransactionPoolErrors::BatchedErrors(errors) => {
let errors: Vec<_> =
errors.into_iter().map(|e| e.to_string()).collect();
dispatch_errors(errors);
}
TransactionPoolErrors::LoadingVK(error) => dispatch_errors(vec![error]),
TransactionPoolErrors::Unexpected(es) => {
panic!("{es}")
}
}
TransactionPoolErrors::Unexpected(es) => {
panic!("{es}")
}
},
}
}
}
TransactionPoolAction::VerifyError { .. } => {
Expand Down