mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-22 02:34:29 +00:00
add new requests
This commit is contained in:
parent
ed887a7c85
commit
bc619b61eb
2 changed files with 39 additions and 5 deletions
|
@ -29,6 +29,10 @@ fn handle_blockchain_request(
|
||||||
) -> Result<BlockchainResponse, RuntimeError> {
|
) -> Result<BlockchainResponse, RuntimeError> {
|
||||||
match req {
|
match req {
|
||||||
BlockchainWriteRequest::WriteBlock(block) => write_block(env, block),
|
BlockchainWriteRequest::WriteBlock(block) => write_block(env, block),
|
||||||
|
BlockchainWriteRequest::WriteAltBlock(_) => todo!(),
|
||||||
|
BlockchainWriteRequest::StartReorg(_) => todo!(),
|
||||||
|
BlockchainWriteRequest::ReverseReorg(_) => todo!(),
|
||||||
|
BlockchainWriteRequest::FlushAltBlocks => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
ops::Range,
|
ops::Range,
|
||||||
};
|
};
|
||||||
|
use crate::{AltBlockInformation, ChainId};
|
||||||
use crate::types::{Chain, ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation};
|
use crate::types::{Chain, ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- ReadRequest
|
//---------------------------------------------------------------------------------------------------- ReadRequest
|
||||||
|
@ -112,6 +112,27 @@ pub enum BlockchainWriteRequest {
|
||||||
///
|
///
|
||||||
/// Input is an already verified block.
|
/// Input is an already verified block.
|
||||||
WriteBlock(VerifiedBlockInformation),
|
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
|
//---------------------------------------------------------------------------------------------------- Response
|
||||||
|
@ -198,11 +219,20 @@ pub enum BlockchainResponse {
|
||||||
FindFirstUnknown(Option<(usize, usize)>),
|
FindFirstUnknown(Option<(usize, usize)>),
|
||||||
|
|
||||||
//------------------------------------------------------ Writes
|
//------------------------------------------------------ Writes
|
||||||
/// Response to [`BlockchainWriteRequest::WriteBlock`].
|
/// A generic Ok response to indicate a request was successfully handled.
|
||||||
///
|
///
|
||||||
/// This response indicates that the requested block has
|
/// currently the response for:
|
||||||
/// successfully been written to the database without error.
|
/// - [`BlockchainWriteRequest::WriteBlock`]
|
||||||
WriteBlockOk,
|
/// - [`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
|
//---------------------------------------------------------------------------------------------------- Tests
|
||||||
|
|
Loading…
Reference in a new issue