Skip to content

Commit

Permalink
Use threshold const
Browse files Browse the repository at this point in the history
  • Loading branch information
keppel committed Oct 27, 2023
1 parent 8f9b333 commit 6c2f3b0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
6 changes: 2 additions & 4 deletions src/bitcoin/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use orga::{
Error as OrgaError, Result as OrgaResult,
};

use super::SIGSET_THRESHOLD;
use orga::{describe::Describe, store::Store};
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
Expand Down Expand Up @@ -966,10 +967,7 @@ impl Config {
target_checkpoint_inclusion: 2,
min_fee_rate: 2, // relay threshold is 1 sat/vbyte
max_fee_rate: 200,
#[cfg(feature = "testnet")]
sigset_threshold: (9, 10),
#[cfg(not(feature = "testnet"))]
sigset_threshold: (2, 3),
sigset_threshold: SIGSET_THRESHOLD,
emergency_disbursal_min_tx_amt: 1000,
#[cfg(feature = "testnet")]
emergency_disbursal_lock_time_interval: 60 * 60 * 24 * 7, // one week
Expand Down
6 changes: 6 additions & 0 deletions src/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ pub const NETWORK: ::bitcoin::Network = ::bitcoin::Network::Testnet;
#[cfg(all(feature = "devnet", feature = "testnet"))]
pub const NETWORK: ::bitcoin::Network = ::bitcoin::Network::Regtest;

// TODO: move to config
#[cfg(feature = "testnet")]
pub const SIGSET_THRESHOLD: (u64, u64) = (9, 10);
#[cfg(not(feature = "testnet"))]
pub const SIGSET_THRESHOLD: (u64, u64) = (2, 3);

/// The configuration parameters for the Bitcoin module.
#[orga(skip(Default), version = 3)]
pub struct Config {
Expand Down
13 changes: 4 additions & 9 deletions src/bitcoin/relayer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::signatory::Signatory;
use super::SignatorySet;
use super::SIGSET_THRESHOLD;
use crate::app::Dest;
use crate::app_client;
use crate::bitcoin::deposit_index::{Deposit, DepositIndex};
Expand Down Expand Up @@ -33,12 +34,6 @@ where

const HEADER_BATCH_SIZE: usize = 250;

// TODO: get dynamically from sigset
#[cfg(feature = "testnet")]
const THRESHOLD: (u64, u64) = (9, 10);
#[cfg(not(feature = "testnet"))]
const THRESHOLD: (u64, u64) = (2, 3);

#[derive(Serialize, Deserialize)]
pub struct DepositsQuery {
pub receiver: String,
Expand Down Expand Up @@ -195,7 +190,7 @@ impl Relayer {
&sigset
.output_script(
dest.commitment_bytes().map_err(|_| reject())?.as_slice(),
THRESHOLD,
SIGSET_THRESHOLD,
)
.map_err(warp::reject::custom)?,
super::NETWORK,
Expand Down Expand Up @@ -1023,7 +1018,7 @@ impl WatchedScripts {
}

pub fn insert(&mut self, dest: Dest, sigset: &SignatorySet) -> Result<bool> {
let script = self.derive_script(&dest, sigset, THRESHOLD)?;
let script = self.derive_script(&dest, sigset, SIGSET_THRESHOLD)?;

if self.scripts.contains_key(&script) {
return Ok(false);
Expand All @@ -1049,7 +1044,7 @@ impl WatchedScripts {
}

for dest in dests {
let script = self.derive_script(dest, sigset, THRESHOLD)?; // TODO: get threshold from state
let script = self.derive_script(dest, sigset, SIGSET_THRESHOLD)?; // TODO: get threshold from state
self.scripts.remove(&script);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/bitcoin/threshold_sig.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::SignatorySet;
use super::{SignatorySet, SIGSET_THRESHOLD};
use bitcoin::blockdata::transaction::EcdsaSighashType;
use bitcoin::secp256k1::{
self,
Expand Down Expand Up @@ -258,7 +258,8 @@ impl ThresholdSig {
}

// TODO: get threshold ratio from somewhere else
ts.threshold = ((total_vp as u128) * 9 / 10) as u64;
ts.threshold =
((total_vp as u128) * SIGSET_THRESHOLD.0 as u128 / SIGSET_THRESHOLD.1 as u128) as u64;

Ok(ts)
}
Expand All @@ -281,7 +282,8 @@ impl ThresholdSig {
}

// TODO: get threshold ratio from somewhere else
ts.threshold = ((total_vp as u128) * 9 / 10) as u64;
ts.threshold =
((total_vp as u128) * SIGSET_THRESHOLD.0 as u128 / SIGSET_THRESHOLD.1 as u128) as u64;
ts.len = len;

Ok(ts)
Expand Down

0 comments on commit 6c2f3b0

Please sign in to comment.