X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fkeysinterface.rs;h=338e81d17099cc0aecd193216aa7f228d60409b6;hb=7f49f6bf4d838196ff7b20e78207b4bfdad264c6;hp=b1290708b95f70a71ebf6193cceb1677aa3150bd;hpb=5f96d1334435e74545670a5dff24078edf749d60;p=rust-lightning diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index b1290708b..338e81d17 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -85,6 +85,8 @@ pub struct DelayedPaymentOutputDescriptor { } impl DelayedPaymentOutputDescriptor { /// The maximum length a well-formed witness spending one of these should have. + /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte + /// shorter. // Calculated as 1 byte length + 73 byte signature, 1 byte empty vec push, 1 byte length plus // redeemscript push length. pub const MAX_WITNESS_LENGTH: usize = 1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH + 1; @@ -117,6 +119,8 @@ pub struct StaticPaymentOutputDescriptor { } impl StaticPaymentOutputDescriptor { /// The maximum length a well-formed witness spending one of these should have. + /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte + /// shorter. // Calculated as 1 byte legnth + 73 byte signature, 1 byte empty vec push, 1 byte length plus // redeemscript push length. pub const MAX_WITNESS_LENGTH: usize = 1 + 73 + 34; @@ -543,15 +547,21 @@ pub trait SignerProvider { /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs. /// + /// If this function returns an error, this will result in a channel failing to open. + /// /// This method should return a different value each time it is called, to avoid linking /// on-chain funds across channels as controlled to the same user. - fn get_destination_script(&self) -> Script; + fn get_destination_script(&self) -> Result; /// Get a script pubkey which we will send funds to when closing a channel. /// + /// If this function returns an error, this will result in a channel failing to open or close. + /// In the event of a failure when the counterparty is initiating a close, this can result in a + /// channel force close. + /// /// This method should return a different value each time it is called, to avoid linking /// on-chain funds across channels as controlled to the same user. - fn get_shutdown_scriptpubkey(&self) -> ShutdownScript; + fn get_shutdown_scriptpubkey(&self) -> Result; } /// A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory. @@ -1188,6 +1198,8 @@ impl KeysManager { witness: Witness::new(), }); witness_weight += StaticPaymentOutputDescriptor::MAX_WITNESS_LENGTH; + #[cfg(feature = "grind_signatures")] + { witness_weight -= 1; } // Guarantees a low R signature input_value += descriptor.output.value; if !output_set.insert(descriptor.outpoint) { return Err(()); } }, @@ -1199,6 +1211,8 @@ impl KeysManager { witness: Witness::new(), }); witness_weight += DelayedPaymentOutputDescriptor::MAX_WITNESS_LENGTH; + #[cfg(feature = "grind_signatures")] + { witness_weight -= 1; } // Guarantees a low R signature input_value += descriptor.output.value; if !output_set.insert(descriptor.outpoint) { return Err(()); } }, @@ -1210,6 +1224,8 @@ impl KeysManager { witness: Witness::new(), }); witness_weight += 1 + 73 + 34; + #[cfg(feature = "grind_signatures")] + { witness_weight -= 1; } // Guarantees a low R signature input_value += output.value; if !output_set.insert(*outpoint) { return Err(()); } } @@ -1366,12 +1382,12 @@ impl SignerProvider for KeysManager { InMemorySigner::read(&mut io::Cursor::new(reader), self) } - fn get_destination_script(&self) -> Script { - self.destination_script.clone() + fn get_destination_script(&self) -> Result { + Ok(self.destination_script.clone()) } - fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { - ShutdownScript::new_p2wpkh_from_pubkey(self.shutdown_pubkey.clone()) + fn get_shutdown_scriptpubkey(&self) -> Result { + Ok(ShutdownScript::new_p2wpkh_from_pubkey(self.shutdown_pubkey.clone())) } } @@ -1461,11 +1477,11 @@ impl SignerProvider for PhantomKeysManager { self.inner.read_chan_signer(reader) } - fn get_destination_script(&self) -> Script { + fn get_destination_script(&self) -> Result { self.inner.get_destination_script() } - fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { + fn get_shutdown_scriptpubkey(&self) -> Result { self.inner.get_shutdown_scriptpubkey() } }