Remove redundant data from InboundLaneData (#638)

* Remove latest_*_nonce.

* cargo fmt --all

* Fix tests.

* cargo fmt --all

* Fix benchmarking.

* Update docs.
This commit is contained in:
Tomasz Drwięga
2021-01-12 22:27:53 +01:00
committed by Bastian Köcher
parent 58fbd8cb49
commit e6fc67c705
4 changed files with 78 additions and 63 deletions
+18 -17
View File
@@ -464,7 +464,8 @@ decl_module! {
// mark messages as delivered
let mut lane = outbound_lane::<T, I>(lane_id);
let received_range = lane.confirm_delivery(lane_data.latest_received_nonce);
let last_delivered_nonce = lane_data.last_delivered_nonce();
let received_range = lane.confirm_delivery(last_delivered_nonce);
if let Some(received_range) = received_range {
Self::deposit_event(RawEvent::MessagesDelivered(lane_id, received_range.0, received_range.1));
@@ -499,7 +500,7 @@ decl_module! {
frame_support::debug::trace!(
"Received messages delivery proof up to (and including) {} at lane {:?}",
lane_data.latest_received_nonce,
last_delivered_nonce,
lane_id,
);
@@ -526,12 +527,12 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
/// Get nonce of latest received message at given inbound lane.
pub fn inbound_latest_received_nonce(lane: LaneId) -> MessageNonce {
InboundLanes::<T, I>::get(&lane).latest_received_nonce
InboundLanes::<T, I>::get(&lane).last_delivered_nonce()
}
/// Get nonce of latest confirmed message at given inbound lane.
pub fn inbound_latest_confirmed_nonce(lane: LaneId) -> MessageNonce {
InboundLanes::<T, I>::get(&lane).latest_confirmed_nonce
InboundLanes::<T, I>::get(&lane).last_confirmed_nonce
}
/// Get state of unrewarded relayers set.
@@ -795,7 +796,7 @@ mod tests {
Ok((
TEST_LANE_ID,
InboundLaneData {
latest_received_nonce: 1,
last_confirmed_nonce: 1,
..Default::default()
},
)),
@@ -905,7 +906,7 @@ mod tests {
Ok((
TEST_LANE_ID,
InboundLaneData {
latest_received_nonce: 1,
last_confirmed_nonce: 1,
..Default::default()
},
)),
@@ -977,7 +978,7 @@ mod tests {
REGULAR_PAYLOAD.1,
));
assert_eq!(InboundLanes::<TestRuntime>::get(TEST_LANE_ID).latest_received_nonce, 1);
assert_eq!(InboundLanes::<TestRuntime>::get(TEST_LANE_ID).last_delivered_nonce(), 1);
});
}
@@ -988,8 +989,7 @@ mod tests {
InboundLanes::<TestRuntime, DefaultInstance>::insert(
TEST_LANE_ID,
InboundLaneData {
latest_confirmed_nonce: 8,
latest_received_nonce: 10,
last_confirmed_nonce: 8,
relayers: vec![(9, 9, TEST_RELAYER_A), (10, 10, TEST_RELAYER_B)]
.into_iter()
.collect(),
@@ -1022,11 +1022,10 @@ mod tests {
assert_eq!(
InboundLanes::<TestRuntime>::get(TEST_LANE_ID),
InboundLaneData {
last_confirmed_nonce: 9,
relayers: vec![(10, 10, TEST_RELAYER_B), (11, 11, TEST_RELAYER_A)]
.into_iter()
.collect(),
latest_received_nonce: 11,
latest_confirmed_nonce: 9,
},
);
assert_eq!(
@@ -1108,7 +1107,6 @@ mod tests {
TEST_LANE_ID,
InboundLaneData {
relayers: vec![(1, 1, TEST_RELAYER_A)].into_iter().collect(),
latest_received_nonce: 1,
..Default::default()
}
)),
@@ -1136,7 +1134,6 @@ mod tests {
relayers: vec![(1, 1, TEST_RELAYER_A), (2, 2, TEST_RELAYER_B)]
.into_iter()
.collect(),
latest_received_nonce: 2,
..Default::default()
}
)),
@@ -1180,7 +1177,6 @@ mod tests {
relayers: vec![(1, 1, TEST_RELAYER_A), (2, 2, TEST_RELAYER_B)]
.into_iter()
.collect(),
latest_received_nonce: 2,
..Default::default()
}
)),
@@ -1203,7 +1199,6 @@ mod tests {
relayers: vec![(1, 1, TEST_RELAYER_A), (2, 2, TEST_RELAYER_B)]
.into_iter()
.collect(),
latest_received_nonce: 2,
..Default::default()
}
)),
@@ -1232,7 +1227,10 @@ mod tests {
0, // weight may be zero in this case (all messages are improperly encoded)
),);
assert_eq!(InboundLanes::<TestRuntime>::get(&TEST_LANE_ID).latest_received_nonce, 1,);
assert_eq!(
InboundLanes::<TestRuntime>::get(&TEST_LANE_ID).last_delivered_nonce(),
1,
);
});
}
@@ -1255,7 +1253,10 @@ mod tests {
REGULAR_PAYLOAD.1 + REGULAR_PAYLOAD.1,
),);
assert_eq!(InboundLanes::<TestRuntime>::get(&TEST_LANE_ID).latest_received_nonce, 3,);
assert_eq!(
InboundLanes::<TestRuntime>::get(&TEST_LANE_ID).last_delivered_nonce(),
3,
);
});
}