-impl Readable for EnforcingChannelKeys {
- fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
- let inner = Readable::read(reader)?;
- let obscure_and_last = Readable::read(reader)?;
- Ok(EnforcingChannelKeys {
- inner: inner,
- commitment_number_obscure_and_last: Arc::new(Mutex::new(obscure_and_last))
- })
+impl EnforcingSigner {
+ fn verify_counterparty_commitment_tx<'a, T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &'a CommitmentTransaction, secp_ctx: &Secp256k1<T>) -> TrustedCommitmentTransaction<'a> {
+ commitment_tx.verify(&self.inner.get_channel_parameters().as_counterparty_broadcastable(),
+ self.inner.counterparty_pubkeys(), self.inner.pubkeys(), secp_ctx)
+ .expect("derived different per-tx keys or built transaction")
+ }
+
+ fn verify_holder_commitment_tx<'a, T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &'a CommitmentTransaction, secp_ctx: &Secp256k1<T>) -> TrustedCommitmentTransaction<'a> {
+ commitment_tx.verify(&self.inner.get_channel_parameters().as_holder_broadcastable(),
+ self.inner.pubkeys(), self.inner.counterparty_pubkeys(), secp_ctx)
+ .expect("derived different per-tx keys or built transaction")
+ }
+}
+
+/// The state used by [`EnforcingSigner`] in order to enforce policy checks
+///
+/// This structure is maintained by KeysInterface since we may have multiple copies of
+/// the signer and they must coordinate their state.
+#[derive(Clone)]
+pub struct EnforcementState {
+ /// The last counterparty commitment number we signed, backwards counting
+ pub last_counterparty_commitment: u64,
+ /// The last counterparty commitment they revoked, backwards counting
+ pub last_counterparty_revoked_commitment: u64,
+ /// The last holder commitment number we revoked, backwards counting
+ pub last_holder_revoked_commitment: u64,
+ /// The last validated holder commitment number, backwards counting
+ pub last_holder_commitment: u64,
+}
+
+impl EnforcementState {
+ /// Enforcement state for a new channel
+ pub fn new() -> Self {
+ EnforcementState {
+ last_counterparty_commitment: INITIAL_REVOKED_COMMITMENT_NUMBER,
+ last_counterparty_revoked_commitment: INITIAL_REVOKED_COMMITMENT_NUMBER,
+ last_holder_revoked_commitment: INITIAL_REVOKED_COMMITMENT_NUMBER,
+ last_holder_commitment: INITIAL_REVOKED_COMMITMENT_NUMBER,
+ }