From f561fa9ba1122f52b000da87e064c1ad84de23ba Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sun, 22 Oct 2023 19:15:52 -0400 Subject: [PATCH] Fix a bug which would attempt to create a transaction with N::MAX_INPUTS + 1 --- processor/src/multisigs/scheduler.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/processor/src/multisigs/scheduler.rs b/processor/src/multisigs/scheduler.rs index e0f9894b..ac45ef76 100644 --- a/processor/src/multisigs/scheduler.rs +++ b/processor/src/multisigs/scheduler.rs @@ -312,17 +312,18 @@ impl Scheduler { let utxos = utxo_chunks.remove(0); // If the last chunk exists and only has one output, don't try aggregating it - // Just immediately consider it another output + // Set it to be restored to UTXO set + let mut to_restore = None; if let Some(mut chunk) = utxo_chunks.pop() { if chunk.len() == 1 { - self.utxos.push(chunk.pop().unwrap()); + to_restore = Some(chunk.pop().unwrap()); } else { utxo_chunks.push(chunk); } } for chunk in utxo_chunks.drain(..) { - log::debug!("aggregating a chunk of {} inputs", N::MAX_INPUTS); + log::debug!("aggregating a chunk of {} inputs", chunk.len()); plans.push(Plan { key: self.key, inputs: chunk, @@ -377,6 +378,14 @@ impl Scheduler { }); } + // If there's a UTXO to restore, restore it + // This is down now as if there is a to_restore output, and it was inserted into self.utxos + // earlier, self.utxos.len() may become `N::MAX_INPUTS + 1` + // The prior block requires the len to be `<= N::MAX_INPUTS` + if let Some(to_restore) = to_restore { + self.utxos.push(to_restore); + } + txn.put(scheduler_key::(&self.key), self.serialize()); log::info!(