Skip to content

Commit abf2605

Browse files
committed
simplify backend dependecy
1 parent 8e1249a commit abf2605

File tree

5 files changed

+31
-28
lines changed

5 files changed

+31
-28
lines changed

finality-aleph/src/justification/handler.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
use futures::{channel::mpsc, Stream, StreamExt};
77
use futures_timer::Delay;
88
use log::{debug, error};
9-
use sc_client_api::backend::Backend;
9+
use sc_client_api::blockchain::Backend as BlockchainBackend;
1010
use sp_api::BlockT;
1111
use sp_runtime::traits::Header;
1212
use tokio::time::timeout;
@@ -20,36 +20,36 @@ use crate::{
2020
network, Metrics, STATUS_REPORT_INTERVAL,
2121
};
2222

23-
pub struct JustificationHandler<B, V, RB, S, SI, F, BE>
23+
pub struct JustificationHandler<B, V, RB, S, SI, F, BB>
2424
where
2525
B: BlockT,
2626
V: Verifier<B>,
2727
RB: network::RequestBlocks<B> + 'static,
2828
S: JustificationRequestScheduler,
2929
SI: SessionInfoProvider<B, V>,
3030
F: BlockFinalizer<B>,
31-
BE: Backend<B> + Send + Sync + 'static,
31+
BB: BlockchainBackend<B> + Send + Sync + 'static,
3232
{
3333
session_info_provider: SI,
34-
block_requester: BlockRequester<B, RB, S, F, V, BE>,
34+
block_requester: BlockRequester<B, RB, S, F, V, BB>,
3535
verifier_timeout: Duration,
3636
notification_timeout: Duration,
3737
}
3838

