Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Realized unrealized experimentation #3322

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
5cae2f9
separate participation cache by epoch and add it to the beacon state
realbigsean Apr 23, 2022
6c7ab85
Mutate state via mini beacon state in epoch processing
realbigsean May 3, 2022
fb16cd7
fork choice schema migration
realbigsean May 5, 2022
24a5c16
update filter block tree
realbigsean May 5, 2022
24c6273
cargo fmt and fix
realbigsean May 5, 2022
513d2b2
refactors
realbigsean May 5, 2022
1b81c56
fixes and debugging
realbigsean May 6, 2022
e67f07d
debugging
realbigsean May 9, 2022
1854a23
remove debugging lines, fix chache initialization slot
realbigsean May 9, 2022
365d58c
Add first unit test
paulhauner Apr 20, 2022
2ae43cd
adjust pauls test to only run for altair and to, and to assert the he…
realbigsean May 9, 2022
8a5d9f3
Add scenario for n + 2
realbigsean May 12, 2022
e166d55
Merge branch 'unstable' of https://github.com/sigp/lighthouse into fc…
realbigsean Jun 14, 2022
dc51a24
updates for fc store unrealized justification tracking
realbigsean Jun 14, 2022
da9047c
filter block tree changes
realbigsean Jun 15, 2022
58b2892
changes for tests
realbigsean Jun 17, 2022
0ce2a6b
Merge branch 'unstable' of https://github.com/sigp/lighthouse into fc…
realbigsean Jun 17, 2022
3a0fea7
test
realbigsean Jun 17, 2022
76b5344
revert changes to ef test tester
realbigsean Jun 18, 2022
5b43461
remove ef-test proposer boost shim
realbigsean Jun 18, 2022
4ce3e40
- pass thrugh spec argument
realbigsean Jun 20, 2022
c8315e1
EthSpec generic in proto array
realbigsean Jun 20, 2022
2421281
process justifiable for base as well
realbigsean Jun 20, 2022
a7b1e82
Merge branch 'fc-refactor' of https://github.com/realbigsean/lighthou…
realbigsean Jun 21, 2022
7d8f85f
update justification and finalization method
realbigsean Jun 21, 2022
ec5f058
Squash previous works
macladson Mar 10, 2022
61ff3b5
Resolve `BeaconChain` compile errors
paulhauner May 30, 2022
4fa5be6
Revert `common/eth2` to `unstable`
paulhauner May 30, 2022
ac01a7e
Fix `http_api` to pass `make lint`
paulhauner Jun 7, 2022
8ade87e
Remove old fork choice functions
paulhauner May 30, 2022
b00c0db
Fix compile errors in HTTP tests
paulhauner May 31, 2022
095ff72
Wrap harness in Arc
paulhauner May 31, 2022
211e4cc
Start *horrific* async test refactor
paulhauner May 31, 2022
3438ac2
More test fixes
paulhauner May 31, 2022
9aa796f
Make tests *finally* compile with async FC
paulhauner Jun 1, 2022
87b4760
Add progress on async block import
paulhauner Jun 2, 2022
3cbffa4
Solve `StoreOp` lifetime problem
paulhauner Jun 2, 2022
ac35a43
Reinstate panda banner
paulhauner Jun 4, 2022
2d0f5b9
Partially add `PayloadNotifier`
paulhauner Jun 4, 2022
4597d24
Start Arc-ifying SignedBeaconBlock
paulhauner Jun 5, 2022
0a6b9ae
Arc-ification of networking crate
paulhauner Jun 6, 2022
3e21adb
Fix http_api, `make lint` passes
paulhauner Jun 6, 2022
689f3e6
Refactor exec payload "prepare payload"
paulhauner Jun 6, 2022
59351d2
Make block production async (make lint passing)
paulhauner Jun 6, 2022
f9634a6
Fix test compilation errors
paulhauner Jun 6, 2022
dc4c7b6
Fix justified checkpoint getter
paulhauner Jun 6, 2022
d21536e
Remove deadlock from block import
paulhauner Jun 7, 2022
f452bd8
Fix clippy lint
paulhauner Jun 7, 2022
49fce95
Update test for finalized_checkpoint event
paulhauner Jun 7, 2022
11a3eaa
Fix MSRV issue
paulhauner Jun 7, 2022
d305f49
Fix failing network tests
paulhauner Jun 7, 2022
c3d04bd
Remove HeadSafetyStatus
paulhauner Jun 7, 2022
b7bee40
Remove unused error
paulhauner Jun 7, 2022
2e9a8c0
Fix compile errors in beacon chain tests
paulhauner Jun 7, 2022
5be6374
Simplify chain segment processing
paulhauner Jun 8, 2022
1bcf234
Remove some blocking methods
paulhauner Jun 8, 2022
7b7b356
Fix missing `!`
paulhauner Jun 8, 2022
2296643
Fix failing payload_invalidation tests
paulhauner Jun 10, 2022
a6a6aae
Fix store test
paulhauner Jun 10, 2022
a861777
Remove commented-out code
paulhauner Jun 10, 2022
93864b8
Fix weak subjectivity test
paulhauner Jun 10, 2022
ab4e1e8
Move EL update spawning
paulhauner Jun 10, 2022
1faf17a
Fix http_api compile error
paulhauner Jun 11, 2022
52bbd94
Fix compile error in client builder
paulhauner Jun 11, 2022
81d7fc7
Remove genesis alias workaround from EF tests
paulhauner Jun 11, 2022
cb8677c
Remove `block_on` from EL
paulhauner Jun 11, 2022
706e385
Remove block_on for blinded blocks in HTTP API
paulhauner Jun 11, 2022
67fd2a4
Disable rayon for fork choice tests
paulhauner Jun 14, 2022
de8482d
Simplify getting for active val count
paulhauner Jun 14, 2022
8f24eb1
Make block_on_dangerous respect exit, metrics
paulhauner Jun 14, 2022
1a3070f
Patch and unify status_message
paulhauner Jun 14, 2022
5cda3ee
Move recompute_head into canonical_head
paulhauner Jun 14, 2022
67ca5d7
Remove head_proposer_shuffling_decision_root
paulhauner Jun 14, 2022
ccdc74d
Arc-ify BeaconSnapshot
paulhauner Jun 15, 2022
be38daa
Spawn new task for after_finalization
paulhauner Jun 15, 2022
90730a7
Provide different state root to db migrator
paulhauner Jun 15, 2022
d84550f
Don't log crit when tokio stops block import
paulhauner Jun 15, 2022
0ab1b64
Add back warning for opt head
paulhauner Jun 15, 2022
4badadf
Remove debug formatting for roots
paulhauner Jun 15, 2022
98bed99
Raise gossip block log levels
paulhauner Jun 15, 2022
52cb170
Revert "Remove debug formatting for roots"
paulhauner Jun 15, 2022
6426347
Add weight logging
paulhauner Jun 15, 2022
1603b44
Drop txn_lock
paulhauner Jun 15, 2022
5b2f46a
Compute state root in spawned function
paulhauner Jun 15, 2022
7552f9a
Use state roots iter directly
paulhauner Jun 15, 2022
888b278
Avoid blocking async on canon head lock
paulhauner Jun 16, 2022
161c923
Add fast canonical head
paulhauner Jun 16, 2022
1a4bb67
Remove inconsistent head errors
paulhauner Jun 16, 2022
7f2db8e
Update fast head earlier
paulhauner Jun 16, 2022
1d67297
Ensure FFG checkpoints are consistent with head
paulhauner Jun 16, 2022
4ffdb41
Do timeout lock for beacon state metrics
paulhauner Jun 16, 2022
7199425
Use fast head in http_api
paulhauner Jun 16, 2022
7a44522
Use fast head in notifier
paulhauner Jun 16, 2022
611db3a
Split head and FC locks
paulhauner Jun 17, 2022
79aab62
Get make lint passing
paulhauner Jun 17, 2022
5d4ad4e
Tidy, add comments
paulhauner Jun 17, 2022
65ead81
Tidy comments
paulhauner Jun 17, 2022
7cc0d27
Switch to `Arc<Snapshot>` for `CachedHead`
paulhauner Jun 20, 2022
dbde4bf
Expose fork choice locks
paulhauner Jun 20, 2022
08082fb
Tidy
paulhauner Jun 20, 2022
82d8068
Fix test compile errors
paulhauner Jun 20, 2022
858db36
Update Cargo.lock
paulhauner Jun 20, 2022
b5043b9
Unify is_optimistic_candidate_block
paulhauner Jun 20, 2022
44a75e7
Fix flipped bool
paulhauner Jun 20, 2022
7c5ea7a
Revert changes to clippy.toml
paulhauner Jun 21, 2022
01e760f
Revert changes to beacon_chain Cargo.toml
paulhauner Jun 21, 2022
459c677
Refactor head accessor methods
paulhauner Jun 21, 2022
2905a9d
Fix broken store test
paulhauner Jun 21, 2022
fcbe53f
Fix state_advance_timer TODO
paulhauner Jun 21, 2022
0d8a9d8
Refactor `BeaconChain::best_slot`
paulhauner Jun 21, 2022
b5388ae
Fix conflict in `state_advance_timer`
paulhauner Jun 21, 2022
2b1bb42
Use blocking task for FC notifier tx
paulhauner Jun 21, 2022
57d62f1
Update opt sync error message
paulhauner Jun 21, 2022
9d73de2
Remove commented-out code from beacon_processor
paulhauner Jun 21, 2022
343aa37
Add comments to `TaskSpawner`
paulhauner Jun 21, 2022
6de54f1
Reduce duplicate code in sync_methods
paulhauner Jun 21, 2022
934a147
Add comment about val count caches
paulhauner Jun 21, 2022
9ca7d49
Update block_on_dangerous comments
paulhauner Jun 21, 2022
42af8db
Remove phantom block_efficiency file
paulhauner Jun 21, 2022
219327b
Remove parking lot from ef_tests
paulhauner Jun 21, 2022
836ac1c
Use rayon in ef_tests by default
paulhauner Jun 21, 2022
19870a8
Remove erroneous log for opt transition block
paulhauner Jun 22, 2022
6b3b2b7
Tidy
paulhauner Jun 22, 2022
2afe98d
Undo changes to `BeaconChain::import_block`
paulhauner Jun 22, 2022
f3ac736
Reduce diff for attestation production
paulhauner Jun 22, 2022
de9a72e
Reduce chain segment diff
paulhauner Jun 22, 2022
74f8e0b
Tidy
paulhauner Jun 22, 2022
b46088d
Tidy
paulhauner Jun 22, 2022
5f67350
Tidy
paulhauner Jun 22, 2022
733192a
Apply suggestions from code review
paulhauner Jun 22, 2022
acc9aac
Use fc write lock for restore
paulhauner Jun 23, 2022
011818f
Address review comments from @realbigsean
paulhauner Jun 23, 2022
91b877f
Squash-merge `nfd-2`
paulhauner Jun 28, 2022
49321ec
Merge pull request #4 from sigp/fc-refactor-nfd-2
paulhauner Jun 28, 2022
33d7305
Merge branch 'nfd-2' into fc-refactor
paulhauner Jun 28, 2022
d98041e
Fix trivial test compile errors
paulhauner Jun 28, 2022
9212770
Revert state_processing and types/beacon_state
paulhauner Jun 28, 2022
6764608
Add `JustificationAndFinalizationState`
paulhauner Jun 28, 2022
eb64294
Tidy, fix compile errors
paulhauner Jun 28, 2022
94557f2
uncomment ef tests
realbigsean Jun 28, 2022
1b59be9
add reorg test
realbigsean Jun 28, 2022
ab76e2c
Account for `state.get_block_root_at_epoch` errors
paulhauner Jun 28, 2022
060c3d1
Merge branch 'fc-refactor-participation-cache' of https://github.com/…
realbigsean Jun 28, 2022
af1623d
Remove participation_cache.rs
paulhauner Jun 28, 2022
d73b74c
Merge branch 'fc-refactor-participation-cache' of https://github.com/…
realbigsean Jun 28, 2022
de0a2bb
Remove mut ref
paulhauner Jun 29, 2022
24b4667
Use fork choice for block import finalization
paulhauner Jun 29, 2022
cbd8237
Fix failing gossip verification test
paulhauner Jun 29, 2022
aa44285
Ensure best justified is finalized descendent
paulhauner Jun 29, 2022
f57cbbb
remove n plus 2 test
realbigsean Jul 5, 2022
aff44e8
Add schema 10 -> 9 downgrade
realbigsean Jul 5, 2022
f073510
fix failing test
realbigsean Jul 5, 2022
d935728
Merge branch 'unstable' of https://github.com/sigp/lighthouse into re…
realbigsean Jul 5, 2022
6b71365
fix compile errors after merging
realbigsean Jul 5, 2022
d0f6f9e
add flag to enable unrealized vote counting
realbigsean Jul 7, 2022
1df5164
Merge branch 'unstable' of https://github.com/sigp/lighthouse into re…
realbigsean Jul 8, 2022
9951c2f
get tests passing
realbigsean Jul 8, 2022
b8ce0cb
Only count unrealized when we are syncing non-finalized chain segments
realbigsean Jul 8, 2022
c1a44c7
fix test
realbigsean Jul 10, 2022
dc6e836
fix tests
realbigsean Jul 10, 2022
9737b2b
delete commented out test
realbigsean Jul 10, 2022
e939bd4
copied on Result in unstable in our current msrv
realbigsean Jul 12, 2022
828d5bc
Merge branch 'unstable' of https://github.com/sigp/lighthouse into re…
realbigsean Jul 12, 2022
d4269a1
Update beacon_node/src/cli.rs
realbigsean Jul 13, 2022
5e512f7
Update consensus/fork_choice/src/fork_choice.rs
realbigsean Jul 13, 2022
8fbb9e7
Update consensus/state_processing/src/per_epoch_processing/justificat…
realbigsean Jul 13, 2022
3f9e6c3
Update consensus/state_processing/src/per_epoch_processing/altair/par…
realbigsean Jul 13, 2022
3c80207
Update testing/ef_tests/src/cases/fork_choice.rs
realbigsean Jul 13, 2022
e01fa88
Update testing/ef_tests/src/cases/fork_choice.rs
realbigsean Jul 13, 2022
b3ef232
only count unrealized in last block of chain in block replay
realbigsean Jul 13, 2022
0c6de63
cargo fmt
realbigsean Jul 13, 2022
8496857
cargo fmt
realbigsean Jul 13, 2022
ec06f03
Add `UpdateJustifiedCheckpointSlots`
paulhauner Jul 13, 2022
3e3b9e0
Add late-epoch optimisation
paulhauner Jul 13, 2022
89c27d0
iter
realbigsean Jul 13, 2022
04647be
fix compile error
realbigsean Jul 13, 2022
7265479
hide -> hidden
realbigsean Jul 14, 2022
58e8134
Merge branch 'unstable' of https://github.com/sigp/lighthouse into re…
realbigsean Jul 21, 2022
be4955e
lints
realbigsean Jul 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ use types::beacon_state::CloneConfig;
use types::*;

