Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
093e8e0
feat!: persist execution state in platform state
shumkov Nov 2, 2023
817e5b1
chore: verbose debug fro G1Elements
shumkov Nov 2, 2023
8810fca
feat: store protocol version separately
shumkov Nov 10, 2023
c880879
chore: some additions
shumkov Nov 13, 2023
5377011
Merge branch 'v1.0-dev' into feat/execution_state
shumkov Jan 17, 2024
c4f1cc6
chore: use current protocol version to deserialize state
shumkov Jan 20, 2024
3482c94
chore: keep using aux data
shumkov Jan 20, 2024
168de58
fix: invalid protocol version
shumkov Jan 20, 2024
8f11682
style: fix formatting
shumkov Jan 20, 2024
68abee5
refactor: don't use grovedb directly in drive abci
shumkov Jan 22, 2024
4bb5382
chore: some fixes
shumkov Jan 22, 2024
980d371
refactor: renamings
shumkov Jan 22, 2024
24b742b
refactor: use map instead of if
shumkov Jan 22, 2024
5e6e7f7
refactor: rename methods
shumkov Jan 22, 2024
49f2b20
fix: compilation errors
shumkov Jan 22, 2024
2059f6d
revert: execution -> cache
shumkov Jan 22, 2024
474563d
chore: set initial protocol version on init chain
shumkov Jan 23, 2024
a920e33
test: fix tests
shumkov Jan 24, 2024
5a73b52
Merge branch 'v1.0-dev' into feat/execution_state
QuantumExplorer Jan 25, 2024
e625f71
chore: introduce store_current_protocol_version
shumkov Jan 25, 2024
9bc285e
docs: remove unnecessary todo
shumkov Jan 25, 2024
76e05c8
revert: platform state versioned conversion
shumkov Jan 25, 2024
ec22c04
refactor: move fetch_platform_state into Platform
shumkov Jan 25, 2024
f811f09
chore: fix review comments
shumkov Jan 26, 2024
7eefb1c
refactor: remove extra return
shumkov Jan 26, 2024
7eabbce
chore: typo
shumkov Jan 26, 2024
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
7 changes: 2 additions & 5 deletions packages/rs-drive-abci/src/abci/handler/execution_result.rs
Original file line number Diff line number Diff line change
@@ -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<ExecTxResult> for StateTransitionExecutionResult {
type Error = Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;
Comment thread
QuantumExplorer marked this conversation as resolved.

if tracing::enabled!(tracing::Level::TRACE) {
tracing::trace!(
platform_state_fingerprint = hex::encode(state_guard.fingerprint()),
Expand Down
2 changes: 2 additions & 0 deletions packages/rs-drive-abci/src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<C> Platform<C> {
/// Fetches execution state from grovedb storage
pub fn fetch_platform_state(
drive: &Drive,
transaction: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<Option<PlatformState>, Error> {
match platform_version
.drive_abci
.methods
.platform_state_storage
.fetch_platform_state
{
0 => Platform::<C>::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,
})),
}
}
}
Original file line number Diff line number Diff line change
@@ -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<C> Platform<C> {
pub(super) fn fetch_platform_state_v0(
drive: &Drive,
transaction: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<Option<PlatformState>, 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()
}
}
5 changes: 5 additions & 0 deletions packages/rs-drive-abci/src/execution/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod fetch_platform_state;
mod store_platform_state;

pub use fetch_platform_state::*;
pub use store_platform_state::*;
Original file line number Diff line number Diff line change
@@ -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<C> Platform<C> {
/// 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,
})),
}
}
}
Original file line number Diff line number Diff line change
@@ -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<C> Platform<C> {
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)
}
}
4 changes: 2 additions & 2 deletions packages/rs-drive-abci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -51,6 +52,9 @@ pub struct RequestInitChainCleanedParams {

/// Initial core chain lock height.
pub initial_core_height: Option<u32>,

/// Initial protocol version
pub initial_protocol_version: ProtocolVersion,
}

impl TryFrom<RequestInitChain> for RequestInitChainCleanedParams {
Expand All @@ -67,10 +71,20 @@ impl TryFrom<RequestInitChain> 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,
})
}
}
Loading