Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async manager #247

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 6 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ on:
push:
branches:
- master
- 'testci/**'
- "testci/**"
pull_request:

name: Continuous integration
Expand All @@ -26,7 +26,7 @@ jobs:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
components: rustfmt
- name: Check format
run: cargo fmt --all --check
no-std:
Expand All @@ -38,11 +38,11 @@ jobs:
- name: install clippy
run: rustup component add clippy
- name: Run clippy dlc
run: cargo clippy --no-default-features --features no-std -p dlc -- -D warnings
run: cargo clippy --no-default-features --features no-std -p ddk-dlc -- -D warnings
- name: Run clippy dlc-messages
run: cargo clippy --no-default-features --features no-std -p dlc-messages -- -D warnings
run: cargo clippy --no-default-features --features no-std -p ddk-messages -- -D warnings
- name: Run clippy dlc-trie
run: cargo clippy --no-default-features --features no-std -p dlc-trie -- -D warnings
run: cargo clippy --no-default-features --features no-std -p ddk-trie -- -D warnings
unit-tests:
name: unit-tests
runs-on: ubuntu-latest
Expand All @@ -68,7 +68,7 @@ jobs:
key: test-cache-${{ github.run_id }}-${{ github.run_number }}
- uses: actions/checkout@v4
- id: set-matrix
run: cargo test --no-run && echo "::set-output name=matrix::$(scripts/get_test_list.sh execution manager channel_execution)"
run: cargo test --no-run && echo "::set-output name=matrix::$(scripts/get_test_list.sh execution manager)"
integration_tests:
name: integration-tests
needs: integration_tests_prepare
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ members = [
"bitcoin-test-utils",
"bitcoin-rpc-provider",
"p2pd-oracle-client",
"dlc",
"dlc-messages",
"dlc-trie",
"dlc-manager",
"ddk-dlc",
"ddk-messages",
"ddk-trie",
"ddk-manager",
"mocks",
"sample",
"simple-wallet",
Expand Down
3 changes: 2 additions & 1 deletion bitcoin-rpc-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ name = "bitcoin-rpc-provider"
version = "0.1.0"

[dependencies]
async-trait = "0.1.83"
bitcoin = {version = "0.32.2"}
bitcoincore-rpc = {version = "0.19.0"}
bitcoincore-rpc-json = {version = "0.19.0"}
dlc-manager = {path = "../dlc-manager"}
ddk-manager = {path = "../ddk-manager"}
hex = { package = "hex-conservative", version = "0.1" }
lightning = { version = "0.0.125" }
log = "0.4.14"
Expand Down
15 changes: 8 additions & 7 deletions bitcoin-rpc-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use bitcoincore_rpc::jsonrpc::serde_json;
use bitcoincore_rpc::jsonrpc::serde_json::Value;
use bitcoincore_rpc::{json, Auth, Client, RpcApi};
use bitcoincore_rpc_json::AddressType;
use dlc_manager::error::Error as ManagerError;
use dlc_manager::{Blockchain, ContractSignerProvider, SimpleSigner, Utxo, Wallet};
use ddk_manager::error::Error as ManagerError;
use ddk_manager::{Blockchain, ContractSignerProvider, SimpleSigner, Utxo, Wallet};
use hex::DisplayHex;
use json::EstimateMode;
use lightning::chain::chaininterface::{ConfirmationTarget, FeeEstimator};
Expand Down Expand Up @@ -396,8 +396,9 @@ impl Wallet for BitcoinCoreProvider {
}
}