39-
impl<B, V, RB, S, SI, F, BE> JustificationHandler<B, V, RB, S, SI, F, BE>
39+
impl<B, V, RB, S, SI, F, BB> JustificationHandler<B, V, RB, S, SI, F, BB>
4040
where
4141
B: BlockT,
4242
V: Verifier<B>,
4343
RB: network::RequestBlocks<B> + 'static,
4444
S: JustificationRequestScheduler,
4545
SI: SessionInfoProvider<B, V>,
4646
F: BlockFinalizer<B>,
47-
BE: Backend<B> + Send + Sync + 'static,
47+
BB: BlockchainBackend<B> + Send + Sync + 'static,
4848
{
4949
pub fn new(
5050
session_info_provider: SI,
5151
block_requester: RB,
52-
backend: Arc<BE>,
52+
backend: Arc<BB>,
5353
finalizer: F,
5454
justification_request_scheduler: S,
5555
metrics: Option<Metrics<<B::Header as Header>::Hash>>,

finality-aleph/src/justification/requester.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{fmt, marker::PhantomData, sync::Arc, time::Instant};
22

33
use aleph_primitives::ALEPH_ENGINE_ID;
44
use log::{debug, error, info, warn};
5-
use sc_client_api::{backend::Backend, blockchain::Backend as _, HeaderBackend};
5+
use sc_client_api::{blockchain::Backend as BlockchainBackend, HeaderBackend};
66
use sp_api::{BlockId, BlockT, NumberFor};
77
use sp_runtime::traits::{Header, One};
88

@@ -72,36 +72,36 @@ impl<B: BlockT> fmt::Display for JustificationRequestStatus<B> {
7272
}
7373
}
7474

75-
pub struct BlockRequester<B, RB, S, F, V, BE>
75+
pub struct BlockRequester<B, RB, S, F, V, BB>
7676
where
7777
B: BlockT,
7878
RB: network::RequestBlocks<B> + 'static,
7979
S: JustificationRequestScheduler,
8080
F: BlockFinalizer<B>,
8181
V: Verifier<B>,
82-
BE: Backend<B>,
82+
BB: BlockchainBackend<B>,
8383
{
8484
block_requester: RB,
85-
backend: Arc<BE>,
85+
backend: Arc<BB>,
8686
finalizer: F,
8787
justification_request_scheduler: S,
8888
metrics: Option<Metrics<<B::Header as Header>::Hash>>,
8989
request_status: JustificationRequestStatus<B>,
9090
_phantom: PhantomData<V>,
9191
}
9292

93-
impl<B, RB, S, F, V, BE> BlockRequester<B, RB, S, F, V, BE>
93+
impl<B, RB, S, F, V, BB> BlockRequester<B, RB, S, F, V, BB>
9494
where
9595
B: BlockT,
9696
RB: network::RequestBlocks<B> + 'static,
9797
S: JustificationRequestScheduler,
9898
F: BlockFinalizer<B>,
9999
V: Verifier<B>,
100-
BE: Backend<B>,
100+
BB: BlockchainBackend<B>,
101101
{
102102
pub fn new(
103103
block_requester: RB,
104-
backend: Arc<BE>,
104+
backend: Arc<BB>,
105105
finalizer: F,
106106
justification_request_scheduler: S,
107107
metrics: Option<Metrics<<B::Header as Header>::Hash>>,
@@ -182,11 +182,11 @@ where
182182
}
183183

184184
pub fn finalized_number(&self) -> NumberFor<B> {
185-
self.backend.blockchain().info().finalized_number
185+
self.backend.info().finalized_number
186186
}
187187

188188
fn request(&mut self, hash: <B as BlockT>::Hash) {
189-
if let Ok(Some(header)) = self.backend.blockchain().header(BlockId::Hash(hash)) {
189+
if let Ok(Some(header)) = self.backend.header(BlockId::Hash(hash)) {
190190
let number = *header.number();
191191
debug!(target: "aleph-justification", "Trying to request block {:?}", number);
192192
self.request_status.save_block_number(number);
@@ -207,19 +207,16 @@ where
207207
// We don't remove the child that it's on the same branch as best since a fork may happen
208208
// somewhere in between them.
209209
fn request_targets(&self, mut top_wanted: NumberFor<B>) -> Vec<<B as BlockT>::Hash> {
210-
let blockchain_backend = self.backend.blockchain();
211-
let blockchain_info = blockchain_backend.info();
210+
let blockchain_info = self.backend.info();
212211
let finalized_hash = blockchain_info.finalized_hash;
213212

214-
let mut targets = blockchain_backend
215-
.children(finalized_hash)
216-
.unwrap_or_default();
213+
let mut targets = self.backend.children(finalized_hash).unwrap_or_default();
217214
let best_number = blockchain_info.best_number;
218215
if best_number <= top_wanted {
219216
// most probably block best_number is not yet finalized
220217
top_wanted = best_number - NumberFor::<B>::one();
221218
}
222-
match blockchain_backend.hash(top_wanted) {
219+
match self.backend.hash(top_wanted) {
223220
Ok(Some(hash)) => {
224221
if !targets.contains(&hash) {
225222
targets.push(hash);

finality-aleph/src/nodes/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use aleph_primitives::{AuthorityId, SessionAuthorityData};
77
use codec::Encode;
88
use log::warn;
99
pub use nonvalidator_node::run_nonvalidator_node;
10+
use sc_client_api::blockchain::Backend as BlockchainBackend;
1011
use sc_client_api::Backend;
1112
use sc_network::{ExHashT, NetworkService};
1213
use sp_runtime::{
@@ -83,10 +84,10 @@ impl<B: Block> Verifier<B> for JustificationVerifier {
8384
}
8485
}
8586

86-
struct JustificationParams<B: Block, H: ExHashT, C, BE> {
87+
struct JustificationParams<B: Block, H: ExHashT, C, BB> {
8788
pub network: Arc<NetworkService<B, H>>,
8889
pub client: Arc<C>,
89-
pub backend: Arc<BE>,
90+
pub backend: Arc<BB>,
9091
pub justification_rx: mpsc::UnboundedReceiver<JustificationNotification<B>>,
9192
pub metrics: Option<Metrics<<B::Header as Header>::Hash>>,
9293
pub session_period: SessionPeriod,
@@ -127,8 +128,8 @@ impl<B: Block> SessionInfoProvider<B, JustificationVerifier> for SessionInfoProv
127128
}
128129
}
129130

130-
fn setup_justification_handler<B, H, C, BE>(
131-
just_params: JustificationParams<B, H, C, BE>,
131+
fn setup_justification_handler<B, H, C, BB, BE>(
132+
just_params: JustificationParams<B, H, C, BB>,
132133
) -> (
133134
UnboundedSender<JustificationNotification<B>>,
134135
impl Future<Output = ()>,
@@ -138,6 +139,7 @@ where
138139
H: ExHashT,
139140
C: crate::ClientForAleph<B, BE> + Send + Sync + 'static,
140141
C::Api: aleph_primitives::AlephSessionApi<B>,
142+
BB: BlockchainBackend<B> + 'static,
141143
BE: Backend<B> + 'static,
142144
{
143145
let JustificationParams {

finality-aleph/src/nodes/nonvalidator_node.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use log::{debug, error};
2+
use sc_client_api::blockchain::Backend as BlockchainBackend;
23
use sc_client_api::Backend;
34
use sc_network::ExHashT;
45
use sp_consensus::SelectChain;
@@ -10,12 +11,13 @@ use crate::{
1011
AlephConfig,
1112
};
1213

13-
pub async fn run_nonvalidator_node<B, H, C, BE, SC>(aleph_config: AlephConfig<B, H, C, SC, BE>)
14+
pub async fn run_nonvalidator_node<B, H, C, BB, BE, SC>(aleph_config: AlephConfig<B, H, C, SC, BB>)
1415
where
1516
B: Block,
1617
H: ExHashT,
1718
C: crate::ClientForAleph<B, BE> + Send + Sync + 'static,
1819
C::Api: aleph_primitives::AlephSessionApi<B>,
20+
BB: BlockchainBackend<B> + 'static,
1921
BE: Backend<B> + 'static,
2022
SC: SelectChain<B> + 'static,
2123
{

finality-aleph/src/nodes/validator_node.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{marker::PhantomData, sync::Arc};
33
use bip39::{Language, Mnemonic, MnemonicType};
44
use futures::channel::oneshot;
55
use log::{debug, error};
6+
use sc_client_api::blockchain::Backend as BlockchainBackend;
67
use sc_client_api::Backend;
78
use sc_network::ExHashT;
89
use sp_consensus::SelectChain;
@@ -37,12 +38,13 @@ pub async fn new_pen(mnemonic: &str, keystore: Arc<dyn CryptoStore>) -> Authorit
3738
.expect("we just generated this key so everything should work")
3839
}
3940

40-
pub async fn run_validator_node<B, H, C, BE, SC>(aleph_config: AlephConfig<B, H, C, SC, BE>)
41+
pub async fn run_validator_node<B, H, C, BB, BE, SC>(aleph_config: AlephConfig<B, H, C, SC, BB>)
4142
where
4243
B: Block,
4344
H: ExHashT,
4445
C: crate::ClientForAleph<B, BE> + Send + Sync + 'static,
4546
C::Api: aleph_primitives::AlephSessionApi<B>,
47+
BB: BlockchainBackend<B> + 'static,
4648
BE: Backend<B> + 'static,
4749
SC: SelectChain<B> + 'static,
4850
{

0 commit comments

Comments
 (0)