Skip to content

Commit

Permalink
Remove the EventDb from Tributary scanner
Browse files Browse the repository at this point in the history
We used per-Transaction DB TXNs so on error, we don't have to rescan the entire
block yet only the rest of it. We prevented scanning multiple transactions by
tracking which we already had.

This is over-engineered and not worth it.
  • Loading branch information
kayabaNerve committed Dec 10, 2023
1 parent 09b25ac commit b3c82d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
10 changes: 1 addition & 9 deletions coordinator/src/tributary/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub enum Accumulation {
}

create_db!(
NewTributary {
Tributary {
SeraiBlockNumber: (hash: [u8; 32]) -> u64,
LastBlock: (genesis: [u8; 32]) -> [u8; 32],
FatalSlashes: (genesis: [u8; 32]) -> Vec<[u8; 32]>,
Expand All @@ -57,7 +57,6 @@ create_db!(
AttemptDb: (genesis: [u8; 32], topic: &Topic) -> u32,
DataReceived: (genesis: [u8; 32], data_spec: &DataSpecification) -> u16,
DataDb: (genesis: [u8; 32], data_spec: &DataSpecification, signer_bytes: &[u8; 32]) -> Vec<u8>,
EventDb: (id: [u8; 32], index: u32) -> (),
}
);

Expand Down Expand Up @@ -152,10 +151,3 @@ impl DataDb {
Accumulation::NotReady
}
}

impl EventDb {
pub fn handle_event(txn: &mut impl DbTxn, id: [u8; 32], index: u32) {
assert!(Self::get(txn, id, index).is_none());
Self::set(txn, id, index, &());
}
}
20 changes: 3 additions & 17 deletions coordinator/src/tributary/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
Db,
tributary::handle::{fatal_slash, handle_application_tx},
processors::Processors,
tributary::{TributarySpec, Transaction, LastBlock, EventDb},
tributary::{TributarySpec, Transaction, LastBlock},
P2p,
};

Expand Down Expand Up @@ -70,18 +70,8 @@ async fn handle_block<
) {
log::info!("found block for Tributary {:?}", spec.set());

let hash = block.hash();

let mut event_id = 0;
#[allow(clippy::explicit_counter_loop)] // event_id isn't TX index. It just currently lines up
let mut txn = db.txn();
for tx in block.transactions {
if EventDb::get(db, hash, event_id).is_some() {
event_id += 1;
continue;
}

let mut txn = db.txn();

match tx {
TributaryTransaction::Tendermint(TendermintTx::SlashEvidence(ev)) => {
// Since the evidence is on the chain, it should already have been validated
Expand Down Expand Up @@ -130,12 +120,8 @@ async fn handle_block<
.await;
}
}

EventDb::handle_event(&mut txn, hash, event_id);
txn.commit();

event_id += 1;
}
txn.commit();

// TODO: Trigger any necessary re-attempts
}
Expand Down

0 comments on commit b3c82d4

Please sign in to comment.