Skip to content

Commit

Permalink
Merge #855
Browse files Browse the repository at this point in the history
855: chore: add oracle to setup r=holzeis a=holzeis

- Adds the oracle service to docker-compose
- Configurable oracle endpoint and public key on app and coordinator

fixes https://github.com/get10101/cloud-conf/issues/211



Co-authored-by: Richard Holzeis <[email protected]>
  • Loading branch information
bors[bot] and holzeis authored Jun 29, 2023
2 parents e58fe60 + 313f754 commit 79dfcce
Show file tree
Hide file tree
Showing 20 changed files with 250 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
coordinator_port_http: 80
network: mainnet
tag: ${{ github.ref_name }}
oracle_endpoint: http://api.10101.finance:8081
oracle_pubkey: 67532a288516236e0a6a8018ae6fcd3c59cfcf28da58f4ac2b2b727a59fc6db5

build_android_apk:
runs-on: macos-latest
Expand Down Expand Up @@ -125,6 +127,8 @@ jobs:
--dart-define="NETWORK=$NETWORK" \
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="ORACLE_ENDPOINT=$ORACLE_ENDPOINT" \
--dart-define="ORACLE_PUBKEY=$ORACLE_PUBKEY" \
--build-name=$BUILD_NAME --build-number=$BUILD_NUMBER \
--release
mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/get10101-$BUILD_NAME.apk
Expand All @@ -138,6 +142,8 @@ jobs:
COORDINATOR_P2P_ENDPOINT: 022ae8dbec1caa4dac93f07f2ebf5ad7a5dd08d375b79f11095e81b065c2155156@34.30.20.202:9045
NETWORK: regtest
COORDINATOR_PORT_HTTP: 80
ORACLE_ENDPOINT: http://api.test.10101.finance:8081
ORACLE_PUBKEY: 5d12d79f575b8d99523797c46441c0549eb0defb6195fe8a080000cbe3ab3859

- name: Upload APK to job
uses: actions/upload-artifact@v3
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deliverables-push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ jobs:
coordinator_port_http: 80
network: regtest
tag: main
oracle_endpoint: http://api.test.10101.finance:8081
oracle_pubkey: 5d12d79f575b8d99523797c46441c0549eb0defb6195fe8a080000cbe3ab3859
18 changes: 18 additions & 0 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ on:
required: true
description: "The branch, tag or SHA to checkout."
type: string
oracle_endpoint:
required: true
type: string
oracle_pubkey:
required: true
description: "The public key of the oracle. Must match with the public key returned at http://${oracle_endpoint}/oracle/publickey"
type: string
workflow_dispatch:
inputs:
coordinator_port_http:
Expand All @@ -39,6 +46,13 @@ on:
required: true
description: "The branch, tag or SHA to checkout."
type: string
oracle_endpoint:
required: true
type: string
oracle_pubkey:
required: true
description: "The public key of the oracle. Must match with the public key returned at http://${oracle_endpoint}/oracle/publickey"
type: string

jobs:
build:
Expand Down Expand Up @@ -148,13 +162,17 @@ jobs:
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="COORDINATOR_PORT_HTTP=$COORDINATOR_PORT_HTTP" \
--dart-define="ORACLE_ENDPOINT=$ORACLE_ENDPOINT" \
--dart-define="ORACLE_PUBKEY=$ORACLE_PUBKEY" \
--build-name=$BUILD_NAME \
--build-number=$BUILD_NUMBER
env:
ESPLORA_ENDPOINT: ${{ inputs.esplora_endpoint }}
COORDINATOR_P2P_ENDPOINT: ${{ inputs.coordinator_p2p_endpoint }}
NETWORK: ${{ inputs.network }}
COORDINATOR_PORT_HTTP: ${{ inputs.coordinator_port_http }}
ORACLE_ENDPOINT: ${{ inputs.oracle_endpoint }}
ORACLE_PUBKEY: ${{ inputs.oracle_pubkey }}

- name: Release to TestFlight
env:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- Fix panic when processing accept message while peer is disconnected.
- Configurable oracle endpoint and public key
- Removed stop-gap from receiving payments with open position.
- Reduced min amount of 50k sats on receiving payments.

Expand Down
3 changes: 2 additions & 1 deletion coordinator/src/bin/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ async fn main() -> Result<()> {
address,
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), address.port()),
opts.p2p_announcement_addresses(),
opts.esplora,
opts.esplora.clone(),
seed,
ephemeral_randomness,
settings.ln_dlc.clone(),
opts.get_oracle_info(),
)?);

// set up database connection pool
Expand Down
22 changes: 22 additions & 0 deletions coordinator/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use anyhow::Result;
use bitcoin::XOnlyPublicKey;
use clap::Parser;
use lightning::ln::msgs::NetAddress;
use ln_dlc_node::node::OracleInfo;
use local_ip_address::local_ip;
use std::env::current_dir;
use std::net::IpAddr;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::str::FromStr;

