marks db as upgraded, maintains a copy of the value balance in the old format
This commit is contained in:
parent
f40d0f8735
commit
d3319ba92b
|
@ -37,7 +37,7 @@ use crate::{
|
|||
disk_format::{tests::KV, RawBytes},
|
||||
FinalizedState,
|
||||
},
|
||||
Config, ReadDisk,
|
||||
Config, IntoDisk, ReadDisk,
|
||||
};
|
||||
|
||||
/// Snapshot test for RocksDB column families, and their key-value data.
|
||||
|
@ -145,6 +145,16 @@ fn snapshot_raw_rocksdb_column_family_data(db: &DiskDb, original_cf_names: &[Str
|
|||
// because those roots are used to populate the anchor column families.
|
||||
insta::assert_ron_snapshot!(format!("{cf_name}_raw_data"), cf_data);
|
||||
}
|
||||
|
||||
if cf_name == "tip_chain_value_pool" && !cf_data.is_empty() {
|
||||
let chain_value_pool_cf = db.cf_handle("tip_chain_value_pool").unwrap();
|
||||
let value_pool: RawBytes = db
|
||||
.zs_get(&chain_value_pool_cf, &())
|
||||
.expect("should have value at &()");
|
||||
|
||||
let cf_data = KV::new(().as_bytes(), value_pool.raw_bytes());
|
||||
insta::assert_ron_snapshot!(format!("legacy_tip_chain_value_pool_raw_data"), cf_data);
|
||||
}
|
||||
}
|
||||
|
||||
insta::assert_ron_snapshot!("empty_column_families", empty_column_families);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
source: zebra-state/src/service/finalized_state/disk_format/tests/snapshot.rs
|
||||
expression: cf_data
|
||||
---
|
||||
KV(
|
||||
k: "",
|
||||
v: "24f4000000000000000000000000000000000000000000000000000000000000",
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
source: zebra-state/src/service/finalized_state/disk_format/tests/snapshot.rs
|
||||
expression: cf_data
|
||||
---
|
||||
KV(
|
||||
k: "",
|
||||
v: "6cdc020000000000000000000000000000000000000000000000000000000000",
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
source: zebra-state/src/service/finalized_state/disk_format/tests/snapshot.rs
|
||||
expression: cf_data
|
||||
---
|
||||
KV(
|
||||
k: "",
|
||||
v: "24f4000000000000000000000000000000000000000000000000000000000000",
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
source: zebra-state/src/service/finalized_state/disk_format/tests/snapshot.rs
|
||||
expression: cf_data
|
||||
---
|
||||
KV(
|
||||
k: "",
|
||||
v: "6cdc020000000000000000000000000000000000000000000000000000000000",
|
||||
)
|
|
@ -7,4 +7,8 @@ expression: cf_data
|
|||
k: "",
|
||||
v: "24f4000000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
KV(
|
||||
k: "01",
|
||||
v: "24f4000000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
]
|
||||
|
|
|
@ -7,4 +7,8 @@ expression: cf_data
|
|||
k: "",
|
||||
v: "6cdc020000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
KV(
|
||||
k: "01",
|
||||
v: "6cdc020000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
]
|
||||
|
|
|
@ -7,4 +7,8 @@ expression: cf_data
|
|||
k: "",
|
||||
v: "24f4000000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
KV(
|
||||
k: "01",
|
||||
v: "24f4000000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
]
|
||||
|
|
|
@ -7,4 +7,8 @@ expression: cf_data
|
|||
k: "",
|
||||
v: "6cdc020000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
KV(
|
||||
k: "01",
|
||||
v: "6cdc020000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
]
|
||||
|
|
|
@ -541,6 +541,14 @@ impl DbFormatChange {
|
|||
timer.finish(module_path!(), line!(), "tree keys and caches upgrade");
|
||||
}
|
||||
|
||||
let version_for_value_balance_format =
|
||||
Version::parse("25.4.0").expect("hard-coded version string should be valid.");
|
||||
|
||||
// Check if we need to do the upgrade.
|
||||
if older_disk_version < &version_for_value_balance_format {
|
||||
Self::mark_as_upgraded_to(db, &version_for_value_balance_format);
|
||||
}
|
||||
|
||||
// # New Upgrades Usually Go Here
|
||||
//
|
||||
// New code goes above this comment!
|
||||
|
|
|
@ -17,7 +17,10 @@ use std::{
|
|||
};
|
||||
|
||||
use zebra_chain::{
|
||||
amount::NonNegative, block::Height, history_tree::HistoryTree, transparent,
|
||||
amount::{Amount, NonNegative},
|
||||
block::Height,
|
||||
history_tree::HistoryTree,
|
||||
transparent,
|
||||
value_balance::ValueBalance,
|
||||
};
|
||||
|
||||
|
@ -60,7 +63,7 @@ pub const CHAIN_VALUE_POOLS: &str = "tip_chain_value_pool";
|
|||
///
|
||||
/// This constant should be used so the compiler can detect incorrectly typed accesses to the
|
||||
/// column family.
|
||||
pub type ChainValuePoolsCf<'cf> = TypedColumnFamily<'cf, (), ValueBalance<NonNegative>>;
|
||||
pub type ChainValuePoolsCf<'cf> = TypedColumnFamily<'cf, RawBytes, ValueBalance<NonNegative>>;
|
||||
|
||||
impl ZebraDb {
|
||||
// Column family convenience methods
|
||||
|
@ -159,7 +162,8 @@ impl ZebraDb {
|
|||
let chain_value_pools_cf = self.chain_value_pools_cf();
|
||||
|
||||
chain_value_pools_cf
|
||||
.zs_get(&())
|
||||
.zs_get(&RawBytes::new_raw_bytes(vec![1]))
|
||||
.or_else(|| chain_value_pools_cf.zs_get(&RawBytes::new_raw_bytes(vec![])))
|
||||
.unwrap_or_else(ValueBalance::zero)
|
||||
}
|
||||
}
|
||||
|
@ -227,18 +231,19 @@ impl DiskWriteBatch {
|
|||
utxos_spent_by_block: HashMap<transparent::OutPoint, transparent::Utxo>,
|
||||
value_pool: ValueBalance<NonNegative>,
|
||||
) -> Result<(), BoxError> {
|
||||
let _ = db
|
||||
let mut value_balance = value_pool.add_chain_value_pool_change(
|
||||
finalized
|
||||
.block
|
||||
.chain_value_pool_change(&utxos_spent_by_block, finalized.deferred_balance)?,
|
||||
)?;
|
||||
|
||||
let batch = db
|
||||
.chain_value_pools_cf()
|
||||
.with_batch_for_writing(self)
|
||||
.zs_insert(
|
||||
&(),
|
||||
&value_pool.add_chain_value_pool_change(
|
||||
finalized.block.chain_value_pool_change(
|
||||
&utxos_spent_by_block,
|
||||
finalized.deferred_balance,
|
||||
)?,
|
||||
)?,
|
||||
);
|
||||
.zs_insert(&RawBytes::new_raw_bytes(vec![1]), &value_balance);
|
||||
|
||||
value_balance.set_deferred_amount(Amount::zero());
|
||||
let _ = batch.zs_insert(&RawBytes::new_raw_bytes(vec![]), &value_balance);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue