Skip to content
Snippets Groups Projects
Commit 12aac56c authored by Wei Tang's avatar Wei Tang
Browse files

yamltests, beacon: port back crosslinks and pass all crosslinks test

parent dee394c8
Branches
No related merge requests found
use crate::{Config, BeaconState, Error};
impl<C: Config> BeaconState<C> {
/// Update crosslinks
pub fn process_crosslinks(&mut self) -> Result<(), Error> {
self.previous_crosslinks = self.current_crosslinks.clone();
for epoch in &[self.previous_epoch(), self.current_epoch()] {
for offset in 0..self.committee_count(*epoch) {
let shard = (self.start_shard(*epoch)? + offset) % C::shard_count();
let crosslink_committee = self.crosslink_committee(*epoch, shard)?;
let (winning_crosslink, attesting_indices) =
self.winning_crosslink_and_attesting_indices(*epoch, shard)?;
if 3 * self.total_balance(&attesting_indices) >=
2 * self.total_balance(&crosslink_committee)
{
self.current_crosslinks[shard as usize] = winning_crosslink;
}
}
}
Ok(())
}
}
mod helpers;
mod justification;
mod crosslink;
......@@ -18,21 +18,21 @@ impl<C: Config> Test for JustificationAndFinalizationTest<C> {
}
}
// #[derive(Serialize, Deserialize, Debug)]
// #[serde(deny_unknown_fields)]
// pub struct CrosslinksTest {
// pub description: String,
// pub pre: BeaconState,
// pub post: Option<BeaconState>,
// }
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct CrosslinksTest<C: Config> {
pub description: String,
pub pre: BeaconState<C>,
pub post: Option<BeaconState<C>>,
}
// impl Test for CrosslinksTest {
// fn run<C: Config>(&self, config: &C) {
// run_test_with(&self.description, &self.pre, self.post.as_ref(), config, |executive| {
// executive.process_crosslinks()
// });
// }
// }
impl<C: Config> Test for CrosslinksTest<C> {
fn run(&self) {
run_test_with(&self.description, &self.pre, self.post.as_ref(), |state| {
state.process_crosslinks()
});
}
}
// #[derive(Serialize, Deserialize, Debug)]
// #[serde(deny_unknown_fields)]
......
......@@ -46,7 +46,7 @@ fn run_all<C: Config + serde::Serialize + DeserializeOwned>(runner: &str, file:
"transfer" => run::<TransferTest<C>>(file),
"voluntary_exit" => run::<VoluntaryExitTest<C>>(file),
"justification_and_finalization" => run::<JustificationAndFinalizationTest<C>>(file),
// "crosslinks" => run::<CrosslinksTest, _>(file, &config),
"crosslinks" => run::<CrosslinksTest<C>>(file),
// "registry_updates" => run::<RegistryUpdatesTest, _>(file, &config),
// "blocks" => run::<BlocksTest, _>(file, &config),
// "slots" => run::<SlotsTest, _>(file, &config),
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment