Skip to content

Commit

Permalink
fix(graphql): add root object version for dynamic field queries (#17934)
Browse files Browse the repository at this point in the history
Adds the following attribute to
`sui_graphql_rpc::types::object::Object`:
```rust
    /// Optional root parent object version if this is a dynamic field.
    ///
    /// This enables consistent dynamic field reads in the case of chained dynamic object fields,
    /// e.g., `Parent -> DOF1 -> DOF2`. In such cases, the object versions may end up like
    /// `Parent >= DOF1, DOF2` but `DOF1 < DOF2`. Thus, database queries for dynamic fields must
    /// bound the object versions by the version of the root object of the tree.
    ///
    /// Essentially, lamport timestamps of objects are updated for all top-level mutable objects
    /// provided as inputs to a transaction as well as any mutated dynamic child objects. However,
    /// any dynamic child objects that were loaded but not actually mutated don't end up having
    /// their versions updated.
    root_version: Option<u64>,
```

I tried making sure that this attribute is set correctly wherever an
`Object` is created.

There's one scenario which still isn't covered: if the GQL query is
rooted at a DOF, something like
```graphql
query DynamicFields($parent: SuiAddress!, $version: Int, $after: String) {
  object(address: $parent, version: $version) {
    dynamicFields(/* ... */) {
        // ...
    }
  }
}
```
where `$parent` is a DOF's object id, then the server has no way to know
the root object's version. Instead, we will use the rooting object's version, even if it is a nested child object.

New tests `immutable_dof.move` and `nested_dof.move`.

---

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:
- [ ] CLI:
- [ ] Rust SDK:

---------

Co-authored-by: Ashok Menon <amenon94@gmail.com>
Co-authored-by: Will Yang <willyang@mystenlabs.com>
  • Loading branch information
3 people committed Jun 24, 2024
1 parent 7df125c commit d8b7462
Show file tree
Hide file tree
Showing 16 changed files with 1,221 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ Response: {
"value": {
"contents": {
"json": {
"id": "0xa770d3129adc43c7383b2911822e58bac862439eb5079d7ca74d9df6246fb780",
"count": "1"
"id": "0x49cf623123e519b96c66de2c643cd2823f87957fbfcec77c2797acfe5b1925bb",
"count": "2"
}
}
}
Expand Down Expand Up @@ -301,8 +301,8 @@ Response: {
"value": {
"contents": {
"json": {
"id": "0xa770d3129adc43c7383b2911822e58bac862439eb5079d7ca74d9df6246fb780",
"count": "1"
"id": "0x49cf623123e519b96c66de2c643cd2823f87957fbfcec77c2797acfe5b1925bb",
"count": "2"
}
}
}
Expand Down Expand Up @@ -406,6 +406,53 @@ Response: {
"json": "df2"
}
}
},
{
"cursor": "ICqrOlZMehwZo7RQiTUBo9x8xQUO+2aWXUyFsrYcBpiqAwAAAAAAAAA=",
"node": {
"name": {
"bcs": "pAEAAAAAAAA=",
"type": {
"repr": "u64"
}
},
"value": {
"contents": {
"json": {
"id": "0x49cf623123e519b96c66de2c643cd2823f87957fbfcec77c2797acfe5b1925bb",
"count": "2"
}
}
}
}
},
{
"cursor": "IDHVR7rljFBCp61DB3y1jtd077khUkj1O2eRyuo8Si43AwAAAAAAAAA=",
"node": {
"name": {
"bcs": "A2RmMQ==",
"type": {
"repr": "0x0000000000000000000000000000000000000000000000000000000000000001::string::String"
}
},
"value": {
"json": "df1"
}
}
},
{
"cursor": "IF/yimojYFsFiaF/BkJLbQLFAAzw9I07bgPiS8aEHh4VAwAAAAAAAAA=",
"node": {
"name": {
"bcs": "A2RmMw==",
"type": {
"repr": "0x0000000000000000000000000000000000000000000000000000000000000001::string::String"
}
},
"value": {
"json": "df3"
}
}
}
]
}
Expand Down Expand Up @@ -473,8 +520,8 @@ Response: {
"value": {
"contents": {
"json": {
"id": "0xa770d3129adc43c7383b2911822e58bac862439eb5079d7ca74d9df6246fb780",
"count": "1"
"id": "0x49cf623123e519b96c66de2c643cd2823f87957fbfcec77c2797acfe5b1925bb",
"count": "2"
}
}
}
Expand Down Expand Up @@ -696,8 +743,8 @@ Response: {
"value": {
"contents": {
"json": {
"id": "0xa770d3129adc43c7383b2911822e58bac862439eb5079d7ca74d9df6246fb780",
"count": "1"
"id": "0x49cf623123e519b96c66de2c643cd2823f87957fbfcec77c2797acfe5b1925bb",
"count": "2"
}
}
}
Expand Down Expand Up @@ -811,8 +858,8 @@ Response: {
"value": {
"contents": {
"json": {
"id": "0xa770d3129adc43c7383b2911822e58bac862439eb5079d7ca74d9df6246fb780",
"count": "1"
"id": "0x49cf623123e519b96c66de2c643cd2823f87957fbfcec77c2797acfe5b1925bb",
"count": "2"
}
}
}
Expand Down Expand Up @@ -963,7 +1010,14 @@ Response: {
"repr": "u64"
}
},
"value": null
"value": {
"contents": {
"json": {
"id": "0x49cf623123e519b96c66de2c643cd2823f87957fbfcec77c2797acfe5b1925bb",
"count": "2"
}
}
}
}
}
]
Expand All @@ -982,7 +1036,14 @@ Response: {
"repr": "u64"
}
},
"value": null
"value": {
"contents": {
"json": {
"id": "0x49cf623123e519b96c66de2c643cd2823f87957fbfcec77c2797acfe5b1925bb",
"count": "2"
}
}
}
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
processed 17 tasks

