Skip to content

Commit

Permalink
indexer-reader: remove references to tx_senders (#19802)
Browse files Browse the repository at this point in the history
## Description

Replace uses of `tx_senders` in `IndexerReader`, with other tables that
can offer equivalent functionality, so that we can eventually get rid of
this table.

In transaction filtering, we support filtering by sender using
`tx_affected_addresses` (where setting both `sender` and `affected` is
equivalent to querying `tx_senders` by `sender`).

In event filtering, we support filtering by sender using the
`event_senders` table.

## Test plan

Manually tested Indexer Reader on the following package:

```move
module test::test;

use sui::event;

public struct Event(u64) has copy, drop, store;

public fun emit() {
  10u64.do!(|i| event::emit(Event(i)))
}
```

Start the local network:

```
sui$ sui start --force-regenesis --with-faucet --with-indexer
```

Set-up two addresses, and call the test function:

```
sui$ sui client faucet
sui$ sui client ptb --call "$PKG::test::emit"
sui$ sui client switch --address X
sui$ sui client faucet
sui$ sui client ptb --call "$PKG::test::emit"
```

Run the query against both addresses:

```
curl -LX POST "http://localhost:9124" \
        --header 'Content-Type: application/json' \
        --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "suix_queryEvents",
  "params": [
    {
      "Sender": "'(sui client active-address)'"
    },
    null,
    5
  ]
}' | jq .
```

## Stack

- #19708 

---

## 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:
  • Loading branch information
amnn authored Oct 11, 2024
1 parent 7d006ef commit 86e6e88
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions crates/sui-indexer/src/indexer_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,8 @@ impl IndexerReader {
Some(TransactionFilter::FromAddress(from_address)) => {
let from_address = Hex::encode(from_address.to_vec());
(
"tx_senders".to_owned(),
format!("sender = '\\x{from_address}'::bytea"),
"tx_affected_addresses".to_owned(),
format!("sender = '\\x{from_address}'::bytea AND affected = '\\x{from_address}'::bytea"),
)
}
Some(TransactionFilter::FromAndToAddress { from, to }) => {
Expand Down Expand Up @@ -997,11 +997,10 @@ impl IndexerReader {
format!(
"( \
SELECT *
FROM tx_senders s
FROM event_senders s
JOIN events e
ON e.tx_sequence_number = s.tx_sequence_number
AND s.sender = '\\x{}'::bytea
WHERE {} \
USING (tx_sequence_number, event_sequence_number)
WHERE s.sender = '\\x{}'::bytea AND {} \
ORDER BY {} \
LIMIT {}
)",
Expand Down

0 comments on commit 86e6e88

Please sign in to comment.