pub use crate::canonical_head::{CanonicalHead, CanonicalHeadRwLock};
pub use fork_choice::CountUnrealized;

pub type ForkChoiceError = fork_choice::Error<crate::ForkChoiceStoreError>;

Expand Down Expand Up @@ -1735,6 +1736,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.slot()?,
verified.indexed_attestation(),
AttestationFromBlock::False,
&self.spec,
)
.map_err(Into::into)
}
Expand Down Expand Up @@ -2215,6 +2217,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
pub async fn process_chain_segment(
self: &Arc<Self>,
chain_segment: Vec<Arc<SignedBeaconBlock<T::EthSpec>>>,
count_unrealized: CountUnrealized,
) -> ChainSegmentResult<T::EthSpec> {
let mut imported_blocks = 0;

Expand Down Expand Up @@ -2279,7 +2282,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

// Import the blocks into the chain.
for signature_verified_block in signature_verified_blocks {
match self.process_block(signature_verified_block).await {
match self
.process_block(signature_verified_block, count_unrealized)
.await
{
Ok(_) => imported_blocks += 1,
Err(error) => {
return ChainSegmentResult::Failed {
Expand Down Expand Up @@ -2363,6 +2369,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
pub async fn process_block<B: IntoExecutionPendingBlock<T>>(
self: &Arc<Self>,
unverified_block: B,
count_unrealized: CountUnrealized,
) -> Result<Hash256, BlockError<T::EthSpec>> {
// Start the Prometheus timer.
let _full_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_TIMES);
Expand All @@ -2378,7 +2385,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let import_block = async move {
let execution_pending = unverified_block.into_execution_pending_block(&chain)?;
chain
.import_execution_pending_block(execution_pending)
.import_execution_pending_block(execution_pending, count_unrealized)
.await
};

Expand Down Expand Up @@ -2436,6 +2443,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
async fn import_execution_pending_block(
self: Arc<Self>,
execution_pending_block: ExecutionPendingBlock<T>,
count_unrealized: CountUnrealized,
) -> Result<Hash256, BlockError<T::EthSpec>> {
let ExecutionPendingBlock {
block,
Expand Down Expand Up @@ -2494,6 +2502,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state,
confirmed_state_roots,
payload_verification_status,
count_unrealized,
)
},
"payload_verification_handle",
Expand All @@ -2515,6 +2524,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
mut state: BeaconState<T::EthSpec>,
confirmed_state_roots: Vec<Hash256>,
payload_verification_status: PayloadVerificationStatus,
count_unrealized: CountUnrealized,
) -> Result<Hash256, BlockError<T::EthSpec>> {
let current_slot = self.slot()?;
let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch());
Expand Down Expand Up @@ -2660,6 +2670,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&state,
payload_verification_status,
&self.spec,
count_unrealized.and(self.config.count_unrealized.into()),
)
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
}
Expand All @@ -2685,6 +2696,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
current_slot,
&indexed_attestation,
AttestationFromBlock::True,
&self.spec,
) {
Ok(()) => Ok(()),
// Ignore invalid attestations whilst importing attestations from a block. The
Expand Down
36 changes: 32 additions & 4 deletions beacon_node/beacon_chain/src/beacon_fork_choice_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ pub struct BeaconForkChoiceStore<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<
justified_checkpoint: Checkpoint,
justified_balances: Vec<u64>,
best_justified_checkpoint: Checkpoint,
unrealized_justified_checkpoint: Checkpoint,
unrealized_finalized_checkpoint: Checkpoint,
proposer_boost_root: Hash256,
_phantom: PhantomData<E>,
}
Expand Down Expand Up @@ -201,6 +203,8 @@ where
justified_balances: anchor_state.balances().clone().into(),
finalized_checkpoint,
best_justified_checkpoint: justified_checkpoint,
unrealized_justified_checkpoint: justified_checkpoint,
unrealized_finalized_checkpoint: finalized_checkpoint,
proposer_boost_root: Hash256::zero(),
_phantom: PhantomData,
}
Expand All @@ -216,6 +220,8 @@ where
justified_checkpoint: self.justified_checkpoint,
justified_balances: self.justified_balances.clone(),
best_justified_checkpoint: self.best_justified_checkpoint,
unrealized_justified_checkpoint: self.unrealized_justified_checkpoint,
unrealized_finalized_checkpoint: self.unrealized_finalized_checkpoint,
proposer_boost_root: self.proposer_boost_root,
}
}
Expand All @@ -233,6 +239,8 @@ where
justified_checkpoint: persisted.justified_checkpoint,
justified_balances: persisted.justified_balances,
best_justified_checkpoint: persisted.best_justified_checkpoint,
unrealized_justified_checkpoint: persisted.unrealized_justified_checkpoint,
unrealized_finalized_checkpoint: persisted.unrealized_finalized_checkpoint,
proposer_boost_root: persisted.proposer_boost_root,
_phantom: PhantomData,
})
Expand Down Expand Up @@ -280,6 +288,14 @@ where
&self.finalized_checkpoint
}

