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(drive): platform version patching and state migrations #1941

Merged
merged 38 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
be2b0cc
feat(drive): platform version patching and state migrations
shumkov Jul 10, 2024
a4d0988
chore: remove duplicate dependency
shumkov Jul 10, 2024
b45a1db
refactor: unnecessary reference
shumkov Jul 10, 2024
bbad647
docs: update field documentation
shumkov Jul 10, 2024
82dbe71
refactor: fix review comments
shumkov Jul 12, 2024
4e5a790
refactor: move patches to version crate
shumkov Jul 13, 2024
3857883
refactor: rename patch function and move version setting to if condition
shumkov Jul 13, 2024
386cb65
docs: fix comment
shumkov Jul 13, 2024
90e984b
refactor: remove dbg
shumkov Jul 13, 2024
3fb9e7a
docs: reword patched_platform_version doc
shumkov Jul 13, 2024
17c7c72
Merge branch 'refs/heads/v1.0-dev' into feat/drive/version-patch-and-…
shumkov Jul 13, 2024
a8f2746
test: use default_minimal_verifications
shumkov Jul 13, 2024
fc90dac
chore: add logging to migration function
shumkov Jul 13, 2024
3c68376
modifed yaml file for AWS secrets
vivekgsharma Jul 13, 2024
b23e693
updated workflos to use AWS secrets from github secrets
vivekgsharma Jul 13, 2024
dacdf32
aws login credentials github secrets
vivekgsharma Jul 13, 2024
9e6312b
added aws account id
vivekgsharma Jul 14, 2024
a2e62b7
configre sccache env
vivekgsharma Jul 14, 2024
b644ac7
small fix
vivekgsharma Jul 14, 2024
975e57a
fix2
vivekgsharma Jul 14, 2024
eb972df
fix
vivekgsharma Jul 14, 2024
25eefa8
fix
vivekgsharma Jul 14, 2024
94bfc42
fix
vivekgsharma Jul 14, 2024
6cb211b
fix_fin
vivekgsharma Jul 14, 2024
f7ef6b3
fic
vivekgsharma Jul 14, 2024
febed5e
fix
vivekgsharma Jul 14, 2024
ffb2607
printing env varibles to see if aws creds are there during the build …
vivekgsharma Jul 15, 2024
a9621f3
ci: pass AWS creds to docker build
shumkov Jul 15, 2024
127ceae
build: remove aws debug call
shumkov Jul 15, 2024
4d7eb3e
Changed to github secrets for Rust packages workflows
vivekgsharma Jul 15, 2024
f98b441
proto fix
vivekgsharma Jul 15, 2024
c0552dc
chore: remove unused once_cell
shumkov Jul 15, 2024
26cd101
chore: kick off CI
shumkov Jul 16, 2024
cb923ac
Merge branch 'refs/heads/v1.0-dev' into feat/drive/version-patch-and-…
shumkov Jul 16, 2024
b67c6d0
revert: ci changes
shumkov Jul 16, 2024
29e5314
chore: fix code after merging v1
shumkov Jul 16, 2024
5139ca7
Merge branch 'v1.0-dev' into feat/drive/version-patch-and-migrations
shumkov Jul 16, 2024
31734aa
Merge branch 'v1.0-dev' into feat/drive/version-patch-and-migrations
QuantumExplorer Jul 16, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/rs-drive-abci/src/abci/handler/check_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::metrics::{LABEL_ABCI_RESPONSE_CODE, LABEL_CHECK_TX_MODE, LABEL_STATE_TRANSITION_NAME};
use crate::platform_types::platform::{Platform, PlatformRef};
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::rpc::core::CoreRPCLike;
use dpp::consensus::codes::ErrorWithCode;
use dpp::fee::SignedCredits;
Expand Down
1 change: 1 addition & 0 deletions packages/rs-drive-abci/src/abci/handler/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::execution::types::block_execution_context::v0::BlockExecutionContextV0Getters;
use crate::platform_types::cleaned_abci_messages::finalized_block_cleaned_request::v0::FinalizeBlockCleanedRequest;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::rpc::core::CoreRPCLike;
use std::sync::atomic::Ordering;
use tenderdash_abci::proto::abci as proto;
Expand Down
8 changes: 2 additions & 6 deletions packages/rs-drive-abci/src/abci/handler/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::platform_types::state_transitions_processing_result::StateTransitionExecutionResult;
use crate::rpc::core::CoreRPCLike;
use dpp::dashcore::hashes::Hash;
use dpp::version::PlatformVersion;
use dpp::version::TryIntoPlatformVersioned;
use tenderdash_abci::proto::abci as proto;
use tenderdash_abci::proto::abci::tx_record::TxAction;
Expand Down Expand Up @@ -117,13 +116,10 @@ where
app_hash,
state_transitions_result,
validator_set_update,
protocol_version,
platform_version,
mut block_execution_context,
} = run_result.into_data().map_err(Error::Protocol)?;

