Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
914bb1e
persist light client updates
eserilev Apr 2, 2024
c308768
update beacon chain to serve light client updates
eserilev Apr 2, 2024
e332b00
resolve todos
eserilev Apr 2, 2024
3a93933
cache best update
eserilev Apr 3, 2024
b9bdd88
extend cache parts
eserilev Apr 10, 2024
9671423
is better light client update
eserilev Apr 10, 2024
5861417
resolve merge conflict
eserilev Apr 10, 2024
6e0fa26
initial api changes
eserilev Apr 11, 2024
c8af8fb
add lc update db column
eserilev Apr 15, 2024
45a5d8d
fmt
eserilev Apr 16, 2024
2545655
added tests
eserilev Apr 28, 2024
3029f2c
add sim
eserilev Apr 28, 2024
fad083a
Merge branch 'unstable' of https://github.com/sigp/lighthouse into pe…
eserilev May 14, 2024
49a7e61
fix some weird issues with the simulator
eserilev May 15, 2024
00d4fd0
tests
eserilev May 27, 2024
4b8683c
Merge branch 'unstable' of https://github.com/sigp/lighthouse into pe…
eserilev May 27, 2024
6f12133
test changes
eserilev May 29, 2024
9464518
merge conflict
eserilev May 29, 2024
22e9201
testing
eserilev May 31, 2024
1946100
started work on ef tests and some code clean up
eserilev Jun 3, 2024
2b1e47d
update tests
eserilev Jun 4, 2024
211601c
linting
eserilev Jun 4, 2024
891d677
noop pre altair, were still failing on electra though
eserilev Jun 5, 2024
d729fea
allow for zeroed light client header
eserilev Jun 10, 2024
58f178a
Merge branch 'unstable' of https://github.com/sigp/lighthouse into pe…
eserilev Jun 10, 2024
fe2b43d
merge unstable
eserilev Jun 10, 2024
1774e63
remove unwraps
eserilev Jun 10, 2024
af9b20d
remove unwraps
eserilev Jun 10, 2024
d82226b
fetch bootstrap without always querying for state
eserilev Jun 11, 2024
ce765f3
storing bootstrap parts in db
eserilev Jun 12, 2024
4a9b088
mroe code cleanup
eserilev Jun 13, 2024
7a0fdae
test
eserilev Jun 17, 2024
93a97ea
prune sync committee branches from dropped chains
eserilev Jun 24, 2024
d8e6891
Update light_client_update.rs
dapplion Jun 25, 2024
bfd6ca2
merge unstable
eserilev Jun 25, 2024
fa7cd25
move functionality to helper methods
eserilev Jun 25, 2024
bb69c48
refactor is best update fn
eserilev Jun 25, 2024
fa50339
refactor is best update fn
eserilev Jun 25, 2024
89ae007
improve organization of light client server cache logic
eserilev Jun 25, 2024
7fcf032
fork diget calc, and only spawn as many blcoks as we need for the lc …
eserilev Jun 25, 2024
b4c5775
resovle merge conflict
eserilev Jun 25, 2024
0fdf544
add electra bootstrap logic, add logic to cache current sync committee
eserilev Jun 25, 2024
d983c3b
add latest sync committe branch cache
eserilev Jun 26, 2024
8bf1bc6
fetch lc update from the cache if it exists
eserilev Jun 26, 2024
f70b93e
fmt
eserilev Jun 26, 2024
eb19b0d
Fix beacon_chain tests
dapplion Jul 5, 2024
bcda61b
Add debug code to update ranking_order ef test
dapplion Jul 5, 2024
e8691db
Fix compare code
dapplion Jul 5, 2024
50a29c5
merge conflicts
eserilev Jul 26, 2024
194bf5a
merge conflict
eserilev Jul 29, 2024
6458ec9
add better error messaging
eserilev Jul 29, 2024
206a629
resolve merge conflicts
eserilev Aug 12, 2024
807ec80
remove lc update from basicsim
eserilev Aug 12, 2024
8c1f980
rename sync comittte variable and fix persist condition
eserilev Aug 13, 2024
8ef297b
refactor get_light_client_update logic
eserilev Aug 13, 2024
e75b84f
add better comments, return helpful error messages over http and rpc
eserilev Aug 13, 2024
de331f0
pruning canonical non checkpoint slots
eserilev Aug 14, 2024
35c5453
fix test
eserilev Aug 15, 2024
091bff1
rerun test
eserilev Aug 15, 2024
dddc5a8
update pruning logic, add tests
eserilev Aug 22, 2024
d5eab8c
fix tests
eserilev Aug 22, 2024
c42c580
fix imports
eserilev Aug 22, 2024
8686eb2
fmt
eserilev Aug 22, 2024
ea0e0c4
refactor db code
eserilev Aug 22, 2024
430b00b
Refactor db method
eserilev Aug 22, 2024
5646203
Refactor db method
eserilev Aug 22, 2024
a202eac
add additional comments
eserilev Aug 28, 2024
a62e3c8
Merge branch 'unstable' of https://github.com/sigp/lighthouse into pe…
eserilev Sep 5, 2024
f66aa7c
fix merge
eserilev Sep 5, 2024
b9c3f44
linting
eserilev Sep 5, 2024
d8822a0
merge conflict
eserilev Sep 6, 2024
82a57b5
prevent overflow
eserilev Sep 6, 2024
e141c80
enable lc server for http api tests
eserilev Sep 6, 2024
521d5f2
fix tests
eserilev Sep 9, 2024
1873484
remove prints
eserilev Sep 9, 2024
05b6426
remove warning
eserilev Sep 9, 2024
2221562
revert change
eserilev Sep 9, 2024
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
3 changes: 2 additions & 1 deletion beacon_node/beacon_chain/src/light_client_server_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
self.get_sync_committee_branch(store, block_root)?
else {
return Err(BeaconChainError::LightClientBootstrapError(format!(
"Sync committee branch for block root {block_root} not found"
"Sync committee branch for block root {:?} not found",
block_root
)));
};

