Skip to content

Commit

Permalink
Add logging for daemon connect and update tip
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil McLean committed Apr 17, 2024
1 parent ce4764c commit a64561a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
10 changes: 9 additions & 1 deletion src/bin/electrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,20 @@ fn run_server(config: Arc<Config>) -> Result<()> {
break;
}

debug!("checking for new blocks, current_tip={}", tip);

// Index new blocks
let current_tip = daemon.getbestblockhash()?;

debug!("new blockhash from bitcoind={}", current_tip);

if current_tip != tip {
debug!("updating index to {}", current_tip);
indexer.update(&daemon)?;
tip = current_tip;
};
} else {
debug!("tip unchanged, no update");
}

// Update mempool
if let Err(e) = Mempool::update(&mempool, &daemon) {
Expand Down
1 change: 1 addition & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl Connection {
}

fn reconnect(&self) -> Result<Connection> {
debug!("reconnect to {}", self.addr);
Connection::new(self.addr, self.cookie_getter.clone(), self.signal.clone())
}

Expand Down
6 changes: 3 additions & 3 deletions src/new_index/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ impl Mempool {
&mut self.asset_issuance,
);
}
log_fn_duration("mempool::add", t.elapsed().as_micros());
// log_fn_duration("mempool::add", t.elapsed().as_micros());
}

pub fn lookup_txo(&self, outpoint: &OutPoint) -> Result<TxOut> {
Expand Down Expand Up @@ -437,7 +437,7 @@ impl Mempool {

let mut txos = confirmed_txos;
txos.extend(mempool_txos);
log_fn_duration("mempool::lookup_txos", t.elapsed().as_micros());
// log_fn_duration("mempool::lookup_txos", t.elapsed().as_micros());
Ok(txos)
}

Expand Down Expand Up @@ -541,7 +541,7 @@ impl Mempool {
mempool.update_backlog_stats();
}
}
log_fn_duration("mempool::update", t.elapsed().as_micros());
// log_fn_duration("mempool::update", t.elapsed().as_micros());
Ok(())
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl ChainQuery {
}

pub fn get_block_txids(&self, hash: &BlockHash) -> Option<Vec<Txid>> {
let _timer = self.start_timer("get_block_txids");
// let _timer = self.start_timer("get_block_txids");

if self.light_mode {
// TODO fetch block as binary from REST API instead of as hex
Expand All @@ -393,7 +393,7 @@ impl ChainQuery {
}

pub fn get_block_meta(&self, hash: &BlockHash) -> Option<BlockMeta> {
let _timer = self.start_timer("get_block_meta");
// let _timer = self.start_timer("get_block_meta");

if self.light_mode {
let blockinfo = self.daemon.getblock_raw(hash, 1).ok()?;
Expand Down Expand Up @@ -866,20 +866,20 @@ impl ChainQuery {
}

pub fn lookup_txo(&self, outpoint: &OutPoint) -> Option<TxOut> {
let _timer = self.start_timer("lookup_txo");
//let _timer = self.start_timer("lookup_txo");
lookup_txo(&self.store.txstore_db, outpoint)
}

pub fn lookup_txos(&self, outpoints: &BTreeSet<OutPoint>) -> HashMap<OutPoint, TxOut> {
let _timer = self.start_timer("lookup_txos");
//let _timer = self.start_timer("lookup_txos");
lookup_txos(&self.store.txstore_db, outpoints, false, self.num_threads)
}

pub fn lookup_avail_txos(&self, outpoints: &BTreeSet<OutPoint>) -> HashMap<OutPoint, TxOut> {
let t = Instant::now();
let _timer = self.start_timer("lookup_available_txos");
//let t = Instant::now();
// let _timer = self.start_timer("lookup_available_txos");
let res = lookup_txos(&self.store.txstore_db, outpoints, true, self.num_threads);
log_fn_duration("chainquery::lookup_avail_txos", t.elapsed().as_micros());
//log_fn_duration("chainquery::lookup_avail_txos", t.elapsed().as_micros());
res
}

Expand Down Expand Up @@ -1059,7 +1059,7 @@ fn lookup_txos(
.thread_name(|i| format!("lookup-txo-{}", i))
.build()
.unwrap();
log_fn_duration("schema::ThreadPoolBuilder", t.elapsed().as_micros());
//log_fn_duration("schema::ThreadPoolBuilder", t.elapsed().as_micros());
let t2 = Instant::now();
let res = pool.install(|| {
outpoints
Expand All @@ -1076,8 +1076,8 @@ fn lookup_txos(
})
.collect()
});
log_fn_duration("schema::pool::install", t2.elapsed().as_micros());
log_fn_duration("schema::lookup_txos", t.elapsed().as_micros());
//log_fn_duration("schema::pool::install", t2.elapsed().as_micros());
//log_fn_duration("schema::lookup_txos", t.elapsed().as_micros());
res
}

Expand All @@ -1086,7 +1086,7 @@ fn lookup_txo(txstore_db: &DB, outpoint: &OutPoint) -> Option<TxOut> {
let res = txstore_db
.get(&TxOutRow::key(&outpoint))
.map(|val| deserialize(&val).expect("failed to parse TxOut"));
log_fn_duration("schema::lookup_txo", t.elapsed().as_micros());
// log_fn_duration("schema::lookup_txo", t.elapsed().as_micros());
res
}

Expand Down

0 comments on commit a64561a

Please sign in to comment.