From 5999f5d65a003afca675166fe12605f7f19ad68b Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Fri, 30 Aug 2024 00:20:34 -0400 Subject: [PATCH] Route the DB w.r.t. forwarded outputs' information --- processor/scanner/src/db.rs | 47 +++++++++++------------- processor/scanner/src/eventuality/mod.rs | 1 + 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/processor/scanner/src/db.rs b/processor/scanner/src/db.rs index 698bf546..cc86afeb 100644 --- a/processor/scanner/src/db.rs +++ b/processor/scanner/src/db.rs @@ -101,6 +101,8 @@ create_db!( */ // This collapses from `bool` to `()`, using if the value was set for true and false otherwise NotableBlock: (number: u64) -> (), + + SerializedForwardedOutput: (id: &[u8]) -> Vec, } ); @@ -267,7 +269,15 @@ impl ScannerGlobalDb { getter: &impl Get, output: & as ReceivedOutput, AddressFor>>::Id, ) -> Option<(Option>, InInstructionWithBalance)> { - todo!("TODO") + let buf = SerializedForwardedOutput::get(getter, output.as_ref())?; + let mut buf = buf.as_slice(); + + let mut opt = [0xff]; + buf.read_exact(&mut opt).unwrap(); + assert!((opt[0] == 0) || (opt[0] == 1)); + + let address = (opt[0] == 1).then(|| AddressFor::::read(&mut buf).unwrap()); + Some((address, InInstructionWithBalance::decode(&mut IoReader(buf)).unwrap())) } } @@ -321,32 +331,19 @@ impl ScanToEventualityDb { NotableBlock::set(txn, block_number, &()); } - /* - TODO + // Save all the forwarded outputs' data + for forward in &data.forwards { + let mut buf = vec![]; + if let Some(address) = &forward.return_address { + buf.write_all(&[1]).unwrap(); + address.write(&mut buf).unwrap(); + } else { + buf.write_all(&[0]).unwrap(); + } + forward.in_instruction.encode_to(&mut buf); - SerializedForwardedOutputsIndex: (block_number: u64) -> Vec, - SerializedForwardedOutput: (output_id: &[u8]) -> Vec, - - pub(crate) fn save_output_being_forwarded( - txn: &mut impl DbTxn, - block_forwarded_from: u64, - output: &OutputWithInInstruction, - ) { - let mut buf = Vec::with_capacity(128); - output.write(&mut buf).unwrap(); - - let id = output.output.id(); - - // Save this to an index so we can later fetch all outputs to forward - let mut forwarded_outputs = SerializedForwardedOutputsIndex::get(txn, block_forwarded_from) - .unwrap_or(Vec::with_capacity(32)); - forwarded_outputs.extend(id.as_ref()); - SerializedForwardedOutputsIndex::set(txn, block_forwarded_from, &forwarded_outputs); - - // Save the output itself - SerializedForwardedOutput::set(txn, id.as_ref(), &buf); + SerializedForwardedOutput::set(txn, forward.output.id().as_ref(), &buf); } - */ let mut buf = vec![]; buf.write_all(&data.block_number.to_le_bytes()).unwrap(); diff --git a/processor/scanner/src/eventuality/mod.rs b/processor/scanner/src/eventuality/mod.rs index 9068769b..3be7f3ce 100644 --- a/processor/scanner/src/eventuality/mod.rs +++ b/processor/scanner/src/eventuality/mod.rs @@ -116,6 +116,7 @@ impl> EventualityTask { Self { db, feed, scheduler } } + #[allow(clippy::type_complexity)] fn keys_and_keys_with_stages( &self, block_number: u64,