Skip to content

Commit

Permalink
chore(migrations): remove temporary patch from v3 to v4 storage migra…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
drcpu-github committed Nov 13, 2024
1 parent 678b5d7 commit cb6f067
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions node/src/storage_mngr/node_migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,20 @@ fn migrate_chain_state_v3_to_v4(old_chain_state_bytes: &[u8]) -> Vec<u8> {
let db_version: u32 = 4;
let db_version_bytes = db_version.to_le_bytes();

// This little trick makes sure that we don't run a migration on a v4 chain state that was
// incorrectly tagged as v3 in the context of a development release, by checking if the bytes
// match a pattern where the environment enum is stored at a certain position
if old_chain_state_bytes[5..9] == [0x02, 0x00, 0x00, 0x00] {
// Extra fields in ChainState v4:
let protocol_info = ProtocolInfo::default();
let protocol_info_bytes = serialize(&protocol_info).unwrap();
let stakes = StakesTracker::default();
let stakes_bytes = serialize(&stakes).unwrap();

[
&db_version_bytes,
&old_chain_state_bytes[4..5],
&protocol_info_bytes,
&old_chain_state_bytes[5..],
&stakes_bytes,
]
.concat()
} else {
[&db_version_bytes, &old_chain_state_bytes[4..]].concat()
}
// Extra fields in ChainState v4:
let protocol_info = ProtocolInfo::default();
let protocol_info_bytes = serialize(&protocol_info).unwrap();
let stakes = StakesTracker::default();
let stakes_bytes = serialize(&stakes).unwrap();

[
&db_version_bytes,
&old_chain_state_bytes[4..5],
&protocol_info_bytes,
&old_chain_state_bytes[5..],
&stakes_bytes,
]
.concat()
}

fn migrate_chain_state(mut bytes: Vec<u8>) -> Result<ChainState, failure::Error> {
Expand Down

0 comments on commit cb6f067

Please # to comment.