Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 97d9e15

Browse files
committed
type absurdism
1 parent 0733a4e commit 97d9e15

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ build = "build.rs"
88
bitcoin = "0.21"
99
bitcoin-bech32 = "0.7"
1010
bitcoin_hashes = "0.7"
11-
lightning = { git = "https://github.com/TheBlueMatt/rust-lightning", rev = "6d1779522f97ca47770a0a91e74de15f3300cc46" }
12-
lightning-net-tokio = { git = "https://github.com/TheBlueMatt/rust-lightning", rev = "6d1779522f97ca47770a0a91e74de15f3300cc46" }
11+
lightning = { path = "../rust-lightning/lightning" }
12+
lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
1313
lightning-invoice = { git = "https://github.com/rust-bitcoin/rust-lightning-invoice", rev = "e738b463d041eb6236997c5f78fd1bc1c612af27" }
1414
secp256k1 = "0.15"
1515
hyper = "0.12"

src/chain_monitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ fn find_fork(mut steps_tx: mpsc::Sender<ForkStep>, current_hash: String, target_
236236
}));
237237
}
238238

239-
pub fn spawn_chain_monitor(fee_estimator: Arc<FeeEstimator>, rpc_client: Arc<RPCClient>, chain_interface: Arc<ChainInterface>, chain_notifier: Arc<BlockNotifier>, event_notify: mpsc::Sender<()>) {
239+
pub fn spawn_chain_monitor<A : ::std::ops::Deref<Target = lightning::chain::chaininterface::ChainListener + 'static> + Send + 'static>(fee_estimator: Arc<FeeEstimator>, rpc_client: Arc<RPCClient>, chain_interface: Arc<ChainInterface>, chain_notifier: Arc<BlockNotifier<'static, A>>, event_notify: mpsc::Sender<()>) {
240240
tokio::spawn(FeeEstimator::update_values(fee_estimator.clone(), &rpc_client));
241241
let cur_block = Arc::new(Mutex::new(String::from("")));
242242
tokio::spawn(tokio::timer::Interval::new(Instant::now(), Duration::from_secs(1)).for_each(move |_| {

src/main.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rand::{thread_rng, Rng};
4343
use lightning::chain;
4444
use lightning::chain::chaininterface;
4545
use lightning::chain::keysinterface::{KeysInterface, KeysManager, SpendableOutputDescriptor, InMemoryChannelKeys};
46-
use lightning::ln::{peer_handler, router, channelmanager, channelmonitor};
46+
use lightning::ln::{peer_handler, router, channelmanager, channelmonitor, msgs};
4747
use lightning::ln::channelmonitor::ManyChannelMonitor;
4848
use lightning::ln::channelmanager::{PaymentHash, PaymentPreimage};
4949
use lightning::util::events::{Event, EventsProvider};
@@ -78,19 +78,21 @@ fn _check_usize_is_64() {
7878
unsafe { mem::transmute::<*const usize, [u8; 8]>(panic!()); }
7979
}
8080

81+
type CM = channelmanager::ChannelManager<InMemoryChannelKeys, Arc<ChannelMonitor>>;
82+
8183
struct EventHandler {
8284
network: constants::Network,
8385
file_prefix: String,
8486
rpc_client: Arc<RPCClient>,
85-
peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor>>,
86-
channel_manager: Arc<channelmanager::ChannelManager<InMemoryChannelKeys>>,
87+
peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor<CM>, Arc<CM>>>,
88+
channel_manager: Arc<CM>,
8789
monitor: Arc<channelmonitor::SimpleManyChannelMonitor<chain::transaction::OutPoint>>,
8890
broadcaster: Arc<dyn chain::chaininterface::BroadcasterInterface>,
8991
txn_to_broadcast: Mutex<HashMap<chain::transaction::OutPoint, blockdata::transaction::Transaction>>,
9092
payment_preimages: Arc<Mutex<HashMap<PaymentHash, PaymentPreimage>>>,
9193
}
9294
impl EventHandler {
93-
fn setup(network: constants::Network, file_prefix: String, rpc_client: Arc<RPCClient>, peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor>>, monitor: Arc<channelmonitor::SimpleManyChannelMonitor<chain::transaction::OutPoint>>, channel_manager: Arc<channelmanager::ChannelManager<InMemoryChannelKeys>>, broadcaster: Arc<dyn chain::chaininterface::BroadcasterInterface>, payment_preimages: Arc<Mutex<HashMap<PaymentHash, PaymentPreimage>>>) -> mpsc::Sender<()> {
95+
fn setup(network: constants::Network, file_prefix: String, rpc_client: Arc<RPCClient>, peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor<CM>, Arc<CM>>>, monitor: Arc<channelmonitor::SimpleManyChannelMonitor<chain::transaction::OutPoint>>, channel_manager: Arc<CM>, broadcaster: Arc<dyn chain::chaininterface::BroadcasterInterface>, payment_preimages: Arc<Mutex<HashMap<PaymentHash, PaymentPreimage>>>) -> mpsc::Sender<()> {
9496
let us = Arc::new(Self { network, file_prefix, rpc_client, peer_manager, channel_manager, monitor, broadcaster, txn_to_broadcast: Mutex::new(HashMap::new()), payment_preimages });
9597
let (sender, receiver) = mpsc::channel(2);
9698
let self_sender = sender.clone();
@@ -135,20 +137,20 @@ impl EventHandler {
135137
us.broadcaster.broadcast_transaction(&tx);
136138
println!("Broadcast funding tx {}!", tx.txid());
137139
},
138-
Event::PaymentReceived { payment_hash, payment_secret, amt } => {
140+
Event::PaymentReceived { payment_hash, amt } => {
139141
println!("handling pr in 60 secs...");
140142
let us = us.clone();
141143
let mut self_sender = self_sender.clone();
142144
tokio::spawn(tokio::timer::Delay::new(Instant::now() + Duration::from_secs(60)).then(move |_| {
143145
let images = us.payment_preimages.lock().unwrap();
144146
if let Some(payment_preimage) = images.get(&payment_hash) {
145-
if us.channel_manager.claim_funds(payment_preimage.clone(), &payment_secret, amt) { // Cheating by using amt here!
147+
if us.channel_manager.claim_funds(payment_preimage.clone(), amt) { // Cheating by using amt here!
146148
println!("Moneymoney! {} id {}", amt, hex_str(&payment_hash.0));
147149
} else {
148150
println!("Failed to claim money we were told we had?");
149151
}
150152
} else {
151-
us.channel_manager.fail_htlc_backwards(&payment_hash, &payment_secret);
153+
us.channel_manager.fail_htlc_backwards(&payment_hash);
152154
println!("Received payment but we didn't know the preimage :(");
153155
}
154156
let _ = self_sender.try_send(());
@@ -183,22 +185,22 @@ impl EventHandler {
183185
previous_output: outpoint,
184186
script_sig: bitcoin::Script::new(),
185187
sequence: to_self_delay as u32,
186-
witness: vec![witness_script.to_vec()],
188+
witness: vec![],
187189
}],
188190
lock_time: 0,
189191
output: vec![bitcoin::TxOut {
190-
script_pubkey:
191-
value: output.value,
192+
script_pubkey: ::bitcoin::Script::new(),
193+
value: 0,
192194
}],
193195
version: 2,
194196
};
195197
//XXX: Sign!
196198
},
197199
SpendableOutputDescriptor::DynamicOutputP2WPKH { outpoint, key, output } => {
198200
println!("Got on-chain output we should claim...");
199-
tokio::spawn(rpc_client.make_rpc_call("importprivkey",
200-
&[&("\"".to_string() + &bitcoin::util::key::PrivateKey{ key: import_key_2, compressed: true, network}.to_wif() + "\""), "\"rust-lightning cooperative close\"", "false"], false)
201-
.then(|_| Ok(())));
201+
//tokio::spawn(rpc_client.make_rpc_call("importprivkey",
202+
//&[&("\"".to_string() + &bitcoin::util::key::PrivateKey{ key: import_key_2, compressed: true, network}.to_wif() + "\""), "\"rust-lightning cooperative close\"", "false"], false)
203+
//.then(|_| Ok(())));
202204
//TODO: Send back to Bitcoin Core!
203205
},
204206
}
@@ -426,22 +428,22 @@ fn main() {
426428

427429
let mut monitors_loaded = ChannelMonitor::load_from_disk(&(data_path.clone() + "/monitors"));
428430
let monitor = Arc::new(ChannelMonitor {
429-
monitor: channelmonitor::SimpleManyChannelMonitor::new(chain_monitor.clone(), chain_monitor.clone(), logger.clone(), fee_estimator.clone()),
431+
monitor: Arc::new(channelmonitor::SimpleManyChannelMonitor::new(chain_monitor.clone(), chain_monitor.clone(), logger.clone(), fee_estimator.clone())),
430432
file_prefix: data_path.clone() + "/monitors",
431433
});
432-
block_notifier.register_listener(Arc::downgrade(&(monitor.monitor.clone() as Arc<dyn chaininterface::ChainListener>)));
434+
block_notifier.register_listener(Arc::clone(&(monitor.monitor.clone() as Arc<dyn chaininterface::ChainListener>)));
433435

434436
let mut config: config::UserConfig = Default::default();
435437
config.channel_options.fee_proportional_millionths = FEE_PROPORTIONAL_MILLIONTHS;
436438
config.channel_options.announced_channel = ANNOUNCE_CHANNELS;
437439

438-
let channel_manager = if let Ok(mut f) = fs::File::open(data_path.clone() + "/manager_data") {
440+
let channel_manager = Arc::new(if let Ok(mut f) = fs::File::open(data_path.clone() + "/manager_data") {
439441
let (last_block_hash, manager) = {
440442
let mut monitors_refs = HashMap::new();
441443
for (outpoint, monitor) in monitors_loaded.iter_mut() {
442444
monitors_refs.insert(*outpoint, monitor);
443445
}
444-
<(Sha256dHash, channelmanager::ChannelManager<InMemoryChannelKeys>)>::read(&mut f, channelmanager::ChannelManagerReadArgs {
446+
<(Sha256dHash, CM)>::read(&mut f, channelmanager::ChannelManagerReadArgs {
445447
keys_manager: keys.clone(),
446448
fee_estimator: fee_estimator.clone(),
447449
monitor: monitor.clone(),
@@ -454,15 +456,14 @@ fn main() {
454456
};
455457
monitor.load_from_vec(monitors_loaded);
456458
//TODO: Rescan
457-
let manager = Arc::new(manager);
458459
manager
459460
} else {
460461
if !monitors_loaded.is_empty() {
461462
panic!("Found some channel monitors but no channel state!");
462463
}
463464
channelmanager::ChannelManager::new(network, fee_estimator.clone(), monitor.clone(), chain_monitor.clone(), logger.clone(), keys.clone(), config, 0).unwrap() //TODO: Get blockchain height
464-
};
465-
block_notifier.register_listener(Arc::downgrade(&(channel_manager.clone() as Arc<dyn chaininterface::ChainListener>)));
465+
});
466+
block_notifier.register_listener(Arc::clone(&(channel_manager.clone() as Arc<dyn chaininterface::ChainListener>)));
466467
let router = Arc::new(router::Router::new(PublicKey::from_secret_key(&secp_ctx, &keys.get_node_secret()), chain_monitor.clone(), logger.clone()));
467468

468469
let mut ephemeral_data = [0; 32];
@@ -665,7 +666,7 @@ fn main() {
665666
Ok(route) => {
666667
let mut payment_hash = PaymentHash([0; 32]);
667668
payment_hash.0.copy_from_slice(&invoice.payment_hash()[..]);
668-
match channel_manager.send_payment(route, payment_hash, None) {
669+
match channel_manager.send_payment(route, payment_hash) {
669670
Ok(()) => {
670671
println!("Sending {} msat", amt);
671672
let _ = event_notify.try_send(());

0 commit comments

Comments
 (0)