]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Move validate_counterparty_revocation to ChannelSigner.
authorArik Sosman <git@arik.io>
Wed, 29 Nov 2023 00:14:09 +0000 (16:14 -0800)
committerArik Sosman <git@arik.io>
Wed, 29 Nov 2023 00:14:09 +0000 (16:14 -0800)
lightning/src/sign/ecdsa.rs
lightning/src/sign/mod.rs
lightning/src/util/test_channel_signer.rs

index c9677c8ba250245084e7ddf1dbed8b5be59b194b..194d714c977855e6058165ef4b1d4839f54ee2a2 100644 (file)
@@ -40,11 +40,6 @@ pub trait EcdsaChannelSigner: ChannelSigner {
        fn sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction,
                preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>
        ) -> Result<(Signature, Vec<Signature>), ()>;
-       /// Validate the counterparty's revocation.
-       ///
-       /// This is required in order for the signer to make sure that the state has moved
-       /// forward and it is safe to sign the next counterparty commitment.
-       fn validate_counterparty_revocation(&self, idx: u64, secret: &SecretKey) -> Result<(), ()>;
        /// Creates a signature for a holder's commitment transaction.
        ///
        /// This will be called
index 65457d27dbc1e42c6f293c027ce25f6595d1e87e..9fff6378e763df4741060d115d760c9efc17dae2 100644 (file)
@@ -603,6 +603,12 @@ pub trait ChannelSigner {
        fn validate_holder_commitment(&self, holder_tx: &HolderCommitmentTransaction,
                preimages: Vec<PaymentPreimage>) -> Result<(), ()>;
 
+       /// Validate the counterparty's revocation.
+       ///
+       /// This is required in order for the signer to make sure that the state has moved
+       /// forward and it is safe to sign the next counterparty commitment.
+       fn validate_counterparty_revocation(&self, idx: u64, secret: &SecretKey) -> Result<(), ()>;
+
        /// Returns the holder's channel public keys and basepoints.
        fn pubkeys(&self) -> &ChannelPublicKeys;
 
@@ -1084,6 +1090,10 @@ impl ChannelSigner for InMemorySigner {
                Ok(())
        }
 
+       fn validate_counterparty_revocation(&self, _idx: u64, _secret: &SecretKey) -> Result<(), ()> {
+               Ok(())
+       }
+
        fn pubkeys(&self) -> &ChannelPublicKeys { &self.holder_channel_pubkeys }
 
        fn channel_keys_id(&self) -> [u8; 32] { self.channel_keys_id }
@@ -1131,10 +1141,6 @@ impl EcdsaChannelSigner for InMemorySigner {
                Ok((commitment_sig, htlc_sigs))
        }
 
-       fn validate_counterparty_revocation(&self, _idx: u64, _secret: &SecretKey) -> Result<(), ()> {
-               Ok(())
-       }
-
        fn sign_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
                let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
                let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
index 0e3890f54de518340f9dabb5c695b9c558e17c30..51edce1768c7283aac89b865e09dc12e0a7395f6 100644 (file)
@@ -146,6 +146,16 @@ impl ChannelSigner for TestChannelSigner {
                Ok(())
        }
 
+       fn validate_counterparty_revocation(&self, idx: u64, _secret: &SecretKey) -> Result<(), ()> {
+               if !*self.available.lock().unwrap() {
+                       return Err(());
+               }
+               let mut state = self.state.lock().unwrap();
+               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);
+               state.last_counterparty_revoked_commitment = idx;
+               Ok(())
+       }
+
        fn pubkeys(&self) -> &ChannelPublicKeys { self.inner.pubkeys() }
 
        fn channel_keys_id(&self) -> [u8; 32] { self.inner.channel_keys_id() }
@@ -178,16 +188,6 @@ impl EcdsaChannelSigner for TestChannelSigner {
                Ok(self.inner.sign_counterparty_commitment(commitment_tx, preimages, secp_ctx).unwrap())
        }
 
-       fn validate_counterparty_revocation(&self, idx: u64, _secret: &SecretKey) -> Result<(), ()> {
-               if !*self.available.lock().unwrap() {
-                       return Err(());
-               }
-               let mut state = self.state.lock().unwrap();
-               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);
-               state.last_counterparty_revoked_commitment = idx;
-               Ok(())
-       }
-
        fn sign_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
                if !*self.available.lock().unwrap() {
                        return Err(());