Skip to content

Commit 6e5065d

Browse files
committed
Move validate_counterparty_revocation to ChannelSigner.
1 parent 007e678 commit 6e5065d

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

lightning/src/sign/ecdsa.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ pub trait EcdsaChannelSigner: ChannelSigner {
4040
fn sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction,
4141
preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>
4242
) -> Result<(Signature, Vec<Signature>), ()>;
43-
/// Validate the counterparty's revocation.
44-
///
45-
/// This is required in order for the signer to make sure that the state has moved
46-
/// forward and it is safe to sign the next counterparty commitment.
47-
fn validate_counterparty_revocation(&self, idx: u64, secret: &SecretKey) -> Result<(), ()>;
4843
/// Creates a signature for a holder's commitment transaction.
4944
///
5045
/// This will be called

lightning/src/sign/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,12 @@ pub trait ChannelSigner {
603603
fn validate_holder_commitment(&self, holder_tx: &HolderCommitmentTransaction,
604604
preimages: Vec<PaymentPreimage>) -> Result<(), ()>;
605605

606+
/// Validate the counterparty's revocation.
607+
///
608+
/// This is required in order for the signer to make sure that the state has moved
609+
/// forward and it is safe to sign the next counterparty commitment.
610+
fn validate_counterparty_revocation(&self, idx: u64, secret: &SecretKey) -> Result<(), ()>;
611+
606612
/// Returns the holder's channel public keys and basepoints.
607613
fn pubkeys(&self) -> &ChannelPublicKeys;
608614

@@ -1084,6 +1090,10 @@ impl ChannelSigner for InMemorySigner {
10841090
Ok(())
10851091
}
10861092

1093+
fn validate_counterparty_revocation(&self, _idx: u64, _secret: &SecretKey) -> Result<(), ()> {
1094+
Ok(())
1095+
}
1096+
10871097
fn pubkeys(&self) -> &ChannelPublicKeys { &self.holder_channel_pubkeys }
10881098

10891099
fn channel_keys_id(&self) -> [u8; 32] { self.channel_keys_id }
@@ -1131,10 +1141,6 @@ impl EcdsaChannelSigner for InMemorySigner {
11311141
Ok((commitment_sig, htlc_sigs))
11321142
}
11331143

1134-
fn validate_counterparty_revocation(&self, _idx: u64, _secret: &SecretKey) -> Result<(), ()> {
1135-
Ok(())
1136-
}
1137-
11381144
fn sign_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
11391145
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
11401146
let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);

lightning/src/util/test_channel_signer.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ impl ChannelSigner for TestChannelSigner {
146146
Ok(())
147147
}
148148

149+
fn validate_counterparty_revocation(&self, idx: u64, _secret: &SecretKey) -> Result<(), ()> {
150+
if !*self.available.lock().unwrap() {
151+
return Err(());
152+
}
153+
let mut state = self.state.lock().unwrap();
154+
assert!(idx == state.last_counterparty_revoked_commitment || idx == state.last_counterparty_revoked_commitment - 1, "expecting to validate the current or next counterparty revocation - trying {}, current {}", idx, state.last_counterparty_revoked_commitment);
155+
state.last_counterparty_revoked_commitment = idx;
156+
Ok(())
157+
}
158+
149159
fn pubkeys(&self) -> &ChannelPublicKeys { self.inner.pubkeys() }
150160

151161
fn channel_keys_id(&self) -> [u8; 32] { self.inner.channel_keys_id() }
@@ -178,16 +188,6 @@ impl EcdsaChannelSigner for TestChannelSigner {
178188
Ok(self.inner.sign_counterparty_commitment(commitment_tx, preimages, secp_ctx).unwrap())
179189
}
180190

181-
fn validate_counterparty_revocation(&self, idx: u64, _secret: &SecretKey) -> Result<(), ()> {
182-
if !*self.available.lock().unwrap() {
183-
return Err(());
184-
}
185-
let mut state = self.state.lock().unwrap();
186-
assert!(idx == state.last_counterparty_revoked_commitment || idx == state.last_counterparty_revoked_commitment - 1, "expecting to validate the current or next counterparty revocation - trying {}, current {}", idx, state.last_counterparty_revoked_commitment);
187-
state.last_counterparty_revoked_commitment = idx;
188-
Ok(())
189-
}
190-
191191
fn sign_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
192192
if !*self.available.lock().unwrap() {
193193
return Err(());

0 commit comments

Comments
 (0)