Skip to content

Commit

Permalink
Add script to get all dependencies of a PR
Browse files Browse the repository at this point in the history
  • Loading branch information
bingyanglin committed Jan 15, 2025
1 parent c247952 commit 8d96895
Show file tree
Hide file tree
Showing 13 changed files with 798 additions and 187 deletions.
10 changes: 1 addition & 9 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2353,6 +2353,7 @@ impl AuthorityState {
let object_type = object.data.type_().unwrap().clone();
(version, digest, object_type)
};

DynamicFieldInfo {
name,
bcs_name,
Expand All @@ -2363,15 +2364,6 @@ impl AuthorityState {
digest,
}
}
DynamicFieldType::DynamicField { .. } => DynamicFieldInfo {
name,
bcs_name,
type_,
object_type: move_object.into_type().into_type_params()[1].to_string(),
object_id: o.id(),
version: o.version(),
digest: o.digest(),
},
}))
}

Expand Down
55 changes: 18 additions & 37 deletions crates/iota-core/src/rest_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,45 +671,26 @@ fn try_create_dynamic_field_info(
return Ok(None);
}

let (name_value, dynamic_field_type, object_id) = {
let layout = iota_types::layout_resolver::into_struct_layout(
resolver
.get_annotated_layout(&move_object.type_().clone().into())
.map_err(StorageError::custom)?,
)
.map_err(StorageError::custom)?;

let move_struct = move_object
.to_move_struct(&layout)
.map_err(StorageError::serialization)?;

// SAFETY: move struct has already been validated to be of type DynamicField
DynamicFieldInfo::parse_move_object(&move_struct).unwrap()
};

let name_type = move_object
.type_()
.try_extract_field_name(&dynamic_field_type)
.expect("object is of type Field");

let name_value = name_value
.undecorate()
.simple_serialize()
.expect("serialization cannot fail");

let dynamic_object_id = match dynamic_field_type {
DynamicFieldType::DynamicObject => Some(object_id),
DynamicFieldType::DynamicField => None,
};
let layout = resolver
.get_annotated_layout(&move_object.type_().clone().into())
.map_err(StorageError::custom)?
.into_layout();

let field_info = DynamicFieldIndexInfo {
name_type,
name_value,
dynamic_field_type,
dynamic_object_id,
};
let field = DFV::FieldVisitor::deserialize(move_object.contents(), &layout)
.map_err(StorageError::custom)?;

Ok(Some(field_info))
let value_metadata = field.value_metadata().map_err(StorageError::custom)?;

Ok(Some(DynamicFieldIndexInfo {
name_type: field.name_layout.into(),
name_value: field.name_bytes.to_owned(),
dynamic_field_type: field.kind,
dynamic_object_id: if let DFV::ValueMetadata::DynamicObjectField(id) = value_metadata {
Some(id)
} else {
None
},
}))
}

