-
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
feat(drive): platform version patching and state migrations #1941
Conversation
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.
I feel like I reviewed this too early, maybe it wasn't done, please keep PRs in draft form until ready.
patch_platform_version(&block_info, platform_version, &mut block_platform_state)?; | ||
|
||
// Perform state migration to fix bugs or support new features | ||
self.migrate_state(&block_info, &mut block_platform_state)?; |
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.
This should be one call only. We should call it, check_for_chain_halt_hot_fix.
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.
And it should do everything inside.
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.
Migrations aren't only for chain halts. We might want to migrate data for features as well.
@@ -0,0 +1,27 @@ | |||
mod migration_42_example; |
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.
This should not be inside the build...
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.
Ok
match block_info.height { | ||
42 => self.migration_42_example(block_info, block_platform_state), | ||
52 => self.migration_42_example(block_info, block_platform_state), | ||
_ => {} |
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.
Why did we leave in examples?
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.
For people so they see how to follow. I will hide it for builds
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.
Removed all test data from the code. Now it's defined in tests
current_platform_version: &PlatformVersion, | ||
block_platform_state: &mut PlatformState, | ||
) -> Result<(), Error> { | ||
// Check if a patch that matches protocol version and block height is already applied |
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.
We should be able to apply more than one patch.
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.
More than one patch for the same version? You can.
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.
Per block height
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.
Done
@@ -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 |
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
dbg!( | ||
state | ||
.last_committed_block_info() | ||
.as_ref() | ||
.unwrap() | ||
.basic_info() | ||
.height | ||
); |
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.
dbg
@@ -42,6 +42,10 @@ pub struct PlatformStateV0 { | |||
pub current_validator_set_quorum_hash: QuorumHash, | |||
/// next quorum | |||
pub next_validator_set_quorum_hash: Option<QuorumHash>, | |||
/// This is a clone of current platform version based on |
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.
this is not a clone
static PATCHES: Lazy<HashMap<ProtocolVersion, HeightToPatchRanges>> = Lazy::new(|| { | ||
HashMap::from_iter(vec![ | ||
#[cfg(feature = "test-patch-platform")] | ||
{ | ||
( | ||
1, | ||
BTreeMap::from_iter(vec![ | ||
(5, patch_1_5_test as PatchFn), | ||
(10, patch_1_10_test as PatchFn), | ||
]), | ||
) | ||
}, | ||
#[cfg(feature = "test-patch-platform")] | ||
{ | ||
( | ||
TEST_PROTOCOL_VERSION_2, | ||
BTreeMap::from_iter(vec![(30, patch_2_30_test as PatchFn)]), | ||
) | ||
}, | ||
]) | ||
}); |
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.
patches should be in versioning crate.
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.
Moved
block_platform_state | ||
.set_current_protocol_version_in_consensus(current_block_protocol_version); |
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.
This needs to remain here.
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.
Agreed to move inside if-condition in run_block_proposal to make PlatformState consistent with patching
// 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do if
, because we need to run some logic anyway (clean up patches). Also, we would need to acquire a read lock twice. I renamed the function and updated the comment.
…migrations # Conflicts: # Cargo.lock # packages/rs-platform-version/Cargo.toml # packages/rs-platform-version/src/version/v1.rs
…migrations # Conflicts: # packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs # packages/rs-platform-version/src/version/mod.rs
Issue being fixed or feature implemented
To be able to recover from chain halt and fix urgent bugs without waiting for protocol version upgrade (which happens only on epoch change), we need to provide a mechanism to apply fixes and modify the corrupted state.
What was done?
How Has This Been Tested?
Introduced example patches and migrations and running strategy tests with tracing enabled.
Breaking Changes
None
Checklist:
For repository code-owners and collaborators only