Fix which key is used to index substrate_signers on ScannerEvent::Block

First notably bug found by docker tests.
This commit is contained in:
Luke Parker 2023-07-24 19:38:29 -04:00
parent 5e565fa3ef
commit f05e909d0e
No known key found for this signature in database

View file

@ -342,12 +342,15 @@ async fn handle_coordinator_msg<D: Db, C: Coin, Co: Coordinator>(
} }
// Find the first block to do so // Find the first block to do so
let mut earliest = (get_latest_block_number(coin).await + 1).saturating_sub(C::CONFIRMATIONS); let mut earliest =
(get_latest_block_number(coin).await + 1).saturating_sub(C::CONFIRMATIONS);
assert!(get_block(coin, earliest).await.time() >= context.serai_time); assert!(get_block(coin, earliest).await.time() >= context.serai_time);
// earliest > 0 prevents a panic if Serai creates keys before the genesis block // earliest > 0 prevents a panic if Serai creates keys before the genesis block
// which... should be impossible // which... should be impossible
// Yet a prevented panic is a prevented panic // Yet a prevented panic is a prevented panic
while (earliest > 0) && (get_block(coin, earliest - 1).await.time() >= context.serai_time) { while (earliest > 0) &&
(get_block(coin, earliest - 1).await.time() >= context.serai_time)
{
earliest -= 1; earliest -= 1;
} }
@ -663,8 +666,6 @@ async fn run<C: Coin, D: Db, Co: Coordinator>(mut raw_db: D, coin: C, mut coordi
match msg.unwrap() { match msg.unwrap() {
ScannerEvent::Block { key, block, batch, outputs } => { ScannerEvent::Block { key, block, batch, outputs } => {
let key = key.to_bytes().as_ref().to_vec();
let mut block_hash = [0; 32]; let mut block_hash = [0; 32];
block_hash.copy_from_slice(block.as_ref()); block_hash.copy_from_slice(block.as_ref());
@ -700,7 +701,12 @@ async fn run<C: Coin, D: Db, Co: Coordinator>(mut raw_db: D, coin: C, mut coordi
}; };
// Start signing this batch // Start signing this batch
tributary_mutable.substrate_signers.get_mut(&key).unwrap().sign(&mut txn, batch).await; tributary_mutable
.substrate_signers
.get_mut(tributary_mutable.key_gen.keys(&key).0.group_key().to_bytes().as_slice())
.unwrap()
.sign(&mut txn, batch)
.await;
}, },
ScannerEvent::Completed(id, tx) => { ScannerEvent::Completed(id, tx) => {