Skip to content

Commit 88fe0c3

Browse files
committed
Integrate KeysInterface to ChannelManager with Arc
1 parent da94539 commit 88fe0c3

File tree

4 files changed

+92
-54
lines changed

4 files changed

+92
-54
lines changed

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ extern crate secp256k1;
55

66
use bitcoin::blockdata::block::BlockHeader;
77
use bitcoin::blockdata::transaction::{Transaction, TxOut};
8-
use bitcoin::blockdata::script::Script;
8+
use bitcoin::blockdata::script::{Builder, Script};
9+
use bitcoin::blockdata::opcodes;
910
use bitcoin::network::constants::Network;
1011
use bitcoin::network::serialize::{deserialize, serialize, BitcoinHash};
11-
use bitcoin::util::hash::Sha256dHash;
12+
use bitcoin::util::hash::{Sha256dHash, Hash160};
1213

1314
use crypto::digest::Digest;
1415

1516
use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil};
1617
use lightning::chain::transaction::OutPoint;
18+
use lightning::chain::keysinterface::{ChannelKeys, KeysInterface};
1719
use lightning::ln::channelmonitor;
1820
use lightning::ln::channelmanager::{ChannelManager, PaymentFailReason};
1921
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
@@ -196,6 +198,54 @@ impl<'a> Drop for MoneyLossDetector<'a> {
196198
}
197199
}
198200

201+
struct KeyProvider {
202+
node_secret: SecretKey,
203+
}
204+
impl KeysInterface for KeyProvider {
205+
fn get_node_secret(&self) -> SecretKey {
206+
self.node_secret.clone()
207+
}
208+
209+
fn get_destination_script(&self) -> Script {
210+
let secp_ctx = Secp256k1::signing_only();
211+
let channel_monitor_claim_key = SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
212+
let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
213+
Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
214+
}
215+
216+
fn get_shutdown_pubkey(&self) -> PublicKey {
217+
let secp_ctx = Secp256k1::signing_only();
218+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap())
219+
}
220+
221+
fn get_channel_keys(&self, inbound: bool) -> ChannelKeys {
222+
let secp_ctx = Secp256k1::without_caps();
223+
if inbound {
224+
ChannelKeys {
225+
funding_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]).unwrap(),
226+
revocation_base_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0]).unwrap(),
227+
payment_base_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0]).unwrap(),
228+
delayed_payment_base_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0]).unwrap(),
229+
htlc_base_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0]).unwrap(),
230+
channel_close_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0]).unwrap(),
231+
channel_monitor_claim_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0]).unwrap(),
232+
commitment_seed: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
233+
}
234+
} else {
235+
ChannelKeys {
236+
funding_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
237+
revocation_base_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
238+
payment_base_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
239+
delayed_payment_base_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
240+
htlc_base_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
241+
channel_close_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
242+
channel_monitor_claim_key: SecretKey::from_slice(&secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
243+
commitment_seed: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
244+
}
245+
}
246+
}
247+
}
248+
199249
#[inline]
200250
pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
201251
reset_rng_state();
@@ -236,8 +286,9 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
236286
let broadcast = Arc::new(TestBroadcaster{});
237287
let monitor = channelmonitor::SimpleManyChannelMonitor::new(watch.clone(), broadcast.clone());
238288

239-
let channelmanager = ChannelManager::new(our_network_key, slice_to_be32(get_slice!(4)), get_slice!(1)[0] != 0, Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger)).unwrap();
240-
let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &our_network_key), watch.clone(), Arc::clone(&logger)));
289+
let keys_manager = Arc::new(KeyProvider { node_secret: our_network_key.clone() });
290+
let channelmanager = ChannelManager::new(slice_to_be32(get_slice!(4)), get_slice!(1)[0] != 0, Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone()).unwrap();
291+
let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &keys_manager.get_node_secret()), watch.clone(), Arc::clone(&logger)));
241292