let platform_version = PlatformVersion::get(protocol_version)
.expect("must be set in run block proposal from existing protocol version");

// We need to let Tenderdash know about the transactions we should remove from execution
let valid_tx_count = state_transitions_result.valid_count();
let failed_tx_count = state_transitions_result.failed_count();
Expand Down Expand Up @@ -192,7 +188,7 @@ where
validator_set_update,
// TODO: implement consensus param updates
consensus_param_updates: None,
app_version: protocol_version as u64,
app_version: platform_version.protocol_version as u64,
};

block_execution_context.set_proposer_results(Some(response.clone()));
Expand Down
5 changes: 1 addition & 4 deletions packages/rs-drive-abci/src/abci/handler/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use crate::platform_types::block_execution_outcome;
use crate::platform_types::state_transitions_processing_result::StateTransitionExecutionResult;
use crate::rpc::core::CoreRPCLike;
use dpp::version::PlatformVersion;

Check warning on line 13 in packages/rs-drive-abci/src/abci/handler/process_proposal.rs

View workflow job for this annotation

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

unused import: `dpp::version::PlatformVersion`

warning: unused import: `dpp::version::PlatformVersion` --> packages/rs-drive-abci/src/abci/handler/process_proposal.rs:13:5 | 13 | use dpp::version::PlatformVersion; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use dpp::version::TryIntoPlatformVersioned;
use tenderdash_abci::proto::abci as proto;
use tenderdash_abci::proto::abci::tx_record::TxAction;
Expand Down Expand Up @@ -202,13 +202,10 @@
app_hash,
state_transitions_result: state_transition_results,
validator_set_update,
protocol_version,
platform_version,
block_execution_context,
} = run_result.into_data().map_err(Error::Protocol)?;

let platform_version = PlatformVersion::get(protocol_version)
.expect("must be set in run block proposer from existing platform version");

app.block_execution_context()
.write()
.unwrap()
Expand Down
1 change: 1 addition & 0 deletions packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@
check_tx_result.unique_identifiers = state_transition.unique_identifiers();

let validation_result = state_transition_to_execution_event_for_check_tx(
&platform_ref,

Check warning on line 157 in packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs

View workflow job for this annotation

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

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs:157:13 | 157 | &platform_ref, | ^^^^^^^^^^^^^ help: change this to: `platform_ref` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
state_transition,
check_tx_level,
platform_version,
)?;

// If there are any validation errors happen we return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,19 @@ where
last_committed_platform_version,
)?;

// Determine a protocol version for this block
let platform_version = if epoch_info.is_epoch_change_but_not_genesis() {
// Create a bock state from previous committed state
let mut block_platform_state = platform_state.clone();

// Determine a platform version for this block
let block_platform_version = if epoch_info.is_epoch_change_but_not_genesis()
&& platform_state.next_epoch_protocol_version()
!= platform_state.current_protocol_version_in_consensus()
{
// Switch to next proposed platform version if we are on the first block of the new epoch
// This version must be set to the state as current one during block processing
// and the next protocol version (locked in the previous epoch) is different from the
// current protocol version.
// This version will be set to the block state, and we decide on next version for next epoch
// during block processing
let next_protocol_version = platform_state.next_epoch_protocol_version();

// We should panic if this node is not supported a new protocol version
Expand All @@ -80,13 +89,31 @@ Your software version: {}, latest supported protocol version: {}."#,
);
};

