Skip to content

Commit 29b7a94

Browse files
authored
Improve logging for indexer models and processors (#505)
* Add logging for wsc unspecified type and wsc_indices in ans_processor * run rust linter * Add logging to ans and fung_asset processors * formatting
1 parent 35dcd59 commit 29b7a94

File tree

10 files changed

+40
-6
lines changed

10 files changed

+40
-6
lines changed

rust/processor/src/db/common/models/coin_models/coin_activities.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,24 @@ impl CoinActivity {
149149
}
150150

151151
// Need coin info from move resources
152-
for wsc in &transaction_info.changes {
152+
for (wsc_index, wsc) in transaction_info.changes.iter().enumerate() {
153153
let (maybe_coin_info, maybe_coin_balance_data) =
154154
if let WriteSetChangeEnum::WriteResource(write_resource) =
155155
&wsc.change.as_ref().unwrap()
156156
{
157157
(
158-
CoinInfo::from_write_resource(write_resource, txn_version, txn_timestamp)
159-
.unwrap(),
158+
CoinInfo::from_write_resource(
159+
write_resource,
160+
txn_version,
161+
txn_timestamp,
162+
wsc_index as i64,
163+
)
164+
.unwrap(),
160165
CoinBalance::from_write_resource(
161166
write_resource,
162167
txn_version,
163168
txn_timestamp,
169+
wsc_index as i64,
164170
)
165171
.unwrap(),
166172
)

rust/processor/src/db/common/models/coin_models/coin_balances.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ impl CoinBalance {
4949
write_resource: &WriteResource,
5050
txn_version: i64,
5151
txn_timestamp: chrono::NaiveDateTime,
52+
wsc_index: i64,
5253
) -> anyhow::Result<Option<(Self, CurrentCoinBalance, EventToCoinType)>> {
5354
match &CoinResource::from_write_resource(write_resource, txn_version)? {
5455
Some(CoinResource::CoinStoreResource(inner)) => {
5556
let coin_info_type = &CoinInfoType::from_move_type(
5657
&write_resource.r#type.as_ref().unwrap().generic_type_params[0],
5758
write_resource.type_str.as_ref(),
5859
txn_version,
60+
wsc_index,
5961
);
6062
let owner_address = standardize_address(write_resource.address.as_str());
6163
let coin_balance = Self {

rust/processor/src/db/common/models/coin_models/coin_infos.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ impl CoinInfo {
3333
write_resource: &WriteResource,
3434
txn_version: i64,
3535
txn_timestamp: chrono::NaiveDateTime,
36+
wsc_index: i64,
3637
) -> anyhow::Result<Option<Self>> {
3738
match &CoinResource::from_write_resource(write_resource, txn_version)? {
3839
Some(CoinResource::CoinInfoResource(inner)) => {
3940
let coin_info_type = &CoinInfoType::from_move_type(
4041
&write_resource.r#type.as_ref().unwrap().generic_type_params[0],
4142
write_resource.type_str.as_ref(),
4243
txn_version,
44+
wsc_index,
4345
);
4446
let (supply_aggregator_table_handle, supply_aggregator_table_key) = inner
4547
.get_aggregator_metadata()

rust/processor/src/db/common/models/coin_models/coin_utils.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,18 @@ impl CoinInfoType {
169169
/// get creator address from move_type, and get coin type from move_type_str
170170
/// Since move_type_str will contain things we don't need, e.g. 0x1::coin::CoinInfo<T>. We will use
171171
/// regex to extract T.
172-
pub fn from_move_type(move_type: &MoveType, move_type_str: &str, txn_version: i64) -> Self {
172+
pub fn from_move_type(
173+
move_type: &MoveType,
174+
move_type_str: &str,
175+
txn_version: i64,
176+
wsc_index: i64,
177+
) -> Self {
173178
if let Content::Struct(struct_tag) = move_type.content.as_ref().unwrap() {
174179
let matched = RE.captures(move_type_str).unwrap_or_else(|| {
175180
error!(
176181
txn_version = txn_version,
177182
move_type_str = move_type_str,
183+
wsc_index = wsc_index,
178184
"move_type should look like 0x1::coin::CoinInfo<T>"
179185
);
180186
panic!();

rust/processor/src/db/common/models/default_models/write_set_changes.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use aptos_protos::transaction::v1::{
1919
};
2020
use field_count::FieldCount;
2121
use serde::{Deserialize, Serialize};
22+
use tracing::error;
2223

2324
#[derive(
2425
Associations, Clone, Debug, Deserialize, FieldCount, Identifiable, Insertable, Serialize,
@@ -42,7 +43,7 @@ impl WriteSetChange {
4243
transaction_version: i64,
4344
transaction_block_height: i64,
4445
) -> (Self, WriteSetChangeDetail) {
45-
let type_ = Self::get_write_set_change_type(write_set_change);
46+
let type_ = Self::get_write_set_change_type(write_set_change, index, transaction_version);
4647
let change = write_set_change
4748
.change
4849
.as_ref()
@@ -179,7 +180,7 @@ impl WriteSetChange {
179180
.unzip()
180181
}
181182

182-
fn get_write_set_change_type(t: &WriteSetChangePB) -> String {
183+
fn get_write_set_change_type(t: &WriteSetChangePB, index: i64, txn_version: i64) -> String {
183184
match WriteSetChangeTypeEnum::try_from(t.r#type)
184185
.expect("WriteSetChange must have a valid type.")
185186
{
@@ -190,6 +191,11 @@ impl WriteSetChange {
190191
WriteSetChangeTypeEnum::WriteResource => "write_resource".to_string(),
191192
WriteSetChangeTypeEnum::WriteTableItem => "write_table_item".to_string(),
192193
WriteSetChangeTypeEnum::Unspecified => {
194+
error!(
195+
wsc_index = index,
196+
txn_version = txn_version,
197+
"Encountered Unspecified WriteSetChange type. "
198+
);
193199
panic!("WriteSetChange type must be specified.")
194200
},
195201
}

rust/processor/src/db/common/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl FungibleAssetBalance {
139139
&delete_resource.r#type.as_ref().unwrap().generic_type_params[0],
140140
delete_resource.type_str.as_ref(),
141141
txn_version,
142+
write_set_change_index,
142143
);
143144
if let Some(coin_type) = coin_info_type.get_coin_type_below_max() {
144145
let owner_address = standardize_address(delete_resource.address.as_str());
@@ -192,6 +193,7 @@ impl FungibleAssetBalance {
192193
&write_resource.r#type.as_ref().unwrap().generic_type_params[0],
193194
write_resource.type_str.as_ref(),
194195
txn_version,
196+
write_set_change_index,
195197
);
196198
if let Some(coin_type) = coin_info_type.get_coin_type_below_max() {
197199
let owner_address = standardize_address(write_resource.address.as_str());

rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_asset_balances.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ impl FungibleAssetBalance {
220220
&delete_resource.r#type.as_ref().unwrap().generic_type_params[0],
221221
delete_resource.type_str.as_ref(),
222222
txn_version,
223+
write_set_change_index,
223224
);
224225
if let Some(coin_type) = coin_info_type.get_coin_type_below_max() {
225226
let owner_address = standardize_address(delete_resource.address.as_str());
@@ -273,6 +274,7 @@ impl FungibleAssetBalance {
273274
&write_resource.r#type.as_ref().unwrap().generic_type_params[0],
274275
write_resource.type_str.as_ref(),
275276
txn_version,
277+
write_set_change_index,
276278
);
277279
if let Some(coin_type) = coin_info_type.get_coin_type_below_max() {
278280
let owner_address = standardize_address(write_resource.address.as_str());

rust/processor/src/db/common/models/fungible_asset_models/v2_fungible_metadata.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl FungibleAssetMetadataModel {
106106
/// We can find v1 coin info from resources
107107
pub fn get_v1_from_write_resource(
108108
write_resource: &WriteResource,
109+
write_set_change_index: i64,
109110
txn_version: i64,
110111
txn_timestamp: chrono::NaiveDateTime,
111112
) -> anyhow::Result<Option<Self>> {
@@ -115,6 +116,7 @@ impl FungibleAssetMetadataModel {
115116
&write_resource.r#type.as_ref().unwrap().generic_type_params[0],
116117
write_resource.type_str.as_ref(),
117118
txn_version,
119+
write_set_change_index,
118120
);
119121
let (supply_aggregator_table_handle, supply_aggregator_table_key) = inner
120122
.get_aggregator_metadata()
@@ -149,6 +151,7 @@ impl FungibleAssetMetadataModel {
149151

150152
pub fn get_v1_from_delete_resource(
151153
delete_resource: &DeleteResource,
154+
write_set_change_index: i64,
152155
txn_version: i64,
153156
txn_timestamp: chrono::NaiveDateTime,
154157
) -> anyhow::Result<Option<Self>> {
@@ -158,6 +161,7 @@ impl FungibleAssetMetadataModel {
158161
&delete_resource.r#type.as_ref().unwrap().generic_type_params[0],
159162
delete_resource.type_str.as_ref(),
160163
txn_version,
164+
write_set_change_index,
161165
);
162166
let (supply_aggregator_table_handle, supply_aggregator_table_key) = inner
163167
.get_aggregator_metadata()

rust/processor/src/processors/ans_processor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ fn parse_ans(
582582
.unwrap_or_else(|e| {
583583
error!(
584584
error = ?e,
585+
write_set_change_index = wsc_index,
586+
transaction_version = txn_version,
585587
"Error parsing ANS v1 name record from write table item"
586588
);
587589
panic!();
@@ -608,6 +610,7 @@ fn parse_ans(
608610
.unwrap_or_else(|e| {
609611
error!(
610612
error = ?e,
613+
write_set_change_index = wsc_index,
611614
"Error parsing ANS v1 primary name from write table item"
612615
);
613616
panic!();

rust/processor/src/processors/fungible_asset_processor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ async fn parse_v2_coin(
689689
if let Some(fa_metadata) =
690690
FungibleAssetMetadataModel::get_v1_from_write_resource(
691691
write_resource,
692+
index as i64,
692693
txn_version,
693694
txn_timestamp,
694695
)

0 commit comments

Comments
 (0)