gnunet-svn
[Top][All Lists]
Advanced

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

[taler-depolymerization] branch master updated (5362e27 -> 3b39a25)


From: gnunet
Subject: [taler-depolymerization] branch master updated (5362e27 -> 3b39a25)
Date: Wed, 23 Feb 2022 12:24:33 +0100

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

antoine pushed a change to branch master
in repository depolymerization.

    from 5362e27  instrumentation: new instrumentation test
     new 8928134  Fix test
     new 3b39a25  Fix broken pipe when waiting for new block on real bitcoin 
blockchain

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:
 btc-wire/src/bin/btc-wire-utils.rs |  2 +-
 btc-wire/src/loops/watcher.rs      |  2 +-
 btc-wire/src/rpc.rs                | 15 +++++++++++--
 instrumentation/src/main.rs        | 44 ++++++++++++++++----------------------
 test/common.sh                     |  2 +-
 5 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/btc-wire/src/bin/btc-wire-utils.rs 
b/btc-wire/src/bin/btc-wire-utils.rs
index 7ad09b3..8075d67 100644
--- a/btc-wire/src/bin/btc-wire-utils.rs
+++ b/btc-wire/src/bin/btc-wire-utils.rs
@@ -113,7 +113,7 @@ fn main() {
                 }
                 _ => {
                     // Wait for next network block
-                    rpc.wait_for_new_block(0).ok();
+                    rpc.wait_for_new_block().ok();
                 }
             }
         }
diff --git a/btc-wire/src/loops/watcher.rs b/btc-wire/src/loops/watcher.rs
index 50c0039..2d24b6e 100644
--- a/btc-wire/src/loops/watcher.rs
+++ b/btc-wire/src/loops/watcher.rs
@@ -25,7 +25,7 @@ pub fn watcher(mut rpc: AutoRpcCommon, mut db: 
AutoReconnectDb) {
         let db = db.client();
         let result: LoopResult<()> = (|| loop {
             db.execute("NOTIFY new_block", &[])?;
-            rpc.wait_for_new_block(0)?;
+            rpc.wait_for_new_block()?;
         })();
         if let Err(e) = result {
             error!("watcher: {}", e);
diff --git a/btc-wire/src/rpc.rs b/btc-wire/src/rpc.rs
index 8fe8121..72c904d 100644
--- a/btc-wire/src/rpc.rs
+++ b/btc-wire/src/rpc.rs
@@ -373,8 +373,14 @@ impl Rpc {
     /* ----- Watcher ----- */
 
     /// Block until a new block is mined
-    pub fn wait_for_new_block(&mut self, timeout: u64) -> Result<Nothing> {
-        self.call("waitfornewblock", &[timeout])
+    pub fn wait_for_new_block(&mut self) -> Result<()> {
+        let init_height = self.get_blockchain_info()?.blocks;
+        loop {
+            let info: BlockInfo = self.call("waitfornewblock", &[10])?;
+            if info.blocks != init_height {
+                return Ok(());
+            }
+        }
     }
 
     /// List new and removed transaction since a block
@@ -399,6 +405,11 @@ pub struct BlockchainInfo {
     pub best_block_hash: BlockHash,
 }
 
+#[derive(Clone, Debug, serde::Deserialize)]
+struct BlockInfo {
+    pub blocks: u64,
+}
+
 #[derive(Debug, serde::Deserialize)]
 pub struct BumpResult {
     pub txid: Txid,
diff --git a/instrumentation/src/main.rs b/instrumentation/src/main.rs
index 1f0f8a5..70414c5 100644
--- a/instrumentation/src/main.rs
+++ b/instrumentation/src/main.rs
@@ -16,7 +16,7 @@
 
 use std::{fmt::Display, io::Write, path::PathBuf};
 
-use bitcoin::{Amount, BlockHash, Network, SignedAmount};
+use bitcoin::{Amount, Network, SignedAmount};
 use btc_wire::{
     config::BitcoinConfig,
     config_bounce_fee,
@@ -46,24 +46,6 @@ fn print_now(disp: impl Display) {
     std::io::stdout().flush().unwrap();
 }
 
-fn wait_while_pending(rpc: &mut Rpc, wallet: &str, since: &mut BlockHash) {
-    print_now(format_args!("Skip pending {}:", wallet));
-    let mut pending = true;
-    while pending {
-        pending = false;
-        rpc.wait_for_new_block(0).unwrap();
-        print_now(".");
-        let sync = rpc.list_since_block(Some(&since), 1).unwrap();
-        for tx in sync.transactions {
-            if tx.confirmations == 0 {
-                pending = true;
-            }
-        }
-        *since = sync.lastblock;
-    }
-    println!("");
-}
-
 /// Depolymerizer instrumentation test
 #[derive(clap::Parser, Debug)]
 struct Args {
@@ -118,7 +100,7 @@ pub fn main() {
                 println!("Client need a minimum of {} BTC to run this test, 
send coins to this address: {}", min_fund.as_btc(), client_addr);
                 print_now("Waiting for fund:");
                 while client_rpc.get_balance().unwrap() < min_fund {
-                    client_rpc.wait_for_new_block(0).unwrap();
+                    client_rpc.wait_for_new_block().unwrap();
                     print_now(".");
                 }
             }
@@ -138,9 +120,6 @@ pub fn main() {
             };
             let mut wire_rpc = Rpc::wallet(&btc_config, WIRE).unwrap();
             let wire_addr = wire_rpc.gen_addr().unwrap();
-            // Skip pending
-            wait_while_pending(&mut client_rpc, CLIENT, &mut since);
-            wait_while_pending(&mut wire_rpc, WIRE, &mut since);
             // Load balances
             let client_balance = client_rpc.get_balance().unwrap();
             let wire_balance = wire_rpc.get_balance().unwrap();
@@ -185,7 +164,7 @@ pub fn main() {
             let mut bounced_id = None;
             while pending || bounced_id.is_none() {
                 pending = false;
-                rpc.wait_for_new_block(0).unwrap();
+                rpc.wait_for_new_block().unwrap();
                 print_now(".");
                 let sync = client_rpc.list_since_block(Some(&since), 
1).unwrap();
                 for tx in sync.transactions {
@@ -257,7 +236,22 @@ pub fn main() {
                     credit_account: btc_payto_url(&client_addr),
                 })
                 .unwrap();
-            wait_while_pending(&mut wire_rpc, WIRE, &mut since);
+
+            print_now("Wait for mining:");
+            let mut pending = true;
+            while pending {
+                pending = false;
+                rpc.wait_for_new_block().unwrap();
+                print_now(".");
+                let sync = rpc.list_since_block(Some(&since), 1).unwrap();
+                for tx in sync.transactions {
+                    if tx.confirmations == 0 {
+                        pending = true;
+                    }
+                }
+                since = sync.lastblock;
+            }
+            println!("");
 
             // Check balances change
             let last_client_balance = client_rpc.get_balance().unwrap();
diff --git a/test/common.sh b/test/common.sh
index 960b43d..83c3b13 100644
--- a/test/common.sh
+++ b/test/common.sh
@@ -362,7 +362,7 @@ function next_eth() {
 # Start wire-gateway in test mode
 function gateway() {
     cargo build --bin wire-gateway --release --features test &> /dev/null
-    target/release/wire-gateway $CONF &>> log/gateway.log & 
+    target/release/wire-gateway -c $CONF &>> log/gateway.log & 
     GATEWAY_PID="$!"
     for n in `seq 1 50`; do
         echo -n "."

-- 
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]