Skip to content

Commit

Permalink
fix: remove unbounded vec allocations from base node grpc/p2p messaging
Browse files Browse the repository at this point in the history
- replaces unbounded height lists with bound height ranges in internal base node service
  interfaces and p2p messaging
- removes unused and deprecated base node p2p messaging requests/responses
- load chain headers when requesting headers, this simplifies and
  reduces the database load when calling grpc get_blocks
- use iterator with almost no footprint for paging in grpc calls
- implement `DoubleSidedIterator` for `NonOverlappingIntegerPairIter`
- add overflow protection to `NonOverlappingIntegerPairIter` and
  additional tests
  • Loading branch information
sdbondi committed Oct 18, 2021
1 parent 1d11ae4 commit 81b633d
Show file tree
Hide file tree
Showing 25 changed files with 403 additions and 950 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions applications/tari_base_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ anyhow = "1.0.32"
bincode = "1.3.1"
chrono = "0.4"
config = { version = "0.9.3" }
either = "1.6.1"
futures = { version = "^0.3.16", default-features = false, features = ["alloc"] }
log = { version = "0.4.8", features = ["std"] }
num_cpus = "1"
Expand Down
36 changes: 16 additions & 20 deletions applications/tari_base_node/src/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,9 @@ impl CommandHandler {
status_line.add_field("State", state_info.borrow().state_info.short_desc());

let metadata = node.get_metadata().await.unwrap();

let last_header = node
.get_headers(vec![metadata.height_of_longest_chain()])
.await
.unwrap()
.pop()
.unwrap();
let last_block_time = DateTime::<Utc>::from(last_header.timestamp);
let height = metadata.height_of_longest_chain();
let last_header = node.get_headers(height, height).await.unwrap().pop().unwrap();
let last_block_time = DateTime::<Utc>::from(last_header.header().timestamp);
status_line.add_field(
"Tip",
format!(
Expand Down Expand Up @@ -866,8 +861,9 @@ impl CommandHandler {
io::stdout().flush().unwrap();
// we can only check till the pruning horizon, 0 is archive node so it needs to check every block.
if height > horizon_height {
match node.get_blocks(vec![height]).await {
Err(_err) => {
match node.get_blocks(height, height).await {
Err(err) => {
error!(target: LOG_TARGET, "{}", err);
missing_blocks.push(height);
},
Ok(mut data) => match data.pop() {
Expand All @@ -879,8 +875,8 @@ impl CommandHandler {
};
}
height -= 1;
let next_header = node.get_headers(vec![height]).await;
if next_header.is_err() {
let next_header = node.get_headers(height, height).await.ok().filter(|h| !h.is_empty());
if next_header.is_none() {
// this header is missing, so we stop here and need to ask for this header
missing_headers.push(height);
};
Expand Down Expand Up @@ -917,32 +913,32 @@ impl CommandHandler {
print!("{}", height);
io::stdout().flush().unwrap();

let block = match node.get_blocks(vec![height]).await {
Err(_err) => {
println!("Error in db, could not get block");
let block = match node.get_blocks(height, height).await {
Err(err) => {
println!("Error in db, could not get block: {}", err);
break;
},
Ok(mut data) => match data.pop() {
// We need to check the data it self, as FetchMatchingBlocks will suppress any error, only
// logging it.
Some(historical_block) => historical_block,
None => {
println!("Error in db, could not get block");
println!("Error in db, block not found at height {}", height);
break;
},
},
};
let prev_block = match node.get_blocks(vec![height - 1]).await {
Err(_err) => {
println!("Error in db, could not get block");
let prev_block = match node.get_blocks(height - 1, height - 1).await {
Err(err) => {
println!("Error in db, could not get block: {}", err);
break;
},
Ok(mut data) => match data.pop() {
// We need to check the data it self, as FetchMatchingBlocks will suppress any error, only
// logging it.
Some(historical_block) => historical_block,
None => {
println!("Error in db, could not get block");
println!("Error in db, block not found at height {}", height - 1);
break;
},
},
Expand Down
Loading

0 comments on commit 81b633d

Please sign in to comment.