Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node): carry out quote's payee neighbourhood check #2513

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ant-networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ impl Network {
let mut all_quotes = vec![];
let mut quotes_to_pay = vec![];
for (peer, response) in responses {
info!(
"StoreCostReq for {record_address:?} received response: {response:?}");
info!("StoreCostReq for {record_address:?} received response: {response:?}");
match response {
Ok(Response::Query(QueryResponse::GetStoreQuote {
quote: Ok(quote),
Expand Down
4 changes: 1 addition & 3 deletions ant-networking/src/log_markers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ pub enum Marker<'a> {
/// Close records held (Used in VDash)
CloseRecordsLen(usize),
/// Quoting metrics
QuotingMetrics {
quoting_metrics: &'a QuotingMetrics,
},
QuotingMetrics { quoting_metrics: &'a QuotingMetrics },
/// The peer has been considered as bad
PeerConsideredAsBad { bad_peer: &'a PeerId },
/// We have been flagged as a bad node by a peer.
Expand Down
4 changes: 1 addition & 3 deletions ant-networking/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ impl NetworkMetricsRecorder {
}
});
}
Marker::QuotingMetrics {
quoting_metrics,
} => {
Marker::QuotingMetrics { quoting_metrics } => {
let _ = self.relevant_records.set(
quoting_metrics
.close_records_stored
Expand Down
5 changes: 3 additions & 2 deletions ant-node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ impl Node {
let record_key = key.to_record_key();
let self_id = network.peer_id();

let maybe_quoting_metrics = network.get_local_quoting_metrics(record_key.clone()).await;
let maybe_quoting_metrics =
network.get_local_quoting_metrics(record_key.clone()).await;

let storage_proofs = if let Some(nonce) = nonce {
Self::respond_x_closest_record_proof(
Expand All @@ -588,7 +589,7 @@ impl Node {
}
} else {
QueryResponse::GetStoreQuote {
quote: Self::create_quote_for_storecost(
quote: Self::create_quote_for_storecost(
network,
&key,
&quoting_metrics,
Expand Down
11 changes: 10 additions & 1 deletion ant-node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,21 @@ impl Node {
)));
}

// verify the claimed payees are all known to us within the certain range.
let closest_k_peers = self.network().get_closest_k_value_local_peers().await?;
let mut payees = payment.payees();
payees.retain(|peer_id| !closest_k_peers.contains(peer_id));
if !payees.is_empty() {
return Err(Error::InvalidRequest(format!(
"Payment quote has out-of-range payees {payees:?}"
)));
}

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}");
Expand Down
8 changes: 2 additions & 6 deletions ant-node/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ impl Node {
) -> Result<PaymentQuote, ProtocolError> {
let content = address.as_xorname().unwrap_or_default();
let timestamp = std::time::SystemTime::now();
let bytes = PaymentQuote::bytes_for_signing(
content,
timestamp,
quoting_metrics,
payment_address,
);
let bytes =
PaymentQuote::bytes_for_signing(content, timestamp, quoting_metrics, payment_address);

let Ok(signature) = network.sign(&bytes) else {
return Err(ProtocolError::QuoteGenerationFailed);
Expand Down
4 changes: 3 additions & 1 deletion autonomi/src/client/external_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ impl Client {
> {
let quote = self.get_store_quotes(content_addrs.clone()).await?;
let payments = quote.payments();
let free_chunks = content_addrs.filter(|addr| !quote.0.contains_key(addr)).collect();
let free_chunks = content_addrs
.filter(|addr| !quote.0.contains_key(addr))
.collect();
let quotes_per_addr = quote.0.into_iter().collect();

Ok((quotes_per_addr, payments, free_chunks))
Expand Down
2 changes: 1 addition & 1 deletion evmlib/src/external_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// permissions and limitations relating to use of the SAFE Network Software.

use crate::common::{Address, Amount, Calldata, QuoteHash, QuotePayment, U256};
use crate::contract::network_token::{NetworkToken, self};
use crate::contract::network_token::{self, NetworkToken};
use crate::contract::payment_vault::MAX_TRANSFERS_PER_TRANSACTION;
use crate::utils::http_provider;
use crate::Network;
Expand Down
2 changes: 1 addition & 1 deletion evmlib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use crate::common::{Address, Amount, QuotePayment, QuoteHash, TxHash, U256};
use crate::common::{Address, Amount, QuoteHash, QuotePayment, TxHash, U256};
use crate::contract::network_token::NetworkToken;
use crate::contract::payment_vault::handler::PaymentVaultHandler;
use crate::contract::payment_vault::MAX_TRANSFERS_PER_TRANSACTION;
Expand Down
6 changes: 1 addition & 5 deletions evmlib/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ async fn test_pay_for_quotes_and_data_payment_verification() {
let result = verify_data_payment(
&network,
vec![*quote_hash],
vec![(
*quote_hash,
QuotingMetrics::default(),
*reward_addr,
)],
vec![(*quote_hash, QuotingMetrics::default(), *reward_addr)],
)
.await;

Expand Down
Loading