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
361 changes: 204 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ edition = "2021"
[dependencies]
# --- BITCOIN --- #

bitcoin = { version = "0.28.1", features = ["std", "use-serde"] }
bitcoin = { version = "0.29", features = ["std", "serde"] }
bitcoin-bech32 = "0.12"
base64 = "0.13.0"

# --- LIGHTNING --- #

lightning = { version = "0.0.110", features = ["max_level_trace"] }
# lightning-block-sync = { version = "0.0.110", features = [ "rpc-client" ] }
lightning-invoice = { version = "0.18" }
# lightning-net-tokio = { version = "0.0.110" }
lightning = { version = "0.0.111", features = ["max_level_trace"] }
# lightning-block-sync = { version = "0.0.111", features = [ "rpc-client" ] }
lightning-invoice = { version = "0.19" }
# lightning-net-tokio = { version = "0.0.111" }

# lightning = { git = "https://github.com/lexe-tech/rust-lightning", features = ["max_level_trace"], branch = "main" }
# lightning-block-sync = { git = "https://github.com/lexe-tech/rust-lightning", features = [ "rpc-client" ], branch = "main" }
Expand Down
2 changes: 1 addition & 1 deletion common/src/root_seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl RootSeed {
.ckd_priv(&secp_ctx, child_number)
.expect("should never fail")
.private_key;
KeyPair::from_secret_key(&secp_ctx, node_sk)
KeyPair::from_secret_key(&secp_ctx, &node_sk)
}

/// Derive the Lightning node pubkey.
Expand Down
10 changes: 5 additions & 5 deletions lexe-ln/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ common = { path = "../common" }

# --- BITCOIN --- #

bitcoin = { version = "0.28.1", features = ["use-serde"] }
bitcoin = { version = "0.29", features = ["serde"] }
bitcoin-bech32 = "0.12"
# bech32 = "0.8"
base64 = "0.13.0"

# --- LIGHTNING --- #

lightning = { version = "0.0.110", features = ["max_level_trace"] }
lightning-block-sync = { version = "0.0.110", features = [ "rpc-client" ] }
lightning-invoice = { version = "0.18" }
lightning-net-tokio = { version = "0.0.110" }
lightning = { version = "0.0.111", features = ["max_level_trace"] }
lightning-block-sync = { version = "0.0.111", features = [ "rpc-client" ] }
lightning-invoice = { version = "0.19" }
lightning-net-tokio = { version = "0.0.111" }

# lightning = { git = "https://github.com/lexe-tech/rust-lightning", features = # ["max_level_trace"], branch = "main" }
# lightning-block-sync = { git = "https://github.com/lexe-tech/rust-lightning", # features = [ "rpc-client" ], branch = "main" }
Expand Down
12 changes: 6 additions & 6 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ lexe-ln = { path = "../lexe-ln" }

# --- BITCOIN --- #

bitcoin = { version = "0.28.1", features = ["use-serde"] }
bitcoin = { version = "0.29", features = ["serde"] }
bitcoin-bech32 = "0.12"
# bech32 = "0.8"
base64 = "0.13.0"

# --- LIGHTNING --- #

lightning = { version = "0.0.110", features = ["max_level_trace"] }
lightning-block-sync = { version = "0.0.110", features = [ "rpc-client" ] }
lightning-invoice = { version = "0.18" }
lightning-net-tokio = { version = "0.0.110" }
lightning = { version = "0.0.111", features = ["max_level_trace"] }
lightning-block-sync = { version = "0.0.111", features = [ "rpc-client" ] }
lightning-invoice = { version = "0.19" }
lightning-net-tokio = { version = "0.0.111" }

