Orphan bead handling wrt DB by Sansh2356 · Pull Request #309 · braidpool/braidpool · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
bd0f4f9
fix: Persisting orphan beads in DB and removing redundant request cal…
Sansh2356 Dec 6, 2025
e98b056
refactor: removing braid atomic refs for locking in main thread
Sansh2356 Dec 11, 2025
f2ed9ce
feat: orphan beads persisted without tight coupling
Sansh2356 Dec 12, 2025
e5f7bb7
removing ibd_manager and timestamp based checking in favour of sync c…
Sansh2356 Dec 12, 2025
4c9c822
adding batched insertions along with reducing insertion logic redundancy
Sansh2356 Feb 14, 2026
59bc587
separating raw batch-query to sub-queries and adding test for batch
Sansh2356 Mar 24, 2026
4fc4f16
removing original master head to adapt current branch changes during …
Sansh2356 Mar 24, 2026
15feaeb
removing GetParents call immediately after orphan_bead is received
Sansh2356 Mar 27, 2026
8404821
changing verbosity of logs and formation
Sansh2356 Apr 2, 2026
8284ef3
adding more error types and removing unwanted unwraps
Sansh2356 Apr 4, 2026
f01748e
fix(typo): removing commented logs and fmt check
Sansh2356 Apr 27, 2026
228ae87
chore(ibd): Adding ibd peer data to be replaced at retry,replacing co…
Sansh2356 May 8, 2026
1b59be9
chore(ibd): Removing Mutex lock around connection pool and query para…
Sansh2356 May 11, 2026
41a7403
chore(ibd): Adding sync_flag for IBD completion and re-requesting IBD…
Sansh2356 May 12, 2026
1cf63e6
fix: Updating locking scopes and changing serde functions during db i…
Sansh2356 May 16, 2026
7832048
feat(ibd): Adding pagination in beadhash to limit the beadhash memory…
Sansh2356 May 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
558 changes: 73 additions & 485 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Cargo.toml
3 changes: 0 additions & 3 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ serde_json = { workspace = true }
clap = { workspace = true }
bitcoin = { workspace = true }
bitcoin_hashes = { workspace = true }
bitcoincore-rpc = { workspace = true }
bitcoincore-rpc-json = { workspace = true }
bitcoincore-zmq = { workspace = true }
shellexpand = { workspace = true }
num = { workspace = true }
rand = { workspace = true }
Expand Down
33 changes: 31 additions & 2 deletions node/src/bead/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ braidpool_protocol! {
}
}

/// Maximum size in bytes of a single bead-sync request or response frame.
///
/// A remote peer that sends more than this on a single request/response
/// substream has its frame rejected before deserialization. Without this
/// cap, `read_to_end` would allocate without bound and a malicious peer
/// could OOM us during IBD.
///
/// Sized to comfortably hold one `IBD_HASH_PAGE_MAX`-sized hash list plus
/// one `IBD_BATCH_SIZE` worth of beads at realistic per-bead sizes.
pub const MAX_BEAD_SYNC_FRAME: usize = 4 * 1024 * 1024;

/// Codec for encoding/decoding bead sync messages over libp2p.
///
/// Implements the `libp2p::request_response::Codec` trait to handle serialization
Expand All @@ -138,8 +149,18 @@ impl Codec for BeadCodec {
where
T: AsyncRead + Unpin + Send,
{
// `take(MAX + 1)` lets us distinguish "exactly at the cap" (valid)
// from "exceeded the cap" (reject) without an extra read.
let mut buf = Vec::new();
io.read_to_end(&mut buf).await?;
io.take(MAX_BEAD_SYNC_FRAME as u64 + 1)
.read_to_end(&mut buf)
.await?;
if buf.len() > MAX_BEAD_SYNC_FRAME {
return Err(IoError::new(
ErrorKind::InvalidData,
"bead-sync request frame exceeds MAX_BEAD_SYNC_FRAME",
));
}
BeadRequest::consensus_decode(&mut buf.as_slice())
.map_err(|e| IoError::new(ErrorKind::InvalidData, e))
}
Expand All @@ -149,7 +170,15 @@ impl Codec for BeadCodec {
T: AsyncRead + Unpin + Send,
{
let mut buf = Vec::new();
io.read_to_end(&mut buf).await?;
io.take(MAX_BEAD_SYNC_FRAME as u64 + 1)
.read_to_end(&mut buf)
.await?;
if buf.len() > MAX_BEAD_SYNC_FRAME {
return Err(IoError::new(
ErrorKind::InvalidData,
"bead-sync response frame exceeds MAX_BEAD_SYNC_FRAME",
));
}
BeadResponse::consensus_decode(&mut buf.as_slice())
.map_err(|e| IoError::new(ErrorKind::InvalidData, e))
}
Expand Down
117 changes: 75 additions & 42 deletions node/src/braid/mod.rs
Loading
Loading