init:
A: object(0,0)

task 1 'publish'. lines 20-68:
created: object(1,0)
mutated: object(0,1)
gas summary: computation_cost: 1000000, storage_cost: 8770400, storage_rebate: 0, non_refundable_storage_fee: 0

task 2 'run'. lines 70-70:
created: object(2,0)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 2302800, storage_rebate: 0, non_refundable_storage_fee: 0

task 3 'run'. lines 72-72:
created: object(3,0)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 2295200, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4 'run'. lines 74-74:
created: object(4,0)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 2295200, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 5 'run'. lines 76-76:
created: object(5,0)
mutated: object(0,0), object(2,0), object(3,0)
gas summary: computation_cost: 1000000, storage_cost: 6064800, storage_rebate: 3573900, non_refundable_storage_fee: 36100

task 6 'run'. lines 78-78:
created: object(6,0)
mutated: object(0,0), object(2,0), object(4,0)
gas summary: computation_cost: 1000000, storage_cost: 6064800, storage_rebate: 3573900, non_refundable_storage_fee: 36100

task 7 'run'. lines 80-80:
mutated: object(0,0), object(2,0), object(3,0)
deleted: object(5,0)
gas summary: computation_cost: 1000000, storage_cost: 3610000, storage_rebate: 6004152, non_refundable_storage_fee: 60648

task 8 'create-checkpoint'. lines 82-82:
Checkpoint created: 1

task 9 'run-graphql'. lines 84-114:
Response: {
"data": {
"object": {
"dynamicFields": {
"nodes": [
{
"value": {
"address": "0x6b7e8ee3f855e9c484caf53b5fef5fe958d7266d8a3a12577f4a17830e213983",
"version": 5,
"contents": {
"json": {
"id": "0x6b7e8ee3f855e9c484caf53b5fef5fe958d7266d8a3a12577f4a17830e213983",
"count": "0"
}
},
"dynamicFields": {
"nodes": []
}
}
}
]
}
}
}
}

task 10 'run-graphql'. lines 116-146:
Response: {
"data": {
"object": {
"dynamicFields": {
"nodes": [
{
"value": {
"address": "0x6b7e8ee3f855e9c484caf53b5fef5fe958d7266d8a3a12577f4a17830e213983",
"version": 5,
"contents": {
"json": {
"id": "0x6b7e8ee3f855e9c484caf53b5fef5fe958d7266d8a3a12577f4a17830e213983",
"count": "0"
}
},
"dynamicFields": {
"nodes": [
{
"value": {
"address": "0x4198a12c0cd01da21a6cd35cc5e986d855c532676233d004105dbaa77bdfda77",
"version": 6,
"contents": {
"json": {
"id": "0x4198a12c0cd01da21a6cd35cc5e986d855c532676233d004105dbaa77bdfda77",
"count": "0"
}
}
}
}
]
}
}
}
]
}
}
}
}

task 11 'run-graphql'. lines 148-178:
Response: {
"data": {
"object": {
"dynamicFields": {
"nodes": []
}
}
}
}

task 12 'run-graphql'. lines 180-210:
Response: {
"data": {
"object": null
}
}

task 13 'run-graphql'. lines 212-239:
Response: {
"data": {
"object": {
"owner": {
"parent": {
"address": "0x14c69bfdef30d74f3cb7e305aead3f5d2558ca8d4a32c96b01936c7cfbb36af0"
}
},
"dynamicFields": {
"nodes": []
}
}
}
}

task 14 'run-graphql'. lines 241-258:
Response: {
"data": {
"object": null
}
}

task 15 'run-graphql'. lines 260-287:
Response: {
"data": {
"object": {
"owner": {
"_": null
},
"dynamicFields": {
"nodes": [
{
"value": {
"address": "0x4198a12c0cd01da21a6cd35cc5e986d855c532676233d004105dbaa77bdfda77",
"version": 6,
"contents": {
"json": {
"id": "0x4198a12c0cd01da21a6cd35cc5e986d855c532676233d004105dbaa77bdfda77",
"count": "0"
}
}
}
}
]
}
}
}
}

task 16 'run-graphql'. lines 289-316:
Response: {
"data": {
"object": {
"owner": {
"_": null
},
"dynamicFields": {
"nodes": [
{
"value": {
"address": "0x4198a12c0cd01da21a6cd35cc5e986d855c532676233d004105dbaa77bdfda77",
"version": 6,
"contents": {
"json": {
"id": "0x4198a12c0cd01da21a6cd35cc5e986d855c532676233d004105dbaa77bdfda77",
"count": "0"
}
}
}
}
]
}
}
}
}
Loading

0 comments on commit d8b7462

Please sign in to comment.