# lightning = { git = "https://github.com/lexe-tech/rust-lightning", features = # ["max_level_trace"], branch = "main" }
# lightning-block-sync = { git = "https://github.com/lexe-tech/rust-lightning", # features = [ "rpc-client" ], branch = "main" }
Expand Down Expand Up @@ -122,7 +122,7 @@ tokio = { version = "=1.15.0", default-features = false, features = [

[target.'cfg(not(target_env = "sgx"))'.dev-dependencies]
# Run bitcoin regtest for tests
bitcoind = { version = "0.26", features = [ "22_0" ] }
bitcoind = { version = "0.27", features = [ "22_0" ] }
# Enable all default features outside SGX for better test convenience
proptest = "1"

Expand Down
6 changes: 6 additions & 0 deletions node/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use lightning::chain;
use lightning::chain::chainmonitor::ChainMonitor;
use lightning::chain::keysinterface::KeysInterface;
use lightning::chain::transaction::OutPoint;
use lightning::onion_message::OnionMessenger;
use lightning::routing::gossip::P2PGossipSync;
use lightning_invoice::payment;
use lightning_invoice::utils::DefaultRouter;
Expand Down Expand Up @@ -223,12 +224,17 @@ impl UserNode {
scorer_res.context("Could not read probabilistic scorer")?;
let scorer = Arc::new(Mutex::new(scorer));

// Init onion messenger
let onion_messenger =
Arc::new(OnionMessenger::new(keys_manager.clone(), logger.clone()));

// Initialize PeerManager
let peer_manager = NodePeerManager::init(
rng,
&keys_manager,
channel_manager.clone(),
gossip_sync.clone(),
onion_messenger,
logger.clone(),
);

Expand Down
34 changes: 13 additions & 21 deletions node/src/lexe/background_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::types::{
const PROCESS_EVENTS_INTERVAL: Duration = Duration::from_millis(1000);
const PEER_MANAGER_PING_INTERVAL: Duration = Duration::from_secs(15);
const CHANNEL_MANAGER_TICK_INTERVAL: Duration = Duration::from_secs(60);
const CHANNEL_MANAGER_POLL_INTERVAL: Duration = Duration::from_millis(1000);
const NETWORK_GRAPH_INITIAL_DELAY: Duration = Duration::from_secs(60);
const NETWORK_GRAPH_PRUNE_INTERVAL: Duration = Duration::from_secs(15 * 60);
const PROB_SCORER_PERSIST_INTERVAL: Duration = Duration::from_secs(5 * 60);
Expand All @@ -45,7 +44,6 @@ impl LexeBackgroundProcessor {
let mut process_timer = interval(PROCESS_EVENTS_INTERVAL);
let mut pm_timer = interval(PEER_MANAGER_PING_INTERVAL);
let mut cm_tick_timer = interval(CHANNEL_MANAGER_TICK_INTERVAL);
let mut cm_poll_timer = interval(CHANNEL_MANAGER_POLL_INTERVAL);
let start = Instant::now() + NETWORK_GRAPH_INITIAL_DELAY;
let mut ng_timer = interval_at(start, NETWORK_GRAPH_PRUNE_INTERVAL);
let mut ps_timer = interval(PROB_SCORER_PERSIST_INTERVAL);
Expand All @@ -71,25 +69,19 @@ impl LexeBackgroundProcessor {
}

// --- Persistence branches --- //
_ = cm_poll_timer.tick() => {
trace!("Polling channel manager for updates");
// TODO Use get_persistence_condvar_value instead
let timeout = Duration::from_millis(10);
let needs_persist = channel_manager
.await_persistable_update_timeout(timeout);
if needs_persist {
let persist_res = persister
.persist_manager(channel_manager.deref())
.await;
if let Err(e) = persist_res {
// Failing to persist the channel manager won't
// lose funds so long as the chain monitors have
// been persisted correctly, but it's still
// serious - initiate a shutdown
error!("Couldn't persist channel manager: {:#}", e);
shutdown.send();
break;
}
_ = channel_manager.get_persistable_update_future() => {
debug!("Persisting channel manager");
let persist_res = persister
.persist_manager(channel_manager.deref())
.await;
if let Err(e) = persist_res {
// Failing to persist the channel manager won't
// lose funds so long as the chain monitors have
// been persisted correctly, but it's still
// serious - initiate a shutdown
error!("Couldn't persist channel manager: {:#}", e);
shutdown.send();
break;
}
}
_ = ng_timer.tick() => {
Expand Down
3 changes: 3 additions & 0 deletions node/src/lexe/channel_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const CHANNEL_HANDSHAKE_CONFIG: ChannelHandshakeConfig =
// so that it is possible to sweep all funds to an address
// specified at the time of channel close.
commit_upfront_shutdown_pubkey: false,
// The counterparty must reserve 1% of the total channel value to be
// claimable by us on-chain in the case of a channel breach.
their_channel_reserve_proportional_millionths: 10_000,
};

const CHANNEL_HANDSHAKE_LIMITS: ChannelHandshakeLimits =
Expand Down
18 changes: 16 additions & 2 deletions node/src/lexe/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::net::SocketAddr;
use std::ops::Deref;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

use anyhow::{bail, Context};
use bitcoin::secp256k1::PublicKey;
Expand All @@ -17,7 +17,7 @@ use tokio::net::TcpStream;
use tokio::time;

use crate::lexe::channel_manager::NodeChannelManager;
use crate::types::{P2PGossipSyncType, PeerManagerType};
use crate::types::{OnionMessengerType, P2PGossipSyncType, PeerManagerType};

const CONNECT_TIMEOUT: Duration = Duration::from_secs(5);

Expand All @@ -38,6 +38,7 @@ impl NodePeerManager {
keys_manager: &LexeKeysManager,
channel_manager: NodeChannelManager,
gossip_sync: Arc<P2PGossipSyncType>,
onion_messenger: Arc<OnionMessengerType>,
logger: LexeTracingLogger,
) -> Self {
let mut ephemeral_bytes = Zeroizing::new([0u8; 32]);
Expand All @@ -46,14 +47,27 @@ impl NodePeerManager {
let lightning_msg_handler = MessageHandler {
chan_handler: channel_manager,
route_handler: gossip_sync,
onion_message_handler: onion_messenger,
};
let node_secret = keys_manager
.get_node_secret(Recipient::Node)
.expect("Always succeeds when called with Recipient::Node");

// `current_time` is supposed to be monotonically increasing across node
// restarts, but since secure timekeeping within an enclave is a hard
// problem, and this field is used to help peers choose between
// multiple node announcements (it becomes last_node_announcement_serial
// which then becomes the timestamp field of UnsignedNodeAnnouncement
// which is specified in BOLT#07), using the system time is fine.
let current_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("System time is before Unix epoch")
.as_secs();

let peer_manager: PeerManagerType = PeerManagerType::new(
lightning_msg_handler,
node_secret,
current_time,
&ephemeral_bytes,
logger,
Arc::new(IgnoringMessageHandler {}),
Expand Down
6 changes: 3 additions & 3 deletions node/src/lexe/persister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::lexe::channel_manager::{LxChannelMonitorUpdate, USER_CONFIG};
use crate::lexe::peer_manager::ChannelPeer;
use crate::types::{
ApiClientType, ChainMonitorType, ChannelManagerType, ChannelMonitorType,
LoggerType, NetworkGraphType, ProbabilisticScorerType, SignerType,
NetworkGraphType, ProbabilisticScorerType, SignerType,
};

// Singleton objects use SINGLETON_DIRECTORY with a fixed filename
Expand Down Expand Up @@ -201,7 +201,7 @@ impl InnerPersister {
pub async fn read_probabilistic_scorer(
&self,
graph: Arc<NetworkGraphType>,
logger: LoggerType,
logger: LexeTracingLogger,
) -> anyhow::Result<ProbabilisticScorerType> {
debug!("Reading probabilistic scorer");
let params = ProbabilisticScoringParameters::default();
Expand Down Expand Up @@ -238,7 +238,7 @@ impl InnerPersister {
pub async fn read_network_graph(
&self,
genesis_hash: BlockHash,
logger: LoggerType,
logger: LexeTracingLogger,
) -> anyhow::Result<NetworkGraphType> {
debug!("Reading network graph");
let ng_file_id = NodeFileId::new(
Expand Down
20 changes: 13 additions & 7 deletions node/src/types/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use lightning::chain::{Access, Filter};
use lightning::ln::channelmanager::ChannelManager;
use lightning::ln::peer_handler::{IgnoringMessageHandler, PeerManager};
use lightning::ln::PaymentHash;
use lightning::onion_message::OnionMessenger;
use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
use lightning::routing::scoring::ProbabilisticScorer;
use lightning_invoice::payment;
Expand All @@ -35,10 +36,14 @@ pub type ChainMonitorType = ChainMonitor<
NodePersister,
>;

pub type OnionMessengerType =
OnionMessenger<SignerType, LexeKeysManager, LexeTracingLogger>;

pub type PeerManagerType = PeerManager<
SocketDescriptor,
NodeChannelManager,
Arc<P2PGossipSyncType>,
Arc<OnionMessengerType>,
LexeTracingLogger,
Arc<IgnoringMessageHandler>,
>;
Expand Down Expand Up @@ -71,15 +76,16 @@ pub type InvoicePayerType = payment::InvoicePayer<
>;

pub type ProbabilisticScorerType =
ProbabilisticScorer<Arc<NetworkGraphType>, LoggerType>;
ProbabilisticScorer<Arc<NetworkGraphType>, LexeTracingLogger>;

pub type RouterType = DefaultRouter<Arc<NetworkGraphType>, LoggerType>;
pub type RouterType = DefaultRouter<Arc<NetworkGraphType>, LexeTracingLogger>;

pub type P2PGossipSyncType =
P2PGossipSync<Arc<NetworkGraphType>, Arc<ChainAccessType>, LoggerType>;
pub type P2PGossipSyncType = P2PGossipSync<
Arc<NetworkGraphType>,
Arc<ChainAccessType>,
LexeTracingLogger,
>;

pub type NetworkGraphType = NetworkGraph<LoggerType>;
pub type NetworkGraphType = NetworkGraph<LexeTracingLogger>;

pub type ChainAccessType = dyn Access + Send + Sync;

pub type LoggerType = LexeTracingLogger;