Add ProposerSlashingBuilder
It is capable of producing double votes
This commit is contained in:
parent
bb4d392a98
commit
8e1380d7c4
@ -6,6 +6,10 @@ use serde_derive::Serialize;
|
|||||||
use ssz_derive::{Decode, Encode, TreeHash};
|
use ssz_derive::{Decode, Encode, TreeHash};
|
||||||
use test_random_derive::TestRandom;
|
use test_random_derive::TestRandom;
|
||||||
|
|
||||||
|
mod builder;
|
||||||
|
|
||||||
|
pub use builder::ProposerSlashingBuilder;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize, Encode, Decode, TreeHash, TestRandom)]
|
#[derive(Debug, PartialEq, Clone, Serialize, Encode, Decode, TreeHash, TestRandom)]
|
||||||
pub struct ProposerSlashing {
|
pub struct ProposerSlashing {
|
||||||
pub proposer_index: u64,
|
pub proposer_index: u64,
|
||||||
|
48
eth2/types/src/proposer_slashing/builder.rs
Normal file
48
eth2/types/src/proposer_slashing/builder.rs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
use crate::*;
|
||||||
|
use ssz::TreeHash;
|
||||||
|
|
||||||
|
pub struct ProposerSlashingBuilder();
|
||||||
|
|
||||||
|
impl ProposerSlashingBuilder {
|
||||||
|
pub fn double_vote<F>(proposer_index: u64, signer: F, spec: &ChainSpec) -> ProposerSlashing
|
||||||
|
where
|
||||||
|
F: Fn(u64, &[u8], Epoch, u64) -> Signature,
|
||||||
|
{
|
||||||
|
let slot = Slot::new(0);
|
||||||
|
let shard = 0;
|
||||||
|
|
||||||
|
let proposal_data_1 = ProposalSignedData {
|
||||||
|
slot,
|
||||||
|
shard,
|
||||||
|
block_root: Hash256::from("one".as_bytes()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let proposal_data_2 = ProposalSignedData {
|
||||||
|
slot,
|
||||||
|
shard,
|
||||||
|
block_root: Hash256::from("two".as_bytes()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let proposal_signature_1 = {
|
||||||
|
let message = proposal_data_1.hash_tree_root();
|
||||||
|
let epoch = slot.epoch(spec.epoch_length);
|
||||||
|
let domain = spec.domain_proposal;
|
||||||
|
signer(proposer_index, &message[..], epoch, domain)
|
||||||
|
};
|
||||||
|
|
||||||
|
let proposal_signature_2 = {
|
||||||
|
let message = proposal_data_2.hash_tree_root();
|
||||||
|
let epoch = slot.epoch(spec.epoch_length);
|
||||||
|
let domain = spec.domain_proposal;
|
||||||
|
signer(proposer_index, &message[..], epoch, domain)
|
||||||
|
};
|
||||||
|
|
||||||
|
ProposerSlashing {
|
||||||
|
proposer_index,
|
||||||
|
proposal_data_1,
|
||||||
|
proposal_signature_1,
|
||||||
|
proposal_data_2,
|
||||||
|
proposal_signature_2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user