mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-28 14:57:17 +00:00
Change test_harness proposer_slashings YAML
Removes a lot of the detail from the `proposer_slashings` field -- IMO this is not necessary in the test spec, the details of how a proposer_slashing is created should be held in the program and the spec should only define that one happens.
This commit is contained in:
parent
8e1380d7c4
commit
e59404f463
@ -20,19 +20,18 @@ test_cases:
|
||||
amount: 32
|
||||
merkle_index: 2
|
||||
proposer_slashings:
|
||||
- slot: 8 # At slot 8, trigger a proposal slashing
|
||||
proposer_index: 42 # Penalize the validator at position 42
|
||||
proposal_1_shard: 0
|
||||
proposal_1_slot: 15
|
||||
proposal_1_root: !!binary |
|
||||
LkmqmqoodLKAslkjdkajsdljasdkajlksjdasldjasdd
|
||||
proposal_2_shard: 0
|
||||
proposal_2_slot: 15
|
||||
proposal_2_root: !!binary |
|
||||
DIFFERENTKAslkjdkajsdljasdkajlksjdasldjasdd
|
||||
# At slot 2, trigger a proposer slashing for validator #42.
|
||||
- slot: 2
|
||||
validator_index: 42
|
||||
# At slot 8, trigger a proposer slashing for validator #13.
|
||||
- slot: 8
|
||||
validator_index: 13
|
||||
attester_slashings:
|
||||
# At slot 2, trigger an attester slashing for validators #11 and #12
|
||||
# At slot 2, trigger an attester slashing for validators #11 and #12.
|
||||
- slot: 2
|
||||
validator_indices: [11, 12]
|
||||
# At slot 5, trigger an attester slashing for validator #14.
|
||||
- slot: 5
|
||||
validator_indices: [14]
|
||||
results:
|
||||
num_validators: 1000
|
||||
|
@ -273,32 +273,7 @@ impl BeaconChainHarness {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_proposer_slashing(&mut self, mut proposer_slashing: ProposerSlashing) {
|
||||
let validator = &self.validators[proposer_slashing.proposer_index as usize];
|
||||
|
||||
// This following code is a little awkward, but managing the data_1 and data_1 was getting
|
||||
// rather confusing. I think this is better
|
||||
let proposals = vec![
|
||||
&proposer_slashing.proposal_data_1,
|
||||
&proposer_slashing.proposal_data_2,
|
||||
];
|
||||
let signatures: Vec<Signature> = proposals
|
||||
.iter()
|
||||
.map(|proposal_data| {
|
||||
let message = proposal_data.hash_tree_root();
|
||||
let epoch = proposal_data.slot.epoch(self.spec.epoch_length);
|
||||
let domain = self
|
||||
.beacon_chain
|
||||
.state
|
||||
.read()
|
||||
.fork
|
||||
.get_domain(epoch, self.spec.domain_proposal);
|
||||
Signature::new(&message[..], domain, &validator.keypair.sk)
|
||||
})
|
||||
.collect();
|
||||
proposer_slashing.proposal_signature_1 = signatures[0].clone();
|
||||
proposer_slashing.proposal_signature_2 = signatures[1].clone();
|
||||
|
||||
pub fn add_proposer_slashing(&mut self, proposer_slashing: ProposerSlashing) {
|
||||
self.beacon_chain
|
||||
.receive_proposer_slashing_for_inclusion(proposer_slashing);
|
||||
}
|
||||
|
@ -7,8 +7,10 @@ use env_logger::{Builder, Env};
|
||||
use log::{info, warn};
|
||||
use ssz::TreeHash;
|
||||
use std::{fs::File, io::prelude::*};
|
||||
use types::attester_slashing::AttesterSlashingBuilder;
|
||||
use types::*;
|
||||
use types::{
|
||||
attester_slashing::AttesterSlashingBuilder, proposer_slashing::ProposerSlashingBuilder,
|
||||
};
|
||||
use yaml_rust::{Yaml, YamlLoader};
|
||||
|
||||
mod beacon_chain_harness;
|
||||
@ -99,13 +101,14 @@ impl Manifest {
|
||||
|
||||
// Feed proposer slashings to the BeaconChain.
|
||||
if let Some(ref slashings) = self.config.proposer_slashings {
|
||||
for (slot, slashing) in slashings {
|
||||
for (slot, validator_index) in slashings {
|
||||
if *slot == slot_height {
|
||||
info!(
|
||||
"Including proposer slashing at slot height {}.",
|
||||
slot_height
|
||||
"Including proposer slashing at slot height {} for validator #{}.",
|
||||
slot_height, validator_index
|
||||
);
|
||||
harness.add_proposer_slashing(slashing.clone());
|
||||
let slashing = build_proposer_slashing(&harness, *validator_index);
|
||||
harness.add_proposer_slashing(slashing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,8 +118,8 @@ impl Manifest {
|
||||
for (slot, validator_indices) in slashings {
|
||||
if *slot == slot_height {
|
||||
info!(
|
||||
"Including attester slashing at slot height {}.",
|
||||
slot_height
|
||||
"Including attester slashing at slot height {} for validators {:?}.",
|
||||
slot_height, validator_indices
|
||||
);
|
||||
let slashing =
|
||||
build_double_vote_attester_slashing(&harness, &validator_indices[..]);
|
||||
@ -205,8 +208,18 @@ fn build_double_vote_attester_slashing(
|
||||
AttesterSlashingBuilder::double_vote(validator_indices, signer, &harness.spec)
|
||||
}
|
||||
|
||||
fn build_proposer_slashing(harness: &BeaconChainHarness, validator_index: u64) -> ProposerSlashing {
|
||||
let signer = |validator_index: u64, message: &[u8], epoch: Epoch, domain: u64| {
|
||||
harness
|
||||
.validator_sign(validator_index as usize, message, epoch, domain)
|
||||
.expect("Unable to sign AttesterSlashing")
|
||||
};
|
||||
|
||||
ProposerSlashingBuilder::double_vote(validator_index, signer, &harness.spec)
|
||||
}
|
||||
|
||||
pub type DepositTuple = (u64, Deposit, Keypair);
|
||||
pub type ProposerSlashingTuple = (u64, ProposerSlashing);
|
||||
pub type ProposerSlashingTuple = (u64, u64);
|
||||
pub type AttesterSlashingTuple = (u64, Vec<u64>);
|
||||
|
||||
struct ExecutionResult {
|
||||
@ -272,40 +285,11 @@ fn parse_proposer_slashings(yaml: &Yaml) -> Option<Vec<ProposerSlashingTuple>> {
|
||||
let mut slashings = vec![];
|
||||
|
||||
for slashing in yaml["proposer_slashings"].as_vec()? {
|
||||
let slot = as_u64(slashing, "slot").expect("Incomplete slashing");
|
||||
let slot = as_u64(slashing, "slot").expect("Incomplete proposer slashing (slot)_");
|
||||
let validator_index = as_u64(slashing, "validator_index")
|
||||
.expect("Incomplete proposer slashing (validator_index)");
|
||||
|
||||
// Builds a ProposerSlashing object from YAML fields.
|
||||
//
|
||||
// Rustfmt make this look rather ugly, however it is just a simple struct
|
||||
// instantiation.
|
||||
let slashing = ProposerSlashing {
|
||||
proposer_index: as_u64(slashing, "proposer_index")
|
||||
.expect("Incomplete slashing (proposer_index)"),
|
||||
proposal_data_1: ProposalSignedData {
|
||||
slot: Slot::from(
|
||||
as_u64(slashing, "proposal_1_slot")
|
||||
.expect("Incomplete slashing (proposal_1_slot)."),
|
||||
),
|
||||
shard: as_u64(slashing, "proposal_1_shard")
|
||||
.expect("Incomplete slashing (proposal_1_shard)."),
|
||||
block_root: as_hash256(slashing, "proposal_1_root")
|
||||
.expect("Incomplete slashing (proposal_1_root)."),
|
||||
},
|
||||
proposal_signature_1: Signature::empty_signature(), // Will be replaced with real signature at runtime.
|
||||
proposal_data_2: ProposalSignedData {
|
||||
slot: Slot::from(
|
||||
as_u64(slashing, "proposal_2_slot")
|
||||
.expect("Incomplete slashing (proposal_2_slot)."),
|
||||
),
|
||||
shard: as_u64(slashing, "proposal_2_shard")
|
||||
.expect("Incomplete slashing (proposal_2_shard)."),
|
||||
block_root: as_hash256(slashing, "proposal_2_root")
|
||||
.expect("Incomplete slashing (proposal_2_root)."),
|
||||
},
|
||||
proposal_signature_2: Signature::empty_signature(), // Will be replaced with real signature at runtime.
|
||||
};
|
||||
|
||||
slashings.push((slot, slashing));
|
||||
slashings.push((slot, validator_index));
|
||||
}
|
||||
|
||||
Some(slashings)
|
||||
|
Loading…
Reference in New Issue
Block a user