fix: add logging for some tx outcomes that were missing

This commit is contained in:
Greg Coppola
2022-05-16 16:03:33 -05:00
parent 584a7fe87b
commit d09ea40a07
2 changed files with 44 additions and 15 deletions

View File

@@ -890,11 +890,12 @@ impl<'a> StacksMicroblockBuilder<'a> {
"Microblock miner deadline exceeded ({} ms)",
self.settings.max_miner_time_ms
);
return Ok(false);
return Ok(None);
}
if considered.contains(&mempool_tx.tx.txid()) {
return Ok(true);
return Ok(Some(TransactionResult::skipped(
&mempool_tx.tx, "Transaction already considered.".to_string()).convert_to_event()));
} else {
considered.insert(mempool_tx.tx.txid());
}
@@ -907,6 +908,7 @@ impl<'a> StacksMicroblockBuilder<'a> {
&block_limit_hit,
) {
Ok(tx_result) => {
let result_event = tx_result.convert_to_event();
tx_events.push(tx_result.convert_to_event());
match tx_result {
TransactionResult::Success(TransactionSuccess {
@@ -937,7 +939,7 @@ impl<'a> StacksMicroblockBuilder<'a> {
num_txs += 1;
num_added += 1;
num_selected += 1;
Ok(true)
Ok(Some(result_event))
}
TransactionResult::Skipped(TransactionSkipped {
error,
@@ -963,7 +965,7 @@ impl<'a> StacksMicroblockBuilder<'a> {
debug!("Block budget exceeded while mining microblock";
"tx" => %mempool_tx.tx.txid(), "next_behavior" => "Stop mining microblock");
block_limit_hit = BlockLimitFunction::LIMIT_REACHED;
return Ok(false);
return Ok(None);
}
}
Error::TransactionTooBigError => {
@@ -971,7 +973,7 @@ impl<'a> StacksMicroblockBuilder<'a> {
}
_ => {}
}
return Ok(true)
return Ok(Some(result_event))
}
}
}
@@ -1995,28 +1997,49 @@ impl StacksBlockBuilder {
let update_estimator = to_consider.update_estimate;
if block_limit_hit == BlockLimitFunction::LIMIT_REACHED {
return Ok(false);
return Ok(None);
}
if get_epoch_time_ms() >= deadline {
debug!("Miner mining time exceeded ({} ms)", max_miner_time_ms);
return Ok(false);
return Ok(None);
}
// skip transactions early if we can
if considered.contains(&txinfo.tx.txid()) {
return Ok(true);
return Ok(Some(
TransactionResult::skipped(
&txinfo.tx,
"Transaction already considered.".to_string(),
)
.convert_to_event(),
));
}
if let Some(nonce) = mined_origin_nonces.get(&txinfo.tx.origin_address()) {
if *nonce >= txinfo.tx.get_origin_nonce() {
return Ok(true);
let message = format!(
"Bad origin nonce, tx nonce {} versus {}.",
txinfo.tx.get_origin_nonce(),
*nonce
);
return Ok(Some(
TransactionResult::skipped(&txinfo.tx, message)
.convert_to_event(),
));
}
}
if let Some(sponsor_addr) = txinfo.tx.sponsor_address() {
if let Some(nonce) = mined_sponsor_nonces.get(&sponsor_addr) {
if let Some(sponsor_nonce) = txinfo.tx.get_sponsor_nonce() {
if *nonce >= sponsor_nonce {
return Ok(true);
let message = format!(
"Bad sponsor nonce, tx nonce {} versus {}.",
sponsor_nonce, *nonce
);
return Ok(Some(
TransactionResult::skipped(&txinfo.tx, message)
.convert_to_event(),
));
}
}
}
@@ -2033,6 +2056,7 @@ impl StacksBlockBuilder {
);
tx_events.push(tx_result.convert_to_event());
let result_event = tx_result.convert_to_event();
match tx_result {
TransactionResult::Success(TransactionSuccess { receipt, .. }) => {
num_txs += 1;
@@ -2079,7 +2103,7 @@ impl StacksBlockBuilder {
"Stop mining anchored block due to limit exceeded"
);
block_limit_hit = BlockLimitFunction::LIMIT_REACHED;
return Ok(false);
return Ok(Some(result_event));
}
}
Error::TransactionTooBigError => {
@@ -2090,13 +2114,13 @@ impl StacksBlockBuilder {
}
e => {
warn!("Failed to apply tx {}: {:?}", &txinfo.tx.txid(), &e);
return Ok(true);
return Ok(Some(result_event));
}
}
}
}
Ok(true)
Ok(Some(result_event))
},
);

View File

@@ -1019,7 +1019,11 @@ impl MemPoolDB {
) -> Result<u64, E>
where
C: ClarityConnection,
F: FnMut(&mut C, &ConsiderTransaction, &mut dyn CostEstimator) -> Result<bool, E>,
F: FnMut(
&mut C,
&ConsiderTransaction,
&mut dyn CostEstimator,
) -> Result<Option<TransactionEvent>, E>,
E: From<db_error> + From<ChainstateError>,
{
let start_time = Instant::now();
@@ -1079,7 +1083,8 @@ impl MemPoolDB {
"size" => consider.tx.metadata.len);
total_considered += 1;
if !todo(clarity_tx, &consider, self.cost_estimator.as_mut())? {
let todo_result = todo(clarity_tx, &consider, self.cost_estimator.as_mut())?;
if !todo_result.is_some() {
debug!("Mempool iteration early exit from iterator");
break;
}