mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Use latest state to pack attestation (#15113)
* Use latest state to pack attestation * Add a test to make sure it would have failed when using head state instead of latest state
This commit is contained in:
@@ -112,11 +112,7 @@ func (vs *Server) packAttestations(ctx context.Context, latestState state.Beacon
|
||||
|
||||
var sorted proposerAtts
|
||||
if postElectra {
|
||||
st, err := vs.HeadFetcher.HeadStateReadOnly(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sorted, err = deduped.sortOnChainAggregates(ctx, st)
|
||||
sorted, err = deduped.sortOnChainAggregates(ctx, latestState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -792,6 +792,44 @@ func TestPackAttestations_ElectraOnChainAggregates(t *testing.T) {
|
||||
require.Equal(t, uint64(21481408), got)
|
||||
require.Equal(t, primitives.Slot(1), atts[6].GetData().Slot)
|
||||
})
|
||||
|
||||
t.Run("use latest state", func(t *testing.T) {
|
||||
moreRecent := att(0b1100000, cb1, ðpb.AttestationData{
|
||||
Slot: 1,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte{'0'}, 32),
|
||||
})
|
||||
require.NoError(t, pool.SaveUnaggregatedAttestations([]ethpb.Att{moreRecent}))
|
||||
|
||||
copiedState := st.Copy()
|
||||
// Setting head state validator set to empty, but it shouldn't matter as pack attestation should be using latest state.
|
||||
require.NoError(t, copiedState.SetValidators([]*ethpb.Validator{}))
|
||||
s := &Server{
|
||||
AttPool: pool,
|
||||
HeadFetcher: &chainMock.ChainService{State: copiedState, MockHeadSlot: &headSlot},
|
||||
TimeFetcher: &chainMock.ChainService{Slot: &slot},
|
||||
}
|
||||
atts, err := s.packAttestations(ctx, st, params.BeaconConfig().SlotsPerEpoch)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 7, len(atts))
|
||||
|
||||
totalBalance, err := helpers.TotalActiveBalance(st)
|
||||
require.NoError(t, err)
|
||||
|
||||
// The reward numerator should be the same as the previous test.
|
||||
expected := []uint64{
|
||||
193332672,
|
||||
150369856,
|
||||
150369856,
|
||||
64444224,
|
||||
42962816,
|
||||
42962816,
|
||||
}
|
||||
for i, want := range expected {
|
||||
got, err := electra.GetProposerRewardNumerator(ctx, st, atts[i], totalBalance)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func sliceCast(atts []*ethpb.AttestationElectra) []ethpb.Att {
|
||||
|
||||
3
changelog/tt_3.md
Normal file
3
changelog/tt_3.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### Fixed
|
||||
|
||||
- Use latest state to pack attestation.
|
||||
Reference in New Issue
Block a user