depolymerization

wire gateway for Bitcoin/Ethereum
Log | Files | Refs | Submodules | README | LICENSE

commit 60e4b9be19afea1a91e0b29cf4ff14af6f41dbfa
parent 0c9b92207adf196edbbca426830d6ffd4ad2032f
Author: Antoine A <>
Date:   Wed,  9 Feb 2022 18:53:23 +0100

Fix worker loop continuing when stuck on removed transactions

Diffstat:
MCargo.lock | 4++--
Mbtc-wire/src/loops/worker.rs | 20+++++++++-----------
Meth-wire/src/loops/worker.rs | 15+++++++--------
Mtest/btc/hell.sh | 18++++++++++++------
Mtest/common.sh | 4++--
Mtest/eth/hell.sh | 16+++++++++++-----
6 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -760,9 +760,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" +checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" [[package]] name = "httpdate" diff --git a/btc-wire/src/loops/worker.rs b/btc-wire/src/loops/worker.rs @@ -97,15 +97,13 @@ pub fn worker(mut rpc: AutoReconnectRPC, mut db: AutoReconnectDb, state: &WireSt } // Sync chain - let stuck = sync_chain(rpc, db, state, &mut status)?; + if let Some(stuck) = sync_chain(rpc, db, state, &mut status)? { + // As we are now in sync with the blockchain if a transaction has Requested status it have not been sent - // As we are now in sync with the blockchain if a transaction has Requested status it have not been sent + // Send requested withdraws + while withdraw(db, rpc)? {} - // Send requested withdraws - while withdraw(db, rpc)? {} - - // Bump stuck transactions - if let Some(stuck) = stuck { + // Bump stuck transactions for id in stuck { let bump = rpc.bump_fee(&id)?; fail_point("(injected) fail bump", 0.3)?; @@ -120,11 +118,11 @@ pub fn worker(mut rpc: AutoReconnectRPC, mut db: AutoReconnectDb, state: &WireSt bump.txid ); } - } - let bounce_fee = BtcAmount::from_sat(state.config.bounce_fee); - // Send requested bounce - while bounce(db, rpc, &bounce_fee)? {} + let bounce_fee = BtcAmount::from_sat(state.config.bounce_fee); + // Send requested bounce + while bounce(db, rpc, &bounce_fee)? {} + } Ok(()) })(); diff --git a/eth-wire/src/loops/worker.rs b/eth-wire/src/loops/worker.rs @@ -88,16 +88,15 @@ pub fn worker(mut rpc: AutoReconnectRPC, mut db: AutoReconnectDb, state: &WireSt } // Sync chain - sync_chain(rpc, db, state, &mut status)?; + if sync_chain(rpc, db, state, &mut status)? { + // As we are now in sync with the blockchain if a transaction has Requested status it have not been sent - // As we are now in sync with the blockchain if a transaction has Requested status it have not been sent - - // Send requested withdraws - while withdraw(db, rpc, state)? {} - - // Send requested bounce - while bounce(db, rpc, U256::from(state.config.bounce_fee))? {} + // Send requested withdraws + while withdraw(db, rpc, state)? {} + // Send requested bounce + while bounce(db, rpc, U256::from(state.config.bounce_fee))? {} + } Ok(()) })(); diff --git a/test/btc/hell.sh b/test/btc/hell.sh @@ -45,14 +45,17 @@ echo -n "Generate conflict:" restart_btc -minrelaytxfee=0.0001 $WIRE_UTILS abandon client $WIRE_UTILS transfer 0.0054 > /dev/null -next_btc +mine_btc check_balance 9.99457382 0.00540000 echo " OK" -echo -n "Check btc-wire have not read the conflicting transaction:" +echo -n "Check btc-wire suspend function:" sleep 5 # Wait for reconnection +$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.0042 > /dev/null +next_btc +sleep 1 gateway_down -check_balance 9.99457382 0.00540000 +check_balance 9.99035972 0.00960000 # Not bounced echo " OK" # Recover by paying for the customer ? @@ -97,14 +100,17 @@ echo -n "Generate conflict:" restart_btc -minrelaytxfee=0.0001 $WIRE_UTILS abandon client $WIRE_UTILS transfer 0.054 > /dev/null -next_btc +mine_btc check_balance 9.94597382 0.05400000 echo " OK" -echo -n "Check btc-wire have not read the conflicting transaction:" +echo -n "Check btc-wire suspend function:" sleep 5 # Wait for reconnection +$BTC_CLI -rpcwallet=client sendtoaddress $WIRE 0.0042 > /dev/null +next_btc +sleep 1 gateway_down -check_balance 9.94597382 0.05400000 +check_balance 9.94175972 0.05820000 # Not bounced echo " OK" diff --git a/test/common.sh b/test/common.sh @@ -257,7 +257,7 @@ function init_eth() { # Initialize blockchain $ETH_CLI init $DIR/genesis.json &>> log/node.log # Start node - $ETH_CLI --miner.recommit 0s --miner.gasprice 0 $* &>> log/node.log & + $ETH_CLI --miner.gasprice 0 $* &>> log/node.log & NODE_PID="$!" sleep 1 # Create wire address @@ -270,7 +270,7 @@ function init_eth2() { # Initialize blockchain $ETH_CLI2 init $DIR/genesis.json &>> log/node2.log # Start node - $ETH_CLI2 --port 30305 --miner.recommit 0s --miner.gasprice 0 $* &>> log/node2.log & + $ETH_CLI2 --port 30305 --miner.gasprice 0 $* &>> log/node2.log & sleep 1 # Create etherbase account for mining $ETH_CLI2 account new --password <(echo "password") &> /dev/null diff --git a/test/eth/hell.sh b/test/eth/hell.sh @@ -47,9 +47,12 @@ next_eth 5 check_balance_eth 999999999 0 echo " OK" -echo -n "Check eth-wire have not read the conflicting transaction:" +echo -n "Check eth-wire suspend function:" gateway_down -check_balance_eth 999999999 0 +$WIRE_UTILS send $CLIENT $WIRE 0.000 42 +next_eth 6 +sleep 1 +check_balance_eth 999957999 42000 # Not bounced echo " OK" # Recover by paying for the customer ? @@ -79,8 +82,8 @@ eth_deco echo -n "Bounce:" $WIRE_UTILS send $CLIENT $WIRE 0.00 42 -sleep 1 next_eth 6 +sleep 1 check_balance_eth 999999000 1000 echo " OK" @@ -97,9 +100,12 @@ next_eth 5 check_balance_eth 999999999 0 echo " OK" -echo -n "Check eth-wire have not read the conflicting transaction:" +echo -n "Check eth-wire suspend function:" +$WIRE_UTILS send $CLIENT $WIRE 0.000 42 +next_eth 6 +sleep 1 gateway_down -check_balance_eth 999999999 0 +check_balance_eth 999957999 42000 # Not bounced echo " OK"