Skip to content

Commit

Permalink
[pick #17200][GraphQL] Cancelled Shared Object
Browse files Browse the repository at this point in the history
## Description

Take parts of #17200 that define the cnacelled input (and output) shared
object(s).

## Test plan

```
sui$ cargo simtest
```

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol:
- [ ] Nodes (Validators and Full nodes):
- [ ] Indexer:
- [ ] JSON-RPC:
- [x] GraphQL: Adds a SharedObjectCancelled type to represent an input
  object that was shared and part of a cancelled transaction.
- [ ] CLI:
- [ ] Rust SDK:

---------
  • Loading branch information
amnn committed Jul 30, 2024
1 parent f7408a0 commit eabd9fd
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 5 deletions.
4 changes: 3 additions & 1 deletion crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5113,7 +5113,9 @@ impl NodeStateDump {
shared_objects.push(ObjDumpFormat::new(w))
}
}
InputSharedObject::ReadDeleted(..) | InputSharedObject::MutateDeleted(..) => (),
InputSharedObject::ReadDeleted(..)
| InputSharedObject::MutateDeleted(..)
| InputSharedObject::Cancelled(..) => (), // TODO: consider record congested objects.
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/sui-core/src/checkpoints/causal_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl RWLockDependencyBuilder {
.entry(*effect.transaction_digest())
.or_default()
.push(ObjectKey(oid, version)),
InputSharedObject::Cancelled(..) => (), // TODO: confirm that consensus_commit_prologue is always at the beginning of the checkpoint, so that cancelled txn don't need to worry about dependency.
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions crates/sui-core/tests/staged/sui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ CompressedSignature:
ZkLogin:
NEWTYPE:
TYPENAME: ZkLoginAuthenticatorAsBytes
CongestedObjects:
NEWTYPESTRUCT:
SEQ:
TYPENAME: ObjectID
ConsensusCommitDigest:
NEWTYPESTRUCT:
TYPENAME: Digest
Expand Down Expand Up @@ -447,6 +451,11 @@ ExecutionFailureStatus:
SharedObjectOperationNotAllowed: UNIT
32:
InputObjectDeleted: UNIT
33:
ExecutionCancelledDueToSharedObjectCongestion:
STRUCT:
- congested_objects:
TYPENAME: CongestedObjects
ExecutionStatus:
ENUM:
0:
Expand Down Expand Up @@ -1073,6 +1082,10 @@ UnchangedSharedKind:
ReadDeleted:
NEWTYPE:
TYPENAME: SequenceNumber
3:
Cancelled:
NEWTYPE:
TYPENAME: SequenceNumber
UpgradeInfo:
STRUCT:
- upgraded_id:
Expand Down
16 changes: 15 additions & 1 deletion crates/sui-graphql-rpc/schema/current_progress_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3117,6 +3117,20 @@ type SharedInput {
mutable: Boolean!
}

"""
The transaction accpeted a shared object as input, but its execution was cancelled.
"""
type SharedObjectCancelled {
"""
ID of the shared object.
"""
address: SuiAddress!
"""
The assigned shared object version. It is a special version indicating transaction cancellation reason.
"""
version: Int!
}

"""
The transaction accepted a shared object as input, but it was deleted before the transaction
executed.
Expand Down Expand Up @@ -3885,7 +3899,7 @@ This information is considered part of the effects, because although the transac
the shared object as input, consensus must schedule it and pick the version that is actually
used.
"""
union UnchangedSharedObject = SharedObjectRead | SharedObjectDelete
union UnchangedSharedObject = SharedObjectRead | SharedObjectDelete | SharedObjectCancelled

type UnchangedSharedObjectConnection {
"""
Expand Down
16 changes: 16 additions & 0 deletions crates/sui-graphql-rpc/src/types/unchanged_shared_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use super::{object_read::ObjectRead, sui_address::SuiAddress};
pub(crate) enum UnchangedSharedObject {
Read(SharedObjectRead),
Delete(SharedObjectDelete),
Cancelled(SharedObjectCancelled),
}

/// The transaction accepted a shared object as input, but only to read it.
Expand All @@ -39,6 +40,16 @@ pub(crate) struct SharedObjectDelete {
mutable: bool,
}

/// The transaction accpeted a shared object as input, but its execution was cancelled.
#[derive(SimpleObject)]
pub(crate) struct SharedObjectCancelled {
/// ID of the shared object.
address: SuiAddress,

/// The assigned shared object version. It is a special version indicating transaction cancellation reason.
version: u64,
}

/// Error for converting from an `InputSharedObject`.
pub(crate) struct SharedObjectChanged;

Expand Down Expand Up @@ -71,6 +82,11 @@ impl UnchangedSharedObject {
version: v.value(),
mutable: true,
})),

I::Cancelled(id, v) => Ok(U::Cancelled(SharedObjectCancelled {
address: id.into(),
version: v.value(),
})),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3121,6 +3121,20 @@ type SharedInput {
mutable: Boolean!
}
"""
The transaction accpeted a shared object as input, but its execution was cancelled.
"""
type SharedObjectCancelled {
"""
ID of the shared object.
"""
address: SuiAddress!
"""
The assigned shared object version. It is a special version indicating transaction cancellation reason.
"""
version: Int!
}
"""
The transaction accepted a shared object as input, but it was deleted before the transaction
executed.
Expand Down Expand Up @@ -3889,7 +3903,7 @@ This information is considered part of the effects, because although the transac
the shared object as input, consensus must schedule it and pick the version that is actually
used.
"""
union UnchangedSharedObject = SharedObjectRead | SharedObjectDelete
union UnchangedSharedObject = SharedObjectRead | SharedObjectDelete | SharedObjectCancelled
type UnchangedSharedObjectConnection {
"""
Expand Down
4 changes: 4 additions & 0 deletions crates/sui-types/src/digests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ impl ObjectDigest {
pub const MAX: ObjectDigest = Self::new([u8::MAX; 32]);
pub const OBJECT_DIGEST_DELETED_BYTE_VAL: u8 = 99;
pub const OBJECT_DIGEST_WRAPPED_BYTE_VAL: u8 = 88;
pub const OBJECT_DIGEST_CANCELLED_BYTE_VAL: u8 = 77;

/// A marker that signifies the object is deleted.
pub const OBJECT_DIGEST_DELETED: ObjectDigest =
Expand All @@ -829,6 +830,9 @@ impl ObjectDigest {
pub const OBJECT_DIGEST_WRAPPED: ObjectDigest =
Self::new([Self::OBJECT_DIGEST_WRAPPED_BYTE_VAL; 32]);

pub const OBJECT_DIGEST_CANCELLED: ObjectDigest =
Self::new([Self::OBJECT_DIGEST_CANCELLED_BYTE_VAL; 32]);

pub const fn new(digest: [u8; 32]) -> Self {
Self(Digest::new(digest))
}
Expand Down
3 changes: 3 additions & 0 deletions crates/sui-types/src/effects/effects_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ impl TransactionEffectsAPI for TransactionEffectsV1 {
self.shared_objects
.push((id, version, ObjectDigest::OBJECT_DIGEST_DELETED));
}
InputSharedObject::Cancelled(..) => {
panic!("Transaction cancellation is not supported in effect v1");
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions crates/sui-types/src/effects/effects_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ impl TransactionEffectsAPI for TransactionEffectsV2 {
UnchangedSharedKind::ReadDeleted(seqno) => {
InputSharedObject::ReadDeleted(*id, *seqno)
}
UnchangedSharedKind::Cancelled(seqno) => {
InputSharedObject::Cancelled(*id, *seqno)
}
},
))
.collect()
Expand Down Expand Up @@ -354,6 +357,9 @@ impl TransactionEffectsAPI for TransactionEffectsV2 {
InputSharedObject::MutateDeleted(obj_id, seqno) => self
.unchanged_shared_objects
.push((obj_id, UnchangedSharedKind::MutateDeleted(seqno))),
InputSharedObject::Cancelled(obj_id, seqno) => self
.unchanged_shared_objects
.push((obj_id, UnchangedSharedKind::Cancelled(seqno))),
}
}

Expand Down Expand Up @@ -420,6 +426,10 @@ impl TransactionEffectsV2 {
Some((id, UnchangedSharedKind::ReadDeleted(version)))
}
}
SharedInput::Cancelled((id, version)) => {
debug_assert!(!changed_objects.contains_key(&id));
Some((id, UnchangedSharedKind::Cancelled(version)))
}
})
.collect();
let changed_objects: Vec<_> = changed_objects.into_iter().collect();
Expand Down Expand Up @@ -575,4 +585,6 @@ pub enum UnchangedSharedKind {
MutateDeleted(SequenceNumber),
/// Deleted shared objects that appear as read-only in the input.
ReadDeleted(SequenceNumber),
/// Shared objects in cancelled transaction. The sequence number embed cancellation reason.
Cancelled(SequenceNumber),
}
7 changes: 6 additions & 1 deletion crates/sui-types/src/effects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ pub enum InputSharedObject {
ReadOnly(ObjectRef),
ReadDeleted(ObjectID, SequenceNumber),
MutateDeleted(ObjectID, SequenceNumber),
Cancelled(ObjectID, SequenceNumber),
}

impl InputSharedObject {
Expand All @@ -319,6 +320,9 @@ impl InputSharedObject {
| InputSharedObject::MutateDeleted(id, version) => {
(*id, *version, ObjectDigest::OBJECT_DIGEST_DELETED)
}
InputSharedObject::Cancelled(id, version) => {
(*id, *version, ObjectDigest::OBJECT_DIGEST_CANCELLED)
}
}
}
}
Expand Down Expand Up @@ -372,7 +376,8 @@ pub trait TransactionEffectsAPI {
InputSharedObject::MutateDeleted(id, _) => Some(id),
InputSharedObject::Mutate(..)
| InputSharedObject::ReadOnly(..)
| InputSharedObject::ReadDeleted(..) => None,
| InputSharedObject::ReadDeleted(..)
| InputSharedObject::Cancelled(..) => None,
})
.collect()
}
Expand Down
1 change: 1 addition & 0 deletions crates/sui-types/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub type DeletedSharedObjects = Vec<DeletedSharedObjectInfo>;
pub enum SharedInput {
Existing(ObjectRef),
Deleted(DeletedSharedObjectInfo),
Cancelled((ObjectID, SequenceNumber)),
}

impl<T> SuiResolver for T
Expand Down
17 changes: 16 additions & 1 deletion crates/sui-types/src/execution_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::ObjectID;
use move_binary_format::file_format::{CodeOffset, TypeParameterIndex};
use move_core_types::language_storage::ModuleId;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
use std::fmt::{self, Display, Formatter};
use sui_macros::EnumVariantOrder;
use thiserror::Error;

Expand All @@ -25,6 +25,18 @@ pub enum ExecutionStatus {
},
}

#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize)]
pub struct CongestedObjects(pub Vec<ObjectID>);

impl fmt::Display for CongestedObjects {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
for obj in &self.0 {
write!(f, "{}, ", obj)?;
}
Ok(())
}
}

#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize, Error, EnumVariantOrder)]
pub enum ExecutionFailureStatus {
//
Expand Down Expand Up @@ -188,6 +200,9 @@ pub enum ExecutionFailureStatus {

#[error("Certificate cannot be executed due to a dependency on a deleted shared object")]
InputObjectDeleted,

#[error("Certificate is cancelled due to congestion on shared objects: {congested_objects}")]
ExecutionCancelledDueToSharedObjectCongestion { congested_objects: CongestedObjects },
// NOTE: if you want to add a new enum,
// please add it at the end for Rust SDK backward compatibility.
}
Expand Down
1 change: 1 addition & 0 deletions crates/sui-types/tests/staged/exec_failure_status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
30: SuiMoveVerificationTimedout
31: SharedObjectOperationNotAllowed
32: InputObjectDeleted
33: ExecutionCancelledDueToSharedObjectCongestion
3 changes: 3 additions & 0 deletions sui-execution/v0/sui-adapter/src/temporary_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ impl<'backing> TemporaryStore<'backing> {
SharedInput::Deleted(_) => {
unreachable!("Shared object deletion not supported in effects v1")
}
SharedInput::Cancelled(_) => {
unreachable!("Per object congestion control not supported in effects v1.")
}
})
.collect();

Expand Down
3 changes: 3 additions & 0 deletions sui-execution/v1/sui-adapter/src/temporary_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ impl<'backing> TemporaryStore<'backing> {
SharedInput::Deleted(_) => {
unreachable!("Shared object deletion not supported in effects v1")
}
SharedInput::Cancelled(_) => {
unreachable!("Per object congestion control not supported in effects v1.")
}
})
.collect();
self.into_effects_v1(
Expand Down
3 changes: 3 additions & 0 deletions sui-execution/v2/sui-adapter/src/temporary_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ impl<'backing> TemporaryStore<'backing> {
SharedInput::Deleted(_) => {
unreachable!("Shared object deletion not supported in effects v1")
}
SharedInput::Cancelled(_) => {
unreachable!("Per object congestion control not supported in effects v1.")
}
})
.collect();
self.into_effects_v1(
Expand Down

0 comments on commit eabd9fd

Please sign in to comment.