Trait lightning_signer::policy::validator::Validator
source · pub trait Validator {
Show 24 methods
// Required methods
fn validate_ready_channel(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
holder_shutdown_key_path: &[u32]
) -> Result<(), ValidationError>;
fn validate_channel_value(
&self,
setup: &ChannelSetup
) -> Result<(), ValidationError>;
fn validate_onchain_tx(
&self,
wallet: &dyn Wallet,
channels: Vec<Option<Arc<Mutex<ChannelSlot>>>>,
tx: &Transaction,
segwit_flags: &[bool],
values_sat: &[u64],
opaths: &[Vec<u32>],
weight_lower_bound: usize
) -> Result<u64, ValidationError>;
fn decode_commitment_tx(
&self,
keys: &InMemorySigner,
setup: &ChannelSetup,
is_counterparty: bool,
tx: &Transaction,
output_witscripts: &[Vec<u8>]
) -> Result<CommitmentInfo, ValidationError>;
fn validate_counterparty_commitment_tx(
&self,
estate: &EnforcementState,
commit_num: u64,
commitment_point: &PublicKey,
setup: &ChannelSetup,
cstate: &ChainState,
info2: &CommitmentInfo2
) -> Result<(), ValidationError>;
fn validate_holder_commitment_tx(
&self,
estate: &EnforcementState,
commit_num: u64,
commitment_point: &PublicKey,
setup: &ChannelSetup,
cstate: &ChainState,
info2: &CommitmentInfo2
) -> Result<(), ValidationError>;
fn validate_counterparty_revocation(
&self,
state: &EnforcementState,
revoke_num: u64,
commitment_secret: &SecretKey
) -> Result<(), ValidationError>;
fn decode_and_validate_htlc_tx(
&self,
is_counterparty: bool,
setup: &ChannelSetup,
txkeys: &TxCreationKeys,
tx: &Transaction,
redeemscript: &Script,
htlc_amount_sat: u64,
output_witscript: &Script
) -> Result<(u32, HTLCOutputInCommitment, Sighash, EcdsaSighashType), ValidationError>;
fn validate_htlc_tx(
&self,
setup: &ChannelSetup,
cstate: &ChainState,
is_counterparty: bool,
htlc: &HTLCOutputInCommitment,
feerate_per_kw: u32
) -> Result<(), ValidationError>;
fn decode_and_validate_mutual_close_tx(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
state: &EnforcementState,
tx: &Transaction,
opaths: &[Vec<u32>]
) -> Result<ClosingTransaction, ValidationError>;
fn validate_mutual_close_tx(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
state: &EnforcementState,
to_holder_value_sat: u64,
to_counterparty_value_sat: u64,
holder_shutdown_script: &Option<Script>,
counterparty_shutdown_script: &Option<Script>,
holder_wallet_path_hint: &[u32]
) -> Result<(), ValidationError>;
fn validate_delayed_sweep(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
cstate: &ChainState,
tx: &Transaction,
input: usize,
amount_sat: u64,
key_path: &[u32]
) -> Result<(), ValidationError>;
fn validate_counterparty_htlc_sweep(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
cstate: &ChainState,
tx: &Transaction,
redeemscript: &Script,
input: usize,
amount_sat: u64,
key_path: &[u32]
) -> Result<(), ValidationError>;
fn validate_justice_sweep(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
cstate: &ChainState,
tx: &Transaction,
input: usize,
amount_sat: u64,
key_path: &[u32]
) -> Result<(), ValidationError>;
fn validate_payment_balance(
&self,
incoming_msat: u64,
outgoing_msat: u64,
invoiced_amount_msat: Option<u64>
) -> Result<(), ValidationError>;
fn minimum_initial_balance(&self, holder_value_msat: u64) -> u64;
fn policy(&self) -> Box<&dyn Policy>;
// Provided methods
fn enforce_balance(&self) -> bool { ... }
fn set_next_holder_commit_num(
&self,
estate: &mut EnforcementState,
num: u64,
current_commitment_info: CommitmentInfo2,
counterparty_signatures: CommitmentSignatures
) -> Result<(), ValidationError> { ... }
fn get_current_holder_commitment_info(
&self,
estate: &mut EnforcementState,
commitment_number: u64
) -> Result<CommitmentInfo2, ValidationError> { ... }
fn set_next_counterparty_commit_num(
&self,
estate: &mut EnforcementState,
num: u64,
current_point: PublicKey,
current_commitment_info: CommitmentInfo2
) -> Result<(), ValidationError> { ... }
fn set_next_counterparty_revoke_num(
&self,
estate: &mut EnforcementState,
num: u64
) -> Result<(), ValidationError> { ... }
fn validate_block(
&self,
proof: &TxoProof,
height: u32,
header: &BlockHeader,
external_block_hash: Option<&BlockHash>,
prev_filter_header: &FilterHeader,
outpoint_watches: &[OutPoint]
) -> Result<(), ValidationError> { ... }
fn validate_invoice(
&self,
invoice: &Invoice,
now: Duration
) -> Result<(), ValidationError> { ... }
}
Expand description
A policy checker
Called by Node / Channel as needed.
Required Methods§
sourcefn validate_ready_channel(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
holder_shutdown_key_path: &[u32]
) -> Result<(), ValidationError>
fn validate_ready_channel( &self, wallet: &dyn Wallet, setup: &ChannelSetup, holder_shutdown_key_path: &[u32] ) -> Result<(), ValidationError>
Validate ready channel parameters. The holder_shutdown_key_path should be an empty vector if the setup.holder_shutdown_script is not set or the address is in the allowlist.
sourcefn validate_channel_value(
&self,
setup: &ChannelSetup
) -> Result<(), ValidationError>
fn validate_channel_value( &self, setup: &ChannelSetup ) -> Result<(), ValidationError>
Validate channel value after it is late-filled
sourcefn validate_onchain_tx(
&self,
wallet: &dyn Wallet,
channels: Vec<Option<Arc<Mutex<ChannelSlot>>>>,
tx: &Transaction,
segwit_flags: &[bool],
values_sat: &[u64],
opaths: &[Vec<u32>],
weight_lower_bound: usize
) -> Result<u64, ValidationError>
fn validate_onchain_tx( &self, wallet: &dyn Wallet, channels: Vec<Option<Arc<Mutex<ChannelSlot>>>>, tx: &Transaction, segwit_flags: &[bool], values_sat: &[u64], opaths: &[Vec<u32>], weight_lower_bound: usize ) -> Result<u64, ValidationError>
Validate an onchain transaction (funding tx, simple sweeps). This transaction may fund multiple channels at the same time.
segwit_flags
must be validated by the caller by checking
the input transactions.
channels
the funded channel for each funding output, or None for change outputssegwit_flags
- whether the corresponding input tx is segwitvalues_sat
- the amount in satoshi per inputopaths
- derivation path per output. Empty for non-wallet/non-xpub-whitelist outputs.weight_lower_bound
- lower bound of tx size, for feerate checking
Returns the total “non-beneficial value” (i.e. fees) in satoshi
sourcefn decode_commitment_tx(
&self,
keys: &InMemorySigner,
setup: &ChannelSetup,
is_counterparty: bool,
tx: &Transaction,
output_witscripts: &[Vec<u8>]
) -> Result<CommitmentInfo, ValidationError>
fn decode_commitment_tx( &self, keys: &InMemorySigner, setup: &ChannelSetup, is_counterparty: bool, tx: &Transaction, output_witscripts: &[Vec<u8>] ) -> Result<CommitmentInfo, ValidationError>
Phase 1 CommitmentInfo
sourcefn validate_counterparty_commitment_tx(
&self,
estate: &EnforcementState,
commit_num: u64,
commitment_point: &PublicKey,
setup: &ChannelSetup,
cstate: &ChainState,
info2: &CommitmentInfo2
) -> Result<(), ValidationError>
fn validate_counterparty_commitment_tx( &self, estate: &EnforcementState, commit_num: u64, commitment_point: &PublicKey, setup: &ChannelSetup, cstate: &ChainState, info2: &CommitmentInfo2 ) -> Result<(), ValidationError>
Validate a counterparty commitment
sourcefn validate_holder_commitment_tx(
&self,
estate: &EnforcementState,
commit_num: u64,
commitment_point: &PublicKey,
setup: &ChannelSetup,
cstate: &ChainState,
info2: &CommitmentInfo2
) -> Result<(), ValidationError>
fn validate_holder_commitment_tx( &self, estate: &EnforcementState, commit_num: u64, commitment_point: &PublicKey, setup: &ChannelSetup, cstate: &ChainState, info2: &CommitmentInfo2 ) -> Result<(), ValidationError>
Validate a holder commitment
sourcefn validate_counterparty_revocation(
&self,
state: &EnforcementState,
revoke_num: u64,
commitment_secret: &SecretKey
) -> Result<(), ValidationError>
fn validate_counterparty_revocation( &self, state: &EnforcementState, revoke_num: u64, commitment_secret: &SecretKey ) -> Result<(), ValidationError>
Check a counterparty’s revocation of an old state. This also makes a note that the counterparty has committed to their current commitment transaction.
sourcefn decode_and_validate_htlc_tx(
&self,
is_counterparty: bool,
setup: &ChannelSetup,
txkeys: &TxCreationKeys,
tx: &Transaction,
redeemscript: &Script,
htlc_amount_sat: u64,
output_witscript: &Script
) -> Result<(u32, HTLCOutputInCommitment, Sighash, EcdsaSighashType), ValidationError>
fn decode_and_validate_htlc_tx( &self, is_counterparty: bool, setup: &ChannelSetup, txkeys: &TxCreationKeys, tx: &Transaction, redeemscript: &Script, htlc_amount_sat: u64, output_witscript: &Script ) -> Result<(u32, HTLCOutputInCommitment, Sighash, EcdsaSighashType), ValidationError>
Phase 1 decoding of 2nd level HTLC tx and validation by recomposition
sourcefn validate_htlc_tx(
&self,
setup: &ChannelSetup,
cstate: &ChainState,
is_counterparty: bool,
htlc: &HTLCOutputInCommitment,
feerate_per_kw: u32
) -> Result<(), ValidationError>
fn validate_htlc_tx( &self, setup: &ChannelSetup, cstate: &ChainState, is_counterparty: bool, htlc: &HTLCOutputInCommitment, feerate_per_kw: u32 ) -> Result<(), ValidationError>
Phase 2 validation of 2nd level HTLC tx
sourcefn decode_and_validate_mutual_close_tx(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
state: &EnforcementState,
tx: &Transaction,
opaths: &[Vec<u32>]
) -> Result<ClosingTransaction, ValidationError>
fn decode_and_validate_mutual_close_tx( &self, wallet: &dyn Wallet, setup: &ChannelSetup, state: &EnforcementState, tx: &Transaction, opaths: &[Vec<u32>] ) -> Result<ClosingTransaction, ValidationError>
Phase 1 decoding and recomposition of mutual_close
sourcefn validate_mutual_close_tx(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
state: &EnforcementState,
to_holder_value_sat: u64,
to_counterparty_value_sat: u64,
holder_shutdown_script: &Option<Script>,
counterparty_shutdown_script: &Option<Script>,
holder_wallet_path_hint: &[u32]
) -> Result<(), ValidationError>
fn validate_mutual_close_tx( &self, wallet: &dyn Wallet, setup: &ChannelSetup, state: &EnforcementState, to_holder_value_sat: u64, to_counterparty_value_sat: u64, holder_shutdown_script: &Option<Script>, counterparty_shutdown_script: &Option<Script>, holder_wallet_path_hint: &[u32] ) -> Result<(), ValidationError>
Phase 2 Validatation of mutual_close
sourcefn validate_delayed_sweep(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
cstate: &ChainState,
tx: &Transaction,
input: usize,
amount_sat: u64,
key_path: &[u32]
) -> Result<(), ValidationError>
fn validate_delayed_sweep( &self, wallet: &dyn Wallet, setup: &ChannelSetup, cstate: &ChainState, tx: &Transaction, input: usize, amount_sat: u64, key_path: &[u32] ) -> Result<(), ValidationError>
Validation of delayed sweep transaction
sourcefn validate_counterparty_htlc_sweep(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
cstate: &ChainState,
tx: &Transaction,
redeemscript: &Script,
input: usize,
amount_sat: u64,
key_path: &[u32]
) -> Result<(), ValidationError>
fn validate_counterparty_htlc_sweep( &self, wallet: &dyn Wallet, setup: &ChannelSetup, cstate: &ChainState, tx: &Transaction, redeemscript: &Script, input: usize, amount_sat: u64, key_path: &[u32] ) -> Result<(), ValidationError>
Validation of counterparty htlc sweep transaction (first level commitment htlc outputs)
sourcefn validate_justice_sweep(
&self,
wallet: &dyn Wallet,
setup: &ChannelSetup,
cstate: &ChainState,
tx: &Transaction,
input: usize,
amount_sat: u64,
key_path: &[u32]
) -> Result<(), ValidationError>
fn validate_justice_sweep( &self, wallet: &dyn Wallet, setup: &ChannelSetup, cstate: &ChainState, tx: &Transaction, input: usize, amount_sat: u64, key_path: &[u32] ) -> Result<(), ValidationError>
Validation of justice sweep transaction
sourcefn validate_payment_balance(
&self,
incoming_msat: u64,
outgoing_msat: u64,
invoiced_amount_msat: Option<u64>
) -> Result<(), ValidationError>
fn validate_payment_balance( &self, incoming_msat: u64, outgoing_msat: u64, invoiced_amount_msat: Option<u64> ) -> Result<(), ValidationError>
Validation of the payment state for a payment hash. This could include a payment routed through us, or a payment we are making, or both. If we are not making a payment, then the incoming must be greater or equal to the outgoing. Otherwise, the incoming minus outgoing should be enough to pay for the invoice and routing fees, but no larger.
sourcefn minimum_initial_balance(&self, holder_value_msat: u64) -> u64
fn minimum_initial_balance(&self, holder_value_msat: u64) -> u64
The minimum initial commitment transaction balance to us, given the funding amount. The result is in satoshi.
Provided Methods§
sourcefn enforce_balance(&self) -> bool
fn enforce_balance(&self) -> bool
Whether the policy specifies that holder balance should be tracked and enforced.
sourcefn set_next_holder_commit_num(
&self,
estate: &mut EnforcementState,
num: u64,
current_commitment_info: CommitmentInfo2,
counterparty_signatures: CommitmentSignatures
) -> Result<(), ValidationError>
fn set_next_holder_commit_num( &self, estate: &mut EnforcementState, num: u64, current_commitment_info: CommitmentInfo2, counterparty_signatures: CommitmentSignatures ) -> Result<(), ValidationError>
Set next holder commitment number
sourcefn get_current_holder_commitment_info(
&self,
estate: &mut EnforcementState,
commitment_number: u64
) -> Result<CommitmentInfo2, ValidationError>
fn get_current_holder_commitment_info( &self, estate: &mut EnforcementState, commitment_number: u64 ) -> Result<CommitmentInfo2, ValidationError>
Get the current commitment info
sourcefn set_next_counterparty_commit_num(
&self,
estate: &mut EnforcementState,
num: u64,
current_point: PublicKey,
current_commitment_info: CommitmentInfo2
) -> Result<(), ValidationError>
fn set_next_counterparty_commit_num( &self, estate: &mut EnforcementState, num: u64, current_point: PublicKey, current_commitment_info: CommitmentInfo2 ) -> Result<(), ValidationError>
Set next counterparty commitment number
sourcefn set_next_counterparty_revoke_num(
&self,
estate: &mut EnforcementState,
num: u64
) -> Result<(), ValidationError>
fn set_next_counterparty_revoke_num( &self, estate: &mut EnforcementState, num: u64 ) -> Result<(), ValidationError>
Set next counterparty revoked commitment number
sourcefn validate_block(
&self,
proof: &TxoProof,
height: u32,
header: &BlockHeader,
external_block_hash: Option<&BlockHash>,
prev_filter_header: &FilterHeader,
outpoint_watches: &[OutPoint]
) -> Result<(), ValidationError>
fn validate_block( &self, proof: &TxoProof, height: u32, header: &BlockHeader, external_block_hash: Option<&BlockHash>, prev_filter_header: &FilterHeader, outpoint_watches: &[OutPoint] ) -> Result<(), ValidationError>
Validate a block and a TXOO proof for spent/unspent watched outputs
sourcefn validate_invoice(
&self,
invoice: &Invoice,
now: Duration
) -> Result<(), ValidationError>
fn validate_invoice( &self, invoice: &Invoice, now: Duration ) -> Result<(), ValidationError>
Validate an invoice