Skip to content

Commit 98b517f

Browse files
authored
fix(rocksdb): prioritize slot ordering over version in comparison logic [MTG-1415] (#446)
* fix(rocksdb): prioritize slot ordering over version in comparison logic Change the comparison order in macro to check slot_updated values first before checking update_version. This ensures account-based assets are properly indexed by slot-first ordering, which better represents the correct temporal sequence of asset updates. Closes MTG-1415 * chore: fmt * test: Fix tests after reprioritising the ordering
1 parent 370d3d3 commit 98b517f

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

rocks-db/src/columns/asset.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -3607,7 +3607,12 @@ mod tests {
36073607
}
36083608
assert!(asset.other_known_owners().is_none());
36093609
let asset_mapped = AssetCompleteDetails::from(asset);
3610-
assert_eq!(asset_mapped.owner.unwrap().owner.value.unwrap(), new_owner);
3610+
// Now that slot is prioritized over version, we expect the existing owner to be kept
3611+
// because the new owner has a smaller slot (1) despite higher write version
3612+
assert_eq!(
3613+
asset_mapped.owner.as_ref().unwrap().owner.value.unwrap(),
3614+
Pubkey::from_str(EXISTING_OWNER).unwrap()
3615+
);
36113616
}
36123617

36133618
#[test]
@@ -3650,13 +3655,9 @@ mod tests {
36503655
}
36513656
assert!(asset.other_known_owners().is_none());
36523657
let asset_mapped = AssetCompleteDetails::from(asset);
3653-
assert_eq!(
3654-
asset_mapped.owner.as_ref().unwrap().owner.value.unwrap(),
3655-
Pubkey::from_str(EXISTING_OWNER).unwrap()
3656-
);
3657-
// This is ther case, when the is current owner was not ever set and now it's updated by some old update.
3658-
// This update shouldn't have happened as usually the vesioning of owner, delegate and is_current_owner is done together.
3659-
// For the case of empty data after the migration this is acceptable imho.
3658+
// With slot prioritized over version, the new owner should be used because it has a higher slot
3659+
// even though it has a smaller write version
3660+
assert_eq!(asset_mapped.owner.as_ref().unwrap().owner.value.unwrap(), new_owner);
36603661
assert!(asset_mapped.owner.unwrap().is_current_owner.value);
36613662
}
36623663

rocks-db/src/mappers.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,19 @@ macro_rules! impl_partial_ord_for_updated {
228228
($name:ident) => {
229229
impl PartialOrd for fb::$name<'_> {
230230
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
231-
Some(match self.update_version().partial_cmp(&other.update_version()) {
232-
Some(std::cmp::Ordering::Equal) => {
233-
self.slot_updated().cmp(&other.slot_updated())
234-
},
235-
Some(ord) => ord,
236-
None => self.slot_updated().cmp(&other.slot_updated()),
237-
})
231+
// Compare slot_updated first
232+
let slot_order = self.slot_updated().cmp(&other.slot_updated());
233+
234+
// If slots are equal, then check update_version
235+
if slot_order == Ordering::Equal {
236+
match self.update_version().partial_cmp(&other.update_version()) {
237+
Some(ord) => Some(ord),
238+
None => Some(Ordering::Equal), // If versions can't be compared, consider them equal since slots are equal
239+
}
240+
} else {
241+
// If slots are different, use that ordering
242+
Some(slot_order)
243+
}
238244
}
239245
}
240246
};

0 commit comments

Comments
 (0)