Service name should be printed when writing errors to log
@@ -357,7 +357,7 @@ impl Blockchain {
index: usize,
fork: &mut Fork,
) -> Result<(), failure::Error> {
- let tx = {
+ let (tx, service_name) = {
let schema = Schema::new(&fork);
let tx = schema
@@ -365,13 +365,21 @@ impl Blockchain {
.get(&tx_hash)
.ok_or_else(|| failure::err_msg("BUG: Cannot find transaction in database."))?;
- self.tx_from_raw(tx).or_else(|error| {
+ let service_name = self.service_map
+ .get(tx.service_id() as usize)
+ .ok_or_else(|| failure::err_msg("Service not found."))?
+ .service_name();
+
+ let tx = self.tx_from_raw(tx).or_else(|error| {
Err(failure::err_msg(format!(
- "{}, tx: {:?}",
+ "Service <{}>: {}, tx: {:?}",
+ service_name,
error.description(),
tx_hash
)))
- })?
+ })?;
+
+ (tx, service_name)
};
fork.checkpoint();
@@ -387,7 +395,10 @@ impl Blockchain {
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);
+ info!(
+ "Service <{}>: {:?} transaction execution failed: {:?}",
+ service_name, tx_hash, e
+ );
fork.rollback();
}
}
@@ -399,7 +410,10 @@ impl Blockchain {
panic::resume_unwind(err);
}
fork.rollback();
- error!("{:?} transaction execution panicked: {:?}", tx, err);
+ error!(
+ "Service <{}>: {:?} transaction execution panicked: {:?}",
+ service_name, tx, err
+ );
Err(TransactionError::from_panic(&err))
}
};
