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

graphql: filter transactions by affected object #19474

Merged
merged 2 commits into from
Sep 30, 2024
Merged

Conversation

amnn
Copy link
Member

@amnn amnn commented Sep 21, 2024

Description

Add support for filtering transactions by the objects they touch, which will supersede filtering by a transaction's input and output objects.

This feature will exist only in staging mode until the underlying data has been fully backfilled.

Test plan

New staging-only tests:

sui$ cargo nextest run -p sui-graphql-e2e-tests --features staging -- affected_object

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:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • REST API:

Copy link

vercel bot commented Sep 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 30, 2024 10:35am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Sep 30, 2024 10:35am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Sep 30, 2024 10:35am
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Sep 30, 2024 10:35am

## Description

Add support for filtering transactions by the objects they touch, which
will supersede filtering by a transaction's input and output objects.

This feature will exist only in staging mode until the underlying data
has been fully backfilled.

## Test plan

New staging-only tests:

```
sui$ cargo nextest run -p sui-graphql-e2e-tests --features staging -- affected_object
```
@amnn amnn merged commit 841f5e3 into main Sep 30, 2024
48 checks passed
@amnn amnn deleted the amnn/tx-affected-obj-gql branch September 30, 2024 14:32
amnn added a commit that referenced this pull request Sep 30, 2024
## Description

Add an `AffectedObject` filter on `TransactionFilter` and implement it
in `IndexerReader` and in the subscription system.

This filter is not implemented on fullnode indices, and in a follow-up
PR, support for `InputObject` and `ChangedObject` will be removed from
the PG-backed implementation of JSON-RPC.

It was difficult to replace `InputObject`/`ChangedObject` support on
fullnode with `AffectedObject` because we don't have (and don't want to
add) the necessary indices, and the current filters are referred to in
certain tests.

## Test plan

Manually tested with a local network:

```
sui$ cargo run --bin sui -- start --with-indexer --force-regenesis
```

```
sui$ curl -LX POST  "http://localhost:9124" \
        --header 'Content-Type: application/json' \
        --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "suix_queryTransactionBlocks",
  "params": [
    { "filter": { "AffectedObject":"0x2" } },
    null,
    50,
    true
  ]
}' | jq '.result.data.[].digest'
```

## Stack

- #19474 

---

## 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): 
- [x] Indexer: Adds support for filtering transactions by their affected
object
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
amnn added a commit that referenced this pull request Sep 30, 2024
## Description

Deprecate `InputObject` and `OutputObject` as filters in IndexerReader,
to be replaced by `AffectedObject`.

## Test plan

Tested manually:

```
sui$ cargo run --bin sui -- start --with-indexer --force-regenesis
```

```
curl -LX POST  "http://localhost:9124" \
       --header 'Content-Type: application/json' \
       --data '{
 "jsonrpc": "2.0",
 "id": 1,
 "method": "suix_queryTransactionBlocks",
 "params": [
   {
     "filter": {
       "ChangedObject":"0x2"
     }
   },
   null,
   50,
   true
 ]
' | jq .

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32000,
    "message": "Indexer does not support the feature with error: `InputObject and OutputObject filters are not supported, please use AffectedObject instead.`"
  },
  "id": 1
}
```

## Stack

- #19474 
- #19614 

---

## 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): 
- [x] Indexer: Remove support for `InputObject` and `OutputObject`
transaction filters (replaced by `AffectedObject`).
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
amnn added a commit that referenced this pull request Sep 30, 2024
## Description

Remove support for filtering by `ToAddress` in PG-backed JSON-RPC. At
the same time, change implementations for `FromAndToAddress` and
`FromOrToAddress` to use the new `tx_affected_addresses` table, which
should be more efficient.

## Test plan

Manually tested:

```
sui$ cargo run --bin sui -- --force-regenesis \
  --with-faucet --with-indexer
```

