feat: add eth_syncing (#188)

* adding documentation for rpc.md

* adding rpc methods in table for rpc.md

* adjusting readme to link to rpc.md

* fixing grammar

* grammar

* adding RPC Methods according to documentation and listing column as Client Function

* adding more description space

* undoing description spacing

* adding get block transaction count by hash to node.rs and rpc.rs

* functioning getblocktransactioncountbyhash function

* removing documentation

* adding second rpc method and simplifying logic

* adjusting example and node.rs

* formatting

* fixing clippy errors

* adding to client and to rpc.md

* formatting

* integrating into client

* u64 return types, rpc.md updated to get_nonce, get_transaction_count -> get_nonce revert

* cargo fmt

* readme architecture init

* removing blockchain

* removing complexity

* updating mermaid with links from evm -> execution, renaming, and recoloring

* coloring letters black

* removing uncessary styling and adding untrustedexecutionrpc and untrustedconsensusrpc

* initial syncing work

* adding in proper computations to syncing()

* simplificaiton of logic

* cargo fmt

* updaing rpc.md and rpc

* removing unwrapping
This commit is contained in:
Giovanni Vignone 2023-02-11 18:05:22 -05:00 committed by GitHub
parent da520290ce
commit 32d09736e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 4 deletions

View File

@ -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<DB: Database> Client<DB> {
self.node.read().await.chain_id()
}
pub async fn syncing(&self) -> Result<SyncingStatus> {
self.node.read().await.syncing()
}
pub async fn get_header(&self) -> Result<Header> {
self.node.read().await.get_header()
}

View File

@ -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<SyncingStatus> {
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<Header> {
self.check_head_age()?;
Ok(self.consensus.get_header().clone())

View File

@ -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<String, Error>;
#[method(name = "getCoinbase")]
async fn get_coinbase(&self) -> Result<Address, Error>;
#[method(name = "syncing")]
async fn syncing(&self) -> Result<SyncingStatus, Error>;
}
#[rpc(client, server, namespace = "net")]
@ -278,6 +280,11 @@ impl EthRpcServer for RpcInner {
Ok(node.get_coinbase().unwrap())
}
async fn syncing(&self) -> Result<SyncingStatus, Error> {
let node = self.node.read().await;
convert_err(node.syncing())
}
async fn get_logs(&self, filter: Filter) -> Result<Vec<Log>, Error> {
let node = self.node.read().await;
convert_err(node.get_logs(&filter).await)

4
rpc.md
View File

@ -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)` |
| `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)` |