commit 535ce15a129cd35a528ef215ec2c739f68dae144
parent a9dfe0e23f161458a018caafad966b1c3c68ae2f
Author: Antoine A <>
Date: Tue, 29 Jul 2025 15:19:56 +0200
bitcoin: improve wire gateway compliance
Diffstat:
6 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/contrib/ci/jobs/0-codespell/job.sh b/contrib/ci/jobs/0-codespell/job.sh
@@ -14,6 +14,8 @@ skip=$(cat <<EOF
./uri-pack/src/majestic_million.csv
./uri-pack/src/urltestdata.json
./article-brains22/*
+./testbench/env
+./testbench/instrumentation
EOF
);
diff --git a/depolymerizer-bitcoin/src/cli.rs b/depolymerizer-bitcoin/src/cli.rs
@@ -53,7 +53,7 @@ pub enum Command {
#[clap(long, short)]
reset: bool,
},
- /// TODO
+ /// Check worker configuration and setup worker state
Setup {
#[clap(long, short)]
reset: bool,
@@ -130,10 +130,6 @@ pub async fn run(cmd: Command, cfg: &Config) -> anyhow::Result<()> {
panic!("lol")
}
- /*if let Some(cfg) = cfg.revenue {
- router = router.revenue(api, cfg.auth);
- }*/
- // TODO http lifetime
router
.layer(middleware::from_fn_with_state(
api.clone(),
diff --git a/depolymerizer-bitcoin/src/db.rs b/depolymerizer-bitcoin/src/db.rs
@@ -184,9 +184,11 @@ pub async fn transfer_page<'a>(
},
|r: PgRow| {
Ok(TransferListStatus {
- row_id: r.try_get_safeu64("id")?,
- // TODO Fetch inner status
- status: TransferState::success,
+ row_id: r.try_get_safeu64(0)?,
+ status: match r.try_get(1)? {
+ DebitStatus::requested => TransferState::pending,
+ DebitStatus::sent => TransferState::success,
+ },
amount: r.try_get_amount("amount", currency)?,
credit_account: sql_payto(&r, "credit_acc", "credit_name")?,
timestamp: r.try_get_timestamp("created")?,
@@ -219,8 +221,10 @@ pub async fn transfer_by_id<'a>(
.bind(id as i64)
.try_map(|r: PgRow| {
Ok(TransferStatus {
- // TODO Fetch inner status
- status: TransferState::success,
+ status: match r.try_get(0)? {
+ DebitStatus::requested => TransferState::pending,
+ DebitStatus::sent => TransferState::success,
+ },
status_msg: None,
amount: r.try_get_amount_i(1, currency)?,
origin_exchange_url: r.try_get(3)?,
diff --git a/depolymerizer-bitcoin/src/loops/worker.rs b/depolymerizer-bitcoin/src/loops/worker.rs
@@ -20,9 +20,10 @@ use common::{
metadata::OutMetadata,
status::BounceStatus,
taler_common::{api_common::ShortHashCode, types::timestamp::Timestamp},
+ url::Url,
};
use sqlx::{PgPool, postgres::PgListener};
-use taler_common::{ExpoBackoffDecorr, types::url};
+use taler_common::ExpoBackoffDecorr;
use tokio::time::sleep;
use tracing::{debug, error, info, trace, warn};
@@ -334,6 +335,7 @@ async fn sync_chain_debit(
txid: &Txid,
full: &Transaction,
wtid: &ShortHashCode,
+ exchange_url: &Url,
db: &mut PgListener,
confirmations: i32,
state: &WorkerCfg,
@@ -352,7 +354,7 @@ async fn sync_chain_debit(
txid,
full.replaced_by_txid.as_ref(),
&amount,
- &url("https://exchange.url.TODO/"),
+ exchange_url,
&credit_addr,
wtid,
&Timestamp::from_sql_micros((full.time * 1000000) as i64).unwrap(),
@@ -430,8 +432,8 @@ async fn sync_chain_outgoing(
.map(|(full, bytes)| (full, OutMetadata::decode(&bytes)))
{
Ok((full, Ok(info))) => match info {
- OutMetadata::Debit { wtid, .. } => {
- return sync_chain_debit(id, &full, &wtid, db, confirmations, state).await;
+ OutMetadata::Debit { wtid, url } => {
+ return sync_chain_debit(id, &full, &wtid, &url, db, confirmations, state).await;
}
OutMetadata::Bounce { bounced } => {
sync_chain_bounce(id, &Txid::from_byte_array(bounced), db, confirmations).await?
diff --git a/depolymerizer-bitcoin/src/rpc.rs b/depolymerizer-bitcoin/src/rpc.rs
@@ -474,7 +474,13 @@ pub struct BlockchainInfo {
#[derive(Clone, Debug, serde::Deserialize)]
pub struct WalletInfo {
pub walletname: String,
- pub scanning: serde_json::Value,
+ pub scanning: Option<Scanning>,
+}
+
+#[derive(Clone, Debug, serde::Deserialize)]
+pub struct Scanning {
+ pub duration: u64,
+ pub progress: f32,
}
#[derive(Debug, serde::Deserialize)]
diff --git a/depolymerizer-bitcoin/src/setup.rs b/depolymerizer-bitcoin/src/setup.rs
@@ -17,7 +17,7 @@
use anyhow::bail;
use taler_common::{config::Config, db::pool};
use tokio::try_join;
-use tracing::info;
+use tracing::{info, warn};
use crate::{
DB_SCHEMA,
@@ -40,9 +40,6 @@ pub async fn setup(cfg: &Config, reset: bool) -> anyhow::Result<()> {
}
let genesis_hash = rpc.get_genesis().await.unwrap();
- // TODO wait for the blockchain to sync && wallet scan ?
- // Wait for verification_progress = 1.0 and use initial_block_download as a hint
-
info!(target: "setup", "Check wallet");
rpc.load_wallet(&worker_cfg.wallet_cfg.name).await?;
if let Some(password) = &worker_cfg.wallet_cfg.password {
@@ -77,6 +74,21 @@ pub async fn setup(cfg: &Config, reset: bool) -> anyhow::Result<()> {
db::init_sync_state(&pool, &genesis_hash, reset)
)?;
+ let info = rpc.get_blockchain_info().await?;
+
+ if info.verification_progress < 1.0 {
+ if info.initial_block_download {
+ warn!(target: "setup", "node is initializing behind at {:.2}% of validation, you should wait for the validation to end before starting the worker", info.verification_progress);
+ } else {
+ warn!(target: "setup", "node is lagging behind at {:.2}% of validation, you should wait for the validation to end before starting the worker", info.verification_progress);
+ }
+ } else {
+ let wallet = rpc.get_wallet_info().await?;
+ if let Some(sync) = wallet.scanning {
+ warn!(target: "setup", "worker wallet is scanning at {:.2}%", sync.progress)
+ }
+ }
+
info!(target: "setup", "Worker setup");
Ok(())
}