[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-depolymerization] branch master updated (42c8009 -> 9d00fd8)
From: |
gnunet |
Subject: |
[taler-depolymerization] branch master updated (42c8009 -> 9d00fd8) |
Date: |
Mon, 21 Mar 2022 17:50:00 +0100 |
This is an automated email from the git hooks/post-receive script.
antoine pushed a change to branch master
in repository depolymerization.
from 42c8009 Add missing figures
new 471390e report progress
new 9d00fd8 remove all occurrence of withdraw and deposit
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/README.md | 2 +-
btc-wire/src/bin/btc-wire-utils.rs | 2 +-
btc-wire/src/loops/worker.rs | 56 +++++++++++++++----------------
common/src/metadata.rs | 20 +++++------
common/src/status.rs | 16 ++++-----
docs/figures/depolymerizer_arch.tex | 21 ++++++++++++
docs/report.tex | 63 ++++++++++++++++++++++++++++++-----
eth-wire/README.md | 2 +-
eth-wire/src/bin/eth-wire-utils.rs | 8 ++---
eth-wire/src/lib.rs | 12 +++----
eth-wire/src/loops/worker.rs | 66 +++++++++++++++++--------------------
instrumentation/src/btc.rs | 6 ++--
instrumentation/src/eth.rs | 8 ++---
test/btc/hell.sh | 2 +-
test/eth/analysis.sh | 4 +--
test/eth/bumpfee.sh | 2 +-
test/eth/hell.sh | 4 +--
test/eth/lifetime.sh | 2 +-
test/eth/maxfee.sh | 2 +-
test/eth/reconnect.sh | 4 +--
test/eth/reorg.sh | 2 +-
test/eth/stress.sh | 2 +-
test/eth/wire.sh | 2 +-
23 files changed, 185 insertions(+), 123 deletions(-)
create mode 100644 docs/figures/depolymerizer_arch.tex
diff --git a/btc-wire/README.md b/btc-wire/README.md
index 0a2fd9b..9e281f7 100644
--- a/btc-wire/README.md
+++ b/btc-wire/README.md
@@ -3,7 +3,7 @@
btc-wire is taler wire adapter for
[bitcoincore](https://bitcoincore.org/en/about/) node
-## Deposit metadata format
+## Credit metadata format
Starting from a bitcoin payto URI you will have to generate fake segwit
addresses to encode the reserve public key as metadata into a common bitcoin
diff --git a/btc-wire/src/bin/btc-wire-utils.rs
b/btc-wire/src/bin/btc-wire-utils.rs
index 841df85..7520874 100644
--- a/btc-wire/src/bin/btc-wire-utils.rs
+++ b/btc-wire/src/bin/btc-wire-utils.rs
@@ -40,7 +40,7 @@ struct Args {
#[derive(clap::Subcommand, Debug)]
enum Cmd {
- /// Send taler deposit transactions
+ /// Perform wire credit transactions
Transfer {
#[clap(short, long, default_value_t = String::from("client"))]
/// sender wallet
diff --git a/btc-wire/src/loops/worker.rs b/btc-wire/src/loops/worker.rs
index aeb56b9..7ab6390 100644
--- a/btc-wire/src/loops/worker.rs
+++ b/btc-wire/src/loops/worker.rs
@@ -34,7 +34,7 @@ use common::{
postgres,
reconnect::AutoReconnectDb,
sql::{sql_array, sql_url},
- status::{BounceStatus, WithdrawStatus},
+ status::{BounceStatus, DebitStatus},
};
use postgres::{fallible_iterator::FallibleIterator, Client};
@@ -101,8 +101,8 @@ pub fn worker(mut rpc: AutoRpcWallet, mut db:
AutoReconnectDb, state: &WireState
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
- // Send requested withdraws
- while withdraw(db, rpc, state)? {}
+ // Send requested debits
+ while debit(db, rpc, state)? {}
// Bump stuck transactions
for id in stuck {
@@ -239,13 +239,13 @@ fn sync_chain_removed(
db: &mut Client,
min_confirmations: i32,
) -> LoopResult<bool> {
- // Removed transactions are correctness issues in only two cases:
- // - An incoming valid transaction considered confirmed in the database
- // - An incoming invalid transactions already bounced
+ // A removed incoming transaction is a correctness issues in only two
cases:
+ // - it is a confirmed credit registered in the database
+ // - it is an invalid transactions already bounced
// Those two cases can compromise bitcoin backing
// Removed outgoing transactions will be retried automatically by the node
- let mut blocking_deposit = Vec::new();
+ let mut blocking_debit = Vec::new();
let mut blocking_bounce = Vec::new();
// Only keep incoming transaction that are not reconfirmed
@@ -259,13 +259,13 @@ fn sync_chain_removed(
}) {
match rpc.get_tx_segwit_key(id) {
Ok((full, key)) => {
- // Deposit are only problematic if not reconfirmed and stored
in the database
+ // Credits are only problematic if not reconfirmed and stored
in the database
if db
.query_opt("SELECT 1 FROM tx_in WHERE reserve_pub=$1",
&[&key.as_ref()])?
.is_some()
{
let debit_addr = sender_address(rpc, &full)?;
- blocking_deposit.push((key, id, debit_addr));
+ blocking_debit.push((key, id, debit_addr));
}
}
Err(err) => match err {
@@ -286,12 +286,12 @@ fn sync_chain_removed(
}
}
- if !blocking_bounce.is_empty() || !blocking_deposit.is_empty() {
+ if !blocking_bounce.is_empty() || !blocking_debit.is_empty() {
let mut buf = "The following transaction have been removed from the
blockchain, bitcoin backing is compromised until the transaction
reappear:".to_string();
- for (key, id, addr) in blocking_deposit {
+ for (key, id, addr) in blocking_debit {
write!(
&mut buf,
- "\n\tdeposit {} in {} from {}",
+ "\n\tcredit {} in {} from {}",
base32(&key),
id,
addr
@@ -349,8 +349,8 @@ fn sync_chain_incoming_confirmed(
Ok(())
}
-/// Sync database with an outgoing withdraw transaction, return true if stuck
-fn sync_chain_withdraw(
+/// Sync database with a debit transaction, return true if stuck
+fn sync_chain_debit(
id: &Txid,
full: &Transaction,
wtid: &[u8; 32],
@@ -367,7 +367,7 @@ fn sync_chain_withdraw(
// Handle conflicting tx
let nb_row = db.execute(
"UPDATE tx_out SET status=$1, txid=NULL where txid=$2",
- &[&(WithdrawStatus::Requested as i16), &id.as_ref()],
+ &[&(DebitStatus::Requested as i16), &id.as_ref()],
)?;
if nb_row > 0 {
warn!(
@@ -388,12 +388,12 @@ fn sync_chain_withdraw(
// If already in database, sync status
let row_id: i32 = row.get(0);
let status: i16 = row.get(1);
- match WithdrawStatus::try_from(status as u8).unwrap() {
- WithdrawStatus::Requested => {
+ match DebitStatus::try_from(status as u8).unwrap() {
+ DebitStatus::Requested => {
let nb_row = db.execute(
"UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3 AND
status=$4",
&[
- &(WithdrawStatus::Sent as i16),
+ &(DebitStatus::Sent as i16),
&id.as_ref(),
&row_id,
&status,
@@ -409,7 +409,7 @@ fn sync_chain_withdraw(
);
}
}
- WithdrawStatus::Sent => {
+ DebitStatus::Sent => {
if let Some(txid) = full.replaces_txid {
let stored_id = sql_txid(&row, 2);
if txid == stored_id {
@@ -435,7 +435,7 @@ fn sync_chain_withdraw(
let date = SystemTime::UNIX_EPOCH + Duration::from_secs(full.time);
let nb = db.execute(
"INSERT INTO tx_out (_date, amount, wtid, debit_acc,
credit_acc, exchange_url, status, txid, request_uid) VALUES ($1, $2, $3, $4,
$5, $6, $7, $8, $9) ON CONFLICT (wtid) DO NOTHING",
- &[&date, &amount.to_string(), &wtid.as_ref(),
&btc_payto_url(&debit_addr).as_ref(), &btc_payto_url(credit_addr).as_ref(),
&state.base_url.as_ref(), &(WithdrawStatus::Sent as i16), &id.as_ref(),
&None::<&[u8]>],
+ &[&date, &amount.to_string(), &wtid.as_ref(),
&btc_payto_url(&debit_addr).as_ref(), &btc_payto_url(credit_addr).as_ref(),
&state.base_url.as_ref(), &(DebitStatus::Sent as i16), &id.as_ref(),
&None::<&[u8]>],
)?;
if nb > 0 {
warn!(
@@ -534,8 +534,8 @@ fn sync_chain_outgoing(
.map(|(full, bytes)| (full, OutMetadata::decode(&bytes)))
{
Ok((full, Ok(info))) => match info {
- OutMetadata::Withdraw { wtid, .. } => {
- return sync_chain_withdraw(id, &full, &wtid, rpc, db,
confirmations, state);
+ OutMetadata::Debit { wtid, .. } => {
+ return sync_chain_debit(id, &full, &wtid, rpc, db,
confirmations, state);
}
OutMetadata::Bounce { bounced } => {
sync_chain_bounce(id, &Txid::from_inner(bounced), db,
confirmations)?
@@ -550,12 +550,12 @@ fn sync_chain_outgoing(
Ok(false)
}
-/// Send a withdraw transaction on the blockchain, return false if no more
requested transactions are found
-fn withdraw(db: &mut Client, rpc: &mut Rpc, state: &WireState) ->
LoopResult<bool> {
+/// Send a debit transaction on the blockchain, return false if no more
requested transactions are found
+fn debit(db: &mut Client, rpc: &mut Rpc, state: &WireState) ->
LoopResult<bool> {
// We rely on the advisory lock to ensure we are the only one sending
transactions
let row = db.query_opt(
"SELECT id, amount, wtid, credit_acc, exchange_url FROM tx_out WHERE
status=$1 ORDER BY _date LIMIT 1",
- &[&(WithdrawStatus::Requested as i16)],
+ &[&(DebitStatus::Requested as i16)],
)?;
if let Some(row) = &row {
let id: i32 = row.get(0);
@@ -563,13 +563,13 @@ fn withdraw(db: &mut Client, rpc: &mut Rpc, state:
&WireState) -> LoopResult<boo
let wtid: [u8; 32] = sql_array(row, 2);
let addr = sql_addr(row, 3);
let url = sql_url(row, 4);
- let metadata = OutMetadata::Withdraw { wtid, url };
+ let metadata = OutMetadata::Debit { wtid, url };
let tx_id = rpc.send(&addr, &amount, Some(&metadata.encode()), false)?;
- fail_point("(injected) fail withdraw", 0.3)?;
+ fail_point("(injected) fail debit", 0.3)?;
db.execute(
"UPDATE tx_out SET status=$1, txid=$2 WHERE id=$3",
- &[&(WithdrawStatus::Sent as i16), &tx_id.as_ref(), &id],
+ &[&(DebitStatus::Sent as i16), &tx_id.as_ref(), &id],
)?;
let amount = btc_to_taler(&amount.to_signed().unwrap(),
state.currency);
info!(">> {} {} in {} to {}", amount, base32(&wtid), tx_id, addr);
diff --git a/common/src/metadata.rs b/common/src/metadata.rs
index 8e0730b..d38594a 100644
--- a/common/src/metadata.rs
+++ b/common/src/metadata.rs
@@ -31,7 +31,7 @@ pub enum DecodeErr {
/// Encoded metadata for outgoing transaction
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OutMetadata {
- Withdraw { wtid: [u8; 32], url: Url },
+ Debit { wtid: [u8; 32], url: Url },
Bounce { bounced: [u8; 32] },
}
@@ -42,7 +42,7 @@ impl OutMetadata {
pub fn encode(&self) -> Vec<u8> {
let mut buffer = Vec::new();
match self {
- OutMetadata::Withdraw { wtid, url } => {
+ OutMetadata::Debit { wtid, url } => {
buffer.push(if url.scheme() == "http" { 1 } else { 0 });
buffer.extend_from_slice(wtid);
let parts = format!("{}{}", url.domain().unwrap_or(""),
url.path());
@@ -72,7 +72,7 @@ impl OutMetadata {
uri_pack::unpack_uri(&bytes[33..])?,
);
let url = Url::parse(&packed).unwrap();
- Ok(OutMetadata::Withdraw {
+ Ok(OutMetadata::Debit {
wtid: bytes[1..33].try_into().unwrap(),
url,
})
@@ -93,14 +93,14 @@ impl OutMetadata {
/// Encoded metadata for incoming transaction
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum InMetadata {
- Deposit { reserve_pub: [u8; 32] },
+ Credit { reserve_pub: [u8; 32] },
}
impl InMetadata {
pub fn encode(&self) -> Vec<u8> {
let mut buffer = Vec::new();
match self {
- InMetadata::Deposit { reserve_pub } => {
+ InMetadata::Credit { reserve_pub } => {
buffer.push(0);
buffer.extend_from_slice(reserve_pub);
}
@@ -117,7 +117,7 @@ impl InMetadata {
if bytes.len() < 33 {
return Err(DecodeErr::UnexpectedEOF);
}
- Ok(InMetadata::Deposit {
+ Ok(InMetadata::Credit {
reserve_pub: bytes[1..33].try_into().unwrap(),
})
}
@@ -137,9 +137,9 @@ mod test {
};
#[test]
- fn decode_encode_deposit() {
+ fn decode_encode_credit() {
for _ in 0..4 {
- let metadata = InMetadata::Deposit {
+ let metadata = InMetadata::Credit {
reserve_pub: rand_slice(),
};
let encoded = metadata.encode();
@@ -149,7 +149,7 @@ mod test {
}
#[test]
- fn decode_encode_withdraw() {
+ fn decode_encode_debit() {
let urls = [
"https://git.taler.net/",
"https://git.taler.net/depolymerization.git/",
@@ -159,7 +159,7 @@ mod test {
for url in urls {
let wtid = rand_slice();
let url = Url::parse(url).unwrap();
- let metadata = OutMetadata::Withdraw { wtid, url };
+ let metadata = OutMetadata::Debit { wtid, url };
let encoded = metadata.encode();
let decoded = OutMetadata::decode(&encoded).unwrap();
assert_eq!(decoded, metadata);
diff --git a/common/src/status.rs b/common/src/status.rs
index b9e2493..08e71a5 100644
--- a/common/src/status.rs
+++ b/common/src/status.rs
@@ -15,27 +15,27 @@
*/
//! Transactions status in database
-/// Withdraw transaction status
+/// Debit transaction status
///
/// -> Requested API request
/// Requested -> Sent Announced to the bitcoin network
/// Sent -> Requested Conflicting transaction (reorg)
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum WithdrawStatus {
- /// Withdraw have been requested (default)
+pub enum DebitStatus {
+ /// Debit have been requested (default)
Requested = 0,
- /// Withdraw have been announced to the bitcoin network
+ /// Debit have been announced to the bitcoin network
Sent = 1,
}
-impl TryFrom<u8> for WithdrawStatus {
+impl TryFrom<u8> for DebitStatus {
type Error = ();
fn try_from(v: u8) -> Result<Self, Self::Error> {
match v {
- x if x == WithdrawStatus::Requested as u8 =>
Ok(WithdrawStatus::Requested),
- x if x == WithdrawStatus::Sent as u8 => Ok(WithdrawStatus::Sent),
+ x if x == DebitStatus::Requested as u8 =>
Ok(DebitStatus::Requested),
+ x if x == DebitStatus::Sent as u8 => Ok(DebitStatus::Sent),
_ => Err(()),
}
}
@@ -43,7 +43,7 @@ impl TryFrom<u8> for WithdrawStatus {
/// Bounce transaction status
///
-/// -> Requested Deposit in wrong format
+/// -> Requested Credit in wrong format
/// Requested -> Ignored Insufficient found
/// Requested -> Sent Announced to the bitcoin network
/// Sent -> Requested Conflicting transaction (reorg)
diff --git a/docs/figures/depolymerizer_arch.tex
b/docs/figures/depolymerizer_arch.tex
new file mode 100644
index 0000000..75c8e68
--- /dev/null
+++ b/docs/figures/depolymerizer_arch.tex
@@ -0,0 +1,21 @@
+\begin{tikzpicture}[
+ rect/.style={rectangle, draw=black, minimum height=6mm, minimum
width=28mm},
+ sym/.style={stealth-stealth, shorten >= 2pt, shorten <= 2pt}
+ ]
+ \node[rect](1) {Taler Exchange};
+ \node[rect,below=of 1](2) {Wire Gateway};
+ \node[rect,right=of 2](3) {PostgreSQL};
+ \node[rect,right=of 3](4) {DLT Adapter};
+ \node[rect,above=of 4](5) {DLT Full Node};
+
+ \draw[sym] (1) -- node [midway,right] {\tiny HTTP} (2);
+ \draw[sym] (2) -- node [midway,above] {\tiny SQL} (3);
+ \draw[sym] (3) -- node [midway,above] {\tiny SQL} (4);
+ \draw[sym] (4) -- node [midway,left ] {\tiny RPC} (5);
+
+
+ \node[above= 2mm of 1]{\small{\emph{Wire Gateway API}}};
+ \node[above= 2mm of 5]{\small{\emph{DLT specific}}};
+ \node[above=22mm of 3](T) {};
+ \draw[dotted] (3) -- (T);
+\end{tikzpicture}
\ No newline at end of file
diff --git a/docs/report.tex b/docs/report.tex
index e5578f0..19158cd 100644
--- a/docs/report.tex
+++ b/docs/report.tex
@@ -50,7 +50,9 @@ At the heart of these currencies is a blockchain. A
blockchain is an append-only
\subsection{Consensus}
-The blockchain itself is just a storage system. To make it a distributed
ledger, it needs a peer-to-peer network to share its changes. But also a way
for participants (nodes) to agree on a single state of the chain, to reach
consensus in a network where nodes can be malicious and have an economic
interest in deceiving others. There are many ways to create such consensus, but
only two of them interest us: proof of work and proof of stake.
+The blockchain itself is just a storage system. To make it a distributed
ledger (DLT), it needs a peer-to-peer network to share its changes. But also a
way for participants (nodes) to agree on a single state of the chain, to reach
consensus in a network where nodes can be malicious and have an economic
interest in deceiving others. There are many ways to create such consensus, but
only two of them interest us: proof of work and proof of stake.
+
+% DLT definition ?
\subsubsection*{Proof of work}
@@ -96,7 +98,7 @@ Some properties of blockchain-based cryptocurrencies are
problematic for their u
\subsection{Solving chain reorganisation}
-Taler expects deposit transactions to be final. If a deposit transaction
disappears from the blockchain, an irrevocable withdrawal transaction would no
longer be backed by credit. This problem is well known and already mentioned in
the Bitcoin white paper \cite{nakamoto2008bitcoin}. The solution is to wait
until a block has a certain amount of blocks linked to it, before considering
its transactions final.
+Taler expects credits to be final. If a credit disappears from the blockchain,
an irrevocable debit would no longer be backed by credit. This problem is well
known and already mentioned in the Bitcoin white paper
\cite{nakamoto2008bitcoin}. The solution is to wait until a block has a certain
amount of blocks linked to it, before considering its transactions final.
\begin{figure}[H]
\begin{center}
@@ -147,10 +149,6 @@ If we experience a reorganisation once, it is dangerously
likely that another on
We know that transactions can get stuck for a long time, which can be
problematic when we are expecting transactions to be executed in a timely
manner. Depolymerizer keeps track of pending transactions and finds those that
are taking an excessive amount of time to mine. Then, it increases the fee for
these transactions to bump their mining priority. Since the process of
replacing transactions is expensive, this feature is optional and configurable.
-\section{Architecture}
-
-Use existing official client.
-
\clearpage
\section{Metadata}
@@ -233,6 +231,55 @@ Having a common random ID allows us to distinguish real
addresses from fake ones
Ethereum is designed around the concept of smart contracts. Logging inside a
smart contract is the recommended way to add metadata, but it is expensive
(additional storage and execution costs) and adds an avoidable attack surface.
We chose to use the transaction field typically used to call smart contracts to
store our raw metadata.
+\subsection{Friendly behavior on format error}
+
+When we receive a transaction without any metadata or with an incompatible
format (bogus wallet), we want to return the money to its owner (bounce).
However, this is dangerous because we have created a potential attack loophole
as anyone can now make Depolymerizer do a transaction, by sending a malformed
transaction. Depolymerizer takes a bounce fee to make a potential DOS attack
too costly and charges the recipient the transaction fee to ensure it can not
lose money on a bounce.
+
+\clearpage
+
+\section{Architecture}
+
+Each cryptocurrency uses a different distributed ledger (DLT) with its own
format and rules, which evolve over time. We do not want to manage the DLT
logic ourselves, nor do we want to rely on third-party dependencies to
implement their support properly and be maintained. The simplest solution is to
rely on the official clients and communicate with them via RPC.
+
+\begin{figure}[hb]
+ \begin{center}
+ \input{figures/depolymerizer_arch.tex}
+ \end{center}
+ \caption{Depolymerizer architecture}
+\end{figure}
+
+While some parts of Depolymerizer are DLT specific, much of the logic is
common and we want to reuse it. We have a Wire Gateway component that
implements the Taler HTTP API to enable communication with Taler exchanges.
Each supported cryptocurrency has its specific adapter to communicate with the
official full node client via RPC. The Wire Gateway module and the DLT adapter
use a common database to store transactions and communicate with notifications.
+
+\subsection{DLT adapter}
+
+The DTL adapter uses an event-based architecture with three distinct loops.
+
+\paragraph*{Block watcher}
+
+The watcher loop looks for new incoming blocks and notifies the other loops of
their arrival.
+
+\paragraph*{Analysis}
+
+The analysis loop waits for new blocks and then analyzes the behavior of the
blockchain network. If a dangerous reorganization occurs, it is responsible for
updating the confirmation delay.
+
+\paragraph*{Worker}
+
+The worker loop waits for new blocks or transaction requests (from the Wire
Gateway API). When one of these events occurs, it first reconciles the local
database with the DLT, then triggers requested debits, re-issues blocked debits
and bounces malformed credits.
+
+\subsection{Worker loop in detail}
+
+\subsubsection*{DLT reconciliation}
+
+During a DLT reconciliation, we first list all new transactions and any
transactions that have been deleted in a reorganization since the last
reconciliation. If any previously confirmed debits have been deleted without
being reinserted into another block, we notify the Wire Gateway to cease
activity and wait for the next block in hopes of recovering them. All newly
confirmed debits and successful credits are registered in the database.
+
+\subsubsection*{Reconciliation inconsistency}
+
+When we issue a transaction (debit or bounce), it is possible for the database
or DLT request to fail. Since a DLT request does not mean that the
cryptocurrency transaction was not successful and since the database may not
record a successful transaction, it is possible to have an inconsistency in the
DLT and the database where a successful transaction is not recorded as such.
This is very problematic because we must perform each transaction once.
+
+This is also problematic because even if we used a status machine state in the
database to detect this inconsistency, the only way to resolve it is to make
another DLT reconciliation, which is slow and does not play well with database
locking.
+
+Since we know that blockchain-based cryptocurrencies have low throughput, we
don not need parallel worker loops to stay synchronized. Therefore, we can use
a cross-process locking mechanism to ensure that only one working loop is
running at a time. Then, when a database or DLT request error occurs, we can
restart the loop, which will start by performing a DLT reconciliation that will
recover all successful unregistered transactions.
+
\clearpage
\section{Implementation specific issues}
@@ -264,8 +311,8 @@ expensive and limited. Therefore we want our metadata to be
as small as possible
Transactions metadata are composed of three parts:
\begin{itemize}
\item Version and identity metadata ($\sim$ 1B)
- \item Reserve public key or withdraw id (32B)
- \item Base uri (withdraw only, variable)
+ \item Reserve public key or wire transfer id (32B)
+ \item Base uri (debit only, variable)
\end{itemize}
The only variable and so problematic part is the base url. Those url have some
diff --git a/eth-wire/README.md b/eth-wire/README.md
index e15a062..844a2cb 100644
--- a/eth-wire/README.md
+++ b/eth-wire/README.md
@@ -3,7 +3,7 @@
eth-wire is taler wire adapter for [go-ethereum](https://geth.ethereum.org/)
node
-## Deposit metadata format
+## Credit metadata format
TODO
diff --git a/eth-wire/src/bin/eth-wire-utils.rs
b/eth-wire/src/bin/eth-wire-utils.rs
index 69234c8..65dc9a6 100644
--- a/eth-wire/src/bin/eth-wire-utils.rs
+++ b/eth-wire/src/bin/eth-wire-utils.rs
@@ -60,8 +60,8 @@ struct TransactionCmd {
enum Cmd {
/// Send common ethereum transactions
Send(TransactionCmd),
- /// Send taler deposit transactions
- Deposit(TransactionCmd),
+ /// Send taler credit transactions
+ Credit(TransactionCmd),
/// Mine pending transactions and more blocks
Mine {
/// receiver wallet
@@ -110,7 +110,7 @@ fn main() {
let mut rpc = Rpc::new(ipc_path).unwrap();
let passwd = password();
match args.cmd {
- Cmd::Deposit(TransactionCmd {
+ Cmd::Credit(TransactionCmd {
from,
to,
fmt,
@@ -123,7 +123,7 @@ fn main() {
let amount =
Amount::from_str(&format!("{}:{}{}", currency.to_str(),
fmt, amount)).unwrap();
let value = taler_to_eth(&amount, currency).unwrap();
- rpc.deposit(from, to, value, rand_slice()).unwrap();
+ rpc.credit(from, to, value, rand_slice()).unwrap();
}
}
Cmd::Send(TransactionCmd {
diff --git a/eth-wire/src/lib.rs b/eth-wire/src/lib.rs
index e1ff033..6336c4f 100644
--- a/eth-wire/src/lib.rs
+++ b/eth-wire/src/lib.rs
@@ -42,15 +42,15 @@ 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(
+ /// Perform a wire credit
+ fn credit(
&mut self,
from: Address,
to: Address,
value: U256,
reserve_pub: [u8; 32],
) -> rpc::Result<H256> {
- let metadata = InMetadata::Deposit { reserve_pub };
+ let metadata = InMetadata::Credit { reserve_pub };
self.send_transaction(&rpc::TransactionRequest {
from,
to,
@@ -61,8 +61,8 @@ pub trait RpcExtended: RpcClient {
})
}
- /// Perform a Taler withdraw
- fn withdraw(
+ /// Perform a wire debit
+ fn debit(
&mut self,
from: Address,
to: Address,
@@ -70,7 +70,7 @@ pub trait RpcExtended: RpcClient {
wtid: [u8; 32],
url: Url,
) -> rpc::Result<H256> {
- let metadata = OutMetadata::Withdraw { wtid, url };
+ let metadata = OutMetadata::Debit { wtid, url };
self.send_transaction(&rpc::TransactionRequest {
from,
to,
diff --git a/eth-wire/src/loops/worker.rs b/eth-wire/src/loops/worker.rs
index 2e84277..ea1d412 100644
--- a/eth-wire/src/loops/worker.rs
+++ b/eth-wire/src/loops/worker.rs
@@ -22,7 +22,7 @@ use common::{
postgres::{fallible_iterator::FallibleIterator, Client},
reconnect::AutoReconnectDb,
sql::{sql_array, sql_url},
- status::{BounceStatus, WithdrawStatus},
+ status::{BounceStatus, DebitStatus},
};
use eth_wire::{
rpc::{self, AutoRpcWallet, Rpc, RpcClient, Transaction,
TransactionRequest},
@@ -94,8 +94,8 @@ pub fn worker(mut rpc: AutoRpcWallet, mut db:
AutoReconnectDb, state: &WireState
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
- // Send requested withdraws
- while withdraw(db, rpc, state)? {}
+ // Send requested debits
+ while debit(db, rpc, state)? {}
// Bump stuck transactions
while bump(db, rpc, state)? {}
@@ -138,13 +138,7 @@ fn sync_chain(
let list = rpc.list_since_sync(&state.address, sync_state, conf_delay)?;
// Check if a confirmed incoming transaction have been removed by a
blockchain reorganisation
- let new_status = sync_chain_removed(
- &list.txs,
- &list.removed,
- db,
- &state.address,
- conf_delay,
- )?;
+ let new_status = sync_chain_removed(&list.txs, &list.removed, db,
&state.address, conf_delay)?;
// Sync status with database
if *status != new_status {
@@ -188,13 +182,13 @@ fn sync_chain_removed(
addr: &Address,
min_confirmation: u32,
) -> LoopResult<bool> {
- // Removed transactions are correctness issues in only two cases:
- // - An incoming valid transaction considered confirmed in the database
- // - An incoming invalid transactions already bounced
- // Those two cases can compromise ethereum backing
+ // A removed incoming transaction is a correctness issues in only two
cases:
+ // - it is a confirmed credit registered in the database
+ // - it is an invalid transactions already bounced
+ // Those two cases can compromise bitcoin backing
// Removed outgoing transactions will be retried automatically by the node
- let mut blocking_deposit = Vec::new();
+ let mut blocking_credit = Vec::new();
let mut blocking_bounce = Vec::new();
// Only keep incoming transaction that are not reconfirmed
@@ -208,8 +202,8 @@ fn sync_chain_removed(
}) {
match InMetadata::decode(&tx.input) {
Ok(metadata) => match metadata {
- InMetadata::Deposit { reserve_pub } => {
- // Deposit are only problematic if not reconfirmed and
stored in the database
+ InMetadata::Credit { reserve_pub } => {
+ // Credits are only problematic if not reconfirmed and
stored in the database
if db
.query_opt(
"SELECT 1 FROM tx_in WHERE reserve_pub=$1",
@@ -217,7 +211,7 @@ fn sync_chain_removed(
)?
.is_some()
{
- blocking_deposit.push((reserve_pub, tx.hash,
tx.from.unwrap()));
+ blocking_credit.push((reserve_pub, tx.hash,
tx.from.unwrap()));
}
}
},
@@ -236,12 +230,12 @@ fn sync_chain_removed(
}
}
- if !blocking_bounce.is_empty() || !blocking_deposit.is_empty() {
+ if !blocking_bounce.is_empty() || !blocking_credit.is_empty() {
let mut buf = "The following transaction have been removed from the
blockchain, ethereum backing is compromised until the transaction
reappear:".to_string();
- for (key, id, addr) in blocking_deposit {
+ for (key, id, addr) in blocking_credit {
write!(
&mut buf,
- "\n\tdeposit {} in {} from {}",
+ "\n\tcredit {} in {} from {}",
base32(&key),
hex::encode(id),
hex::encode(addr)
@@ -272,7 +266,7 @@ fn sync_chain_incoming_confirmed(
) -> Result<(), LoopError> {
match InMetadata::decode(&tx.input) {
Ok(metadata) => match metadata {
- InMetadata::Deposit { reserve_pub } => {
+ InMetadata::Credit { reserve_pub } => {
let date = SystemTime::now();
let amount = eth_to_taler(&tx.value, state.currency);
let credit_addr = tx.from.expect("Not coinbase");
@@ -306,7 +300,7 @@ fn sync_chain_outgoing(tx: &SyncTransaction, db: &mut
Client, state: &WireState)
let SyncTransaction { tx, confirmations } = tx;
match OutMetadata::decode(&tx.input) {
Ok(metadata) => match metadata {
- OutMetadata::Withdraw { wtid, .. } => {
+ OutMetadata::Debit { wtid, .. } => {
let amount = eth_to_taler(&tx.value, state.currency);
let credit_addr = tx.to.unwrap();
// Get previous out tx
@@ -320,21 +314,21 @@ fn sync_chain_outgoing(tx: &SyncTransaction, db: &mut
Client, state: &WireState)
let status: i16 = row.get(1);
let sent: Option<SystemTime> = row.get(2);
- let expected_status = WithdrawStatus::Sent as i16;
+ let expected_status = DebitStatus::Sent as i16;
let expected_send = sent.filter(|_| *confirmations == 0);
if status != expected_status || sent != expected_send {
let nb_row = db.execute(
"UPDATE tx_out SET status=$1, txid=$2, sent=NULL WHERE
id=$3 AND status=$4",
&[
- &(WithdrawStatus::Sent as i16),
+ &(DebitStatus::Sent as i16),
&tx.hash.as_ref(),
&row_id,
&status,
],
)?;
if nb_row > 0 {
- match WithdrawStatus::try_from(status as
u8).unwrap() {
- WithdrawStatus::Requested => {
+ match DebitStatus::try_from(status as u8).unwrap()
{
+ DebitStatus::Requested => {
warn!(
">> (recovered) {} {} in {} to {}",
amount,
@@ -343,7 +337,7 @@ fn sync_chain_outgoing(tx: &SyncTransaction, db: &mut
Client, state: &WireState)
hex::encode(credit_addr)
);
}
- WithdrawStatus::Sent => { /* Status is correct
*/ }
+ DebitStatus::Sent => { /* Status is correct */
}
}
}
}
@@ -352,7 +346,7 @@ fn sync_chain_outgoing(tx: &SyncTransaction, db: &mut
Client, state: &WireState)
let date = SystemTime::now();
let nb = db.execute(
"INSERT INTO tx_out (_date, amount, wtid, debit_acc,
credit_acc, exchange_url, status, txid, request_uid) VALUES ($1, $2, $3, $4,
$5, $6, $7, $8, $9) ON CONFLICT (wtid) DO NOTHING",
- &[&date, &amount.to_string(), &wtid.as_ref(),
ð_payto_url(&state.address).as_ref(), ð_payto_url(&credit_addr).as_ref(),
&state.base_url.as_ref(), &(WithdrawStatus::Sent as i16), &tx.hash.as_ref(),
&None::<&[u8]>],
+ &[&date, &amount.to_string(), &wtid.as_ref(),
ð_payto_url(&state.address).as_ref(), ð_payto_url(&credit_addr).as_ref(),
&state.base_url.as_ref(), &(DebitStatus::Sent as i16), &tx.hash.as_ref(),
&None::<&[u8]>],
)?;
if nb > 0 {
warn!(
@@ -415,12 +409,12 @@ fn sync_chain_outgoing(tx: &SyncTransaction, db: &mut
Client, state: &WireState)
Ok(())
}
-/// Send a withdraw transaction on the blockchain, return false if no more
requested transactions are found
-fn withdraw(db: &mut Client, rpc: &mut Rpc, state: &WireState) ->
LoopResult<bool> {
+/// Send a debit transaction on the blockchain, return false if no more
requested transactions are found
+fn debit(db: &mut Client, rpc: &mut Rpc, state: &WireState) ->
LoopResult<bool> {
// We rely on the advisory lock to ensure we are the only one sending
transactions
let row = db.query_opt(
"SELECT id, amount, wtid, credit_acc, exchange_url FROM tx_out WHERE status=$1
ORDER BY _date LIMIT 1",
-&[&(WithdrawStatus::Requested as i16)],
+&[&(DebitStatus::Requested as i16)],
)?;
if let Some(row) = &row {
let id: i32 = row.get(0);
@@ -428,11 +422,11 @@ fn withdraw(db: &mut Client, rpc: &mut Rpc, state:
&WireState) -> LoopResult<boo
let wtid: [u8; 32] = sql_array(row, 2);
let addr = sql_addr(row, 3);
let url = sql_url(row, 4);
- let tx_id = rpc.withdraw(state.address, addr, amount, wtid, url)?;
- fail_point("(injected) fail withdraw", 0.3)?;
+ let tx_id = rpc.debit(state.address, addr, amount, wtid, url)?;
+ fail_point("(injected) fail debit", 0.3)?;
db.execute(
"UPDATE tx_out SET status=$1, txid=$2, sent=now() WHERE id=$3",
- &[&(WithdrawStatus::Sent as i16), &tx_id.as_ref(), &id],
+ &[&(DebitStatus::Sent as i16), &tx_id.as_ref(), &id],
)?;
let amount = eth_to_taler(&amount, state.currency);
info!(
@@ -452,7 +446,7 @@ fn bump(db: &mut Client, rpc: &mut Rpc, state: &WireState)
-> LoopResult<bool> {
// We rely on the advisory lock to ensure we are the only one sending
transactions
let row = db.query_opt(
"SELECT id, txid FROM tx_out WHERE status=$1 AND EXTRACT(EPOCH FROM
(now() - sent)) > $2 ORDER BY _date LIMIT 1",
- &[&(WithdrawStatus::Sent as i16), &(delay as f64)],
+ &[&(DebitStatus::Sent as i16), &(delay as f64)],
)?;
if let Some(row) = &row {
let id: i32 = row.get(0);
diff --git a/instrumentation/src/btc.rs b/instrumentation/src/btc.rs
index c1e1f99..ead376e 100644
--- a/instrumentation/src/btc.rs
+++ b/instrumentation/src/btc.rs
@@ -115,7 +115,7 @@ pub fn btc_test(config: Option<&Path>, base_url: &str) {
println!("Send transaction");
let reserve_pub_key = rand_slice();
- let deposit_id = client_rpc
+ let credit_id = client_rpc
.send_segwit_key(&wire_addr, &test_amount, &reserve_pub_key)
.unwrap();
let bounce_min_id = client_rpc
@@ -129,7 +129,7 @@ pub fn btc_test(config: Option<&Path>, base_url: &str) {
.unwrap();
let client_sent_amount_cost =
test_amount + min_send_amount * 2 + min_bounce_amount +
min_send_amount + test_amount;
- let client_sent_fees_cost: Amount = [deposit_id, bounce_min_id,
send_min_id, bounce_id]
+ let client_sent_fees_cost: Amount = [credit_id, bounce_min_id,
send_min_id, bounce_id]
.into_iter()
.map(|id| unsigned(client_rpc.get_tx(&id).unwrap().fee.unwrap()))
.reduce(|acc, i| acc + i)
@@ -148,7 +148,7 @@ pub fn btc_test(config: Option<&Path>, base_url: &str) {
let (tx, metadata) =
client_rpc.get_tx_op_return(&tx.txid).unwrap();
let metadata = OutMetadata::decode(&metadata).unwrap();
match metadata {
- OutMetadata::Withdraw { .. } => {}
+ OutMetadata::Debit { .. } => {}
OutMetadata::Bounce { bounced } => {
let bounced = Txid::from_inner(bounced);
if bounced == bounce_id {
diff --git a/instrumentation/src/eth.rs b/instrumentation/src/eth.rs
index 7c32106..7a99e4e 100644
--- a/instrumentation/src/eth.rs
+++ b/instrumentation/src/eth.rs
@@ -70,8 +70,8 @@ pub fn eth_test(config: Option<&Path>, base_url: &str) {
println!("Send transaction");
let reserve_pub_key = rand_slice();
- let deposit_id = rpc
- .deposit(client_addr, state.address, test_amount, reserve_pub_key)
+ let credit_id = rpc
+ .credit(client_addr, state.address, test_amount, reserve_pub_key)
.unwrap();
let zero_id = rpc
.send_transaction(&TransactionRequest {
@@ -104,7 +104,7 @@ pub fn eth_test(config: Option<&Path>, base_url: &str) {
if tx.to.unwrap() == client_addr && tx.from.unwrap() ==
state.address {
let metadata = OutMetadata::decode(&tx.input).unwrap();
match metadata {
- OutMetadata::Withdraw { .. } => {}
+ OutMetadata::Debit { .. } => {}
OutMetadata::Bounce { bounced } => {
let bounced = H256::from_slice(&bounced);
if bounced == bounce_id {
@@ -127,7 +127,7 @@ pub fn eth_test(config: Option<&Path>, base_url: &str) {
let new_client_balance = rpc.get_balance(&client_addr).unwrap();
let new_wire_balance = rpc.get_balance(&state.address).unwrap();
let client_sent_amount_cost = test_amount * U256::from(2u8);
- let client_sent_fees_cost = [deposit_id, zero_id, bounce_id]
+ let client_sent_fees_cost = [credit_id, zero_id, bounce_id]
.into_iter()
.map(|id| {
let receipt = rpc.get_transaction_receipt(&id).unwrap().unwrap();
diff --git a/test/btc/hell.sh b/test/btc/hell.sh
index 827dc04..d58189b 100644
--- a/test/btc/hell.sh
+++ b/test/btc/hell.sh
@@ -20,7 +20,7 @@ echo "Start gateway"
gateway
echo ""
-echo "----- Handle reorg conflicting incoming deposit -----"
+echo "----- Handle reorg conflicting incoming credit -----"
echo "Loose second bitcoin node"
btc_deco
diff --git a/test/eth/analysis.sh b/test/eth/analysis.sh
index bded5b0..bc1898b 100644
--- a/test/eth/analysis.sh
+++ b/test/eth/analysis.sh
@@ -26,7 +26,7 @@ echo "Loose second ethereum node"
eth_deco
echo -n "Making wire transfer to exchange:"
-$WIRE_UTILS deposit $CLIENT $WIRE 0.00 42
+$WIRE_UTILS credit $CLIENT $WIRE 0.00 42
next_eth # Trigger eth-wire
check_balance_eth 999580000 420000
echo " OK"
@@ -48,7 +48,7 @@ echo "Loose second bitcoin node"
eth_deco
echo -n "Making wire transfer to exchange:"
-$WIRE_UTILS deposit $CLIENT $WIRE 0.00 42
+$WIRE_UTILS credit $CLIENT $WIRE 0.00 42
next_eth # Trigger eth-wire
check_balance_eth 999160000 840000
echo " OK"
diff --git a/test/eth/bumpfee.sh b/test/eth/bumpfee.sh
index 466dca4..16e1952 100644
--- a/test/eth/bumpfee.sh
+++ b/test/eth/bumpfee.sh
@@ -23,7 +23,7 @@ echo ""
SEQ="seq 10 20"
echo -n "Making wire transfer to exchange: "
-$WIRE_UTILS deposit $CLIENT $WIRE 0.000 `$SEQ`
+$WIRE_UTILS credit $CLIENT $WIRE 0.000 `$SEQ`
sleep 1
mine_eth # Trigger eth-wire
check_balance_eth 999835000 165000
diff --git a/test/eth/hell.sh b/test/eth/hell.sh
index f725a9f..48b36b7 100644
--- a/test/eth/hell.sh
+++ b/test/eth/hell.sh
@@ -20,13 +20,13 @@ echo "Start gateway"
gateway
echo ""
-echo "----- Handle reorg conflicting incoming deposit -----"
+echo "----- Handle reorg conflicting incoming credit -----"
echo "Loose second ethereum node"
eth_deco
echo -n "Making wire transfer to exchange:"
-$WIRE_UTILS deposit $CLIENT $WIRE 0.00 42
+$WIRE_UTILS credit $CLIENT $WIRE 0.00 42
next_eth # Trigger eth-wire
check_balance_eth 999580000 420000
echo " OK"
diff --git a/test/eth/lifetime.sh b/test/eth/lifetime.sh
index 4814f5e..4c2c47c 100644
--- a/test/eth/lifetime.sh
+++ b/test/eth/lifetime.sh
@@ -29,7 +29,7 @@ check_up $GATEWAY_PID wire-gateway
echo " OK"
echo -n "Do some work:"
-$WIRE_UTILS deposit $CLIENT $WIRE 0.000 `$SEQ` > /dev/null
+$WIRE_UTILS credit $CLIENT $WIRE 0.000 `$SEQ` > /dev/null
next_eth # Trigger eth-wire
check_balance_eth 999835000 165000
for n in `$SEQ`; do
diff --git a/test/eth/maxfee.sh b/test/eth/maxfee.sh
index 55b775f..556ce4f 100644
--- a/test/eth/maxfee.sh
+++ b/test/eth/maxfee.sh
@@ -21,7 +21,7 @@ echo ""
SEQ="seq 10 20"
echo -n "Making wire transfer to exchange: "
-$WIRE_UTILS deposit $CLIENT $WIRE 0.000 `$SEQ`
+$WIRE_UTILS credit $CLIENT $WIRE 0.000 `$SEQ`
next_eth # Trigger eth-wire
sleep 1
check_delta "incoming?delta=-100" "$SEQ" "0.000"
diff --git a/test/eth/reconnect.sh b/test/eth/reconnect.sh
index 2dd1659..0f21568 100644
--- a/test/eth/reconnect.sh
+++ b/test/eth/reconnect.sh
@@ -21,7 +21,7 @@ echo ""
echo "----- With DB -----"
echo -n "Making wire transfer to exchange:"
-$WIRE_UTILS deposit $CLIENT $WIRE 0.0000 42
+$WIRE_UTILS credit $CLIENT $WIRE 0.0000 42
next_eth # Trigger eth-wire
check_balance_eth 999995800 4200
echo " OK"
@@ -37,7 +37,7 @@ stop_db
echo "Making incomplete wire transfer to exchange"
$WIRE_UTILS send $CLIENT $WIRE 0.0000 42
echo -n "Making wire transfer to exchange:"
-$WIRE_UTILS deposit $CLIENT $WIRE 0.0000 4
+$WIRE_UTILS credit $CLIENT $WIRE 0.0000 4
next_eth
check_balance_eth 999987600 12400
echo "OK"
diff --git a/test/eth/reorg.sh b/test/eth/reorg.sh
index 9f27db6..b129df5 100644
--- a/test/eth/reorg.sh
+++ b/test/eth/reorg.sh
@@ -28,7 +28,7 @@ echo "Loose second ethereum node"
eth_deco
echo -n "Making wire transfer to exchange:"
-$WIRE_UTILS deposit $CLIENT $WIRE 0.000 `$SEQ`
+$WIRE_UTILS credit $CLIENT $WIRE 0.000 `$SEQ`
next_eth # Trigger eth-wire
check_delta "incoming?delta=-100" "$SEQ" "0.000"
check_balance_eth 999835000 165000
diff --git a/test/eth/stress.sh b/test/eth/stress.sh
index 4cddf65..d36aea2 100644
--- a/test/eth/stress.sh
+++ b/test/eth/stress.sh
@@ -23,7 +23,7 @@ SEQ="seq 10 30"
echo "----- Handle incoming -----"
echo -n "Making wire transfer to exchange:"
-$WIRE_UTILS deposit $CLIENT $WIRE 0.000 `$SEQ`
+$WIRE_UTILS credit $CLIENT $WIRE 0.000 `$SEQ`
next_eth # Trigger eth-wire
echo " OK"
diff --git a/test/eth/wire.sh b/test/eth/wire.sh
index 453e491..8533807 100644
--- a/test/eth/wire.sh
+++ b/test/eth/wire.sh
@@ -23,7 +23,7 @@ SEQ="seq 10 99"
echo "----- Receive -----"
echo -n "Making wire transfer to exchange:"
-$WIRE_UTILS deposit $CLIENT $WIRE 0.000 `$SEQ`
+$WIRE_UTILS credit $CLIENT $WIRE 0.000 `$SEQ`
next_eth # Trigger eth-wire
check_balance_eth 995095000 4905000
echo " OK"
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-depolymerization] branch master updated (42c8009 -> 9d00fd8),
gnunet <=