fn try_create_coin_index_info(object: &Object) -> Option<(CoinIndexKey, CoinIndexInfo)> {
Expand Down
42 changes: 11 additions & 31 deletions crates/iota-indexer/src/handlers/checkpoint_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,25 +556,16 @@ where
.collect();

let latest_live_output_objects = data.latest_live_output_objects();
let latest_live_output_object_map = latest_live_output_objects
.clone()
.into_iter()
.map(|o| (o.id(), o.clone()))
.collect::<HashMap<_, _>>();
let move_struct_layout_map =
get_move_struct_layout_map(latest_live_output_objects.clone(), package_resolver)
.await?;
let latest_live_output_object_layouts =
type_layout_map(&latest_live_output_objects, package_resolver).await?;
let changed_objects = latest_live_output_objects
.into_iter()
.map(|o| {
let df_info = try_create_dynamic_field_info(
o,
&move_struct_layout_map,
&latest_live_output_object_map,
);
df_info.map(|info| IndexedObject::from_object(checkpoint_seq, o.clone(), info))
try_extract_df_kind(o, &latest_live_output_object_layouts)
.map(|df_kind| IndexedObject::from_object(checkpoint_seq, o.clone(), df_kind))
})
.collect::<Result<Vec<_>, _>>()?;

Ok(TransactionObjectChangesToCommit {
changed_objects,
deleted_objects: indexed_eventually_removed_objects,
Expand All @@ -601,31 +592,20 @@ where
})
.collect();

let latest_live_output_objects = data.latest_live_output_objects();
let latest_live_output_object_map = latest_live_output_objects
.clone()
.into_iter()
.map(|o| (o.id(), o.clone()))
.collect::<HashMap<_, _>>();

let output_objects = data
let output_objects: Vec<_> = data
.transactions
.iter()
.flat_map(|tx| &tx.output_objects)
.collect::<Vec<_>>();
.collect();

// TODO(gegaowp): the current df_info implementation is not correct,
// but we have decided remove all df_* except df_kind.
let move_struct_layout_map =
get_move_struct_layout_map(output_objects.clone(), package_resolver).await?;
let output_layouts = type_layout_map(&output_objects, package_resolver).await?;
let changed_objects = output_objects
.into_iter()
.map(|o| {
let df_info = try_create_dynamic_field_info(
o,
&move_struct_layout_map,
&latest_live_output_object_map,
);
df_info.map(|info| IndexedObject::from_object(checkpoint_seq, o.clone(), info))
try_extract_df_kind(o, &output_layouts)
.map(|df_kind| IndexedObject::from_object(checkpoint_seq, o.clone(), df_kind))
})
.collect::<Result<Vec<_>, _>>()?;

Expand Down
4 changes: 2 additions & 2 deletions crates/iota-indexer/src/models/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl From<IndexedObject> for StoredObject {
let IndexedObject {
checkpoint_sequence_number,
object,
df_info,
df_kind,
} = o;
let (owner_type, owner_id) = owner_to_owner_info(&object.owner);
let coin_type = object
Expand All @@ -262,7 +262,7 @@ impl From<IndexedObject> for StoredObject {
serialized_object: bcs::to_bytes(&object).unwrap(),
coin_type,
coin_balance: coin_balance.map(|b| b as i64),
df_kind: df_info.as_ref().map(|k| match k.type_ {
df_kind: df_kind.map(|k| match k {
DynamicFieldType::DynamicField => 0,
DynamicFieldType::DynamicObject => 1,
}),
Expand Down
6 changes: 3 additions & 3 deletions crates/iota-indexer/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,19 @@ pub enum DynamicFieldKind {
pub struct IndexedObject {
pub checkpoint_sequence_number: CheckpointSequenceNumber,
pub object: Object,
pub df_info: Option<DynamicFieldInfo>,
pub df_kind: Option<DynamicFieldType>,
}

impl IndexedObject {
pub fn from_object(
checkpoint_sequence_number: CheckpointSequenceNumber,
object: Object,
df_info: Option<DynamicFieldInfo>,
df_kind: Option<DynamicFieldType>,
) -> Self {
Self {
checkpoint_sequence_number,
object,
df_info,
df_kind,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/iota-types/src/dynamic_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ impl Display for DynamicFieldName {
}
}

#[derive(Clone, Serialize, Deserialize, JsonSchema, Ord, PartialOrd, Eq, PartialEq, Debug)]
#[derive(
Copy, Clone, Serialize, Deserialize, JsonSchema, Ord, PartialOrd, Eq, PartialEq, Debug,
)]
pub enum DynamicFieldType {
#[serde(rename_all = "camelCase")]
DynamicField,
Expand Down
14 changes: 9 additions & 5 deletions crates/iota-types/src/object/balance_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::collections::BTreeMap;

use move_core_types::{
annotated_visitor::{self, StructDriver, Traversal},
annotated_visitor::{self, StructDriver, Traversal, ValueDriver},
language_storage::{StructTag, TypeTag},
};

Expand All @@ -31,12 +31,12 @@ impl BalanceTraversal {
}
}

impl Traversal for BalanceTraversal {
impl<'b, 'l> Traversal<'b, 'l> for BalanceTraversal {
type Error = annotated_visitor::Error;

fn traverse_struct(
&mut self,
driver: &mut StructDriver<'_, '_, '_>,
driver: &mut StructDriver<'_, 'b, 'l>,
) -> Result<(), Self::Error> {
let Some(coin_type) = is_balance(&driver.struct_layout().type_) else {
// Not a balance, search recursively for balances among fields.
Expand All @@ -51,9 +51,13 @@ impl Traversal for BalanceTraversal {
}
}

impl Traversal for Accumulator {
impl<'b, 'l> Traversal<'b, 'l> for Accumulator {
type Error = annotated_visitor::Error;
fn traverse_u64(&mut self, value: u64) -> Result<(), Self::Error> {
fn traverse_u64(
&mut self,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u64,
) -> Result<(), Self::Error> {
self.total += value;
Ok(())
}
Expand Down
64 changes: 50 additions & 14 deletions crates/iota-types/src/object/bounded_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anyhow::bail;
use move_core_types::{
account_address::AccountAddress,
annotated_value as A,
annotated_visitor::{self, StructDriver, VecDriver, Visitor},
annotated_visitor::{self, StructDriver, ValueDriver, VecDriver, Visitor},
language_storage::TypeTag,
u256::U256,
};
Expand Down Expand Up @@ -152,49 +152,85 @@ impl BoundedVisitor {
}
}

impl Visitor for BoundedVisitor {
impl<'b, 'l> Visitor<'b, 'l> for BoundedVisitor {
type Value = A::MoveValue;
type Error = Error;

fn visit_u8(&mut self, value: u8) -> Result<Self::Value, Self::Error> {
fn visit_u8(
&mut self,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u8,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U8(value))
}

fn visit_u16(&mut self, value: u16) -> Result<Self::Value, Self::Error> {
fn visit_u16(
&mut self,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u16,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U16(value))
}

fn visit_u32(&mut self, value: u32) -> Result<Self::Value, Self::Error> {
fn visit_u32(
&mut self,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u32,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U32(value))
}

fn visit_u64(&mut self, value: u64) -> Result<Self::Value, Self::Error> {
fn visit_u64(
&mut self,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u64,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U64(value))
}

fn visit_u128(&mut self, value: u128) -> Result<Self::Value, Self::Error> {
fn visit_u128(
&mut self,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u128,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U128(value))
}

fn visit_u256(&mut self, value: U256) -> Result<Self::Value, Self::Error> {
fn visit_u256(
&mut self,
_driver: &ValueDriver<'_, 'b, 'l>,
value: U256,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U256(value))
}

fn visit_bool(&mut self, value: bool) -> Result<Self::Value, Self::Error> {
fn visit_bool(
&mut self,
_driver: &ValueDriver<'_, 'b, 'l>,
value: bool,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::Bool(value))
}

fn visit_address(&mut self, value: AccountAddress) -> Result<Self::Value, Self::Error> {
fn visit_address(
&mut self,
_driver: &ValueDriver<'_, 'b, 'l>,
value: AccountAddress,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::Address(value))
}

fn visit_signer(&mut self, value: AccountAddress) -> Result<Self::Value, Self::Error> {
fn visit_signer(
&mut self,
_driver: &ValueDriver<'_, 'b, 'l>,
value: AccountAddress,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::Signer(value))
}

fn visit_vector(
&mut self,
driver: &mut VecDriver<'_, '_, '_>,
driver: &mut VecDriver<'_, 'b, 'l>,
) -> Result<Self::Value, Self::Error> {
let mut elems = vec![];
while let Some(elem) = driver.next_element(self)? {
Expand All @@ -206,7 +242,7 @@ impl Visitor for BoundedVisitor {

fn visit_struct(
&mut self,
driver: &mut StructDriver<'_, '_, '_>,
driver: &mut StructDriver<'_, 'b, 'l>,
) -> Result<Self::Value, Self::Error> {
let tag = driver.struct_layout().type_.clone().into();

Expand All @@ -232,7 +268,7 @@ impl Visitor for BoundedVisitor {

fn visit_variant(
&mut self,
driver: &mut annotated_visitor::VariantDriver<'_, '_, '_>,
driver: &mut annotated_visitor::VariantDriver<'_, 'b, 'l>,
) -> Result<Self::Value, Self::Error> {
let type_ = driver.enum_layout().type_.clone().into();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use serde::{

use crate::{
account_address::AccountAddress,
annotated_visitor::{visit_struct, visit_value, Error as VError, Visitor},
annotated_visitor::{visit_struct, visit_value, Error as VError, ValueDriver, Visitor},
identifier::Identifier,
language_storage::{StructTag, TypeTag},
runtime_value::{self as R, MOVE_STRUCT_FIELDS, MOVE_STRUCT_TYPE},
Expand Down Expand Up @@ -79,7 +79,7 @@ pub enum MoveValue {
Variant(MoveVariant),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct MoveFieldLayout {
pub name: Identifier,
pub layout: MoveTypeLayout,
Expand Down Expand Up @@ -120,7 +120,7 @@ impl MoveDatatypeLayout {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum MoveTypeLayout {
#[serde(rename(serialize = "bool", deserialize = "bool"))]
Bool,
Expand Down
Loading

0 comments on commit 8d96895

Please sign in to comment.