Skip to content

Commit

Permalink
Fix a bug in TransactionEffects that didn't capture unwrapped objects (
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind authored Jul 21, 2022
1 parent ede61fb commit d3dbcf2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ impl AuthorityState {
indexes.index_tx(
cert.sender_address(),
cert.data.input_objects()?.iter().map(|o| o.object_id()),
effects.effects.mutated_and_created(),
effects.effects.all_mutated(),
cert.data
.move_calls()?
.iter()
Expand Down
9 changes: 5 additions & 4 deletions crates/sui-core/src/gateway_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,14 @@ where

debug!(
digest = ?tx_digest,
?effects.effects,
"Transaction completed successfully"
);

// Download the latest content of every mutated object from the authorities.
let mutated_object_refs: BTreeSet<_> = effects
.effects
.mutated_and_created()
.all_mutated()
.map(|(obj_ref, _)| *obj_ref)
.collect();
let mutated_objects = self
Expand Down Expand Up @@ -561,7 +562,7 @@ where
self.store.insert_object_direct(*obj_ref, object).await?;
}
}
debug!(?result, "Downloaded object from authorities");
debug!("Downloaded object from authorities: {}", result);

Ok(result)
}
Expand Down Expand Up @@ -615,14 +616,14 @@ where
// latest objects.
let mutated_objects = self.store.get_objects(
&effects
.mutated_and_created()
.all_mutated()
.map(|((object_id, _, _), _)| *object_id)
.collect::<Vec<_>>(),
)?;
let mut updated_gas = None;
let mut package = None;
let mut created_objects = vec![];
for ((obj_ref, _), object) in effects.mutated_and_created().zip(mutated_objects) {
for ((obj_ref, _), object) in effects.all_mutated().zip(mutated_objects) {
let object = object.ok_or(SuiError::InconsistentGatewayResult {
error: format!(
"Crated/Updated object doesn't exist in the store: {:?}",
Expand Down
16 changes: 10 additions & 6 deletions crates/sui-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,11 +1312,15 @@ pub struct TransactionEffects {
}

impl TransactionEffects {
/// Return an iterator that iterates through both mutated and
/// created objects.
/// It doesn't include deleted objects.
pub fn mutated_and_created(&self) -> impl Iterator<Item = &(ObjectRef, Owner)> + Clone {
self.mutated.iter().chain(self.created.iter())
/// Return an iterator that iterates through all mutated objects, including mutated,
/// created and unwrapped objects. In other words, all objects that still exist
/// in the object state after this transaction.
/// It doesn't include deleted/wrapped objects.
pub fn all_mutated(&self) -> impl Iterator<Item = &(ObjectRef, Owner)> + Clone {
self.mutated
.iter()
.chain(self.created.iter())
.chain(self.unwrapped.iter())
}

/// Return an iterator of mutated objects, but excluding the gas object.
Expand All @@ -1330,7 +1334,7 @@ impl TransactionEffects {

pub fn is_object_mutated_here(&self, obj_ref: ObjectRef) -> bool {
// The mutated or created case
if self.mutated_and_created().any(|(oref, _)| *oref == obj_ref) {
if self.all_mutated().any(|(oref, _)| *oref == obj_ref) {
return true;
}

Expand Down

0 comments on commit d3dbcf2

Please sign in to comment.