Skip to content

Commit 7698988

Browse files
committed
Always use KeysInterface.read_chan_signer for de-serializing EnforcingSigner in tests
1 parent 7da4ddf commit 7698988

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, HolderCommitment
1111
use ln::{chan_utils, msgs};
1212
use chain::keysinterface::{Sign, InMemorySigner, BaseSign};
1313

14-
use io;
1514
use prelude::*;
1615
use core::cmp;
1716
use sync::{Mutex, Arc};
@@ -23,9 +22,8 @@ use bitcoin::util::bip143;
2322
use bitcoin::secp256k1;
2423
use bitcoin::secp256k1::key::{SecretKey, PublicKey};
2524
use bitcoin::secp256k1::{Secp256k1, Signature};
26-
use util::ser::{Writeable, Writer, Readable};
25+
use util::ser::{Writeable, Writer};
2726
use io::Error;
28-
use ln::msgs::DecodeError;
2927

3028
/// Initial value for revoked commitment downward counter
3129
pub const INITIAL_REVOKED_COMMITMENT_NUMBER: u64 = 1 << 48;
@@ -194,24 +192,14 @@ impl Sign for EnforcingSigner {}
194192

195193
impl Writeable for EnforcingSigner {
196194
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
195+
// NOTE: This will be de-serialized by KeysInterface::read_chan_signer
196+
// and it expects to see just the InMemorySigner. The enforcement state is managed
197+
// by KeysInterface, so we don't serialize it here.
197198
self.inner.write(writer)?;
198-
// NOTE - the commitment state is maintained by KeysInterface, so we don't persist it
199199
Ok(())
200200
}
201201
}
202202

203-
impl Readable for EnforcingSigner {
204-
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
205-
let inner = Readable::read(reader)?;
206-
let state = Arc::new(Mutex::new(EnforcementState::new()));
207-
Ok(EnforcingSigner {
208-
inner,
209-
state,
210-
disable_revocation_policy_check: false,
211-
})
212-
}
213-
}
214-
215203
impl EnforcingSigner {
216204
fn verify_counterparty_commitment_tx<'a, T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &'a CommitmentTransaction, secp_ctx: &Secp256k1<T>) -> TrustedCommitmentTransaction<'a> {
217205
commitment_tx.verify(&self.inner.get_channel_parameters().as_counterparty_broadcastable(),

lightning/src/util/test_utils.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,15 @@ impl keysinterface::KeysInterface for OnlyReadsKeysInterface {
7676
fn get_channel_signer(&self, _inbound: bool, _channel_value_satoshis: u64) -> EnforcingSigner { unreachable!(); }
7777
fn get_secure_random_bytes(&self) -> [u8; 32] { [0; 32] }
7878

79-
fn read_chan_signer(&self, reader: &[u8]) -> Result<Self::Signer, msgs::DecodeError> {
80-
EnforcingSigner::read(&mut io::Cursor::new(reader))
79+
fn read_chan_signer(&self, mut reader: &[u8]) -> Result<Self::Signer, msgs::DecodeError> {
80+
let inner: InMemorySigner = Readable::read(&mut reader)?;
81+
let state = Arc::new(Mutex::new(EnforcementState::new()));
82+
83+
Ok(EnforcingSigner::new_with_revoked(
84+
inner,
85+
state,
86+
false
87+
))
8188
}
8289
fn sign_invoice(&self, _invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> { unreachable!(); }
8390
}
@@ -499,11 +506,11 @@ impl keysinterface::KeysInterface for TestKeysInterface {
499506
let inner: InMemorySigner = Readable::read(&mut reader)?;
500507
let state = self.make_enforcement_state_cell(inner.commitment_seed);
501508

502-
Ok(EnforcingSigner {
509+
Ok(EnforcingSigner::new_with_revoked(
503510
inner,
504511
state,
505-
disable_revocation_policy_check: self.disable_revocation_policy_check,
506-
})
512+
self.disable_revocation_policy_check
513+
))
507514
}
508515

509516
fn sign_invoice(&self, invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> {

0 commit comments

Comments
 (0)