mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 06:51:07 +00:00
Refactor epoch changes to a separate crate (#4785)
* Init epoch changes module * Initial integration of new epoch changes module for BABE * Fix all initial compile errors * rename: digest -> digests * Fix babe tests * Bump impl_version * Fix more test issues * Remove test flag for tree It unfortunately won't work for multiple crates. * Update cargo lock * Fix duplicate parking_lot version * Add missing license header
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
//! Schema for BABE epoch changes in the aux-db.
|
||||
|
||||
use std::sync::Arc;
|
||||
use parking_lot::Mutex;
|
||||
use log::info;
|
||||
use codec::{Decode, Encode};
|
||||
|
||||
@@ -23,8 +25,8 @@ use sc_client_api::backend::AuxStore;
|
||||
use sp_blockchain::{Result as ClientResult, Error as ClientError};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use sp_consensus_babe::BabeBlockWeight;
|
||||
|
||||
use super::{epoch_changes::EpochChangesFor, SharedEpochChanges};
|
||||
use sc_consensus_epochs::{EpochChangesFor, SharedEpochChanges};
|
||||
use crate::Epoch;
|
||||
|
||||
const BABE_EPOCH_CHANGES: &[u8] = b"babe_epoch_changes";
|
||||
|
||||
@@ -49,14 +51,14 @@ fn load_decode<B, T>(backend: &B, key: &[u8]) -> ClientResult<Option<T>>
|
||||
/// Load or initialize persistent epoch change data from backend.
|
||||
pub(crate) fn load_epoch_changes<Block: BlockT, B: AuxStore>(
|
||||
backend: &B,
|
||||
) -> ClientResult<SharedEpochChanges<Block>> {
|
||||
let epoch_changes = load_decode::<_, EpochChangesFor<Block>>(backend, BABE_EPOCH_CHANGES)?
|
||||
.map(Into::into)
|
||||
) -> ClientResult<SharedEpochChanges<Block, Epoch>> {
|
||||
let epoch_changes = load_decode::<_, EpochChangesFor<Block, Epoch>>(backend, BABE_EPOCH_CHANGES)?
|
||||
.map(|v| Arc::new(Mutex::new(v)))
|
||||
.unwrap_or_else(|| {
|
||||
info!(target: "babe",
|
||||
"Creating empty BABE epoch changes on what appears to be first startup."
|
||||
);
|
||||
SharedEpochChanges::new()
|
||||
SharedEpochChanges::<Block, Epoch>::default()
|
||||
});
|
||||
|
||||
// rebalance the tree after deserialization. this isn't strictly necessary
|
||||
@@ -70,7 +72,7 @@ pub(crate) fn load_epoch_changes<Block: BlockT, B: AuxStore>(
|
||||
|
||||
/// Update the epoch changes on disk after a change.
|
||||
pub(crate) fn write_epoch_changes<Block: BlockT, F, R>(
|
||||
epoch_changes: &EpochChangesFor<Block>,
|
||||
epoch_changes: &EpochChangesFor<Block, Epoch>,
|
||||
write_aux: F,
|
||||
) -> R where
|
||||
F: FnOnce(&[(&'static [u8], &[u8])]) -> R,
|
||||
|
||||
Reference in New Issue
Block a user