From ffdaa02e60482c9e0f0f563ee1caf2d93ce5c6ed Mon Sep 17 00:00:00 2001 From: Warm Beer Date: Mon, 9 Dec 2024 20:48:11 +0100 Subject: [PATCH] fix: put validation verify payment import and input --- ant-evm/src/data_payments.rs | 15 +++++++++++++++ ant-node/src/put_validation.rs | 19 ++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/ant-evm/src/data_payments.rs b/ant-evm/src/data_payments.rs index 9f959a93fa..f11486dd0e 100644 --- a/ant-evm/src/data_payments.rs +++ b/ant-evm/src/data_payments.rs @@ -77,6 +77,21 @@ impl ProofOfPayment { .any(|(_, quote)| quote.has_expired()) } + /// Returns all quotes by given peer id + pub fn quotes_by_peer(&self, peer_id: &PeerId) -> Vec<&PaymentQuote> { + self.peer_quotes + .iter() + .filter_map(|(id, quote)| { + if let Ok(id) = id.to_peer_id() { + if id == *peer_id { + return Some(quote); + } + } + None + }) + .collect() + } + /// verifies the proof of payment is valid for the given peer id pub fn verify_for(&self, peer_id: PeerId) -> bool { // make sure I am in the list of payees diff --git a/ant-node/src/put_validation.rs b/ant-node/src/put_validation.rs index 6bfa39b496..436980323c 100644 --- a/ant-node/src/put_validation.rs +++ b/ant-node/src/put_validation.rs @@ -7,7 +7,8 @@ // permissions and limitations relating to use of the SAFE Network Software. use crate::{node::Node, Error, Marker, Result}; -use ant_evm::{AttoTokens, ProofOfPayment, QUOTE_EXPIRATION_SECS}; +use ant_evm::payment_vault::verify_data_payment; +use ant_evm::{AttoTokens, ProofOfPayment}; use ant_networking::NetworkError; use ant_protocol::storage::Transaction; use ant_protocol::{ @@ -19,7 +20,6 @@ use ant_protocol::{ }; use ant_registers::SignedRegister; use libp2p::kad::{Record, RecordKey}; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; use xor_name::XorName; impl Node { @@ -619,14 +619,19 @@ impl Node { ))); } + let owned_payment_quotes = payment + .quotes_by_peer(&self_peer_id) + .iter() + .map(|quote| quote.hash()) + .collect(); + // check if payment is valid on chain let payments_to_verify = payment.digest(); debug!("Verifying payment for record {pretty_key}"); - let reward_amount = self - .evm_network() - .verify_data_payment(payments_to_verify) - .await - .map_err(|e| Error::EvmNetwork(format!("Failed to verify chunk payment: {e}")))?; + let reward_amount = + verify_data_payment(self.evm_network(), owned_payment_quotes, payments_to_verify) + .await + .map_err(|e| Error::EvmNetwork(format!("Failed to verify chunk payment: {e}")))?; debug!("Payment of {reward_amount:?} is valid for record {pretty_key}"); // Notify `record_store` that the node received a payment.