(optionally) include outbound lane data into messages proof (#428)

This commit is contained in:
Svyatoslav Nikolsky
2020-10-22 17:03:32 +03:00
committed by Bastian Köcher
parent bff930d01e
commit a37c1762dc
+12 -1
View File
@@ -45,6 +45,8 @@ pub type MessagesDeliveryProof = Bytes;
pub trait Runtime: Send + Sync + 'static { pub trait Runtime: Send + Sync + 'static {
/// Return runtime storage key for given message. May return None if instance is unknown. /// Return runtime storage key for given message. May return None if instance is unknown.
fn message_key(&self, instance: &InstanceId, lane: &LaneId, nonce: MessageNonce) -> Option<StorageKey>; fn message_key(&self, instance: &InstanceId, lane: &LaneId, nonce: MessageNonce) -> Option<StorageKey>;
/// Return runtime storage key for outbound lane state. May return None if instance is unknown.
fn outbound_lane_data_key(&self, instance: &InstanceId, lane: &LaneId) -> Option<StorageKey>;
/// Return runtime storage key for inbound lane state. May return None if instance is unknown. /// Return runtime storage key for inbound lane state. May return None if instance is unknown.
fn inbound_lane_data_key(&self, instance: &InstanceId, lane: &LaneId) -> Option<StorageKey>; fn inbound_lane_data_key(&self, instance: &InstanceId, lane: &LaneId) -> Option<StorageKey>;
} }
@@ -60,6 +62,7 @@ pub trait MessageLaneApi<BlockHash> {
lane: LaneId, lane: LaneId,
begin: MessageNonce, begin: MessageNonce,
end: MessageNonce, end: MessageNonce,
include_outbound_lane_state: bool,
block: Option<BlockHash>, block: Option<BlockHash>,
) -> FutureResult<MessagesProof>; ) -> FutureResult<MessagesProof>;
@@ -103,14 +106,22 @@ where
lane: LaneId, lane: LaneId,
begin: MessageNonce, begin: MessageNonce,
end: MessageNonce, end: MessageNonce,
include_outbound_lane_state: bool,
block: Option<Block::Hash>, block: Option<Block::Hash>,
) -> FutureResult<MessagesProof> { ) -> FutureResult<MessagesProof> {
let runtime = self.runtime.clone(); let runtime = self.runtime.clone();
let outbound_lane_data_key = if include_outbound_lane_state {
Some(runtime.inbound_lane_data_key(&instance, &lane))
} else {
None
};
Box::new( Box::new(
prove_keys_read( prove_keys_read(
self.backend.clone(), self.backend.clone(),
block, block,
(begin..=end).map(move |nonce| runtime.message_key(&instance, &lane, nonce)), (begin..=end)
.map(move |nonce| runtime.message_key(&instance, &lane, nonce))
.chain(outbound_lane_data_key.into_iter()),
) )
.boxed() .boxed()
.compat() .compat()