From bc619b61eb06d54647dbba14530ebba6e110697f Mon Sep 17 00:00:00 2001 From: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com> Date: Sat, 31 Aug 2024 01:22:30 +0100 Subject: [PATCH] add new requests --- storage/blockchain/src/service/write.rs | 4 +++ types/src/blockchain.rs | 40 +++++++++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/storage/blockchain/src/service/write.rs b/storage/blockchain/src/service/write.rs index 816afc4..a2cc71c 100644 --- a/storage/blockchain/src/service/write.rs +++ b/storage/blockchain/src/service/write.rs @@ -29,6 +29,10 @@ fn handle_blockchain_request( ) -> Result { match req { BlockchainWriteRequest::WriteBlock(block) => write_block(env, block), + BlockchainWriteRequest::WriteAltBlock(_) => todo!(), + BlockchainWriteRequest::StartReorg(_) => todo!(), + BlockchainWriteRequest::ReverseReorg(_) => todo!(), + BlockchainWriteRequest::FlushAltBlocks => todo!(), } } diff --git a/types/src/blockchain.rs b/types/src/blockchain.rs index b502c3f..48eab29 100644 --- a/types/src/blockchain.rs +++ b/types/src/blockchain.rs @@ -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 + }, } //---------------------------------------------------------------------------------------------------- Tests