Skip to content

Commit

Permalink
optimize updating validators. (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogefoodcoin authored Jul 8, 2024
1 parent fd24f9e commit 5a1d404
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions updater/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
evm_rpc = "web3 endopoint"
staking = "staking contract address"
reward = "reward contrat address"
db_url = "postgres://postgres:12345678@localhost/postgres"
evm_rpc = "https://rpc-mainnet.findora.org/"
staking = "0x7a598dEf738a01D771fF92Be33064D5c5E0BC12C"
reward = "0xEDA79C4dA47E9b27820Ef244aa2af7a50657e443"
db_url = "postgres://postgres:csq2400306@localhost/postgres"
2 changes: 1 addition & 1 deletion updater/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::sync::Arc;
use std::time::Duration;

const DEFAULT_RPC_RETRIES: usize = 3;
const DEFAULT_INTERVAL: u64 = 15; // 15s
const DEFAULT_INTERVAL: u64 = 14; // 14s

abigen!(RewardContract, "../abi/Reward.json");
abigen!(StakingContract, "../abi/Staking.json");
Expand Down
10 changes: 5 additions & 5 deletions updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::db::Storage;
use crate::error::Result;
use crate::{RewardContract, StakingContract, DEFAULT_INTERVAL};
use crossbeam::channel::bounded;
use ethers::prelude::{Http, Provider};
use ethers::prelude::{Http, Provider, H160};
use ethers::providers::Middleware;
use ethers::types::Address;
use ethers::utils::hex::encode_prefixed;
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Updater {
}
}

pub async fn update_validators(&self, validators: Vec<String>) -> Result<u64> {
pub async fn update_validators(&self, validators: Vec<H160>) -> Result<u64> {
let block_num = self.caller.provider.get_block_number().await?.as_u64();

let count = validators.len();
Expand All @@ -77,8 +77,7 @@ impl Updater {

let producer_handle = tokio::task::spawn_blocking(move || {
for vaddr in validators {
let addr = Address::from_str(&vaddr).unwrap();
let fut = update_validator_task(caller_cloned.clone(), block_num, addr);
let fut = update_validator_task(caller_cloned.clone(), block_num, vaddr);
sender.send(Some(fut)).unwrap();
}

Expand Down Expand Up @@ -108,7 +107,8 @@ impl Updater {

pub async fn run(&self) -> Result<()> {
loop {
let validators = self.caller.storage.get_validator_list().await?;
let list = self.caller.staking.get_validators_list().call().await?;
let validators = list.into_iter().map(|v| v.addr).collect::<Vec<H160>>();
if validators.len() > 0 {
match self.update_validators(validators).await {
Ok(block_num) => {
Expand Down

0 comments on commit 5a1d404

Please sign in to comment.