Updating the consensus functions according to new struct definitions by Sansh2356 · Pull Request #160 · braidpool/braidpool · GitHub
Skip to content

Updating the consensus functions according to new struct definitions #160

Closed
Sansh2356 wants to merge 3 commits into
devfrom
feat/consensus_functions
Closed

Updating the consensus functions according to new struct definitions #160
Sansh2356 wants to merge 3 commits into
devfrom
feat/consensus_functions

Conversation

@Sansh2356

@Sansh2356 Sansh2356 commented Apr 30, 2025

Copy link
Copy Markdown
Contributor

Continuation of PR #109.
Addresses #147.

@Sansh2356 Sansh2356 requested review from a team and mcelrath April 30, 2025 09:56
@Sansh2356 Sansh2356 marked this pull request as draft April 30, 2025 09:56
@Sansh2356 Sansh2356 changed the base branch from main to dev April 30, 2025 09:57
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
@Sansh2356 Sansh2356 self-assigned this Apr 30, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
// }
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add:

#[derive(Serialize, Deserialize, Debug)]

// }

if self.is_bead_orphaned(&bead) {
if bead.is_orphaned(self) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to Node class.

impl Braid {
// All pub(crate) functions go here!
#[inline]
pub(crate) fn load_bead_from_hash(&self, bead_hash: BeadHash) -> Result<&Bead, BeadLoadError> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to call the cohorts(dangling) algorithm here. See node/src/braid.rs.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why two types here? Why not just use BeadHash?

@Sansh2356 Sansh2356 closed this May 9, 2025
@Sansh2356 Sansh2356 mentioned this pull request Jun 22, 2025
37 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants