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: rename linked list to graph #2587

Merged
merged 1 commit into from
Dec 31, 2024
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 Cargo.lock

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

4 changes: 2 additions & 2 deletions ant-networking/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,14 @@ impl SwarmDriver {
RecordKind::Chunk => RecordType::Chunk,
RecordKind::Scratchpad => RecordType::Scratchpad,
RecordKind::Pointer => RecordType::Pointer,
RecordKind::LinkedList | RecordKind::Register => {
RecordKind::GraphEntry | RecordKind::Register => {
let content_hash = XorName::from_content(&record.value);
RecordType::NonChunk(content_hash)
}
RecordKind::ChunkWithPayment
| RecordKind::RegisterWithPayment
| RecordKind::PointerWithPayment
| RecordKind::LinkedListWithPayment
| RecordKind::GraphEntryWithPayment
| RecordKind::ScratchpadWithPayment => {
error!("Record {record_key:?} with payment shall not be stored locally.");
return Err(NetworkError::InCorrectRecordHeader);
Expand Down
9 changes: 4 additions & 5 deletions ant-networking/src/error.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 ant_protocol::storage::LinkedListAddress;
use ant_protocol::storage::GraphEntryAddress;
use ant_protocol::{messages::Response, storage::RecordKind, NetworkAddress, PrettyPrintRecordKey};
use libp2p::{
kad::{self, QueryId, Record},
Expand Down Expand Up @@ -123,14 +123,13 @@ pub enum NetworkError {
#[error("Record header is incorrect")]
InCorrectRecordHeader,


// ---------- Chunk Errors
#[error("Failed to verify the ChunkProof with the provided quorum")]
FailedToVerifyChunkProof(NetworkAddress),

// ---------- LinkedList Errors
#[error("Linked list not found: {0:?}")]
NoLinkedListFoundInsideRecord(LinkedListAddress),
// ---------- Graph Errors
#[error("Graph entry not found: {0:?}")]
NoGraphEntryFoundInsideRecord(GraphEntryAddress),

// ---------- Store Error
#[error("No Store Cost Responses")]
Expand Down
10 changes: 5 additions & 5 deletions ant-networking/src/event/kad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// permissions and limitations relating to use of the SAFE Network Software.

use crate::{
driver::PendingGetClosestType, get_linked_list_from_record, get_quorum_value,
driver::PendingGetClosestType, get_graph_entry_from_record, get_quorum_value,
target_arch::Instant, GetRecordCfg, GetRecordError, NetworkError, Result, SwarmDriver,
CLOSE_GROUP_SIZE,
};
use ant_protocol::{
storage::{try_serialize_record, LinkedList, RecordKind},
storage::{try_serialize_record, GraphEntry, RecordKind},
NetworkAddress, PrettyPrintRecordKey,
};
use itertools::Itertools;
Expand Down Expand Up @@ -399,7 +399,7 @@ impl SwarmDriver {
debug!("For record {pretty_key:?} task {query_id:?}, fetch completed with split record");
let mut accumulated_transactions = BTreeSet::new();
for (record, _) in result_map.values() {
match get_linked_list_from_record(record) {
match get_graph_entry_from_record(record) {
Ok(transactions) => {
accumulated_transactions.extend(transactions);
}
Expand All @@ -412,11 +412,11 @@ impl SwarmDriver {
info!("For record {pretty_key:?} task {query_id:?}, found split record for a transaction, accumulated and sending them as a single record");
let accumulated_transactions = accumulated_transactions
.into_iter()
.collect::<Vec<LinkedList>>();
.collect::<Vec<GraphEntry>>();

let bytes = try_serialize_record(
&accumulated_transactions,
RecordKind::LinkedList,
RecordKind::GraphEntry,
)?;

let new_accumulated_record = Record {
Expand Down
20 changes: 10 additions & 10 deletions ant-networking/src/linked_list.rs → ant-networking/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
// permissions and limitations relating to use of the SAFE Network Software.

use crate::{driver::GetRecordCfg, Network, NetworkError, Result};
use ant_protocol::storage::{LinkedList, LinkedListAddress};
use ant_protocol::storage::{GraphEntry, GraphEntryAddress};
use ant_protocol::{
storage::{try_deserialize_record, RecordHeader, RecordKind, RetryStrategy},
NetworkAddress, PrettyPrintRecordKey,
};
use libp2p::kad::{Quorum, Record};

impl Network {
/// Gets LinkedList at LinkedListAddress from the Network.
pub async fn get_linked_list(&self, address: LinkedListAddress) -> Result<Vec<LinkedList>> {
let key = NetworkAddress::from_linked_list_address(address).to_record_key();
/// 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),
Expand All @@ -31,20 +31,20 @@ impl Network {
PrettyPrintRecordKey::from(&record.key)
);

get_linked_list_from_record(&record)
get_graph_entry_from_record(&record)
}
}

pub fn get_linked_list_from_record(record: &Record) -> Result<Vec<LinkedList>> {
pub fn get_graph_entry_from_record(record: &Record) -> Result<Vec<GraphEntry>> {
let header = RecordHeader::from_record(record)?;
if let RecordKind::LinkedList = header.kind {
let transactions = try_deserialize_record::<Vec<LinkedList>>(record)?;
if let RecordKind::GraphEntry = header.kind {
let transactions = try_deserialize_record::<Vec<GraphEntry>>(record)?;
Ok(transactions)
} else {
warn!(
"RecordKind mismatch while trying to retrieve linked_list from record {:?}",
"RecordKind mismatch while trying to retrieve graph_entry from record {:?}",
PrettyPrintRecordKey::from(&record.key)
);
Err(NetworkError::RecordKindMismatch(RecordKind::LinkedList))
Err(NetworkError::RecordKindMismatch(RecordKind::GraphEntry))
}
}
16 changes: 8 additions & 8 deletions ant-networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod error;
mod event;
mod external_address;
mod fifo_register;
mod linked_list;
mod graph;
mod log_markers;
#[cfg(feature = "open-metrics")]
mod metrics;
Expand All @@ -40,7 +40,7 @@ pub use self::{
},
error::{GetRecordError, NetworkError},
event::{MsgResponder, NetworkEvent},
linked_list::get_linked_list_from_record,
graph::get_graph_entry_from_record,
record_store::NodeRecordStore,
};
#[cfg(feature = "open-metrics")]
Expand Down Expand Up @@ -75,7 +75,7 @@ use tokio::sync::{
};
use tokio::time::Duration;
use {
ant_protocol::storage::LinkedList,
ant_protocol::storage::GraphEntry,
ant_protocol::storage::{
try_deserialize_record, try_serialize_record, RecordHeader, RecordKind,
},
Expand Down Expand Up @@ -634,17 +634,17 @@ impl Network {
match kind {
RecordKind::Chunk
| RecordKind::ChunkWithPayment
| RecordKind::LinkedListWithPayment
| RecordKind::GraphEntryWithPayment
| RecordKind::RegisterWithPayment
| RecordKind::PointerWithPayment
| RecordKind::ScratchpadWithPayment => {
error!("Encountered a split record for {pretty_key:?} with unexpected RecordKind {kind:?}, skipping.");
continue;
}
RecordKind::LinkedList => {
RecordKind::GraphEntry => {
info!("For record {pretty_key:?}, we have a split record for a transaction attempt. Accumulating transactions");

match get_linked_list_from_record(record) {
match get_graph_entry_from_record(record) {
Ok(transactions) => {
accumulated_transactions.extend(transactions);
}
Expand Down Expand Up @@ -730,10 +730,10 @@ impl Network {
info!("For record {pretty_key:?} task found split record for a transaction, accumulated and sending them as a single record");
let accumulated_transactions = accumulated_transactions
.into_iter()
.collect::<Vec<LinkedList>>();
.collect::<Vec<GraphEntry>>();
let record = Record {
key: key.clone(),
value: try_serialize_record(&accumulated_transactions, RecordKind::LinkedList)
value: try_serialize_record(&accumulated_transactions, RecordKind::GraphEntry)
.map_err(|err| {
error!(
"Error while serializing the accumulated transactions for {pretty_key:?}: {err:?}"
Expand Down
46 changes: 23 additions & 23 deletions ant-node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use crate::{node::Node, Error, Marker, Result};
use ant_evm::payment_vault::verify_data_payment;
use ant_evm::{AttoTokens, ProofOfPayment};
use ant_networking::NetworkError;
use ant_protocol::storage::LinkedList;
use ant_protocol::storage::GraphEntry;
use ant_protocol::{
storage::{
try_deserialize_record, try_serialize_record, Chunk, LinkedListAddress, Pointer,
try_deserialize_record, try_serialize_record, Chunk, GraphEntryAddress, Pointer,
RecordHeader, RecordKind, RecordType, Scratchpad,
},
NetworkAddress, PrettyPrintRecordKey,
Expand Down Expand Up @@ -163,19 +163,19 @@ impl Node {
self.validate_and_store_scratchpad_record(scratchpad, key, false)
.await
}
RecordKind::LinkedList => {
RecordKind::GraphEntry => {
// Transactions should always be paid for
error!("Transaction should not be validated at this point");
Err(Error::InvalidPutWithoutPayment(
PrettyPrintRecordKey::from(&record.key).into_owned(),
))
}
RecordKind::LinkedListWithPayment => {
RecordKind::GraphEntryWithPayment => {
let (payment, transaction) =
try_deserialize_record::<(ProofOfPayment, LinkedList)>(&record)?;
try_deserialize_record::<(ProofOfPayment, GraphEntry)>(&record)?;

// check if the deserialized value's TransactionAddress matches the record's key
let net_addr = NetworkAddress::from_linked_list_address(transaction.address());
let net_addr = NetworkAddress::from_graph_entry_address(transaction.address());
let key = net_addr.to_record_key();
let pretty_key = PrettyPrintRecordKey::from(&key);
if record.key != key {
Expand Down Expand Up @@ -349,7 +349,7 @@ impl Node {
}
}

let res = self.validate_and_store_pointer_record(pointer, key).await;
let res = self.validate_and_store_pointer_record(pointer, key);
if res.is_ok() {
let content_hash = XorName::from_content(&record.value);
Marker::ValidPointerPutFromClient(&PrettyPrintRecordKey::from(&record.key))
Expand Down Expand Up @@ -377,7 +377,7 @@ impl Node {
match record_header.kind {
// A separate flow handles payment for chunks and registers
RecordKind::ChunkWithPayment
| RecordKind::LinkedListWithPayment
| RecordKind::GraphEntryWithPayment
| RecordKind::RegisterWithPayment
| RecordKind::ScratchpadWithPayment
| RecordKind::PointerWithPayment => {
Expand Down Expand Up @@ -409,9 +409,9 @@ impl Node {
self.validate_and_store_scratchpad_record(scratchpad, key, false)
.await
}
RecordKind::LinkedList => {
RecordKind::GraphEntry => {
let record_key = record.key.clone();
let transactions = try_deserialize_record::<Vec<LinkedList>>(&record)?;
let transactions = try_deserialize_record::<Vec<GraphEntry>>(&record)?;
self.validate_merge_and_store_transactions(transactions, &record_key)
.await
}
Expand All @@ -432,7 +432,7 @@ impl Node {
RecordKind::Pointer => {
let pointer = try_deserialize_record::<Pointer>(&record)?;
let key = record.key.clone();
self.validate_and_store_pointer_record(pointer, key).await
self.validate_and_store_pointer_record(pointer, key)
}
}
}
Expand Down Expand Up @@ -621,19 +621,19 @@ impl Node {
/// If we already have a transaction at this address, the Vec is extended and stored.
pub(crate) async fn validate_merge_and_store_transactions(
&self,
transactions: Vec<LinkedList>,
transactions: Vec<GraphEntry>,
record_key: &RecordKey,
) -> Result<()> {
let pretty_key = PrettyPrintRecordKey::from(record_key);
debug!("Validating transactions before storage at {pretty_key:?}");

// only keep transactions that match the record key
let transactions_for_key: Vec<LinkedList> = transactions
let transactions_for_key: Vec<GraphEntry> = transactions
.into_iter()
.filter(|s| {
// get the record key for the transaction
let transaction_address = s.address();
let network_address = NetworkAddress::from_linked_list_address(transaction_address);
let network_address = NetworkAddress::from_graph_entry_address(transaction_address);
let transaction_record_key = network_address.to_record_key();
let transaction_pretty = PrettyPrintRecordKey::from(&transaction_record_key);
if &transaction_record_key != record_key {
Expand All @@ -653,7 +653,7 @@ impl Node {
}

// verify the transactions
let mut validated_transactions: BTreeSet<LinkedList> = transactions_for_key
let mut validated_transactions: BTreeSet<GraphEntry> = transactions_for_key
.into_iter()
.filter(|t| t.verify())
.collect();
Expand All @@ -670,12 +670,12 @@ impl Node {
// add local transactions to the validated transactions, turn to Vec
let local_txs = self.get_local_transactions(addr).await?;
validated_transactions.extend(local_txs.into_iter());
let validated_transactions: Vec<LinkedList> = validated_transactions.into_iter().collect();
let validated_transactions: Vec<GraphEntry> = validated_transactions.into_iter().collect();

// store the record into the local storage
let record = Record {
key: record_key.clone(),
value: try_serialize_record(&validated_transactions, RecordKind::LinkedList)?.to_vec(),
value: try_serialize_record(&validated_transactions, RecordKind::GraphEntry)?.to_vec(),
publisher: None,
expires: None,
};
Expand Down Expand Up @@ -826,9 +826,9 @@ impl Node {

/// Get the local transactions for the provided `TransactionAddress`
/// This only fetches the transactions from the local store and does not perform any network operations.
async fn get_local_transactions(&self, addr: LinkedListAddress) -> Result<Vec<LinkedList>> {
async fn get_local_transactions(&self, addr: GraphEntryAddress) -> Result<Vec<GraphEntry>> {
// get the local transactions
let record_key = NetworkAddress::from_linked_list_address(addr).to_record_key();
let record_key = NetworkAddress::from_graph_entry_address(addr).to_record_key();
debug!("Checking for local transactions with key: {record_key:?}");
let local_record = match self.network().get_local_record(&record_key).await? {
Some(r) => r,
Expand All @@ -841,16 +841,16 @@ impl Node {
// deserialize the record and get the transactions
let local_header = RecordHeader::from_record(&local_record)?;
let record_kind = local_header.kind;
if !matches!(record_kind, RecordKind::LinkedList) {
if !matches!(record_kind, RecordKind::GraphEntry) {
error!("Found a {record_kind} when expecting to find Spend at {addr:?}");
return Err(NetworkError::RecordKindMismatch(RecordKind::LinkedList).into());
return Err(NetworkError::RecordKindMismatch(RecordKind::GraphEntry).into());
}
let local_transactions: Vec<LinkedList> = try_deserialize_record(&local_record)?;
let local_transactions: Vec<GraphEntry> = try_deserialize_record(&local_record)?;
Ok(local_transactions)
}

/// Validate and store a pointer record
pub(crate) async fn validate_and_store_pointer_record(
pub(crate) fn validate_and_store_pointer_record(
&self,
pointer: Pointer,
key: RecordKey,
Expand Down
4 changes: 2 additions & 2 deletions ant-node/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Node {
) -> Result<PaymentQuote, ProtocolError> {
let content = match address {
NetworkAddress::ChunkAddress(addr) => *addr.xorname(),
NetworkAddress::LinkedListAddress(addr) => *addr.xorname(),
NetworkAddress::GraphEntryAddress(addr) => *addr.xorname(),
NetworkAddress::RegisterAddress(addr) => addr.xorname(),
NetworkAddress::ScratchpadAddress(addr) => addr.xorname(),
NetworkAddress::PointerAddress(addr) => *addr.xorname(),
Expand Down Expand Up @@ -61,7 +61,7 @@ pub(crate) fn verify_quote_for_storecost(
// check address
let content = match address {
NetworkAddress::ChunkAddress(addr) => *addr.xorname(),
NetworkAddress::LinkedListAddress(addr) => *addr.xorname(),
NetworkAddress::GraphEntryAddress(addr) => *addr.xorname(),
NetworkAddress::RegisterAddress(addr) => addr.xorname(),
NetworkAddress::ScratchpadAddress(addr) => addr.xorname(),
NetworkAddress::PointerAddress(addr) => *addr.xorname(),
Expand Down
Loading
Loading