Skip to content
Open
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
18 changes: 18 additions & 0 deletions changes/runtime/changed/claim-rewards-kind.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions ledger/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ pub enum Op {
Deploy { address: Vec<u8> },
Maintain { address: Vec<u8> },
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 },
Comment thread
gilescope marked this conversation as resolved.
}

#[derive(Encode, Decode, DecodeWithMemTracking, TypeInfo, Clone, Eq, PartialEq, Debug)]
Expand Down
23 changes: 17 additions & 6 deletions ledger/src/versions/common/api/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,9 +88,10 @@ where
InnerTx::tag_unique_factor()
}
}
pub enum ContractActionExt<P: ProofKind<D>, D: DB> {
enum ContractActionExt<P: ProofKind<D>, D: DB> {
ContractAction(Box<ContractAction<P, D>>),
ClaimRewards { value: u128 },
ClaimBridgeTransfer { value: u128 },
}

struct UtxoOutputInfo {
Expand Down Expand Up @@ -247,8 +248,14 @@ impl<S: SignatureKind<D>, D: DB> Transaction<S, D> {
}
})
.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]
},
};

Expand All @@ -266,6 +273,9 @@ impl<S: SignatureKind<D>, D: DB> Transaction<S, D> {
},
},
ContractActionExt::ClaimRewards { value } => Operation::ClaimRewards { value },
ContractActionExt::ClaimBridgeTransfer { value } => {
Operation::ClaimBridgeTransfer { value }
},
})
}

Expand Down Expand Up @@ -418,6 +428,7 @@ pub enum Operation {
Deploy { address: ContractAddress },
Maintain { address: ContractAddress },
ClaimRewards { value: u128 },
ClaimBridgeTransfer { value: u128 },
}

// grcov-excl-start
Expand Down
13 changes: 12 additions & 1 deletion ledger/src/versions/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,22 @@ where
start_tx_processing_time.elapsed().as_millis()
);
},
TransactionOperation::ClaimRewards { value, .. } => {
TransactionOperation::ClaimRewards { value } => {
event.claim_rewards.push(value);
log::trace!(
target: LOG_TARGET,
"⏱️ Tx op: ClaimRewards (elapsed_ms={})",
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()
);
},
}
}

Expand Down Expand Up @@ -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)
Expand Down
Binary file modified metadata/static/midnight_metadata.scale
Binary file not shown.
Binary file modified metadata/static/midnight_metadata_2.0.0.scale
Binary file not shown.
2 changes: 1 addition & 1 deletion node/src/filtering_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
false
}
},
Op::Call { .. } | Op::ClaimRewards { .. } => false,
Op::Call { .. } | Op::ClaimRewards { .. } | Op::ClaimBridgeTransfer { .. } => false,
})
}

Expand Down