write: impl write_block()

This commit is contained in:
hinto.janai 2024-04-23 13:20:57 -04:00
parent c65eb0a3ca
commit a598fc38d2
No known key found for this signature in database
GPG key ID: D47CE05FA175A499

View file

@ -15,9 +15,11 @@ use cuprate_types::{
}; };
use crate::{ use crate::{
env::{Env, EnvInner},
error::RuntimeError, error::RuntimeError,
service::types::{ResponseReceiver, ResponseResult, ResponseSender}, service::types::{ResponseReceiver, ResponseResult, ResponseSender},
ConcreteEnv, Env, transaction::TxRw,
ConcreteEnv,
}; };
//---------------------------------------------------------------------------------------------------- Constants //---------------------------------------------------------------------------------------------------- Constants
@ -225,6 +227,28 @@ impl DatabaseWriter {
/// [`WriteRequest::WriteBlock`]. /// [`WriteRequest::WriteBlock`].
#[inline] #[inline]
#[allow(clippy::significant_drop_tightening)]
fn write_block(env: &ConcreteEnv, block: &VerifiedBlockInformation) -> ResponseResult { fn write_block(env: &ConcreteEnv, block: &VerifiedBlockInformation) -> ResponseResult {
todo!() let env_inner = env.env_inner();
let tx_rw = env_inner.tx_rw()?;
let result = {
let mut tables_mut = env_inner.open_tables_mut(&tx_rw)?;
crate::ops::block::add_block(block, &mut tables_mut)
};
match result {
Ok(()) => {
tx_rw.commit()?;
Ok(Response::WriteBlockOk)
}
Err(e) => {
// INVARIANT: ensure database atomicity by aborting
// the transaction on `add_block()` failures.
tx_rw
.abort()
.expect("TODO: if we cannot maintain atomicity by aborting, should we panic?");
Err(e)
}
}
} }