Skip to content

Commit

Permalink
[TransactionEffects/API] Lamport Version (MystenLabs#15082)
Browse files Browse the repository at this point in the history
##  Description

Expose lamport version from both Effects v1 and Effects v2 via the
`TransactionEffectsAPI`. This is mainly to serve the GraphQL API which
needs to return this for both kinds of effect.

This corrects another edge case of the existing GraphQL implementation
of `lamportVersion`: If the only object created by a transaction is a
package, then the previous GraphQL implementation would incorrectly
suggest that the package's version is the transaction's lamport version.
This is not correct, because package versioning is treated specially.

## Test Plan

```
sui-graphql-rpc$ cargo nextest run
sui-graphql-e2e-tests$ cargo nextest run \
  -j 1 --features pg_integration         \
  -- transactions
```

##  Stack

- MystenLabs#14929 
- MystenLabs#14930 
- MystenLabs#14934
- MystenLabs#14935 
- MystenLabs#14961 
- MystenLabs#14974
- MystenLabs#15013
- MystenLabs#15014
- MystenLabs#15015
- MystenLabs#15016
- MystenLabs#15018
- MystenLabs#15020
- MystenLabs#15021
- MystenLabs#15036 
- MystenLabs#15037 
- MystenLabs#15038 
- MystenLabs#15039 
- MystenLabs#15040
- MystenLabs#15041
- MystenLabs#15042 
- MystenLabs#15043
- MystenLabs#15044 
- MystenLabs#15074
  • Loading branch information
amnn authored Dec 1, 2023
1 parent a87c153 commit 98be353
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Response: {
"effects": {
"status": "SUCCESS",
"errors": null,
"lamportVersion": 2,
"lamportVersion": 3,
"dependencies": [
{
"digest": "C5AEGK7kAtcPQotXhpzmgaAZFyTu5GtnkmcfNXFAubXk"
Expand Down
7 changes: 3 additions & 4 deletions crates/sui-graphql-rpc/schema/current_progress_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1690,11 +1690,10 @@ type TransactionBlockEffects {
"""
status: ExecutionStatus
"""
The latest version of all objects that have been created or modified by this transaction,
immediately following this transaction. A system transaction that does not modify or create
objects will not have a lamport version.
The latest version of all objects (apart from packages) that have been created or modified
by this transaction, immediately following this transaction.
"""
lamportVersion: Int
lamportVersion: Int!
"""
The reason for a transaction failure, if it did fail.
"""
Expand Down
17 changes: 4 additions & 13 deletions crates/sui-graphql-rpc/src/types/transaction_block_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,10 @@ impl TransactionBlockEffects {
})
}

/// The latest version of all objects that have been created or modified by this transaction,
/// immediately following this transaction. A system transaction that does not modify or create
/// objects will not have a lamport version.
async fn lamport_version(&self) -> Option<u64> {
if let Some(((_id, version, _digest), _owner)) = self.native.created().first() {
Some(version.value())
} else if let Some(((_id, version, _digest), _owner)) = self.native.mutated().first() {
Some(version.value())
} else if let Some(((_id, version, _digest), _owner)) = self.native.unwrapped().first() {
Some(version.value())
} else {
None
}
/// The latest version of all objects (apart from packages) that have been created or modified
/// by this transaction, immediately following this transaction.
async fn lamport_version(&self) -> u64 {
self.native.lamport_version().value()
}

/// The reason for a transaction failure, if it did fail.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1694,11 +1694,10 @@ type TransactionBlockEffects {
"""
status: ExecutionStatus
"""
The latest version of all objects that have been created or modified by this transaction,
immediately following this transaction. A system transaction that does not modify or create
objects will not have a lamport version.
The latest version of all objects (apart from packages) that have been created or modified
by this transaction, immediately following this transaction.
"""
lamportVersion: Int
lamportVersion: Int!
"""
The reason for a transaction failure, if it did fail.
"""
Expand Down
5 changes: 5 additions & 0 deletions crates/sui-types/src/effects/effects_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ impl TransactionEffectsAPI for TransactionEffectsV1 {
fn modified_at_versions(&self) -> Vec<(ObjectID, SequenceNumber)> {
self.modified_at_versions.clone()
}

fn lamport_version(&self) -> SequenceNumber {
SequenceNumber::lamport_increment(self.modified_at_versions.iter().map(|(_, v)| *v))
}

fn old_object_metadata(&self) -> Vec<(ObjectRef, Owner)> {
unimplemented!("Only supposed by v2 and above");
}
Expand Down
4 changes: 4 additions & 0 deletions crates/sui-types/src/effects/effects_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl TransactionEffectsAPI for TransactionEffectsV2 {
.collect()
}

fn lamport_version(&self) -> SequenceNumber {
self.lamport_version
}

fn old_object_metadata(&self) -> Vec<(ObjectRef, Owner)> {
self.changed_objects
.iter()
Expand Down
3 changes: 3 additions & 0 deletions crates/sui-types/src/effects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ pub trait TransactionEffectsAPI {
fn executed_epoch(&self) -> EpochId;
fn modified_at_versions(&self) -> Vec<(ObjectID, SequenceNumber)>;

/// The version assigned to all output objects (apart from packages).
fn lamport_version(&self) -> SequenceNumber;

/// Metadata of objects prior to modification. This includes any object that exists in the
/// store prior to this transaction and is modified in this transaction.
/// It includes objects that are mutated, wrapped and deleted.
Expand Down

0 comments on commit 98be353

Please sign in to comment.