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

[gql] Watermark task reads from watermarks table, use watermarks for Event::paginate #21176

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
150 changes: 150 additions & 0 deletions crates/sui-graphql-e2e-tests/tests/stable/prune/events.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// Test that we handle pruned events. When paginating on a cursor, it should be bounded by
// checkpoint consistency. Last graphql query checks that newer events exist.

//# init --protocol-version 51 --addresses Test=0x0 --accounts A B --simulator --epochs-to-keep 1

//# publish
module Test::M1 {
use sui::event;

public struct EventA has copy, drop {
new_value: u64
}

public struct EventB<phantom T> has copy, drop {
new_value: u64
}

public struct Object has key, store {
id: UID,
value: u64,
}

public entry fun create(value: u64, recipient: address, ctx: &mut TxContext) {
transfer::public_transfer(
Object { id: object::new(ctx), value },
recipient
)
}

public entry fun emit_a(o1: &mut Object, value: u64) {
o1.value = value;
event::emit(EventA { new_value: value })
}
}

//# run Test::M1::create --sender A --args 0 @A

//# run Test::M1::emit_a --sender A --args object(2,0) 0

//# create-checkpoint

//# advance-epoch

//# run Test::M1::emit_a --sender A --args object(2,0) 1

//# create-checkpoint

//# run-graphql --wait-for-checkpoint-pruned 1
{
events(filter: {sender: "@{A}"}) {
edges {
cursor
node {
transactionBlock {
effects {
checkpoint {
sequenceNumber
}
}
}
sendingModule {
name
}
sender {
address
}
contents {
type {
repr
}
json
bcs
}
}
}
}
}

//# create-checkpoint

//# run Test::M1::emit_a --sender A --args object(2,0) 2

//# run Test::M1::emit_a --sender A --args object(2,0) 3

//# create-checkpoint

//# run-graphql --cursors {"tx":5,"e":0,"c":3}
{
events(filter: {sender: "@{A}"}, after: "@{cursor_0}") {
edges {
cursor
node {
transactionBlock {
effects {
checkpoint {
sequenceNumber
}
}
}
sendingModule {
name
}
sender {
address
}
contents {
type {
repr
}
json
bcs
}
}
}
}
}

//# run-graphql
{
events(filter: {sender: "@{A}"}) {
edges {
cursor
node {
transactionBlock {
effects {
checkpoint {
sequenceNumber
}
}
}
sendingModule {
name
}
sender {
address
}
contents {
type {
repr
}
json
bcs
}
}
}
}
}
203 changes: 203 additions & 0 deletions crates/sui-graphql-e2e-tests/tests/stable/prune/events.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
---
source: external-crates/move/crates/move-transactional-test-runner/src/framework.rs
---
processed 15 tasks

init:
A: object(0,0), B: object(0,1)

task 1, lines 9-37:
//# publish
created: object(1,0)
mutated: object(0,2)
gas summary: computation_cost: 1000000, storage_cost: 6657600, storage_rebate: 0, non_refundable_storage_fee: 0

task 2, line 39:
//# run Test::M1::create --sender A --args 0 @A
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, line 41:
//# run Test::M1::emit_a --sender A --args object(2,0) 0
events: Event { package_id: Test, transaction_module: Identifier("M1"), sender: A, type_: StructTag { address: Test, module: Identifier("M1"), name: Identifier("EventA"), type_params: [] }, contents: [0, 0, 0, 0, 0, 0, 0, 0] }
mutated: object(0,0), object(2,0)
gas summary: computation_cost: 1000000, storage_cost: 2302800, storage_rebate: 2279772, non_refundable_storage_fee: 23028

task 4, line 43:
//# create-checkpoint
Checkpoint created: 1

task 5, line 45:
//# advance-epoch
Epoch advanced: 0

task 6, line 47:
//# run Test::M1::emit_a --sender A --args object(2,0) 1
events: Event { package_id: Test, transaction_module: Identifier("M1"), sender: A, type_: StructTag { address: Test, module: Identifier("M1"), name: Identifier("EventA"), type_params: [] }, contents: [1, 0, 0, 0, 0, 0, 0, 0] }
mutated: object(0,0), object(2,0)
gas summary: computation_cost: 1000000, storage_cost: 2302800, storage_rebate: 2279772, non_refundable_storage_fee: 23028

task 7, line 49:
//# create-checkpoint
Checkpoint created: 3