fn unrealized_justified_checkpoint(&self) -> &Checkpoint {
&self.unrealized_justified_checkpoint
}

fn unrealized_finalized_checkpoint(&self) -> &Checkpoint {
&self.unrealized_finalized_checkpoint
}

fn proposer_boost_root(&self) -> Hash256 {
self.proposer_boost_root
}
Expand Down Expand Up @@ -323,29 +339,41 @@ where
self.best_justified_checkpoint = checkpoint
}

fn set_unrealized_justified_checkpoint(&mut self, checkpoint: Checkpoint) {
self.unrealized_justified_checkpoint = checkpoint;
}

fn set_unrealized_finalized_checkpoint(&mut self, checkpoint: Checkpoint) {
self.unrealized_finalized_checkpoint = checkpoint;
}

fn set_proposer_boost_root(&mut self, proposer_boost_root: Hash256) {
self.proposer_boost_root = proposer_boost_root;
}
}

/// A container which allows persisting the `BeaconForkChoiceStore` to the on-disk database.
#[superstruct(
variants(V1, V7, V8),
variants(V1, V7, V8, V10),
variant_attributes(derive(Encode, Decode)),
no_enum
)]
pub struct PersistedForkChoiceStore {
#[superstruct(only(V1, V7))]
pub balances_cache: BalancesCacheV1,
#[superstruct(only(V8))]
#[superstruct(only(V8, V10))]
pub balances_cache: BalancesCacheV8,
pub time: Slot,
pub finalized_checkpoint: Checkpoint,
pub justified_checkpoint: Checkpoint,
pub justified_balances: Vec<u64>,
pub best_justified_checkpoint: Checkpoint,
#[superstruct(only(V7, V8))]
#[superstruct(only(V10))]
pub unrealized_justified_checkpoint: Checkpoint,
#[superstruct(only(V10))]
pub unrealized_finalized_checkpoint: Checkpoint,
#[superstruct(only(V7, V8, V10))]
pub proposer_boost_root: Hash256,
}

