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

log: logging query_finalized_custodian_cells #557

Merged
Merged
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
14 changes: 13 additions & 1 deletion crates/rpc-client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use gw_types::{
use rand::prelude::*;
use serde_json::json;

use std::time::Instant;
use std::{collections::HashSet, time::Duration};

fn to_cell_info(cell: Cell) -> CellInfo {
Expand Down Expand Up @@ -974,6 +975,11 @@ impl RPCClient {
max_cells: usize,
) -> Result<QueryResult<CollectedCustodianCells>> {
const MAX_CELLS: usize = 50;

let mut query_indexer_times = 0;
let mut query_indexer_cells = 0;
let now = Instant::now();

let rollup_context = &self.rollup_context;

let parse_sudt_amount = |cell: &Cell| -> Result<u128> {
Expand Down Expand Up @@ -1002,7 +1008,8 @@ impl RPCClient {
script_type: ScriptType::Lock,
filter,
};
let order = Order::Desc;
// order by ASC so we can search more cells
let order = Order::Asc;
let limit = Uint32::from(DEFAULT_QUERY_LIMIT as u32);

let mut collected = CollectedCustodianCells::default();
Expand Down Expand Up @@ -1036,6 +1043,9 @@ impl RPCClient {
}
cursor = Some(cells.last_cursor);

query_indexer_times += 1;
query_indexer_cells += cells.objects.len();

for cell in cells.objects.into_iter() {
if collected.cells_info.len() >= max_cells {
return Ok(QueryResult::NotEnough(collected));
Expand Down Expand Up @@ -1130,12 +1140,14 @@ impl RPCClient {
if collected.capacity >= required_capacity {
break;
} else {
log::debug!("[query finalized custodian cells] query indexer times: {} query indexer cells: {} duration: {}ms", query_indexer_times, query_indexer_cells, now.elapsed().as_millis());
return Ok(QueryResult::NotEnough(collected));
}
}
}
}

log::debug!("[query finalized custodian cells] query indexer times: {} query indexer cells: {} duration: {}ms", query_indexer_times, query_indexer_cells, now.elapsed().as_millis());
Ok(QueryResult::Full(collected))
}

Expand Down