Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bitcoind.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@
else "aarch64-linux-gnu"
else throw "Unsupported platform";

# Platform-specific hashes
hashes = {
"x86_64-apple-darwin-unsigned" = "sha256-CaYWts/zywipxAAKqiFNNFFEHyR1uZ+2dgrFHhE8BTE=";
"arm64-apple-darwin-unsigned" = "sha256-fq38pBiLmq14+tqlYBlIT/L1Zo+HyhGYMu1wh9KiDkc=";
"x86_64-linux-gnu" = "sha256-REnq1YT+3AjUAoeyg/BjLqm3ap82U5HxCrrkd4LTFFA=";
"aarch64-linux-gnu" = "sha256-M8RDnoYS11cpSEDOEya2byIHYw8nZLpJr8Z/ap8rHxU=";
};

# Construct the appropriate binary URL
binaryUrl = "https://github.com/Sjors/bitcoin/releases/download/sv2-tp-0.1.17/bitcoin-sv2-tp-0.1.17-${platform}.tar.gz";

# Fetch the pre-built binary
binary = pkgs.fetchurl {
url = binaryUrl;
hash = "sha256-REnq1YT+3AjUAoeyg/BjLqm3ap82U5HxCrrkd4LTFFA=";
hash = hashes.${platform};
};
in
pkgs.stdenv.mkDerivation {
Expand Down
2 changes: 1 addition & 1 deletion protocols/v2/subprotocols/mining/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ serde = { version = "1.0.89", default-features = false, optional= true }
binary_sv2 = {version = "^1.0.0", path = "../../binary-sv2/binary-sv2" }
const_sv2 = {version = "^3.0.0", path = "../../const-sv2"}
derive_codec_sv2 = {version = "^1.0.0", path = "../../../../protocols/v2/binary-sv2/no-serde-sv2/derive_codec"}
cdk = { git = "https://github.com/vnprc/cdk", rev = "f057cc87" }
cdk = { git = "https://github.com/vnprc/cdk", rev = "773af52b" }
serde_json = "1.0"

[dev-dependencies]
Expand Down
28 changes: 14 additions & 14 deletions roles/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions roles/mint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
bitcoin = { version= "0.32.2" }

cdk = { git = "https://github.com/vnprc/cdk.git", package = "cdk", rev = "f057cc87" }
cdk-axum = { git = "https://github.com/vnprc/cdk.git", package = "cdk-axum", rev = "f057cc87" }
cdk-mintd = { git = "https://github.com/vnprc/cdk.git", package = "cdk-mintd", rev = "f057cc87" }
cdk-sqlite = { git = "https://github.com/vnprc/cdk.git", package = "cdk-sqlite", rev = "f057cc87" }
cdk-redb = { git = "https://github.com/vnprc/cdk.git", package = "cdk-redb", rev = "f057cc87" }
cdk = { git = "https://github.com/vnprc/cdk.git", package = "cdk", rev = "773af52b" }
cdk-axum = { git = "https://github.com/vnprc/cdk.git", package = "cdk-axum", rev = "773af52b" }
cdk-mintd = { git = "https://github.com/vnprc/cdk.git", package = "cdk-mintd", rev = "773af52b" }
cdk-sqlite = { git = "https://github.com/vnprc/cdk.git", package = "cdk-sqlite", rev = "773af52b" }
cdk-redb = { git = "https://github.com/vnprc/cdk.git", package = "cdk-redb", rev = "773af52b" }
2 changes: 1 addition & 1 deletion roles/pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ key-utils = { version = "^1.0.0", path = "../../utils/key-utils" }
bip39 = { version = "2.0", features = ["rand"] }
mining_sv2 = { version = "^1.0.0", path = "../../protocols/v2/subprotocols/mining" }
bitcoin = { version= "0.32.2" }
cdk = { git = "https://github.com/vnprc/cdk", rev = "f057cc87" }
cdk = { git = "https://github.com/vnprc/cdk", rev = "773af52b" }
bitcoin_hashes = { version = "0.16", features = ["serde"] }
redis = { version = "0.25", features = ["tokio-comp"] }

Expand Down
2 changes: 1 addition & 1 deletion roles/translator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async-compat = "0.2.1"
rand = "0.8.4"
bitcoin = "0.30"
mining_sv2 = { version = "^1.0.0", path = "../../protocols/v2/subprotocols/mining" }
cdk = { git = "https://github.com/vnprc/cdk", rev = "f057cc87" }
cdk = { git = "https://github.com/vnprc/cdk", rev = "773af52b" }
uuid = { version = "1", features = ["v4"] }
ureq = { version = "2", features = ["tls"] }
# TODO delete after implementing the cdk HTTP API to retrieve quote id from header hash
Expand Down
95 changes: 26 additions & 69 deletions roles/translator/src/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,6 @@ pub struct TranslatorSv2 {
wallet: Arc<Wallet>,
}

use serde::Serialize;

#[derive(Serialize)]
struct Output {
amount: u64,
id: String,
#[serde(rename = "B_")]
pubkey: String,
}

#[derive(Serialize)]
struct QuotePayload {
quote: String,
outputs: Vec<Output>,
}

fn create_wallet() -> Arc<Wallet> {
use cdk::cdk_database::WalletMemoryDatabase;
use cdk::nuts::CurrencyUnit;
Expand Down Expand Up @@ -105,7 +89,7 @@ impl TranslatorSv2 {
debug!("Starting up status listener");
let wait_time = self.reconnect_wait_time;

self.spawn_quote_logger();
self.spawn_proof_sweeper();

// Check all tasks if is_finished() is true, if so exit
loop {
Expand Down Expand Up @@ -318,7 +302,7 @@ impl TranslatorSv2 {
task_collector.safe_lock(|t| t.push((task.abort_handle(), "init task".to_string())));
}

fn spawn_quote_logger(&self) {
fn spawn_proof_sweeper(&self) {
let wallet = self.wallet.clone();
task::spawn_blocking(move || {
use redis::Commands;
Expand Down Expand Up @@ -353,8 +337,10 @@ impl TranslatorSv2 {
};

for quote in &quotes {
// quote ID is set to share hash in the wallet, it's a UUID at the mint
let redis_key = format!("mint:quotes:hash:{}", quote.id);

// get the UUID quote ID from the mint
let uuid: Option<String> = loop {
match conn.get(&redis_key) {
Ok(s) => break Some(s),
Expand All @@ -370,44 +356,31 @@ impl TranslatorSv2 {
continue;
};

let premint_secrets = match rt.block_on(wallet.localstore.get_premint_secrets(&quote.id)) {
Ok(Some(s)) => s,
_ => continue,
};

// TODO replace this manual API call with a wallet function
let payload = Self::build_quote_payload(uuid, &premint_secrets.secrets);

match serde_json::to_string(&payload) {
Ok(json) => {
tracing::info!("Sending JSON payload: {}", json);

let resp_result = ureq::post("http://127.0.0.1:3338/v1/mint/bolt11")
.set("Content-Type", "application/json")
.send_string(&json);

match resp_result {
Ok(resp) => {
let status = resp.status();
let status_text = resp.status_text().to_string();
let body = match resp.into_string() {
Ok(s) => s,
Err(e) => format!("(error reading body: {})", e),
};
tracing::info!(
"Payload sent successfully\nStatus: {} {}\nBody:\n{}",
status,
status_text,
body
);
}
Err(e) => {
tracing::warn!("Failed to send payload: {:?}", e);
}
let proofs_result = rt.block_on(wallet.get_mining_share_proofs(&uuid, &quote.id));
match proofs_result {
Ok(_proofs) => {
match rt.block_on(wallet.total_balance()) {
Ok(balance) => info!(
"Successfully minted ehash tokens for share {} with amount {}. Total wallet balance: {}",
quote.id,
quote.amount,
balance
),
Err(e) => info!(
"Minted ehash tokens for share {} with amount {}, but failed to get total balance: {:?}",
quote.id,
quote.amount,
e
),
}

// delete quote id from redis
if let Err(e) = conn.del::<_, ()>(&redis_key) {
tracing::warn!("Failed to delete Redis key {}: {:?}", redis_key, e);
}
}
Err(e) => {
tracing::warn!("Failed to serialize payload: {:?}", e);
info!("Failed to mint ehash tokens for share {} error: {}", quote.id, e);
}
}
}
Expand All @@ -416,22 +389,6 @@ impl TranslatorSv2 {
}
});
}

fn build_quote_payload(quote_id: String, premint_secrets: &[cdk::nuts::PreMint]) -> QuotePayload {
let outputs = premint_secrets
.iter()
.map(|s| Output {
amount: s.blinded_message.amount.into(),
id: s.blinded_message.keyset_id.to_string(),
pubkey: s.blinded_message.blinded_secret.to_hex(),
})
.collect();

QuotePayload {
quote: quote_id,
outputs,
}
}
}

fn kill_tasks(task_collector: Arc<Mutex<Vec<(AbortHandle, String)>>>) {
Expand Down
2 changes: 1 addition & 1 deletion roles/translator/src/lib/upstream_sv2/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ impl ParseUpstreamMiningMessages<Downstream, NullDownstreamMiningSelector, NoRou
let amount = calculate_work(m.hash.inner_as_ref().try_into().expect("not 32 bytes"));

info!(
"Hashpool created a quote for share {} with value {}",
"Successfully created a quote for share {} with value {}",
share_hash,
amount,
);
Expand Down
Loading