Implement rpc server by Aritra8438 · Pull Request #222 · braidpool/braidpool · GitHub
Skip to content

Implement rpc server#222

Closed
Aritra8438 wants to merge 11 commits into
devfrom
implement-rpc-server
Closed

Implement rpc server#222
Aritra8438 wants to merge 11 commits into
devfrom
implement-rpc-server

Conversation

@Aritra8438

@Aritra8438 Aritra8438 commented Jul 2, 2025

Copy link
Copy Markdown
Member

Please don't merge this.

This is a very primitive design for the rpc server.

  • It introduces a braidmanager class which consists of the braid, beads, commands.

  • Please note that. we can remove the beads and that's our next goal. The beads property was needed when we had only the beadhash.

  • Below we will track a list of commands that will be exposed through the rpc server.

  • gettips

  • getbead

  • getcohortcount getcohortscount

  • getbeadcount getbeadscount

If you have any more suggestions, feel free to add!

Aritra8438 and others added 11 commits July 1, 2025 13:36
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
Co-authored-by: Ansh <sansh2356@gmail.com>
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
Signed-off-by: Aritra Majumder <aritramajumder8438@gmail.com>
@Sansh2356 Sansh2356 changed the base branch from main to dev July 2, 2025 17:05

@mcelrath mcelrath left a comment

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.

The biggest problem with this PR is that the RPC cannot exist as an independent entity from the Node. It is part of the node and can't do it's job without access to the data held by the node (in particular, the Braid object).

There are a couple of ways to do this:

  1. Make the RPC methods be handlers on the Node object, so that they have access to all the node data (Braid, Peers, etc).
  2. Pass the relevant immutable object (by reference!) to the RPC object (e.g. Braid&)

Option 1 will make the Node code fairly long and un-modular, but maybe we can separate the RPC handlers in to separate files? Option 2 requires passing a lot of large objects and questions of ownership and lifetime become important.

Comment thread node/src/main.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.

What we should do here is either:

  1. Receive a genesis bead from peers, do IBD, and decide we're "up to date".
  2. If we're the first node or isolated, get the tip from Bitcoind/cmempoold and use that as our genesis.

Comment thread node/src/braid_manager.rs
},
}

pub struct BraidManager {

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 don't think we need a "manager" here. There will only be one braid in general, and having two will be rare (at difficulty retargets, or if we do sub-braids).

The below duplicates storage -- both the Braid class and bead_storage duplicate the storage of beads.

Instead we should put RPC handler methods in the Node class, with access to the Braid object.

Comment thread node/src/main.rs
braid_manager.run().await;
});

let test_bead1 = create_test_bead(1, None); // Genesis 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.

This doesn't belong here, it should be in a test.

Comment thread node/src/main.rs
}
bead::BeadResponse::Tips(tips) => {
BeadResponse::Tips(tips) => {
// Handle tips

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.

For all these, call the corresponding Braid object method, and create a proper response.

Comment thread node/src/rpc_server.rs
));
}
}
"getbeadcount" => {

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 don't understand how this is actually getting the bead count. It needs to have access to the Braid (which is owned by the Node), and call the Braid method to return the response.

Comment thread node/src/rpc_server.rs
async fn get_bead(&self, bead_hash: String) -> Result<String, ErrorObjectOwned>;

#[method(name = "addbead")]
async fn add_bead(&self, bead_data: String) -> Result<String, ErrorObjectOwned>;

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.

See Braid::extend()

@Sansh2356

Copy link
Copy Markdown
Contributor

@Sansh2356 Sansh2356 closed this Jul 10, 2025
@Sansh2356 Sansh2356 deleted the implement-rpc-server branch April 13, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants