Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ impl<B: TransactionBroadcaster + ?Sized> AssetLockManager<B> {
///
/// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
165 changes: 137 additions & 28 deletions packages/rs-sdk/src/platform/dashpay/invitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
};
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand All @@ -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())
Expand All @@ -2467,15 +2505,22 @@ mod tests {
async fn run(
chain_fallback: Option<AssetLockProof>,
script: Vec<Result<u32, Error>>,
) -> (Result<u32, InvitationError>, Vec<AssetLockProof>) {
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<AssetLockProof>,
script: Vec<Result<u32, Error>>,
) -> (Result<u32, InvitationError>, Vec<AssetLockProof>) {
let queue: Arc<Mutex<VecDeque<Result<u32, Error>>>> =
Arc::new(Mutex::new(script.into_iter().collect()));
let submitted: Arc<Mutex<Vec<AssetLockProof>>> = 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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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.
Expand Down
Loading
Loading