Bug fix update finalized blockhash

This commit is contained in:
godmodegalactus 2024-03-22 09:22:51 +01:00
parent 9fabdab32b
commit 5be4d2e755
No known key found for this signature in database
GPG Key ID: 22DA4A30887FDA3C
1 changed files with 18 additions and 17 deletions

View File

@ -114,10 +114,18 @@ impl BlockInformationStore {
std::sync::atomic::Ordering::Relaxed,
);
}
// check if the block has already been added with higher commitment level
match self.blocks.get_mut(&block_info.blockhash) {
Some(mut prev_block_info) => {
let should_update = match prev_block_info.commitment_config.commitment {
// update latest block
{
let latest_block = self.get_latest_block_arc(commitment_config);
if slot > latest_block.read().await.slot {
*latest_block.write().await = block_info.clone();
}
}
match self.blocks.entry(block_info.blockhash.clone()) {
dashmap::mapref::entry::Entry::Occupied(entry) => {
let should_update = match entry.get().commitment_config.commitment {
CommitmentLevel::Finalized => false, // should never update blocks of finalized commitment
CommitmentLevel::Confirmed => {
commitment_config == CommitmentConfig::finalized()
@ -127,23 +135,16 @@ impl BlockInformationStore {
|| commitment_config == CommitmentConfig::finalized()
}
};
if !should_update {
return false;
if should_update {
entry.replace_entry(block_info);
}
*prev_block_info = block_info.clone();
should_update
}
None => {
self.blocks
.insert(block_info.blockhash.clone(), block_info.clone());
dashmap::mapref::entry::Entry::Vacant(entry) => {
entry.insert(block_info);
true
}
}
// update latest block
let latest_block = self.get_latest_block_arc(commitment_config);
if slot > latest_block.read().await.slot {
*latest_block.write().await = block_info;
}
true
}
pub async fn clean(&self) {