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 4 commits
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
70 changes: 30 additions & 40 deletions applications/tari_base_node/src/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,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_header(height).await.unwrap().unwrap();
let last_block_time = DateTime::<Utc>::from(last_header.header().timestamp);
status_line.add_field(
"Tip",
format!(
Expand Down Expand Up @@ -870,21 +865,20 @@ 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) => {
missing_blocks.push(height);
},
Ok(mut data) => match data.pop() {
// We need to check the data it self, as FetchMatchingBlocks will suppress any error, only
match node.get_block(height).await {
Err(err) => {
// We need to check the data itself, as FetchMatchingBlocks will suppress any error, only
// logging it.
Some(_historical_block) => {},
None => missing_blocks.push(height),
error!(target: LOG_TARGET, "{}", err);
missing_blocks.push(height);
},
Ok(Some(_)) => {},
Ok(None) => missing_blocks.push(height),
};
}
height -= 1;
let next_header = node.get_headers(vec![height]).await;
if next_header.is_err() {
let next_header = node.get_header(height).await.ok().flatten();
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 @@ -921,34 +915,30 @@ 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_block(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");
break;
},
// We need to check the data it self, as FetchMatchingBlocks will suppress any error, only
// logging it.
Ok(Some(historical_block)) => historical_block,
Ok(None) => {
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_block(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");
break;
},
// We need to check the data it self, as FetchMatchingBlocks will suppress any error, only
// logging it.
Ok(Some(historical_block)) => historical_block,
Ok(None) => {
println!("Error in db, block not found at height {}", height - 1);
break;
},
};
height -= 1;
Expand Down
Loading