Skip to content

Commit

Permalink
Merge pull request #19 from weaveVM/dynamic-backfilling
Browse files Browse the repository at this point in the history
chore: update server info response
  • Loading branch information
charmful0x authored Sep 28, 2024
2 parents 14bc294 + 3042b81 commit b1febd8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wvm-archiver"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
description = "EL data pipeline for WVM testnet v0"
authors = ["charmful0x <[email protected]>"]
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ curl -X GET https://the_network.wvm.network/info

```rs
pub struct InfoServerResponse {
first_block: Option<u64>,
last_block: Option<u64>,
first_archived_block: Option<u64>,
last_archived_block: Option<u64>,
livesync_start_block: u64,
total_archived_blocks: u64,
archiver_balance: U256,
blocks_behind_live_blockheight: u64,
archiver_balance: U256,
archiver_address: String,
backfill_address: String,
backfill_balance: U256,
network_name: String,
network_chain_id: u32,
network_rpc: String,
Expand Down
25 changes: 18 additions & 7 deletions src/utils/schema.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::utils::env_var::get_env_var;
use crate::utils::get_block::get_current_block_number;
use crate::utils::planetscale::ps_get_archived_blocks_count;
use crate::utils::transaction::get_archiver_balance;
use crate::utils::transaction::get_balance_of;
use borsh::{from_slice, to_vec};
use borsh_derive::{BorshDeserialize, BorshSerialize};
use ethers::types::U256;
use ethers_core::k256::elliptic_curve::consts::U25;
use ethers_providers::{Http, Provider};
use planetscale_driver::Database;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -129,12 +130,15 @@ pub struct PsGetTotalBlocksCount {

#[derive(Debug, Serialize)]
pub struct InfoServerResponse {
first_block: Option<u64>,
last_block: Option<u64>,
first_archived_block: Option<u64>,
last_archived_block: Option<u64>,
livesync_start_block: u64,
total_archived_blocks: u64,
blocks_behind_live_blockheight: u64,
archiver_balance: U256,
archiver_address: String,
backfill_address: String,
backfill_balance: U256,
network_name: String,
network_chain_id: u32,
network_rpc: String,
Expand All @@ -143,19 +147,26 @@ pub struct InfoServerResponse {
impl InfoServerResponse {
pub async fn new(first_block: Option<u64>, last_block: Option<u64>) -> InfoServerResponse {
let network = Network::config();
// balances
let archiver_balance = get_balance_of(network.archiver_address.clone()).await;
let archiver_balance = Some(archiver_balance).unwrap_or("0".into());
let backfill_balance = get_balance_of(network.backfill_address.clone()).await;
let backfill_balance = Some(backfill_balance).unwrap_or("0".into());
// blocks stats
let total_archived_blocks = (ps_get_archived_blocks_count().await).count;
let archiver_balance = get_archiver_balance().await;
let archiver_balance = Some(archiver_balance).unwrap();
let current_live_block = get_current_block_number().await.as_u64();
let blocks_behind_live_blockheight = current_live_block - last_block.unwrap_or(0);

let instance: InfoServerResponse = InfoServerResponse {
archiver_balance,
backfill_balance,
blocks_behind_live_blockheight,
first_block,
last_block,
livesync_start_block: network.start_block,
first_archived_block: first_block,
last_archived_block: last_block,
total_archived_blocks,
archiver_address: network.archiver_address,
backfill_address: network.backfill_address,
network_name: network.name,
network_chain_id: network.network_chain_id,
network_rpc: network.network_rpc,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ async fn assert_non_zero_balance(provider: &Provider<Http>, address: &Address) {
assert!(balance > 0.into());
}

pub async fn get_archiver_balance() -> U256 {
pub async fn get_balance_of(addr: String) -> U256 {
let network = Network::config();
let provider = Network::provider(&network, true).await;
let address = network.archiver_address.parse::<Address>().unwrap();
let address = addr.parse::<Address>().unwrap();
let balance = provider.get_balance(address, None).await.unwrap();
balance
}
Expand Down

0 comments on commit b1febd8

Please sign in to comment.