#[async_trait::async_trait]
impl Blockchain for BitcoinCoreProvider {
fn send_transaction(&self, transaction: &Transaction) -> Result<(), ManagerError> {
async fn send_transaction(&self, transaction: &Transaction) -> Result<(), ManagerError> {
self.client
.lock()
.unwrap()
Expand All @@ -418,23 +419,23 @@ impl Blockchain for BitcoinCoreProvider {
Ok(network)
}

fn get_blockchain_height(&self) -> Result<u64, ManagerError> {
async fn get_blockchain_height(&self) -> Result<u64, ManagerError> {
self.client
.lock()
.unwrap()
.get_block_count()
.map_err(rpc_err_to_manager_err)
}

fn get_block_at_height(&self, height: u64) -> Result<bitcoin::Block, ManagerError> {
async fn get_block_at_height(&self, height: u64) -> Result<bitcoin::Block, ManagerError> {
let client = self.client.lock().unwrap();
let hash = client
.get_block_hash(height)
.map_err(rpc_err_to_manager_err)?;
client.get_block(&hash).map_err(rpc_err_to_manager_err)
}

fn get_transaction(&self, tx_id: &Txid) -> Result<Transaction, ManagerError> {
async fn get_transaction(&self, tx_id: &Txid) -> Result<Transaction, ManagerError> {
let tx_info = self
.client
.lock()
Expand All @@ -446,7 +447,7 @@ impl Blockchain for BitcoinCoreProvider {
Ok(tx)
}

fn get_transaction_confirmations(&self, tx_id: &Txid) -> Result<u32, ManagerError> {
async fn get_transaction_confirmations(&self, tx_id: &Txid) -> Result<u32, ManagerError> {
let tx_info_res = self.client.lock().unwrap().get_transaction(tx_id, None);
match tx_info_res {
Ok(tx_info) => Ok(tx_info.info.confirmations as u32),
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions dlc/Cargo.toml → ddk-dlc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
authors = ["Crypto Garage"]
authors = ["Crypto Garage", "benny b <[email protected]>"]
description = "Creation, signing and verification of Discreet Log Contracts (DLC) transactions."
homepage = "https://github.com/p2pderivatives/rust-dlc"
homepage = "https://github.com/bennyhodl/rust-dlc"
license-file = "../LICENSE"
name = "dlc"
repository = "https://github.com/p2pderivatives/rust-dlc/tree/master/dlc"
name = "ddk-dlc"
repository = "https://github.com/bennyhodl/rust-dlc/tree/master/dlc"
version = "0.7.0"

[dependencies]
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions dlc/benches/benchmarks.rs → ddk-dlc/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

extern crate bitcoin;
extern crate bitcoin_test_utils;
extern crate dlc;
extern crate ddk_dlc;
extern crate rayon;
extern crate secp256k1_zkp;
#[cfg(all(test, feature = "unstable"))]
Expand All @@ -13,7 +13,7 @@ mod benches {

use bitcoin::{ScriptBuf, Transaction};
use bitcoin_test_utils::tx_from_string;
use dlc::*;
use ddk_dlc::*;
use rayon::prelude::*;
use secp256k1_zkp::{
global::SECP256K1, rand::thread_rng, rand::RngCore, Keypair, Message, PublicKey, SecretKey,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 15 additions & 13 deletions dlc-manager/Cargo.toml → ddk-manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
[package]
authors = ["Crypto Garage"]
authors = ["Crypto Garage", "benny b <[email protected]>"]
description = "Creation and handling of Discrete Log Contracts (DLC)."
edition = "2018"
homepage = "https://github.com/p2pderivatives/rust-dlc"
edition = "2021"
homepage = "https://github.com/bennyhodl/rust-dlc"
license-file = "../LICENSE"
name = "dlc-manager"
repository = "https://github.com/p2pderivatives/rust-dlc/tree/master/dlc-manager"
name = "ddk-manager"
repository = "https://github.com/bennyhodl/rust-dlc/tree/master/dlc-manager"
version = "0.7.0"

[features]
default = ["std"]
std = ["dlc/std", "dlc-messages/std", "dlc-trie/std", "bitcoin/std", "lightning/std"]
std = ["ddk-dlc/std", "ddk-messages/std", "ddk-trie/std", "bitcoin/std", "lightning/std"]
fuzztarget = ["rand_chacha"]
parallel = ["dlc-trie/parallel"]
use-serde = ["serde", "dlc/use-serde", "dlc-messages/use-serde", "dlc-trie/use-serde"]
parallel = ["ddk-trie/parallel"]
use-serde = ["serde", "ddk-dlc/use-serde", "ddk-messages/use-serde", "ddk-trie/use-serde"]

[dependencies]
async-trait = "0.1.50"
bitcoin = { version = "0.32.2", default-features = false }
dlc = { version = "0.7.0", default-features = false, path = "../dlc" }
dlc-messages = { version = "0.7.0", default-features = false, path = "../dlc-messages" }
dlc-trie = { version = "0.7.0", default-features = false, path = "../dlc-trie" }
ddk-dlc = { version = "0.7.0", default-features = false, path = "../ddk-dlc" }
ddk-messages = { version = "0.7.0", default-features = false, path = "../ddk-messages" }
ddk-trie = { version = "0.7.0", default-features = false, path = "../ddk-trie" }
futures = "0.3.31"
hex = { package = "hex-conservative", version = "0.1" }
lightning = { version = "0.0.125", default-features = false, features = ["grind_signatures"] }
log = "0.4.14"
Expand All @@ -34,15 +35,16 @@ bitcoin-test-utils = {path = "../bitcoin-test-utils"}
bitcoincore-rpc = {version = "0.19"}
bitcoincore-rpc-json = {version = "0.19"}
criterion = "0.4.0"
dlc-manager = { path = ".", default-features = false, features = ["use-serde"] }
dlc-messages = { path = "../dlc-messages", default-features = false, features = ["serde"] }
ddk-manager = { path = ".", default-features = false, features = ["use-serde"] }
ddk-messages = { path = "../ddk-messages", default-features = false, features = ["serde"] }
electrs-blockchain-provider = {path = "../electrs-blockchain-provider"}
env_logger = "0.9.1"
mocks = {path = "../mocks"}
secp256k1-zkp = {version = "0.11.0", features = ["hashes", "rand", "rand-std", "global-context", "serde"]}
serde = "1.0"
serde_json = "1.0"
simple-wallet = {path = "../simple-wallet"}
tokio = { version = "1.41.1", features = ["macros", "rt-multi-thread", "test-util", "fs"] }

[[bench]]
harness = false
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ use bitcoin::OutPoint;
use bitcoin::ScriptBuf;
use bitcoin::WPubkeyHash;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use dlc::create_dlc_transactions;
use dlc::DlcTransactions;
use dlc::PartyParams;
use dlc::Payout;
use dlc::TxInputInfo;
use dlc_manager::contract::contract_info::ContractInfo;
use dlc_manager::contract::numerical_descriptor::DifferenceParams;
use dlc_manager::contract::numerical_descriptor::NumericalDescriptor;
use dlc_manager::contract::ContractDescriptor;
use dlc_manager::payout_curve::PayoutFunction;
use dlc_manager::payout_curve::PayoutFunctionPiece;
use dlc_manager::payout_curve::PayoutPoint;
use dlc_manager::payout_curve::PolynomialPayoutCurvePiece;
use dlc_manager::payout_curve::RoundingInterval;
use dlc_manager::payout_curve::RoundingIntervals;
use dlc_messages::oracle_msgs::DigitDecompositionEventDescriptor;
use dlc_messages::oracle_msgs::EventDescriptor;
use dlc_messages::oracle_msgs::OracleAnnouncement;
use dlc_messages::oracle_msgs::OracleEvent;
use ddk_dlc::create_dlc_transactions;
use ddk_dlc::DlcTransactions;
use ddk_dlc::PartyParams;
use ddk_dlc::Payout;
use ddk_dlc::TxInputInfo;
use ddk_manager::contract::contract_info::ContractInfo;
use ddk_manager::contract::numerical_descriptor::DifferenceParams;
use ddk_manager::contract::numerical_descriptor::NumericalDescriptor;
use ddk_manager::contract::ContractDescriptor;
use ddk_manager::payout_curve::PayoutFunction;
use ddk_manager::payout_curve::PayoutFunctionPiece;
use ddk_manager::payout_curve::PayoutPoint;
use ddk_manager::payout_curve::PolynomialPayoutCurvePiece;
use ddk_manager::payout_curve::RoundingInterval;
use ddk_manager::payout_curve::RoundingIntervals;
use ddk_messages::oracle_msgs::DigitDecompositionEventDescriptor;
use ddk_messages::oracle_msgs::EventDescriptor;
use ddk_messages::oracle_msgs::OracleAnnouncement;
use ddk_messages::oracle_msgs::OracleEvent;
use secp256k1_zkp::{
global::SECP256K1, rand::thread_rng, schnorr::Signature, Keypair, SecretKey, XOnlyPublicKey,
};
Expand Down Expand Up @@ -120,7 +120,7 @@ fn create_contract_descriptor() -> ContractDescriptor {
rounding_mod: ROUNDING_MOD,
}],
},
oracle_numeric_infos: dlc_trie::OracleNumericInfo {
oracle_numeric_infos: ddk_trie::OracleNumericInfo {
base: BASE as usize,
nb_digits: std::iter::repeat(NB_DIGITS)
.take(NB_ORACLES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::collections::HashMap;

use bitcoin::{Block, OutPoint, Transaction, Txid};
use dlc_messages::ser_impls::{
use ddk_messages::ser_impls::{
read_ecdsa_adaptor_signature, read_hash_map, write_ecdsa_adaptor_signature, write_hash_map,
};
use lightning::ln::msgs::DecodeError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # Structure and methods for channels that have been accepted.

use bitcoin::{ScriptBuf, Transaction};
use dlc_messages::channel::AcceptChannel;
use ddk_messages::channel::AcceptChannel;
use secp256k1_zkp::{EcdsaAdaptorSignature, PublicKey};

use crate::{contract::accepted_contract::AcceptedContract, ChannelId, ContractId};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # Module containing structures and methods for working with DLC channels.

use bitcoin::{hashes::Hash, Transaction, Txid};
use dlc_messages::channel::{AcceptChannel, SignChannel};
use ddk_messages::channel::{AcceptChannel, SignChannel};
use secp256k1_zkp::PublicKey;

use crate::{ChannelId, ContractId};
Expand Down Expand Up @@ -29,10 +29,10 @@ pub enum Channel {
/// A channel whose fund outputs have been signed by the offer party.
Signed(SignedChannel),
/// A channel that failed when validating an
/// [`dlc_messages::channel::AcceptChannel`] message.
/// [`ddk_messages::channel::AcceptChannel`] message.
FailedAccept(FailedAccept),
/// A channel that failed when validating an
/// [`dlc_messages::channel::SignChannel`] message.
/// [`ddk_messages::channel::SignChannel`] message.
FailedSign(FailedSign),
/// A [`OfferedChannel`] that got rejected by the counterparty.
Cancelled(OfferedChannel),
Expand Down Expand Up @@ -95,32 +95,32 @@ impl Channel {
}

/// A channel that failed when validating an
/// [`dlc_messages::channel::AcceptChannel`] message.
/// [`ddk_messages::channel::AcceptChannel`] message.
#[derive(Clone)]
pub struct FailedAccept {
/// The [`secp256k1_zkp::PublicKey`] of the counter party.
pub counter_party: PublicKey,
/// The temporary [`crate::ChannelId`] of the channel.
pub temporary_channel_id: ChannelId,
/// An message describing the error encountered while validating the
/// [`dlc_messages::channel::AcceptChannel`] message.
/// [`ddk_messages::channel::AcceptChannel`] message.
pub error_message: String,
/// The [`dlc_messages::channel::AcceptChannel`] that was received.
/// The [`ddk_messages::channel::AcceptChannel`] that was received.
pub accept_message: AcceptChannel,
}

/// A channel that failed when validating an
/// [`dlc_messages::channel::SignChannel`] message.
/// [`ddk_messages::channel::SignChannel`] message.
#[derive(Clone)]
pub struct FailedSign {
/// The [`secp256k1_zkp::PublicKey`] of the counter party.
pub counter_party: PublicKey,
/// The [`crate::ChannelId`] of the channel.
pub channel_id: ChannelId,
/// An message describing the error encountered while validating the
/// [`dlc_messages::channel::SignChannel`] message.
/// [`ddk_messages::channel::SignChannel`] message.
pub error_message: String,
/// The [`dlc_messages::channel::SignChannel`] that was received.
/// The [`ddk_messages::channel::SignChannel`] that was received.
pub sign_message: SignChannel,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! # A channel is offered when an offer was made or received. This module contains
//! the model for it and method for working with it.

use dlc::PartyParams;
use dlc_messages::channel::OfferChannel;
// use dlc_messages::channel::OfferChannel;
use ddk_dlc::PartyParams;
use ddk_messages::channel::OfferChannel;
// use ddk_messages::channel::OfferChannel;
use secp256k1_zkp::PublicKey;

use crate::{
Expand All @@ -19,7 +19,7 @@ use super::party_points::PartyBasePoints;
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "camelCase")
)]
/// A DLC channel for which an [`dlc_messages::channel::OfferChannel`] message
/// A DLC channel for which an [`ddk_messages::channel::OfferChannel`] message
/// was sent or received.
pub struct OfferedChannel {
/// The temporary [`crate::ContractId`] of the contract that was offered for
Expand Down Expand Up @@ -73,7 +73,7 @@ impl OfferedChannel {
}

/// Creates an [`OfferedChannel`] and [`crate::contract::offered_contract::OfferedContract`]
/// from an [`dlc_messages::channel::OfferChannel`] message. Fails if the
/// from an [`ddk_messages::channel::OfferChannel`] message. Fails if the
/// transactions provided for funding cannot be decoded or the UTXO information
/// are invalid, or if the contract information is invalid.
pub fn from_offer_channel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use super::utils::{derive_public_key, derive_public_revocation_key};
use bitcoin::PublicKey as BitcoinPublicKey;
use dlc::channel::RevokeParams;
use ddk_dlc::channel::RevokeParams;
use secp256k1_zkp::{All, PublicKey, Secp256k1, Signing, Verification};

/// Base points used by a party of a DLC channel to derive public and private
Expand Down
Loading
Loading