Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove unbounded vec allocations from base node grpc/p2p messaging #3467

Merged
merged 5 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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