Skip to content

Commit

Permalink
Convert tributary to use create_db macro (#448)
Browse files Browse the repository at this point in the history
* chore: convert tributary to use create_db macro

* chore: fix fmt

* chore: break long line
  • Loading branch information
davidjohnbell authored Nov 22, 2023
1 parent 9ab2a2c commit 9df8c94
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 278 deletions.
6 changes: 3 additions & 3 deletions coordinator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use ::tributary::{

mod tributary;
use crate::tributary::{
TributarySpec, SignData, Transaction, TributaryDb, NonceDecider, scanner::RecognizedIdType,
TributarySpec, SignData, Transaction, NonceDecider, scanner::RecognizedIdType, PlanIds,
};

mod db;
Expand Down Expand Up @@ -256,7 +256,7 @@ async fn handle_processor_message<D: Db, P: P2p>(
.iter()
.filter_map(|plan| Some(plan.id).filter(|_| plan.key == key))
.collect::<Vec<_>>();
TributaryDb::<D>::set_plan_ids(&mut txn, tributary.spec.genesis(), *block, &plans);
PlanIds::set(&mut txn, &tributary.spec.genesis(), *block, &plans);

let tx = Transaction::SubstrateBlock(*block);
log::trace!(
Expand Down Expand Up @@ -472,7 +472,7 @@ async fn handle_processor_message<D: Db, P: P2p>(
// As for the safety of calling error_generating_key_pair, the processor is presumed
// to only send InvalidShare or GeneratedKeyPair for a given attempt
let mut txs = if let Some(faulty) =
crate::tributary::error_generating_key_pair::<D, _>(&txn, key, spec, id.attempt)
crate::tributary::error_generating_key_pair::<_>(&txn, key, spec, id.attempt)
{
vec![Transaction::RemoveParticipant(faulty)]
} else {
Expand Down
4 changes: 2 additions & 2 deletions coordinator/src/substrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use tokio::{sync::mpsc, time::sleep};
use crate::{
Db,
processors::Processors,
tributary::{TributarySpec, SeraiBlockNumber, TributaryDb},
tributary::{TributarySpec, SeraiBlockNumber, KeyPairDb},
};

mod db;
Expand Down Expand Up @@ -305,7 +305,7 @@ async fn handle_block<D: Db, Pro: Processors>(
// Immediately ensure this key pair is accessible to the tributary, before we fire any
// events off of it
let mut txn = db.0.txn();
TributaryDb::<D>::set_key_pair(&mut txn, set, &key_pair);
KeyPairDb::set(&mut txn, set, &key_pair);
txn.commit();

handle_key_gen(&mut db.0, processors, serai, &block, set, key_pair).await?;
Expand Down
10 changes: 5 additions & 5 deletions coordinator/src/tests/tributary/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sp_runtime::traits::Verify;

use tokio::time::sleep;

use serai_db::{DbTxn, Db, MemDb};
use serai_db::{Db, MemDb, DbTxn};

use processor_messages::{
key_gen::{self, KeyGenId},
Expand All @@ -23,7 +23,7 @@ use processor_messages::{
use tributary::{TransactionTrait, Tributary};

use crate::{
tributary::{TributaryDb, Transaction, TributarySpec, scanner::handle_new_blocks},
tributary::{Transaction, TributarySpec, scanner::handle_new_blocks},
tests::{
MemProcessors, LocalP2p,
tributary::{new_keys, new_spec, new_tributaries, run_tributaries, wait_for_tx_inclusion},
Expand Down Expand Up @@ -81,8 +81,8 @@ async fn dkg_test() {
key: &Zeroizing<<Ristretto as Ciphersuite>::F>,
spec: &TributarySpec,
tributary: &Tributary<MemDb, Transaction, LocalP2p>,
) -> (TributaryDb<MemDb>, MemProcessors) {
let mut scanner_db = TributaryDb(MemDb::new());
) -> (MemDb, MemProcessors) {
let mut scanner_db = MemDb::new();
let processors = MemProcessors::new();
handle_new_blocks::<_, _, _, _, _, _, LocalP2p>(
&mut scanner_db,
Expand Down Expand Up @@ -289,7 +289,7 @@ async fn dkg_test() {
if i != 0 {
scanner_db = &mut local_scanner_db;
}
let mut txn = scanner_db.0.txn();
let mut txn = scanner_db.txn();
let share =
crate::tributary::generated_key_pair::<MemDb>(&mut txn, key, &spec, &key_pair, 0).unwrap();
txn.commit();
Expand Down
Loading

0 comments on commit 9df8c94

Please sign in to comment.