#[derive(Parser)]
pub struct Opts {
Expand Down Expand Up @@ -50,6 +53,17 @@ pub struct Opts {
/// If specified, metrics will be printed at the given interval
#[clap(long)]
pub tokio_metrics_interval_seconds: Option<u64>,

// The endpoint of the p2pderivatives oracle
#[clap(long, default_value = "http://localhost:8081")]
oracle_endpoint: String,

// The public key of the oracle
#[clap(
long,
default_value = "16f88cf7d21e6c0f46bcbc983a4e3b19726c6c98858cc31c83551a88fde171c0"
)]
oracle_pubkey: String,
}

#[derive(Debug, Clone, Copy, clap::ValueEnum)]
Expand Down Expand Up @@ -81,6 +95,14 @@ impl Opts {
self.network.into()
}

pub fn get_oracle_info(&self) -> OracleInfo {
OracleInfo {
endpoint: self.oracle_endpoint.clone(),
public_key: XOnlyPublicKey::from_str(self.oracle_pubkey.as_str())
.expect("Valid oracle public key"),
}
}

pub fn data_dir(&self) -> Result<PathBuf> {
let data_dir = match self.data_dir.clone() {
None => current_dir()?.join("data"),
Expand Down
9 changes: 7 additions & 2 deletions crates/ln-dlc-node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ pub(crate) mod dlc_channel;
mod dlc_manager;
pub(crate) mod invoice;
mod ln_channel;
mod oracle_client;
mod oracle;
mod peer_manager;
mod storage;
mod sub_channel_manager;
mod wallet;

pub use self::dlc_manager::DlcManager;
pub use crate::node::oracle::OracleInfo;
pub use ::dlc_manager as rust_dlc_manager;
pub use channel_manager::ChannelManager;
pub use dlc_channel::dlc_message_name;
Expand Down Expand Up @@ -173,6 +174,7 @@ where
esplora_server_url: String,
seed: Bip39Seed,
ephemeral_randomness: [u8; 32],
oracle: OracleInfo,
) -> Result<Self> {
let user_config = app_config();
Node::new(
Expand All @@ -191,6 +193,7 @@ where
ephemeral_randomness,
user_config,
LnDlcNodeSettings::default(),
oracle.into(),
)
}

Expand All @@ -211,6 +214,7 @@ where
seed: Bip39Seed,
ephemeral_randomness: [u8; 32],
settings: LnDlcNodeSettings,
oracle: OracleInfo,
) -> Result<Self> {
let mut user_config = coordinator_config();

Expand All @@ -233,6 +237,7 @@ where
ephemeral_randomness,
user_config,
settings,
oracle.into(),
)
}

Expand All @@ -255,6 +260,7 @@ where
ephemeral_randomness: [u8; 32],
ldk_user_config: UserConfig,
settings: LnDlcNodeSettings,
oracle_client: P2PDOracleClient,
) -> Result<Self> {
let time_since_unix_epoch = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;

Expand Down Expand Up @@ -430,7 +436,6 @@ where
logger.clone(),
));

let oracle_client = oracle_client::build();
let oracle_client = Arc::new(oracle_client);