task 8, lines 51-80:
//# run-graphql --wait-for-checkpoint-pruned 1
Response: {
"data": {
"events": {
"edges": [
{
"cursor": "eyJ0eCI6NSwiZSI6MCwiYyI6M30",
"node": {
"transactionBlock": {
"effects": {
"checkpoint": {
"sequenceNumber": 3
}
}
},
"sendingModule": {
"name": "M1"
},
"sender": {
"address": "0xfccc9a421bbb13c1a66a1aa98f0ad75029ede94857779c6915b44f94068b921e"
},
"contents": {
"type": {
"repr": "0xa286f296f0fbc2828616670adc9108817eefaa7a440106a2ed54c144582c9401::M1::EventA"
},
"json": {
"new_value": "1"
},
"bcs": "AQAAAAAAAAA="
}
}
}
]
}
}
}

task 9, line 82:
//# create-checkpoint
Checkpoint created: 4

task 10, line 84:
//# run Test::M1::emit_a --sender A --args object(2,0) 2
events: Event { package_id: Test, transaction_module: Identifier("M1"), sender: A, type_: StructTag { address: Test, module: Identifier("M1"), name: Identifier("EventA"), type_params: [] }, contents: [2, 0, 0, 0, 0, 0, 0, 0] }
mutated: object(0,0), object(2,0)
gas summary: computation_cost: 1000000, storage_cost: 2302800, storage_rebate: 2279772, non_refundable_storage_fee: 23028

task 11, line 86:
//# run Test::M1::emit_a --sender A --args object(2,0) 3
events: Event { package_id: Test, transaction_module: Identifier("M1"), sender: A, type_: StructTag { address: Test, module: Identifier("M1"), name: Identifier("EventA"), type_params: [] }, contents: [3, 0, 0, 0, 0, 0, 0, 0] }
mutated: object(0,0), object(2,0)
gas summary: computation_cost: 1000000, storage_cost: 2302800, storage_rebate: 2279772, non_refundable_storage_fee: 23028

task 12, line 88:
//# create-checkpoint
Checkpoint created: 5

task 13, lines 90-119:
//# run-graphql --cursors {"tx":5,"e":0,"c":3}
Response: {
"data": {
"events": {
"edges": []
}
}
}

task 14, lines 121-150:
//# run-graphql
Response: {
"data": {
"events": {
"edges": [
{
"cursor": "eyJ0eCI6NSwiZSI6MCwiYyI6NX0",
"node": {
"transactionBlock": {
"effects": {
"checkpoint": {
"sequenceNumber": 3
}
}
},
"sendingModule": {
"name": "M1"
},
"sender": {
"address": "0xfccc9a421bbb13c1a66a1aa98f0ad75029ede94857779c6915b44f94068b921e"
},
"contents": {
"type": {
"repr": "0xa286f296f0fbc2828616670adc9108817eefaa7a440106a2ed54c144582c9401::M1::EventA"
},
"json": {
"new_value": "1"
},
"bcs": "AQAAAAAAAAA="
}
}
},
{
"cursor": "eyJ0eCI6NiwiZSI6MCwiYyI6NX0",
"node": {
"transactionBlock": {
"effects": {
"checkpoint": {
"sequenceNumber": 5
}
}
},
"sendingModule": {
"name": "M1"
},
"sender": {
"address": "0xfccc9a421bbb13c1a66a1aa98f0ad75029ede94857779c6915b44f94068b921e"
},
"contents": {
"type": {
"repr": "0xa286f296f0fbc2828616670adc9108817eefaa7a440106a2ed54c144582c9401::M1::EventA"
},
"json": {
"new_value": "2"
},
"bcs": "AgAAAAAAAAA="
}
}
},
{
"cursor": "eyJ0eCI6NywiZSI6MCwiYyI6NX0",
"node": {
"transactionBlock": {
"effects": {
"checkpoint": {
"sequenceNumber": 5
}
}
},
"sendingModule": {
"name": "M1"
},
"sender": {
"address": "0xfccc9a421bbb13c1a66a1aa98f0ad75029ede94857779c6915b44f94068b921e"
},
"contents": {
"type": {
"repr": "0xa286f296f0fbc2828616670adc9108817eefaa7a440106a2ed54c144582c9401::M1::EventA"
},
"json": {
"new_value": "3"
},
"bcs": "AwAAAAAAAAA="
}
}
}
]
}
}
}
5 changes: 5 additions & 0 deletions crates/sui-graphql-rpc/src/server/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ pub mod tests {
let watermark = Watermark {
hi_cp: 1,
hi_cp_timestamp_ms: 1,
hi_tx: 1,
epoch: 0,
lo_cp: 0,
lo_tx: 0,
Expand Down Expand Up @@ -1147,6 +1148,10 @@ pub mod tests {
pub async fn test_health_check() {
let cluster = prep_executor_cluster().await;

cluster
.wait_for_checkpoint_catchup(6, Duration::from_secs(60))
.await;

let url = format!(
"http://{}:{}/health",
cluster.graphql_connection_config.host, cluster.graphql_connection_config.port
Expand Down
Loading
Loading