Skip to content

Commit 4fc3a17

Browse files
authored
Merge pull request #2755 from arik-so/arik/taproot-2023-11-followup-2512
Followups to 2512
2 parents 2659a23 + c70ea1d commit 4fc3a17

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

lightning/src/ln/channel.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21452145
.map(|(sig, _)| sig).ok()?
21462146
},
21472147
// TODO (taproot|arik)
2148+
#[cfg(taproot)]
21482149
_ => todo!()
21492150
};
21502151

@@ -2199,6 +2200,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21992200
(counterparty_initial_commitment_tx, funding_signed)
22002201
},
22012202
// TODO (taproot|arik)
2203+
#[cfg(taproot)]
22022204
_ => todo!()
22032205
}
22042206
}
@@ -3492,6 +3494,7 @@ impl<SP: Deref> Channel<SP> where
34923494
).map_err(|_| ChannelError::Close("Failed to validate revocation from peer".to_owned()))?;
34933495
},
34943496
// TODO (taproot|arik)
3497+
#[cfg(taproot)]
34953498
_ => todo!()
34963499
};
34973500

@@ -4447,6 +4450,7 @@ impl<SP: Deref> Channel<SP> where
44474450
}), None, None))
44484451
},
44494452
// TODO (taproot|arik)
4453+
#[cfg(taproot)]
44504454
_ => todo!()
44514455
}
44524456
}
@@ -4700,6 +4704,7 @@ impl<SP: Deref> Channel<SP> where
47004704
}), signed_tx, shutdown_result))
47014705
},
47024706
// TODO (taproot|arik)
4707+
#[cfg(taproot)]
47034708
_ => todo!()
47044709
}
47054710
}
@@ -5333,6 +5338,7 @@ impl<SP: Deref> Channel<SP> where
53335338
})
53345339
},
53355340
// TODO (taproot|arik)
5341+
#[cfg(taproot)]
53365342
_ => todo!()
53375343
}
53385344
}
@@ -5362,6 +5368,7 @@ impl<SP: Deref> Channel<SP> where
53625368
})
53635369
},
53645370
// TODO (taproot|arik)
5371+
#[cfg(taproot)]
53655372
_ => todo!()
53665373
}
53675374
} else {
@@ -5737,6 +5744,7 @@ impl<SP: Deref> Channel<SP> where
57375744
}, (counterparty_commitment_txid, commitment_stats.htlcs_included)))
57385745
},
57395746
// TODO (taproot|arik)
5747+
#[cfg(taproot)]
57405748
_ => todo!()
57415749
}
57425750
}
@@ -9105,7 +9113,7 @@ use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
91059113
assert_eq!(chan_utils::build_commitment_secret(&seed, 1),
91069114
<Vec<u8>>::from_hex("915c75942a26bb3a433a8ce2cb0427c29ec6c1775cfc78328b57f6ba7bfeaa9c").unwrap()[..]);
91079115
}
9108-
9116+
91099117
#[test]
91109118
fn test_key_derivation() {
91119119
// Test vectors from BOLT 3 Appendix E:

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: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use core::convert::TryInto;
5757
use core::ops::Deref;
5858
use core::sync::atomic::{AtomicUsize, Ordering};
5959
#[cfg(taproot)]
60-
use musig2::types::{PartialSignature, PublicNonce, SecretNonce};
60+
use musig2::types::{PartialSignature, PublicNonce};
6161
use crate::io::{self, Error};
6262
use crate::ln::features::ChannelTypeFeatures;
6363
use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
@@ -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);
@@ -1258,7 +1264,7 @@ impl TaprootChannelSigner for InMemorySigner {
12581264
todo!()
12591265
}
12601266

1261-
fn finalize_holder_commitment(&self, commitment_number: u64, commitment_tx: &HolderCommitmentTransaction, counterparty_partial_signature: PartialSignatureWithNonce, secp_ctx: &Secp256k1<All>) -> Result<PartialSignature, ()> {
1267+
fn finalize_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction, counterparty_partial_signature: PartialSignatureWithNonce, secp_ctx: &Secp256k1<All>) -> Result<PartialSignature, ()> {
12621268
todo!()
12631269
}
12641270

lightning/src/sign/taproot.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ pub trait TaprootChannelSigner: ChannelSigner {
5151
/// An external signer implementation should check that the commitment has not been revoked.
5252
///
5353
// TODO: Document the things someone using this interface should enforce before signing.
54-
fn finalize_holder_commitment(&self, commitment_number: u64,
55-
commitment_tx: &HolderCommitmentTransaction,
54+
fn finalize_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction,
5655
counterparty_partial_signature: PartialSignatureWithNonce,
5756
secp_ctx: &Secp256k1<secp256k1::All>
5857
) -> Result<PartialSignature, ()>;

lightning/src/util/test_channel_signer.rs

Lines changed: 11 additions & 11 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(());
@@ -292,7 +292,7 @@ impl TaprootChannelSigner for TestChannelSigner {
292292
todo!()
293293
}
294294

295-
fn finalize_holder_commitment(&self, commitment_number: u64, commitment_tx: &HolderCommitmentTransaction, counterparty_partial_signature: PartialSignatureWithNonce, secp_ctx: &Secp256k1<All>) -> Result<PartialSignature, ()> {
295+
fn finalize_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction, counterparty_partial_signature: PartialSignatureWithNonce, secp_ctx: &Secp256k1<All>) -> Result<PartialSignature, ()> {
296296
todo!()
297297
}
298298

0 commit comments

Comments
 (0)