pub type PersistedForkChoiceStore = PersistedForkChoiceStoreV8;
pub type PersistedForkChoiceStore = PersistedForkChoiceStoreV10;
4 changes: 4 additions & 0 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,10 @@ fn check_block_against_finalized_slot<T: BeaconChainTypes>(
block_root: Hash256,
chain: &BeaconChain<T>,
) -> Result<(), BlockError<T::EthSpec>> {
// The finalized checkpoint is being read from fork choice, rather than the cached head.
//
// Fork choice has the most up-to-date view of finalization and there's no point importing a
// block which conflicts with the fork-choice view of finalization.
let finalized_slot = chain
.canonical_head
.cached_head()
Expand Down
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ where
store.clone(),
Some(current_slot),
&self.spec,
self.chain_config.count_unrealized.into(),
)?;
}

Expand Down
2 changes: 2 additions & 0 deletions beacon_node/beacon_chain/src/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct ChainConfig {
///
/// If set to 0 then block proposal will not wait for fork choice at all.
pub fork_choice_before_proposal_timeout_ms: u64,
pub count_unrealized: bool,
}

impl Default for ChainConfig {
Expand All @@ -35,6 +36,7 @@ impl Default for ChainConfig {
enable_lock_timeouts: true,
max_network_size: 10 * 1_048_576, // 10M
fork_choice_before_proposal_timeout_ms: DEFAULT_FORK_CHOICE_BEFORE_PROPOSAL_TIMEOUT,
count_unrealized: false,
}
}
}
16 changes: 14 additions & 2 deletions beacon_node/beacon_chain/src/fork_revert.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{BeaconForkChoiceStore, BeaconSnapshot};
use fork_choice::{ForkChoice, PayloadVerificationStatus};
use fork_choice::{CountUnrealized, ForkChoice, PayloadVerificationStatus};
use itertools::process_results;
use slog::{info, warn, Logger};
use state_processing::state_advance::complete_state_advance;
Expand Down Expand Up @@ -99,6 +99,7 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
store: Arc<HotColdDB<E, Hot, Cold>>,
current_slot: Option<Slot>,
spec: &ChainSpec,
count_unrealized_config: CountUnrealized,
) -> Result<ForkChoice<BeaconForkChoiceStore<E, Hot, Cold>, E>, String> {
// Fetch finalized block.
let finalized_checkpoint = head_state.finalized_checkpoint();
Expand Down Expand Up @@ -163,7 +164,8 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
.map_err(|e| format!("Error loading blocks to replay for fork choice: {:?}", e))?;

let mut state = finalized_snapshot.beacon_state;
for block in blocks {
let blocks_len = blocks.len();
for (i, block) in blocks.into_iter().enumerate() {
complete_state_advance(&mut state, None, block.slot(), spec)
.map_err(|e| format!("State advance failed: {:?}", e))?;

Expand All @@ -183,6 +185,15 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
// This scenario is so rare that it seems OK to double-verify some blocks.
let payload_verification_status = PayloadVerificationStatus::Optimistic;

// Because we are replaying a single chain of blocks, we only need to calculate unrealized
// justification for the last block in the chain.
let is_last_block = i + 1 == blocks_len;
let count_unrealized = if is_last_block {
count_unrealized_config
} else {
CountUnrealized::False
};

fork_choice
.on_block(
block.slot(),
Expand All @@ -193,6 +204,7 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
&state,
payload_verification_status,
spec,
count_unrealized,
)
.map_err(|e| format!("Error applying replayed block to fork choice: {:?}", e))?;
}
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod validator_pubkey_cache;

pub use self::beacon_chain::{
AttestationProcessingOutcome, BeaconChain, BeaconChainTypes, BeaconStore, ChainSegmentResult,
ForkChoiceError, ProduceBlockVerification, StateSkipConfig, WhenSlotSkipped,
CountUnrealized, ForkChoiceError, ProduceBlockVerification, StateSkipConfig, WhenSlotSkipped,
INVALID_JUSTIFIED_PAYLOAD_SHUTDOWN_REASON, MAXIMUM_GOSSIP_CLOCK_DISPARITY,
};
pub use self::beacon_snapshot::BeaconSnapshot;
Expand Down
10 changes: 7 additions & 3 deletions beacon_node/beacon_chain/src/persisted_fork_choice.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use crate::beacon_fork_choice_store::{
PersistedForkChoiceStoreV1, PersistedForkChoiceStoreV7, PersistedForkChoiceStoreV8,
PersistedForkChoiceStoreV1, PersistedForkChoiceStoreV10, PersistedForkChoiceStoreV7,
PersistedForkChoiceStoreV8,
};
use ssz::{Decode, Encode};
use ssz_derive::{Decode, Encode};
use store::{DBColumn, Error, StoreItem};
use superstruct::superstruct;

// If adding a new version you should update this type alias and fix the breakages.
pub type PersistedForkChoice = PersistedForkChoiceV8;
pub type PersistedForkChoice = PersistedForkChoiceV10;

#[superstruct(
variants(V1, V7, V8),
variants(V1, V7, V8, V10),
variant_attributes(derive(Encode, Decode)),
no_enum
)]
Expand All @@ -22,6 +23,8 @@ pub struct PersistedForkChoice {
pub fork_choice_store: PersistedForkChoiceStoreV7,
#[superstruct(only(V8))]
pub fork_choice_store: PersistedForkChoiceStoreV8,
#[superstruct(only(V10))]
pub fork_choice_store: PersistedForkChoiceStoreV10,
}

