add new requests

This commit is contained in:
Boog900 2024-08-31 01:22:30 +01:00
parent ed887a7c85
commit bc619b61eb
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
2 changed files with 39 additions and 5 deletions

View file

@ -29,6 +29,10 @@ fn handle_blockchain_request(
) -> Result<BlockchainResponse, RuntimeError> {
match req {
BlockchainWriteRequest::WriteBlock(block) => write_block(env, block),
BlockchainWriteRequest::WriteAltBlock(_) => todo!(),
BlockchainWriteRequest::StartReorg(_) => todo!(),
BlockchainWriteRequest::ReverseReorg(_) => todo!(),
BlockchainWriteRequest::FlushAltBlocks => todo!(),
}
}

View file

@ -8,7 +8,7 @@ use std::{
collections::{HashMap, HashSet},
ops::Range,
};
use crate::{AltBlockInformation, ChainId};
use crate::types::{Chain, ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation};
//---------------------------------------------------------------------------------------------------- ReadRequest
@ -112,6 +112,27 @@ pub enum BlockchainWriteRequest {
///
/// Input is an already verified block.
WriteBlock(VerifiedBlockInformation),
/// Write an alternative block to the database,
///
/// Input is the alternative block.
WriteAltBlock(AltBlockInformation),
/// A request to start the re-org process.
///
/// The inner value is the [`ChainId`] of the alt-chain we want to re-org to.
///
/// This will:
/// - pop blocks from the main chain
/// - retrieve all alt-blocks in this alt-chain
/// - flush all other alt blocks
StartReorg(ChainId),
/// A request to reverse the re-org process.
///
/// The inner value is the [`ChainId`] of the old main chain.
///
/// It is invalid to call this with a [`ChainId`] that was not returned from [`BlockchainWriteRequest::StartReorg`].
ReverseReorg(ChainId),
/// A request to flush all alternative blocks.
FlushAltBlocks,
}
//---------------------------------------------------------------------------------------------------- Response
@ -198,11 +219,20 @@ pub enum BlockchainResponse {
FindFirstUnknown(Option<(usize, usize)>),
//------------------------------------------------------ Writes
/// Response to [`BlockchainWriteRequest::WriteBlock`].
/// A generic Ok response to indicate a request was successfully handled.
///
/// This response indicates that the requested block has
/// successfully been written to the database without error.
WriteBlockOk,
/// currently the response for:
/// - [`BlockchainWriteRequest::WriteBlock`]
/// - [`BlockchainWriteRequest::ReverseReorg`]
/// - [`BlockchainWriteRequest::FlushAltBlocks`]
Ok,
/// The response for [`BlockchainWriteRequest::StartReorg`].
StartReorg {
/// The [`ChainId`] of the old main chain blocks that were popped.
old_main_chain_id: ChainId,
/// The next alt chain blocks.
alt_chain: Vec<AltBlockInformation>
},
}
//---------------------------------------------------------------------------------------------------- Tests