mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 21:38:31 +00:00
Remove block_graph from beacon_chain.
This commit is contained in:
@@ -17,7 +17,6 @@ use types::{
|
||||
};
|
||||
|
||||
use crate::attestation_aggregator::{AttestationAggregator, Outcome as AggregationOutcome};
|
||||
use crate::block_graph::BlockGraph;
|
||||
use crate::checkpoint::CheckPoint;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -65,7 +64,6 @@ pub struct BeaconChain<T: ClientDB + Sized, U: SlotClock, F: ForkChoice> {
|
||||
pub block_store: Arc<BeaconBlockStore<T>>,
|
||||
pub state_store: Arc<BeaconStateStore<T>>,
|
||||
pub slot_clock: U,
|
||||
pub block_graph: BlockGraph,
|
||||
pub attestation_aggregator: RwLock<AttestationAggregator>,
|
||||
canonical_head: RwLock<CheckPoint>,
|
||||
finalized_head: RwLock<CheckPoint>,
|
||||
@@ -101,9 +99,6 @@ where
|
||||
let block_root = genesis_block.canonical_root();
|
||||
block_store.put(&block_root, &ssz_encode(&genesis_block)[..])?;
|
||||
|
||||
let block_graph = BlockGraph::new();
|
||||
block_graph.add_leaf(&Hash256::zero(), block_root);
|
||||
|
||||
let finalized_head = RwLock::new(CheckPoint::new(
|
||||
genesis_block.clone(),
|
||||
block_root,
|
||||
@@ -128,7 +123,6 @@ where
|
||||
block_store,
|
||||
state_store,
|
||||
slot_clock,
|
||||
block_graph,
|
||||
attestation_aggregator,
|
||||
state: RwLock::new(genesis_state.clone()),
|
||||
justified_head,
|
||||
@@ -484,9 +478,6 @@ where
|
||||
self.block_store.put(&block_root, &ssz_encode(&block)[..])?;
|
||||
self.state_store.put(&state_root, &ssz_encode(&state)[..])?;
|
||||
|
||||
// Update the block DAG.
|
||||
self.block_graph.add_leaf(&parent_block_root, block_root);
|
||||
|
||||
// run the fork_choice add_block logic
|
||||
self.fork_choice.add_block(&block, &block_root)?;
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
use parking_lot::{RwLock, RwLockReadGuard};
|
||||
use std::collections::HashSet;
|
||||
use types::Hash256;
|
||||
|
||||
/// Maintains a view of the block DAG, also known as the "blockchain" (except, it tracks multiple
|
||||
/// chains eminating from a single root instead of just the head of some canonical chain).
|
||||
///
|
||||
/// The BlockGraph does not store the blocks, instead it tracks the block hashes of blocks at the
|
||||
/// tip of the DAG. It is out of the scope of the object to retrieve blocks.
|
||||
///
|
||||
/// Presently, the DAG root (genesis block) is not tracked.
|
||||
///
|
||||
/// The BlogGraph is thread-safe due to internal RwLocks.
|
||||
pub struct BlockGraph {
|
||||
pub leaves: RwLock<HashSet<Hash256>>,
|
||||
}
|
||||
|
||||
impl BlockGraph {
|
||||
/// Create a new block graph without any leaves.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
leaves: RwLock::new(HashSet::new()),
|
||||
}
|
||||
}
|
||||
/// Add a new leaf to the block hash graph. Returns `true` if the leaf was built upon another
|
||||
/// leaf.
|
||||
pub fn add_leaf(&self, parent: &Hash256, leaf: Hash256) -> bool {
|
||||
let mut leaves = self.leaves.write();
|
||||
|
||||
if leaves.contains(parent) {
|
||||
leaves.remove(parent);
|
||||
leaves.insert(leaf);
|
||||
true
|
||||
} else {
|
||||
leaves.insert(leaf);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a read-guarded HashSet of all leaf blocks.
|
||||
pub fn leaves(&self) -> RwLockReadGuard<HashSet<Hash256>> {
|
||||
self.leaves.read()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user