diff --git a/packages/rs-drive-abci/src/abci/handler/execution_result.rs b/packages/rs-drive-abci/src/abci/handler/execution_result.rs index e3b0c0ff2f6..4f7b1230178 100644 --- a/packages/rs-drive-abci/src/abci/handler/execution_result.rs +++ b/packages/rs-drive-abci/src/abci/handler/execution_result.rs @@ -1,14 +1,11 @@ use crate::abci::handler::error::consensus::AbciResponseInfoGetter; use crate::abci::handler::error::HandlerError; use crate::error::Error; -use crate::platform_types::state_transitions_processing_result::{ - StateTransitionExecutionResult, StateTransitionsProcessingResult, -}; +use crate::platform_types::state_transitions_processing_result::StateTransitionExecutionResult; use dpp::fee::SignedCredits; use dpp::version::PlatformVersion; use dpp::version::TryIntoPlatformVersioned; -use tenderdash_abci::proto::abci::tx_record::TxAction; -use tenderdash_abci::proto::abci::{ExecTxResult, TxRecord}; +use tenderdash_abci::proto::abci::ExecTxResult; impl TryIntoPlatformVersioned for StateTransitionExecutionResult { type Error = Error; diff --git a/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs b/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs index 7a585aa5622..2aa68d7f04d 100644 --- a/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs @@ -79,6 +79,14 @@ where state_guard.set_genesis_block_info(Some(genesis_block_info)); + state_guard.set_current_protocol_version_in_consensus(request.initial_protocol_version); + + self.drive.store_current_protocol_version( + request.initial_protocol_version, + Some(transaction), + &platform_version.drive, + )?; + if tracing::enabled!(tracing::Level::TRACE) { tracing::trace!( platform_state_fingerprint = hex::encode(state_guard.fingerprint()), diff --git a/packages/rs-drive-abci/src/execution/mod.rs b/packages/rs-drive-abci/src/execution/mod.rs index 4352caa5718..0e4b73c3f00 100644 --- a/packages/rs-drive-abci/src/execution/mod.rs +++ b/packages/rs-drive-abci/src/execution/mod.rs @@ -4,6 +4,8 @@ mod check_tx; pub mod engine; /// platform execution events pub(in crate::execution) mod platform_events; +/// Storage implementation for the execution state +pub mod storage; /// Types needed in execution pub mod types; /// Validation module diff --git a/packages/rs-drive-abci/src/execution/platform_events/block_end/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/block_end/mod.rs index ee3ad883d94..f881cea1dd8 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/block_end/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/block_end/mod.rs @@ -1,5 +1,3 @@ -/// Storage of the ephemeral state -pub(in crate::execution) mod store_ephemeral_state; /// Updating the state cache happens as the final part of block finalization pub(in crate::execution) mod update_state_cache; /// Validator set update diff --git a/packages/rs-drive-abci/src/execution/platform_events/block_end/store_ephemeral_state/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/block_end/store_ephemeral_state/mod.rs deleted file mode 100644 index bef276301da..00000000000 --- a/packages/rs-drive-abci/src/execution/platform_events/block_end/store_ephemeral_state/mod.rs +++ /dev/null @@ -1,53 +0,0 @@ -mod v0; - -use crate::error::execution::ExecutionError; -use crate::error::Error; -use crate::platform_types::platform::Platform; -use crate::platform_types::platform_state::PlatformState; -use crate::rpc::core::CoreRPCLike; - -use dpp::version::PlatformVersion; - -use drive::grovedb::Transaction; - -impl Platform -where - C: CoreRPCLike, -{ - /// Stores ephemeral state data, including the block information and quorum hash in GroveDB. - /// - /// This function is a version handler that directs to specific version implementations - /// of the store_ephemeral_state function. - /// - /// # Arguments - /// - /// * `platform_state` - A `PlatformState` reference. - /// * `transaction` - A `Transaction` reference. - /// * `platform_version` - A `PlatformVersion` reference that dictates which version of - /// the method to call. - /// - /// # Returns - /// - /// * `Result<(), Error>` - Returns an empty `Result` if the data is successfully stored, otherwise returns an `Error`. - /// - pub fn store_ephemeral_state( - &self, - platform_state: &PlatformState, - transaction: &Transaction, - platform_version: &PlatformVersion, - ) -> Result<(), Error> { - match platform_version - .drive_abci - .methods - .block_end - .store_ephemeral_state - { - 0 => self.store_ephemeral_state_v0(platform_state, transaction), - version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { - method: "store_ephemeral_state".to_string(), - known_versions: vec![0], - received: version, - })), - } - } -} diff --git a/packages/rs-drive-abci/src/execution/platform_events/block_end/store_ephemeral_state/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/block_end/store_ephemeral_state/v0/mod.rs deleted file mode 100644 index 016b67d2072..00000000000 --- a/packages/rs-drive-abci/src/execution/platform_events/block_end/store_ephemeral_state/v0/mod.rs +++ /dev/null @@ -1,51 +0,0 @@ -use crate::error::Error; -use crate::platform_types::platform::Platform; -use crate::rpc::core::CoreRPCLike; - -use crate::platform_types::platform_state::PlatformState; -use dpp::serialization::PlatformSerializable; - -use drive::error::Error::GroveDB; -use drive::grovedb::Transaction; - -impl Platform -where - C: CoreRPCLike, -{ - /// Stores ephemeral state data, including the block information and quorum hash in GroveDB. - /// - /// This function should be removed from the current location. - /// - /// # Arguments - /// - /// * `platform_state` - A `PlatformState` reference. - /// * `transaction` - A `Transaction` reference. - /// - /// # Returns - /// - /// * `Result<(), Error>` - Returns an empty `Result` if the data is successfully stored, otherwise returns an `Error`. - /// - pub(super) fn store_ephemeral_state_v0( - &self, - platform_state: &PlatformState, - transaction: &Transaction, - ) -> Result<(), Error> { - // we need to serialize the platform state - let serialized_platform_state = platform_state.serialize_to_bytes()?; - - // next we need to store this data in grovedb - //todo:: maybe this should be in actual state - self.drive - .grove - .put_aux( - b"saved_state", - &serialized_platform_state, - None, - Some(transaction), - ) - .unwrap() - .map_err(|e| Error::Drive(GroveDB(e)))?; - - Ok(()) - } -} diff --git a/packages/rs-drive-abci/src/execution/platform_events/block_end/update_state_cache/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/block_end/update_state_cache/v0/mod.rs index 5803180c654..115f360179d 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/block_end/update_state_cache/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/block_end/update_state_cache/v0/mod.rs @@ -61,10 +61,12 @@ where state_cache.set_genesis_block_info(None); //todo: verify this with an update - PlatformVersion::set_current(PlatformVersion::get(platform_version.protocol_version)?); + let version = PlatformVersion::get(platform_version.protocol_version)?; - // Persist ephemeral data - self.store_ephemeral_state(&state_cache, transaction, platform_version)?; + PlatformVersion::set_current(version); + + // Persist state cache + self.store_platform_state(&state_cache, Some(transaction), platform_version)?; Ok(()) } diff --git a/packages/rs-drive-abci/src/execution/storage/fetch_platform_state/mod.rs b/packages/rs-drive-abci/src/execution/storage/fetch_platform_state/mod.rs new file mode 100644 index 00000000000..f2537eca34f --- /dev/null +++ b/packages/rs-drive-abci/src/execution/storage/fetch_platform_state/mod.rs @@ -0,0 +1,32 @@ +use crate::error::execution::ExecutionError; +use crate::error::Error; +use crate::platform_types::platform::Platform; +use crate::platform_types::platform_state::PlatformState; +use dpp::version::PlatformVersion; +use drive::drive::Drive; +use drive::query::TransactionArg; + +mod v0; + +impl Platform { + /// Fetches execution state from grovedb storage + pub fn fetch_platform_state( + drive: &Drive, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result, Error> { + match platform_version + .drive_abci + .methods + .platform_state_storage + .fetch_platform_state + { + 0 => Platform::::fetch_platform_state_v0(drive, transaction, platform_version), + version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { + method: "fetch_platform_state".to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive-abci/src/execution/storage/fetch_platform_state/v0/mod.rs b/packages/rs-drive-abci/src/execution/storage/fetch_platform_state/v0/mod.rs new file mode 100644 index 00000000000..25960bf5b39 --- /dev/null +++ b/packages/rs-drive-abci/src/execution/storage/fetch_platform_state/v0/mod.rs @@ -0,0 +1,24 @@ +use crate::error::Error; +use crate::platform_types::platform::Platform; +use crate::platform_types::platform_state::PlatformState; +use dpp::serialization::PlatformDeserializableFromVersionedStructure; +use dpp::version::PlatformVersion; +use drive::drive::Drive; +use drive::query::TransactionArg; + +impl Platform { + pub(super) fn fetch_platform_state_v0( + drive: &Drive, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result, Error> { + drive + .fetch_platform_state_bytes(transaction, platform_version) + .map_err(Error::Drive)? + .map(|bytes| { + PlatformState::versioned_deserialize(&bytes, platform_version) + .map_err(Error::Protocol) + }) + .transpose() + } +} diff --git a/packages/rs-drive-abci/src/execution/storage/mod.rs b/packages/rs-drive-abci/src/execution/storage/mod.rs new file mode 100644 index 00000000000..c45853e2599 --- /dev/null +++ b/packages/rs-drive-abci/src/execution/storage/mod.rs @@ -0,0 +1,5 @@ +mod fetch_platform_state; +mod store_platform_state; + +pub use fetch_platform_state::*; +pub use store_platform_state::*; diff --git a/packages/rs-drive-abci/src/execution/storage/store_platform_state/mod.rs b/packages/rs-drive-abci/src/execution/storage/store_platform_state/mod.rs new file mode 100644 index 00000000000..203b81d2019 --- /dev/null +++ b/packages/rs-drive-abci/src/execution/storage/store_platform_state/mod.rs @@ -0,0 +1,32 @@ +mod v0; + +use crate::error::execution::ExecutionError; +use crate::error::Error; +use crate::platform_types::platform::Platform; +use crate::platform_types::platform_state::PlatformState; +use dpp::version::PlatformVersion; +use drive::query::TransactionArg; + +impl Platform { + /// Store the execution state in grovedb storage + pub fn store_platform_state( + &self, + state: &PlatformState, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result<(), Error> { + match platform_version + .drive_abci + .methods + .platform_state_storage + .store_platform_state + { + 0 => self.store_platform_state_v0(state, transaction, platform_version), + version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { + method: "store_platform_state".to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive-abci/src/execution/storage/store_platform_state/v0/mod.rs b/packages/rs-drive-abci/src/execution/storage/store_platform_state/v0/mod.rs new file mode 100644 index 00000000000..b41100eb477 --- /dev/null +++ b/packages/rs-drive-abci/src/execution/storage/store_platform_state/v0/mod.rs @@ -0,0 +1,19 @@ +use crate::error::Error; +use crate::platform_types::platform::Platform; +use crate::platform_types::platform_state::PlatformState; +use dpp::serialization::PlatformSerializable; +use dpp::version::PlatformVersion; +use drive::query::TransactionArg; + +impl Platform { + pub(super) fn store_platform_state_v0( + &self, + state: &PlatformState, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result<(), Error> { + self.drive + .store_platform_state_bytes(&state.serialize_to_bytes()?, transaction, platform_version) + .map_err(Error::Drive) + } +} diff --git a/packages/rs-drive-abci/src/main.rs b/packages/rs-drive-abci/src/main.rs index 53876c3f33e..dec4bc0a6e5 100644 --- a/packages/rs-drive-abci/src/main.rs +++ b/packages/rs-drive-abci/src/main.rs @@ -372,9 +372,9 @@ mod test { let path = tempdir.join("db"); fs::create_dir(&path).expect("create db dir"); - let platform_version = PlatformVersion::latest(); + let drive = Drive::open(&path, None).expect("open drive"); - let drive = Drive::open(&path, None, platform_version).expect("open drive"); + let platform_version = PlatformVersion::latest(); drive .create_initial_state_structure(None, platform_version) diff --git a/packages/rs-drive-abci/src/platform_types/cleaned_abci_messages/request_init_chain_cleaned_params/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/cleaned_abci_messages/request_init_chain_cleaned_params/v0/mod.rs index 6f6c0a53396..b82e36261d5 100644 --- a/packages/rs-drive-abci/src/platform_types/cleaned_abci_messages/request_init_chain_cleaned_params/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/cleaned_abci_messages/request_init_chain_cleaned_params/v0/mod.rs @@ -34,6 +34,7 @@ //! use crate::abci::AbciError; +use dpp::util::deserializer::ProtocolVersion; use drive::dpp::identity::TimestampMillis; use serde::{Deserialize, Serialize}; use tenderdash_abci::proto::abci::RequestInitChain; @@ -51,6 +52,9 @@ pub struct RequestInitChainCleanedParams { /// Initial core chain lock height. pub initial_core_height: Option, + + /// Initial protocol version + pub initial_protocol_version: ProtocolVersion, } impl TryFrom for RequestInitChainCleanedParams { @@ -67,10 +71,20 @@ impl TryFrom for RequestInitChainCleanedParams { h => Some(h), }; + let consensus_params = request.consensus_params.ok_or(AbciError::BadRequest( + "consensus params are required in init chain".to_string(), + ))?; + + let tenderdash_abci::proto::types::VersionParams { app_version } = + consensus_params.version.ok_or(AbciError::BadRequest( + "consensus params version is required in init chain".to_string(), + ))?; + Ok(Self { genesis_time, initial_height: request.initial_height as u64, initial_core_height, + initial_protocol_version: app_version as ProtocolVersion, }) } } diff --git a/packages/rs-drive-abci/src/platform_types/platform/mod.rs b/packages/rs-drive-abci/src/platform_types/platform/mod.rs index c1519be9226..619c02bd0ec 100644 --- a/packages/rs-drive-abci/src/platform_types/platform/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform/mod.rs @@ -18,9 +18,7 @@ use crate::execution::types::block_execution_context::BlockExecutionContext; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; use dpp::block::block_info::BlockInfo; -use dpp::serialization::PlatformDeserializable; use dpp::version::{PlatformVersion, PlatformVersionCurrentVersion}; -use drive::error::Error::GroveDB; use serde_json::json; /// Platform is not versioned as it holds the main logic, we could not switch from one structure @@ -93,8 +91,8 @@ impl<'a, C> From<&PlatformRef<'a, C>> for PlatformStateRef<'a> { } } -impl std::fmt::Debug for Platform { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl Debug for Platform { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.debug_struct("Platform").finish() } } @@ -144,27 +142,24 @@ impl Platform { Self::open_with_client(path, config, core_rpc_mock) } - /// Recreate the state from the backing store - pub fn recreate_state(&self, _platform_version: &PlatformVersion) -> Result { - let Some(serialized_platform_state) = self - .drive - .grove - .get_aux(b"saved_state", None) - .unwrap() - .map_err(|e| Error::Drive(GroveDB(e)))? + /// Fetch and reload the state from the backing store + pub fn reload_state_from_storage( + &self, + platform_version: &PlatformVersion, + ) -> Result { + let Some(persisted_state) = + Platform::::fetch_platform_state(&self.drive, None, platform_version)? else { return Ok(false); }; - let recreated_state = - PlatformState::deserialize_from_bytes_no_limit(&serialized_platform_state)?; - PlatformVersion::set_current(PlatformVersion::get( - recreated_state.current_protocol_version_in_consensus(), + persisted_state.current_protocol_version_in_consensus(), )?); let mut state_cache = self.state.write().unwrap(); - *state_cache = recreated_state; + *state_cache = persisted_state; + Ok(true) } } @@ -181,35 +176,34 @@ impl Platform { { let config = config.unwrap_or_default(); - // TODO: Replace with version from the disk if present or latest? - let platform_version = PlatformVersion::latest(); + let drive = Drive::open(path, Some(config.drive.clone())).map_err(Error::Drive)?; - let drive = Drive::open(path, Some(config.drive.clone()), platform_version) - .map_err(Error::Drive)?; + if let Some(protocol_version) = drive.fetch_current_protocol_version(None)? { + let platform_version = PlatformVersion::get(protocol_version)?; - // TODO: factor out key so we don't duplicate - let maybe_serialized_platform_state = drive - .grove - .get_aux(b"saved_state", None) - .unwrap() - .map_err(|e| Error::Drive(GroveDB(e)))?; + let Some(execution_state) = + Platform::::fetch_platform_state(&drive, None, platform_version)? + else { + return Err(Error::Execution(ExecutionError::CorruptedCachedState( + "execution state should be stored as well as protocol version", + ))); + }; - if let Some(serialized_platform_state) = maybe_serialized_platform_state { - Platform::open_with_client_saved_state::

( - drive, - core_rpc, - config, - serialized_platform_state, - ) - } else { - Platform::open_with_client_no_saved_state::

( + return Platform::open_with_client_saved_state::

( drive, core_rpc, config, - PROTOCOL_VERSION, - PROTOCOL_VERSION, - ) + execution_state, + ); } + + Platform::open_with_client_no_saved_state::

( + drive, + core_rpc, + config, + PROTOCOL_VERSION, + PROTOCOL_VERSION, + ) } /// Open Platform with Drive and block execution context from saved state. @@ -217,14 +211,11 @@ impl Platform { drive: Drive, core_rpc: C, config: PlatformConfig, - serialized_platform_state: Vec, + platform_state: PlatformState, ) -> Result, Error> where C: CoreRPCLike, { - let platform_state = - PlatformState::deserialize_from_bytes_no_limit(&serialized_platform_state)?; - PlatformVersion::set_current(PlatformVersion::get( platform_state.current_protocol_version_in_consensus(), )?); diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs index d4b08b9ecb8..9e03b3f2b26 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs @@ -20,7 +20,6 @@ use dpp::util::deserializer::ProtocolVersion; use dpp::version::{PlatformVersion, TryFromPlatformVersioned, TryIntoPlatformVersioned}; use dpp::ProtocolError; -use dpp::ProtocolError::{PlatformDeserializationError, PlatformSerializationError}; use indexmap::IndexMap; use crate::error::execution::ExecutionError; @@ -59,34 +58,15 @@ impl PlatformSerializable for PlatformState { let platform_state_for_saving: PlatformStateForSaving = self.clone().try_into_platform_versioned(platform_version)?; bincode::encode_to_vec(platform_state_for_saving, config).map_err(|e| { - PlatformSerializationError(format!("unable to serialize PlatformState: {}", e)).into() + ProtocolError::PlatformSerializationError(format!( + "unable to serialize PlatformState: {}", + e + )) + .into() }) } } -// The version we should deserialize this into is determined by the actual saved state -impl PlatformDeserializable for PlatformState { - fn deserialize_from_bytes_no_limit(data: &[u8]) -> Result - where - Self: Sized, - { - let config = config::standard().with_big_endian().with_no_limit(); - let platform_state_in_save_format: PlatformStateForSaving = - bincode::decode_from_slice(data, config) - .map_err(|e| { - PlatformDeserializationError(format!( - "unable to deserialize PlatformStateForSaving: {}", - e - )) - })? - .0; - let platform_version = PlatformVersion::get( - platform_state_in_save_format.current_protocol_version_in_consensus(), - )?; - platform_state_in_save_format.try_into_platform_versioned(platform_version) - } -} - impl PlatformDeserializableFromVersionedStructure for PlatformState { fn versioned_deserialize( data: &[u8], @@ -99,13 +79,16 @@ impl PlatformDeserializableFromVersionedStructure for PlatformState { let platform_state_in_save_format: PlatformStateForSaving = bincode::decode_from_slice(data, config) .map_err(|e| { - PlatformDeserializationError(format!( + ProtocolError::PlatformDeserializationError(format!( "unable to deserialize PlatformStateForSaving: {}", e )) })? .0; - platform_state_in_save_format.try_into_platform_versioned(platform_version) + + platform_state_in_save_format + .try_into_platform_versioned(platform_version) + .map_err(|e: Error| ProtocolError::Generic(e.to_string())) } } @@ -183,7 +166,7 @@ impl TryFromPlatformVersioned for PlatformStateForSaving { } impl TryFromPlatformVersioned for PlatformState { - type Error = ProtocolError; + type Error = Error; fn try_from_platform_versioned( value: PlatformStateForSaving, @@ -193,16 +176,17 @@ impl TryFromPlatformVersioned for PlatformState { PlatformStateForSaving::V0(v0) => { match platform_version.drive_abci.structs.platform_state_structure { 0 => { - let platform_state_v0: PlatformStateV0 = v0.into(); + let platform_state_v0 = PlatformStateV0::from(v0); + Ok(platform_state_v0.into()) } - version => Err(ProtocolError::UnknownVersionMismatch { + version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { method: "PlatformState::try_from_platform_versioned(PlatformStateForSaving)" .to_string(), known_versions: vec![0], received: version, - }), + })), } } } diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs index b15dce4743d..af69a73643b 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs @@ -25,7 +25,7 @@ use std::fmt::{Debug, Formatter}; #[derive(Clone)] pub struct PlatformStateV0 { /// Information about the genesis block - pub genesis_block_info: Option, + pub genesis_block_info: Option, // TODO: we already have it in epoch 0 /// Information about the last block pub last_committed_block_info: Option, /// Current Version @@ -51,6 +51,7 @@ pub struct PlatformStateV0 { impl Debug for PlatformStateV0 { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.debug_struct("PlatformStateV0") + .field("genesis_block_info", &self.genesis_block_info) .field("last_committed_block_info", &self.last_committed_block_info) .field( "current_protocol_version_in_consensus", diff --git a/packages/rs-drive-abci/src/test/fixture/abci.rs b/packages/rs-drive-abci/src/test/fixture/abci.rs index afe4f6fb0c6..0330ac740cc 100644 --- a/packages/rs-drive-abci/src/test/fixture/abci.rs +++ b/packages/rs-drive-abci/src/test/fixture/abci.rs @@ -30,6 +30,7 @@ //! Execution Tests //! +use crate::config::PlatformConfig; use crate::platform_types::required_identity_public_key_set::v0::RequiredIdentityPublicKeysSet; use crate::platform_types::system_identity_public_keys::v0::SystemIdentityPublicKeysV0; use dpp::version::PlatformVersion; @@ -38,20 +39,26 @@ use rand::rngs::StdRng; use rand::SeedableRng; use tenderdash_abci::proto::abci::RequestInitChain; use tenderdash_abci::proto::google::protobuf::Timestamp; +use tenderdash_abci::proto::types::{ConsensusParams, VersionParams}; /// Creates static init chain request fixture -pub fn static_init_chain_request() -> RequestInitChain { +pub fn static_init_chain_request(config: &PlatformConfig) -> RequestInitChain { RequestInitChain { time: Some(Timestamp { seconds: 0, nanos: 0, }), chain_id: "strategy_tests".to_string(), - consensus_params: None, + consensus_params: Some(ConsensusParams { + version: Some(VersionParams { + app_version: config.initial_protocol_version as u64, + }), + ..Default::default() + }), validator_set: None, app_state_bytes: [0u8; 32].to_vec(), - initial_height: 0, - initial_core_height: 1, + initial_height: config.abci.genesis_height as i64, + initial_core_height: config.abci.genesis_core_height, } } diff --git a/packages/rs-drive-abci/tests/strategy_tests/execution.rs b/packages/rs-drive-abci/tests/strategy_tests/execution.rs index 313f68eb506..c51a376673f 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/execution.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/execution.rs @@ -530,7 +530,7 @@ pub(crate) fn start_chain_for_strategy( .expect("expected a quorum to be found"); // init chain - let mut init_chain_request = static_init_chain_request(); + let mut init_chain_request = static_init_chain_request(&config); init_chain_request.initial_core_height = config.abci.genesis_core_height; init_chain_request.validator_set = Some(ValidatorSetUpdate { diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index 0fd3a7efea2..3e4070df124 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -312,7 +312,7 @@ mod tests { abci_app .platform - .recreate_state(platform_version) + .reload_state_from_storage(platform_version) .expect("expected to recreate state"); let ResponseInfo { @@ -454,7 +454,7 @@ mod tests { abci_app .platform - .recreate_state(platform_version) + .reload_state_from_storage(platform_version) .expect("expected to recreate state"); let ResponseInfo { @@ -573,7 +573,7 @@ mod tests { .expect("expected to fetch balances") .expect("expected to have an identity to get balance from"); - assert_eq!(balance, 99869074420) + assert_eq!(balance, 99869044820) } #[test] @@ -1228,7 +1228,7 @@ mod tests { .unwrap() .unwrap() ), - "7185a9b987f4fe7290f048ccdb2935d92446c240b9361be46a20f956164a9378".to_string() + "31479dd805715e196773106ae8f00e1f28f8e5d4f8e3cbf21e6dd59f94643207".to_string() ) } @@ -1838,7 +1838,7 @@ mod tests { .unwrap() .unwrap() ), - "5dfc31d164388c22154e10629030edb5557620c5fcd5c87ffeff5f4e81bdb657".to_string() + "1a1b119866b5cdff20d2fa04f3d2ff8e8d7349aa4b83e7ea05adeae0cfc9cb2c".to_string() ) } @@ -2921,7 +2921,7 @@ mod tests { abci_app .platform - .recreate_state(platform_version) + .reload_state_from_storage(platform_version) .expect("expected to recreate state"); let ResponseInfo { diff --git a/packages/rs-drive/src/drive/document/delete/mod.rs b/packages/rs-drive/src/drive/document/delete/mod.rs index 01a7df4435b..a43971fef05 100644 --- a/packages/rs-drive/src/drive/document/delete/mod.rs +++ b/packages/rs-drive/src/drive/document/delete/mod.rs @@ -118,9 +118,10 @@ mod tests { #[test] fn test_add_and_remove_family_one_document_no_transaction() { let tmp_dir = TempDir::new().unwrap(); + + let drive: Drive = Drive::open(tmp_dir, None).expect("expected to open Drive successfully"); + let platform_version = PlatformVersion::latest(); - let drive: Drive = Drive::open(tmp_dir, None, platform_version) - .expect("expected to open Drive successfully"); drive .create_initial_state_structure(None, platform_version) diff --git a/packages/rs-drive/src/drive/mod.rs b/packages/rs-drive/src/drive/mod.rs index 053a051452a..d7fbda7eee8 100644 --- a/packages/rs-drive/src/drive/mod.rs +++ b/packages/rs-drive/src/drive/mod.rs @@ -93,6 +93,8 @@ mod open; #[cfg(feature = "full")] mod operations; #[cfg(feature = "full")] +mod platform_state; +#[cfg(feature = "full")] mod prove; #[cfg(feature = "full")] mod system_contracts_cache; diff --git a/packages/rs-drive/src/drive/open/mod.rs b/packages/rs-drive/src/drive/open/mod.rs index 7496a651cd7..3c5cb661924 100644 --- a/packages/rs-drive/src/drive/open/mod.rs +++ b/packages/rs-drive/src/drive/open/mod.rs @@ -24,11 +24,7 @@ impl Drive { /// /// * `Result` - On success, returns `Ok(Self)`, where `Self` is a `Drive` instance. On error, returns an `Error`. /// - pub fn open>( - path: P, - config: Option, - platform_version: &PlatformVersion, - ) -> Result { + pub fn open>(path: P, config: Option) -> Result { match GroveDb::open(path) { Ok(grove) => { let config = config.unwrap_or_default(); @@ -40,7 +36,7 @@ impl Drive { grove, config, system_contracts: SystemContracts::load_genesis_system_contracts( - platform_version.protocol_version, + 1, // TODO: Will be fixed in #1676 )?, cache: RwLock::new(DriveCache { cached_contracts: DataContractCache::new( diff --git a/packages/rs-drive/src/drive/platform_state/fetch_platform_state_bytes/mod.rs b/packages/rs-drive/src/drive/platform_state/fetch_platform_state_bytes/mod.rs new file mode 100644 index 00000000000..1f341d57eab --- /dev/null +++ b/packages/rs-drive/src/drive/platform_state/fetch_platform_state_bytes/mod.rs @@ -0,0 +1,30 @@ +use crate::drive::Drive; +use crate::error::drive::DriveError; +use crate::error::Error; +use dpp::version::PlatformVersion; +use grovedb::TransactionArg; + +mod v0; + +impl Drive { + /// Fetches execution state from grovedb storage + pub fn fetch_platform_state_bytes( + &self, + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result>, Error> { + match platform_version + .drive + .methods + .platform_state + .fetch_platform_state_bytes + { + 0 => self.fetch_platform_state_bytes_v0(transaction), + version => Err(Error::Drive(DriveError::UnknownVersionMismatch { + method: "fetch_platform_state_bytes".to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive/src/drive/platform_state/fetch_platform_state_bytes/v0/mod.rs b/packages/rs-drive/src/drive/platform_state/fetch_platform_state_bytes/v0/mod.rs new file mode 100644 index 00000000000..7a0bf1f18c2 --- /dev/null +++ b/packages/rs-drive/src/drive/platform_state/fetch_platform_state_bytes/v0/mod.rs @@ -0,0 +1,16 @@ +use crate::drive::platform_state::PLATFORM_STATE_KEY; +use crate::drive::Drive; +use crate::error::Error; +use grovedb::TransactionArg; + +impl Drive { + pub(super) fn fetch_platform_state_bytes_v0( + &self, + transaction: TransactionArg, + ) -> Result>, Error> { + self.grove + .get_aux(PLATFORM_STATE_KEY, transaction) + .unwrap() + .map_err(Error::GroveDB) + } +} diff --git a/packages/rs-drive/src/drive/platform_state/mod.rs b/packages/rs-drive/src/drive/platform_state/mod.rs new file mode 100644 index 00000000000..eb34a17d339 --- /dev/null +++ b/packages/rs-drive/src/drive/platform_state/mod.rs @@ -0,0 +1,7 @@ +mod fetch_platform_state_bytes; +mod store_platform_state_bytes; + +pub use fetch_platform_state_bytes::*; +pub use store_platform_state_bytes::*; + +const PLATFORM_STATE_KEY: &[u8; 11] = b"saved_state"; diff --git a/packages/rs-drive/src/drive/platform_state/store_platform_state_bytes/mod.rs b/packages/rs-drive/src/drive/platform_state/store_platform_state_bytes/mod.rs new file mode 100644 index 00000000000..4b5bb4be29c --- /dev/null +++ b/packages/rs-drive/src/drive/platform_state/store_platform_state_bytes/mod.rs @@ -0,0 +1,31 @@ +mod v0; + +use crate::drive::Drive; +use crate::error::drive::DriveError; +use crate::error::Error; +use dpp::version::PlatformVersion; +use grovedb::TransactionArg; + +impl Drive { + /// Store the execution state in grovedb storage + pub fn store_platform_state_bytes( + &self, + state_bytes: &[u8], + transaction: TransactionArg, + platform_version: &PlatformVersion, + ) -> Result<(), Error> { + match platform_version + .drive + .methods + .platform_state + .store_platform_state_bytes + { + 0 => self.store_platform_state_bytes_v0(state_bytes, transaction), + version => Err(Error::Drive(DriveError::UnknownVersionMismatch { + method: "store_platform_state_bytes".to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive/src/drive/platform_state/store_platform_state_bytes/v0/mod.rs b/packages/rs-drive/src/drive/platform_state/store_platform_state_bytes/v0/mod.rs new file mode 100644 index 00000000000..57401f43a61 --- /dev/null +++ b/packages/rs-drive/src/drive/platform_state/store_platform_state_bytes/v0/mod.rs @@ -0,0 +1,17 @@ +use crate::drive::platform_state::PLATFORM_STATE_KEY; +use crate::drive::Drive; +use crate::error::Error; +use grovedb::TransactionArg; + +impl Drive { + pub(super) fn store_platform_state_bytes_v0( + &self, + state_bytes: &[u8], + transaction: TransactionArg, + ) -> Result<(), Error> { + self.grove + .put_aux(PLATFORM_STATE_KEY, state_bytes, None, transaction) + .unwrap() + .map_err(Error::GroveDB) + } +} diff --git a/packages/rs-drive/src/drive/protocol_upgrade/change_to_new_version_and_clear_version_information/v0/mod.rs b/packages/rs-drive/src/drive/protocol_upgrade/change_to_new_version_and_clear_version_information/v0/mod.rs index 42fbb2a643b..fd37f923f70 100644 --- a/packages/rs-drive/src/drive/protocol_upgrade/change_to_new_version_and_clear_version_information/v0/mod.rs +++ b/packages/rs-drive/src/drive/protocol_upgrade/change_to_new_version_and_clear_version_information/v0/mod.rs @@ -27,7 +27,6 @@ impl Drive { self.set_current_protocol_version_operations( current_version, - transaction, &mut batch_operations, &platform_version.drive, )?; diff --git a/packages/rs-drive/src/drive/system/protocol_version/fetch_current_protocol_version/v0/mod.rs b/packages/rs-drive/src/drive/system/protocol_version/fetch_current_protocol_version.rs similarity index 64% rename from packages/rs-drive/src/drive/system/protocol_version/fetch_current_protocol_version/v0/mod.rs rename to packages/rs-drive/src/drive/system/protocol_version/fetch_current_protocol_version.rs index a8035d3049e..2a38de6766d 100644 --- a/packages/rs-drive/src/drive/system/protocol_version/fetch_current_protocol_version/v0/mod.rs +++ b/packages/rs-drive/src/drive/system/protocol_version/fetch_current_protocol_version.rs @@ -1,16 +1,36 @@ -use crate::drive::system::misc_path; -use crate::drive::system::misc_tree_constants::PROTOCOL_VERSION_STORAGE_KEY; use crate::drive::Drive; use crate::error::drive::DriveError; use crate::error::Error; +use crate::drive::system::misc_path; +use crate::drive::system::misc_tree_constants::PROTOCOL_VERSION_STORAGE_KEY; use dpp::util::deserializer::ProtocolVersion; use grovedb::TransactionArg; use integer_encoding::VarInt; +/// impl Drive { /// Gets the current protocol version from the backing store - pub(super) fn fetch_current_protocol_version_v0( + /// + /// !!!DON'T CHANGE!!!! + /// + /// This function should never be changed !!! since it's using + /// to get protocol version to read the state from the storage. + /// In plain English, this is the first function that we call, + /// so we don't know version yet. + /// + /// # Arguments + /// + /// * `transaction` - A `TransactionArg` object representing the transaction. + /// + /// # Returns + /// + /// * `Result, Error>` - If successful, returns an `Ok(Option)`. If an error occurs during the operation, returns an `Error`. + /// + /// # Errors + /// + /// This function will return an error if the Drive version is unknown. + pub fn fetch_current_protocol_version( &self, transaction: TransactionArg, ) -> Result, Error> { diff --git a/packages/rs-drive/src/drive/system/protocol_version/fetch_current_protocol_version/mod.rs b/packages/rs-drive/src/drive/system/protocol_version/fetch_current_protocol_version/mod.rs deleted file mode 100644 index 78e654cc382..00000000000 --- a/packages/rs-drive/src/drive/system/protocol_version/fetch_current_protocol_version/mod.rs +++ /dev/null @@ -1,44 +0,0 @@ -mod v0; - -use crate::drive::Drive; -use crate::error::drive::DriveError; -use crate::error::Error; - -use dpp::util::deserializer::ProtocolVersion; -use dpp::version::drive_versions::DriveVersion; -use grovedb::TransactionArg; - -impl Drive { - /// Gets the current protocol version from the backing store - /// - /// # Arguments - /// - /// * `transaction` - A `TransactionArg` object representing the transaction. - /// - /// # Returns - /// - /// * `Result, Error>` - If successful, returns an `Ok(Option)`. If an error occurs during the operation, returns an `Error`. - /// - /// # Errors - /// - /// This function will return an error if the Drive version is unknown. - pub fn fetch_current_protocol_version( - &self, - transaction: TransactionArg, - drive_version: &DriveVersion, - ) -> Result, Error> { - match drive_version - .methods - .platform_system - .protocol_version - .fetch_current_protocol_version - { - 0 => self.fetch_current_protocol_version_v0(transaction), - version => Err(Error::Drive(DriveError::UnknownVersionMismatch { - method: "fetch_current_protocol_version".to_string(), - known_versions: vec![0], - received: version, - })), - } - } -} diff --git a/packages/rs-drive/src/drive/system/protocol_version/mod.rs b/packages/rs-drive/src/drive/system/protocol_version/mod.rs index 2f93b44a5c0..d561094fc84 100644 --- a/packages/rs-drive/src/drive/system/protocol_version/mod.rs +++ b/packages/rs-drive/src/drive/system/protocol_version/mod.rs @@ -2,7 +2,7 @@ mod fetch_current_protocol_version; pub use fetch_current_protocol_version::*; mod fetch_next_protocol_version; pub use fetch_next_protocol_version::*; -mod set_current_protocol_version_operations; -pub use set_current_protocol_version_operations::*; +mod store_current_protocol_version; +pub use store_current_protocol_version::*; mod set_next_protocol_version_operations; pub use set_next_protocol_version_operations::*; diff --git a/packages/rs-drive/src/drive/system/protocol_version/set_current_protocol_version_operations/mod.rs b/packages/rs-drive/src/drive/system/protocol_version/set_current_protocol_version_operations/mod.rs deleted file mode 100644 index 8e271bb055d..00000000000 --- a/packages/rs-drive/src/drive/system/protocol_version/set_current_protocol_version_operations/mod.rs +++ /dev/null @@ -1,54 +0,0 @@ -mod v0; - -use crate::drive::Drive; -use crate::error::drive::DriveError; -use crate::error::Error; -use crate::fee::op::LowLevelDriveOperation; -use dpp::util::deserializer::ProtocolVersion; -use dpp::version::drive_versions::DriveVersion; -use grovedb::TransactionArg; - -impl Drive { - /// Sets the current protocol version - /// - /// # Arguments - /// - /// * `protocol_version` - A `ProtocolVersion` object representing the current protocol version. - /// * `transaction` - A `TransactionArg` object representing the transaction. - /// * `drive_operations` - A mutable reference to a vector of `LowLevelDriveOperation` objects. - /// * `drive_version` - A `DriveVersion` object representing the version of the Drive. - /// - /// # Returns - /// - /// * `Result<(), Error>` - If successful, returns an `Ok(())`. If an error occurs during the operation, returns an `Error`. - /// - /// # Errors - /// - /// This function will return an error if the version of the Drive is unknown. - pub fn set_current_protocol_version_operations( - &self, - protocol_version: ProtocolVersion, - transaction: TransactionArg, - drive_operations: &mut Vec, - drive_version: &DriveVersion, - ) -> Result<(), Error> { - match drive_version - .methods - .platform_system - .protocol_version - .set_current_protocol_version_operations - { - 0 => self.set_current_protocol_version_operations_v0( - protocol_version, - transaction, - drive_operations, - drive_version, - ), - version => Err(Error::Drive(DriveError::UnknownVersionMismatch { - method: "set_current_protocol_version_operations".to_string(), - known_versions: vec![0], - received: version, - })), - } - } -} diff --git a/packages/rs-drive/src/drive/system/protocol_version/set_current_protocol_version_operations/v0/mod.rs b/packages/rs-drive/src/drive/system/protocol_version/set_current_protocol_version_operations/v0/mod.rs deleted file mode 100644 index c91ec847d9d..00000000000 --- a/packages/rs-drive/src/drive/system/protocol_version/set_current_protocol_version_operations/v0/mod.rs +++ /dev/null @@ -1,35 +0,0 @@ -use crate::drive::grove_operations::BatchInsertApplyType; -use crate::drive::object_size_info::PathKeyElementInfo; -use crate::drive::system::misc_path; -use crate::drive::system::misc_tree_constants::PROTOCOL_VERSION_STORAGE_KEY; -use crate::drive::Drive; -use crate::error::Error; -use crate::fee::op::LowLevelDriveOperation; -use dpp::util::deserializer::ProtocolVersion; -use dpp::version::drive_versions::DriveVersion; -use grovedb::{Element, TransactionArg}; -use integer_encoding::VarInt; - -impl Drive { - /// Sets the current protocol version - pub(super) fn set_current_protocol_version_operations_v0( - &self, - protocol_version: ProtocolVersion, - transaction: TransactionArg, - drive_operations: &mut Vec, - drive_version: &DriveVersion, - ) -> Result<(), Error> { - self.batch_insert_if_changed_value( - PathKeyElementInfo::PathFixedSizeKeyRefElement(( - misc_path(), - PROTOCOL_VERSION_STORAGE_KEY, - Element::new_item(protocol_version.encode_var_vec()), - )), - BatchInsertApplyType::StatefulBatchInsert, - transaction, - drive_operations, - drive_version, - )?; - Ok(()) - } -} diff --git a/packages/rs-drive/src/drive/system/protocol_version/store_current_protocol_version.rs b/packages/rs-drive/src/drive/system/protocol_version/store_current_protocol_version.rs new file mode 100644 index 00000000000..bb954764120 --- /dev/null +++ b/packages/rs-drive/src/drive/system/protocol_version/store_current_protocol_version.rs @@ -0,0 +1,78 @@ +use crate::drive::grove_operations::BatchInsertApplyType; +use crate::drive::object_size_info::PathKeyElementInfo; +use crate::drive::system::misc_path; +use crate::drive::system::misc_tree_constants::PROTOCOL_VERSION_STORAGE_KEY; +use crate::drive::Drive; +use crate::error::Error; +use crate::fee::op::LowLevelDriveOperation; +use dpp::util::deserializer::ProtocolVersion; +use dpp::version::drive_versions::DriveVersion; +use grovedb::{Element, TransactionArg}; +use integer_encoding::VarInt; + +impl Drive { + /// Store the current protocol version in grovedb storage + /// + /// !!!DON'T CHANGE!!!! + /// This function should never be changed !!! since it must always be compatible + /// with fetch_current_protocol_version which is should never be changed. + pub fn store_current_protocol_version( + &self, + protocol_version: ProtocolVersion, + transaction: TransactionArg, + drive_version: &DriveVersion, + ) -> Result<(), Error> { + let mut batch_operations = vec![]; + + self.set_current_protocol_version_operations( + protocol_version, + &mut batch_operations, + drive_version, + )?; + + self.apply_batch_low_level_drive_operations( + None, + transaction, + batch_operations, + &mut vec![], + drive_version, + ) + } + + /// Sets the current protocol version operations to batch + /// + /// !!!DON'T CHANGE!!!! + /// This function should never be changed !!! since it must always be compatible + /// with fetch_current_protocol_version which is should never be changed. + /// + /// # Arguments + /// + /// * `protocol_version` - A `ProtocolVersion` object representing the current protocol version. + /// * `transaction` - A `TransactionArg` object representing the transaction. + /// * `drive_operations` - A mutable reference to a vector of `LowLevelDriveOperation` objects. + /// * `drive_version` - A `DriveVersion` object representing the version of the Drive. + /// + /// # Returns + /// + /// * `Result<(), Error>` - If successful, returns an `Ok(())`. If an error occurs during the operation, returns an `Error`. + /// + /// # Errors + /// + /// This function will return an error if the version of the Drive is unknown. + pub fn set_current_protocol_version_operations( + &self, + protocol_version: ProtocolVersion, + drive_operations: &mut Vec, + drive_version: &DriveVersion, + ) -> Result<(), Error> { + self.batch_insert( + PathKeyElementInfo::PathFixedSizeKeyRefElement(( + misc_path(), + PROTOCOL_VERSION_STORAGE_KEY, + Element::new_item(protocol_version.encode_var_vec()), + )), + drive_operations, + drive_version, + ) + } +} diff --git a/packages/rs-drive/src/query/mod.rs b/packages/rs-drive/src/query/mod.rs index 0023c0681fb..7217e72c101 100644 --- a/packages/rs-drive/src/query/mod.rs +++ b/packages/rs-drive/src/query/mod.rs @@ -1974,10 +1974,9 @@ mod tests { fn setup_family_contract() -> (Drive, DataContract) { let tmp_dir = TempDir::new().unwrap(); - let platform_version = PlatformVersion::latest(); + let drive: Drive = Drive::open(tmp_dir, None).expect("expected to open Drive successfully"); - let drive: Drive = Drive::open(tmp_dir, None, platform_version) - .expect("expected to open Drive successfully"); + let platform_version = PlatformVersion::latest(); drive .create_initial_state_structure(None, platform_version) diff --git a/packages/rs-drive/src/tests/helpers/setup.rs b/packages/rs-drive/src/tests/helpers/setup.rs index 15095a15f2f..a62e55de431 100644 --- a/packages/rs-drive/src/tests/helpers/setup.rs +++ b/packages/rs-drive/src/tests/helpers/setup.rs @@ -64,9 +64,8 @@ impl Default for SetupFeePoolsOptions { /// Sets up Drive using a temporary directory and the optionally given Drive configuration settings. pub fn setup_drive(drive_config: Option) -> Drive { let tmp_dir = TempDir::new().unwrap(); - let platform_version = PlatformVersion::latest(); - let drive: Drive = Drive::open(tmp_dir, drive_config, platform_version) - .expect("should open Drive successfully"); + + let drive: Drive = Drive::open(tmp_dir, drive_config).expect("should open Drive successfully"); drive } diff --git a/packages/rs-platform-version/src/version/drive_abci_versions.rs b/packages/rs-platform-version/src/version/drive_abci_versions.rs index 36c5af53083..e39f192cf83 100644 --- a/packages/rs-platform-version/src/version/drive_abci_versions.rs +++ b/packages/rs-platform-version/src/version/drive_abci_versions.rs @@ -69,6 +69,7 @@ pub struct DriveAbciMethodVersions { pub epoch: DriveAbciEpochMethodVersions, pub block_start: DriveAbciBlockStartMethodVersions, pub block_end: DriveAbciBlockEndMethodVersions, + pub platform_state_storage: DriveAbciPlatformStateStorageMethodVersions, } #[derive(Clone, Debug, Default)] @@ -78,6 +79,12 @@ pub struct DriveAbciValidationVersions { pub state_transition_to_execution_event_for_check_tx: FeatureVersion, } +#[derive(Clone, Debug, Default)] +pub struct DriveAbciPlatformStateStorageMethodVersions { + pub fetch_platform_state: FeatureVersion, + pub store_platform_state: FeatureVersion, +} + #[derive(Clone, Debug, Default)] pub struct DriveAbciDocumentsStateTransitionValidationVersions { pub structure: FeatureVersion, @@ -223,7 +230,6 @@ pub struct DriveAbciBlockStartMethodVersions { #[derive(Clone, Debug, Default)] pub struct DriveAbciBlockEndMethodVersions { - pub store_ephemeral_state: FeatureVersion, pub update_state_cache: FeatureVersion, pub update_drive_cache: FeatureVersion, pub validator_set_update: FeatureVersion, diff --git a/packages/rs-platform-version/src/version/drive_versions.rs b/packages/rs-platform-version/src/version/drive_versions.rs index eb8d6f7da77..7afa099da93 100644 --- a/packages/rs-platform-version/src/version/drive_versions.rs +++ b/packages/rs-platform-version/src/version/drive_versions.rs @@ -31,6 +31,13 @@ pub struct DriveMethodVersions { pub batch_operations: DriveBatchOperationsMethodVersion, pub prove: DriveProveMethodVersions, pub state_transitions: DriveStateTransitionMethodVersions, + pub platform_state: DrivePlatformStateMethodVersions, +} + +#[derive(Clone, Debug, Default)] +pub struct DrivePlatformStateMethodVersions { + pub fetch_platform_state_bytes: FeatureVersion, + pub store_platform_state_bytes: FeatureVersion, } #[derive(Clone, Debug, Default)] @@ -211,8 +218,6 @@ pub struct DriveBatchOperationsMethodVersion { #[derive(Clone, Debug, Default)] pub struct DriveSystemProtocolVersionMethodVersions { - pub fetch_current_protocol_version: FeatureVersion, - pub set_current_protocol_version_operations: FeatureVersion, pub fetch_next_protocol_version: FeatureVersion, pub set_next_protocol_version_operations: FeatureVersion, } diff --git a/packages/rs-platform-version/src/version/mocks/v2_test.rs b/packages/rs-platform-version/src/version/mocks/v2_test.rs index 3d9e442214f..98050279775 100644 --- a/packages/rs-platform-version/src/version/mocks/v2_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v2_test.rs @@ -18,8 +18,9 @@ use crate::version::drive_abci_versions::{ DriveAbciFeePoolOutwardsDistributionMethodVersions, DriveAbciIdentityCreditWithdrawalMethodVersions, DriveAbciInitializationMethodVersions, DriveAbciMasternodeIdentitiesUpdatesMethodVersions, DriveAbciMethodVersions, - DriveAbciProtocolUpgradeMethodVersions, DriveAbciQueryDataContractVersions, - DriveAbciQueryIdentityVersions, DriveAbciQuerySystemVersions, DriveAbciQueryVersions, + DriveAbciPlatformStateStorageMethodVersions, DriveAbciProtocolUpgradeMethodVersions, + DriveAbciQueryDataContractVersions, DriveAbciQueryIdentityVersions, + DriveAbciQuerySystemVersions, DriveAbciQueryVersions, DriveAbciStateTransitionCommonValidationVersions, DriveAbciStateTransitionProcessingMethodVersions, DriveAbciStateTransitionValidationVersion, DriveAbciStateTransitionValidationVersions, DriveAbciStructureVersions, @@ -50,13 +51,13 @@ use crate::version::drive_versions::{ DriveIdentityKeysProveMethodVersions, DriveIdentityMethodVersions, DriveIdentityProveMethodVersions, DriveIdentityUpdateMethodVersions, DriveInitializationMethodVersions, DriveMethodVersions, DriveOperationsMethodVersion, - DrivePlatformSystemMethodVersions, DriveProtocolUpgradeVersions, DriveProveMethodVersions, - DriveStateTransitionMethodVersions, DriveStateTransitionOperationMethodVersions, - DriveStructureVersion, DriveSystemEstimationCostsMethodVersions, - DriveSystemProtocolVersionMethodVersions, DriveVerifyContractMethodVersions, - DriveVerifyDocumentMethodVersions, DriveVerifyIdentityMethodVersions, - DriveVerifyMethodVersions, DriveVerifySingleDocumentMethodVersions, - DriveVerifySystemMethodVersions, DriveVersion, + DrivePlatformStateMethodVersions, DrivePlatformSystemMethodVersions, + DriveProtocolUpgradeVersions, DriveProveMethodVersions, DriveStateTransitionMethodVersions, + DriveStateTransitionOperationMethodVersions, DriveStructureVersion, + DriveSystemEstimationCostsMethodVersions, DriveSystemProtocolVersionMethodVersions, + DriveVerifyContractMethodVersions, DriveVerifyDocumentMethodVersions, + DriveVerifyIdentityMethodVersions, DriveVerifyMethodVersions, + DriveVerifySingleDocumentMethodVersions, DriveVerifySystemMethodVersions, DriveVersion, }; use crate::version::mocks::TEST_BYTES; use crate::version::protocol_version::{FeatureVersionBounds, PlatformVersion}; @@ -361,8 +362,6 @@ pub(crate) const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { }, platform_system: DrivePlatformSystemMethodVersions { protocol_version: DriveSystemProtocolVersionMethodVersions { - fetch_current_protocol_version: 0, - set_current_protocol_version_operations: 0, fetch_next_protocol_version: 0, set_next_protocol_version_operations: 0, }, @@ -391,6 +390,10 @@ pub(crate) const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { }, }, }, + platform_state: DrivePlatformStateMethodVersions { + fetch_platform_state_bytes: 0, + store_platform_state_bytes: 0, + }, }, grove_methods: DriveGroveMethodVersions { basic: DriveGroveBasicMethodVersions { @@ -531,11 +534,14 @@ pub(crate) const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { clear_drive_block_cache: 0, }, block_end: DriveAbciBlockEndMethodVersions { - store_ephemeral_state: 0, update_state_cache: 0, update_drive_cache: 0, validator_set_update: 0, }, + platform_state_storage: DriveAbciPlatformStateStorageMethodVersions { + fetch_platform_state: 0, + store_platform_state: 0, + }, }, validation_and_processing: DriveAbciValidationVersions { state_transitions: DriveAbciStateTransitionValidationVersions { diff --git a/packages/rs-platform-version/src/version/mocks/v3_test.rs b/packages/rs-platform-version/src/version/mocks/v3_test.rs index da4bde11542..2825786c603 100644 --- a/packages/rs-platform-version/src/version/mocks/v3_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v3_test.rs @@ -18,8 +18,9 @@ use crate::version::drive_abci_versions::{ DriveAbciFeePoolOutwardsDistributionMethodVersions, DriveAbciIdentityCreditWithdrawalMethodVersions, DriveAbciInitializationMethodVersions, DriveAbciMasternodeIdentitiesUpdatesMethodVersions, DriveAbciMethodVersions, - DriveAbciProtocolUpgradeMethodVersions, DriveAbciQueryDataContractVersions, - DriveAbciQueryIdentityVersions, DriveAbciQuerySystemVersions, DriveAbciQueryVersions, + DriveAbciPlatformStateStorageMethodVersions, DriveAbciProtocolUpgradeMethodVersions, + DriveAbciQueryDataContractVersions, DriveAbciQueryIdentityVersions, + DriveAbciQuerySystemVersions, DriveAbciQueryVersions, DriveAbciStateTransitionCommonValidationVersions, DriveAbciStateTransitionProcessingMethodVersions, DriveAbciStateTransitionValidationVersion, DriveAbciStateTransitionValidationVersions, DriveAbciStructureVersions, @@ -50,13 +51,13 @@ use crate::version::drive_versions::{ DriveIdentityKeysProveMethodVersions, DriveIdentityMethodVersions, DriveIdentityProveMethodVersions, DriveIdentityUpdateMethodVersions, DriveInitializationMethodVersions, DriveMethodVersions, DriveOperationsMethodVersion, - DrivePlatformSystemMethodVersions, DriveProtocolUpgradeVersions, DriveProveMethodVersions, - DriveStateTransitionMethodVersions, DriveStateTransitionOperationMethodVersions, - DriveStructureVersion, DriveSystemEstimationCostsMethodVersions, - DriveSystemProtocolVersionMethodVersions, DriveVerifyContractMethodVersions, - DriveVerifyDocumentMethodVersions, DriveVerifyIdentityMethodVersions, - DriveVerifyMethodVersions, DriveVerifySingleDocumentMethodVersions, - DriveVerifySystemMethodVersions, DriveVersion, + DrivePlatformStateMethodVersions, DrivePlatformSystemMethodVersions, + DriveProtocolUpgradeVersions, DriveProveMethodVersions, DriveStateTransitionMethodVersions, + DriveStateTransitionOperationMethodVersions, DriveStructureVersion, + DriveSystemEstimationCostsMethodVersions, DriveSystemProtocolVersionMethodVersions, + DriveVerifyContractMethodVersions, DriveVerifyDocumentMethodVersions, + DriveVerifyIdentityMethodVersions, DriveVerifyMethodVersions, + DriveVerifySingleDocumentMethodVersions, DriveVerifySystemMethodVersions, DriveVersion, }; use crate::version::mocks::TEST_BYTES; use crate::version::protocol_version::{FeatureVersionBounds, PlatformVersion}; @@ -369,8 +370,6 @@ pub(crate) const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { }, platform_system: DrivePlatformSystemMethodVersions { protocol_version: DriveSystemProtocolVersionMethodVersions { - fetch_current_protocol_version: 0, - set_current_protocol_version_operations: 0, fetch_next_protocol_version: 0, set_next_protocol_version_operations: 0, }, @@ -391,6 +390,10 @@ pub(crate) const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { convert_drive_operations_to_grove_operations: 0, apply_drive_operations: 0, }, + platform_state: DrivePlatformStateMethodVersions { + fetch_platform_state_bytes: 0, + store_platform_state_bytes: 0, + }, }, grove_methods: DriveGroveMethodVersions { basic: DriveGroveBasicMethodVersions { @@ -531,11 +534,14 @@ pub(crate) const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { clear_drive_block_cache: 0, }, block_end: DriveAbciBlockEndMethodVersions { - store_ephemeral_state: 0, update_state_cache: 0, update_drive_cache: 0, validator_set_update: 0, }, + platform_state_storage: DriveAbciPlatformStateStorageMethodVersions { + fetch_platform_state: 0, + store_platform_state: 0, + }, }, validation_and_processing: DriveAbciValidationVersions { state_transitions: DriveAbciStateTransitionValidationVersions { diff --git a/packages/rs-platform-version/src/version/v1.rs b/packages/rs-platform-version/src/version/v1.rs index 8ffb8fddb1e..057e9eb0413 100644 --- a/packages/rs-platform-version/src/version/v1.rs +++ b/packages/rs-platform-version/src/version/v1.rs @@ -18,8 +18,9 @@ use crate::version::drive_abci_versions::{ DriveAbciFeePoolOutwardsDistributionMethodVersions, DriveAbciIdentityCreditWithdrawalMethodVersions, DriveAbciInitializationMethodVersions, DriveAbciMasternodeIdentitiesUpdatesMethodVersions, DriveAbciMethodVersions, - DriveAbciProtocolUpgradeMethodVersions, DriveAbciQueryDataContractVersions, - DriveAbciQueryIdentityVersions, DriveAbciQuerySystemVersions, DriveAbciQueryVersions, + DriveAbciPlatformStateStorageMethodVersions, DriveAbciProtocolUpgradeMethodVersions, + DriveAbciQueryDataContractVersions, DriveAbciQueryIdentityVersions, + DriveAbciQuerySystemVersions, DriveAbciQueryVersions, DriveAbciStateTransitionCommonValidationVersions, DriveAbciStateTransitionProcessingMethodVersions, DriveAbciStateTransitionValidationVersion, DriveAbciStateTransitionValidationVersions, DriveAbciStructureVersions, @@ -50,13 +51,13 @@ use crate::version::drive_versions::{ DriveIdentityKeysProveMethodVersions, DriveIdentityMethodVersions, DriveIdentityProveMethodVersions, DriveIdentityUpdateMethodVersions, DriveInitializationMethodVersions, DriveMethodVersions, DriveOperationsMethodVersion, - DrivePlatformSystemMethodVersions, DriveProtocolUpgradeVersions, DriveProveMethodVersions, - DriveStateTransitionMethodVersions, DriveStateTransitionOperationMethodVersions, - DriveStructureVersion, DriveSystemEstimationCostsMethodVersions, - DriveSystemProtocolVersionMethodVersions, DriveVerifyContractMethodVersions, - DriveVerifyDocumentMethodVersions, DriveVerifyIdentityMethodVersions, - DriveVerifyMethodVersions, DriveVerifySingleDocumentMethodVersions, - DriveVerifySystemMethodVersions, DriveVersion, + DrivePlatformStateMethodVersions, DrivePlatformSystemMethodVersions, + DriveProtocolUpgradeVersions, DriveProveMethodVersions, DriveStateTransitionMethodVersions, + DriveStateTransitionOperationMethodVersions, DriveStructureVersion, + DriveSystemEstimationCostsMethodVersions, DriveSystemProtocolVersionMethodVersions, + DriveVerifyContractMethodVersions, DriveVerifyDocumentMethodVersions, + DriveVerifyIdentityMethodVersions, DriveVerifyMethodVersions, + DriveVerifySingleDocumentMethodVersions, DriveVerifySystemMethodVersions, DriveVersion, }; use crate::version::protocol_version::{FeatureVersionBounds, PlatformVersion}; use crate::version::{AbciStructureVersion, PlatformArchitectureVersion}; @@ -358,8 +359,6 @@ pub(super) const PLATFORM_V1: PlatformVersion = PlatformVersion { }, platform_system: DrivePlatformSystemMethodVersions { protocol_version: DriveSystemProtocolVersionMethodVersions { - fetch_current_protocol_version: 0, - set_current_protocol_version_operations: 0, fetch_next_protocol_version: 0, set_next_protocol_version_operations: 0, }, @@ -388,6 +387,10 @@ pub(super) const PLATFORM_V1: PlatformVersion = PlatformVersion { convert_drive_operations_to_grove_operations: 0, apply_drive_operations: 0, }, + platform_state: DrivePlatformStateMethodVersions { + fetch_platform_state_bytes: 0, + store_platform_state_bytes: 0, + }, }, grove_methods: DriveGroveMethodVersions { basic: DriveGroveBasicMethodVersions { @@ -528,11 +531,14 @@ pub(super) const PLATFORM_V1: PlatformVersion = PlatformVersion { clear_drive_block_cache: 0, }, block_end: DriveAbciBlockEndMethodVersions { - store_ephemeral_state: 0, update_state_cache: 0, update_drive_cache: 0, validator_set_update: 0, }, + platform_state_storage: DriveAbciPlatformStateStorageMethodVersions { + fetch_platform_state: 0, + store_platform_state: 0, + }, }, validation_and_processing: DriveAbciValidationVersions { state_transitions: DriveAbciStateTransitionValidationVersions {