```
sui$ $SUI client faucet
sui$ $SUI client ptb --transfer-objects [gas] @0x42
sui$ curl -LX POST  "http://localhost:9124" \
        --header 'Content-Type: application/json' \
        --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "suix_queryTransactionBlocks",
  "params": [
    {
      "filter": {
        "FromOrToAddress": { "addr": "'($SUI client active-address)'" }
      }
    },
    null,
    50,
    true
  ]
}' | jq .result.data.[].digest

"4NDjddQA8Q158EuskHm73AVoo4Gmr6SknuTv1nzghVd1"
"5EECPcG6ZbUaH6nXCZWazpg6vcsC33nfnEw6qVkAnN9W"

sui$ curl -LX POST  "http://localhost:9124" \
        --header 'Content-Type: application/json' \
        --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "suix_queryTransactionBlocks",
  "params": [
    {
      "filter": {
        "FromOrToAddress": { "addr": "0x0000000000000000000000000000000000000000000000000000000000000042" }
      }
    },
    null,
    50,
    true
  ]
}' | jq .result.data.[].digest

"4NDjddQA8Q158EuskHm73AVoo4Gmr6SknuTv1nzghVd1"

sui$ curl -LX POST  "http://localhost:9124" \
        --header 'Content-Type: application/json' \
        --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "suix_queryTransactionBlocks",
  "params": [
    {
      "filter": {
        "FromAndToAddress": {
          "from": "'($SUI client active-address)'",
          "to": "0x0000000000000000000000000000000000000000000000000000000000000042"
        }
      }
    },
    null,
    50,
    true
  ]
}' | jq .result.data.[].digest

"4NDjddQA8Q158EuskHm73AVoo4Gmr6SknuTv1nzghVd1"

```

## Stack

- #19474 
- #19614 
- #19615 

---

## 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): 
- [x] Indexer: Remove support for filtering transactions by `ToAddress`,
(instead of `FromOrToAddress`).
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
amnn added a commit that referenced this pull request Sep 30, 2024
## Description

This PR removes EventFilters from JSON-RPC that aren't supported already
by fullnode-backed JSON-RPC:

- Combination filters (`All`, `Any`, `Not`, `And`, `Or`)
- `Package`
- `EventField`

These filters were, however, supported by the now-deprecated
subscription system, so a question remains whether they are safe to
remove.

## Test plan

Manually tested, in particular `All: []` support, which we do still need
to keep as a way to get all filters (this was also added to the
`IndexerReader` implementation):

```
sui$ cargo run --bin sui -- --force-regenesis \
  --with-indexer --with-faucet
```

...run for some time, so that some system events accumulate, then test
that we get them from both the fullnode-backed JSONRPC and
indexer-backed:

Fullnode:
```
curl -LX POST  "http://localhost:9000" \
        --header 'Content-Type: application/json' \
        --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "suix_queryEvents",
  "params": [
    {
      "All": []
    },
    null,
    50,
    true
  ]
}' | jq .
```

Indexer:
```
curl -LX POST  "http://localhost:9124" \
        --header 'Content-Type: application/json' \
        --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "suix_queryEvents",
  "params": [
    {
      "All": []
    },
    null,
    50,
    true
  ]
}' | jq .
```

## Stack

- #19474 
- #19614 
- #19615 
- #19616 

---

## 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: 
- [x] Nodes (Validators and Full nodes): Remove unsupported compound
filters for querying events from the JSON-RPC schema to avoid confusion.
Remove support for compound filters from the deprecated events
subscription system.
- [x] Indexer: Remove compound filters for querying events.
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
amnn added a commit that referenced this pull request Sep 30, 2024
…19618)

## Description

Broaden the definition of "affected object" to include objects that a
transaction creates and then immediately wraps, or objects that it
unwraps and then immediately deletes. This ensures that a transaction
will show up in the response to an `affectedObject` query if and only if
the Object's ID shows up in its `objectChanges` response.

## Test plan

Updated GraphQL E2E test:

```
sui$ cargo nextest run -p sui-graphql-e2e-tests \
  --features staging -- affected_object
```

## Stack

- #19474 
- #19614 
- #19615 
- #19616 
- #19617

---

## 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): 
- [x] Indexer: A transaction's "affected objects" include objects that
it created and wrapped, or unwrapped.
- [x] JSON-RPC: A transaction's "affected objects" include objects that
it created and wrapped, or unwrapped.
- [x] GraphQL: A transaction's "affected objects" include objects that
it created and wrapped, or unwrapped.
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants