Skip to content

Commit f892cea

Browse files
test: add binary e2e test for joining with an outdated checkpoint (#86)
Changes: - Adds a route to the RPC server that returns the current epoch - Adds another binary e2e test (similar to stake-and-checkpoint), where a node joins with an outdated checkpoint (2 epochs old). Since the nodes keep track of 4 peer sets by default, a node should be able to join with a checkpoint that contains an outdated peer set, as long as it is not older than 4 epochs.
1 parent 4b5ad02 commit f892cea

File tree

6 files changed

+880
-0
lines changed

6 files changed

+880
-0
lines changed

finalizer/src/actor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,10 @@ impl<
767767
let height = self.canonical_state.get_latest_height();
768768
let _ = sender.send(ConsensusStateResponse::LatestHeight(height));
769769
}
770+
ConsensusStateRequest::GetLatestEpoch => {
771+
let epoch = self.canonical_state.get_epoch();
772+
let _ = sender.send(ConsensusStateResponse::LatestEpoch(epoch));
773+
}
770774
ConsensusStateRequest::GetValidatorBalance(public_key) => {
771775
let mut key_bytes = [0u8; 32];
772776
key_bytes.copy_from_slice(&public_key);

finalizer/src/ingress.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ impl<S: Scheme, B: ConsensusBlock + Committable> FinalizerMailbox<S, B> {
150150
height
151151
}
152152

153+
pub async fn get_latest_epoch(&self) -> u64 {
154+
let (response, rx) = oneshot::channel();
155+
let request = ConsensusStateRequest::GetLatestEpoch;
156+
let _ = self
157+
.sender
158+
.clone()
159+
.send(FinalizerMessage::QueryState { request, response })
160+
.await;
161+
162+
let res = rx
163+
.await
164+
.expect("consensus state query response sender dropped");
165+
let ConsensusStateResponse::LatestEpoch(epoch) = res else {
166+
unreachable!("request and response variants must match");
167+
};
168+
epoch
169+
}
170+
153171
pub async fn get_validator_balance(&self, public_key: PublicKey) -> Option<u64> {
154172
let (response, rx) = oneshot::channel();
155173
let request = ConsensusStateRequest::GetValidatorBalance(public_key);

node/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ name = "stake-and-checkpoint"
1616
path = "src/bin/stake_and_checkpoint.rs"
1717
required-features = ["e2e"]
1818

19+
[[bin]]
20+
name = "stake-and-join-with-outdated-checkpoint"
21+
path = "src/bin/stake_and_join_with_outdated_ckpt.rs"
22+
required-features = ["e2e"]
23+
1924
[[bin]]
2025
name = "withdraw-and-exit"
2126
path = "src/bin/withdraw_and_exit.rs"

0 commit comments

Comments
 (0)