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

fix: shall only have Chunk and NonChunk for RecordType #2602

Merged
merged 1 commit into from
Jan 7, 2025
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
7 changes: 4 additions & 3 deletions ant-networking/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,10 @@ impl SwarmDriver {
Ok(record_header) => {
match record_header.kind {
RecordKind::Chunk => RecordType::Chunk,
RecordKind::Scratchpad => RecordType::Scratchpad,
RecordKind::Pointer => RecordType::Pointer,
RecordKind::GraphEntry | RecordKind::Register => {
RecordKind::GraphEntry
| RecordKind::Pointer
| RecordKind::Register
| RecordKind::Scratchpad => {
let content_hash = XorName::from_content(&record.value);
RecordType::NonChunk(content_hash)
}
Expand Down
19 changes: 14 additions & 5 deletions ant-networking/src/record_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,14 +820,23 @@ impl RecordStore for NodeRecordStore {
match RecordHeader::from_record(&record) {
Ok(record_header) => {
match record_header.kind {
RecordKind::ChunkWithPayment | RecordKind::RegisterWithPayment => {
RecordKind::ChunkWithPayment
| RecordKind::GraphEntryWithPayment
| RecordKind::PointerWithPayment
| RecordKind::RegisterWithPayment
| RecordKind::ScratchpadWithPayment => {
debug!("Record {record_key:?} with payment shall always be processed.");
}
_ => {
// Shall not use wildcard, to avoid mis-match during enum update.
RecordKind::Chunk
| RecordKind::GraphEntry
| RecordKind::Pointer
| RecordKind::Register
| RecordKind::Scratchpad => {
// Chunk with existing key do not to be stored again.
// `Spend` or `Register` with same content_hash do not to be stored again,
// otherwise shall be passed further to allow
// double transaction to be detected or register op update.
// Others with same content_hash do not to be stored again,
// otherwise shall be passed further to allow different version of nonchunk
// to be detected or updated.
match self.records.get(&record.key) {
Some((_addr, RecordType::Chunk)) => {
debug!("Chunk {record_key:?} already exists.");
Expand Down
10 changes: 6 additions & 4 deletions ant-node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,21 @@ impl Node {
// we eagerly retry replicaiton as it seems like other nodes are having trouble
// did not manage to get this scratchpad as yet.
Ok(_) | Err(Error::IgnoringOutdatedScratchpadPut) => {
let content_hash = XorName::from_content(&record.value);
Marker::ValidScratchpadRecordPutFromClient(&PrettyPrintRecordKey::from(
&record_key,
))
.log();
self.replicate_valid_fresh_record(
record_key.clone(),
RecordType::Scratchpad,
RecordType::NonChunk(content_hash),
);

// Notify replication_fetcher to mark the attempt as completed.
// Send the notification earlier to avoid it got skipped due to:
// the record becomes stored during the fetch because of other interleaved process.
self.network()
.notify_fetch_completed(record_key, RecordType::Scratchpad);
.notify_fetch_completed(record_key, RecordType::NonChunk(content_hash));
}
Err(_) => {}
}
Expand Down Expand Up @@ -552,14 +553,15 @@ impl Node {
publisher: None,
expires: None,
};
self.network().put_local_record(record);
self.network().put_local_record(record.clone());

let pretty_key = PrettyPrintRecordKey::from(&scratchpad_key);

self.record_metrics(Marker::ValidScratchpadRecordPutFromNetwork(&pretty_key));

if is_client_put {
self.replicate_valid_fresh_record(scratchpad_key, RecordType::Scratchpad);
let content_hash = XorName::from_content(&record.value);
self.replicate_valid_fresh_record(scratchpad_key, RecordType::NonChunk(content_hash));
}

Ok(())
Expand Down
14 changes: 2 additions & 12 deletions ant-node/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
use crate::{NodeBuilder, RunningNode};
use ant_evm::{EvmNetwork, RewardsAddress};
use ant_networking::PutRecordCfg;
use ant_protocol::{
node::get_antnode_root_dir,
storage::{ChunkAddress, RecordType},
NetworkAddress,
};
use ant_protocol::{node::get_antnode_root_dir, storage::ChunkAddress, NetworkAddress};
use const_hex::FromHex;
use libp2p::{
identity::{Keypair, PeerId},
Expand Down Expand Up @@ -239,7 +235,7 @@ impl AntNode {
self_: PyRef<Self>,
key: String,
value: Vec<u8>,
record_type: String,
_data_type: String,
) -> PyResult<()> {
let node_guard = self_
.node
Expand All @@ -250,12 +246,6 @@ impl AntNode {
.try_lock()
.map_err(|_| PyRuntimeError::new_err("Failed to acquire runtime lock"))?;

let _record_type = match record_type.to_lowercase().as_str() {
"chunk" => RecordType::Chunk,
"scratchpad" => RecordType::Scratchpad,
_ => return Err(PyValueError::new_err("Invalid record type. Must be one of: 'chunk', 'register', 'scratchpad', 'transaction'")),
};

match (&*node_guard, &*rt_guard) {
(Some(node), Some(rt)) => {
let xorname = XorName::from_content(
Expand Down
7 changes: 2 additions & 5 deletions ant-protocol/src/storage/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ use std::fmt::Display;
use xor_name::XorName;

/// Indicates the type of the record content.
/// Note for `Spend` and `Register`, using its content_hash (in `XorName` format)
/// to indicate different content body.
/// This is to be only used within the node instance to reflect different content version.
/// Hence, only need to have two entries: Chunk and NonChunk.
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
pub enum RecordType {
Chunk,
Scratchpad,
Pointer,
GraphEntry,
NonChunk(XorName),
}

Expand Down
Loading