From 84f0e6c26ec823938936bf02b38b0d7545890c9f Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Mon, 8 Jul 2024 20:33:00 -0400 Subject: [PATCH] Add additional documentation --- coins/monero/wallet/src/decoys.rs | 3 ++- coins/monero/wallet/src/extra.rs | 4 +++- coins/monero/wallet/src/output.rs | 2 +- coins/monero/wallet/src/scan.rs | 10 ++++++---- coins/monero/wallet/src/send/mod.rs | 14 ++++++++------ 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/coins/monero/wallet/src/decoys.rs b/coins/monero/wallet/src/decoys.rs index 503a7d44..ba11215e 100644 --- a/coins/monero/wallet/src/decoys.rs +++ b/coins/monero/wallet/src/decoys.rs @@ -94,7 +94,8 @@ async fn select_n( let mut candidates = Vec::with_capacity(remaining); while candidates.len() != remaining { // Use a gamma distribution, as Monero does - // TODO: Cite these constants + // https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c45 + // /src/wallet/wallet2.cpp#L142-L143 let mut age = Gamma::::new(19.28, 1.0 / 1.61).unwrap().sample(rng).exp(); #[allow(clippy::cast_precision_loss)] if age > TIP_APPLICATION { diff --git a/coins/monero/wallet/src/extra.rs b/coins/monero/wallet/src/extra.rs index 20cd3c8f..55f087f8 100644 --- a/coins/monero/wallet/src/extra.rs +++ b/coins/monero/wallet/src/extra.rs @@ -226,7 +226,9 @@ impl Extra { } /// The payment ID embedded within this extra. - // TODO: Monero distinguishes encrypted/unencrypted payment ID retrieval + // Monero finds the first nonce field and reads the payment ID from it: + // https://github.com/monero-project/monero/blob/ac02af92867590ca80b2779a7bbeafa99ff94dcb/ + // src/wallet/wallet2.cpp#L2709-L2752 pub fn payment_id(&self) -> Option { for field in &self.0 { if let ExtraField::Nonce(data) = field { diff --git a/coins/monero/wallet/src/output.rs b/coins/monero/wallet/src/output.rs index b896d5fd..1c405ca5 100644 --- a/coins/monero/wallet/src/output.rs +++ b/coins/monero/wallet/src/output.rs @@ -301,7 +301,7 @@ impl WalletOutput { /// The payment ID included with this output. /// - /// This field may be `Some` even if wallet would not return a payment ID. This will happen if + /// This field may be `Some` even if wallet2 would not return a payment ID. This will happen if /// the scanned output belongs to the subaddress which spent Monero within the transaction which /// created the output. If multiple subaddresses spent Monero within this transactions, the key /// image with the highest index is determined to be the subaddress considered as the one diff --git a/coins/monero/wallet/src/scan.rs b/coins/monero/wallet/src/scan.rs index 2572eb7d..a1f64f48 100644 --- a/coins/monero/wallet/src/scan.rs +++ b/coins/monero/wallet/src/scan.rs @@ -336,8 +336,8 @@ impl InternalScanner { } // If the block's version is >= 12, drop all unencrypted payment IDs - // TODO: Cite rule - // TODO: What if TX extra had multiple payment IDs embedded? + // https://github.com/monero-project/monero/blob/ac02af92867590ca80b2779a7bbeafa99ff94dcb/ + // src/wallet/wallet2.cpp#L2739-L2744 if block.header.hardfork_version >= 12 { for output in &mut res.0 { if matches!(output.metadata.payment_id, Some(PaymentId::Unencrypted(_))) { @@ -354,8 +354,10 @@ impl InternalScanner { /// /// When an output is successfully scanned, the output key MUST be checked against the local /// database for lack of prior observation. If it was prior observed, that output is an instance -/// of the burning bug (TODO: cite) and MAY be unspendable. Only the prior received output(s) or -/// the newly received output will be spendable (as spending one will burn all of them). +/// of the +/// [burning bug](https://web.getmonero.org/2018/09/25/a-post-mortum-of-the-burning-bug.html) and +/// MAY be unspendable. Only the prior received output(s) or the newly received output will be +/// spendable (as spending one will burn all of them). /// /// Once checked, the output key MUST be saved to the local database so future checks can be /// performed. diff --git a/coins/monero/wallet/src/send/mod.rs b/coins/monero/wallet/src/send/mod.rs index f63915d4..87d98d69 100644 --- a/coins/monero/wallet/src/send/mod.rs +++ b/coins/monero/wallet/src/send/mod.rs @@ -238,7 +238,6 @@ impl SignableTransaction { Err(SendError::NoInputs)?; } for input in &self.inputs { - // TODO: Add a function for the ring length if input.decoys().len() != match self.rct_type { RctType::ClsagBulletproof => 11, @@ -317,11 +316,14 @@ impl SignableTransaction { })?; } - // The actual limit is half the block size, and for the minimum block size of 300k, that'd be - // 150k - // wallet2 will only create transactions up to 100k bytes however - // TODO: Cite - const MAX_TX_SIZE: usize = 100_000; + // The limit is half the no-penalty block size + // https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454 + // /src/wallet/wallet2.cpp#L110766-L11085 + // https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454 + // /src/cryptonote_config.h#L61 + // https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454 + // /src/cryptonote_config.h#L64 + const MAX_TX_SIZE: usize = (300_000 / 2) - 600; if weight >= MAX_TX_SIZE { Err(SendError::TooLargeTransaction)?; }