let dlc_manager = dlc_manager::build(
Expand Down
27 changes: 27 additions & 0 deletions crates/ln-dlc-node/src/node/oracle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::node::Node;
use bitcoin::secp256k1::XOnlyPublicKey;
use dlc_manager::Oracle;
use p2pd_oracle_client::P2PDOracleClient;
use serde::Deserialize;
use serde::Serialize;

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct OracleInfo {
pub endpoint: String,
pub public_key: XOnlyPublicKey,
}

impl From<OracleInfo> for P2PDOracleClient {
fn from(oracle: OracleInfo) -> Self {
P2PDOracleClient {
host: oracle.endpoint + "/",
public_key: oracle.public_key,
}
}
}

impl<P> Node<P> {
pub fn oracle_pk(&self) -> XOnlyPublicKey {
self.oracle.get_public_key()
}
}
24 changes: 0 additions & 24 deletions crates/ln-dlc-node/src/node/oracle_client.rs

This file was deleted.

10 changes: 10 additions & 0 deletions crates/ln-dlc-node/src/tests/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ use crate::ln::app_config;
use crate::node::InMemoryStore;
use crate::node::Node;
use crate::node::NodeInfo;
use crate::node::OracleInfo;
use crate::tests::init_tracing;
use crate::tests::wait_until_dlc_channel_state;
use crate::tests::SubChannelStateName;
use anyhow::Result;
use bitcoin::XOnlyPublicKey;
use coordinator::Coordinator;
use coordinator::Direction;
use std::borrow::Borrow;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;

mod coordinator;

const ESPLORA_ORIGIN_PUBLIC_REGTEST: &str = "http://35.189.57.114:3000";
const ORACLE_ORIGIN_PUBLIC_REGTEST: &str = "http://35.189.57.114:8081";
const ORACLE_PUBKEY_PUBLIC_REGTEST: &str =
"5d12d79f575b8d99523797c46441c0549eb0defb6195fe8a080000cbe3ab3859";

#[tokio::test(flavor = "multi_thread")]
async fn single_app_many_positions_load() {
Expand All @@ -26,6 +32,10 @@ async fn single_app_many_positions_load() {
"app",
app_config(),
ESPLORA_ORIGIN_PUBLIC_REGTEST.to_string(),
OracleInfo {
endpoint: ORACLE_ORIGIN_PUBLIC_REGTEST.to_string(),
public_key: XOnlyPublicKey::from_str(ORACLE_PUBKEY_PUBLIC_REGTEST).unwrap(),
},
)
.unwrap(),
);
Expand Down
33 changes: 30 additions & 3 deletions crates/ln-dlc-node/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::node::InMemoryStore;
use crate::node::LnDlcNodeSettings;
use crate::node::Node;
use crate::node::NodeInfo;
use crate::node::OracleInfo;
use crate::seed::Bip39Seed;
use crate::util;
use anyhow::Result;
Expand Down Expand Up @@ -38,6 +39,8 @@ use rust_decimal::Decimal;
use std::env::temp_dir;
use std::net::TcpListener;
use std::path::PathBuf;
use std::str::FromStr;
use std::string::ToString;
use std::sync::Once;
use std::time::Duration;
use tokio::task::block_in_place;
Expand All @@ -53,6 +56,8 @@ mod load;

const ESPLORA_ORIGIN: &str = "http://localhost:3000";
const FAUCET_ORIGIN: &str = "http://localhost:8080";
const ORACLE_ORIGIN: &str = "http://localhost:8081";
const ORACLE_PUBKEY: &str = "16f88cf7d21e6c0f46bcbc983a4e3b19726c6c98858cc31c83551a88fde171c0";

fn init_tracing() {
static TRACING_TEST_SUBSCRIBER: Once = Once::new();
Expand All @@ -77,14 +82,35 @@ fn init_tracing() {

impl Node<InMemoryStore> {
fn start_test_app(name: &str) -> Result<Self> {
Self::start_test(name, app_config(), ESPLORA_ORIGIN.to_string())
Self::start_test(
name,
app_config(),
ESPLORA_ORIGIN.to_string(),
OracleInfo {
endpoint: ORACLE_ORIGIN.to_string(),
public_key: XOnlyPublicKey::from_str(ORACLE_PUBKEY)?,
},
)
}

fn start_test_coordinator(name: &str) -> Result<Self> {
Self::start_test(name, coordinator_config(), ESPLORA_ORIGIN.to_string())
Self::start_test(
name,
coordinator_config(),
ESPLORA_ORIGIN.to_string(),
OracleInfo {
endpoint: ORACLE_ORIGIN.to_string(),
public_key: XOnlyPublicKey::from_str(ORACLE_PUBKEY)?,
},
)
}

fn start_test(name: &str, user_config: UserConfig, esplora_origin: String) -> Result<Self> {
fn start_test(
name: &str,
user_config: UserConfig,
esplora_origin: String,
oracle: OracleInfo,
) -> Result<Self> {
let data_dir = random_tmp_dir().join(name);

let seed = Bip39Seed::new().expect("A valid bip39 seed");
Expand All @@ -110,6 +136,7 @@ impl Node<InMemoryStore> {
ephemeral_randomness,
user_config,
LnDlcNodeSettings::default(),
oracle.into(),
)?;

tracing::debug!(%name, info = %node.info, "Node started");
Expand Down
3 changes: 3 additions & 0 deletions crates/tests-e2e/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ fn default_config() -> native::config::api::Config {
p2p_port: 9045,
http_port: 8000,
network: "regtest".to_string(),
oracle_endpoint: "http://127.0.0.1:8081".to_string(),
oracle_pubkey: "16f88cf7d21e6c0f46bcbc983a4e3b19726c6c98858cc31c83551a88fde171c0"
.to_string(),
}
}
1 change: 1 addition & 0 deletions database/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ GRANT ALL PRIVILEGES ON DATABASE orderbook TO orderbook_user;
CREATE USER maker_user;
CREATE DATABASE maker;
GRANT ALL PRIVILEGES ON DATABASE maker TO maker_user;
CREATE DATABASE oracle;
Loading

0 comments on commit 79dfcce

Please sign in to comment.