mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 11:52:42 +00:00
Update attestation rewards API for Electra (#6819)
Closes: - https://github.com/sigp/lighthouse/issues/6818 Use `MAX_EFFECTIVE_BALANCE_ELECTRA` (2048) for attestation reward calculations involving Electra. Add a new `InteropGenesisBuilder` that tries to provide a more flexible way to build genesis states. Unfortunately due to lifetime jank, it is quite unergonomic at present. We may want to refactor this builder in future to make it easier to use.
This commit is contained in:
@@ -31,7 +31,7 @@ use execution_layer::{
|
||||
ExecutionLayer,
|
||||
};
|
||||
use futures::channel::mpsc::Receiver;
|
||||
pub use genesis::{interop_genesis_state_with_eth1, DEFAULT_ETH1_BLOCK_HASH};
|
||||
pub use genesis::{InteropGenesisBuilder, DEFAULT_ETH1_BLOCK_HASH};
|
||||
use int_to_bytes::int_to_bytes32;
|
||||
use kzg::trusted_setup::get_trusted_setup;
|
||||
use kzg::{Kzg, TrustedSetup};
|
||||
@@ -232,6 +232,7 @@ pub struct Builder<T: BeaconChainTypes> {
|
||||
mock_execution_layer: Option<MockExecutionLayer<T::EthSpec>>,
|
||||
testing_slot_clock: Option<TestingSlotClock>,
|
||||
validator_monitor_config: Option<ValidatorMonitorConfig>,
|
||||
genesis_state_builder: Option<InteropGenesisBuilder<T::EthSpec>>,
|
||||
import_all_data_columns: bool,
|
||||
runtime: TestRuntime,
|
||||
log: Logger,
|
||||
@@ -253,16 +254,22 @@ impl<E: EthSpec> Builder<EphemeralHarnessType<E>> {
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
let genesis_state_builder = self.genesis_state_builder.take().unwrap_or_else(|| {
|
||||
// Set alternating withdrawal credentials if no builder is specified.
|
||||
InteropGenesisBuilder::default().set_alternating_eth1_withdrawal_credentials()
|
||||
});
|
||||
|
||||
let mutator = move |builder: BeaconChainBuilder<_>| {
|
||||
let header = generate_genesis_header::<E>(builder.get_spec(), false);
|
||||
let genesis_state = interop_genesis_state_with_eth1::<E>(
|
||||
&validator_keypairs,
|
||||
HARNESS_GENESIS_TIME,
|
||||
Hash256::from_slice(DEFAULT_ETH1_BLOCK_HASH),
|
||||
header,
|
||||
builder.get_spec(),
|
||||
)
|
||||
.expect("should generate interop state");
|
||||
let genesis_state = genesis_state_builder
|
||||
.set_opt_execution_payload_header(header)
|
||||
.build_genesis_state(
|
||||
&validator_keypairs,
|
||||
HARNESS_GENESIS_TIME,
|
||||
Hash256::from_slice(DEFAULT_ETH1_BLOCK_HASH),
|
||||
builder.get_spec(),
|
||||
)
|
||||
.expect("should generate interop state");
|
||||
builder
|
||||
.genesis_state(genesis_state)
|
||||
.expect("should build state using recent genesis")
|
||||
@@ -318,16 +325,22 @@ impl<E: EthSpec> Builder<DiskHarnessType<E>> {
|
||||
.clone()
|
||||
.expect("cannot build without validator keypairs");
|
||||
|
||||
let genesis_state_builder = self.genesis_state_builder.take().unwrap_or_else(|| {
|
||||
// Set alternating withdrawal credentials if no builder is specified.
|
||||
InteropGenesisBuilder::default().set_alternating_eth1_withdrawal_credentials()
|
||||
});
|
||||
|
||||
let mutator = move |builder: BeaconChainBuilder<_>| {
|
||||
let header = generate_genesis_header::<E>(builder.get_spec(), false);
|
||||
let genesis_state = interop_genesis_state_with_eth1::<E>(
|
||||
&validator_keypairs,
|
||||
HARNESS_GENESIS_TIME,
|
||||
Hash256::from_slice(DEFAULT_ETH1_BLOCK_HASH),
|
||||
header,
|
||||
builder.get_spec(),
|
||||
)
|
||||
.expect("should generate interop state");
|
||||
let genesis_state = genesis_state_builder
|
||||
.set_opt_execution_payload_header(header)
|
||||
.build_genesis_state(
|
||||
&validator_keypairs,
|
||||
HARNESS_GENESIS_TIME,
|
||||
Hash256::from_slice(DEFAULT_ETH1_BLOCK_HASH),
|
||||
builder.get_spec(),
|
||||
)
|
||||
.expect("should generate interop state");
|
||||
builder
|
||||
.genesis_state(genesis_state)
|
||||
.expect("should build state using recent genesis")
|
||||
@@ -375,6 +388,7 @@ where
|
||||
mock_execution_layer: None,
|
||||
testing_slot_clock: None,
|
||||
validator_monitor_config: None,
|
||||
genesis_state_builder: None,
|
||||
import_all_data_columns: false,
|
||||
runtime,
|
||||
log,
|
||||
@@ -560,6 +574,15 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_genesis_state_builder(
|
||||
mut self,
|
||||
f: impl FnOnce(InteropGenesisBuilder<E>) -> InteropGenesisBuilder<E>,
|
||||
) -> Self {
|
||||
let builder = self.genesis_state_builder.take().unwrap_or_default();
|
||||
self.genesis_state_builder = Some(f(builder));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> BeaconChainHarness<BaseHarnessType<E, Hot, Cold>> {
|
||||
let (shutdown_tx, shutdown_receiver) = futures::channel::mpsc::channel(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user