Misc tidying of serai-db calls

This commit is contained in:
Luke Parker
2024-09-11 09:12:00 -04:00
parent 59fa49f750
commit 9b8c8f8231
6 changed files with 46 additions and 49 deletions

View File

@@ -111,14 +111,14 @@ async fn coordinator_loop<D: Db>(
);
// Queue the key to be activated upon the next Batch
db::KeyToActivate::send::<
db::KeyToActivate::<
<<KeyGenParams as ::key_gen::KeyGenParams>::ExternalNetworkCurve as Ciphersuite>::G,
>(txn, &key);
>::send(txn, &key);
// Set the external key, as needed by the signers
db::ExternalKeyForSessionForSigners::set::<
db::ExternalKeyForSessionForSigners::<
<<KeyGenParams as ::key_gen::KeyGenParams>::ExternalNetworkCurve as Ciphersuite>::G,
>(txn, session, &key);
>::set(txn, session, &key);
// This isn't cheap yet only happens for the very first set of keys
if scanner.is_none() {
@@ -130,9 +130,9 @@ async fn coordinator_loop<D: Db>(
// Since this session had its slashes reported, it has finished all its signature
// protocols and has been fully retired. We retire it from the signers accordingly
let key = db::ExternalKeyForSessionForSigners::take::<
let key = db::ExternalKeyForSessionForSigners::<
<<KeyGenParams as ::key_gen::KeyGenParams>::ExternalNetworkCurve as Ciphersuite>::G,
>(txn, session)
>::take(txn, session)
.unwrap()
.0;
@@ -147,9 +147,9 @@ async fn coordinator_loop<D: Db>(
} => {
let mut txn = txn.take().unwrap();
let scanner = scanner.as_mut().unwrap();
let key_to_activate = db::KeyToActivate::try_recv::<
let key_to_activate = db::KeyToActivate::<
<<KeyGenParams as ::key_gen::KeyGenParams>::ExternalNetworkCurve as Ciphersuite>::G,
>(&mut txn)
>::try_recv(&mut txn)
.map(|key| key.0);
// This is a cheap call as it internally just queues this to be done later
scanner.acknowledge_batch(

View File

@@ -107,7 +107,7 @@ create_db!(
pub(crate) struct ScannerGlobalDb<S: ScannerFeed>(PhantomData<S>);
impl<S: ScannerFeed> ScannerGlobalDb<S> {
pub(crate) fn has_any_key_been_queued(getter: &impl Get) -> bool {
ActiveKeys::get::<EncodableG<KeyFor<S>>>(getter).is_some()
ActiveKeys::<EncodableG<KeyFor<S>>>::get(getter).is_some()
}
/// Queue a key.
@@ -315,7 +315,7 @@ pub(crate) struct ReceiverScanData<S: ScannerFeed> {
db_channel! {
ScannerScanEventuality {
ScannedBlock: (empty_key: ()) -> Vec<u8>,
ScannedBlock: () -> Vec<u8>,
}
}
@@ -364,14 +364,14 @@ impl<S: ScannerFeed> ScanToEventualityDb<S> {
for output in &data.returns {
output.write(&mut buf).unwrap();
}
ScannedBlock::send(txn, (), &buf);
ScannedBlock::send(txn, &buf);
}
pub(crate) fn recv_scan_data(
txn: &mut impl DbTxn,
expected_block_number: u64,
) -> ReceiverScanData<S> {
let data =
ScannedBlock::try_recv(txn, ()).expect("receiving data for a scanned block not yet sent");
ScannedBlock::try_recv(txn).expect("receiving data for a scanned block not yet sent");
let mut data = data.as_slice();
let block_number = {
@@ -462,7 +462,7 @@ struct BlockBoundInInstructions {
db_channel! {
ScannerScanReport {
InInstructions: (empty_key: ()) -> BlockBoundInInstructions,
InInstructions: () -> BlockBoundInInstructions,
}
}
@@ -484,7 +484,6 @@ impl<S: ScannerFeed> ScanToReportDb<S> {
}
InInstructions::send(
txn,
(),
&BlockBoundInInstructions { block_number, returnable_in_instructions: buf },
);
}
@@ -493,7 +492,7 @@ impl<S: ScannerFeed> ScanToReportDb<S> {
txn: &mut impl DbTxn,
block_number: u64,
) -> InInstructionData<S> {
let data = InInstructions::try_recv(txn, ())
let data = InInstructions::try_recv(txn)
.expect("receiving InInstructions for a scanned block not yet sent");
assert_eq!(
block_number, data.block_number,
@@ -556,7 +555,7 @@ mod _public_db {
db_channel! {
ScannerPublic {
Batches: (empty_key: ()) -> Batch,
Batches: () -> Batch,
BatchesToSign: (key: &[u8]) -> Batch,
AcknowledgedBatches: (key: &[u8]) -> u32,
CompletedEventualities: (key: &[u8]) -> [u8; 32],
@@ -570,12 +569,12 @@ mod _public_db {
pub struct Batches;
impl Batches {
pub(crate) fn send(txn: &mut impl DbTxn, batch: &Batch) {
_public_db::Batches::send(txn, (), batch);
_public_db::Batches::send(txn, batch);
}
/// Receive a batch to publish.
pub fn try_recv(txn: &mut impl DbTxn) -> Option<Batch> {
_public_db::Batches::try_recv(txn, ())
_public_db::Batches::try_recv(txn)
}
}

View File

@@ -54,9 +54,7 @@ impl<S: ScannerFeed> ReportDb<S> {
}
pub(crate) fn take_block_number_for_batch(txn: &mut impl DbTxn, id: u32) -> Option<u64> {
let block_number = BlockNumberForBatch::get(txn, id)?;
BlockNumberForBatch::del(txn, id);
Some(block_number)
BlockNumberForBatch::take(txn, id)
}
pub(crate) fn save_external_key_for_session_to_sign_batch(
@@ -103,8 +101,7 @@ impl<S: ScannerFeed> ReportDb<S> {
txn: &mut impl DbTxn,
id: u32,
) -> Option<Vec<Option<ReturnInformation<S>>>> {
let buf = SerializedReturnAddresses::get(txn, id)?;
SerializedReturnAddresses::del(txn, id);
let buf = SerializedReturnAddresses::take(txn, id)?;
let mut buf = buf.as_slice();
let mut res = Vec::with_capacity(buf.len() / (32 + 1 + 8));

View File

@@ -37,7 +37,7 @@ pub(crate) enum Action<S: ScannerFeed> {
db_channel!(
ScannerSubstrate {
Actions: (empty_key: ()) -> ActionEncodable,
Actions: () -> ActionEncodable,
}
);
@@ -52,7 +52,6 @@ impl<S: ScannerFeed> SubstrateDb<S> {
) {
Actions::send(
txn,
(),
&ActionEncodable::AcknowledgeBatch(AcknowledgeBatchEncodable {
batch_id,
in_instruction_succeededs,
@@ -62,11 +61,11 @@ impl<S: ScannerFeed> SubstrateDb<S> {
);
}
pub(crate) fn queue_queue_burns(txn: &mut impl DbTxn, burns: Vec<OutInstructionWithBalance>) {
Actions::send(txn, (), &ActionEncodable::QueueBurns(burns));
Actions::send(txn, &ActionEncodable::QueueBurns(burns));
}
pub(crate) fn next_action(txn: &mut impl DbTxn) -> Option<Action<S>> {
let action_encodable = Actions::try_recv(txn, ())?;
let action_encodable = Actions::try_recv(txn)?;
Some(match action_encodable {
ActionEncodable::AcknowledgeBatch(AcknowledgeBatchEncodable {
batch_id,

View File

@@ -69,9 +69,7 @@ impl<S: ScannerFeed> Db<S> {
txn: &mut impl DbTxn,
output: &<OutputFor<S> as ReceivedOutput<KeyFor<S>, AddressFor<S>>>::Id,
) -> bool {
let res = AlreadyAccumulatedOutput::get(txn, output.as_ref()).is_some();
AlreadyAccumulatedOutput::del(txn, output.as_ref());
res
AlreadyAccumulatedOutput::take(txn, output.as_ref()).is_some()
}
pub(crate) fn queued_payments(