gnunet-svn
[Top][All Lists]
Advanced

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

[taler-depolymerization] branch master updated (dac7fd3 -> 3e9cedb)


From: gnunet
Subject: [taler-depolymerization] branch master updated (dac7fd3 -> 3e9cedb)
Date: Thu, 10 Mar 2022 16:54:26 +0100

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

antoine pushed a change to branch master
in repository depolymerization.

    from dac7fd3  eth-wire: update default confirmation to 27 blocks
     new b9033f9  Small improvements
     new 3e9cedb  Improve documentation

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 +-
 README.md                          | 54 ++++++++++-----------
 btc-wire/src/loops/analysis.rs     |  1 -
 btc-wire/src/loops/watcher.rs      |  3 +-
 btc-wire/src/loops/worker.rs       |  1 +
 btc-wire/src/main.rs               |  1 +
 btc-wire/src/rpc.rs                |  2 +
 eth-wire/src/bin/eth-wire-utils.rs |  6 +--
 eth-wire/src/lib.rs                |  4 ++
 eth-wire/src/main.rs               |  3 +-
 eth-wire/src/rpc.rs                | 96 ++++++++++++++++++++++++--------------
 wire-gateway/src/main.rs           |  1 +
 12 files changed, 104 insertions(+), 72 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 6c4838d..5d93bf5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1905,9 +1905,9 @@ checksum = 
"360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
 
 [[package]]
 name = "tracing"
-version = "0.1.31"
+version = "0.1.32"
 source = "registry+https://github.com/rust-lang/crates.io-index";
-checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f"
+checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f"
 dependencies = [
  "cfg-if",
  "pin-project-lite",
diff --git a/README.md b/README.md
index 9476f3b..01618c5 100644
--- a/README.md
+++ b/README.md
@@ -181,26 +181,6 @@ BUMP_DELAY = 0
 8. Run wire-gateway `wire-gateway`
 9. Run eth-wire `eth-wire`
 
-## NGINX TODO
-
-```
-server {
-    location /btc-wire {
-        proxy_pass http://unix:$UNIX_PATH;
-    }
-}
-```
-
-or
-
-```
-server {
-    location /btc-wire {
-        proxy_pass http://localhost:$PORT;
-    }
-}
-```
-
 ## Security
 
 Depolymerizer only use an encrypted wallet and provide an easy way to create
@@ -211,11 +191,30 @@ Only the wire adapter need to have the password stored in 
its environment.
 
 ## Log format
 
-TODO
+Wire log use an ASCII code for transaction logs:
+
+- `<<` for an credit
+- `>>` for a debit
+- `||` for a bounce
+
+You can have an additional context:
+
+- `bump ` stuck transaction have been bumped
+- `conflict ` transaction have been canceled by a conflicting blockchain
+  transaction
+- `recovered ` successful transaction that we failed to register in the local
+  database have been found in the blockchain
+- `onchain ` unknown transaction have been found in the blockchain
 
 ## Test
 
-The following binaries need to be in the local user PATH:
+Instrumentation test documentation can be founded in the
+[instrumentation](instrumentation/README.md) directory.
+
+### Unit test
+
+Unit test require additional binaries. The following binaries must be in the
+local user PATH:
 
 - `pg_ctl` and `psql` from PostgreSQL
 - `geth` from [go-ethereum](https://geth.ethereum.org/downloads/)
@@ -228,8 +227,9 @@ You can use the [prepare](script/prepare.sh) script to 
downloads and extract
 blockchain binaries and find the path of the local postgres installation.
 However, taler binaries need to be compiled from source for now.
 
-TODO
-
-To also install test tools from source run: `make install_test`.
-
-To run all tests: `make test`.
+| Command             | Run                |
+| ------------------- | ------------------ |
+| `make test`         | all tests          |
+| `make test_gateway` | wire-gateway tests |
+| `make test_btc`     | btc-wire tests     |
+| `make test_eth`     | eth-wire tests     |
diff --git a/btc-wire/src/loops/analysis.rs b/btc-wire/src/loops/analysis.rs
index 423e780..32f64cc 100644
--- a/btc-wire/src/loops/analysis.rs
+++ b/btc-wire/src/loops/analysis.rs
@@ -23,7 +23,6 @@ use common::{
 };
 
 use crate::WireState;
-
 use super::LoopResult;
 
 /// Analyse blockchain behavior and adapt confirmations in real time
diff --git a/btc-wire/src/loops/watcher.rs b/btc-wire/src/loops/watcher.rs
index 815b9bd..8c9e2fd 100644
--- a/btc-wire/src/loops/watcher.rs
+++ b/btc-wire/src/loops/watcher.rs
@@ -1,5 +1,3 @@
-use std::time::Duration;
-
 /*
   This file is part of TALER
   Copyright (C) 2022 Taler Systems SA
@@ -17,6 +15,7 @@ use std::time::Duration;
 */
 use common::{log::log::error, reconnect::AutoReconnectDb};
 use btc_wire::rpc::AutoRpcCommon;
+use std::time::Duration;
 
 use super::LoopResult;
 
diff --git a/btc-wire/src/loops/worker.rs b/btc-wire/src/loops/worker.rs
index 07442ce..9d1800b 100644
--- a/btc-wire/src/loops/worker.rs
+++ b/btc-wire/src/loops/worker.rs
@@ -46,6 +46,7 @@ use crate::{
 
 use super::{LoopError, LoopResult};
 
+/// Synchronize local db with blockchain and perform transactions
 pub fn worker(mut rpc: AutoRpcWallet, mut db: AutoReconnectDb, state: 
&WireState) {
     let mut lifetime = state.lifetime;
     let mut status = true;
diff --git a/btc-wire/src/main.rs b/btc-wire/src/main.rs
index 52c8b39..5323238 100644
--- a/btc-wire/src/main.rs
+++ b/btc-wire/src/main.rs
@@ -175,4 +175,5 @@ fn run(config: Option<PathBuf>) {
         analysis(rpc_analysis, db_analysis, state)
     });
     worker(rpc_worker, db_worker, state);
+    info!("btc-wire stopped");
 }
diff --git a/btc-wire/src/rpc.rs b/btc-wire/src/rpc.rs
index 6b59fe9..786d21c 100644
--- a/btc-wire/src/rpc.rs
+++ b/btc-wire/src/rpc.rs
@@ -39,6 +39,7 @@ use crate::btc_config::{BitcoinConfig, BtcAuth};
 
 pub type AutoRpcWallet = AutoReconnect<(BitcoinConfig, &'static str), Rpc>;
 
+/// Create a reconnecting rpc connection with an unlocked wallet
 pub fn auto_rpc_wallet(config: BitcoinConfig, wallet: &'static str) -> 
AutoRpcWallet {
     AutoReconnect::new(
         (config, wallet),
@@ -58,6 +59,7 @@ pub fn auto_rpc_wallet(config: BitcoinConfig, wallet: 
&'static str) -> AutoRpcWa
 
 pub type AutoRpcCommon = AutoReconnect<BitcoinConfig, Rpc>;
 
+/// Create a reconnecting rpc connection
 pub fn auto_rpc_common(config: BitcoinConfig) -> AutoRpcCommon {
     AutoReconnect::new(
         config,
diff --git a/eth-wire/src/bin/eth-wire-utils.rs 
b/eth-wire/src/bin/eth-wire-utils.rs
index f6da903..69234c8 100644
--- a/eth-wire/src/bin/eth-wire-utils.rs
+++ b/eth-wire/src/bin/eth-wire-utils.rs
@@ -212,7 +212,7 @@ fn main() {
                     );
                     exit(1);
                 } else {
-                    std::thread::sleep(Duration::from_secs(1))
+                    std::thread::sleep(Duration::from_secs(5))
                 }
             }
         }
@@ -227,7 +227,7 @@ fn main() {
                 if start.elapsed() > Duration::from_secs(60) {
                     panic!("Connect timeout");
                 }
-                std::thread::sleep(Duration::from_secs(1))
+                std::thread::sleep(Duration::from_secs(5))
             }
         }
         Cmd::Disconnect { datadir } => {
@@ -241,7 +241,7 @@ fn main() {
                 if start.elapsed() > Duration::from_secs(60) {
                     panic!("Disconnect timeout");
                 }
-                std::thread::sleep(Duration::from_secs(1))
+                std::thread::sleep(Duration::from_secs(5))
             }
         }
         Cmd::Abandon { from } => {
diff --git a/eth-wire/src/lib.rs b/eth-wire/src/lib.rs
index 7971a8a..44d883d 100644
--- a/eth-wire/src/lib.rs
+++ b/eth-wire/src/lib.rs
@@ -41,7 +41,9 @@ pub mod rpc;
 mod rpc_utils;
 pub mod taler_util;
 
+/// An extended geth JSON-RPC api client who can send and retrieve metadata 
with their transaction
 pub trait RpcExtended: RpcClient {
+    /// Perform a Taler deposit
     fn deposit(
         &mut self,
         from: Address,
@@ -60,6 +62,7 @@ pub trait RpcExtended: RpcClient {
         })
     }
 
+    /// Perform a Taler withdraw
     fn withdraw(
         &mut self,
         from: Address,
@@ -79,6 +82,7 @@ pub trait RpcExtended: RpcClient {
         })
     }
 
+    /// Perform a Taler bounce
     fn bounce(&mut self, hash: H256, bounce_fee: U256) -> 
rpc::Result<Option<H256>> {
         let tx = self
             .get_transaction(&hash)?
diff --git a/eth-wire/src/main.rs b/eth-wire/src/main.rs
index 70b748e..a844491 100644
--- a/eth-wire/src/main.rs
+++ b/eth-wire/src/main.rs
@@ -17,7 +17,7 @@
 use std::path::PathBuf;
 
 use clap::StructOpt;
-use common::{named_spawn, password, postgres::NoTls, 
reconnect::auto_reconnect_db};
+use common::{named_spawn, password, postgres::NoTls, 
reconnect::auto_reconnect_db, log::log::info};
 use eth_wire::{
     load_taler_config,
     rpc::{auto_rpc_common, auto_rpc_wallet, Rpc, RpcClient},
@@ -163,4 +163,5 @@ fn run(config: Option<PathBuf>) {
     });
 
     worker(rpc_worker, db_worker, state);
+    info!("eth-wire stopped");
 }
diff --git a/eth-wire/src/rpc.rs b/eth-wire/src/rpc.rs
index f94d286..7766702 100644
--- a/eth-wire/src/rpc.rs
+++ b/eth-wire/src/rpc.rs
@@ -34,6 +34,7 @@ use self::hex::Hex;
 
 pub type AutoRpcWallet = AutoReconnect<(PathBuf, Address), Rpc>;
 
+/// Create a reconnecting rpc connection with an unlocked wallet
 pub fn auto_rpc_wallet(ipc_path: PathBuf, address: Address) -> AutoRpcWallet {
     AutoReconnect::new(
         (ipc_path, address),
@@ -52,6 +53,7 @@ pub fn auto_rpc_wallet(ipc_path: PathBuf, address: Address) 
-> AutoRpcWallet {
 
 pub type AutoRpcCommon = AutoReconnect<PathBuf, Rpc>;
 
+/// Create a reconnecting rpc connection
 pub fn auto_rpc_common(ipc_path: PathBuf) -> AutoRpcCommon {
     AutoReconnect::new(
         ipc_path,
@@ -99,9 +101,7 @@ pub type Result<T> = std::result::Result<T, Error>;
 
 const EMPTY: [(); 0] = [];
 
-pub trait RpcTrait {}
-
-/// Bitcoin RPC connection
+/// Ethereum RPC connection
 pub struct Rpc {
     id: u64,
     conn: BufWriter<UnixStream>,
@@ -110,6 +110,7 @@ pub struct Rpc {
 }
 
 impl Rpc {
+    /// Start a RPC connection, path can be datadir or ipc path
     pub fn new(path: impl AsRef<Path>) -> io::Result<Self> {
         let path = path.as_ref();
 
@@ -128,7 +129,6 @@ impl Rpc {
     }
 
     fn send(&mut self, method: &str, params: &impl serde::Serialize) -> 
Result<()> {
-        // TODO rethink timeout
         let request = RpcRequest {
             method,
             id: self.id,
@@ -146,6 +146,7 @@ impl Rpc {
         T: serde::de::DeserializeOwned + Debug,
     {
         loop {
+            // Double buffer size if full
             if self.cursor == self.read_buf.len() {
                 self.read_buf.resize(self.cursor * 2, 0);
             }
@@ -292,6 +293,7 @@ impl<N: Debug + DeserializeOwned> RpcClient for 
RpcStream<'_, N> {
     {
         self.rpc.send(method, params)?;
         loop {
+            // Buffer notifications until response
             let response: NotificationOrResponse<T, N> = self.rpc.receive()?;
             match response {
                 NotificationOrResponse::Notification(n) => {
@@ -312,22 +314,26 @@ pub trait RpcClient {
     where
         T: serde::de::DeserializeOwned + Debug;
 
+    /* ----- Account management ----- */
+
+    /// List registered acount
     fn list_accounts(&mut self) -> Result<Vec<Address>> {
         self.call("personal_listAccounts", &EMPTY)
     }
 
+    /// Create a new encrypted account
     fn new_account(&mut self, passwd: &str) -> Result<Address> {
         self.call("personal_newAccount", &[passwd])
     }
 
-    fn import_account(&mut self, hex: &str, passwd: &str) -> Result<bool> {
-        self.call("personal_importRawKey", &(hex, passwd))
-    }
-
+    /// Unlock an existinf acount
     fn unlock_account(&mut self, account: &Address, passwd: &str) -> 
Result<bool> {
         self.call("personal_unlockAccount", &(account, passwd, 0))
     }
 
+    /* ----- Getter ----- */
+
+    /// Get a transaction by hash
     fn get_transaction(&mut self, hash: &H256) -> Result<Option<Transaction>> {
         match self.call("eth_getTransactionByHash", &[hash]) {
             Err(Error::Null) => Ok(None),
@@ -335,21 +341,15 @@ pub trait RpcClient {
         }
     }
 
+    /// Get a transaction receipt by hash
     fn get_transaction_receipt(&mut self, hash: &H256) -> 
Result<Option<TransactionReceipt>> {
         match self.call("eth_getTransactionReceipt", &[hash]) {
             Err(Error::Null) => Ok(None),
             r => r,
         }
     }
-
-    fn fill_transaction(&mut self, req: &TransactionRequest) -> Result<Filled> 
{
-        self.call("eth_fillTransaction", &[req])
-    }
-
-    fn send_transaction(&mut self, req: &TransactionRequest) -> Result<H256> {
-        self.call("eth_sendTransaction", &[req])
-    }
-
+    
+    /// Get block by hash
     fn block(&mut self, hash: &H256) -> Result<Option<Block>> {
         match self.call("eth_getBlockByHash", &(hash, &true)) {
             Err(Error::Null) => Ok(None),
@@ -357,10 +357,46 @@ pub trait RpcClient {
         }
     }
 
+    /// Get pending transactions
     fn pending_transactions(&mut self) -> Result<Vec<Transaction>> {
         self.call("eth_pendingTransactions", &EMPTY)
     }
+    
+    /// Get latest block
+    fn latest_block(&mut self) -> Result<Block> {
+        self.call("eth_getBlockByNumber", &("latest", &true))
+    }
+
+    /// Get earliest block (genesis if not pruned)
+    fn earliest_block(&mut self) -> Result<Block> {
+        self.call("eth_getBlockByNumber", &("earliest", &true))
+    }
 
+    /// Get account balance
+    fn get_balance(&mut self, addr: &Address) -> Result<U256> {
+        self.call("eth_getBalance", &(addr, "latest"))
+    }
+
+    /// Get node info
+    fn node_info(&mut self) -> Result<NodeInfo> {
+        self.call("admin_nodeInfo", &EMPTY)
+    }
+
+    /* ----- Transactions ----- */
+
+    /// Fill missing options from transaction request with default values
+    fn fill_transaction(&mut self, req: &TransactionRequest) -> Result<Filled> 
{
+        self.call("eth_fillTransaction", &[req])
+    }
+
+    /// Send ethereum transaction
+    fn send_transaction(&mut self, req: &TransactionRequest) -> Result<H256> {
+        self.call("eth_sendTransaction", &[req])
+    }
+
+    /* ----- Miner ----- */
+
+    /// Start mining
     fn miner_start(&mut self) -> Result<()> {
         match self.call("miner_start", &[8]) {
             Err(Error::Null) => Ok(()),
@@ -368,6 +404,7 @@ pub trait RpcClient {
         }
     }
 
+    /// Stop mining
     fn miner_stop(&mut self) -> Result<()> {
         match self.call("miner_stop", &EMPTY) {
             Err(Error::Null) => Ok(()),
@@ -375,35 +412,22 @@ pub trait RpcClient {
         }
     }
 
-    fn latest_block(&mut self) -> Result<Block> {
-        self.call("eth_getBlockByNumber", &("latest", &true))
-    }
-
-    fn earliest_block(&mut self) -> Result<Block> {
-        self.call("eth_getBlockByNumber", &("earliest", &true))
-    }
-
-    fn get_balance(&mut self, addr: &Address) -> Result<U256> {
-        self.call("eth_getBalance", &(addr, "latest"))
-    }
-
     /* ----- Peer management ----- */
 
-    fn node_info(&mut self) -> Result<NodeInfo> {
-        self.call("admin_nodeInfo", &EMPTY)
-    }
-
+    /// Add peer to the peer list
     fn add_peer(&mut self, url: &Url) -> Result<bool> {
         self.call("admin_addPeer", &[url])
     }
 
+    /// Remove a peer to the peer list
     fn remove_peer(&mut self, url: &Url) -> Result<bool> {
         self.call("admin_removePeer", &[url])
     }
 
-    fn count_peer(&mut self) -> Result<usize> {
-        let peers: Vec<Nothing> = self.call("admin_peers", &EMPTY)?;
-        Ok(peers.len())
+    /// Get peer count
+    fn count_peer(&mut self) -> Result<u32> {
+        let peers: U64 = self.call("net_peerCount", &EMPTY)?;
+        Ok(peers.as_u32())
     }
 }
 
diff --git a/wire-gateway/src/main.rs b/wire-gateway/src/main.rs
index 45ee186..35e20f1 100644
--- a/wire-gateway/src/main.rs
+++ b/wire-gateway/src/main.rs
@@ -217,6 +217,7 @@ async fn main() {
             error!("server: {}", e);
         }
     };
+    info!("wire-gateway stopped");
 }
 
 /// Check if an url if a valid payto url for the configured currency

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