Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging for indexer models and processors #505

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,24 @@ impl CoinActivity {
}

// Need coin info from move resources
for wsc in &transaction_info.changes {
for (wsc_index, wsc) in transaction_info.changes.iter().enumerate() {
let (maybe_coin_info, maybe_coin_balance_data) =
if let WriteSetChangeEnum::WriteResource(write_resource) =
&wsc.change.as_ref().unwrap()
{
(
CoinInfo::from_write_resource(write_resource, txn_version, txn_timestamp)
.unwrap(),
CoinInfo::from_write_resource(
write_resource,
txn_version,
txn_timestamp,
wsc_index as i64,
)
.unwrap(),
CoinBalance::from_write_resource(
write_resource,
txn_version,
txn_timestamp,
wsc_index as i64,
)
.unwrap(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ impl CoinBalance {
write_resource: &WriteResource,
txn_version: i64,
txn_timestamp: chrono::NaiveDateTime,
wsc_index: i64,
) -> anyhow::Result<Option<(Self, CurrentCoinBalance, EventToCoinType)>> {
match &CoinResource::from_write_resource(write_resource, txn_version)? {
Some(CoinResource::CoinStoreResource(inner)) => {
let coin_info_type = &CoinInfoType::from_move_type(
&write_resource.r#type.as_ref().unwrap().generic_type_params[0],
write_resource.type_str.as_ref(),
txn_version,
wsc_index,
);
let owner_address = standardize_address(write_resource.address.as_str());
let coin_balance = Self {
Expand Down
2 changes: 2 additions & 0 deletions rust/processor/src/db/common/models/coin_models/coin_infos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ impl CoinInfo {
write_resource: &WriteResource,
txn_version: i64,
txn_timestamp: chrono::NaiveDateTime,
wsc_index: i64,
) -> anyhow::Result<Option<Self>> {
match &CoinResource::from_write_resource(write_resource, txn_version)? {
Some(CoinResource::CoinInfoResource(inner)) => {
let coin_info_type = &CoinInfoType::from_move_type(
&write_resource.r#type.as_ref().unwrap().generic_type_params[0],
write_resource.type_str.as_ref(),
txn_version,
wsc_index,
);
let (supply_aggregator_table_handle, supply_aggregator_table_key) = inner
.get_aggregator_metadata()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,18 @@ impl CoinInfoType {
/// get creator address from move_type, and get coin type from move_type_str
/// Since move_type_str will contain things we don't need, e.g. 0x1::coin::CoinInfo<T>. We will use
/// regex to extract T.
pub fn from_move_type(move_type: &MoveType, move_type_str: &str, txn_version: i64) -> Self {
pub fn from_move_type(
move_type: &MoveType,
move_type_str: &str,
txn_version: i64,
wsc_index: i64,
) -> Self {
if let Content::Struct(struct_tag) = move_type.content.as_ref().unwrap() {
let matched = RE.captures(move_type_str).unwrap_or_else(|| {
error!(
txn_version = txn_version,
move_type_str = move_type_str,
wsc_index = wsc_index,
"move_type should look like 0x1::coin::CoinInfo<T>"
);
panic!();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use aptos_protos::transaction::v1::{
};
use field_count::FieldCount;
use serde::{Deserialize, Serialize};
use tracing::error;

#[derive(
Associations, Clone, Debug, Deserialize, FieldCount, Identifiable, Insertable, Serialize,
Expand All @@ -42,7 +43,7 @@ impl WriteSetChange {
transaction_version: i64,
transaction_block_height: i64,
) -> (Self, WriteSetChangeDetail) {
let type_ = Self::get_write_set_change_type(write_set_change);
let type_ = Self::get_write_set_change_type(write_set_change, index, transaction_version);
let change = write_set_change
.change
.as_ref()
Expand Down Expand Up @@ -179,7 +180,7 @@ impl WriteSetChange {
.unzip()
}

fn get_write_set_change_type(t: &WriteSetChangePB) -> String {
fn get_write_set_change_type(t: &WriteSetChangePB, index: i64, txn_version: i64) -> String {
match WriteSetChangeTypeEnum::try_from(t.r#type)
.expect("WriteSetChange must have a valid type.")
{
Expand All @@ -190,6 +191,11 @@ impl WriteSetChange {
WriteSetChangeTypeEnum::WriteResource => "write_resource".to_string(),
WriteSetChangeTypeEnum::WriteTableItem => "write_table_item".to_string(),
WriteSetChangeTypeEnum::Unspecified => {
error!(
wsc_index = index,
txn_version = txn_version,
"Encountered Unspecified WriteSetChange type. "
);
panic!("WriteSetChange type must be specified.")
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl FungibleAssetBalance {
&delete_resource.r#type.as_ref().unwrap().generic_type_params[0],
delete_resource.type_str.as_ref(),
txn_version,
write_set_change_index,
);
if let Some(coin_type) = coin_info_type.get_coin_type_below_max() {
let owner_address = standardize_address(delete_resource.address.as_str());
Expand Down Expand Up @@ -192,6 +193,7 @@ impl FungibleAssetBalance {
&write_resource.r#type.as_ref().unwrap().generic_type_params[0],
write_resource.type_str.as_ref(),
txn_version,
write_set_change_index,
);
if let Some(coin_type) = coin_info_type.get_coin_type_below_max() {
let owner_address = standardize_address(write_resource.address.as_str());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl FungibleAssetBalance {
&delete_resource.r#type.as_ref().unwrap().generic_type_params[0],
delete_resource.type_str.as_ref(),
txn_version,
write_set_change_index,
);
if let Some(coin_type) = coin_info_type.get_coin_type_below_max() {
let owner_address = standardize_address(delete_resource.address.as_str());
Expand Down Expand Up @@ -273,6 +274,7 @@ impl FungibleAssetBalance {
&write_resource.r#type.as_ref().unwrap().generic_type_params[0],
write_resource.type_str.as_ref(),
txn_version,
write_set_change_index,
);
if let Some(coin_type) = coin_info_type.get_coin_type_below_max() {
let owner_address = standardize_address(write_resource.address.as_str());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl FungibleAssetMetadataModel {
/// We can find v1 coin info from resources
pub fn get_v1_from_write_resource(
write_resource: &WriteResource,
write_set_change_index: i64,
txn_version: i64,
txn_timestamp: chrono::NaiveDateTime,
) -> anyhow::Result<Option<Self>> {
Expand All @@ -115,6 +116,7 @@ impl FungibleAssetMetadataModel {
&write_resource.r#type.as_ref().unwrap().generic_type_params[0],
write_resource.type_str.as_ref(),
txn_version,
write_set_change_index,
);
let (supply_aggregator_table_handle, supply_aggregator_table_key) = inner
.get_aggregator_metadata()
Expand Down Expand Up @@ -149,6 +151,7 @@ impl FungibleAssetMetadataModel {

pub fn get_v1_from_delete_resource(
delete_resource: &DeleteResource,
write_set_change_index: i64,
txn_version: i64,
txn_timestamp: chrono::NaiveDateTime,
) -> anyhow::Result<Option<Self>> {
Expand All @@ -158,6 +161,7 @@ impl FungibleAssetMetadataModel {
&delete_resource.r#type.as_ref().unwrap().generic_type_params[0],
delete_resource.type_str.as_ref(),
txn_version,
write_set_change_index,
);
let (supply_aggregator_table_handle, supply_aggregator_table_key) = inner
.get_aggregator_metadata()
Expand Down
3 changes: 3 additions & 0 deletions rust/processor/src/processors/ans_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ fn parse_ans(
.unwrap_or_else(|e| {
error!(
error = ?e,
write_set_change_index = wsc_index,
dermanyang marked this conversation as resolved.
Show resolved Hide resolved
transaction_version = txn_version,
"Error parsing ANS v1 name record from write table item"
);
panic!();
Expand All @@ -608,6 +610,7 @@ fn parse_ans(
.unwrap_or_else(|e| {
error!(
error = ?e,
write_set_change_index = wsc_index,
"Error parsing ANS v1 primary name from write table item"
);
panic!();
Expand Down
1 change: 1 addition & 0 deletions rust/processor/src/processors/fungible_asset_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ async fn parse_v2_coin(
if let Some(fa_metadata) =
FungibleAssetMetadataModel::get_v1_from_write_resource(
write_resource,
index as i64,
txn_version,
txn_timestamp,
)
Expand Down
Loading