Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Nov 28, 2024
1 parent 4491a9f commit 995b587
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 68 deletions.
4 changes: 2 additions & 2 deletions base_layer/core/src/chain_storage/blockchain_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ pub trait BlockchainBackend: Send + Sync {
fn validator_node_is_active(
&self,
sidechain_pk: Option<&PublicKey>,
height: u64,
end_epoch: VnEpoch,
validator_node_pk: &PublicKey,
) -> Result<bool, ChainStorageError>;

fn validator_node_is_active_for_shard_group(
&self,
sidechain_pk: Option<&PublicKey>,
height: u64,
epoch: VnEpoch,
validator_node_pk: &PublicKey,
shard_group: u32,
) -> Result<bool, ChainStorageError>;
Expand Down
9 changes: 7 additions & 2 deletions base_layer/core/src/chain_storage/lmdb_db/composite_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<const L: usize> CompositeKey<L> {
}
let mut buf = [0u8; 8];
buf.copy_from_slice(&self.bytes[offset..offset + 8]);
Ok(u64::from_le_bytes(buf))
Ok(u64::from_be_bytes(buf))
}

/// Returns a fixed 0-filled byte array.
Expand Down Expand Up @@ -200,7 +200,12 @@ impl<'a, const SECTIONS: usize> SectionIter<'a, SECTIONS> {
/// Panics if the next section is not 8 bytes long.
pub fn next_be_u64(&mut self) -> Option<u64> {
let bytes = self.next()?;
assert_eq!(bytes.len(), 8);
assert_eq!(
bytes.len(),
8,
"Next section is not 8 bytes long. Section length: {}",
bytes.len()
);
let mut buf = [0u8; 8];
buf.copy_from_slice(bytes);
Some(u64::from_be_bytes(buf))
Expand Down
20 changes: 9 additions & 11 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,10 @@ impl LMDBDatabase {
// Nothing to do
},
SideChainFeatureData::EvictionProof(evict) => {
let epoch = constants.block_height_to_epoch(height);
self.validator_node_store(txn).unevict(
let next_epoch = constants.block_height_to_epoch(height) + VnEpoch(1);
self.validator_node_store(txn).undo_exit(
sidechain_features.sidechain_public_key(),
epoch,
next_epoch,
evict.node_to_evict(),
)?;
},
Expand Down Expand Up @@ -1405,16 +1405,16 @@ impl LMDBDatabase {
let store = self.validator_node_store(txn);
let evict_node = proof.node_to_evict();
let constants = self.get_consensus_constants(header.height);
let epoch = constants.block_height_to_epoch(header.height);
let next_epoch = constants.block_height_to_epoch(header.height) + VnEpoch(1);
let sidechain_pk = sidechain_feature.sidechain_id().map(|id| id.public_key());
info!(
target: LOG_TARGET,
"Evicting ValidatorNode in {}: public_key: {}, sidechain_public_key: {:?}",
epoch,
next_epoch,
evict_node,
sidechain_pk.map(|pk| pk.to_hex()),
);
store.evict(sidechain_pk, evict_node, epoch)?;
store.exit(sidechain_pk, evict_node, next_epoch)?;
},
}

Expand Down Expand Up @@ -2725,28 +2725,26 @@ impl BlockchainBackend for LMDBDatabase {
fn validator_node_is_active(
&self,
sidechain_pk: Option<&PublicKey>,
height: u64,
end_epoch: VnEpoch,
validator_node_pk: &PublicKey,
) -> Result<bool, ChainStorageError> {
let txn = self.read_transaction()?;
let vn_store = self.validator_node_store(&txn);
let constants = self.consensus_manager.consensus_constants(height);

// Get the current epoch for the height
let end_epoch = constants.block_height_to_epoch(height);
let is_active = vn_store.is_vn_active(sidechain_pk, validator_node_pk, end_epoch)?;
Ok(is_active)
}

fn validator_node_is_active_for_shard_group(
&self,
sidechain_pk: Option<&PublicKey>,
height: u64,
end_epoch: VnEpoch,
validator_node_pk: &PublicKey,
_shard_group: u32,
) -> Result<bool, ChainStorageError> {
// TODO: account for shard group
self.validator_node_is_active(sidechain_pk, height, validator_node_pk)
self.validator_node_is_active(sidechain_pk, end_epoch, validator_node_pk)
}

fn validator_nodes_count_for_shard_group(
Expand Down
Loading

0 comments on commit 995b587

Please sign in to comment.