Repository navigation
feat(contract): add authorized upgrade path with storage-layout versioning and migration (#41) - #64
Closed
huangji6693-max wants to merge 1 commit into
Conversation
…oning and migration (trustflow-protocol#41)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an admin-authorized contract upgrade path (
upgrade) alongside explicit storage-layout schema versioning (DataKey::StorageVersion) and a state migration routine (migrate) that safely transforms legacy v1 escrow and dispute records to the current v2 schema.Closes #41
Changes
STORAGE_VERSION_V1 = 1andCURRENT_STORAGE_VERSION = 2constants andDataKey::StorageVersion(set oninitialize, queried viaget_storage_version).upgrade(env, caller, new_wasm_hash)entrypoint restricted to the contractAdmin, invokingenv.deployer().update_current_contract_wasm(new_wasm_hash)and emitting aContractUpgradedevent ((symbol_short!("contract"), symbol_short!("upgraded"))).migrate):MilestoneV1,EscrowRecordV1,DisputeRecordV1) andDataKey::LegacyEscrowV1(u64)/DataKey::LegacyDisputeV1(u64).migrate(env, caller) -> Result<u32, TrustFlowError>that guards against redundant runs (TrustFlowError::AlreadyAtLatestVersion), backfills missingFeeBps/Treasurydefaults, transforms v1 escrows (MilestoneV1->Milestonewithrelease_time: 0) and missingEscrowFeeConfigsnapshots, transforms v1 disputes with commit/reveal deadlines, bumps persistent TTLs, updatesDataKey::StorageVersiontoCURRENT_STORAGE_VERSION, and emits aStorageMigratedevent ((symbol_short!("storage"), symbol_short!("migrated"))).AlreadyAtLatestVersionguard, and end-to-end v1 -> v2 escrow + dispute migration followed by milestone tranche release.Verification
[MEASURED]cargo test --package trustflow:68 passed; 0 failed[MEASURED]cargo build --target wasm32-unknown-unknown --release --package trustflow: succeeded[MEASURED]cargo fmt --all --check&cargo clippy --all-features --workspace --lib: passed