Skip to content
Merged
Changes from all 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
24 changes: 16 additions & 8 deletions binaries/cuprated/src/blockchain/manager/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,19 @@ impl super::BlockchainManager {
let block_hash = block.hash();
let res = self.handle_incoming_alt_block(block, prepared_txs).await?;

if matches!(res, AddAltBlock::Cached(true)) {
if let AddAltBlock::NewlyCached(block_blob) = res {
info!(
alt_block = true,
hash = hex::encode(block_hash),
"Successfully added block"
);

let chain_height = self
.blockchain_context_service
.blockchain_context()
.chain_height;
Comment on lines +132 to +135
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

monerod seems to assume this is the block's height in its logs, which for alt blocks it might not be. This shouldn't be an issue just wanted to note it.


self.broadcast_block(block_blob, chain_height).await;
}

return Ok(IncomingBlockOk::AddedToAltChain);
Expand Down Expand Up @@ -324,7 +331,7 @@ impl super::BlockchainManager {
return;
}
// continue adding alt blocks.
Ok(AddAltBlock::Cached(_)) => (),
Ok(AddAltBlock::NewlyCached(_) | AddAltBlock::AlreadyCached) => (),
}
}

Expand Down Expand Up @@ -366,7 +373,7 @@ impl super::BlockchainManager {
};

match chain {
Some((Chain::Alt(_), _)) => return Ok(AddAltBlock::Cached(false)),
Some((Chain::Alt(_), _)) => return Ok(AddAltBlock::AlreadyCached),
Some((Chain::Main, _)) => anyhow::bail!("Alt block already in main chain"),
None => (),
}
Expand All @@ -386,14 +393,15 @@ impl super::BlockchainManager {
return Ok(AddAltBlock::Reorged);
}

let block_blob = Bytes::copy_from_slice(&alt_block_info.block_blob);
self.blockchain_write_handle
.ready()
.await
.expect(PANIC_CRITICAL_SERVICE_ERROR)
.call(BlockchainWriteRequest::WriteAltBlock(alt_block_info))
.await?;

Ok(AddAltBlock::Cached(true))
Ok(AddAltBlock::NewlyCached(block_blob))
}

/// Attempt a re-org with the given top block of the alt-chain.
Expand Down Expand Up @@ -693,10 +701,10 @@ impl super::BlockchainManager {

/// The result from successfully adding an alt-block.
enum AddAltBlock {
/// The alt-block was cached.
///
/// The inner `bool` is for if the block was cached before [`false`] or was cached during the call [`true`].
Cached(bool),
/// We already had this alt-block cached.
AlreadyCached,
/// The alt-block was newly cached. Contains the block blob.
NewlyCached(Bytes),
/// The chain was reorged.
Reorged,
}
Expand Down
Loading