Add a new primitive of a DB-backed channel

The coordinator already had one of these, albeit implemented much worse than
the one now properly introduced. It had to either be sending or receiving,
whereas the new one can do both at the same time.

This replaces said instance and enables pleasant patterns when implementing the
processor/coordinator.
This commit is contained in:
Luke Parker
2023-11-19 02:05:01 -05:00
parent bd14db9f76
commit 74a8df4c7b
5 changed files with 83 additions and 72 deletions

View File

@@ -368,7 +368,6 @@ async fn handle_new_blocks<D: Db, Pro: Processors>(
// TODO: If this block directly builds off a cosigned block *and* doesn't contain events, mark
// cosigned,
// TODO: Can we remove any of these events while maintaining security?
{
// If:
// A) This block has events and it's been at least X blocks since the last cosign or
@@ -533,16 +532,14 @@ async fn handle_new_blocks<D: Db, Pro: Processors>(
if let Some(has_no_cosigners) = has_no_cosigners {
log::debug!("{} had no cosigners available, marking as cosigned", has_no_cosigners.number());
SubstrateDb::<D>::set_latest_cosigned_block(&mut txn, has_no_cosigners.number());
txn.commit();
} else {
CosignTriggered::set(&mut txn, &());
let mut txn = CosignTxn::new(txn);
for (set, block, hash) in cosign {
log::debug!("cosigning {block} with {:?} {:?}", set.network, set.session);
CosignTransactions::append_cosign(&mut txn, set, block, hash);
}
txn.commit();
}
txn.commit();
}
// Reduce to the latest cosigned block