Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KnowWhoami committed Jan 1, 2025
1 parent 4a3c042 commit cedfe95
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 159 deletions.
8 changes: 6 additions & 2 deletions directory.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[directory_config]
# Listening port
port = 8080
# Socks port
socks_port = 19060
connection_type = "tor"
# Connection type
connection_type = TOR
# RPC listening port
rpc_port = 4321
40 changes: 13 additions & 27 deletions maker.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
Think about this?
[maker_config]
# Listening port
port = 6102
# Time interval between connection checks
heart_beat_interval_secs = 3
# Time interval to ping the RPC backend
rpc_ping_interval_secs = 60
# Time interval to ping directory server
# 12 hours = 60*60*12 = 43200
directory_servers_refresh_interval_secs = 43200
# Time interval to close a connection if no response is received
idle_connection_timeout = 300
# Absolute coinswap fee
base_fee_sats = 1000
# Fee rate per swap amount in ppb.
amount_relative_fee_ppb = 10000000
# Fee rate for timelocked contract in ppb
time_relative_fee_ppb = 100000
# No of confirmation required for funding transaction
required_confirms = 1
# Minimum timelock difference between contract transaction of two hops
min_contract_reaction_time = 48
# Minimum coinswap amount size in sats
min_size = 10000
# RPC listening port
rpc_port
# Minimum Coinswap amount
min_swap_amount = 100000
# Socks port
socks_part = 19050
# Directory server onion address
directory_server_onion_address = "directoryhiddenserviceaddress.onion:8080"
connection_type = "tor"
socks_port = 19050
# Directory server address
directory_server_address = 127.0.0.1:8080
# Fidelity Bond amount
fidelity_amount = 5000000
# Fidelity Bond timelock in Block heights
fidelity_timelock = 26000
# Connection type
connection_type = TOR
7 changes: 2 additions & 5 deletions src/bin/directoryd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,15 @@ fn main() -> Result<(), DirectoryServerError> {
wallet_name: "random".to_string(), // we can put anything here as it will get updated in the init.
};

let conn_type = if cfg!(feature = "integration-test") {
ConnectionType::CLEARNET
} else {
ConnectionType::TOR
};
let conn_type = ConnectionType::TOR;

Check warning on line 60 in src/bin/directoryd.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/directoryd.rs#L60

Added line #L60 was not covered by tests

#[cfg(feature = "tor")]
{
if conn_type == ConnectionType::TOR {
setup_mitosis();
}
}

let directory = Arc::new(DirectoryServer::new(args.data_directory, Some(conn_type))?);

start_directory_server(directory, Some(rpc_config))?;
Expand Down
6 changes: 1 addition & 5 deletions src/bin/makerd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ fn main() -> Result<(), MakerError> {
wallet_name: "random".to_string(), // we can put anything here as it will get updated in the init.
};

let conn_type = if cfg!(feature = "integration-test") {
ConnectionType::CLEARNET
} else {
ConnectionType::TOR
};
let conn_type = ConnectionType::TOR;

Check warning on line 67 in src/bin/makerd.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/makerd.rs#L67

Added line #L67 was not covered by tests

