-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: v2.0-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
} | ||
} |
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 { | ||||
/// Information about the genesis block | ||||
pub genesis_block_info: Option<BlockInfo>, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 platform/packages/rs-drive-abci/src/execution/platform_events/block_end/update_state_cache/v0/mod.rs Line 56 in 2fdd949
|
||||
/// 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, | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
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.
So you want to duplicate these data in both PlatfromState and ReducedPlatform state? and serialize and store it twice a block?