feat: wire components together in reth node (#416)

* feat: naively wire up components

* chore: clippy lints

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
Bjerg
2022-12-14 11:51:56 +01:00
committed by GitHub
parent 12e7f0acbc
commit 601bdc5022
10 changed files with 216 additions and 40 deletions

View File

@ -12,7 +12,8 @@ pub use storage::{
use reth_db::database::Database;
/// Provider
/// A provider that fetches data from a database.
// TODO: ProviderImpl is a bad name
pub struct ProviderImpl<DB: Database> {
/// Database
db: Arc<DB>,

View File

@ -1,7 +1,7 @@
use crate::{HeaderProvider, ProviderImpl};
use crate::{BlockProvider, ChainInfo, HeaderProvider, ProviderImpl};
use reth_db::{database::Database, tables, transaction::DbTx};
use reth_interfaces::Result;
use reth_primitives::{BlockNumber, Header};
use reth_primitives::{rpc::BlockId, Block, BlockNumber, Header, H256, U256};
impl<DB: Database> HeaderProvider for ProviderImpl<DB> {
fn header(&self, block_hash: &reth_primitives::BlockHash) -> Result<Option<Header>> {
@ -16,3 +16,30 @@ impl<DB: Database> HeaderProvider for ProviderImpl<DB> {
}
}
}
impl<DB: Database> BlockProvider for ProviderImpl<DB> {
fn chain_info(&self) -> Result<ChainInfo> {
Ok(ChainInfo {
best_hash: Default::default(),
best_number: 0,
last_finalized: None,
safe_finalized: None,
})
}
fn block(&self, _id: BlockId) -> Result<Option<Block>> {
// TODO
Ok(None)
}
fn block_number(&self, hash: H256) -> Result<Option<BlockNumber>> {
self.db.view(|tx| tx.get::<tables::HeaderNumbers>(hash))?.map_err(Into::into)
}
fn block_hash(&self, number: U256) -> Result<Option<H256>> {
// TODO: This unwrap is potentially unsafe
self.db
.view(|tx| tx.get::<tables::CanonicalHeaders>(number.try_into().unwrap()))?
.map_err(Into::into)
}
}