diff --git a/taptrade-cli-demo/coordinator/.cookie b/taptrade-cli-demo/coordinator/.cookie index 7840072..7ae6cd7 100644 --- a/taptrade-cli-demo/coordinator/.cookie +++ b/taptrade-cli-demo/coordinator/.cookie @@ -1 +1 @@ -__cookie__:b3219c105fc87f4de97f8a14a17ea82da2f0e5c17ba79bbf45e641de96cd6a55 \ No newline at end of file +__cookie__:7b9dd407a2bf94a226776d1d35d5aeb64148b9425ddd6cf286381d6ab1d5f585 \ No newline at end of file diff --git a/taptrade-cli-demo/coordinator/src/coordinator/mempool_monitoring.rs b/taptrade-cli-demo/coordinator/src/coordinator/mempool_monitoring.rs index d8ca9e4..459f2db 100644 --- a/taptrade-cli-demo/coordinator/src/coordinator/mempool_monitoring.rs +++ b/taptrade-cli-demo/coordinator/src/coordinator/mempool_monitoring.rs @@ -1,17 +1,16 @@ use super::*; use anyhow::Ok; use bdk::bitcoin::consensus::encode::deserialize; -use bdk::bitcoin::Transaction; +use bdk::bitcoin::{OutPoint, Transaction}; use bdk::bitcoin::{TxIn, Txid}; use bdk::bitcoincore_rpc::{Client, RpcApi}; -use serde::Deserialize; use std::collections::{HashMap, HashSet}; use std::ops::Deref; use std::sync::RwLock; struct Mempool { transactions: Arc>>>, - utxo_set: Arc>>, + utxo_set: Arc>>, json_rpc_client: Arc, } @@ -75,7 +74,7 @@ fn run_mempool(mempool: Arc) { utxo_set.clear(); for (_, inputs) in mempool_state.iter() { for input in inputs { - utxo_set.insert(input.clone()); + utxo_set.insert(input.previous_output); } } } @@ -97,16 +96,18 @@ impl MempoolHandler { &self, bonds: &Vec, ) -> Result, (MonitoringBond, anyhow::Error)>> { + debug!("Looking up mempool inputs for bonds"); let mut bonds_to_punish: HashMap, (MonitoringBond, anyhow::Error)> = HashMap::new(); let utxo_set = self .mempool .utxo_set .read() .expect("Error locking utxo_set read mutex"); + debug!("Mempool utxo_set: {:?}", utxo_set); for bond in bonds { let bond_tx: Transaction = deserialize(&hex::decode(&bond.bond_tx_hex)?)?; for input in bond_tx.input { - if utxo_set.contains(&input) { + if utxo_set.contains(&input.previous_output) { bonds_to_punish.insert(bond.id()?, (bond.clone(), anyhow!("Input in mempool"))); break; } diff --git a/taptrade-cli-demo/coordinator/src/coordinator/monitoring.rs b/taptrade-cli-demo/coordinator/src/coordinator/monitoring.rs index 3120bc7..18da9ef 100644 --- a/taptrade-cli-demo/coordinator/src/coordinator/monitoring.rs +++ b/taptrade-cli-demo/coordinator/src/coordinator/monitoring.rs @@ -30,8 +30,9 @@ impl MonitoringBond { Ok(sha256(&hex::decode(&self.bond_tx_hex)?)) } - async fn remove_from_db_tables(&self, db: Arc) -> Result<()> { + async fn remove_from_db_tables(&self, db: &Arc) -> Result<()> { // remove bond from db + debug!("Removing violating bond from db tables"); db.remove_violating_bond(self) .await .context("Error removing violating bond from db")?; @@ -51,7 +52,7 @@ impl MonitoringBond { .publish_bond_tx_hex(&self.bond_tx_hex)?; // can be made async with esplora backend if we figure out the compilation error of bdk // remove offer from db/orderbook - self.remove_from_db_tables(coordinator.coordinator_db.clone()) + self.remove_from_db_tables(&coordinator.coordinator_db) .await?; Ok(()) } @@ -81,11 +82,11 @@ pub async fn monitor_bonds(coordinator: Arc) -> Result<()> { .as_str() { "1" => { - dbg!("Punishing trader for bond violation: {:?}", error); + warn!("Punishing trader for bond violation: {:?}", error); bond.punish(&coordinator).await?; } "0" => { - dbg!("Punishment disabled, ignoring bond violation: {:?}", error); + warn!("Punishment disabled, ignoring bond violation: {:?}", error); continue; } _ => Err(anyhow!("Invalid PUNISHMENT_ENABLED env var"))?, diff --git a/taptrade-cli-demo/trader/maker.env b/taptrade-cli-demo/trader/maker.env index caf09e9..ce3fd62 100644 --- a/taptrade-cli-demo/trader/maker.env +++ b/taptrade-cli-demo/trader/maker.env @@ -4,5 +4,5 @@ ROBOHASH_HEX="26ee3dee4815655d223c3505162fd4610294a9542f89bb3d3e9748f534ac10ae" TRADE_TYPE="buy" PAYOUT_ADDRESS="tb1p45daj2eaza6drcd85c3wvn0zrpqxuduk3rzcmla4eu7a02cep9kqjzkc64" BOND_RATIO=5 -XPRV="tprv8ZgxMBicQKsPdHuCSjhQuSZP1h6ZTeiRqREYS5guGPdtL7D1uNLpnJmb2oJep99Esq1NbNZKVJBNnD2ZhuXSK7G5eFmmcx73gsoa65e2U32" # wallet xprv +XPRV="tprv8ZgxMBicQKsPdRP5cDng7tV2hShHRDqRGGp749EEiXgP9t7RXCPqhPyHfDUL4pG6pzYD7mX4Kmx6Y21bdTDuNAwcDaPCkTNJn2odyRdCHRU" # wallet xprv OFFER_DURATION_HOURS=48 diff --git a/taptrade-cli-demo/trader/src/wallet/bond.rs b/taptrade-cli-demo/trader/src/wallet/bond.rs index d1d76ea..b05aa78 100644 --- a/taptrade-cli-demo/trader/src/wallet/bond.rs +++ b/taptrade-cli-demo/trader/src/wallet/bond.rs @@ -47,13 +47,13 @@ impl Bond { builder .add_recipient(address.script_pubkey(), bond_target.locking_amount_sat) - .do_not_spend_change() // reconsider if we need this? + // .do_not_spend_change() // reconsider if we need this? .fee_rate(FeeRate::from_sat_per_vb(201.0)); builder.finish()? }; debug!("Signing bond transaction."); - let finalized = wallet.sign(&mut psbt, SignOptions::default())?; // deactivated to test bond validation + let finalized = wallet.sign(&mut psbt, SignOptions::default())?; // deactivate to test bond validation if !finalized { return Err(anyhow!("Transaction could not be finalized")); }; diff --git a/taptrade-cli-demo/trader/taker.env b/taptrade-cli-demo/trader/taker.env index 1f1cc92..4c2d553 100644 --- a/taptrade-cli-demo/trader/taker.env +++ b/taptrade-cli-demo/trader/taker.env @@ -4,5 +4,5 @@ ROBOHASH_HEX="169b6049cf865eba7d01e1ad26975f1d5ff29d570297ff18d40a53c8281dff5d" TRADE_TYPE="sell" PAYOUT_ADDRESS="tb1pca4thykxsj4ura8h2pj3zx7v9hzlcvlw9k32u8m0vqs6mxp02c9qr9eup6" BOND_RATIO=5 -XPRV="tprv8ZgxMBicQKsPdHuCSjhQuSZP1h6ZTeiRqREYS5guGPdtL7D1uNLpnJmb2oJep99Esq1NbNZKVJBNnD2ZhuXSK7G5eFmmcx73gsoa65e2U32" # wallet xprv +XPRV="tprv8ZgxMBicQKsPdrVEng4ZxVWady4HcwJp34wDo5VmA34J5V2rUfPTeQbcsiTbx5YWZQKnSfCE5vLBtxcBjZafH5L1JJNHtjuVMDyBtDogfeG" # wallet xprv OFFER_DURATION_HOURS=48