Skip to content

Commit

Permalink
Fix Dynamic Field Cursor Index Bug (#11789) (#11791)
Browse files Browse the repository at this point in the history
## Description 

Cherrypick of #11789
Fixes dynamic field pagination/cursor issue:
#7686


## Test Plan 

Manual testing

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [x] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes

## Description 

Describe the changes or additions included in this PR.

## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
oxade authored May 7, 2023
1 parent d56e02c commit 38c31cd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2238,8 +2238,8 @@ impl AuthorityState {
let df = self
.get_dynamic_fields_iterator(table, None)
.ok()?
.find(|df| key_bcs == df.bcs_name)?;
let field: Field<K, V> = self.get_move_object(&df.object_id).ok()?;
.find(|(_, df)| key_bcs == df.bcs_name)?;
let field: Field<K, V> = self.get_move_object(&df.1.object_id).ok()?;
Some(field.value)
}

Expand Down Expand Up @@ -2420,7 +2420,7 @@ impl AuthorityState {
// If `Some`, the query will start from the next item after the specified cursor
cursor: Option<ObjectID>,
limit: usize,
) -> SuiResult<Vec<DynamicFieldInfo>> {
) -> SuiResult<Vec<(ObjectID, DynamicFieldInfo)>> {
Ok(self
.get_dynamic_fields_iterator(owner, cursor)?
.take(limit)
Expand All @@ -2432,7 +2432,7 @@ impl AuthorityState {
owner: ObjectID,
// If `Some`, the query will start from the next item after the specified cursor
cursor: Option<ObjectID>,
) -> SuiResult<impl Iterator<Item = DynamicFieldInfo> + '_> {
) -> SuiResult<impl Iterator<Item = (ObjectID, DynamicFieldInfo)> + '_> {
if let Some(indexes) = &self.indexes {
indexes.get_dynamic_fields_iterator(owner, cursor)
} else {
Expand Down
5 changes: 4 additions & 1 deletion crates/sui-core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3417,7 +3417,10 @@ async fn create_and_retrieve_df_info(function: &IdentStr) -> (SuiAddress, Vec<Dy
sender,
authority_state
.get_dynamic_fields(outer_v0.0, None, usize::MAX)
.unwrap(),
.unwrap()
.into_iter()
.map(|x| x.1)
.collect(),
)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/sui-json-rpc/src/governance_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ async fn exchange_rates(
system_state_summary.inactive_pools_size as usize,
)? {
let pool_id: ID =
bcs::from_bytes(&df.bcs_name).map_err(|e| SuiError::ObjectDeserializationError {
bcs::from_bytes(&df.1.bcs_name).map_err(|e| SuiError::ObjectDeserializationError {
error: e.to_string(),
})?;
let validator = get_validator_from_table(
Expand All @@ -380,7 +380,7 @@ async fn exchange_rates(
.get_dynamic_fields(exchange_rates_id, None, exchange_rates_size as usize)?
.into_iter()
.map(|df| {
let epoch: EpochId = bcs::from_bytes(&df.bcs_name).map_err(|e| {
let epoch: EpochId = bcs::from_bytes(&df.1.bcs_name).map_err(|e| {
SuiError::ObjectDeserializationError {
error: e.to_string(),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-json-rpc/src/indexer_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ impl<R: ReadApiServer> IndexerApiServer for IndexerApi<R> {
.map_err(|e| anyhow!("{e}"))?;
let has_next_page = data.len() > limit;
data.truncate(limit);
let next_cursor = data.last().cloned().map_or(cursor, |c| Some(c.object_id));
let next_cursor = data.last().cloned().map_or(cursor, |c| Some(c.0));
self.metrics
.get_dynamic_fields_result_size
.report(data.len() as u64);
self.metrics
.get_dynamic_fields_result_size_total
.inc_by(data.len() as u64);
Ok(DynamicFieldPage {
data,
data: data.into_iter().map(|(_, w)| w).collect(),
next_cursor,
has_next_page,
})
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-storage/src/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ impl IndexStore {
&self,
object: ObjectID,
cursor: Option<ObjectID>,
) -> SuiResult<impl Iterator<Item = DynamicFieldInfo> + '_> {
) -> SuiResult<impl Iterator<Item = (ObjectID, DynamicFieldInfo)> + '_> {
debug!(?object, "get_dynamic_fields");
let iter_lower_bound = (object, ObjectID::ZERO);
let iter_upper_bound = (object, ObjectID::MAX);
Expand All @@ -1100,7 +1100,7 @@ impl IndexStore {
// skip an extra b/c the cursor is exclusive
.skip(usize::from(cursor.is_some()))
.take_while(move |((object_owner, _), _)| (object_owner == &object))
.map(|(_, object_info)| object_info))
.map(|((_, c), object_info)| (c, object_info)))
}

pub fn get_dynamic_field_object_id(
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-tool/src/db_tool/db_dump.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::anyhow;
use anyhow::{anyhow, Ok};
use clap::{Parser, ValueEnum};
use comfy_table::{Cell, ContentArrangement, Row, Table};
use rocksdb::MultiThreaded;
Expand Down

0 comments on commit 38c31cd

Please sign in to comment.