Skip to content

Commit

Permalink
dropping last_known_blocks after using it
Browse files Browse the repository at this point in the history
`last_known_blocks` was taking up ~300migs of memory (for 100 blocks) because it was not dropped in `main`.

Co-authored-by: Sergi Delgado Segura <[email protected]>
  • Loading branch information
mariocynicys and sr-gi committed Aug 7, 2023
1 parent 1db4dd1 commit 492f472
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions teos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,6 @@ async fn main() {
any => any,
};

let mut poller = ChainPoller::new(&mut derefed, Network::from_str(btc_network).unwrap());
let last_n_blocks = get_last_n_blocks(&mut poller, tip, IRREVOCABLY_RESOLVED as usize)
.await.unwrap_or_else(|e| {
// I'm pretty sure this can only happen if we are pulling blocks from the target to the prune height, and by the time we get to
// the end at least one has been pruned.
log::error!("Couldn't load the latest {IRREVOCABLY_RESOLVED} blocks. Please try again (Error: {})", e.into_inner());
std::process::exit(1);
}
);

// Build components
let gatekeeper = Arc::new(Gatekeeper::new(
tip.height,
Expand All @@ -276,23 +266,35 @@ async fn main() {
dbm.clone(),
));

let carrier = Carrier::new(rpc, bitcoind_reachable.clone(), tip.height);
let responder = Arc::new(Responder::new(
&last_n_blocks,
tip.height,
carrier,
gatekeeper.clone(),
dbm.clone(),
));
let watcher = Arc::new(Watcher::new(
gatekeeper.clone(),
responder.clone(),
&last_n_blocks[0..6],
tip.height,
tower_sk,
TowerId(tower_pk),
dbm.clone(),
));
let mut poller = ChainPoller::new(&mut derefed, Network::from_str(btc_network).unwrap());
let (responder, watcher) = {
let last_n_blocks = get_last_n_blocks(&mut poller, tip, IRREVOCABLY_RESOLVED as usize)
.await.unwrap_or_else(|e| {
// I'm pretty sure this can only happen if we are pulling blocks from the target to the prune height, and by the time we get to
// the end at least one has been pruned.
log::error!("Couldn't load the latest {IRREVOCABLY_RESOLVED} blocks. Please try again (Error: {})", e.into_inner());
std::process::exit(1);
}
);

let responder = Arc::new(Responder::new(
&last_n_blocks,
tip.height,
Carrier::new(rpc, bitcoind_reachable.clone(), tip.height),
gatekeeper.clone(),
dbm.clone(),
));
let watcher = Arc::new(Watcher::new(
gatekeeper.clone(),
responder.clone(),
&last_n_blocks[0..6],
tip.height,
tower_sk,
TowerId(tower_pk),
dbm.clone(),
));
(responder, watcher)
};

if watcher.is_fresh() & responder.is_fresh() & gatekeeper.is_fresh() {
log::info!("Fresh bootstrap");
Expand Down

0 comments on commit 492f472

Please sign in to comment.