Move heartbeat_tributaries from Tributary to TributaryReader

Reduces contention.
This commit is contained in:
Luke Parker
2023-09-25 17:15:36 -04:00
parent 4babf898d7
commit 0440e60645
3 changed files with 24 additions and 14 deletions

View File

@@ -344,7 +344,8 @@ impl<D: Db, T: TransactionTrait> TributaryReader<D, T> {
pub fn genesis(&self) -> [u8; 32] {
self.1
}
// Since these values are static, they can be safely read from the database without lock
// Since these values are static once set, they can be safely read from the database without lock
// acquisition
pub fn block(&self, hash: &[u8; 32]) -> Option<Block<T>> {
Blockchain::<D, T>::block_from_db(&self.0, self.1, hash)
@@ -363,4 +364,9 @@ impl<D: Db, T: TransactionTrait> TributaryReader<D, T> {
.commit(hash)
.map(|commit| Commit::<Validators>::decode(&mut commit.as_ref()).unwrap().end_time)
}
// This isn't static, yet can be read with only minor discrepancy risks
pub fn tip(&self) -> [u8; 32] {
Blockchain::<D, T>::tip_from_db(&self.0, self.1)
}
}