diff --git a/client/src/client.rs b/client/src/client.rs index 1095dda..77abdce 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use config::networks::Network; use consensus::errors::ConsensusError; use ethers::prelude::{Address, U256}; -use ethers::types::{Filter, Log, Transaction, TransactionReceipt, H256}; +use ethers::types::{Filter, Log, SyncingStatus, Transaction, TransactionReceipt, H256}; use eyre::{eyre, Result}; use common::types::BlockTag; @@ -541,6 +541,10 @@ impl Client { self.node.read().await.chain_id() } + pub async fn syncing(&self) -> Result { + self.node.read().await.syncing() + } + pub async fn get_header(&self) -> Result
{ self.node.read().await.get_header() } diff --git a/client/src/node.rs b/client/src/node.rs index cb4e35d..6f06cee 100644 --- a/client/src/node.rs +++ b/client/src/node.rs @@ -3,7 +3,9 @@ use std::sync::Arc; use std::time::Duration; use ethers::prelude::{Address, U256}; -use ethers::types::{Filter, Log, Transaction, TransactionReceipt, H256}; +use ethers::types::{ + Filter, Log, SyncProgress, SyncingStatus, Transaction, TransactionReceipt, H256, +}; use eyre::{eyre, Result}; use common::errors::BlockNotFoundError; @@ -315,6 +317,37 @@ impl Node { self.config.chain.chain_id } + pub fn syncing(&self) -> Result { + if self.check_head_age().is_ok() { + Ok(SyncingStatus::IsFalse) + } else { + let latest_synced_block = self.get_block_number()?; + let oldest_payload = self.payloads.first_key_value(); + let oldest_synced_block = + oldest_payload.map_or(latest_synced_block, |(key, _value)| *key); + let highest_block = self.consensus.expected_current_slot(); + Ok(SyncingStatus::IsSyncing(Box::new(SyncProgress { + current_block: latest_synced_block.into(), + highest_block: highest_block.into(), + starting_block: oldest_synced_block.into(), + pulled_states: None, + known_states: None, + healed_bytecode_bytes: None, + healed_bytecodes: None, + healed_trienode_bytes: None, + healed_trienodes: None, + healing_bytecode: None, + healing_trienodes: None, + synced_account_bytes: None, + synced_accounts: None, + synced_bytecode_bytes: None, + synced_bytecodes: None, + synced_storage: None, + synced_storage_bytes: None, + }))) + } + } + pub fn get_header(&self) -> Result
{ self.check_head_age()?; Ok(self.consensus.get_header().clone()) diff --git a/client/src/rpc.rs b/client/src/rpc.rs index 8044da2..392e547 100644 --- a/client/src/rpc.rs +++ b/client/src/rpc.rs @@ -1,6 +1,6 @@ use ethers::{ abi::AbiEncode, - types::{Address, Filter, Log, Transaction, TransactionReceipt, H256, U256}, + types::{Address, Filter, Log, SyncingStatus, Transaction, TransactionReceipt, H256, U256}, }; use eyre::Result; use log::info; @@ -114,6 +114,8 @@ trait EthRpc { ) -> Result; #[method(name = "getCoinbase")] async fn get_coinbase(&self) -> Result; + #[method(name = "syncing")] + async fn syncing(&self) -> Result; } #[rpc(client, server, namespace = "net")] @@ -278,6 +280,11 @@ impl EthRpcServer for RpcInner { Ok(node.get_coinbase().unwrap()) } + async fn syncing(&self) -> Result { + let node = self.node.read().await; + convert_err(node.syncing()) + } + async fn get_logs(&self, filter: Filter) -> Result, Error> { let node = self.node.read().await; convert_err(node.get_logs(&filter).await) diff --git a/rpc.md b/rpc.md index 07c5097..2672cfd 100644 --- a/rpc.md +++ b/rpc.md @@ -22,4 +22,6 @@ Helios provides a variety of RPC methods for interacting with the Ethereum netwo | `eth_getLogs` | `get_logs` | Returns an array of logs matching the filter. | `client.get_logs(&self, filter: Filter)` | | `eth_getStorageAt` | `get_storage_at` | Returns the value from a storage position at a given address. | `client.get_storage_at(&self, address: &str, slot: H256, block: BlockTag)` | | `eth_getBlockTransactionCountByHash` | `get_block_transaction_count_by_hash` | Returns the number of transactions in a block from a block matching the transaction hash. | `client.get_block_transaction_count_by_hash(&self, hash: &str)` | -| `eth_getBlockTransactionCountByNumber` | `get_block_transaction_count_by_number` | Returns the number of transactions in a block from a block matching the block number. | `client.get_block_transaction_count_by_number(&self, block: BlockTag)` | \ No newline at end of file +| `eth_getBlockTransactionCountByNumber` | `get_block_transaction_count_by_number` | Returns the number of transactions in a block from a block matching the block number. | `client.get_block_transaction_count_by_number(&self, block: BlockTag)` | +| `eth_coinbase` | `get_coinbase` | Returns the client coinbase address. | `client.get_coinbase(&self)` | +| `eth_syncing` | `syncing` | Returns an object with data about the sync status or false. | `client.syncing(&self)` | \ No newline at end of file