1818
1919use crate :: error:: { Error , FutureResult } ;
2020
21- use bp_message_lane:: { LaneId , MessageNonce , OutboundLaneApi } ;
21+ use bp_message_lane:: { LaneId , MessageNonce } ;
2222use bp_runtime:: InstanceId ;
23- use frame_support:: weights:: Weight ;
2423use futures:: { FutureExt , TryFutureExt } ;
2524use jsonrpc_core:: futures:: Future as _;
2625use jsonrpc_derive:: rpc;
2726use sc_client_api:: Backend as BackendT ;
28- use sp_api:: ProvideRuntimeApi ;
2927use sp_blockchain:: { Error as BlockchainError , HeaderBackend } ;
3028use sp_core:: { storage:: StorageKey , Bytes } ;
3129use sp_runtime:: { codec:: Encode , generic:: BlockId , traits:: Block as BlockT } ;
@@ -56,8 +54,8 @@ pub trait Runtime: Send + Sync + 'static {
5654/// Provides RPC methods for interacting with message-lane pallet.
5755#[ rpc]
5856pub trait MessageLaneApi < BlockHash > {
59- /// Returns cumulative dispatch weight of messages in given inclusive range and their storage proof.
60- /// The state of outbound lane is included in the proof if `include_outbound_lane_state` is true.
57+ /// Returns storage proof of messages in given inclusive range. The state of outbound
58+ /// lane is included in the proof if `include_outbound_lane_state` is true.
6159 #[ rpc( name = "messageLane_proveMessages" ) ]
6260 fn prove_messages (
6361 & self ,
@@ -67,7 +65,7 @@ pub trait MessageLaneApi<BlockHash> {
6765 end : MessageNonce ,
6866 include_outbound_lane_state : bool ,
6967 block : Option < BlockHash > ,
70- ) -> FutureResult < ( Weight , MessagesProof ) > ;
68+ ) -> FutureResult < MessagesProof > ;
7169
7270 /// Returns proof-of-message(s) delivery.
7371 #[ rpc( name = "messageLane_proveMessagesDelivery" ) ]
@@ -80,30 +78,26 @@ pub trait MessageLaneApi<BlockHash> {
8078}
8179
8280/// Implements the MessageLaneApi trait for interacting with message lanes.
83- pub struct MessageLaneRpcHandler < Block , Client , Backend , R > {
84- client : Arc < Client > ,
81+ pub struct MessageLaneRpcHandler < Block , Backend , R > {
8582 backend : Arc < Backend > ,
8683 runtime : Arc < R > ,
8784 _phantom : std:: marker:: PhantomData < Block > ,
8885}
8986
90- impl < Block , Client , Backend , R > MessageLaneRpcHandler < Block , Client , Backend , R > {
87+ impl < Block , Backend , R > MessageLaneRpcHandler < Block , Backend , R > {
9188 /// Creates new mesage lane RPC handler.
92- pub fn new ( client : Arc < Client > , backend : Arc < Backend > , runtime : Arc < R > ) -> Self {
89+ pub fn new ( backend : Arc < Backend > , runtime : Arc < R > ) -> Self {
9390 Self {
94- client,
9591 backend,
9692 runtime,
9793 _phantom : Default :: default ( ) ,
9894 }
9995 }
10096}
10197
102- impl < Block , Client , Backend , R > MessageLaneApi < Block :: Hash > for MessageLaneRpcHandler < Block , Client , Backend , R >
98+ impl < Block , Backend , R > MessageLaneApi < Block :: Hash > for MessageLaneRpcHandler < Block , Backend , R >
10399where
104100 Block : BlockT ,
105- Client : ProvideRuntimeApi < Block > + Send + Sync + ' static ,
106- Client :: Api : OutboundLaneApi < Block > ,
107101 Backend : BackendT < Block > + ' static ,
108102 R : Runtime ,
109103{
@@ -115,22 +109,7 @@ where
115109 end : MessageNonce ,
116110 include_outbound_lane_state : bool ,
117111 block : Option < Block :: Hash > ,
118- ) -> FutureResult < ( Weight , MessagesProof ) > {
119- let block = unwrap_or_best ( & * self . backend , block) ;
120-
121- let messages_dispatch_weight_result =
122- self . client
123- . runtime_api ( )
124- . messages_dispatch_weight ( & BlockId :: Hash ( block) , lane, begin, end) ;
125- let messages_dispatch_weight = match messages_dispatch_weight_result {
126- Ok ( messages_dispatch_weight) => messages_dispatch_weight,
127- Err ( error) => {
128- return Box :: new ( jsonrpc_core:: futures:: future:: err (
129- blockchain_err ( BlockchainError :: Execution ( Box :: new ( format ! ( "{:?}" , error) ) ) ) . into ( ) ,
130- ) )
131- }
132- } ;
133-
112+ ) -> FutureResult < MessagesProof > {
134113 let runtime = self . runtime . clone ( ) ;
135114 let outbound_lane_data_key = if include_outbound_lane_state {
136115 Some ( runtime. inbound_lane_data_key ( & instance, & lane) )
@@ -140,14 +119,14 @@ where
140119 Box :: new (
141120 prove_keys_read (
142121 self . backend . clone ( ) ,
143- Some ( block) ,
122+ block,
144123 ( begin..=end)
145124 . map ( move |nonce| runtime. message_key ( & instance, & lane, nonce) )
146125 . chain ( outbound_lane_data_key. into_iter ( ) ) ,
147126 )
148127 . boxed ( )
149128 . compat ( )
150- . map ( move |proof| ( messages_dispatch_weight , serialize_storage_proof ( proof ) ) )
129+ . map ( serialize_storage_proof)
151130 . map_err ( Into :: into) ,
152131 )
153132 }
0 commit comments