Improve log statements in processor

This commit is contained in:
Luke Parker 2023-04-11 06:06:17 -04:00
parent 7538c10159
commit caa695511b
No known key found for this signature in database
5 changed files with 37 additions and 13 deletions

View file

@ -533,7 +533,7 @@ impl Coin for Bitcoin {
Err(RpcError::ConnectionError) => Err(CoinError::ConnectionError)?,
// TODO: Distinguish already in pool vs double spend (other signing attempt succeeded) vs
// invalid transaction
Err(e) => panic!("failed to publish TX {:?}: {e}", tx.txid()),
Err(e) => panic!("failed to publish TX {}: {e}", tx.txid()),
}
Ok(())
}

View file

@ -517,7 +517,7 @@ impl Coin for Monero {
Err(RpcError::ConnectionError) => Err(CoinError::ConnectionError)?,
// TODO: Distinguish already in pool vs double spend (other signing attempt succeeded) vs
// invalid transaction
Err(e) => panic!("failed to publish TX {:?}: {e}", tx.hash()),
Err(e) => panic!("failed to publish TX {}: {e}", hex::encode(tx.hash())),
}
}

View file

@ -73,8 +73,10 @@ impl<C: Coin, D: Db> ScannerDb<C, D> {
let key_bytes = key.to_bytes();
// Don't add this key if it's already present
let key_len = key_bytes.as_ref().len();
assert_eq!(keys.len() % key_len, 0);
// Don't add this key if it's already present
let mut i = 0;
while i < keys.len() {
if keys[i .. (i + key_len)].as_ref() == key_bytes.as_ref() {
@ -330,7 +332,7 @@ impl<C: Coin, D: Db> Scanner<C, D> {
// CONFIRMATIONS - 1 as whatever's in the latest block already has 1 confirm
Ok(latest) => latest.saturating_sub(C::CONFIRMATIONS.saturating_sub(1)),
Err(_) => {
warn!("Couldn't get {}'s latest block number", C::ID);
warn!("couldn't get latest block number");
sleep(Duration::from_secs(60)).await;
continue;
}
@ -360,7 +362,7 @@ impl<C: Coin, D: Db> Scanner<C, D> {
let block = match scanner.coin.get_block(i).await {
Ok(block) => block,
Err(_) => {
warn!("Couldn't get {} block {i}", C::ID);
warn!("couldn't get block {i}");
break;
}
};
@ -369,7 +371,7 @@ impl<C: Coin, D: Db> Scanner<C, D> {
if let Some(id) = scanner.db.block(i) {
// TODO2: Also check this block builds off the previous block
if id != block_id {
panic!("{} reorg'd from {id:?} to {:?}", C::ID, hex::encode(block_id));
panic!("reorg'd from finalized {} to {}", hex::encode(id), hex::encode(block_id));
}
} else {
info!("Found new block: {}", hex::encode(&block_id));
@ -400,7 +402,7 @@ impl<C: Coin, D: Db> Scanner<C, D> {
let outputs = match scanner.coin.get_outputs(&block, key).await {
Ok(outputs) => outputs,
Err(_) => {
warn!("Couldn't scan {} block {i:?}", C::ID);
warn!("Couldn't scan block {i}");
break;
}
};

View file

@ -54,7 +54,19 @@ impl<C: Coin, D: Db> SignerDb<C, D> {
// Transactions can be completed by multiple signatures
// Save every solution in order to be robust
let mut existing = txn.get(Self::completed_key(id)).unwrap_or(vec![]);
// TODO: Don't do this if this TX is already present
// Don't add this TX if it's already present
let tx_len = tx.as_ref().len();
assert_eq!(existing.len() % tx_len, 0);
let mut i = 0;
while i < existing.len() {
if existing[i .. (i + tx_len)].as_ref() == tx.as_ref() {
return;
}
i += tx_len;
}
existing.extend(tx.as_ref());
txn.put(Self::completed_key(id), existing);
}

View file

@ -135,7 +135,7 @@ impl<D: Db> SubstrateSigner<D> {
// If we don't have an attempt logged, it's because the coordinator is faulty OR
// because we rebooted
None => {
warn!("not attempting {:?}. this is an error if we didn't reboot", id);
warn!("not attempting {}. this is an error if we didn't reboot", hex::encode(id.id));
// Don't panic on the assumption we rebooted
Err(())?;
}
@ -171,7 +171,10 @@ impl<D: Db> SubstrateSigner<D> {
let machine = match self.preprocessing.remove(&id.id) {
// Either rebooted or RPC error, or some invariant
None => {
warn!("not preprocessing for {:?}. this is an error if we didn't reboot", id);
warn!(
"not preprocessing for {}. this is an error if we didn't reboot",
hex::encode(id.id)
);
return;
}
Some(machine) => machine,
@ -219,7 +222,10 @@ impl<D: Db> SubstrateSigner<D> {
panic!("never preprocessed yet signing?");
}
warn!("not preprocessing for {:?}. this is an error if we didn't reboot", id);
warn!(
"not preprocessing for {}. this is an error if we didn't reboot",
hex::encode(id.id)
);
return;
}
Some(machine) => machine,
@ -347,7 +353,7 @@ impl<D: Db> SubstrateSigner<D> {
if !id.signing_set(&signer.keys.params()).contains(&signer.keys.params().i()) {
continue;
}
info!("selected to sign {:?}", id);
info!("selected to sign {} #{}", hex::encode(id.id), id.attempt);
// If we reboot mid-sign, the current design has us abort all signs and wait for latter
// attempts/new signing protocols
@ -362,7 +368,11 @@ impl<D: Db> SubstrateSigner<D> {
//
// Only run if this hasn't already been attempted
if signer.db.has_attempt(&id) {
warn!("already attempted {:?}. this is an error if we didn't reboot", id);
warn!(
"already attempted {} #{}. this is an error if we didn't reboot",
hex::encode(id.id),
id.attempt
);
continue;
}