242293
let peers = RefCell::new([false; 256]);
243294
let mut loss_detector = MoneyLossDetector::new(&peers, channelmanager.clone(), monitor.clone(), PeerManager::new(MessageHandler {

src/chain/keysinterface.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub trait KeysInterface: Send + Sync {
6060
}
6161

6262
/// Set of lightning keys needed to operate a channel as described in BOLT 3
63+
#[derive(Clone)]
6364
pub struct ChannelKeys {
6465
/// Private key of anchor tx
6566
pub funding_key: SecretKey,

src/ln/channel.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ln::chan_utils::{TxCreationKeys,HTLCOutputInCommitment,HTLC_SUCCESS_TX_WEIGH
2020
use ln::chan_utils;
2121
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
2222
use chain::transaction::OutPoint;
23-
use chain::keysinterface::ChannelKeys;
23+
use chain::keysinterface::{ChannelKeys, KeysInterface};
2424
use util::{transaction_utils,rng};
2525
use util::ser::Writeable;
2626
use util::sha2::Sha256;
@@ -415,7 +415,9 @@ impl Channel {
415415
}
416416

417417
// Constructors:
418-
pub fn new_outbound(fee_estimator: &FeeEstimator, chan_keys: ChannelKeys, their_node_id: PublicKey, channel_value_satoshis: u64, push_msat: u64, announce_publicly: bool, user_id: u64, logger: Arc<Logger>) -> Result<Channel, APIError> {
418+
pub fn new_outbound(fee_estimator: &FeeEstimator, keys_provider: &Arc<KeysInterface>, their_node_id: PublicKey, channel_value_satoshis: u64, push_msat: u64, announce_publicly: bool, user_id: u64, logger: Arc<Logger>) -> Result<Channel, APIError> {
419+
let chan_keys = keys_provider.get_channel_keys(false);
420+
419421
if channel_value_satoshis >= MAX_FUNDING_SATOSHIS {
420422
return Err(APIError::APIMisuseError{err: "funding value > 2^24"});
421423
}
@@ -524,7 +526,9 @@ impl Channel {
524526

525527
/// Creates a new channel from a remote sides' request for one.
526528
/// Assumes chain_hash has already been checked and corresponds with what we expect!
527-
pub fn new_from_req(fee_estimator: &FeeEstimator, chan_keys: ChannelKeys, their_node_id: PublicKey, msg: &msgs::OpenChannel, user_id: u64, require_announce: bool, allow_announce: bool, logger: Arc<Logger>) -> Result<Channel, ChannelError> {
529+
pub fn new_from_req(fee_estimator: &FeeEstimator, keys_provider: &Arc<KeysInterface>, their_node_id: PublicKey, msg: &msgs::OpenChannel, user_id: u64, require_announce: bool, allow_announce: bool, logger: Arc<Logger>) -> Result<Channel, ChannelError> {
530+
let chan_keys = keys_provider.get_channel_keys(true);
531+
528532
// Check sanity of message fields:
529533
if msg.funding_satoshis >= MAX_FUNDING_SATOSHIS {
530534
return Err(ChannelError::Close("funding value > 2^24"));
@@ -3236,6 +3240,7 @@ mod tests {
32363240
use ln::channel::MAX_FUNDING_SATOSHIS;
32373241
use ln::chan_utils;
32383242
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
3243+
use chain::keysinterface::KeysInterface;
32393244
use chain::transaction::OutPoint;
32403245
use util::test_utils;
32413246
use util::logger::Logger;
@@ -3260,6 +3265,16 @@ mod tests {
32603265
"MAX_FUNDING_SATOSHIS is greater than all satoshis on existence");
32613266
}
32623267

3268+
struct Keys {
3269+
chan_keys: ChannelKeys,
3270+
}
3271+
impl KeysInterface for Keys {
3272+
fn get_node_secret(&self) -> SecretKey { panic!(); }
3273+
fn get_destination_script(&self) -> Script { panic!(); }
3274+
fn get_shutdown_pubkey(&self) -> PublicKey { panic!(); }
3275+
fn get_channel_keys(&self, _inbound: bool) -> ChannelKeys { self.chan_keys.clone() }
3276+
}
3277+
32633278
#[test]
32643279
fn outbound_commitment_test() {
32653280
// Test vectors from BOLT 3 Appendix C:
@@ -3281,9 +3296,10 @@ mod tests {
32813296
};
32823297
assert_eq!(PublicKey::from_secret_key(&secp_ctx, &chan_keys.funding_key).serialize()[..],
32833298
hex::decode("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb").unwrap()[..]);
3299+
let keys_provider: Arc<KeysInterface> = Arc::new(Keys { chan_keys });
32843300

32853301
let their_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap());
3286-
let mut chan = Channel::new_outbound(&feeest, chan_keys, their_node_id, 10000000, 100000, false, 42, Arc::clone(&logger)).unwrap(); // Nothing uses their network key in this test
3302+
let mut chan = Channel::new_outbound(&feeest, &keys_provider, their_node_id, 10000000, 100000, false, 42, Arc::clone(&logger)).unwrap(); // Nothing uses their network key in this test
32873303
chan.their_to_self_delay = 144;
32883304
chan.our_dust_limit_satoshis = 546;
32893305

src/ln/channelmanager.rs

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use ln::channelmonitor::{ChannelMonitorUpdateErr, ManyChannelMonitor, CLTV_CLAIM
2727
use ln::router::{Route,RouteHop};
2828
use ln::msgs;
2929
use ln::msgs::{ChannelMessageHandler, HandleError, RAACommitmentOrder};
30-
use chain::keysinterface::ChannelKeys;
30+
use chain::keysinterface::KeysInterface;
3131
use util::{byte_utils, events, internal_traits, rng};
3232
use util::sha2::Sha256;
3333
use util::ser::{Readable, Writeable};
@@ -302,6 +302,8 @@ pub struct ChannelManager {
302302

303303
pending_events: Mutex<Vec<events::Event>>,
304304

305+
keys_manager: Arc<KeysInterface>,
306+
305307
logger: Arc<Logger>,
306308
}
307309

@@ -374,7 +376,7 @@ impl ChannelManager {
374376
/// Non-proportional fees are fixed according to our risk using the provided fee estimator.
375377
///
376378
/// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
377-
pub fn new(our_network_key: SecretKey, fee_proportional_millionths: u32, announce_channels_publicly: bool, network: Network, feeest: Arc<FeeEstimator>, monitor: Arc<ManyChannelMonitor>, chain_monitor: Arc<ChainWatchInterface>, tx_broadcaster: Arc<BroadcasterInterface>, logger: Arc<Logger>) -> Result<Arc<ChannelManager>, secp256k1::Error> {
379+
pub fn new(fee_proportional_millionths: u32, announce_channels_publicly: bool, network: Network, feeest: Arc<FeeEstimator>, monitor: Arc<ManyChannelMonitor>, chain_monitor: Arc<ChainWatchInterface>, tx_broadcaster: Arc<BroadcasterInterface>, logger: Arc<Logger>, keys_manager: Arc<KeysInterface>) -> Result<Arc<ChannelManager>, secp256k1::Error> {
378380
let secp_ctx = Secp256k1::new();
379381

380382
let res = Arc::new(ChannelManager {
@@ -396,10 +398,12 @@ impl ChannelManager {
396398
forward_htlcs: HashMap::new(),
397399
claimable_htlcs: HashMap::new(),
398400
}),
399-
our_network_key,
401+
our_network_key: keys_manager.get_node_secret(),
400402

401403
pending_events: Mutex::new(Vec::new()),
402404

405+
keys_manager,
406+
403407
logger,
404408
});
405409
let weak_res = Arc::downgrade(&res);
@@ -419,24 +423,7 @@ impl ChannelManager {
419423
///
420424
/// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat being greater than channel_value_satoshis * 1k
421425
pub fn create_channel(&self, their_network_key: PublicKey, channel_value_satoshis: u64, push_msat: u64, user_id: u64) -> Result<(), APIError> {
422-
let chan_keys = if cfg!(feature = "fuzztarget") {
423-
ChannelKeys {
424-
funding_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
425-
revocation_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
426-
payment_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
427-
delayed_payment_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
428-
htlc_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
429-
channel_close_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
430-
channel_monitor_claim_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap(),
431-
commitment_seed: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
432-
}
433-
} else {
434-
let mut key_seed = [0u8; 32];
435-
rng::fill_bytes(&mut key_seed);
436-
ChannelKeys::new_from_seed(&key_seed)
437-
};
438-
439-
let channel = Channel::new_outbound(&*self.fee_estimator, chan_keys, their_network_key, channel_value_satoshis, push_msat, self.announce_channels_publicly, user_id, Arc::clone(&self.logger))?;
426+
let channel = Channel::new_outbound(&*self.fee_estimator, &self.keys_manager, their_network_key, channel_value_satoshis, push_msat, self.announce_channels_publicly, user_id, Arc::clone(&self.logger))?;
440427
let res = channel.get_open_channel(self.genesis_hash.clone(), &*self.fee_estimator);
441428
let mut channel_state = self.channel_state.lock().unwrap();
442429
match channel_state.by_id.entry(channel.channel_id()) {
@@ -1673,24 +1660,7 @@ impl ChannelManager {
16731660
return Err(MsgHandleErrInternal::send_err_msg_no_close("temporary_channel_id collision!", msg.temporary_channel_id.clone()));
16741661
}
16751662

1676-
let chan_keys = if cfg!(feature = "fuzztarget") {
1677-
ChannelKeys {
1678-
funding_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]).unwrap(),
1679-
revocation_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0]).unwrap(),
1680-
payment_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0]).unwrap(),
1681-
delayed_payment_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0]).unwrap(),
1682-
htlc_base_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0]).unwrap(),
1683-
channel_close_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0]).unwrap(),
1684-
channel_monitor_claim_key: SecretKey::from_slice(&self.secp_ctx, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0]).unwrap(),
1685-
commitment_seed: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1686-
}
1687-
} else {
1688-
let mut key_seed = [0u8; 32];
1689-
rng::fill_bytes(&mut key_seed);
1690-
ChannelKeys::new_from_seed(&key_seed)
1691-
};
1692-
1693-
let channel = Channel::new_from_req(&*self.fee_estimator, chan_keys, their_node_id.clone(), msg, 0, false, self.announce_channels_publicly, Arc::clone(&self.logger))
1663+
let channel = Channel::new_from_req(&*self.fee_estimator, &self.keys_manager, their_node_id.clone(), msg, 0, false, self.announce_channels_publicly, Arc::clone(&self.logger))
16941664
.map_err(|e| MsgHandleErrInternal::from_chan_no_close(e, msg.temporary_channel_id))?;
16951665
let accept_msg = channel.get_accept_channel();
16961666
channel_state.by_id.insert(channel.channel_id(), channel);
@@ -2680,6 +2650,8 @@ mod tests {
26802650
use chain::chaininterface;
26812651
use chain::transaction::OutPoint;
26822652
use chain::chaininterface::ChainListener;
2653+
use chain::keysinterface::KeysInterface;
2654+
use chain::keysinterface;
26832655
use ln::channelmanager::{ChannelManager,OnionKeys,PaymentFailReason};
26842656
use ln::channelmonitor::{ChannelMonitorUpdateErr, CLTV_CLAIM_BUFFER, HTLC_FAIL_TIMEOUT_BLOCKS};
26852657
use ln::router::{Route, RouteHop, Router};
@@ -3452,14 +3424,12 @@ mod tests {
34523424
let feeest = Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 });
34533425
let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&logger)));
34543426
let tx_broadcaster = Arc::new(test_utils::TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new())});
3427+
let mut seed = [0; 32];
3428+
rng.fill_bytes(&mut seed);
3429+
let keys_manager = Arc::new(keysinterface::KeysManager::new(&seed, Network::Testnet, Arc::clone(&logger)));
34553430
let chan_monitor = Arc::new(test_utils::TestChannelMonitor::new(chain_monitor.clone(), tx_broadcaster.clone()));
3456-
let node_id = {
3457-
let mut key_slice = [0; 32];
3458-
rng.fill_bytes(&mut key_slice);
3459-
SecretKey::from_slice(&secp_ctx, &key_slice).unwrap()
3460-
};
3461-
let node = ChannelManager::new(node_id.clone(), 0, true, Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger)).unwrap();
3462-
let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &node_id), chain_monitor.clone(), Arc::clone(&logger));
3431+
let node = ChannelManager::new(0, true, Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger), keys_manager.clone()).unwrap();
3432+
let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &keys_manager.get_node_secret()), chain_monitor.clone(), Arc::clone(&logger));
34633433
nodes.push(Node { chain_monitor, tx_broadcaster, chan_monitor, node, router,
34643434
network_payment_count: payment_count.clone(),
34653435
network_chan_count: chan_count.clone(),

0 commit comments

Comments
 (0)