Skip to content
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

feat!: store/fetch reduced platform state in drive #2457

Open
wants to merge 1 commit into
base: v2.0-dev
Choose a base branch
from
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
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
40 changes: 40 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,40 @@
use crate::reduced_platform_state::v0::ReducedPlatformStateForSavingV0;
use crate::serialization::{PlatformSerializable, ReducedPlatformDeserializable};
use crate::ProtocolError;
use bincode::{config, Decode, Encode};
use derive_more::From;
use platform_version::version::PlatformVersion;
use platform_version::TryIntoPlatformVersioned;
use serde::{Deserialize, Serialize};

pub mod v0;

/// Reduced Platform State For Saving
#[derive(Clone, Debug, Encode, Decode)]
pub enum ReducedPlatformStateForSaving {
V0(ReducedPlatformStateForSavingV0),
}

impl ReducedPlatformDeserializable for ReducedPlatformStateForSaving {
type Error = ();

fn versioned_deserialize(
data: &[u8],
platform_version: &PlatformVersion,
) -> 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)
}
}
25 changes: 25 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,25 @@
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
Member

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?

/// Information about the genesis block
pub genesis_block_info: Option<BlockInfo>,
Copy link
Member

Choose a reason for hiding this comment

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

We set it to None every block (not sure why) so I guess you don't need it then

/// 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,
}
15 changes: 15 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,21 @@ pub trait PlatformSerializable {
}
}

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

pub trait ReducedPlatformDeserializable {
type Error;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you define the associated type and don't use it? Why do you need these traits in the first place?

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