Skip to content

Commit

Permalink
fix: put validation verify payment import and input
Browse files Browse the repository at this point in the history
  • Loading branch information
mickvandijke committed Dec 9, 2024
1 parent 918d236 commit ffdaa02
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
15 changes: 15 additions & 0 deletions ant-evm/src/data_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions ant-node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ffdaa02

Please sign in to comment.