#[cfg(feature = "tor")]
{
Expand Down
14 changes: 4 additions & 10 deletions src/bin/taker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bitcoind::bitcoincore_rpc::{json::ListUnspentResultEntry, Auth};
use clap::Parser;
use coinswap::{
taker::{error::TakerError, SwapParams, Taker, TakerBehavior},
utill::{parse_proxy_auth, setup_taker_logger, ConnectionType},
utill::{parse_proxy_auth, setup_taker_logger, ConnectionType, REQUIRED_CONFIRMS},
wallet::{Destination, RPCConfig, SendAmount},
};
use log::LevelFilter;
Expand Down Expand Up @@ -51,9 +51,6 @@ struct Cli {
/// Sets the transaction count.
#[clap(name = "tx_count", default_value = "3")]
pub tx_count: u32,
/// Sets the required on-chain confirmations.
#[clap(name = "required_confirms", default_value = "1000")]
pub required_confirms: u32,
/// List of sub commands to process various endpoints of taker cli app.
#[clap(subcommand)]
command: Commands,
Expand Down Expand Up @@ -98,11 +95,8 @@ fn main() -> Result<(), TakerError> {
let args = Cli::parse();

let rpc_network = bitcoin::Network::from_str(&args.bitcoin_network).unwrap();
let connection_type = if cfg!(feature = "integration-test") {
ConnectionType::CLEARNET
} else {
ConnectionType::TOR
};

let connection_type = ConnectionType::TOR;

Check warning on line 99 in src/bin/taker.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/taker.rs#L99

Added line #L99 was not covered by tests

let rpc_config = RPCConfig {
url: args.rpc,
Expand All @@ -115,7 +109,7 @@ fn main() -> Result<(), TakerError> {
send_amount: Amount::from_sat(args.send_amount),
maker_count: args.maker_count,
tx_count: args.tx_count,
required_confirms: args.required_confirms,
required_confirms: REQUIRED_CONFIRMS,
};

let mut taker = Taker::init(
Expand Down
17 changes: 12 additions & 5 deletions src/maker/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use crate::{
messages::{FidelityProof, ReqContractSigsForSender},
Hash160,
},
utill::{get_maker_dir, redeemscript_to_scriptpubkey, ConnectionType, HEART_BEAT_INTERVAL},
utill::{
get_maker_dir, redeemscript_to_scriptpubkey, ConnectionType, HEART_BEAT_INTERVAL,
REQUIRED_CONFIRMS,
},
wallet::{RPCConfig, SwapCoin, WalletSwapCoin},
};
use bitcoin::{
Expand Down Expand Up @@ -57,9 +60,6 @@ pub const RPC_PING_INTERVAL: Duration = Duration::from_secs(60);
/// Maker triggers the recovery mechanism, if Taker is idle for more than 300 secs.
pub const IDLE_CONNECTION_TIMEOUT: Duration = Duration::from_secs(300);

/// Number of confirmation required funding transaction.
pub const REQUIRED_CONFIRMS: u32 = 1;

/// The minimum difference in locktime (in blocks) between the incoming and outgoing swaps.
///
/// This value specifies the reaction time, in blocks, available to a Maker
Expand Down Expand Up @@ -591,6 +591,13 @@ pub fn check_for_broadcasted_contracts(maker: Arc<Maker>) -> Result<(), MakerErr
/// Broadcast the contract transactions and claim funds via timelock.
pub fn check_for_idle_states(maker: Arc<Maker>) -> Result<(), MakerError> {
let mut bad_ip = Vec::new();

let conn_timeout = if cfg!(feature = "integration-test") {
Duration::from_secs(60)
} else {
IDLE_CONNECTION_TIMEOUT
};

loop {
if maker.shutdown.load(Relaxed) {
break;
Expand All @@ -612,7 +619,7 @@ pub fn check_for_idle_states(maker: Arc<Maker>) -> Result<(), MakerError> {
ip,
no_response_since
);
if no_response_since > IDLE_CONNECTION_TIMEOUT {
if no_response_since > conn_timeout {
log::error!(
"[{}] Potential Dropped Connection from {}",
maker.config.port,
Expand Down
21 changes: 10 additions & 11 deletions src/maker/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ pub struct MakerConfig {
pub port: u16,
/// RPC listening port
pub rpc_port: u16,
/// Minimum swap size.
/// Minimum Coinswap amount
pub min_swap_amount: u64,
/// Socks port
pub socks_port: u16,
/// Directory server address (can be clearnet or onion)
pub directory_server_address: String,
/// Fidelity Bond Value
pub fidelity_value: u64,
/// Fidelity Bond amount
pub fidelity_amount: u64,
/// Fidelity Bond timelock in Block heights.
pub fidelity_timelock: u32,
/// Connection type
Expand All @@ -38,8 +38,8 @@ impl Default for MakerConfig {
min_swap_amount: MIN_SWAP_AMOUNT,
socks_port: 19050,
directory_server_address: "127.0.0.1:8080".to_string(),
fidelity_value: 5_000_000, // 5 million sats
fidelity_timelock: 26_000, // Approx 6 months of blocks
fidelity_amount: 5_000_000, // 5 million sats
fidelity_timelock: 26_000, // Approx 6 months of blocks
connection_type: {
#[cfg(feature = "tor")]
{
Expand Down Expand Up @@ -100,9 +100,9 @@ impl MakerConfig {
config_map.get("directory_server_address"),
default_config.directory_server_address,
),
fidelity_value: parse_field(
config_map.get("fidelity_value"),
default_config.fidelity_value,
fidelity_amount: parse_field(
config_map.get("fidelity_amount"),
default_config.fidelity_amount,
),
fidelity_timelock: parse_field(
config_map.get("fidelity_timelock"),
Expand All @@ -123,15 +123,15 @@ rpc_port = {}
min_swap_amount = {}
socks_port = {}
directory_server_address = {}
fidelity_value = {}
fidelity_amount = {}
fidelity_timelock = {}
connection_type = {:?}",
self.port,
self.rpc_port,
self.min_swap_amount,
self.socks_port,
self.directory_server_address,
self.fidelity_value,
self.fidelity_amount,
self.fidelity_timelock,
self.connection_type,
);
Expand Down Expand Up @@ -172,7 +172,6 @@ mod tests {
port = 6102
rpc_port = 6103
required_confirms = 1
min_contract_reaction_time = 48
min_swap_amount = 100000
socks_port = 19050
"#;
Expand Down
13 changes: 2 additions & 11 deletions src/maker/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use bitcoind::bitcoincore_rpc::RpcApi;
use super::{
api::{
recover_from_swap, ConnectionState, ExpectedMessage, Maker, MakerBehavior,
AMOUNT_RELATIVE_FEE_PCT, BASE_FEE, MIN_CONTRACT_REACTION_TIME, REQUIRED_CONFIRMS,
TIME_RELATIVE_FEE_PCT,
AMOUNT_RELATIVE_FEE_PCT, BASE_FEE, MIN_CONTRACT_REACTION_TIME, TIME_RELATIVE_FEE_PCT,
},
error::MakerError,
};
Expand All @@ -40,6 +39,7 @@ use crate::{
},
Hash160,
},
utill::REQUIRED_CONFIRMS,
wallet::{IncomingSwapCoin, SwapCoin, WalletError, WalletSwapCoin},
};

Expand Down Expand Up @@ -236,8 +236,6 @@ impl Maker {

if total_funding_amount >= self.config.min_swap_amount
&& total_funding_amount < self.wallet.read()?.store.offer_maxsize
// TODO: Taker must not be allowed to send the amount beyond this range?
// why can't it be <= ?
{
log::info!(
"[{}] Total Funding Amount = {} | Funding Txids = {:?}",
Expand All @@ -249,7 +247,6 @@ impl Maker {
ContractSigsForSender { sigs },
))
} else {
// Instead , we must create a MakerToTakerMessage variant stating about it rather than giving error back to Maker itself.
Err(MakerError::General("not enough funds"))
}
}
Expand Down Expand Up @@ -425,12 +422,6 @@ impl Maker {
act_funding_txs_fees
);

// log::info!(
// "Refund Tx locktime (blocks) = {} | Total Funding Tx Mining Fees = {} | ",
// message.refund_locktime,
// act_funding_txs_fees
// );

connection_state.pending_funding_txes = my_funding_txes;
connection_state.outgoing_swapcoins = outgoing_swapcoins;

Expand Down
1 change: 0 additions & 1 deletion src/maker/rpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ pub fn start_rpc_server(maker: Arc<Maker>) -> Result<(), MakerError> {
// do nothing
} else {
log::error!("Error accepting RPC connection: {:?}", e);
return Err(e.into()); // Why are we returning the error instead of continuing?
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/maker/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ fn setup_fidelity_bond(maker: &Arc<Maker>, maker_address: &str) -> Result<(), Ma
*proof = Some(highest_proof);
} else {
// No bond in the wallet. Lets attempt to create one.
let amount = Amount::from_sat(maker.config.fidelity_value);
let amount = Amount::from_sat(maker.config.fidelity_amount);
let current_height = maker
.get_wallet()
.read()?
Expand Down
21 changes: 10 additions & 11 deletions src/protocol/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ pub struct HashPreimage {
}

/// Multisig Privatekeys used in the last step of coinswap to perform privatekey handover.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct MultisigPrivkey {
pub multisig_redeemscript: ScriptBuf,
pub key: SecretKey,
}

/// Message to perform the final Privatekey Handover. This is the last message of the Coinswap Protocol.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize)]
pub struct PrivKeyHandover {
pub multisig_privkeys: Vec<MultisigPrivkey>,
}
Expand Down Expand Up @@ -221,22 +221,22 @@ impl Display for TakerToMakerMessage {
}

/// Represents the initial handshake message sent from Maker to Taker.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize)]
pub struct MakerHello {
pub protocol_version_min: u32,
pub protocol_version_max: u32,
}

/// Contains proof data related to fidelity bond.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Hash)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct FidelityProof {
pub bond: FidelityBond,
pub cert_hash: Hash,
pub cert_sig: bitcoin::secp256k1::ecdsa::Signature,
}

/// Represents an offer in the context of the Coinswap protocol.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, PartialOrd)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Offer {
pub base_fee: u64, // base fee in sats
pub amount_relative_fee_pct: f64, // % fee on total amount
Expand All @@ -248,16 +248,15 @@ pub struct Offer {
pub tweakable_point: PublicKey,
pub fidelity: FidelityProof,
}
// TODO: Should Offer struct use Amount struct instead of u64?

/// Contract Tx signatures provided by a Sender of a Coinswap.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize)]
pub struct ContractSigsForSender {
pub sigs: Vec<Signature>,
}

/// Contract Tx and extra metadata from a Sender of a Coinswap
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize)]
pub struct SenderContractTxInfo {
pub contract_tx: Transaction,
pub timelock_pubkey: PublicKey,
Expand All @@ -269,7 +268,7 @@ pub struct SenderContractTxInfo {
/// for the Maker as both Sender and Receiver of Coinswaps.
///
/// This message is sent by a Maker after a [`ProofOfFunding`] has been received.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize)]
pub struct ContractSigsAsRecvrAndSender {
/// Contract Tx by which this maker is receiving Coinswap.
pub receivers_contract_txs: Vec<Transaction>,
Expand All @@ -278,13 +277,13 @@ pub struct ContractSigsAsRecvrAndSender {
}

/// Contract Tx signatures a Maker sends as a Receiver of CoinSwap.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize)]
pub struct ContractSigsForRecvr {
pub sigs: Vec<Signature>,
}

/// All messages sent from Maker to Taker.
#[derive(Debug, Serialize, Deserialize, PartialEq)] // why do we require PartialEq?
#[derive(Debug, Serialize, Deserialize)]
pub enum MakerToTakerMessage {
/// Protocol Handshake.
MakerHello(MakerHello),
Expand Down
Loading

0 comments on commit cedfe95

Please sign in to comment.