// Set current protocol version to the block platform state
block_platform_state.set_current_protocol_version_in_consensus(next_protocol_version);

next_platform_version
} else {
// Stay on the last committed platform version
last_committed_platform_version
};

match platform_version
// Patch platform version and run migrations if we have patches and/or
// migrations defined for this height.
// It modifies the protocol version to function version mapping to apply hotfixes
// Also it performs migrations to fix corrupted state or prepare it for new features
let block_platform_version = if let Some(patched_platform_version) = self
.apply_platform_version_patch_and_migrate_state_for_height(
block_proposal.height,
&mut block_platform_state,
transaction,
)? {
patched_platform_version
} else {
block_platform_version
};

match block_platform_version
.drive_abci
.methods
.engine
Expand All @@ -98,7 +125,8 @@ Your software version: {}, latest supported protocol version: {}."#,
epoch_info,
transaction,
platform_state,
platform_version,
block_platform_state,
block_platform_version,
),
version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
method: "run_block_proposal".to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ where
epoch_info: EpochInfo,
transaction: &Transaction,
last_committed_platform_state: &PlatformState,
platform_version: &PlatformVersion,
mut block_platform_state: PlatformState,
platform_version: &'static PlatformVersion,
) -> Result<ValidationResult<block_execution_outcome::v0::BlockExecutionOutcome, Error>, Error>
{
tracing::trace!(
Expand Down Expand Up @@ -102,9 +103,6 @@ where
let last_block_core_height = last_committed_platform_state
.last_committed_known_core_height_or(self.config.abci.genesis_core_height);

// Create a bock state from previous committed state
let mut block_platform_state = last_committed_platform_state.clone();

// Init block execution context
let block_state_info = block_state_info::v0::BlockStateInfoV0::from_block_proposal(
&block_proposal,
Expand Down Expand Up @@ -388,7 +386,7 @@ where
app_hash: root_hash,
state_transitions_result,
validator_set_update,
protocol_version: platform_version.protocol_version,
platform_version,
block_execution_context,
},
))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::error::Error;

use dpp::prelude::BlockHeight;
use drive::grovedb::Transaction;

use crate::platform_types::platform::Platform;

use crate::platform_types::platform_state::PlatformState;