Expand Down
149 changes: 140 additions & 9 deletions beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ pub enum SyncCommitteeStrategy {
NoValidators,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LightClientStrategy {
Enabled,
Disabled,
}

/// Indicates whether the `BeaconChainHarness` should use the `state.current_sync_committee` or
/// `state.next_sync_committee` when creating sync messages or contributions.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -2215,6 +2221,96 @@ where
.await
}

fn update_light_client_server_cache(
&self,
state: &BeaconState<E>,
slot: Slot,
block_root: Hash256,
) {
let fork_name = state.fork_name(&self.spec).unwrap();
if !fork_name.altair_enabled() {
return;
}

let log = self.logger();
let contributions =
self.make_sync_contributions(state, block_root, slot, RelativeSyncCommittee::Current);

for (_, contribution_and_proof) in contributions {
let Some(contribution_and_proof) = contribution_and_proof else {
continue;
};
let contribution = contribution_and_proof.message.contribution;
self.chain
.op_pool
.insert_sync_contribution(contribution.clone())
.unwrap();
self.chain
.op_pool
.insert_sync_contribution(contribution)
.unwrap();
}

let Some(sync_aggregate) = self.chain.op_pool.get_sync_aggregate(state).unwrap() else {
return;
};

let _ = self
.chain
.light_client_server_cache
.recompute_and_cache_updates(
self.chain.store.clone(),
slot,
&block_root,
&sync_aggregate,
log,
&self.spec,
);
}

pub async fn add_attested_blocks_at_slots_with_lc_data(
&self,
mut state: BeaconState<E>,
state_root: Hash256,
slots: &[Slot],
validators: &[usize],
mut latest_block_hash: Option<SignedBeaconBlockHash>,
sync_committee_strategy: SyncCommitteeStrategy,
) -> AddBlocksResult<E> {
assert!(
slots.windows(2).all(|w| w[0] <= w[1]),
"Slots have to be sorted"
); // slice.is_sorted() isn't stabilized at the moment of writing this
let mut block_hash_from_slot: HashMap<Slot, SignedBeaconBlockHash> = HashMap::new();
let mut state_hash_from_slot: HashMap<Slot, BeaconStateHash> = HashMap::new();
for slot in slots {
let (block_hash, new_state) = self
.add_attested_block_at_slot_with_sync(
*slot,
state,
state_root,
validators,
sync_committee_strategy,
)
.await
.unwrap();

state = new_state;

self.update_light_client_server_cache(&state, *slot, block_hash.into());

block_hash_from_slot.insert(*slot, block_hash);
state_hash_from_slot.insert(*slot, state.canonical_root().unwrap().into());
latest_block_hash = Some(block_hash);
}
(
block_hash_from_slot,
state_hash_from_slot,
latest_block_hash.unwrap(),
state,
)
}

async fn add_attested_blocks_at_slots_given_lbh(
&self,
mut state: BeaconState<E>,
Expand All @@ -2241,7 +2337,9 @@ where
)
.await
.unwrap();

state = new_state;

block_hash_from_slot.insert(*slot, block_hash);
state_hash_from_slot.insert(*slot, state.canonical_root().unwrap().into());
latest_block_hash = Some(block_hash);
Expand Down Expand Up @@ -2450,6 +2548,23 @@ where
block_strategy,
attestation_strategy,
SyncCommitteeStrategy::NoValidators,
LightClientStrategy::Disabled,
)
.await
}

pub async fn extend_chain_with_light_client_data(
&self,
num_blocks: usize,
block_strategy: BlockStrategy,
attestation_strategy: AttestationStrategy,
) -> Hash256 {
self.extend_chain_with_sync(
num_blocks,
block_strategy,
attestation_strategy,
SyncCommitteeStrategy::NoValidators,
LightClientStrategy::Enabled,
)
.await
}
Expand All @@ -2460,6 +2575,7 @@ where
block_strategy: BlockStrategy,
attestation_strategy: AttestationStrategy,
sync_committee_strategy: SyncCommitteeStrategy,
light_client_strategy: LightClientStrategy,
) -> Hash256 {
let (mut state, slots) = match block_strategy {
BlockStrategy::OnCanonicalHead => {
Expand Down Expand Up @@ -2491,15 +2607,30 @@ where
};

let state_root = state.update_tree_hash_cache().unwrap();
let (_, _, last_produced_block_hash, _) = self
.add_attested_blocks_at_slots_with_sync(
state,
state_root,
&slots,
&validators,
sync_committee_strategy,
)
.await;
let (_, _, last_produced_block_hash, _) = match light_client_strategy {
LightClientStrategy::Enabled => {
self.add_attested_blocks_at_slots_with_lc_data(
state,
state_root,
&slots,
&validators,
None,
sync_committee_strategy,
)
.await
}
LightClientStrategy::Disabled => {
self.add_attested_blocks_at_slots_with_sync(
state,
state_root,
&slots,
&validators,
sync_committee_strategy,
)
.await
}
};

last_produced_block_hash.into()
}

Expand Down
Loading