mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Remove dupe info between ChainSpec and EthSpec
This commit is contained in:
@@ -55,11 +55,13 @@ impl<T: EthSpec> BlockProcessingBuilder<T> {
|
||||
let keypair = &keypairs[proposer_index];
|
||||
|
||||
match randao_sk {
|
||||
Some(sk) => builder.set_randao_reveal(&sk, &state.fork, spec),
|
||||
None => builder.set_randao_reveal(&keypair.sk, &state.fork, spec),
|
||||
Some(sk) => builder.set_randao_reveal::<T>(&sk, &state.fork, spec),
|
||||
None => builder.set_randao_reveal::<T>(&keypair.sk, &state.fork, spec),
|
||||
}
|
||||
|
||||
let block = self.block_builder.build(&keypair.sk, &state.fork, spec);
|
||||
let block = self
|
||||
.block_builder
|
||||
.build::<T>(&keypair.sk, &state.fork, spec);
|
||||
|
||||
(block, state)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ pub const VALIDATOR_COUNT: usize = 10;
|
||||
|
||||
#[test]
|
||||
fn valid_block_ok() {
|
||||
let spec = FoundationEthSpec::spec();
|
||||
let spec = FoundationEthSpec::default_spec();
|
||||
let builder = get_builder(&spec);
|
||||
let (block, mut state) = builder.build(None, None, &spec);
|
||||
|
||||
@@ -20,7 +20,7 @@ fn valid_block_ok() {
|
||||
|
||||
#[test]
|
||||
fn invalid_block_header_state_slot() {
|
||||
let spec = FoundationEthSpec::spec();
|
||||
let spec = FoundationEthSpec::default_spec();
|
||||
let builder = get_builder(&spec);
|
||||
let (mut block, mut state) = builder.build(None, None, &spec);
|
||||
|
||||
@@ -39,7 +39,7 @@ fn invalid_block_header_state_slot() {
|
||||
|
||||
#[test]
|
||||
fn invalid_parent_block_root() {
|
||||
let spec = FoundationEthSpec::spec();
|
||||
let spec = FoundationEthSpec::default_spec();
|
||||
let builder = get_builder(&spec);
|
||||
let invalid_parent_root = Hash256::from([0xAA; 32]);
|
||||
let (block, mut state) = builder.build(None, Some(invalid_parent_root), &spec);
|
||||
@@ -59,14 +59,14 @@ fn invalid_parent_block_root() {
|
||||
|
||||
#[test]
|
||||
fn invalid_block_signature() {
|
||||
let spec = FoundationEthSpec::spec();
|
||||
let spec = FoundationEthSpec::default_spec();
|
||||
let builder = get_builder(&spec);
|
||||
let (mut block, mut state) = builder.build(None, None, &spec);
|
||||
|
||||
// sign the block with a keypair that is not the expected proposer
|
||||
let keypair = Keypair::random();
|
||||
let message = block.signed_root();
|
||||
let epoch = block.slot.epoch(spec.slots_per_epoch);
|
||||
let epoch = block.slot.epoch(FoundationEthSpec::slots_per_epoch());
|
||||
let domain = spec.get_domain(epoch, Domain::BeaconProposer, &state.fork);
|
||||
block.signature = Signature::new(&message, domain, &keypair.sk);
|
||||
|
||||
@@ -82,7 +82,7 @@ fn invalid_block_signature() {
|
||||
|
||||
#[test]
|
||||
fn invalid_randao_reveal_signature() {
|
||||
let spec = FoundationEthSpec::spec();
|
||||
let spec = FoundationEthSpec::default_spec();
|
||||
let builder = get_builder(&spec);
|
||||
|
||||
// sign randao reveal with random keypair
|
||||
@@ -104,7 +104,8 @@ fn get_builder(spec: &ChainSpec) -> (BlockProcessingBuilder<FoundationEthSpec>)
|
||||
let mut builder = BlockProcessingBuilder::new(VALIDATOR_COUNT, &spec);
|
||||
|
||||
// Set the state and block to be in the last slot of the 4th epoch.
|
||||
let last_slot_of_epoch = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
||||
let last_slot_of_epoch =
|
||||
(spec.genesis_epoch + 4).end_slot(FoundationEthSpec::slots_per_epoch());
|
||||
builder.set_slot(last_slot_of_epoch, &spec);
|
||||
builder.build_caches(&spec);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ fn validate_attestation_parametric<T: EthSpec>(
|
||||
}
|
||||
);
|
||||
verify!(
|
||||
state.slot <= attestation_slot + spec.slots_per_epoch,
|
||||
state.slot <= attestation_slot + T::slots_per_epoch(),
|
||||
Invalid::IncludedTooLate {
|
||||
state: state.slot,
|
||||
attestation: attestation_slot
|
||||
|
||||
@@ -21,8 +21,8 @@ pub fn verify_proposer_slashing<T: EthSpec>(
|
||||
})?;
|
||||
|
||||
verify!(
|
||||
proposer_slashing.header_1.slot.epoch(spec.slots_per_epoch)
|
||||
== proposer_slashing.header_2.slot.epoch(spec.slots_per_epoch),
|
||||
proposer_slashing.header_1.slot.epoch(T::slots_per_epoch())
|
||||
== proposer_slashing.header_2.slot.epoch(T::slots_per_epoch()),
|
||||
Invalid::ProposalEpochMismatch(
|
||||
proposer_slashing.header_1.slot,
|
||||
proposer_slashing.header_2.slot
|
||||
@@ -40,7 +40,7 @@ pub fn verify_proposer_slashing<T: EthSpec>(
|
||||
);
|
||||
|
||||
verify!(
|
||||
verify_header_signature(
|
||||
verify_header_signature::<T>(
|
||||
&proposer_slashing.header_1,
|
||||
&proposer.pubkey,
|
||||
&state.fork,
|
||||
@@ -49,7 +49,7 @@ pub fn verify_proposer_slashing<T: EthSpec>(
|
||||
Invalid::BadProposal1Signature
|
||||
);
|
||||
verify!(
|
||||
verify_header_signature(
|
||||
verify_header_signature::<T>(
|
||||
&proposer_slashing.header_2,
|
||||
&proposer.pubkey,
|
||||
&state.fork,
|
||||
@@ -66,7 +66,7 @@ pub fn verify_proposer_slashing<T: EthSpec>(
|
||||
/// Returns `true` if the signature is valid.
|
||||
///
|
||||
/// Spec v0.6.1
|
||||
fn verify_header_signature(
|
||||
fn verify_header_signature<T: EthSpec>(
|
||||
header: &BeaconBlockHeader,
|
||||
pubkey: &PublicKey,
|
||||
fork: &Fork,
|
||||
@@ -74,7 +74,7 @@ fn verify_header_signature(
|
||||
) -> bool {
|
||||
let message = header.signed_root();
|
||||
let domain = spec.get_domain(
|
||||
header.slot.epoch(spec.slots_per_epoch),
|
||||
header.slot.epoch(T::slots_per_epoch()),
|
||||
Domain::BeaconProposer,
|
||||
fork,
|
||||
);
|
||||
|
||||
@@ -101,7 +101,7 @@ fn verify_transfer_parametric<T: EthSpec>(
|
||||
.get(transfer.sender as usize)
|
||||
.ok_or_else(|| Error::Invalid(Invalid::FromValidatorUnknown(transfer.sender)))?;
|
||||
|
||||
let epoch = state.slot.epoch(spec.slots_per_epoch);
|
||||
let epoch = state.slot.epoch(T::slots_per_epoch());
|
||||
|
||||
// Ensure one of the following is met:
|
||||
//
|
||||
@@ -136,7 +136,7 @@ fn verify_transfer_parametric<T: EthSpec>(
|
||||
// Verify the transfer signature.
|
||||
let message = transfer.signed_root();
|
||||
let domain = spec.get_domain(
|
||||
transfer.slot.epoch(spec.slots_per_epoch),
|
||||
transfer.slot.epoch(T::slots_per_epoch()),
|
||||
Domain::Transfer,
|
||||
&state.fork,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user