Skip to content

Commit 3d24712

Browse files
committed
refactor: remove the redundant tip field in ClientForward
Signed-off-by: etorreborre <etorreborre@yahoo.com>
1 parent a1ee222 commit 3d24712

3 files changed

Lines changed: 16 additions & 20 deletions

File tree

crates/amaru/src/stages/consensus/forward_chain.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ impl Worker {
134134
"tip_changed"
135135
);
136136

137-
self.clients.send(ClientMsg::Op(ClientOp::Forward(
138-
header.clone(),
139-
self.our_tip.clone(),
140-
)));
137+
self.clients
138+
.send(ClientMsg::Op(ClientOp::Forward(header.clone())));
141139

142140
stage
143141
.downstream
@@ -188,7 +186,7 @@ enum ClientOp {
188186
/// the tip to go back to
189187
Backward(Tip),
190188
/// the header to go forward to and the tip we will be at after sending this header
191-
Forward(Header, Tip),
189+
Forward(Header),
192190
}
193191

194192
impl std::fmt::Debug for ClientOp {
@@ -198,13 +196,16 @@ impl std::fmt::Debug for ClientOp {
198196
.debug_struct("Backward")
199197
.field("tip", &(tip.1, PrettyPoint(&tip.0)))
200198
.finish(),
201-
Self::Forward(header, tip) => f
199+
Self::Forward(header) => f
202200
.debug_struct("Forward")
203201
.field(
204202
"header",
205203
&(header.block_height(), PrettyPoint(&header.pallas_point())),
206204
)
207-
.field("tip", &(tip.1, PrettyPoint(&tip.0)))
205+
.field(
206+
"tip",
207+
&(header.as_tip().1, PrettyPoint(&header.pallas_point())),
208+
)
208209
.finish(),
209210
}
210211
}
@@ -234,9 +235,7 @@ impl PartialEq for ClientOp {
234235
fn eq(&self, other: &Self) -> bool {
235236
match (self, other) {
236237
(Self::Backward(l0), Self::Backward(r0)) => (&l0.0, l0.1) == (&r0.0, r0.1),
237-
(Self::Forward(l0, l1), Self::Forward(r0, r1)) => {
238-
l0 == r0 && (&l1.0, l1.1) == (&r1.0, r1.1)
239-
}
238+
(Self::Forward(l0), Self::Forward(r0)) => l0 == r0,
240239
_ => false,
241240
}
242241
}
@@ -248,7 +247,7 @@ impl ClientOp {
248247
pub fn tip(&self) -> Tip {
249248
match self {
250249
ClientOp::Backward(tip) => tip.clone(),
251-
ClientOp::Forward(_, tip) => tip.clone(),
250+
ClientOp::Forward(header) => header.as_tip(),
252251
}
253252
}
254253
}

crates/amaru/src/stages/consensus/forward_chain/client_protocol.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ async fn chain_sync_handler(
179179

180180
if let ActoInput::Message(op) = cell.recv().await {
181181
match op {
182-
Some((ClientOp::Forward(header, _), tip)) => {
182+
Some((ClientOp::Forward(header), tip)) => {
183183
tracing::debug!("sending roll forward");
184184
server
185185
.send_roll_forward(to_header_content(header), tip)
@@ -196,7 +196,7 @@ async fn chain_sync_handler(
196196
return Ok(());
197197
};
198198
match op {
199-
ClientOp::Forward(header, _) => {
199+
ClientOp::Forward(header) => {
200200
server
201201
.send_roll_forward(to_header_content(header), tip)
202202
.await?;

crates/amaru/src/stages/consensus/forward_chain/client_state.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use super::{ClientOp, hash_point};
16-
use crate::stages::AsTip;
16+
use crate::stages::{AsTip, PallasPoint};
1717
use amaru_kernel::Header;
1818
use amaru_ouroboros_traits::{ChainStore, IsHeader};
1919
use pallas_network::miniprotocols::{Point, chainsync::Tip};
@@ -44,7 +44,7 @@ impl ClientState {
4444
ClientOp::Backward(tip) => {
4545
if let Some((index, _)) =
4646
self.ops.iter().enumerate().rfind(
47-
|(_, op)| matches!(op, ClientOp::Forward(_, tip2) if tip2.0 == tip.0),
47+
|(_, op)| matches!(op, ClientOp::Forward(header2) if header2.pallas_point() == tip.0),
4848
)
4949
{
5050
tracing::debug!("found backward op at index {index} in {:?}", self.ops);
@@ -81,10 +81,7 @@ pub(super) fn find_headers_between(
8181

8282
// Find the first point that is in the past of start_point
8383
let mut current_header = start_header;
84-
let mut headers = vec![ClientOp::Forward(
85-
current_header.clone(),
86-
current_header.as_tip(),
87-
)];
84+
let mut headers = vec![ClientOp::Forward(current_header.clone())];
8885

8986
while let Some(parent_hash) = current_header.parent() {
9087
match store.load_header(&parent_hash) {
@@ -94,7 +91,7 @@ pub(super) fn find_headers_between(
9491
headers.reverse();
9592
return Some((headers, header.as_tip()));
9693
}
97-
headers.push(ClientOp::Forward(header.clone(), header.as_tip()));
94+
headers.push(ClientOp::Forward(header.clone()));
9895
current_header = header;
9996
}
10097
None => return None, // Broken chain

0 commit comments

Comments
 (0)