serai-processor-bin

Moves the coordinator loop out of serai-bitcoin-processor, completing it.

Fixes a potential race condition in the message-queue regarding multiple
sockets sending messages at once.
This commit is contained in:
Luke Parker
2024-09-11 18:56:23 -04:00
parent fcd5fb85df
commit b6811f9015
22 changed files with 705 additions and 594 deletions

View File

@@ -72,6 +72,9 @@ pub(crate) fn queue_message(
// Assert one, and only one of these, is the coordinator
assert!(matches!(meta.from, Service::Coordinator) ^ matches!(meta.to, Service::Coordinator));
// Lock the queue
let queue_lock = QUEUES.read().unwrap()[&(meta.from, meta.to)].write().unwrap();
// Verify (from, to, intent) hasn't been prior seen
fn key(domain: &'static [u8], key: impl AsRef<[u8]>) -> Vec<u8> {
[&[u8::try_from(domain.len()).unwrap()], domain, key.as_ref()].concat()
@@ -93,7 +96,7 @@ pub(crate) fn queue_message(
DbTxn::put(&mut txn, intent_key, []);
// Queue it
let id = QUEUES.read().unwrap()[&(meta.from, meta.to)].write().unwrap().queue_message(
let id = queue_lock.queue_message(
&mut txn,
QueuedMessage {
from: meta.from,