Skip to content

Commit

Permalink
pick(19618), indexer: affected objects include created+wrapped/unwrap…
Browse files Browse the repository at this point in the history
…ped+deleted (#19620)

## 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
```
---

## 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 Sep 30, 2024
1 parent 313798d commit 218db6e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
25 changes: 15 additions & 10 deletions crates/sui-indexer/src/handlers/checkpoint_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sui_types::base_types::ObjectID;
use sui_types::dynamic_field::DynamicFieldInfo;
use sui_types::dynamic_field::DynamicFieldName;
use sui_types::dynamic_field::DynamicFieldType;
use sui_types::effects::TransactionEffectsAPI;
use sui_types::effects::{ObjectChange, TransactionEffectsAPI};
use sui_types::event::SystemEpochInfoEvent;
use sui_types::messages_checkpoint::{
CertifiedCheckpointSummary, CheckpointContents, CheckpointSequenceNumber,
Expand Down Expand Up @@ -441,10 +441,7 @@ impl CheckpointHandler {
.map(|display| (display.object_type.clone(), display)),
);

let objects = input_objects
.iter()
.chain(output_objects.iter())
.collect::<Vec<_>>();
let objects: Vec<_> = input_objects.iter().chain(output_objects.iter()).collect();

let (balance_change, object_changes) =
TxChangesProcessor::new(&objects, metrics.clone())
Expand Down Expand Up @@ -477,14 +474,21 @@ impl CheckpointHandler {
.expect("committed txns have been validated")
.into_iter()
.map(|obj_kind| obj_kind.object_id())
.collect::<Vec<_>>();
.collect();

// Changed Objects
let changed_objects = fx
.all_changed_objects()
.into_iter()
.map(|(object_ref, _owner, _write_kind)| object_ref.0)
.collect::<Vec<_>>();
.collect();

// Affected Objects
let affected_objects = fx
.object_changes()
.into_iter()
.map(|ObjectChange { id, .. }| id)
.collect();

// Payers
let payers = vec![tx.gas_owner()];
Expand All @@ -501,13 +505,13 @@ impl CheckpointHandler {
_ => None,
})
.unique()
.collect::<Vec<_>>();
.collect();

// Move Calls
let move_calls = tx
.move_calls()
.iter()
.map(|(p, m, f)| (*<&ObjectID>::clone(p), m.to_string(), f.to_string()))
.into_iter()
.map(|(p, m, f)| (*p, m.to_string(), f.to_string()))
.collect();

db_tx_indices.push(TxIndex {
Expand All @@ -516,6 +520,7 @@ impl CheckpointHandler {
checkpoint_sequence_number: *checkpoint_seq,
input_objects,
changed_objects,
affected_objects,
sender,
payers,
recipients,
Expand Down
4 changes: 1 addition & 3 deletions crates/sui-indexer/src/models/tx_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@ impl TxIndex {
.collect();

let tx_affected_objects = self
.input_objects
.affected_objects
.iter()
.chain(self.changed_objects.iter())
.unique()
.map(|o| StoredTxAffectedObjects {
tx_sequence_number,
affected: o.to_vec(),
Expand Down
1 change: 1 addition & 0 deletions crates/sui-indexer/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ pub struct TxIndex {
pub checkpoint_sequence_number: u64,
pub input_objects: Vec<ObjectID>,
pub changed_objects: Vec<ObjectID>,
pub affected_objects: Vec<ObjectID>,
pub payers: Vec<SuiAddress>,
pub sender: SuiAddress,
pub recipients: Vec<SuiAddress>,
Expand Down

0 comments on commit 218db6e

Please sign in to comment.