Skip to content
Closed
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
1 change: 1 addition & 0 deletions packages/rs-dpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub mod voting;
pub mod core_types;

pub mod group;
pub mod reduced_platform_state;
pub mod withdrawal;

pub use async_trait;
Expand Down
39 changes: 39 additions & 0 deletions packages/rs-dpp/src/reduced_platform_state/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::reduced_platform_state::v0::ReducedPlatformStateForSavingV0;
use crate::serialization::{PlatformSerializable, ReducedPlatformDeserializable};

Check warning on line 2 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused import: `PlatformSerializable`

warning: unused import: `PlatformSerializable` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:2:28 | 2 | use crate::serialization::{PlatformSerializable, ReducedPlatformDeserializable}; | ^^^^^^^^^^^^^^^^^^^^

Check warning on line 2 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused import: `PlatformSerializable`

warning: unused import: `PlatformSerializable` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:2:28 | 2 | use crate::serialization::{PlatformSerializable, ReducedPlatformDeserializable}; | ^^^^^^^^^^^^^^^^^^^^

Check warning on line 2 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused import: `PlatformSerializable`

warning: unused import: `PlatformSerializable` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:2:28 | 2 | use crate::serialization::{PlatformSerializable, ReducedPlatformDeserializable}; | ^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 2 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused import: `PlatformSerializable`

warning: unused import: `PlatformSerializable` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:2:28 | 2 | use crate::serialization::{PlatformSerializable, ReducedPlatformDeserializable}; | ^^^^^^^^^^^^^^^^^^^^
use crate::ProtocolError;
use bincode::{config, Decode, Encode};
use derive_more::From;

Check warning on line 5 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused import: `derive_more::From`

warning: unused import: `derive_more::From` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:5:5 | 5 | use derive_more::From; | ^^^^^^^^^^^^^^^^^

Check warning on line 5 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused import: `derive_more::From`

warning: unused import: `derive_more::From` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:5:5 | 5 | use derive_more::From; | ^^^^^^^^^^^^^^^^^

Check warning on line 5 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused import: `derive_more::From`

warning: unused import: `derive_more::From` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:5:5 | 5 | use derive_more::From; | ^^^^^^^^^^^^^^^^^

Check warning on line 5 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused import: `derive_more::From`

warning: unused import: `derive_more::From` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:5:5 | 5 | use derive_more::From; | ^^^^^^^^^^^^^^^^^
use platform_version::version::PlatformVersion;
use platform_version::TryIntoPlatformVersioned;

Check warning on line 7 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused import: `platform_version::TryIntoPlatformVersioned`

warning: unused import: `platform_version::TryIntoPlatformVersioned` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:7:5 | 7 | use platform_version::TryIntoPlatformVersioned; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check warning on line 7 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused import: `platform_version::TryIntoPlatformVersioned`

warning: unused import: `platform_version::TryIntoPlatformVersioned` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:7:5 | 7 | use platform_version::TryIntoPlatformVersioned; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check warning on line 7 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused import: `platform_version::TryIntoPlatformVersioned`

warning: unused import: `platform_version::TryIntoPlatformVersioned` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:7:5 | 7 | use platform_version::TryIntoPlatformVersioned; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check warning on line 7 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused import: `platform_version::TryIntoPlatformVersioned`

warning: unused import: `platform_version::TryIntoPlatformVersioned` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:7:5 | 7 | use platform_version::TryIntoPlatformVersioned; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
use serde::{Deserialize, Serialize};

Check warning on line 8 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused imports: `Deserialize` and `Serialize`

warning: unused imports: `Deserialize` and `Serialize` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:8:13 | 8 | use serde::{Deserialize, Serialize}; | ^^^^^^^^^^^ ^^^^^^^^^

Check warning on line 8 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused imports: `Deserialize` and `Serialize`

warning: unused imports: `Deserialize` and `Serialize` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:8:13 | 8 | use serde::{Deserialize, Serialize}; | ^^^^^^^^^^^ ^^^^^^^^^

Check warning on line 8 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused imports: `Deserialize` and `Serialize`

warning: unused imports: `Deserialize` and `Serialize` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:8:13 | 8 | use serde::{Deserialize, Serialize}; | ^^^^^^^^^^^ ^^^^^^^^^

Check warning on line 8 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused imports: `Deserialize` and `Serialize`

warning: unused imports: `Deserialize` and `Serialize` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:8:13 | 8 | use serde::{Deserialize, Serialize}; | ^^^^^^^^^^^ ^^^^^^^^^

pub mod v0;

/// Reduced Platform State For Saving
#[derive(Clone, Debug, Encode, Decode)]
pub enum ReducedPlatformStateForSaving {
V0(ReducedPlatformStateForSavingV0),
}
Comment on lines +14 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Consider implementing serialization for symmetry.

The enum only implements deserialization but might need serialization for completeness.

Consider adding serialization implementation:

impl PlatformSerializable for ReducedPlatformStateForSaving {
    fn versioned_serialize(&self, platform_version: &PlatformVersion) -> Result<Vec<u8>, ProtocolError> {
        let config = config::standard().with_big_endian().with_no_limit();
        bincode::encode_to_vec(self, config).map_err(|e| {
            ProtocolError::PlatformSerializationError(format!(
                "unable to serialize ReducedPlatformStateForSaving: {}", e
            ))
        })
    }
}

🏁 Script executed:

#!/bin/bash
# Search for PlatformSerializable implementations
rg -A 5 'impl.*PlatformSerializable' --type rust

Length of output: 8993


Implement serialization for ReducedPlatformStateForSaving

Currently, the enum in the file packages/rs-dpp/src/reduced_platform_state/mod.rs only supports deserialization. For consistency with similar types in the repository (e.g., implementations for PlatformState and CreatedDataContract), add a serialization implementation. For example:

impl PlatformSerializable for ReducedPlatformStateForSaving {
    fn versioned_serialize(&self, platform_version: &PlatformVersion) -> Result<Vec<u8>, ProtocolError> {
        let config = config::standard().with_big_endian().with_no_limit();
        bincode::encode_to_vec(self, config).map_err(|e| {
            ProtocolError::PlatformSerializationError(format!(
                "unable to serialize ReducedPlatformStateForSaving: {}", e
            ))
        })
    }
}

This change will provide symmetry between serialization and deserialization for this type.


impl ReducedPlatformDeserializable for ReducedPlatformStateForSaving {

fn versioned_deserialize(
data: &[u8],
platform_version: &PlatformVersion,

Check warning on line 22 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused variable: `platform_version`

warning: unused variable: `platform_version` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:22:9 | 22 | platform_version: &PlatformVersion, | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_platform_version`

Check warning on line 22 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused variable: `platform_version`

warning: unused variable: `platform_version` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:22:9 | 22 | platform_version: &PlatformVersion, | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_platform_version`

Check warning on line 22 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused variable: `platform_version`

warning: unused variable: `platform_version` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:22:9 | 22 | platform_version: &PlatformVersion, | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_platform_version`

Check warning on line 22 in packages/rs-dpp/src/reduced_platform_state/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused variable: `platform_version`

warning: unused variable: `platform_version` --> packages/rs-dpp/src/reduced_platform_state/mod.rs:22:9 | 22 | platform_version: &PlatformVersion, | ^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_platform_version`
) -> Result<Self, ProtocolError>
where
Self: Sized,
{
let config = config::standard().with_big_endian().with_no_limit();
let reduced_platform_state_in_save_format: ReducedPlatformStateForSaving =
bincode::decode_from_slice(data, config)
.map_err(|e| {
ProtocolError::PlatformDeserializationError(format!(
"unable to deserialize ReducedPlatformStateForSaving: {}",
e
))
})?
.0;
Ok(reduced_platform_state_in_save_format)
}
}
23 changes: 23 additions & 0 deletions packages/rs-dpp/src/reduced_platform_state/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::block::block_info::BlockInfo;

Check warning on line 1 in packages/rs-dpp/src/reduced_platform_state/v0/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (dash-sdk) / Linting

unused import: `crate::block::block_info::BlockInfo`

warning: unused import: `crate::block::block_info::BlockInfo` --> packages/rs-dpp/src/reduced_platform_state/v0/mod.rs:1:5 | 1 | use crate::block::block_info::BlockInfo; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check warning on line 1 in packages/rs-dpp/src/reduced_platform_state/v0/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive) / Linting

unused import: `crate::block::block_info::BlockInfo`

warning: unused import: `crate::block::block_info::BlockInfo` --> packages/rs-dpp/src/reduced_platform_state/v0/mod.rs:1:5 | 1 | use crate::block::block_info::BlockInfo; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check warning on line 1 in packages/rs-dpp/src/reduced_platform_state/v0/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (wasm-dpp) / Linting

unused import: `crate::block::block_info::BlockInfo`

warning: unused import: `crate::block::block_info::BlockInfo` --> packages/rs-dpp/src/reduced_platform_state/v0/mod.rs:1:5 | 1 | use crate::block::block_info::BlockInfo; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check warning on line 1 in packages/rs-dpp/src/reduced_platform_state/v0/mod.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused import: `crate::block::block_info::BlockInfo`

warning: unused import: `crate::block::block_info::BlockInfo` --> packages/rs-dpp/src/reduced_platform_state/v0/mod.rs:1:5 | 1 | use crate::block::block_info::BlockInfo; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
use crate::block::extended_block_info::ExtendedBlockInfo;
use crate::fee::default_costs::EpochIndexFeeVersionsForStorage;
use crate::util::deserializer::ProtocolVersion;
use bincode::{Decode, Encode};
use platform_value::Bytes32;

/// Reduced Platform State for Saving V0
#[derive(Clone, Debug, Encode, Decode)]
pub struct ReducedPlatformStateForSavingV0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you want to duplicate these data in both PlatfromState and ReducedPlatform state? and serialize and store it twice a block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this complicates the logic, I propose to make a separate PR for this, since it is only an optimisation/refactoring.

/// Information about the last block
pub last_committed_block_info: Option<ExtendedBlockInfo>,
/// Current Version
pub current_protocol_version_in_consensus: ProtocolVersion,
/// upcoming protocol version
pub next_epoch_protocol_version: ProtocolVersion,
/// current quorum
pub current_validator_set_quorum_hash: Bytes32,
/// next quorum
pub next_validator_set_quorum_hash: Option<Bytes32>,
/// previous Fee Versions
pub previous_fee_versions: EpochIndexFeeVersionsForStorage,
}
14 changes: 14 additions & 0 deletions packages/rs-dpp/src/serialization/serialization_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ pub trait PlatformSerializable {
}
}

pub trait ReducedPlatformSerializable {
type Error;
fn reduced_serialize_to_bytes(&self) -> Result<Vec<u8>, Self::Error>;
}

pub trait ReducedPlatformDeserializable {
fn versioned_deserialize(
data: &[u8],
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError>
where
Self: Sized;
}

pub trait PlatformSerializableWithPlatformVersion {
type Error;
/// Version based serialization is done based on the desired structure version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use dpp::version::PlatformVersion;
use drive::grovedb::Transaction;

mod v0;
mod v1;

impl<C> Platform<C>
where
Expand Down Expand Up @@ -161,6 +162,16 @@ Your software version: {}, latest supported protocol version: {}."#,
block_platform_version,
timer,
),
1 => self.run_block_proposal_v1(
block_proposal,
known_from_us,
epoch_info,
transaction,
platform_state,
block_platform_state,
block_platform_version,
timer,
),
version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
method: "run_block_proposal".to_string(),
known_versions: vec![0],
Expand Down
Loading
Loading