Skip to content

Commit 2f5f8de

Browse files
Merge pull request #96 from anoma/feat/redelegations
feat: add redelegation info
2 parents 234aae7 + eceebec commit 2f5f8de

26 files changed

Lines changed: 726 additions & 117 deletions

File tree

chain/src/main.rs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use chain::config::AppConfig;
88
use chain::repository;
99
use chain::services::namada::{
1010
query_all_balances, query_all_bonds_and_unbonds, query_all_proposals,
11-
query_bonds, query_last_block_height, query_tokens,
11+
query_bonds, query_last_block_height, query_redelegations, query_tokens,
1212
};
1313
use chain::services::{
1414
db as db_service, namada as namada_service,
@@ -96,7 +96,7 @@ async fn main() -> Result<(), MainError> {
9696
})
9797
}
9898
(None, Some(crawler_state)) => {
99-
tracing::info!(
99+
tracing::debug!(
100100
"Found chain crawler state, attempting initial crawl at block \
101101
{}...",
102102
crawler_state.last_processed_block
@@ -128,7 +128,7 @@ async fn main() -> Result<(), MainError> {
128128
// If any other type of error occurred, we should not
129129
// increment last_processed_block but
130130
// crawl from there without initial_query
131-
tracing::info!(
131+
tracing::debug!(
132132
"Initial crawl had an error (not RpcError), \
133133
continuing from block {}...",
134134
crawler_state.last_processed_block
@@ -139,7 +139,7 @@ async fn main() -> Result<(), MainError> {
139139
// If the crawl was successful, increment last_processed
140140
// block and continue from there.
141141
let next_block = crawler_state.last_processed_block + 1;
142-
tracing::info!(
142+
tracing::debug!(
143143
"Initial crawl was successful, continuing from block \
144144
{}...",
145145
next_block
@@ -152,7 +152,7 @@ async fn main() -> Result<(), MainError> {
152152
}
153153
}
154154
(None, None) => {
155-
tracing::info!(
155+
tracing::debug!(
156156
"No chain crawler state found, starting from initial_query..."
157157
);
158158
None
@@ -373,12 +373,16 @@ async fn crawling_fn(
373373
);
374374

375375
let addresses = block.bond_addresses();
376-
let bonds = query_bonds(&client, addresses).await.into_rpc_error()?;
376+
let bonds = query_bonds(&client, &addresses).await.into_rpc_error()?;
377377
tracing::debug!(
378378
block = block_height,
379379
"Updating bonds for {} addresses",
380380
bonds.len()
381381
);
382+
let redelegations = query_redelegations(&client, &addresses)
383+
.await
384+
.into_rpc_error()?;
385+
tracing::debug!("Updating redelegations for {} addresses", bonds.len());
382386

383387
let bonds_updates = bonds
384388
.iter()
@@ -437,7 +441,7 @@ async fn crawling_fn(
437441

438442
let first_checkpoint = Instant::now();
439443

440-
tracing::info!(
444+
tracing::debug!(
441445
txs = block.transactions.len(),
442446
ibc_tokens = ibc_tokens.len(),
443447
balance_changes = balances.len(),
@@ -514,6 +518,10 @@ async fn crawling_fn(
514518
repository::pos::insert_bonds(transaction_conn, bonds_updates)?;
515519

516520
repository::pos::insert_unbonds(transaction_conn, unbonds)?;
521+
repository::pos::insert_redelegations(
522+
transaction_conn,
523+
redelegations,
524+
)?;
517525
repository::pos::remove_withdraws(
518526
transaction_conn,
519527
epoch,
@@ -553,7 +561,7 @@ async fn crawling_fn(
553561

554562
let second_checkpoint = Instant::now();
555563

556-
tracing::info!(
564+
tracing::debug!(
557565
block = block_height,
558566
time_taken = second_checkpoint
559567
.duration_since(first_checkpoint)
@@ -588,7 +596,6 @@ async fn try_initial_query(
588596
tracing::debug!("Querying initial data...");
589597
let block_height =
590598
query_last_block_height(client).await.into_rpc_error()?;
591-
592599
let first_block_in_epoch = namada_service::get_first_block_in_epoch(client)
593600
.await
594601
.into_rpc_error()?;
@@ -644,7 +651,18 @@ async fn try_initial_query(
644651
.await
645652
.into_rpc_error()?;
646653

647-
tracing::debug!(block = block_height, "Querying bonds and unbonds...",);
654+
let validators_set =
655+
namada_service::get_validator_addresses_at_epoch(client, epoch)
656+
.await
657+
.into_rpc_error()?;
658+
659+
tracing::debug!("Querying redelegations...");
660+
let redelegations =
661+
namada_service::query_all_redelegations(client, validators_set)
662+
.await
663+
.into_rpc_error()?;
664+
665+
tracing::debug!("Querying bonds and unbonds...");
648666
let (bonds, unbonds) = query_all_bonds_and_unbonds(client, None, None)
649667
.await
650668
.into_rpc_error()?;
@@ -672,7 +690,7 @@ async fn try_initial_query(
672690
timestamp,
673691
};
674692

675-
tracing::info!(block = block_height, "Inserting initial data...");
693+
tracing::debug!(block = block_height, "Inserting initial data...");
676694

677695
conn.interact(move |conn| {
678696
conn.build_transaction()
@@ -723,6 +741,10 @@ async fn try_initial_query(
723741

724742
repository::pos::insert_bonds(transaction_conn, bonds)?;
725743
repository::pos::insert_unbonds(transaction_conn, unbonds)?;
744+
repository::pos::insert_redelegations(
745+
transaction_conn,
746+
redelegations,
747+
)?;
726748

727749
repository::crawler_state::upsert_crawler_state(
728750
transaction_conn,
@@ -812,7 +834,7 @@ async fn get_block(
812834
.await
813835
.into_rpc_error()?;
814836

815-
tracing::info!(
837+
tracing::debug!(
816838
block = block_height,
817839
tm_address = tm_block_response.block.header.proposer_address.to_string(),
818840
namada_address = ?proposer_address_namada,

0 commit comments

Comments
 (0)