impl<C> Platform<C> {
/// Perform state migration based on block height
pub fn migrate_state_for_height(
&self,
height: BlockHeight,
_block_platform_state: &mut PlatformState,
_transaction: &Transaction,
) -> Result<(), Error> {
#[allow(clippy::match_single_binding)]
let is_migrated = match height {
// 30 => self.migration_30_test(block_platform_state, transaction)?,
_ => false,
};

if is_migrated {
tracing::debug!("Successfully migrated state for height {}", height);
}

Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/// Clearing the drive cache should happen when a new block is going to be run
pub(in crate::execution) mod clear_drive_block_cache;
/// State migration
mod migrate_state;
/// Patch the platform version function mapping and migrate state based on the block height
pub(in crate::execution) mod patch_platform;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::error::Error;
use crate::platform_types::platform::Platform;
use crate::platform_types::platform_state::PlatformState;
use dpp::prelude::BlockHeight;
use dpp::version::PlatformVersion;
use drive::grovedb::Transaction;

impl<C> Platform<C> {
/// This function patches platform version and run migrations
/// It modifies protocol version to function version mapping to apply hotfixes
/// Also it performs migrations to fix corrupted state or prepare it for new features
///
/// This function appends the patch to PlatformState, potentially alter Drive and Platform execution state
/// and returns patched version
pub fn apply_platform_version_patch_and_migrate_state_for_height(
&self,
height: BlockHeight,
platform_state: &mut PlatformState,
transaction: &Transaction,
) -> Result<Option<&'static PlatformVersion>, Error> {
let patched_platform_version =
platform_state.apply_platform_version_patch_for_height(height)?;

self.migrate_state_for_height(height, platform_state, transaction)?;

Ok(patched_platform_version)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl<C> Platform<C> {
#[cfg(test)]
mod tests {
use super::*;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;

mod add_epoch_pool_to_proposers_payout_operations {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ impl<C> Platform<C> {
previous_block_protocol_version,
current_block_protocol_version,
);

block_platform_state
.set_current_protocol_version_in_consensus(current_block_protocol_version);
Comment on lines -56 to -57
Copy link
Member

Choose a reason for hiding this comment

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

This needs to remain here.

Copy link
Member Author

@shumkov shumkov Jul 13, 2024

Choose a reason for hiding this comment

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

Agreed to move inside if-condition in run_block_proposal to make PlatformState consistent with patching

};

// Determine a new protocol version for the next epoch if enough proposers voted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::platform_types::platform::PlatformRef;
use crate::rpc::core::CoreRPCLike;
use dpp::prelude::ConsensusValidationResult;
use dpp::state_transition::StateTransition;
use dpp::version::PlatformVersion;

use crate::execution::check_tx::CheckTxLevel;

Expand All @@ -25,8 +26,8 @@ pub(in crate::execution) fn state_transition_to_execution_event_for_check_tx<'a,
platform: &'a PlatformRef<C>,
state_transition: StateTransition,
check_tx_level: CheckTxLevel,
platform_version: &PlatformVersion,
) -> Result<ConsensusValidationResult<Option<ExecutionEvent<'a>>>, Error> {
let platform_version = platform.state.current_platform_version()?;
match platform_version
.drive_abci
.validation_and_processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use dpp::block::block_info::BlockInfo;
use dpp::prelude::ConsensusValidationResult;
use dpp::state_transition::StateTransition;

use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use drive::grovedb::TransactionArg;

/// There are multiple stages in a state transition processing:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::execution::validation::state_transition::processor::v0::{
};
use crate::execution::validation::state_transition::transformer::StateTransitionActionTransformerV0;
use crate::execution::validation::state_transition::ValidationMode;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;

impl ValidationMode {
/// Returns if we should validate the contract when we transform it from its serialized form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::execution::validation::state_transition::data_contract_update::state:
use crate::execution::validation::state_transition::transformer::StateTransitionActionTransformerV0;
use crate::execution::validation::state_transition::ValidationMode;
use crate::platform_types::platform::PlatformRef;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::rpc::core::CoreRPCLike;

impl StateTransitionActionTransformerV0 for DataContractUpdateTransition {
Expand Down Expand Up @@ -78,6 +79,7 @@ mod tests {
DataContractUpdateTransition, DataContractUpdateTransitionV0,
};

use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::platform_types::state_transitions_processing_result::StateTransitionExecutionResult;
use dpp::tests::fixtures::get_data_contract_fixture;
use dpp::tests::json_document::json_document_to_contract;
Expand Down Expand Up @@ -577,9 +579,8 @@ mod tests {

let card_game_path = "tests/supporting_files/contract/crypto-card-game/crypto-card-game-direct-purchase-creation-restricted-to-owner.json";

let platform_version = platform
.state
.load()
let platform_state = platform.state.load();
let platform_version = platform_state
.current_platform_version()
.expect("expected to get current platform version");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::execution::validation::state_transition::data_contract_update::state:
use crate::execution::validation::state_transition::processor::v0::StateTransitionStateValidationV0;
use crate::execution::validation::state_transition::ValidationMode;
use crate::platform_types::platform::PlatformRef;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
use crate::rpc::core::CoreRPCLike;
use dpp::block::block_info::BlockInfo;
use dpp::state_transition::data_contract_update_transition::DataContractUpdateTransition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ mod tests {
use dpp::withdrawal::Pooling;
use drive::drive::contract::DataContractFetchInfo;
use crate::execution::types::state_transition_execution_context::v0::StateTransitionExecutionContextV0;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;

#[test]
fn should_throw_error_if_withdrawal_not_found() {
Expand Down
Loading
Loading