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

remove empty object change #2894

Merged
merged 1 commit into from
Nov 14, 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
4 changes: 1 addition & 3 deletions crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,7 @@ fn parse_changed_objects(
let mut deleted_objs = vec![];
for obj_change in changes {
let metadata = obj_change.metadata.clone();
//TODO fixme
//https://github.com/rooch-network/rooch/issues/2657
//debug_assert!(obj_change.value.is_some() || !obj_change.fields.is_empty());
debug_assert!(obj_change.value.is_some() || !obj_change.fields.is_empty());
match obj_change.value {
Some(OpView::New(_)) => new_objs.push(metadata),
Some(OpView::Modify(_)) => modified_objs.push(metadata),
Expand Down
46 changes: 20 additions & 26 deletions moveos/moveos-object-runtime/src/runtime_object_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@ use moveos_types::{
moveos_std::object::{ObjectID, ObjectMeta, SYSTEM_OWNER_ADDRESS},
};

#[derive(Debug, Clone)]
pub(crate) enum DataStatus {
Clean,
Dirty,
}

#[derive(Debug, Clone)]
pub(crate) struct ObjectMetaValue {
metadata: ObjectMeta,
value_layout: MoveTypeLayout,
status: DataStatus,
}

pub(crate) enum RuntimeObjectMeta {
None(ObjectID),
Fresh(ObjectMetaValue),
Cached(ObjectMetaValue),
// The first element is the metadata to be changed in runtime,
// the second element is the original metadata loaded from resolver.
Cached((ObjectMetaValue, ObjectMeta)),
Deleted(ObjectMetaValue),
}

Expand All @@ -37,18 +32,19 @@ impl RuntimeObjectMeta {
}

pub fn cached(metadata: ObjectMeta, value_layout: MoveTypeLayout) -> Self {
RuntimeObjectMeta::Cached(ObjectMetaValue {
RuntimeObjectMeta::Cached((
ObjectMetaValue {
metadata: metadata.clone(),
value_layout,
},
metadata,
value_layout,
status: DataStatus::Clean,
})
))
}

pub fn fresh(metadata: ObjectMeta, value_layout: MoveTypeLayout) -> Self {
RuntimeObjectMeta::Fresh(ObjectMetaValue {
metadata,
value_layout,
status: DataStatus::Dirty,
})
}

Expand All @@ -61,7 +57,7 @@ impl RuntimeObjectMeta {
Self::None(id) => id.clone(),
//If the object is removed, and init it again, we treat it is fresh
Self::Deleted(meta) => meta.metadata.id.clone(),
Self::Fresh(v) | Self::Cached(v) => {
Self::Fresh(v) | Self::Cached((v, _)) => {
//If the object is removed, and init it again, the value type may be different
v.metadata.object_type = value_type;
v.value_layout = value_layout;
Expand All @@ -73,7 +69,6 @@ impl RuntimeObjectMeta {
*self = Self::Fresh(ObjectMetaValue {
metadata,
value_layout,
status: DataStatus::Dirty,
});
Ok(())
}
Expand All @@ -89,10 +84,10 @@ impl RuntimeObjectMeta {
_ => unreachable!(),
}
}
Self::Cached(meta) => {
Self::Cached((meta, _)) => {
let meta_copy = meta.clone();
match std::mem::replace(self, Self::Deleted(meta_copy)) {
Self::Cached(meta) => Ok(meta.metadata),
Self::Cached((meta, _)) => Ok(meta.metadata),
_ => unreachable!(),
}
}
Expand All @@ -110,7 +105,7 @@ impl RuntimeObjectMeta {
Self::None(id) => id,
Self::Deleted(meta) => &meta.metadata.id,
Self::Fresh(meta) => &meta.metadata.id,
Self::Cached(meta) => &meta.metadata.id,
Self::Cached((meta, _)) => &meta.metadata.id,
}
}

Expand All @@ -123,7 +118,7 @@ impl RuntimeObjectMeta {
Ok(&meta.metadata)
}
Self::Fresh(meta) => Ok(&meta.metadata),
Self::Cached(meta) => Ok(&meta.metadata),
Self::Cached((meta, _)) => Ok(&meta.metadata),
}
}

Expand All @@ -139,7 +134,7 @@ impl RuntimeObjectMeta {
Self::Deleted(meta) => Err(PartialVMError::new(StatusCode::MISSING_DATA)
.with_message(format!("Layout of {} is Deleted", &meta.metadata.id))),
Self::Fresh(meta) => Ok(&meta.value_layout),
Self::Cached(meta) => Ok(&meta.value_layout),
Self::Cached((meta, _)) => Ok(&meta.value_layout),
}
}

Expand All @@ -160,9 +155,8 @@ impl RuntimeObjectMeta {
.with_message(format!("ObjectMeta of {} is Deleted", &meta.metadata.id)));
}
RuntimeObjectMeta::Fresh(meta) => meta,
RuntimeObjectMeta::Cached(meta) => meta,
RuntimeObjectMeta::Cached((meta, _)) => meta,
};
meta_value.status = DataStatus::Dirty;
Ok(&mut meta_value.metadata)
}

Expand Down Expand Up @@ -257,10 +251,10 @@ impl RuntimeObjectMeta {
match self {
RuntimeObjectMeta::None(_) => None,
RuntimeObjectMeta::Fresh(meta) => Some((meta.metadata, true)),
RuntimeObjectMeta::Cached(meta) => match meta.status {
DataStatus::Clean => Some((meta.metadata, false)),
DataStatus::Dirty => Some((meta.metadata, true)),
},
RuntimeObjectMeta::Cached((meta, origin)) => {
let is_dirty = meta.metadata != origin;
Some((meta.metadata, is_dirty))
}
RuntimeObjectMeta::Deleted(meta) => Some((meta.metadata, true)),
}
}
Expand Down
Loading