Skip to content

Commit bd8effc

Browse files
committed
don't serialize computable field in InMemoryChannelKeys
1 parent 58b8cc3 commit bd8effc

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ impl KeysInterface for KeyProvider {
161161
SecretKey::from_slice(&[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, 8, self.node_id]).unwrap(),
162162
[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, 9, self.node_id],
163163
channel_value_satoshis,
164+
None,
164165
))
165166
}
166167

fuzz/src/full_stack.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ impl KeysInterface for KeyProvider {
263263
SecretKey::from_slice(&[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, ctr]).unwrap(),
264264
[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, ctr],
265265
channel_value_satoshis,
266+
None,
266267
)
267268
} else {
268269
InMemoryChannelKeys::new(
@@ -274,6 +275,7 @@ impl KeysInterface for KeyProvider {
274275
SecretKey::from_slice(&[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, 11, ctr]).unwrap(),
275276
[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, 12, ctr],
276277
channel_value_satoshis,
278+
None,
277279
)
278280
})
279281
}

lightning/src/chain/keysinterface.rs

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ use secp256k1;
2121

2222
use util::byte_utils;
2323
use util::logger::Logger;
24-
use util::ser::Writeable;
24+
use util::ser::{Writeable, Writer, Readable};
2525

2626
use ln::chan_utils;
2727
use ln::chan_utils::{TxCreationKeys, HTLCOutputInCommitment, make_funding_redeemscript, ChannelPublicKeys};
2828
use ln::msgs;
2929

3030
use std::sync::Arc;
3131
use std::sync::atomic::{AtomicUsize, Ordering};
32+
use std::io::Error;
33+
use ln::msgs::DecodeError;
3234

3335
/// When on-chain outputs are created by rust-lightning (which our counterparty is not able to
3436
/// claim at any point in the future) an event is generated which you must track and be able to
@@ -214,7 +216,8 @@ impl InMemoryChannelKeys {
214216
delayed_payment_base_key: SecretKey,
215217
htlc_base_key: SecretKey,
216218
commitment_seed: [u8; 32],
217-
channel_value_satoshis: u64) -> InMemoryChannelKeys {
219+
channel_value_satoshis: u64,
220+
remote_channel_pubkeys: Option<ChannelPublicKeys>) -> InMemoryChannelKeys {
218221
let from_secret = |s: &SecretKey| PublicKey::from_secret_key(secp_ctx, s);
219222
let local_keys = ChannelPublicKeys {
220223
funding_pubkey: from_secret(&funding_key),
@@ -231,7 +234,7 @@ impl InMemoryChannelKeys {
231234
htlc_base_key,
232235
commitment_seed,
233236
channel_value_satoshis,
234-
remote_channel_pubkeys: None,
237+
remote_channel_pubkeys,
235238
local_channel_pubkeys: local_keys
236239
}
237240
}
@@ -301,17 +304,47 @@ impl ChannelKeys for InMemoryChannelKeys {
301304
}
302305
}
303306

304-
impl_writeable!(InMemoryChannelKeys, 0, {
305-
funding_key,
306-
revocation_base_key,
307-
payment_base_key,
308-
delayed_payment_base_key,
309-
htlc_base_key,
310-
commitment_seed,
311-
local_channel_pubkeys,
312-
remote_channel_pubkeys,
313-
channel_value_satoshis
314-
});
307+
impl Writeable for InMemoryChannelKeys {
308+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
309+
self.funding_key.write(writer)?;
310+
self.revocation_base_key.write(writer)?;
311+
self.payment_base_key.write(writer)?;
312+
self.delayed_payment_base_key.write(writer)?;
313+
self.htlc_base_key.write(writer)?;
314+
self.commitment_seed.write(writer)?;
315+
self.remote_channel_pubkeys.write(writer)?;
316+
self.channel_value_satoshis.write(writer)?;
317+
318+
Ok(())
319+
}
320+
}
321+
322+
impl<R: ::std::io::Read> Readable<R> for InMemoryChannelKeys {
323+
fn read(reader: &mut R) -> Result<Self, DecodeError> {
324+
let funding_key = Readable::read(reader)?;
325+
let revocation_base_key = Readable::read(reader)?;
326+
let payment_base_key = Readable::read(reader)?;
327+
let delayed_payment_base_key = Readable::read(reader)?;
328+
let htlc_base_key = Readable::read(reader)?;
329+
let commitment_seed = Readable::read(reader)?;
330+
let remote_channel_pubkeys = Readable::read(reader)?;
331+
let channel_value_satoshis = Readable::read(reader)?;
332+
let secp_ctx = Secp256k1::signing_only();
333+
334+
335+
Ok(InMemoryChannelKeys::new(
336+
&secp_ctx,
337+
funding_key,
338+
revocation_base_key,
339+
payment_base_key,
340+
delayed_payment_base_key,
341+
htlc_base_key,
342+
commitment_seed,
343+
channel_value_satoshis,
344+
remote_channel_pubkeys
345+
))
346+
}
347+
}
315348

316349
/// Simple KeysInterface implementor that takes a 32-byte seed for use as a BIP 32 extended key
317350
/// and derives keys from that.
@@ -461,6 +494,7 @@ impl KeysInterface for KeysManager {
461494
htlc_base_key,
462495
commitment_seed,
463496
channel_value_satoshis,
497+
None,
464498
)
465499
}
466500

lightning/src/ln/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4130,6 +4130,7 @@ mod tests {
41304130
// These aren't set in the test vectors:
41314131
[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
41324132
7000000000,
4133+
None,
41334134
);
41344135

41354136
assert_eq!(PublicKey::from_secret_key(&secp_ctx, chan_keys.funding_key()).serialize()[..],

lightning/src/ln/channelmonitor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,6 +3327,7 @@ mod tests {
33273327
SecretKey::from_slice(&[41; 32]).unwrap(),
33283328
[41; 32],
33293329
0,
3330+
None,
33303331
);
33313332

33323333
{
@@ -3741,6 +3742,7 @@ mod tests {
37413742
SecretKey::from_slice(&[41; 32]).unwrap(),
37423743
[41; 32],
37433744
0,
3745+
None,
37443746
);
37453747

37463748
// Prune with one old state and a local commitment tx holding a few overlaps with the

0 commit comments

Comments
 (0)