Skip to content

Commit

Permalink
Merge branch 'maidsafe:main' into drop-Rpc-replace-Metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ermineJose authored Jan 31, 2025
2 parents 65c07df + 3cf18dd commit 7f6233c
Show file tree
Hide file tree
Showing 52 changed files with 2,067 additions and 712 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ node_modules/

# MkDocs
site/
/evmlib/tests/private.rs
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions ant-evm/src/data_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ impl ProofOfPayment {
}
true
}

/// Verifies whether all quotes were made for the expected data type.
pub fn verify_data_type(&self, data_type: u32) -> bool {
for (_, quote) in self.peer_quotes.iter() {
if quote.quoting_metrics.data_type != data_type {
return false;
}
}

true
}
}

/// A payment quote to store data given by a node to a client
Expand Down Expand Up @@ -231,6 +242,7 @@ impl PaymentQuote {
data_size: 0,
data_type: 0,
close_records_stored: 0,
records_per_type: vec![],
max_records: 0,
received_payment_count: 0,
live_time: 0,
Expand Down
22 changes: 17 additions & 5 deletions ant-networking/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub enum LocalSwarmCmd {
AddLocalRecordAsStored {
key: RecordKey,
record_type: ValidationType,
data_type: DataTypes,
},
/// Add a peer to the blocklist
AddPeerToBlockList {
Expand Down Expand Up @@ -235,10 +236,14 @@ impl Debug for LocalSwarmCmd {
PrettyPrintRecordKey::from(key)
)
}
LocalSwarmCmd::AddLocalRecordAsStored { key, record_type } => {
LocalSwarmCmd::AddLocalRecordAsStored {
key,
record_type,
data_type,
} => {
write!(
f,
"LocalSwarmCmd::AddLocalRecordAsStored {{ key: {:?}, record_type: {record_type:?} }}",
"LocalSwarmCmd::AddLocalRecordAsStored {{ key: {:?}, record_type: {record_type:?}, data_type: {data_type:?} }}",
PrettyPrintRecordKey::from(key)
)
}
Expand Down Expand Up @@ -778,7 +783,11 @@ impl SwarmDriver {
return Err(err.into());
};
}
LocalSwarmCmd::AddLocalRecordAsStored { key, record_type } => {
LocalSwarmCmd::AddLocalRecordAsStored {
key,
record_type,
data_type,
} => {
info!(
"Adding Record locally, for {:?} and {record_type:?}",
PrettyPrintRecordKey::from(&key)
Expand All @@ -788,7 +797,7 @@ impl SwarmDriver {
.behaviour_mut()
.kademlia
.store_mut()
.mark_as_stored(key, record_type);
.mark_as_stored(key, record_type, data_type);
// Reset counter on any success HDD write.
self.hard_disk_write_error = 0;
}
Expand Down Expand Up @@ -1119,7 +1128,10 @@ impl SwarmDriver {
);
let request = Request::Cmd(Cmd::Replicate {
holder: NetworkAddress::from_peer(self.self_peer_id),
keys: all_records,
keys: all_records
.into_iter()
.map(|(addr, val_type, _data_type)| (addr, val_type))
.collect(),
});
for peer_id in replicate_targets {
self.queue_network_swarm_cmd(NetworkSwarmCmd::SendRequest {
Expand Down
8 changes: 7 additions & 1 deletion ant-networking/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use libp2p::{
};

use ant_evm::{PaymentQuote, ProofOfPayment};
use ant_protocol::storage::DataTypes;
#[cfg(feature = "open-metrics")]
use ant_protocol::CLOSE_GROUP_SIZE;
use ant_protocol::{
Expand Down Expand Up @@ -137,7 +138,12 @@ pub enum NetworkEvent {
/// Fresh replicate to fetch
FreshReplicateToFetch {
holder: NetworkAddress,
keys: Vec<(NetworkAddress, ValidationType, Option<ProofOfPayment>)>,
keys: Vec<(
NetworkAddress,
DataTypes,
ValidationType,
Option<ProofOfPayment>,
)>,
},
}

Expand Down
30 changes: 5 additions & 25 deletions ant-networking/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,13 @@
// 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::{driver::GetRecordCfg, Network, NetworkError, Result};
use ant_protocol::storage::{DataTypes, GraphEntry, GraphEntryAddress};
use crate::{NetworkError, Result};
use ant_protocol::storage::{DataTypes, GraphEntry};
use ant_protocol::{
storage::{try_deserialize_record, RecordHeader, RecordKind, RetryStrategy},
NetworkAddress, PrettyPrintRecordKey,
storage::{try_deserialize_record, RecordHeader, RecordKind},
PrettyPrintRecordKey,
};
use libp2p::kad::{Quorum, Record};

impl Network {
/// Gets GraphEntry at GraphEntryAddress from the Network.
pub async fn get_graph_entry(&self, address: GraphEntryAddress) -> Result<Vec<GraphEntry>> {
let key = NetworkAddress::from_graph_entry_address(address).to_record_key();
let get_cfg = GetRecordCfg {
get_quorum: Quorum::All,
retry_strategy: Some(RetryStrategy::Quick),
target_record: None,
expected_holders: Default::default(),
};
let record = self.get_record_from_network(key.clone(), &get_cfg).await?;
debug!(
"Got record from the network, {:?}",
PrettyPrintRecordKey::from(&record.key)
);

get_graph_entry_from_record(&record)
}
}
use libp2p::kad::Record;

pub fn get_graph_entry_from_record(record: &Record) -> Result<Vec<GraphEntry>> {
let header = RecordHeader::from_record(record)?;
Expand Down
13 changes: 10 additions & 3 deletions ant-networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,19 @@ impl Network {
if !storage_proofs.is_empty() {
debug!("Storage proofing during GetStoreQuote to be implemented.");
}

// Check the quote itself is valid.
if !quote.check_is_signed_by_claimed_peer(peer) {
warn!("Received invalid quote from {peer_address:?}, {quote:?}");
continue;
}

// Check if the returned data type matches the request
if quote.quoting_metrics.data_type != data_type {
warn!("Received invalid quote from {peer_address:?}, {quote:?}. Data type did not match the request.");
continue;
}

all_quotes.push((peer_address.clone(), quote.clone()));
quotes_to_pay.push((peer, quote));
}
Expand Down Expand Up @@ -617,7 +624,7 @@ impl Network {
continue;
};

if !pointer.verify() {
if !pointer.verify_signature() {
warn!("Rejecting Pointer for {pretty_key} PUT with invalid signature");
continue;
}
Expand All @@ -639,15 +646,15 @@ impl Network {
continue;
};

if !scratchpad.is_valid() {
if !scratchpad.verify_signature() {
warn!(
"Rejecting Scratchpad for {pretty_key} PUT with invalid signature"
);
continue;
}

if let Some(old) = &valid_scratchpad {
if old.count() >= scratchpad.count() {
if old.counter() >= scratchpad.counter() {
info!("Rejecting Scratchpad for {pretty_key} with lower count than the previous one");
continue;
}
Expand Down
Loading

0 comments on commit 7f6233c

Please sign in to comment.