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] - Implement sync_committee_rewards API (per-validator reward) #3903

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
039173d
Added sync committee reward api blueprint
ensi321 Dec 1, 2022
e8ef118
Added sync committee reward api blueprint
ensi321 Dec 1, 2022
5bbdd46
lib.rs modification + add sync_committee_rewards
kevinbogner Dec 1, 2022
09705bd
change order
kevinbogner Dec 1, 2022
4cc09c6
add types and function to lib.rs
kevinbogner Dec 2, 2022
73ba07b
use declarations
kevinbogner Dec 2, 2022
6f3a7e6
change use declaration of BlockId
kevinbogner Dec 3, 2022
c3c4c33
get block, get state, convert slot, compute reward
kevinbogner Dec 3, 2022
a820451
Added sync_committee_attestation_rewards
ensi321 Dec 3, 2022
dda4c27
Partial implementation on sync committee reward api
ensi321 Dec 5, 2022
0b5d6ad
delete imports, change comments
kevinbogner Dec 7, 2022
4994c27
Updated logic to grab rewards
ensi321 Dec 8, 2022
29d1822
fix imports, add comment
kevinbogner Dec 9, 2022
afefce8
Changed fields to optional in sync_committee_attestation_rewards
ensi321 Dec 9, 2022
9cb4fb0
Fixed conflict
ensi321 Dec 9, 2022
552581b
Populate reward content in sync_committee_rewards
ensi321 Dec 10, 2022
7d5ae25
Handle case where validators is empty in sync_committee_rewards
ensi321 Dec 10, 2022
511f96b
Added debug messages
ensi321 Dec 10, 2022
46b3624
change data types + delete comment
kevinbogner Dec 12, 2022
37e8729
Handle case where participants are penalized
ensi321 Dec 14, 2022
aeaded7
add endpoint to common/eth2/src/lib.rs
kevinbogner Dec 15, 2022
9b29113
Rewrite logic for sync_committee_rewards
ensi321 Dec 15, 2022
04f9768
Rewrite logic for sync_committee_rewards
ensi321 Dec 15, 2022
93bdc09
Apply rewards to proposer balance
ensi321 Dec 16, 2022
662d723
Add sync committee rewards to beacon chain trait
ensi321 Dec 22, 2022
70a5cf3
Filter reward_payload by validators
ensi321 Dec 26, 2022
3a71579
Added initial ver of unit test for sync committee rewards
ensi321 Dec 27, 2022
3d3f71c
Use post state for sync committee rewards
ensi321 Dec 27, 2022
5627e5f
Added unit test for sync committee rewards
ensi321 Jan 7, 2023
992b56d
Clean up some of the code
ensi321 Jan 7, 2023
968fa24
Added log
ensi321 Jan 9, 2023
e29604b
Refactored naming
ensi321 Jan 9, 2023
0843f23
Polish code according to PR comments
ensi321 Jan 17, 2023
1f894aa
To be more specific with http status code it returns
ensi321 Jan 17, 2023
576fc80
Fix conflict
ensi321 Jan 17, 2023
fa4fe11
Format some of the code
ensi321 Jan 17, 2023
7a150e6
Fix lint error
ensi321 Jan 20, 2023
32bce39
Addressed comments
ensi321 Jan 23, 2023
1d746c0
Fix Clippy
michaelsproul Jan 24, 2023
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
Prev Previous commit
Next Next commit
Added initial ver of unit test for sync committee rewards
  • Loading branch information
ensi321 committed Dec 27, 2022
commit 3a715797b45ede6fb3f789812e1b744394778d1f
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ mod payload_invalidation;
mod store_tests;
mod sync_committee_verification;
mod tests;
mod rewards;
57 changes: 57 additions & 0 deletions beacon_node/beacon_chain/tests/rewards.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#![cfg(test)]

use lazy_static::lazy_static;
use beacon_chain::types::{
test_utils::TestRandom, BeaconState, BeaconStateAltair, BeaconStateBase, BeaconStateError,
ChainSpec, CloneConfig, Domain, Epoch, EthSpec, FixedVector, Hash256, Keypair, MainnetEthSpec,
MinimalEthSpec, RelativeEpoch, Slot
};
use eth2::lighthouse::SyncCommitteeAttestationReward;
use beacon_chain::test_utils::{EphemeralHarnessType, BeaconChainHarness, generate_deterministic_keypairs};

pub const SLOT: Slot = Slot::new(12);
lazy_static! {
static ref KEYPAIRS: Vec<Keypair> = generate_deterministic_keypairs(8);
}

fn get_harness<E: EthSpec>() -> BeaconChainHarness<EphemeralHarnessType<E>> {
let harness = BeaconChainHarness::builder(E::default())
.default_spec()
.keypairs(KEYPAIRS.to_vec())
.fresh_ephemeral_store()
.build();

let state = harness.get_current_state();
let target_slot = SLOT;

harness
.add_attested_blocks_at_slots(
state,
Hash256::zero(),
(1..target_slot.as_u64())
.map(Slot::new)
.collect::<Vec<_>>()
.as_slice(),
(0..12).collect::<Vec<_>>().as_slice(),
);

harness
}

#[tokio::test]
async fn test_sync_committee_rewards() {
let harness = get_harness::<MainnetEthSpec>();
let chain = harness.chain.clone();

let block = chain.block_at_slot(SLOT, beacon_chain::WhenSlotSkipped::None).unwrap().unwrap();

let mut state = harness.get_current_state();

let reward_payload = chain
.compute_sync_committee_rewards(block.message(), &mut state)
.unwrap();

assert_eq!(reward_payload.len(), 8);


}