From ffe3446849594c3593f359d7b68b3e03731c739e Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 10 Nov 2026 20:02:10 +0700 Subject: [PATCH] fix(sdk): retry an InstantSend asset lock proof refused for too many inputs with a ChainLock proof MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From protocol 15 (#5825) Platform holds only the transaction an InstantSend proof embeds to the 100-input cap (`max_asset_lock_transaction_inputs`). A lock with more inputs than that still fits the 20 KiB transition limit up to about 108 inputs, so Platform refuses its InstantSend proof with 10534 (`IdentityAssetLockTransactionTooManyInputsError`) rather than the size error, and `needs_chain_lock_proof` did not retry it. Above about 108 inputs the size fallback already did. `needs_chain_lock_proof` now also retries when the refusal is 10534 and the proof's own transaction has more inputs than the cap the error names. Measuring against the error's cap, not one the SDK assumes, keeps the retry independent of the SDK's protocol version, and a refusal that does not match the proof starts no ChainLock wait. Before protocol 15 the ChainLock proof is refused the same way, so there the retry only delays that refusal by one ChainLock wait, as the size fallback does. The invitation claim's not-chain-locked signal names the input cap for this case instead of "too large", and the docs that list the fallback's triggers name the new one. Tests would have caught this: ✖ before the fix, ✔ after — `should_retry_an_instant_proof_refused_for_too_many_inputs_with_a_chain_lock_proof`, `should_measure_the_proofs_transaction_against_the_cap_the_refusal_names`, and the invitation claim tests `should_resubmit_the_chain_fallback_when_the_islock_proofs_transaction_is_over_the_input_cap` and `should_surface_the_retry_signal_for_an_islock_proof_over_the_input_cap_without_fallback` (red with the new check disabled). Guards: a refusal of a proof within the cap, or of a ChainLock proof, is not retried. Fixes #5826 Co-Authored-By: Claude Opus 5.5 --- .../src/wallet/asset_lock/orchestration.rs | 6 +- .../src/wallet/identity/network/invitation.rs | 5 +- .../wallet/identity/network/registration.rs | 9 +- .../fund_from_asset_lock.rs | 4 +- .../wallet/shielded/fund_from_asset_lock.rs | 5 +- .../rs-sdk/src/platform/dashpay/invitation.rs | 165 +++++++++++++++--- .../transition/asset_lock_submission.rs | 120 ++++++++++++- 7 files changed, 266 insertions(+), 48 deletions(-) diff --git a/packages/rs-platform-wallet/src/wallet/asset_lock/orchestration.rs b/packages/rs-platform-wallet/src/wallet/asset_lock/orchestration.rs index 2dc021033c6..ab401c35572 100644 --- a/packages/rs-platform-wallet/src/wallet/asset_lock/orchestration.rs +++ b/packages/rs-platform-wallet/src/wallet/asset_lock/orchestration.rs @@ -400,9 +400,9 @@ impl AssetLockManager { /// /// Each submission is wrapped in [`submit_with_cl_height_retry`]. When the /// first one fails with an unusable InstantSend proof - /// ([`needs_chain_lock_proof`]: a stale islock, or a transition too large - /// with it), the ChainLock proof for the same outpoint is built and - /// attached to the tracked row + /// ([`needs_chain_lock_proof`]: a stale islock, a transition too large + /// with it, or a funding transaction over the input cap), the ChainLock + /// proof for the same outpoint is built and attached to the tracked row /// ([`upgrade_to_persisted_chain_lock_proof`](Self::upgrade_to_persisted_chain_lock_proof)), /// waiting up to `cl_wait` (`None`: without a bound), and submitted /// instead. If the submit that ends the call fails, a ChainLock proof diff --git a/packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs b/packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs index 1cca521cce3..1c158cf7248 100644 --- a/packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs +++ b/packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs @@ -305,8 +305,9 @@ impl IdentityWallet { /// funded by the imported voucher, then record it in this wallet. /// /// The claim itself — refetching the funding transaction, rebuilding the - /// asset-lock proof, the IS → ChainLock fallback (a stale islock, or a - /// claim too large with the IS proof) and adopting an earlier claim that + /// asset-lock proof, the IS → ChainLock fallback (a stale islock, a claim + /// too large with the IS proof, or a funding transaction over the input + /// cap) and adopting an earlier claim that /// already landed — is /// [`dash_sdk::Sdk::claim_invitation`]. This adds the identity and its /// keys to the wallet's identity manager at `identity_index`. diff --git a/packages/rs-platform-wallet/src/wallet/identity/network/registration.rs b/packages/rs-platform-wallet/src/wallet/identity/network/registration.rs index 66c1ed96c2e..68d3c47e0d0 100644 --- a/packages/rs-platform-wallet/src/wallet/identity/network/registration.rs +++ b/packages/rs-platform-wallet/src/wallet/identity/network/registration.rs @@ -33,7 +33,9 @@ //! (`InvalidInstantAssetLockProofSignatureError`), or the IS proof made //! the transition larger than `max_state_transition_size` //! (`StateTransitionMaxSizeExceededError`, refused by the SDK before -//! broadcast). Detected via +//! broadcast), or its funding transaction has more inputs than an IS +//! proof may carry (`IdentityAssetLockTransactionTooManyInputsError`; +//! from protocol 15 a ChainLock proof is not held to that cap). Detected via //! [`needs_chain_lock_proof`]. Upgrade IS→CL via //! `upgrade_to_persisted_chain_lock_proof`, which attaches the proof to //! the tracked row first, and retry. The CL retry is itself wrapped in @@ -217,8 +219,9 @@ impl IdentityWallet { // Step 3: submit, with two layers of Platform-side fallback: // - **CL-height-too-low** (transient): bump `user_fee_increase` // and retry the same proof. See [`submit_with_cl_height_retry`]. - // - **Unusable IS proof** (quorum rotated, or the IS proof made - // the transition too large): upgrade IS→CL on the same + // - **Unusable IS proof** (quorum rotated, the IS proof made the + // transition too large, or its funding transaction is over the + // input cap): upgrade IS→CL on the same // credit-output outpoint — no new asset lock built, no new // funding-tx broadcast. // diff --git a/packages/rs-platform-wallet/src/wallet/platform_addresses/fund_from_asset_lock.rs b/packages/rs-platform-wallet/src/wallet/platform_addresses/fund_from_asset_lock.rs index 50881adff0f..c44e8f14a2c 100644 --- a/packages/rs-platform-wallet/src/wallet/platform_addresses/fund_from_asset_lock.rs +++ b/packages/rs-platform-wallet/src/wallet/platform_addresses/fund_from_asset_lock.rs @@ -18,8 +18,8 @@ //! shared `submit_with_cl_height_retry` wrapper. IS→CL fallback //! fires both on Core-side timeout (resolver returns `IsTimeout`) //! and on an unusable IS proof (`needs_chain_lock_proof`: Platform -//! rejected the IS lock, or the IS proof made the transition too -//! large). +//! rejected the IS lock, the IS proof made the transition too +//! large, or its funding transaction is over the input cap). //! 4. **Bookkeeping + cleanup** — write each recipient's new credit //! balance into `ManagedPlatformAccount` and emit a //! `PlatformAddressChangeSet`; then `consume_asset_lock` the diff --git a/packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs b/packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs index ea2befa19a5..e0b03b89c03 100644 --- a/packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs +++ b/packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs @@ -18,9 +18,10 @@ //! asset-lock-proof signature is routed through the external //! `key_wallet::signer::Signer` (the host never sees the raw key). //! IS→CL fallback fires when `needs_chain_lock_proof` matches: -//! Platform rejected the IS signature, or the InstantSend proof +//! Platform rejected the IS signature, the InstantSend proof //! made the transition too large (the SDK refuses that before -//! broadcast with a typed error). +//! broadcast with a typed error), or its funding transaction has +//! more inputs than an InstantSend proof may carry. //! 4. **Finalize lock state** — a verified submit completes a wallet drain //! (`DrainCompleted`) or consumes a generic lock. A resumed drain that //! Platform rejects because its exact outpoint was already consumed is diff --git a/packages/rs-sdk/src/platform/dashpay/invitation.rs b/packages/rs-sdk/src/platform/dashpay/invitation.rs index 38b4d61a6ea..debf6d7536f 100644 --- a/packages/rs-sdk/src/platform/dashpay/invitation.rs +++ b/packages/rs-sdk/src/platform/dashpay/invitation.rs @@ -85,8 +85,8 @@ use dpp::secp256k1::{PublicKey, SecretKey}; use crate::core::FetchedCoreTransaction; use crate::platform::transition::asset_lock_submission::{ - is_asset_lock_already_consumed, is_instant_lock_proof_invalid, needs_chain_lock_proof, - submit_with_cl_height_retry, + as_asset_lock_transaction_too_many_inputs, is_asset_lock_already_consumed, + is_instant_lock_proof_invalid, needs_chain_lock_proof, submit_with_cl_height_retry, }; use crate::platform::transition::put_identity::PutIdentity; use crate::platform::transition::put_settings::PutSettings; @@ -828,10 +828,12 @@ impl Sdk { /// stale with `InvalidInstantAssetLockProofSignatureError` — its own message /// asks to "try chain asset lock proof instead". An islock proof over a /// funding tx with many inputs can also make the claim larger than - /// `max_state_transition_size`. When the funding tx is already - /// chain-locked (the usual case by claim time), this resubmits a - /// `ChainAssetLockProof` over the SAME credit output — for the size case - /// only if the claim fits with it. If the tx is not yet + /// `max_state_transition_size`, or carry more inputs than an islock proof + /// may (`IdentityAssetLockTransactionTooManyInputsError`). When the funding + /// tx is already chain-locked (the usual case by claim time), this + /// resubmits a `ChainAssetLockProof` over the SAME credit output — for the + /// size case only if the claim fits with it, and for the input cap case + /// only if the islock proof's own transaction is over the cap. If the tx is not yet /// chain-locked no fallback is possible and the claim returns /// [`InvitationError::NotChainLocked`] as a retry signal. /// @@ -896,7 +898,8 @@ impl Sdk { }); // Submit the primary proof first and — only when the IS proof is - // unusable (a stale islock, or a claim too large to submit with it) — + // unusable (a stale islock, a claim too large to submit with it, or a + // funding transaction over the input cap) — // the ChainLock fallback over the SAME credit output. Each // submission is wrapped in the CL-height-too-low retry (Platform's // observed Core tip briefly behind the proof's chain-locked height; @@ -1019,12 +1022,18 @@ where /// /// `primary` is submitted first. Exactly ONE recovery is attempted, and only /// for an InstantSend primary whose rejection indicts the proof kind rather -/// than the claim (as in `needs_chain_lock_proof`): Platform rejected a stale -/// islock — its signing quorum rotated out, or it is no longer "recent"; -/// Platform's own message asks us to "try chain asset lock proof instead" — -/// or the islock proof made the claim too large to submit, and a ChainLock -/// proof in its place fits. On that rejection the ChainLock -/// `chain_fallback` over the SAME credit output is submitted — +/// than the claim (as in `needs_chain_lock_proof`): +/// - Platform rejected a stale islock — its signing quorum rotated out, or it +/// is no longer "recent"; Platform's own message asks us to "try chain asset +/// lock proof instead"; +/// - the islock proof made the claim too large to submit, and a ChainLock +/// proof in its place fits; +/// - Platform refused the funding transaction for having more inputs than an +/// islock proof may carry (from protocol 15; before it the ChainLock proof +/// is refused the same way). +/// +/// On that rejection the ChainLock `chain_fallback` over the SAME credit output +/// is submitted — /// or, when the funding tx was not yet chain-locked so no fallback could be /// built, [`InvitationError::NotChainLocked`] surfaces a clear retry signal instead of /// the raw consensus error. Every other error — from the primary or from the @@ -1053,6 +1062,9 @@ where let Some(chain_proof) = chain_fallback else { let reason = if is_instant_lock_proof_invalid(&e) { "was rejected by Platform (stale — quorum rotated or no longer recent)" + } else if as_asset_lock_transaction_too_many_inputs(&e).is_some() { + "was rejected by Platform (the funding transaction has more inputs than \ + an islock proof may carry)" } else { "makes the claim too large to submit" }; @@ -1174,8 +1186,10 @@ fn identity_carries_keys( /// populated ONLY when `primary` is InstantSend AND the funding tx is already /// chain-locked — [`Sdk::claim_invitation`]'s IS → ChainLock fallback /// resubmits it if Platform rejects the primary IS proof as stale -/// (`InvalidInstantAssetLockProofSignatureError`) or the IS proof makes the -/// claim too large and the ChainLock proof fits. It is `None` when the primary is +/// (`InvalidInstantAssetLockProofSignatureError`), the IS proof makes the +/// claim too large and the ChainLock proof fits, or Platform refuses the IS +/// proof's transaction for its input count +/// (`IdentityAssetLockTransactionTooManyInputsError`). It is `None` when the primary is /// already a ChainLock proof (nothing to fall back to) or when the funding tx is /// not yet chain-locked (no ChainLock proof can be built — the claim must be /// retried once the block confirms). @@ -1772,8 +1786,8 @@ mod tests { /// An islock that locks the funding tx, with the tx already chain-locked, /// yields an InstantSend primary (fast path) PLUS a ChainLock fallback over the - /// same credit output — what the claim path submits if the IS proof is stale - /// or makes the claim too large. + /// same credit output — what the claim path submits if the IS proof is stale, + /// makes the claim too large, or its transaction is over the input cap. #[test] fn should_carry_a_chain_fallback_for_a_chain_locked_islock_invitation() { let key = voucher(); @@ -2418,16 +2432,19 @@ mod tests { use super::super::submit_claim_with_chain_lock_fallback; use super::super::{Error, InvitationError}; use super::{asset_lock_tx_paying_voucher_at, voucher}; - use dpp::consensus::basic::identity::InvalidInstantAssetLockProofSignatureError; + use dpp::consensus::basic::identity::{ + IdentityAssetLockTransactionTooManyInputsError, + InvalidInstantAssetLockProofSignatureError, + }; use dpp::consensus::basic::state_transition::StateTransitionMaxSizeExceededError; use dpp::consensus::ConsensusError; - use dpp::dashcore::InstantLock; + use dpp::dashcore::{InstantLock, TxIn}; use dpp::identity::state_transition::asset_lock_proof::chain::ChainAssetLockProof; use dpp::identity::state_transition::asset_lock_proof::InstantAssetLockProof; use dpp::prelude::AssetLockProof; - /// One of the two rejections the seam recovers from (the other is a - /// size refusal): Platform's stale-islock consensus error, in the + /// One of the rejections the seam recovers from (the others are a size + /// refusal and an input cap refusal): Platform's stale-islock consensus error, in the /// `Protocol(ConsensusError)` shape `is_instant_lock_proof_invalid` /// matches. fn stale_islock_rejection() -> Error { @@ -2443,6 +2460,27 @@ mod tests { ConsensusError::from(StateTransitionMaxSizeExceededError::new(20_481, 20_480)).into() } + /// Platform's refusal of a funding transaction with one input more than + /// the asset lock input cap (consensus 10534). + fn too_many_inputs_rejection() -> Error { + ConsensusError::from(IdentityAssetLockTransactionTooManyInputsError::new( + 101, 100, + )) + .into() + } + + /// An InstantSend primary over a funding tx with one input more than the + /// asset lock input cap. + fn instant_primary_over_the_input_cap() -> AssetLockProof { + let mut transaction = asset_lock_tx_paying_voucher_at(&voucher(), 0); + transaction.input = vec![TxIn::default(); 101]; + AssetLockProof::Instant(InstantAssetLockProof::new( + InstantLock::default(), + transaction, + 0, + )) + } + /// Any error the seam must NOT treat as an unusable IS proof. fn unrelated_sdk_error() -> Error { Error::Config("simulated unrelated rejection".to_string()) @@ -2467,15 +2505,22 @@ mod tests { async fn run( chain_fallback: Option, script: Vec>, + ) -> (Result, Vec) { + run_with_primary(instant_primary(), chain_fallback, script).await + } + + /// [`run`] with `primary` in place of the one-input InstantSend primary. + async fn run_with_primary( + primary: AssetLockProof, + chain_fallback: Option, + script: Vec>, ) -> (Result, Vec) { let queue: Arc>>> = Arc::new(Mutex::new(script.into_iter().collect())); let submitted: Arc>> = Arc::new(Mutex::new(Vec::new())); let (queue_f, submitted_f) = (Arc::clone(&queue), Arc::clone(&submitted)); - let result = submit_claim_with_chain_lock_fallback( - instant_primary(), - chain_fallback, - move |proof| { + let result = + submit_claim_with_chain_lock_fallback(primary, chain_fallback, move |proof| { let queue = Arc::clone(&queue_f); let submitted = Arc::clone(&submitted_f); async move { @@ -2486,9 +2531,8 @@ mod tests { .pop_front() .expect("script exhausted — the seam submitted more than scripted") } - }, - ) - .await; + }) + .await; let recorded = submitted.lock().expect("submitted").clone(); (result, recorded) } @@ -2568,6 +2612,71 @@ mod tests { ); } + /// From protocol 15 the input cap holds only the transaction an islock + /// proof embeds: a claim refused for its funding transaction's inputs + /// is submitted again with the ChainLock fallback over the same outpoint. + #[tokio::test] + async fn should_resubmit_the_chain_fallback_when_the_islock_proofs_transaction_is_over_the_input_cap( + ) { + let (result, submitted) = run_with_primary( + instant_primary_over_the_input_cap(), + Some(chain_fallback_proof()), + vec![Err(too_many_inputs_rejection()), Ok(9)], + ) + .await; + assert_eq!(result.expect("fallback success"), 9); + assert_eq!(submitted.len(), 2, "primary then fallback"); + assert!( + matches!(submitted[1], AssetLockProof::Chain(_)), + "the resubmission must carry the ChainLock fallback" + ); + } + + /// Without a fallback (funding tx not yet chain-locked) the retry signal + /// names the input cap, not the transition's size. + #[tokio::test] + async fn should_surface_the_retry_signal_for_an_islock_proof_over_the_input_cap_without_fallback( + ) { + let (result, submitted) = run_with_primary( + instant_primary_over_the_input_cap(), + None, + vec![Err(too_many_inputs_rejection())], + ) + .await; + + match result { + Err(InvitationError::NotChainLocked(message)) => { + assert!( + message.contains("more inputs"), + "unexpected message: {message}" + ); + } + other => panic!("expected the not-chain-locked retry signal, got {other:?}"), + } + assert_eq!( + submitted.len(), + 1, + "no second submission without a fallback" + ); + } + + /// A 10534 for an islock primary whose own transaction is within the cap + /// is not about that proof: it propagates after one submission even + /// though a ChainLock fallback exists. + #[tokio::test] + async fn should_not_resubmit_a_too_many_inputs_refusal_of_an_islock_proof_within_the_cap() { + let (result, submitted) = run( + Some(chain_fallback_proof()), + vec![Err(too_many_inputs_rejection())], + ) + .await; + assert!( + matches!(result, Err(InvitationError::Sdk(_))), + "expected the refusal to propagate, got {result:?}" + ); + assert_eq!(submitted.len(), 1, "no fallback for an unrelated refusal"); + } + /// A claim too large by more than the IS proof can give back would be /// too large with the ChainLock proof as well: the error propagates /// after one submission. diff --git a/packages/rs-sdk/src/platform/transition/asset_lock_submission.rs b/packages/rs-sdk/src/platform/transition/asset_lock_submission.rs index e7e3b2651de..457250c8a45 100644 --- a/packages/rs-sdk/src/platform/transition/asset_lock_submission.rs +++ b/packages/rs-sdk/src/platform/transition/asset_lock_submission.rs @@ -10,16 +10,22 @@ //! rejection (the proof's ChainLock is ahead of Platform's Core view). //! - [`as_state_transition_max_size_exceeded`] — the transition is over //! `max_state_transition_size`. +//! - [`as_asset_lock_transaction_too_many_inputs`] — Platform's consensus +//! 10534 rejection (the asset lock transaction has more inputs than +//! `max_asset_lock_transaction_inputs`). //! - [`needs_chain_lock_proof`] — whether a failed submit should be retried //! with a ChainLock proof for the same outpoint: a stale islock, or an -//! InstantSend proof that made the transition too large. +//! InstantSend proof that made the transition too large or whose +//! transaction has more inputs than an InstantSend proof may carry. //! - [`submit_with_cl_height_retry`] — retry-on-10506 wrapper that bumps //! `user_fee_increase` between attempts so Tenderdash's invalid-tx hash //! cache (24h on mainnet/testnet) can't silently drop resubmits. use std::time::Duration; -use dpp::consensus::basic::identity::InvalidAssetLockProofCoreChainHeightError; +use dpp::consensus::basic::identity::{ + IdentityAssetLockTransactionTooManyInputsError, InvalidAssetLockProofCoreChainHeightError, +}; use dpp::consensus::basic::state_transition::StateTransitionMaxSizeExceededError; use dpp::consensus::basic::BasicError; use dpp::consensus::ConsensusError; @@ -150,10 +156,29 @@ pub fn as_state_transition_max_size_exceeded( } } +/// The `IdentityAssetLockTransactionTooManyInputsError` (DPP consensus code +/// 10534) an SDK error carries, if any: Platform refused the asset lock +/// transaction for having more inputs than `max_asset_lock_transaction_inputs`. +/// +/// From protocol version 15 Platform applies the cap only to the transaction +/// an InstantSend proof embeds; before it, also to the transaction Drive +/// fetches from Core for a ChainLock proof. +pub fn as_asset_lock_transaction_too_many_inputs( + error: &Error, +) -> Option<&IdentityAssetLockTransactionTooManyInputsError> { + match error.consensus_error() { + Some(ConsensusError::BasicError( + BasicError::IdentityAssetLockTransactionTooManyInputsError(e), + )) => Some(e), + _ => None, + } +} + /// Whether a failed submit with `proof` should be retried with a ChainLock -/// proof for the same outpoint: Platform could not verify the IS lock, or -/// the IS proof made the transition too large and a ChainLock proof in its -/// place brings it under the limit. +/// proof for the same outpoint: Platform could not verify the IS lock, the +/// IS proof made the transition too large and a ChainLock proof in its +/// place brings it under the limit, or Platform refused the IS proof's +/// transaction for having more inputs than the input cap. /// /// For the size case: an InstantSend proof embeds the whole funding /// transaction and its InstantLock, so it grows with every funding input, @@ -163,11 +188,32 @@ pub fn as_state_transition_max_size_exceeded( /// with a ChainLock proof, so it is not retried: the retry waits for a /// ChainLock first, which would only delay the same error. /// -/// Only an InstantSend `proof` qualifies: a ChainLock proof has no smaller -/// proof to give way to, whatever the error says. +/// For the input cap case: from protocol version 15 the cap holds only the +/// transaction an InstantSend proof embeds, so a lock with more inputs than +/// the cap can be consumed with a ChainLock proof. Before protocol 15 the +/// ChainLock proof is refused with the same error, so there the retry only +/// delays that refusal by one ChainLock wait. +/// +/// Only an InstantSend `proof` qualifies: a ChainLock proof has no other +/// proof kind to give way to, whatever the error says. pub fn needs_chain_lock_proof(error: &Error, proof: &AssetLockProof) -> bool { matches!(proof, AssetLockProof::Instant(_)) - && (is_instant_lock_proof_invalid(error) || chain_lock_proof_fits(error, proof)) + && (is_instant_lock_proof_invalid(error) + || chain_lock_proof_fits(error, proof) + || is_instant_proof_over_the_input_cap(error, proof)) +} + +/// Whether `error` is the input cap refusal of `proof`'s own transaction. The +/// transaction is measured against the cap the error names, as the size +/// case measures the proof itself, so a refusal that does not match the +/// proof does not start a ChainLock wait. +fn is_instant_proof_over_the_input_cap(error: &Error, proof: &AssetLockProof) -> bool { + let (Some(too_many_inputs), AssetLockProof::Instant(instant)) = + (as_asset_lock_transaction_too_many_inputs(error), proof) + else { + return false; + }; + instant.transaction().input.len() > usize::from(too_many_inputs.max_inputs()) } /// Bytes a transition sheds when it carries a ChainLock proof for the same @@ -585,6 +631,7 @@ mod asset_lock_already_consumed_tests { #[cfg(test)] mod chain_lock_fallback_tests { + use dpp::consensus::basic::identity::IdentityAssetLockTransactionTooManyInputsError; use dpp::consensus::basic::state_transition::StateTransitionMaxSizeExceededError; use dpp::consensus::ConsensusError; use dpp::dashcore::{InstantLock, ScriptBuf, Transaction, TxIn}; @@ -720,6 +767,63 @@ mod chain_lock_fallback_tests { assert!(!needs_chain_lock_proof(&stale_islock, &chain_proof())); } + /// Platform's refusal of an asset lock transaction with more inputs than + /// `max_inputs` (consensus 10534). + fn too_many_inputs_error(actual_inputs: u16, max_inputs: u16) -> Error { + ConsensusError::from(IdentityAssetLockTransactionTooManyInputsError::new( + actual_inputs, + max_inputs, + )) + .into() + } + + /// From protocol 15 the input cap holds only the transaction an InstantSend + /// proof embeds, so a lock of more inputs than the cap that still fits the + /// size limit is consumed with a ChainLock proof for the same outpoint. + #[test] + fn should_retry_an_instant_proof_refused_for_too_many_inputs_with_a_chain_lock_proof() { + assert!(needs_chain_lock_proof( + &too_many_inputs_error(101, 100), + &instant_proof(101) + )); + } + + /// The proof's transaction is measured against the cap the refusal names, + /// not a cap the SDK assumes, so the retry does not depend on the protocol + /// version the SDK runs at. + #[test] + fn should_measure_the_proofs_transaction_against_the_cap_the_refusal_names() { + assert!(needs_chain_lock_proof( + &too_many_inputs_error(51, 50), + &instant_proof(51) + )); + assert!(!needs_chain_lock_proof( + &too_many_inputs_error(51, 50), + &instant_proof(50) + )); + } + + /// The refusal is checked against the proof's own transaction: a 10534 for + /// a proof whose transaction is within the cap it names is not about that + /// proof, and waiting for a ChainLock would not change it. + #[test] + fn should_not_retry_a_too_many_inputs_refusal_of_a_proof_within_the_cap() { + assert!(!needs_chain_lock_proof( + &too_many_inputs_error(101, 100), + &instant_proof(100) + )); + } + + /// Before protocol 15 a ChainLock proof is held to the cap too, and it has no + /// smaller proof to give way to: the refusal is surfaced, not retried. + #[test] + fn should_not_retry_a_chain_proof_refused_for_too_many_inputs() { + assert!(!needs_chain_lock_proof( + &too_many_inputs_error(101, 100), + &chain_proof() + )); + } + #[test] fn should_not_retry_an_unrelated_error_with_a_chain_lock_proof() { let error = Error::Generic("transport failure".to_string());