-
Notifications
You must be signed in to change notification settings - Fork 58
feat(dpp)!: indexOnly transitions and ABCI validation — delete-by-values #4493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5aa2a1e
feat(dpp)!: add indexOnly document types with terminal index keys
QuantumExplorer 6970c09
feat(drive)!: indexOnly storage layout — index entries as the rows
QuantumExplorer 5cd8f9b
feat(dpp)!: indexOnly transitions and ABCI validation — delete-by-values
QuantumExplorer fb9dc14
fix(dpp): address indexOnly review — owner-bound entries, terminal ty…
QuantumExplorer 74dbf92
Merge branch 'feat/index-only-dpp' into feat/index-only-drive
QuantumExplorer 9a80440
Merge branch 'feat/index-only-drive' into feat/index-only-transitions
QuantumExplorer f675274
fix(drive-abci): probe every index entry on indexOnly delete validation
QuantumExplorer 2cc3ce0
fix(drive): bind indexOnly entries into one row with a stored commitment
QuantumExplorer e71f609
Merge branch 'feat/index-only-drive' into feat/index-only-transitions
QuantumExplorer 0cadcd1
fix(drive)!: enforce row commitments on indexOnly deletes; version-pr…
QuantumExplorer cdf08cd
Merge remote-tracking branch 'origin/v4.2-dev' into feat/index-only-d…
QuantumExplorer 94a17f5
Merge branch 'feat/index-only-drive' into feat/index-only-transitions
QuantumExplorer cf3bd34
fix(drive): drop unused EpochCosts import in indexOnly e2e tests
QuantumExplorer e6a6512
Merge branch 'feat/index-only-drive' into feat/index-only-transitions
QuantumExplorer 3e77942
refactor(dpp): default index terminals at parse time, not by rebuild
QuantumExplorer d680ce3
Merge branch 'feat/index-only-drive' into feat/index-only-transitions
QuantumExplorer 39a21bc
style(dpp): keep platform_version last in the core parse signature
QuantumExplorer 1362499
Merge branch 'feat/index-only-drive' into feat/index-only-transitions
QuantumExplorer 52608c0
refactor(drive): move index_only_row_commitment into its own module
QuantumExplorer 1676c4f
Merge branch 'feat/index-only-drive' into feat/index-only-transitions
QuantumExplorer d566dfb
fix(drive-abci): validate indexOnly delete values and bill entry probes
QuantumExplorer edade25
Merge remote-tracking branch 'origin/v4.2-dev' into feat/index-only-t…
QuantumExplorer c73007c
docs(drive): align indexOnly test comments and naming with review
QuantumExplorer e1db8ed
test(drive-abci): pin the V0-on-indexOnly refusal to its structure-ga…
QuantumExplorer 9431f84
style: cargo fmt
QuantumExplorer 6f3d0ce
fix(dpp): key the V1 delete's $createdAt ride-along on the doctype re…
QuantumExplorer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...cument/batch_transition/batched_transition/document_delete_transition/v1/from_document.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| use crate::data_contract::document_type::accessors::DocumentTypeV0Getters; | ||
| use crate::data_contract::document_type::DocumentTypeRef; | ||
| use crate::document::property_names::CREATED_AT; | ||
| use crate::document::{Document, DocumentV0Getters}; | ||
| use crate::prelude::IdentityNonce; | ||
| use crate::state_transition::batch_transition::batched_transition::document_delete_transition::DocumentDeleteTransitionV1; | ||
| use crate::state_transition::batch_transition::document_base_transition::DocumentBaseTransition; | ||
| use crate::tokens::token_payment_info::TokenPaymentInfo; | ||
| use crate::ProtocolError; | ||
| use platform_value::Value; | ||
| use platform_version::version::{FeatureVersion, PlatformVersion}; | ||
|
|
||
| impl DocumentDeleteTransitionV1 { | ||
| pub(crate) fn from_document( | ||
| document: Document, | ||
| document_type: DocumentTypeRef, | ||
| token_payment_info: Option<TokenPaymentInfo>, | ||
| identity_contract_nonce: IdentityNonce, | ||
| platform_version: &PlatformVersion, | ||
| base_feature_version: Option<FeatureVersion>, | ||
| ) -> Result<Self, ProtocolError> { | ||
| Ok(DocumentDeleteTransitionV1 { | ||
| base: DocumentBaseTransition::from_document( | ||
| &document, | ||
| document_type, | ||
| token_payment_info, | ||
| identity_contract_nonce, | ||
| platform_version, | ||
| base_feature_version, | ||
| )?, | ||
| // The values ARE the document on an indexOnly type — the | ||
| // delete carries them so every index entry can be recomputed | ||
| // without a primary-storage fetch. `$createdAt` rides along | ||
| // under its system key exactly when the doctype requires it | ||
| // (an indexed `$createdAt` forces the requirement, and it | ||
| // feeds the row commitment) — keyed on the TYPE, not on | ||
| // whatever the local `Document` object happens to carry, so | ||
| // construction always emits the payload shape the structure | ||
| // validation accepts. | ||
| data: { | ||
| let mut data = document.properties().clone(); | ||
| if document_type.required_fields().contains(CREATED_AT) { | ||
| let created_at = document.created_at().ok_or_else(|| { | ||
| ProtocolError::Generic(format!( | ||
| "an indexOnly document of type {} requires $createdAt, but the \ | ||
| document being deleted does not carry one", | ||
| document_type.name() | ||
| )) | ||
| })?; | ||
| data.insert(CREATED_AT.to_string(), Value::U64(created_at)); | ||
| } | ||
| data | ||
| }, | ||
| }) | ||
| } | ||
| } |
83 changes: 83 additions & 0 deletions
83
...sitions/document/batch_transition/batched_transition/document_delete_transition/v1/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| mod from_document; | ||
| pub mod v1_methods; | ||
|
|
||
| use crate::state_transition::batch_transition::document_base_transition::DocumentBaseTransition; | ||
| use std::collections::BTreeMap; | ||
|
|
||
| use bincode::{Decode, Encode}; | ||
| use derive_more::Display; | ||
| use platform_value::Value; | ||
|
|
||
| #[cfg(feature = "json-conversion")] | ||
| use crate::serialization::json_safe_fields; | ||
| #[cfg(feature = "serde-conversion")] | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| pub use super::super::document_base_transition::IDENTIFIER_FIELDS; | ||
|
|
||
| /// The **indexOnly** delete: carries the document's full property-value | ||
| /// tuple alongside the base. | ||
| /// | ||
| /// An indexOnly document has no primary-storage row, so a delete cannot | ||
| /// fetch anything by id — the values in `data` (plus the signer as owner) | ||
| /// are what every index entry is recomputed from, the exact mirror of what | ||
| /// the create wrote. V0 (base only) stays the delete for stored document | ||
| /// types; the ABCI structure gates pair each variant with its storage mode. | ||
| #[cfg_attr(feature = "json-conversion", json_safe_fields)] | ||
| // `Deserialize` is implemented manually below — same reason as | ||
| // `DocumentCreateTransitionV0`: two `#[serde(flatten)]` fields, one of | ||
| // which is a catchall map that would otherwise swallow the base's keys. | ||
| #[derive(Debug, Clone, Default, Encode, Decode, PartialEq, Display)] | ||
| #[cfg_attr( | ||
| feature = "serde-conversion", | ||
| derive(Serialize), | ||
| serde(rename_all = "camelCase") | ||
| )] | ||
| #[display("Base: {}, Data: {:?}", "base", "data")] | ||
| pub struct DocumentDeleteTransitionV1 { | ||
| /// Document Base Transition | ||
| #[cfg_attr(feature = "serde-conversion", serde(flatten))] | ||
| pub base: DocumentBaseTransition, | ||
|
|
||
| /// The property values of the indexOnly document being deleted. | ||
| #[cfg_attr(feature = "serde-conversion", serde(flatten))] | ||
| pub data: BTreeMap<String, Value>, | ||
| } | ||
|
|
||
| // Manual `Deserialize`: peel the base's known keys off the flat object, | ||
| // reconstruct the base from them, and route everything left to `data`. | ||
| // See the WARNING on `DocumentCreateTransitionV0`'s impl — a new base | ||
| // field must be added to `BASE_FIELD_NAMES` here too. | ||
| #[cfg(feature = "serde-conversion")] | ||
| impl<'de> Deserialize<'de> for DocumentDeleteTransitionV1 { | ||
| fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
| where | ||
| D: serde::Deserializer<'de>, | ||
| { | ||
| use serde::de::Error; | ||
|
|
||
| // Tag + every serde-renamed field of `DocumentBaseTransitionV0` / | ||
| // `DocumentBaseTransitionV1`. Keep in sync with the base structs. | ||
| const BASE_FIELD_NAMES: &[&str] = &[ | ||
| "$baseFormatVersion", | ||
| "$id", | ||
| "$identityContractNonce", | ||
| "$type", | ||
| "$dataContractId", | ||
| "$tokenPaymentInfo", | ||
| ]; | ||
|
|
||
| let mut map: BTreeMap<String, Value> = BTreeMap::deserialize(deserializer)?; | ||
|
|
||
| let mut base_pairs: Vec<(Value, Value)> = Vec::with_capacity(BASE_FIELD_NAMES.len()); | ||
| for key in BASE_FIELD_NAMES { | ||
| if let Some(value) = map.remove(*key) { | ||
| base_pairs.push((Value::Text((*key).to_string()), value)); | ||
| } | ||
| } | ||
| let base = platform_value::from_value::<DocumentBaseTransition>(Value::Map(base_pairs)) | ||
| .map_err(D::Error::custom)?; | ||
|
|
||
| Ok(DocumentDeleteTransitionV1 { base, data: map }) | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
.../document/batch_transition/batched_transition/document_delete_transition/v1/v1_methods.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| use crate::state_transition::batch_transition::batched_transition::document_delete_transition::DocumentDeleteTransitionV1; | ||
| use crate::state_transition::batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors; | ||
| use crate::state_transition::batch_transition::document_base_transition::DocumentBaseTransition; | ||
|
|
||
| impl DocumentBaseTransitionAccessors for DocumentDeleteTransitionV1 { | ||
| fn base(&self) -> &DocumentBaseTransition { | ||
| &self.base | ||
| } | ||
|
|
||
| fn base_mut(&mut self) -> &mut DocumentBaseTransition { | ||
| &mut self.base | ||
| } | ||
|
|
||
| fn set_base(&mut self, base: DocumentBaseTransition) { | ||
| self.base = base | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...ons/document/batch_transition/batched_transition/document_delete_transition/v1_methods.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| use crate::state_transition::batch_transition::batched_transition::DocumentDeleteTransition; | ||
| use platform_value::Value; | ||
| use std::collections::BTreeMap; | ||
|
|
||
| /// V1 (indexOnly) accessors on the delete transition enum. V0 arms return | ||
| /// `None` — a stored-document delete carries no values, same convention as | ||
| /// the base transition's `V1Methods`. | ||
| pub trait DocumentDeleteTransitionV1Methods { | ||
| /// The property values of the indexOnly document being deleted, or | ||
| /// `None` on a V0 (stored-document) delete. | ||
| fn data(&self) -> Option<&BTreeMap<String, Value>>; | ||
| } | ||
|
|
||
| impl DocumentDeleteTransitionV1Methods for DocumentDeleteTransition { | ||
| fn data(&self) -> Option<&BTreeMap<String, Value>> { | ||
| match self { | ||
| DocumentDeleteTransition::V0(_) => None, | ||
| DocumentDeleteTransition::V1(v1) => Some(&v1.data), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: The V1 manual deserializer has no V1 round-trip coverage
This hand-written deserializer relies on an exhaustively maintained list of flattened base keys; an omitted current or future base key is silently routed into document data. The delete JSON/value fixtures and umbrella tests construct only
DocumentDeleteTransition::V0, while the ABCI tests exercise platform binary serialization rather than this serde implementation. Add V1 JSON and platform-value round-trip fixtures containing non-default V1 base fields, ordinary document properties, and$createdAt, and assert the complete flattened wire shape and recovered value.source: ['codex']