Remove signed block requirement from no-verify functions (#13314)

* removing fake wrappers

* fixing conficts and missed tests

* fixing more conflicts

* addressing missed unit test

* fixing nogo error

* fixing more unit tests

* fixing more tests
This commit is contained in:
james-prysm
2023-12-12 14:18:40 -06:00
committed by GitHub
parent 8387088a52
commit b19d24c581
26 changed files with 103 additions and 127 deletions

View File

@@ -24,12 +24,12 @@ import (
func ProcessAttestationsNoVerifySignature(
ctx context.Context,
beaconState state.BeaconState,
b interfaces.ReadOnlySignedBeaconBlock,
b interfaces.ReadOnlyBeaconBlock,
) (state.BeaconState, error) {
if err := consensusblocks.BeaconBlockIsNil(b); err != nil {
return nil, err
if b == nil || b.IsNil() {
return nil, consensusblocks.ErrNilBeaconBlock
}
body := b.Block().Body()
body := b.Body()
totalBalance, err := helpers.TotalActiveBalance(beaconState)
if err != nil {
return nil, err

View File

@@ -50,7 +50,7 @@ func TestProcessAttestations_InclusionDelayFailure(t *testing.T) {
)
wsb, err := blocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb.Block())
require.ErrorContains(t, want, err)
}
@@ -81,7 +81,7 @@ func TestProcessAttestations_NeitherCurrentNorPrevEpoch(t *testing.T) {
)
wsb, err := blocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb.Block())
require.ErrorContains(t, want, err)
}
@@ -110,13 +110,13 @@ func TestProcessAttestations_CurrentEpochFFGDataMismatches(t *testing.T) {
want := "source check point not equal to current justified checkpoint"
wsb, err := blocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb.Block())
require.ErrorContains(t, want, err)
b.Block.Body.Attestations[0].Data.Source.Epoch = time.CurrentEpoch(beaconState)
b.Block.Body.Attestations[0].Data.Source.Root = []byte{}
wsb, err = blocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb.Block())
require.ErrorContains(t, want, err)
}
@@ -151,14 +151,14 @@ func TestProcessAttestations_PrevEpochFFGDataMismatches(t *testing.T) {
want := "source check point not equal to previous justified checkpoint"
wsb, err := blocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb.Block())
require.ErrorContains(t, want, err)
b.Block.Body.Attestations[0].Data.Source.Epoch = time.PrevEpoch(beaconState)
b.Block.Body.Attestations[0].Data.Target.Epoch = time.PrevEpoch(beaconState)
b.Block.Body.Attestations[0].Data.Source.Root = []byte{}
wsb, err = blocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb.Block())
require.ErrorContains(t, want, err)
}
@@ -190,7 +190,7 @@ func TestProcessAttestations_InvalidAggregationBitsLength(t *testing.T) {
expected := "failed to verify aggregation bitfield: wanted participants bitfield length 3, got: 4"
wsb, err := blocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb.Block())
require.ErrorContains(t, expected, err)
}
@@ -234,7 +234,7 @@ func TestProcessAttestations_OK(t *testing.T) {
require.NoError(t, err)
wsb, err := blocks.NewSignedBeaconBlock(block)
require.NoError(t, err)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb)
_, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb.Block())
require.NoError(t, err)
}
@@ -426,7 +426,7 @@ func TestFuzzProcessAttestationsNoVerify_10000(t *testing.T) {
}
wsb, err := blocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
r, err := altair.ProcessAttestationsNoVerifySignature(context.Background(), s, wsb)
r, err := altair.ProcessAttestationsNoVerifySignature(context.Background(), s, wsb.Block())
if err != nil && r != nil {
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, s, b)
}

View File

@@ -25,12 +25,12 @@ import (
func ProcessAttestationsNoVerifySignature(
ctx context.Context,
beaconState state.BeaconState,
b interfaces.ReadOnlySignedBeaconBlock,
b interfaces.ReadOnlyBeaconBlock,
) (state.BeaconState, error) {
if err := blocks.BeaconBlockIsNil(b); err != nil {
return nil, err
if b == nil || b.IsNil() {
return nil, blocks.ErrNilBeaconBlock
}
body := b.Block().Body()
body := b.Body()
var err error
for idx, att := range body.Attestations() {
beaconState, err = ProcessAttestationNoVerifySignature(ctx, beaconState, att)

View File

@@ -275,7 +275,7 @@ func TestFuzzProcessAttestationsNoVerify_10000(t *testing.T) {
}
wsb, err := blocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
r, err := ProcessAttestationsNoVerifySignature(ctx, s, wsb)
r, err := ProcessAttestationsNoVerifySignature(ctx, s, wsb.Block())
if err != nil && r != nil {
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b)
}

View File

@@ -28,11 +28,11 @@ const executionToBLSPadding = 12
// signature set.
func ProcessBLSToExecutionChanges(
st state.BeaconState,
signed interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
if signed.Version() < version.Capella {
b interfaces.ReadOnlyBeaconBlock) (state.BeaconState, error) {
if b.Version() < version.Capella {
return st, nil
}
changes, err := signed.Block().Body().BLSToExecutionChanges()
changes, err := b.Body().BLSToExecutionChanges()
if err != nil {
return nil, errors.Wrap(err, "could not get BLSToExecutionChanges")
}

View File

@@ -1134,12 +1134,9 @@ func TestProcessBLSToExecutionChanges(t *testing.T) {
bpb := &ethpb.BeaconBlockCapella{
Body: body,
}
sbpb := &ethpb.SignedBeaconBlockCapella{
Block: bpb,
}
signed, err := consensusblocks.NewSignedBeaconBlock(sbpb)
bb, err := consensusblocks.NewBeaconBlock(bpb)
require.NoError(t, err)
st, err = blocks.ProcessBLSToExecutionChanges(st, signed)
st, err = blocks.ProcessBLSToExecutionChanges(st, bb)
require.NoError(t, err)
vals := st.Validators()
for _, val := range vals {

View File

@@ -324,11 +324,11 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta
}
// VerifyOperationLengths verifies that block operation lengths are valid.
func VerifyOperationLengths(_ context.Context, state state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
if err := blocks.BeaconBlockIsNil(b); err != nil {
return nil, err
func VerifyOperationLengths(_ context.Context, state state.BeaconState, b interfaces.ReadOnlyBeaconBlock) (state.BeaconState, error) {
if b == nil || b.IsNil() {
return nil, blocks.ErrNilBeaconBlock
}
body := b.Block().Body()
body := b.Body()
if uint64(len(body.ProposerSlashings())) > params.BeaconConfig().MaxProposerSlashings {
return nil, fmt.Errorf(

View File

@@ -103,18 +103,18 @@ func TestFuzzprocessOperationsNoVerify_1000(t *testing.T) {
ctx := context.Background()
state, err := state_native.InitializeFromProtoUnsafePhase0(&ethpb.BeaconState{})
require.NoError(t, err)
bb := &ethpb.SignedBeaconBlock{}
bb := &ethpb.BeaconBlock{}
fuzzer := fuzz.NewWithSeed(0)
fuzzer.NilChance(0.1)
for i := 0; i < 1000; i++ {
fuzzer.Fuzz(state)
fuzzer.Fuzz(bb)
if bb.Block == nil || bb.Block.Body == nil {
if bb.Body == nil {
continue
}
wsb, err := blocks.NewSignedBeaconBlock(bb)
wb, err := blocks.NewBeaconBlock(bb)
require.NoError(t, err)
s, err := ProcessOperationsNoVerifyAttsSigs(ctx, state, wsb)
s, err := ProcessOperationsNoVerifyAttsSigs(ctx, state, wb)
if err != nil && s != nil {
t.Fatalf("state should be nil on err. found: %v on error: %v for block body: %v", s, err, bb)
}
@@ -126,18 +126,18 @@ func TestFuzzverifyOperationLengths_10000(t *testing.T) {
defer SkipSlotCache.Enable()
state, err := state_native.InitializeFromProtoUnsafePhase0(&ethpb.BeaconState{})
require.NoError(t, err)
bb := &ethpb.SignedBeaconBlock{}
bb := &ethpb.BeaconBlock{}
fuzzer := fuzz.NewWithSeed(0)
fuzzer.NilChance(0.1)
for i := 0; i < 10000; i++ {
fuzzer.Fuzz(state)
fuzzer.Fuzz(bb)
if bb.Block == nil || bb.Block.Body == nil {
if bb.Body == nil {
continue
}
wsb, err := blocks.NewSignedBeaconBlock(bb)
wb, err := blocks.NewBeaconBlock(bb)
require.NoError(t, err)
_, err = VerifyOperationLengths(context.Background(), state, wsb)
_, err = VerifyOperationLengths(context.Background(), state, wb)
_ = err
}
}

View File

@@ -239,26 +239,26 @@ func ProcessBlockNoVerifyAnySig(
func ProcessOperationsNoVerifyAttsSigs(
ctx context.Context,
state state.BeaconState,
signedBeaconBlock interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
beaconBlock interfaces.ReadOnlyBeaconBlock) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessOperationsNoVerifyAttsSigs")
defer span.End()
if err := blocks.BeaconBlockIsNil(signedBeaconBlock); err != nil {
return nil, err
if beaconBlock == nil || beaconBlock.IsNil() {
return nil, blocks.ErrNilBeaconBlock
}
if _, err := VerifyOperationLengths(ctx, state, signedBeaconBlock); err != nil {
if _, err := VerifyOperationLengths(ctx, state, beaconBlock); err != nil {
return nil, errors.Wrap(err, "could not verify operation lengths")
}
var err error
switch signedBeaconBlock.Version() {
switch beaconBlock.Version() {
case version.Phase0:
state, err = phase0Operations(ctx, state, signedBeaconBlock)
state, err = phase0Operations(ctx, state, beaconBlock)
if err != nil {
return nil, err
}
case version.Altair, version.Bellatrix, version.Capella, version.Deneb:
state, err = altairOperations(ctx, state, signedBeaconBlock)
state, err = altairOperations(ctx, state, beaconBlock)
if err != nil {
return nil, err
}
@@ -342,7 +342,7 @@ func ProcessBlockForStateRoot(
return nil, errors.Wrap(err, "could not process eth1 data")
}
state, err = ProcessOperationsNoVerifyAttsSigs(ctx, state, signed)
state, err = ProcessOperationsNoVerifyAttsSigs(ctx, state, signed.Block())
if err != nil {
tracing.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process block operation")
@@ -382,48 +382,48 @@ func VerifyBlobCommitmentCount(blk interfaces.ReadOnlyBeaconBlock) error {
func altairOperations(
ctx context.Context,
st state.BeaconState,
signedBeaconBlock interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
st, err := b.ProcessProposerSlashings(ctx, st, signedBeaconBlock.Block().Body().ProposerSlashings(), v.SlashValidator)
beaconBlock interfaces.ReadOnlyBeaconBlock) (state.BeaconState, error) {
st, err := b.ProcessProposerSlashings(ctx, st, beaconBlock.Body().ProposerSlashings(), v.SlashValidator)
if err != nil {
return nil, errors.Wrap(err, "could not process altair proposer slashing")
}
st, err = b.ProcessAttesterSlashings(ctx, st, signedBeaconBlock.Block().Body().AttesterSlashings(), v.SlashValidator)
st, err = b.ProcessAttesterSlashings(ctx, st, beaconBlock.Body().AttesterSlashings(), v.SlashValidator)
if err != nil {
return nil, errors.Wrap(err, "could not process altair attester slashing")
}
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, signedBeaconBlock)
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, beaconBlock)
if err != nil {
return nil, errors.Wrap(err, "could not process altair attestation")
}
if _, err := altair.ProcessDeposits(ctx, st, signedBeaconBlock.Block().Body().Deposits()); err != nil {
if _, err := altair.ProcessDeposits(ctx, st, beaconBlock.Body().Deposits()); err != nil {
return nil, errors.Wrap(err, "could not process altair deposit")
}
st, err = b.ProcessVoluntaryExits(ctx, st, signedBeaconBlock.Block().Body().VoluntaryExits())
st, err = b.ProcessVoluntaryExits(ctx, st, beaconBlock.Body().VoluntaryExits())
if err != nil {
return nil, errors.Wrap(err, "could not process voluntary exits")
}
return b.ProcessBLSToExecutionChanges(st, signedBeaconBlock)
return b.ProcessBLSToExecutionChanges(st, beaconBlock)
}
// This calls phase 0 block operations.
func phase0Operations(
ctx context.Context,
st state.BeaconState,
signedBeaconBlock interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
st, err := b.ProcessProposerSlashings(ctx, st, signedBeaconBlock.Block().Body().ProposerSlashings(), v.SlashValidator)
beaconBlock interfaces.ReadOnlyBeaconBlock) (state.BeaconState, error) {
st, err := b.ProcessProposerSlashings(ctx, st, beaconBlock.Body().ProposerSlashings(), v.SlashValidator)
if err != nil {
return nil, errors.Wrap(err, "could not process block proposer slashings")
}
st, err = b.ProcessAttesterSlashings(ctx, st, signedBeaconBlock.Block().Body().AttesterSlashings(), v.SlashValidator)
st, err = b.ProcessAttesterSlashings(ctx, st, beaconBlock.Body().AttesterSlashings(), v.SlashValidator)
if err != nil {
return nil, errors.Wrap(err, "could not process block attester slashings")
}
st, err = b.ProcessAttestationsNoVerifySignature(ctx, st, signedBeaconBlock)
st, err = b.ProcessAttestationsNoVerifySignature(ctx, st, beaconBlock)
if err != nil {
return nil, errors.Wrap(err, "could not process block attestations")
}
if _, err := b.ProcessDeposits(ctx, st, signedBeaconBlock.Block().Body().Deposits()); err != nil {
if _, err := b.ProcessDeposits(ctx, st, beaconBlock.Body().Deposits()); err != nil {
return nil, errors.Wrap(err, "could not process deposits")
}
return b.ProcessVoluntaryExits(ctx, st, signedBeaconBlock.Block().Body().VoluntaryExits())
return b.ProcessVoluntaryExits(ctx, st, beaconBlock.Body().VoluntaryExits())
}

View File

@@ -171,7 +171,7 @@ func TestProcessOperationsNoVerifyAttsSigs_OK(t *testing.T) {
require.NoError(t, err)
beaconState, err = transition.ProcessSlots(context.Background(), beaconState, wsb.Block().Slot())
require.NoError(t, err)
_, err = transition.ProcessOperationsNoVerifyAttsSigs(context.Background(), beaconState, wsb)
_, err = transition.ProcessOperationsNoVerifyAttsSigs(context.Background(), beaconState, wsb.Block())
require.NoError(t, err)
}
@@ -181,7 +181,7 @@ func TestProcessOperationsNoVerifyAttsSigsBellatrix_OK(t *testing.T) {
require.NoError(t, err)
beaconState, err = transition.ProcessSlots(context.Background(), beaconState, wsb.Block().Slot())
require.NoError(t, err)
_, err = transition.ProcessOperationsNoVerifyAttsSigs(context.Background(), beaconState, wsb)
_, err = transition.ProcessOperationsNoVerifyAttsSigs(context.Background(), beaconState, wsb.Block())
require.NoError(t, err)
}
@@ -191,7 +191,7 @@ func TestProcessOperationsNoVerifyAttsSigsCapella_OK(t *testing.T) {
require.NoError(t, err)
beaconState, err = transition.ProcessSlots(context.Background(), beaconState, wsb.Block().Slot())
require.NoError(t, err)
_, err = transition.ProcessOperationsNoVerifyAttsSigs(context.Background(), beaconState, wsb)
_, err = transition.ProcessOperationsNoVerifyAttsSigs(context.Background(), beaconState, wsb.Block())
require.NoError(t, err)
}

View File

@@ -191,7 +191,7 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
require.NoError(t, beaconState.AppendCurrentEpochAttestations(&ethpb.PendingAttestation{}))
wsb, err := consensusblocks.NewSignedBeaconBlock(block)
require.NoError(t, err)
_, err = transition.VerifyOperationLengths(context.Background(), beaconState, wsb)
_, err = transition.VerifyOperationLengths(context.Background(), beaconState, wsb.Block())
wanted := "number of voluntary exits (17) in block body exceeds allowed threshold of 16"
assert.ErrorContains(t, wanted, err)
}
@@ -414,7 +414,7 @@ func TestProcessBlock_OverMaxProposerSlashings(t *testing.T) {
require.NoError(t, err)
wsb, err := consensusblocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb.Block())
assert.ErrorContains(t, want, err)
}
@@ -433,7 +433,7 @@ func TestProcessBlock_OverMaxAttesterSlashings(t *testing.T) {
require.NoError(t, err)
wsb, err := consensusblocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb.Block())
assert.ErrorContains(t, want, err)
}
@@ -451,7 +451,7 @@ func TestProcessBlock_OverMaxAttestations(t *testing.T) {
require.NoError(t, err)
wsb, err := consensusblocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb.Block())
assert.ErrorContains(t, want, err)
}
@@ -470,7 +470,7 @@ func TestProcessBlock_OverMaxVoluntaryExits(t *testing.T) {
require.NoError(t, err)
wsb, err := consensusblocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb.Block())
assert.ErrorContains(t, want, err)
}
@@ -492,7 +492,7 @@ func TestProcessBlock_IncorrectDeposits(t *testing.T) {
s.Eth1Data().DepositCount-s.Eth1DepositIndex(), len(b.Block.Body.Deposits))
wsb, err := consensusblocks.NewSignedBeaconBlock(b)
require.NoError(t, err)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb)
_, err = transition.VerifyOperationLengths(context.Background(), s, wsb.Block())
assert.ErrorContains(t, want, err)
}

View File

@@ -22,6 +22,7 @@ go_library(
"//beacon-chain/state/stategen:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//network/httputil:go_default_library",

View File

@@ -47,7 +47,7 @@ func (s *Server) BlockRewards(w http.ResponseWriter, r *http.Request) {
httputil.HandleError(w, "Could not get block root: "+err.Error(), http.StatusInternalServerError)
return
}
blockRewards, httpError := s.BlockRewardFetcher.GetBlockRewardsData(ctx, blk)
blockRewards, httpError := s.BlockRewardFetcher.GetBlockRewardsData(ctx, blk.Block())
if httpError != nil {
httputil.WriteError(w, httpError)
return
@@ -120,7 +120,7 @@ func (s *Server) SyncCommitteeRewards(w http.ResponseWriter, r *http.Request) {
return
}
st, httpErr := s.BlockRewardFetcher.GetStateForRewards(ctx, blk)
st, httpErr := s.BlockRewardFetcher.GetStateForRewards(ctx, blk.Block())
if httpErr != nil {
httputil.WriteError(w, httpErr)
return

View File

@@ -10,14 +10,15 @@ import (
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/validators"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/stategen"
consensusblocks "github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v4/network/httputil"
)
// BlockRewardsFetcher is a interface that provides access to reward related responses
type BlockRewardsFetcher interface {
GetBlockRewardsData(context.Context, interfaces.ReadOnlySignedBeaconBlock) (*BlockRewards, *httputil.DefaultErrorJson)
GetStateForRewards(context.Context, interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, *httputil.DefaultErrorJson)
GetBlockRewardsData(context.Context, interfaces.ReadOnlyBeaconBlock) (*BlockRewards, *httputil.DefaultErrorJson)
GetStateForRewards(context.Context, interfaces.ReadOnlyBeaconBlock) (state.BeaconState, *httputil.DefaultErrorJson)
}
// BlockRewardService implements BlockRewardsFetcher and can be declared to access the underlying functions
@@ -26,13 +27,20 @@ type BlockRewardService struct {
}
// GetBlockRewardsData returns the BlockRewards Object which is used for the BlockRewardsResponse and ProduceBlockV3
func (rs *BlockRewardService) GetBlockRewardsData(ctx context.Context, blk interfaces.ReadOnlySignedBeaconBlock) (*BlockRewards, *httputil.DefaultErrorJson) {
func (rs *BlockRewardService) GetBlockRewardsData(ctx context.Context, blk interfaces.ReadOnlyBeaconBlock) (*BlockRewards, *httputil.DefaultErrorJson) {
if blk == nil || blk.IsNil() {
return nil, &httputil.DefaultErrorJson{
Message: consensusblocks.ErrNilBeaconBlock.Error(),
Code: http.StatusInternalServerError,
}
}
st, httpErr := rs.GetStateForRewards(ctx, blk)
if httpErr != nil {
return nil, httpErr
}
proposerIndex := blk.Block().ProposerIndex()
proposerIndex := blk.ProposerIndex()
initBalance, err := st.BalanceAtIndex(proposerIndex)
if err != nil {
return nil, &httputil.DefaultErrorJson{
@@ -54,7 +62,7 @@ func (rs *BlockRewardService) GetBlockRewardsData(ctx context.Context, blk inter
Code: http.StatusInternalServerError,
}
}
st, err = coreblocks.ProcessAttesterSlashings(ctx, st, blk.Block().Body().AttesterSlashings(), validators.SlashValidator)
st, err = coreblocks.ProcessAttesterSlashings(ctx, st, blk.Body().AttesterSlashings(), validators.SlashValidator)
if err != nil {
return nil, &httputil.DefaultErrorJson{
Message: "Could not get attester slashing rewards: " + err.Error(),
@@ -68,7 +76,7 @@ func (rs *BlockRewardService) GetBlockRewardsData(ctx context.Context, blk inter
Code: http.StatusInternalServerError,
}
}
st, err = coreblocks.ProcessProposerSlashings(ctx, st, blk.Block().Body().ProposerSlashings(), validators.SlashValidator)
st, err = coreblocks.ProcessProposerSlashings(ctx, st, blk.Body().ProposerSlashings(), validators.SlashValidator)
if err != nil {
return nil, &httputil.DefaultErrorJson{
Message: "Could not get proposer slashing rewards: " + err.Error(),
@@ -82,7 +90,7 @@ func (rs *BlockRewardService) GetBlockRewardsData(ctx context.Context, blk inter
Code: http.StatusInternalServerError,
}
}
sa, err := blk.Block().Body().SyncAggregate()
sa, err := blk.Body().SyncAggregate()
if err != nil {
return nil, &httputil.DefaultErrorJson{
Message: "Could not get sync aggregate: " + err.Error(),
@@ -109,11 +117,11 @@ func (rs *BlockRewardService) GetBlockRewardsData(ctx context.Context, blk inter
}
// GetStateForRewards returns the state replayed up to the block's slot
func (rs *BlockRewardService) GetStateForRewards(ctx context.Context, blk interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, *httputil.DefaultErrorJson) {
func (rs *BlockRewardService) GetStateForRewards(ctx context.Context, blk interfaces.ReadOnlyBeaconBlock) (state.BeaconState, *httputil.DefaultErrorJson) {
// We want to run several block processing functions that update the proposer's balance.
// This will allow us to calculate proposer rewards for each operation (atts, slashings etc).
// To do this, we replay the state up to the block's slot, but before processing the block.
st, err := rs.Replayer.ReplayerForSlot(blk.Block().Slot()-1).ReplayToSlot(ctx, blk.Block().Slot())
st, err := rs.Replayer.ReplayerForSlot(blk.Slot()-1).ReplayToSlot(ctx, blk.Slot())
if err != nil {
return nil, &httputil.DefaultErrorJson{
Message: "Could not get state: " + err.Error(),

View File

@@ -15,14 +15,14 @@ type MockBlockRewardFetcher struct {
State state.BeaconState
}
func (m *MockBlockRewardFetcher) GetBlockRewardsData(_ context.Context, _ interfaces.ReadOnlySignedBeaconBlock) (*rewards.BlockRewards, *httputil.DefaultErrorJson) {
func (m *MockBlockRewardFetcher) GetBlockRewardsData(_ context.Context, _ interfaces.ReadOnlyBeaconBlock) (*rewards.BlockRewards, *httputil.DefaultErrorJson) {
if m.Error != nil {
return nil, m.Error
}
return m.Rewards, nil
}
func (m *MockBlockRewardFetcher) GetStateForRewards(_ context.Context, _ interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, *httputil.DefaultErrorJson) {
func (m *MockBlockRewardFetcher) GetStateForRewards(_ context.Context, _ interfaces.ReadOnlyBeaconBlock) (state.BeaconState, *httputil.DefaultErrorJson) {
if m.Error != nil {
return nil, m.Error
}

View File

@@ -34,7 +34,6 @@ go_library(
"//config/params:go_default_library",
"//consensus-types:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//consensus-types/validator:go_default_library",
"//encoding/bytesutil:go_default_library",

View File

@@ -13,7 +13,6 @@ import (
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared"
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v4/network/httputil"
@@ -277,44 +276,19 @@ func (s *Server) produceBlockV3(ctx context.Context, w http.ResponseWriter, r *h
}
func getConsensusBlockValue(ctx context.Context, blockRewardsFetcher rewards.BlockRewardsFetcher, i interface{} /* block as argument */) (string, *httputil.DefaultErrorJson) {
var wrapper interfaces.ReadOnlySignedBeaconBlock
var err error
// TODO: we should not require this fake signed wrapper and fix associated functions in the future.
switch b := i.(type) {
case *eth.GenericBeaconBlock_Phase0:
//ignore for phase0
return "", nil
case *eth.GenericBeaconBlock_Altair:
wrapper, err = blocks.NewSignedBeaconBlock(&eth.GenericSignedBeaconBlock_Altair{Altair: &eth.SignedBeaconBlockAltair{Block: b.Altair}})
case *eth.GenericBeaconBlock_Bellatrix:
wrapper, err = blocks.NewSignedBeaconBlock(&eth.GenericSignedBeaconBlock_Bellatrix{Bellatrix: &eth.SignedBeaconBlockBellatrix{Block: b.Bellatrix}})
case *eth.GenericBeaconBlock_BlindedBellatrix:
wrapper, err = blocks.NewSignedBeaconBlock(&eth.GenericSignedBeaconBlock_BlindedBellatrix{BlindedBellatrix: &eth.SignedBlindedBeaconBlockBellatrix{Block: b.BlindedBellatrix}})
case *eth.GenericBeaconBlock_Capella:
wrapper, err = blocks.NewSignedBeaconBlock(&eth.GenericSignedBeaconBlock_Capella{Capella: &eth.SignedBeaconBlockCapella{Block: b.Capella}})
case *eth.GenericBeaconBlock_BlindedCapella:
wrapper, err = blocks.NewSignedBeaconBlock(&eth.GenericSignedBeaconBlock_BlindedCapella{BlindedCapella: &eth.SignedBlindedBeaconBlockCapella{Block: b.BlindedCapella}})
case *eth.GenericBeaconBlock_Deneb:
// no need for blobs
wrapper, err = blocks.NewSignedBeaconBlock(&eth.GenericSignedBeaconBlock_Deneb{Deneb: &eth.SignedBeaconBlockContentsDeneb{Block: &eth.SignedBeaconBlockDeneb{Block: b.Deneb.Block}}})
case *eth.GenericBeaconBlock_BlindedDeneb:
wrapper, err = blocks.NewSignedBeaconBlock(&eth.GenericSignedBeaconBlock_BlindedDeneb{BlindedDeneb: &eth.SignedBlindedBeaconBlockDeneb{Message: b.BlindedDeneb}})
default:
return "", &httputil.DefaultErrorJson{
Message: fmt.Errorf("type %T is not supported", b).Error(),
Code: http.StatusInternalServerError,
}
}
bb, err := blocks.NewBeaconBlock(i)
if err != nil {
return "", &httputil.DefaultErrorJson{
Message: err.Error(),
Code: http.StatusInternalServerError,
}
}
if bb.Version() == version.Phase0 {
// ignore for phase 0
return "", nil
}
//get consensus payload value which is the same as the total from the block rewards api
blockRewards, httpError := blockRewardsFetcher.GetBlockRewardsData(ctx, wrapper)
blockRewards, httpError := blockRewardsFetcher.GetBlockRewardsData(ctx, bb)
if httpError != nil {
return "", httpError
}

View File

@@ -209,8 +209,6 @@ func TestProduceBlockV2(t *testing.T) {
assert.StringContains(t, "Prepared block is blinded", e.Message)
})
t.Run("Deneb", func(t *testing.T) {
t.Skip("TODO: Skip deneb until beacon api changes")
var block *shared.SignedBeaconBlockContentsDeneb
err := json.Unmarshal([]byte(rpctesting.DenebBlockContents), &block)
require.NoError(t, err)
@@ -519,7 +517,6 @@ func TestProduceBlockV2SSZ(t *testing.T) {
assert.StringContains(t, "Prepared block is blinded", e.Message)
})
t.Run("Deneb", func(t *testing.T) {
t.Skip("TODO: Skip deneb until beacon api changes")
var block *shared.SignedBeaconBlockContentsDeneb
err := json.Unmarshal([]byte(rpctesting.DenebBlockContents), &block)
require.NoError(t, err)
@@ -790,8 +787,6 @@ func TestProduceBlockV3(t *testing.T) {
require.Equal(t, "10", writer.Header().Get(api.ConsensusBlockValueHeader))
})
t.Run("Deneb", func(t *testing.T) {
t.Skip("TODO: Skip deneb until beacon api changes")
var block *shared.SignedBeaconBlockContentsDeneb
err := json.Unmarshal([]byte(rpctesting.DenebBlockContents), &block)
require.NoError(t, err)

View File

@@ -23,7 +23,9 @@ var (
// ErrNilObject is returned in a constructor when the underlying object is nil.
ErrNilObject = errors.New("received nil object")
// ErrNilSignedBeaconBlock is returned when a nil signed beacon block is received.
ErrNilSignedBeaconBlock = errors.New("signed beacon block can't be nil")
ErrNilSignedBeaconBlock = errors.New("signed beacon block can't be nil")
// ErrNilBeaconBlock is returned when a nil beacon block is received.
ErrNilBeaconBlock = errors.New("beacon block can't be nil")
errNonBlindedSignedBeaconBlock = errors.New("can only build signed beacon block from blinded format")
)

View File

@@ -35,7 +35,7 @@ func RunAttestationTest(t *testing.T, config string) {
body := &ethpb.BeaconBlockBodyAltair{Attestations: []*ethpb.Attestation{att}}
processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk)
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk.Block())
if err != nil {
return nil, err
}

View File

@@ -35,7 +35,7 @@ func RunAttestationTest(t *testing.T, config string) {
body := &ethpb.BeaconBlockBodyBellatrix{Attestations: []*ethpb.Attestation{att}}
processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk)
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk.Block())
if err != nil {
return nil, err
}

View File

@@ -35,7 +35,7 @@ func RunAttestationTest(t *testing.T, config string) {
body := &ethpb.BeaconBlockBodyCapella{Attestations: []*ethpb.Attestation{att}}
processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk)
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk.Block())
if err != nil {
return nil, err
}

View File

@@ -36,7 +36,7 @@ func RunBLSToExecutionChangeTest(t *testing.T, config string) {
BlsToExecutionChanges: []*ethpb.SignedBLSToExecutionChange{change},
}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
st, err := blocks.ProcessBLSToExecutionChanges(s, b)
st, err := blocks.ProcessBLSToExecutionChanges(s, b.Block())
if err != nil {
return nil, err
}

View File

@@ -32,7 +32,7 @@ func RunAttestationTest(t *testing.T, config string) {
body := &ethpb.BeaconBlockBodyDeneb{Attestations: []*ethpb.Attestation{att}}
processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.SignedBeaconBlock) (state.BeaconState, error) {
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk)
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk.Block())
if err != nil {
return nil, err
}

View File

@@ -36,7 +36,7 @@ func RunBLSToExecutionChangeTest(t *testing.T, config string) {
BlsToExecutionChanges: []*ethpb.SignedBLSToExecutionChange{change},
}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
st, err := blocks.ProcessBLSToExecutionChanges(s, b)
st, err := blocks.ProcessBLSToExecutionChanges(s, b.Block())
if err != nil {
return nil, err
}

View File

@@ -35,7 +35,7 @@ func RunAttestationTest(t *testing.T, config string) {
body := &ethpb.BeaconBlockBody{Attestations: []*ethpb.Attestation{att}}
processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
st, err = b.ProcessAttestationsNoVerifySignature(ctx, st, blk)
st, err = b.ProcessAttestationsNoVerifySignature(ctx, st, blk.Block())
if err != nil {
return nil, err
}