gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-depolymerization] branch master updated (485e60e -> 60e4b9b)


From: gnunet
Subject: [taler-depolymerization] branch master updated (485e60e -> 60e4b9b)
Date: Wed, 09 Feb 2022 19:10:55 +0100

This is an automated email from the git hooks/post-receive script.

antoine pushed a change to branch master
in repository depolymerization.

    from 485e60e  presentation: progress
     new 0c9b922  eth-wire: move bump out of sync_chain to prevent stuck 
synchronization caused by excessive transaction fees
     new 60e4b9b  Fix worker loop continuing when stuck on removed transactions

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Cargo.lock                   |  4 +--
 btc-wire/src/loops/worker.rs | 73 +++++++++++++++++++++++++-------------------
 docs/presentation.tex        |  4 +--
 eth-wire/src/loops/worker.rs | 15 +++++----
 test/btc/hell.sh             | 18 +++++++----
 test/common.sh               |  4 +--
 test/eth/hell.sh             | 16 +++++++---
 7 files changed, 78 insertions(+), 56 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 678145b..0ad9236 100644
--- 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
index 85dd8ee..0e3080e 100644
--- a/btc-wire/src/loops/worker.rs
+++ b/btc-wire/src/loops/worker.rs
@@ -97,16 +97,32 @@ pub fn worker(mut rpc: AutoReconnectRPC, mut db: 
AutoReconnectDb, state: &WireSt
             }
 
             // Sync chain
-            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
+                for id in stuck {
+                    let bump = rpc.bump_fee(&id)?;
+                    fail_point("(injected) fail bump", 0.3)?;
+                    let row = db.query_one(
+                        "UPDATE tx_out SET txid=$1 WHERE txid=$2 RETURNING 
wtid",
+                        &[&bump.txid.as_ref(), &id.as_ref()],
+                    )?;
+                    info!(
+                        ">> (bump) {} replace {} with {}",
+                        base32(row.get(0)),
+                        id,
+                        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(())
         })();
@@ -133,13 +149,13 @@ fn last_hash(db: &mut Client) -> Result<BlockHash, 
postgres::Error> {
     Ok(BlockHash::from_slice(row.get(0)).unwrap())
 }
 
-/// Parse new transactions, return true if the database is up to date with the 
latest mined block
+/// Parse new transactions, return stuck transactions if the database is up to 
date with the latest mined block
 fn sync_chain(
     rpc: &mut Rpc,
     db: &mut Client,
     state: &WireState,
     status: &mut bool,
-) -> LoopResult<bool> {
+) -> LoopResult<Option<Vec<Txid>>> {
     // Get stored last_hash
     let last_hash = last_hash(db)?;
     let min_confirmations = state.confirmation.load(Ordering::SeqCst);
@@ -184,12 +200,18 @@ fn sync_chain(
         }
     }
     if !new_status {
-        return Ok(false);
+        return Ok(None);
     }
 
+    let mut stuck = vec![];
+
     for (id, (category, confirmations)) in txs {
         match category {
-            Category::Send => sync_chain_outgoing(&id, confirmations, rpc, db, 
state)?,
+            Category::Send => {
+                if sync_chain_outgoing(&id, confirmations, rpc, db, state)? {
+                    stuck.push(id);
+                }
+            }
             Category::Receive if confirmations >= min_confirmations as i32 => {
                 sync_chain_incoming_confirmed(&id, rpc, db)?
             }
@@ -205,7 +227,7 @@ fn sync_chain(
         &[&lastblock.as_ref()],
     )?;
 
-    Ok(true)
+    Ok(Some(stuck))
 }
 
 /// Sync database with removed transactions, return false if bitcoin backing 
is compromised
@@ -325,7 +347,7 @@ fn sync_chain_incoming_confirmed(
     Ok(())
 }
 
-/// Sync database with an outgoing withdraw transaction
+/// Sync database with an outgoing withdraw transaction, return true if stuck
 fn sync_chain_withdraw(
     id: &Txid,
     full: &TransactionFull,
@@ -334,7 +356,7 @@ fn sync_chain_withdraw(
     db: &mut Client,
     confirmations: i32,
     state: &WireState,
-) -> LoopResult<()> {
+) -> LoopResult<bool> {
     let credit_addr = full.details[0].address.as_ref().unwrap();
     let amount = btc_to_taler(&full.amount);
 
@@ -431,23 +453,12 @@ fn sync_chain_withdraw(
                     .unwrap()
                     .as_secs();
                 if now - full.time > delay as u64 {
-                    let bump = rpc.bump_fee(id)?;
-                    fail_point("(injected) fail bump", 0.3)?;
-                    db.execute(
-                        "UPDATE tx_out SET txid=$1 WHERE txid=$2",
-                        &[&bump.txid.as_ref(), &id.as_ref()],
-                    )?;
-                    info!(
-                        ">> (bump) {} replace {} with {}",
-                        base32(wtid),
-                        id,
-                        bump.txid
-                    );
+                    return Ok(true);
                 }
             }
         }
     }
-    Ok(())
+    Ok(false)
 }
 
 /// Sync database with an outgoing bounce transaction
@@ -507,21 +518,21 @@ fn sync_chain_bounce(
     Ok(())
 }
 
-/// Sync database with an outgoing transaction
+/// Sync database with an outgoing transaction, return true if stuck
 fn sync_chain_outgoing(
     id: &Txid,
     confirmations: i32,
     rpc: &mut Rpc,
     db: &mut Client,
     state: &WireState,
-) -> LoopResult<()> {
+) -> LoopResult<bool> {
     match rpc
         .get_tx_op_return(id)
         .map(|(full, bytes)| (full, OutMetadata::decode(&bytes)))
     {
         Ok((full, Ok(info))) => match info {
             OutMetadata::Withdraw { wtid, .. } => {
-                sync_chain_withdraw(id, &full, &wtid, rpc, db, confirmations, 
state)?
+                return sync_chain_withdraw(id, &full, &wtid, rpc, db, 
confirmations, state);
             }
             OutMetadata::Bounce { bounced } => sync_chain_bounce(id, &bounced, 
db, confirmations)?,
         },
@@ -531,7 +542,7 @@ fn sync_chain_outgoing(
             GetOpReturnErr::RPC(e) => return Err(e)?,
         },
     }
-    Ok(())
+    Ok(false)
 }
 
 /// Send a withdraw transaction on the blockchain, return false if no more 
requested transaction are found
diff --git a/docs/presentation.tex b/docs/presentation.tex
index 67d1410..3c0e0b2 100644
--- a/docs/presentation.tex
+++ b/docs/presentation.tex
@@ -318,8 +318,8 @@
             \node[rect, right= 1cm of wa1](wo1) {Wait for notification};
             \node[rect, below=4mm of wo1](wo2) {Synchronize chain};
             \node[rect, below=4mm of wo2](wo3) {Withdraw};
-            \node[rect, below=4mm of wo3](wo4) {Bounce};
-            \node[rect, below=4mm of wo4](wo5) {Bump};
+            \node[rect, below=4mm of wo3](wo4) {Bump};
+            \node[rect, below=4mm of wo4](wo5) {Bounce};
             \node[above=1mm of wo1]{Worker};
             \draw[-stealth] (wo1) -- (wo2);
             \draw[-stealth] (wo2) -- (wo3);
diff --git a/eth-wire/src/loops/worker.rs b/eth-wire/src/loops/worker.rs
index 0a245c6..5dda0ed 100644
--- 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
index 67559fa..6672b43 100644
--- 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
index 5de7477..1e0dfbf 100644
--- 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
index 115f700..eb767ca 100644
--- 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"
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]