-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(drive): platform version patching and state migrations (#1941)
- Loading branch information
Showing
43 changed files
with
853 additions
and
103 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/rs-drive-abci/src/execution/platform_events/block_start/migrate_state/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/rs-drive-abci/src/execution/platform_events/block_start/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
28 changes: 28 additions & 0 deletions
28
packages/rs-drive-abci/src/execution/platform_events/block_start/patch_platform.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.