diff --git a/processor/src/multisigs/mod.rs b/processor/src/multisigs/mod.rs index d0892381b..a9a694f99 100644 --- a/processor/src/multisigs/mod.rs +++ b/processor/src/multisigs/mod.rs @@ -337,6 +337,8 @@ impl MultisigManager { } fn refund_plan(output: &N::Output, refund_to: N::Address) -> Plan { + log::info!("creating refund plan for {}", hex::encode(output.id())); + assert_eq!(output.kind(), OutputType::External); Plan { key: output.key(), inputs: vec![output.clone()], @@ -639,6 +641,10 @@ impl MultisigManager { if let Some(refund_to) = MultisigsDb::::take_refund(txn, output.id().as_ref()) { // If this isn't a valid refund address, accumulate this output let Ok(refund_to) = refund_to.consume().try_into() else { + log::info!( + "set refund for {} didn't have a valid address to refund to", + hex::encode(output.id()) + ); return true; }; plans.push(Self::refund_plan(output, refund_to)); @@ -830,6 +836,7 @@ impl MultisigManager { let (refund_to, instruction) = instruction_from_output::(&output); let refund = |txn| { if let Some(refund_to) = refund_to { + log::info!("setting refund for output {}", hex::encode(output.id())); MultisigsDb::::set_refund(txn, output.id().as_ref(), refund_to); } }; diff --git a/tests/processor/src/tests/batch.rs b/tests/processor/src/tests/batch.rs index cdc094025..40dfcc0c0 100644 --- a/tests/processor/src/tests/batch.rs +++ b/tests/processor/src/tests/batch.rs @@ -231,7 +231,7 @@ fn batch_test() { let mut serai_address = [0; 32]; OsRng.fill_bytes(&mut serai_address); let instruction = - if i == 1 { Some(InInstruction::Transfer(SeraiAddress(serai_address))) } else { None }; + if i == 0 { Some(InInstruction::Transfer(SeraiAddress(serai_address))) } else { None }; // Send into the processor's wallet let (tx, balance_sent) = @@ -258,9 +258,9 @@ fn batch_test() { network, id: i, block: BlockHash(block_with_tx.unwrap()), - instructions: if let Some(instruction) = instruction { + instructions: if let Some(instruction) = &instruction { vec![InInstructionWithBalance { - instruction, + instruction: instruction.clone(), balance: Balance { coin: balance_sent.coin, amount: Amount( @@ -311,7 +311,7 @@ fn batch_test() { let serai_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs(); for coordinator in &mut coordinators { - assert!(substrate_block( + let plans = substrate_block( coordinator, messages::substrate::CoordinatorMessage::SubstrateBlock { context: SubstrateContext { @@ -324,8 +324,35 @@ fn batch_test() { batches: vec![batch.batch.id], }, ) - .await - .is_empty()); + .await; + if instruction.is_some() || (instruction.is_none() && (network == NetworkId::Monero)) { + assert!(plans.is_empty()); + } else { + // If no instruction was used, and the processor csn presume the origin, it'd have + // created a refund Plan + assert_eq!(plans.len(), 1); + } + } + } + + // With the latter InInstruction not existing, we should've triggered a refund if the origin + // was detectable + // Check this is trying to sign a Plan + if network != NetworkId::Monero { + let mut refund_id = None; + for coordinator in &mut coordinators { + match coordinator.recv_message().await { + messages::ProcessorMessage::Sign(messages::sign::ProcessorMessage::Preprocess { + id, + .. + }) => { + if refund_id.is_none() { + refund_id = Some(id.clone()); + } + assert_eq!(refund_id.as_ref().unwrap(), &id); + } + _ => panic!("processor didn't send preprocess for expected refund transaction"), + } } } });