macro_rules! impl_store_item {
Expand All @@ -45,3 +48,4 @@ macro_rules! impl_store_item {
impl_store_item!(PersistedForkChoiceV1);
impl_store_item!(PersistedForkChoiceV7);
impl_store_item!(PersistedForkChoiceV8);
impl_store_item!(PersistedForkChoiceV10);
31 changes: 30 additions & 1 deletion beacon_node/beacon_chain/src/schema_change.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
//! Utilities for managing database schema changes.
mod migration_schema_v10;
mod migration_schema_v6;
mod migration_schema_v7;
mod migration_schema_v8;
mod migration_schema_v9;
mod types;

use crate::beacon_chain::{BeaconChainTypes, FORK_CHOICE_DB_KEY};
use crate::persisted_fork_choice::{PersistedForkChoiceV1, PersistedForkChoiceV7};
use crate::persisted_fork_choice::{
PersistedForkChoiceV1, PersistedForkChoiceV10, PersistedForkChoiceV7, PersistedForkChoiceV8,
};
use crate::types::ChainSpec;
use slog::{warn, Logger};
use std::path::Path;
Expand Down Expand Up @@ -130,6 +133,32 @@ pub fn migrate_schema<T: BeaconChainTypes>(
migration_schema_v9::downgrade_from_v9::<T>(db.clone(), log)?;
db.store_schema_version(to)
}
(SchemaVersion(9), SchemaVersion(10)) => {
let mut ops = vec![];
let fork_choice_opt = db.get_item::<PersistedForkChoiceV8>(&FORK_CHOICE_DB_KEY)?;
if let Some(fork_choice) = fork_choice_opt {
let updated_fork_choice = migration_schema_v10::update_fork_choice(fork_choice)?;

ops.push(updated_fork_choice.as_kv_store_op(FORK_CHOICE_DB_KEY));
}

db.store_schema_version_atomically(to, ops)?;

Ok(())
}
(SchemaVersion(10), SchemaVersion(9)) => {
let mut ops = vec![];
let fork_choice_opt = db.get_item::<PersistedForkChoiceV10>(&FORK_CHOICE_DB_KEY)?;
if let Some(fork_choice) = fork_choice_opt {
let updated_fork_choice = migration_schema_v10::downgrade_fork_choice(fork_choice)?;

ops.push(updated_fork_choice.as_kv_store_op(FORK_CHOICE_DB_KEY));
}

db.store_schema_version_atomically(to, ops)?;

Ok(())
}
// Anything else is an error.
(_, _) => Err(HotColdDBError::UnsupportedSchemaVersion {
target_version: to,
Expand Down
Loading