-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(drive): platform version patching and state migrations #1941
Changes from 5 commits
be2b0cc
a4d0988
b45a1db
bbad647
82dbe71
4e5a790
3857883
386cb65
90e984b
3fb9e7a
17c7c72
a8f2746
fc90dac
3c68376
b23e693
dacdf32
9e6312b
a2e62b7
b644ac7
975e57a
eb972df
25eefa8
94bfc42
6cb211b
f7ef6b3
febed5e
ffb2607
a9621f3
127ceae
4d7eb3e
f98b441
c0552dc
26cd101
cb923ac
b67c6d0
29e5314
5139ca7
31734aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,10 +61,13 @@ where | |
last_committed_platform_version, | ||
)?; | ||
|
||
// Determine a protocol version for this block | ||
let platform_version = if epoch_info.is_epoch_change_but_not_genesis() { | ||
// 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 | ||
// This version will be set to the block state and we decide on next version 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 | ||
|
@@ -82,11 +85,31 @@ Your software version: {}, latest supported protocol version: {}."#, | |
|
||
next_platform_version | ||
} else { | ||
// Stay on the last committed platform version | ||
// Stay on the last committed plat version | ||
last_committed_platform_version | ||
}; | ||
|
||
match platform_version | ||
// Create a bock state from previous committed state | ||
let mut block_platform_state = platform_state.clone(); | ||
|
||
// Set current protocol version to the block platform state | ||
block_platform_state | ||
.set_current_protocol_version_in_consensus(block_platform_version.protocol_version); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move above into condition |
||
|
||
// Patch platform version and run migrations | ||
// 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.patch_platform( | ||
block_proposal.height, | ||
&mut block_platform_state, | ||
transaction, | ||
)? { | ||
patched_platform_version | ||
} else { | ||
block_platform_version | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would do an if needed { do things } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't do |
||
|
||
match block_platform_version | ||
.drive_abci | ||
.methods | ||
.engine | ||
|
@@ -98,7 +121,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(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::error::Error; | ||
use crate::platform_types::platform::Platform; | ||
use crate::platform_types::platform_state::PlatformState; | ||
use drive::error::Error as DriveError; | ||
use drive::grovedb::Transaction; | ||
|
||
impl<C> Platform<C> { | ||
pub(super) fn migration_30_test( | ||
&self, | ||
_block_platform_state: &mut PlatformState, | ||
transaction: &Transaction, | ||
) -> Result<(), Error> { | ||
self.drive | ||
.grove | ||
.put_aux( | ||
"migration_42_example", | ||
b"migration_42_example", | ||
None, | ||
Some(transaction), | ||
) | ||
.unwrap() | ||
.map_err(DriveError::GroveDB)?; | ||
|
||
Ok(()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#[cfg(feature = "test-patch-platform")] | ||
mod migration_30_test; | ||
|
||
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( | ||
&self, | ||
height: BlockHeight, | ||
block_platform_state: &mut PlatformState, | ||
transaction: &Transaction, | ||
) -> Result<(), Error> { | ||
match height { | ||
#[cfg(feature = "test-patch-platform")] | ||
30 => self.migration_30_test(block_platform_state, transaction)?, | ||
_ => {} | ||
} | ||
|
||
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 patch_platform( | ||
&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(height, platform_state, transaction)?; | ||
|
||
Ok(patched_platform_version) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to remain here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
platform