diff --git a/changes/runtime/changed/claim-rewards-kind.md b/changes/runtime/changed/claim-rewards-kind.md new file mode 100644 index 000000000..2741a9e37 --- /dev/null +++ b/changes/runtime/changed/claim-rewards-kind.md @@ -0,0 +1,18 @@ +#runtime #node + +# Ad `Op` variant for `ClaimBridgeTransfer` + +The added `Op::ClaimBridgeTransfer` variant. `Op` is passed in only from Runtime to Node, +so updating Node before the Runtime makes it a safe change. Decode side is updated before Encode side. +The new variant is added as last to `Op`, so existing variants SCALE encoding doesn't change. + +Claim of bridge transferred amount haven't yet happened in any durable environment yet, so future +consumers of `ClaimRewards` and `ClaimBridgeTransfer` can be sure what caused these events. +This is not true for lower testnets where old runtime will encode both kinds of claims as `ClaimRewards`. + +`TransactionAppliedStateRoot` is not changed, it has only one field for amounts of both kinds of claims. + +`Op` / `Operation` types, and the static runtime metadata is regenerated accordingly. + +PR: https://github.com/midnightntwrk/midnight-node/pull/1727 +Issue: https://github.com/midnightntwrk/midnight-node/issues/1084 diff --git a/ledger/src/common/types.rs b/ledger/src/common/types.rs index 531228652..8e24767b9 100644 --- a/ledger/src/common/types.rs +++ b/ledger/src/common/types.rs @@ -68,6 +68,10 @@ pub enum Op { Deploy { address: Vec }, Maintain { address: Vec }, ClaimRewards { value: u128 }, + // New variants MUST be appended at the end: `Op` is SCALE-encoded across the + // `get_decoded_transaction` runtime-API boundary, so the variant indices are wire-significant. + // Appending keeps existing indices stable (an older decoder simply never sees the new index). + ClaimBridgeTransfer { value: u128 }, } #[derive(Encode, Decode, DecodeWithMemTracking, TypeInfo, Clone, Eq, PartialEq, Debug)] diff --git a/ledger/src/versions/common/api/transaction.rs b/ledger/src/versions/common/api/transaction.rs index f0db26aee..be7f0e5fd 100644 --- a/ledger/src/versions/common/api/transaction.rs +++ b/ledger/src/versions/common/api/transaction.rs @@ -29,9 +29,9 @@ use ledger_storage_local::arena::Sp; use mn_ledger_local::{ error::MalformedTransaction, structure::{ - ClaimRewardsTransaction, ContractAction, IntentHash, OutputInstructionUnshielded, - ProofKind, ProofMarker, SignatureKind, StandardTransaction, Transaction as Tx, Utxo, - UtxoOutput, UtxoSpend, + ClaimKind, ClaimRewardsTransaction, ContractAction, IntentHash, + OutputInstructionUnshielded, ProofKind, ProofMarker, SignatureKind, StandardTransaction, + Transaction as Tx, Utxo, UtxoOutput, UtxoSpend, }, }; use std::borrow::Borrow; @@ -88,9 +88,10 @@ where InnerTx::tag_unique_factor() } } -pub enum ContractActionExt, D: DB> { +enum ContractActionExt, D: DB> { ContractAction(Box>), ClaimRewards { value: u128 }, + ClaimBridgeTransfer { value: u128 }, } struct UtxoOutputInfo { @@ -247,8 +248,14 @@ impl, D: DB> Transaction { } }) .collect(), - Tx::ClaimRewards(ClaimRewardsTransaction { value, .. }) => { - vec![ContractActionExt::ClaimRewards { value: *value }] + Tx::ClaimRewards(ClaimRewardsTransaction { value, kind, .. }) => { + let action = match kind { + ClaimKind::Reward => ContractActionExt::ClaimRewards { value: *value }, + ClaimKind::CardanoBridge => { + ContractActionExt::ClaimBridgeTransfer { value: *value } + }, + }; + vec![action] }, }; @@ -266,6 +273,9 @@ impl, D: DB> Transaction { }, }, ContractActionExt::ClaimRewards { value } => Operation::ClaimRewards { value }, + ContractActionExt::ClaimBridgeTransfer { value } => { + Operation::ClaimBridgeTransfer { value } + }, }) } @@ -418,6 +428,7 @@ pub enum Operation { Deploy { address: ContractAddress }, Maintain { address: ContractAddress }, ClaimRewards { value: u128 }, + ClaimBridgeTransfer { value: u128 }, } // grcov-excl-start diff --git a/ledger/src/versions/common/mod.rs b/ledger/src/versions/common/mod.rs index 5cac7be73..270e71c5d 100644 --- a/ledger/src/versions/common/mod.rs +++ b/ledger/src/versions/common/mod.rs @@ -473,7 +473,7 @@ where start_tx_processing_time.elapsed().as_millis() ); }, - TransactionOperation::ClaimRewards { value, .. } => { + TransactionOperation::ClaimRewards { value } => { event.claim_rewards.push(value); log::trace!( target: LOG_TARGET, @@ -481,6 +481,14 @@ where start_tx_processing_time.elapsed().as_millis() ); }, + TransactionOperation::ClaimBridgeTransfer { value } => { + event.claim_rewards.push(value); + log::trace!( + target: LOG_TARGET, + "⏱️ Tx op: ClaimBridgeTransfer (elapsed_ms={})", + start_tx_processing_time.elapsed().as_millis() + ); + }, } } @@ -673,6 +681,9 @@ where Op::Maintain { address: api.tagged_serialize(&address)? } }, TransactionOperation::ClaimRewards { value } => Op::ClaimRewards { value }, + TransactionOperation::ClaimBridgeTransfer { value } => { + Op::ClaimBridgeTransfer { value } + }, }; acc.push(a); Ok::<_, LedgerApiError>(acc) diff --git a/metadata/static/midnight_metadata.scale b/metadata/static/midnight_metadata.scale index 7c4ab497c..d82818d1a 100644 Binary files a/metadata/static/midnight_metadata.scale and b/metadata/static/midnight_metadata.scale differ diff --git a/metadata/static/midnight_metadata_2.0.0.scale b/metadata/static/midnight_metadata_2.0.0.scale index 7c4ab497c..d82818d1a 100644 Binary files a/metadata/static/midnight_metadata_2.0.0.scale and b/metadata/static/midnight_metadata_2.0.0.scale differ diff --git a/node/src/filtering_pool.rs b/node/src/filtering_pool.rs index 6de203788..47dd0b0eb 100644 --- a/node/src/filtering_pool.rs +++ b/node/src/filtering_pool.rs @@ -112,7 +112,7 @@ where false } }, - Op::Call { .. } | Op::ClaimRewards { .. } => false, + Op::Call { .. } | Op::ClaimRewards { .. } | Op::ClaimBridgeTransfer { .. } => false, }) }