Remove failed transaction body from logging
@@ -256,42 +256,7 @@ impl Blockchain {
"BUG: Cannot find transaction in pool.",
);
- fork.checkpoint();
-
- let catch_result =
- panic::catch_unwind(panic::AssertUnwindSafe(|| tx.execute(&mut fork)));
-
- let transaction_result = match catch_result {
- Ok(execution_result) => {
- match execution_result {
- Ok(()) => fork.commit(),
- Err(ref e) => {
- info!("{:?} transaction execution failed: {:?}", tx, e);
- fork.rollback();
- }
- }
- execution_result.map_err(TransactionError::from)
- }
- Err(err) => {
- if err.is::<Error>() {
- // Continue panic unwind if the reason is StorageError.
- panic::resume_unwind(err);
- }
- fork.rollback();
- error!("{:?} transaction execution panicked: {:?}", tx, err);
- Err(TransactionError::from_panic(&err))
- }
- };
-
- let mut schema = Schema::new(&mut fork);
- schema.transactions_mut().put(hash, tx.raw().clone());
- schema.transaction_results_mut().put(
- hash,
- transaction_result,
- );
- schema.block_txs_mut(height).push(*hash);
- let location = TxLocation::new(height, index as u64);
- schema.tx_location_by_tx_hash_mut().put(hash, location);
+ execute_transaction(tx, height, index, &mut fork);
}
// Get tx & state hash
@@ -492,3 +457,41 @@ impl Clone for Blockchain {
}
}
}
+
+fn execute_transaction(tx: &Box<Transaction>, height: Height, index: usize, fork: &mut Fork) {
+ fork.checkpoint();
+
+ let catch_result = panic::catch_unwind(panic::AssertUnwindSafe(|| tx.execute(fork)));
+
+ let tx_hash = tx.hash();
+ let tx_result = match catch_result {
+ Ok(execution_result) => {
+ match execution_result {
+ Ok(()) => fork.commit(),
+ Err(ref e) => {
+ // Unlike panic, transaction failure isn't that rare, so logging the
+ // whole transaction body is an overkill: it can be relatively big.
+ info!("{:?} transaction execution failed: {:?}", tx_hash, e);
+ fork.rollback();
+ }
+ }
+ execution_result.map_err(TransactionError::from)
+ }
+ Err(err) => {
+ if err.is::<Error>() {
+ // Continue panic unwind if the reason is StorageError.
+ panic::resume_unwind(err);
+ }
+ fork.rollback();
+ error!("{:?} transaction execution panicked: {:?}", tx, err);
+ Err(TransactionError::from_panic(&err))
+ }
+ };
+
+ let mut schema = Schema::new(fork);
+ schema.transactions_mut().put(&tx_hash, tx.raw().clone());
+ schema.transaction_results_mut().put(&tx_hash, tx_result);
+ schema.block_txs_mut(height).push(tx_hash);
+ let location = TxLocation::new(height, index as u64);
+ schema.tx_location_by_tx_hash_mut().put(&tx_hash, location);
+}
