Updating the consensus functions according to new struct definitions #160
Updating the consensus functions according to new struct definitions #160Sansh2356 wants to merge 3 commits into
Conversation
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
There was a problem hiding this comment.
Orphan beads are should be owned by the Node, not the Braid.
|
|
||
| // Database related functions! | ||
| loaded_beads_in_memory: HashMap<BeadHash, Bead>, | ||
| pub(crate) loaded_beads_in_memory: HashMap<BeadHash, Bead>, |
There was a problem hiding this comment.
I'd prefer if this was just called beads. For now assume all beads will be in memory. We will go back and provide the ability to load/save the DAG.
| // self.children.borrow().contains(&child_bead_hash) | ||
| // } | ||
|
|
||
| pub fn is_genesis_bead(&self, braid: &Braid) -> bool { |
There was a problem hiding this comment.
This should be a function on the Braid class instead, which should be able to access committed_metadata.parents without a getter function.
The cohorts algorithm needs the genesis beads as a set. (geneses in python)
Create Braid.geneses() instead.
| } | ||
|
|
||
| #[inline] | ||
| pub fn is_orphaned(&self, braid: &Braid) -> bool { |
There was a problem hiding this comment.
Node should keep the list of orphan beads, and add them to the braid when they become connected.
Orphan beads have missing parents, so we can't add them to the DAG. Node should add (Braid.extend()) both the missing parents and the orphan when the parents are received.
| // self.children.borrow().iter().cloned().collect() | ||
| // } | ||
| } | ||
|
|
There was a problem hiding this comment.
Add:
#[derive(Serialize, Deserialize, Debug)]
| // } | ||
|
|
||
| if self.is_bead_orphaned(&bead) { | ||
| if bead.is_orphaned(self) { |
| impl Braid { | ||
| // All pub(crate) functions go here! | ||
| #[inline] | ||
| pub(crate) fn load_bead_from_hash(&self, bead_hash: BeadHash) -> Result<&Bead, BeadLoadError> { |
There was a problem hiding this comment.
This should be done by Bead serialization, and the db work should go into the Node.
| } | ||
|
|
||
| impl Braid { | ||
| fn update_parents_of_bead(&self, child_bead: &Bead) { |
There was a problem hiding this comment.
We never need to update the parents of a bead.
When a Bead is created, its parents should be set in its constructor. If a new bead comes in, the Node should destroy the old Bead we were mining on, and create a new one (it will have different parents and possibly different transactions). So we basically have to recreate a whole new Bead from scratch instead of modifying an existing Bead.
| } | ||
|
|
||
| // Construct a sub-braid from dangling and compute any new cohorts | ||
| // Here, we just create a new cohort with dangling beads |
There was a problem hiding this comment.
We need to call the cohorts(dangling) algorithm here. See node/src/braid.rs.
There was a problem hiding this comment.
Why two types here? Why not just use BeadHash?

Continuation of PR #109.
Addresses #147.