feat: log all transactions as they are processed for debugging

This commit is contained in:
Aaron Blankstein
2020-09-25 14:27:14 -05:00
parent af3f7a21ec
commit 511f3aea27
4 changed files with 36 additions and 0 deletions

View File

@@ -91,6 +91,7 @@ criterion = "0.3"
developer-mode = []
default = ["developer-mode"]
monitoring_prom = ["prometheus"]
tx_log = []
[target.'cfg(all(target_arch = "x86_64", not(target_env = "msvc")))'.dependencies]
sha2-asm = "0.5.3"

View File

@@ -2904,6 +2904,8 @@ impl StacksChainState {
&block_execution_cost)
.expect("FATAL: failed to advance chain tip");
chainstate_tx.log_transactions_processed(&new_tip.index_block_hash(), &txs_receipts);
let epoch_receipt = StacksEpochReceipt {
header: new_tip,
tx_receipts: txs_receipts,

View File

@@ -372,6 +372,25 @@ impl<'a> ChainstateTx<'a> {
self.headers_tx.commit()?;
self.blocks_tx.commit()
}
#[cfg(feature="tx_log")]
pub fn log_transactions_processed(&self, block_id: &StacksBlockId, events: &[StacksTransactionReceipt]) {
let insert = "INSERT INTO transactions (txid, index_block_hash, tx_hex, result) VALUES (?, ?, ?, ?)";
for tx_event in events.iter() {
let txid = tx_event.transaction.txid();
let tx_hex = to_hex(&tx_event.transaction.serialize_to_vec());
let result = tx_event.result.to_string();
let params: &[&dyn ToSql] = &[&txid, block_id, &tx_hex, &result];
if let Err(e) = self.headers_tx.tx().execute(insert, params) {
warn!("Failed to log TX: {}", e);
}
}
}
#[cfg(not(feature="tx_log"))]
pub fn log_transactions_processed(&self, _block_id: &StacksBlockId, _events: &[StacksTransactionReceipt]) {
}
}
/// Opaque structure for streaming block and microblock data from disk
@@ -426,6 +445,19 @@ const STACKS_CHAIN_STATE_SQL : &'static [&'static str]= &[
PRIMARY KEY(consensus_hash,block_hash)
);
"#,
#[cfg(feature = "tx_log")]
r#"
CREATE TABLE transactions(
id INTEGER PRIMARY KEY,
txid TEXT NOT NULL,
index_block_hash TEXT NOT NULL,
tx_hex TEXT NOT NULL,
result TEXT NOT NULL,
UNIQUE (txid,index_block_hash)
);
CREATE INDEX txid_tx_index ON transactions(txid);
CREATE INDEX index_block_hash_tx_index ON transactions(index_block_hash);
"#,
r#"
CREATE INDEX block_headers_hash_index ON block_headers(block_hash,block_height);
CREATE INDEX block_index_hash_index ON block_headers(index_block_hash,consensus_hash,block_hash);

View File

@@ -31,4 +31,5 @@ path = "src/main.rs"
[features]
monitoring_prom = ["stacks/monitoring_prom"]
tx-log = ["stacks/tx_log"]
default = []