Skip to content

Commit

Permalink
core: add deneb as default (#2734)
Browse files Browse the repository at this point in the history
Add a switch case for `deneb` fork version wherever required. Also add relevant tests.

This makes `deneb` the default block version as beaconmock now uses deneb by default. This ensures all tests use deneb going forward.

category: feature 
ticket: #2729
  • Loading branch information
xenowits authored Dec 13, 2023
1 parent db20ff5 commit ad79ed6
Show file tree
Hide file tree
Showing 17 changed files with 381 additions and 27 deletions.
58 changes: 57 additions & 1 deletion app/eth2wrap/synthproposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import (
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
eth2bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
eth2capella "github.com/attestantio/go-eth2-client/api/v1/capella"
eth2deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
eth2spec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
shuffle "github.com/protolambda/eth2-shuffle"
"go.uber.org/zap"
Expand Down Expand Up @@ -197,6 +199,14 @@ func (h *synthWrapper) syntheticProposal(ctx context.Context, slot eth2p0.Slot,
proposal.Capella.ProposerIndex = vIdx
proposal.Capella.Body.ExecutionPayload.FeeRecipient = feeRecipient
proposal.Capella.Body.ExecutionPayload.Transactions = fraction(proposal.Capella.Body.ExecutionPayload.Transactions)
case eth2spec.DataVersionDeneb:
proposal.Deneb = &eth2deneb.BlockContents{}
proposal.Deneb.Block = signedBlock.Deneb.Message
proposal.Deneb.Block.Body.Graffiti = GetSyntheticGraffiti()
proposal.Deneb.Block.Slot = slot
proposal.Deneb.Block.ProposerIndex = vIdx
proposal.Deneb.Block.Body.ExecutionPayload.FeeRecipient = feeRecipient
proposal.Deneb.Block.Body.ExecutionPayload.Transactions = fraction(proposal.Deneb.Block.Body.ExecutionPayload.Transactions)
default:
return nil, errors.New("unsupported proposal version")
}
Expand Down Expand Up @@ -274,6 +284,8 @@ func IsSyntheticBlindedBlock(block *eth2api.VersionedSignedBlindedProposal) bool
graffiti = block.Bellatrix.Message.Body.Graffiti
case eth2spec.DataVersionCapella:
graffiti = block.Capella.Message.Body.Graffiti
case eth2spec.DataVersionDeneb:
graffiti = block.Deneb.SignedBlindedBlock.Message.Body.Graffiti
default:
return false
}
Expand All @@ -293,6 +305,8 @@ func IsSyntheticProposal(block *eth2api.VersionedSignedProposal) bool {
graffiti = block.Bellatrix.Message.Body.Graffiti
case eth2spec.DataVersionCapella:
graffiti = block.Capella.Message.Body.Graffiti
case eth2spec.DataVersionDeneb:
graffiti = block.Deneb.SignedBlock.Message.Body.Graffiti
default:
return false
}
Expand Down Expand Up @@ -543,7 +557,49 @@ func blindedProposal(proposal *eth2api.VersionedProposal) (*eth2api.VersionedBli
},
},
}
default: // TODO(xenowits): Add a case for deneb blinded block
case eth2spec.DataVersionDeneb:
resp = &eth2api.VersionedBlindedProposal{
Version: proposal.Version,
Deneb: &eth2deneb.BlindedBeaconBlock{
Slot: proposal.Deneb.Block.Slot,
ProposerIndex: proposal.Deneb.Block.ProposerIndex,
ParentRoot: proposal.Deneb.Block.ParentRoot,
StateRoot: proposal.Deneb.Block.StateRoot,
Body: &eth2deneb.BlindedBeaconBlockBody{
RANDAOReveal: proposal.Deneb.Block.Body.RANDAOReveal,
ETH1Data: proposal.Deneb.Block.Body.ETH1Data,
Graffiti: proposal.Deneb.Block.Body.Graffiti,
ProposerSlashings: proposal.Deneb.Block.Body.ProposerSlashings,
AttesterSlashings: proposal.Deneb.Block.Body.AttesterSlashings,
Attestations: proposal.Deneb.Block.Body.Attestations,
Deposits: proposal.Deneb.Block.Body.Deposits,
VoluntaryExits: proposal.Deneb.Block.Body.VoluntaryExits,
SyncAggregate: proposal.Deneb.Block.Body.SyncAggregate,
ExecutionPayloadHeader: &deneb.ExecutionPayloadHeader{
ParentHash: proposal.Deneb.Block.Body.ExecutionPayload.ParentHash,
FeeRecipient: proposal.Deneb.Block.Body.ExecutionPayload.FeeRecipient,
StateRoot: proposal.Deneb.Block.Body.ExecutionPayload.StateRoot,
ReceiptsRoot: proposal.Deneb.Block.Body.ExecutionPayload.ReceiptsRoot,
LogsBloom: proposal.Deneb.Block.Body.ExecutionPayload.LogsBloom,
PrevRandao: proposal.Deneb.Block.Body.ExecutionPayload.PrevRandao,
BlockNumber: proposal.Deneb.Block.Body.ExecutionPayload.BlockNumber,
GasLimit: proposal.Deneb.Block.Body.ExecutionPayload.GasLimit,
GasUsed: proposal.Deneb.Block.Body.ExecutionPayload.GasUsed,
Timestamp: proposal.Deneb.Block.Body.ExecutionPayload.Timestamp,
ExtraData: proposal.Deneb.Block.Body.ExecutionPayload.ExtraData,
BaseFeePerGas: proposal.Deneb.Block.Body.ExecutionPayload.BaseFeePerGas,
BlockHash: proposal.Deneb.Block.Body.ExecutionPayload.BlockHash,
TransactionsRoot: eth2p0.Root{},
WithdrawalsRoot: eth2p0.Root{},
BlobGasUsed: proposal.Deneb.Block.Body.ExecutionPayload.BlobGasUsed,
ExcessBlobGas: proposal.Deneb.Block.Body.ExecutionPayload.ExcessBlobGas,
},
BLSToExecutionChanges: proposal.Deneb.Block.Body.BLSToExecutionChanges,
BlobKZGCommitments: proposal.Deneb.Block.Body.BlobKZGCommitments,
},
},
}
default:
return nil, errors.New("unsupported blinded proposal version")
}

Expand Down
2 changes: 1 addition & 1 deletion app/eth2wrap/synthproposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestSynthProposer(t *testing.T) {
}
require.Equal(t, eth2spec.DataVersionCapella, block.Version)

signed := testutil.RandomVersionedSignedProposal()
signed := testutil.RandomCapellaVersionedSignedProposal()
signed.Capella.Message = block.Capella
err = eth2Cl.SubmitProposal(ctx, signed)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion core/dutydb/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func TestDutyExpiry(t *testing.T) {
// Expire attestation
deadliner.expire()

versionedProposal := core.VersionedProposal{VersionedProposal: *testutil.RandomVersionedProposal()}
versionedProposal := core.VersionedProposal{VersionedProposal: *testutil.RandomDenebVersionedProposal()}

// Store another duty which deletes expired duties
err = db.Store(ctx, core.NewProposerDuty(slot+1), core.UnsignedDataSet{
Expand Down
4 changes: 4 additions & 0 deletions core/eth2signeddata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func TestVerifyEth2SignedData(t *testing.T) {
name: "verify blinded beacon block capella",
data: testutil.RandomCapellaVersionedSignedBlindedProposal(),
},
{
name: "verify blinded beacon block deneb",
data: testutil.RandomDenebVersionedSignedBlindedProposal(),
},
{
name: "verify randao",
data: testutil.RandomCoreSignedRandao(),
Expand Down
4 changes: 4 additions & 0 deletions core/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ func verifyFeeRecipient(ctx context.Context, proposal *eth2api.VersionedProposal
actualAddr = fmt.Sprintf("%#x", proposal.Bellatrix.Body.ExecutionPayload.FeeRecipient)
case eth2spec.DataVersionCapella:
actualAddr = fmt.Sprintf("%#x", proposal.Capella.Body.ExecutionPayload.FeeRecipient)
case eth2spec.DataVersionDeneb:
actualAddr = fmt.Sprintf("%#x", proposal.Deneb.Block.Body.ExecutionPayload.FeeRecipient)
default:
return
}
Expand All @@ -416,6 +418,8 @@ func verifyFeeRecipientBlinded(ctx context.Context, proposal *eth2api.VersionedB
actualAddr = fmt.Sprintf("%#x", proposal.Bellatrix.Body.ExecutionPayloadHeader.FeeRecipient)
case eth2spec.DataVersionCapella:
actualAddr = fmt.Sprintf("%#x", proposal.Capella.Body.ExecutionPayloadHeader.FeeRecipient)
case eth2spec.DataVersionDeneb:
actualAddr = fmt.Sprintf("%#x", proposal.Deneb.Body.ExecutionPayloadHeader.FeeRecipient)
default:
return
}
Expand Down
4 changes: 4 additions & 0 deletions core/fetcher/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ func assertRandao(t *testing.T, randao eth2p0.BLSSignature, block core.Versioned
require.EqualValues(t, randao, block.Bellatrix.Body.RANDAOReveal)
case eth2spec.DataVersionCapella:
require.EqualValues(t, randao, block.Capella.Body.RANDAOReveal)
case eth2spec.DataVersionDeneb:
require.EqualValues(t, randao, block.Deneb.Block.Body.RANDAOReveal)
default:
require.Fail(t, "invalid block")
}
Expand All @@ -579,6 +581,8 @@ func assertRandaoBlindedBlock(t *testing.T, randao eth2p0.BLSSignature, block co
require.EqualValues(t, randao, block.Bellatrix.Body.RANDAOReveal)
case eth2spec.DataVersionCapella:
require.EqualValues(t, randao, block.Capella.Body.RANDAOReveal)
case eth2spec.DataVersionDeneb:
require.EqualValues(t, randao, block.Deneb.Body.RANDAOReveal)
default:
require.Fail(t, "invalid block")
}
Expand Down
14 changes: 8 additions & 6 deletions core/parsigex/parsigex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,29 @@ func TestParSigExVerifier(t *testing.T) {
})

t.Run("Verify proposal", func(t *testing.T) {
proposal := testutil.RandomVersionedSignedProposal()
proposal.Capella.Message.Slot = slot
proposal := testutil.RandomDenebVersionedSignedProposal()
proposal.Deneb.SignedBlock.Message.Slot = slot
sigRoot, err := versionedSignedProposalRoot(t, proposal)
require.NoError(t, err)
sigData, err := signing.GetDataRoot(ctx, bmock, signing.DomainBeaconProposer, epoch, sigRoot)
require.NoError(t, err)
proposal.Capella.Signature = sign(sigData[:])
proposal.Deneb.SignedBlock.Signature = sign(sigData[:])
data, err := core.NewPartialVersionedSignedProposal(proposal, shareIdx)
require.NoError(t, err)

require.NoError(t, verifyFunc(ctx, core.NewProposerDuty(slot), pubkey, data))
})

t.Run("Verify blinded proposal", func(t *testing.T) {
blindedBlock := testutil.RandomCapellaVersionedSignedBlindedProposal()
blindedBlock.Capella.Message.Slot = slot
blindedBlock := testutil.RandomDenebVersionedSignedBlindedProposal()
blindedBlock.Deneb.SignedBlindedBlock.Message.Slot = slot
sigRoot, err := blindedBlock.Root()
require.NoError(t, err)

sigData, err := signing.GetDataRoot(ctx, bmock, signing.DomainBeaconProposer, epoch, sigRoot)
require.NoError(t, err)
blindedBlock.Capella.Signature = sign(sigData[:])

blindedBlock.Deneb.SignedBlindedBlock.Signature = sign(sigData[:])
data, err := core.NewPartialVersionedSignedBlindedProposal(&blindedBlock.VersionedSignedBlindedProposal, shareIdx)
require.NoError(t, err)

Expand Down
8 changes: 8 additions & 0 deletions core/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func TestParSignedDataSetProto(t *testing.T) {
Type: core.DutyProposer,
Data: testutil.RandomCapellaCoreVersionedSignedProposal(),
},
{
Type: core.DutyProposer,
Data: testutil.RandomDenebCoreVersionedSignedProposal(),
},
{
Type: core.DutyBuilderProposer,
Data: testutil.RandomBellatrixVersionedSignedBlindedProposal(),
Expand All @@ -55,6 +59,10 @@ func TestParSignedDataSetProto(t *testing.T) {
Type: core.DutyBuilderProposer,
Data: testutil.RandomCapellaVersionedSignedBlindedProposal(),
},
{
Type: core.DutyBuilderProposer,
Data: testutil.RandomDenebVersionedSignedBlindedProposal(),
},
{
Type: core.DutyBuilderRegistration,
Data: testutil.RandomCoreVersionedSignedValidatorRegistration(t),
Expand Down
16 changes: 16 additions & 0 deletions core/sigagg/sigagg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
eth2bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
eth2capella "github.com/attestantio/go-eth2-client/api/v1/capella"
eth2deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
eth2spec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/altair"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -368,6 +370,20 @@ func TestSigAgg_DutyProposer(t *testing.T) {
},
},
},
{
name: "deneb proposal",
proposal: &eth2api.VersionedSignedProposal{
Version: eth2spec.DataVersionDeneb,
Deneb: &eth2deneb.SignedBlockContents{
SignedBlock: &deneb.SignedBeaconBlock{
Message: testutil.RandomDenebBeaconBlock(),
Signature: testutil.RandomEth2Signature(),
},
KZGProofs: []deneb.KZGProof{},
Blobs: []deneb.Blob{},
},
},
},
}

for _, test := range tests {
Expand Down
16 changes: 16 additions & 0 deletions core/signeddata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
eth2api "github.com/attestantio/go-eth2-client/api"
eth2bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
eth2capella "github.com/attestantio/go-eth2-client/api/v1/capella"
eth2deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
eth2spec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/altair"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
Expand Down Expand Up @@ -60,6 +61,21 @@ func TestSignedDataSetSignature(t *testing.T) {
},
},
},
{
name: "versioned signed blinded proposal deneb",
data: core.VersionedSignedBlindedProposal{
VersionedSignedBlindedProposal: eth2api.VersionedSignedBlindedProposal{
Version: eth2spec.DataVersionDeneb,
Deneb: &eth2deneb.SignedBlindedBlockContents{
SignedBlindedBlock: &eth2deneb.SignedBlindedBeaconBlock{
Message: testutil.RandomDenebBlindedBeaconBlock(),
Signature: testutil.RandomEth2Signature(),
},
SignedBlindedBlobSidecars: []*eth2deneb.SignedBlindedBlobSidecar{},
},
},
},
},
{
name: "signed beacon committee selection",
data: testutil.RandomCoreBeaconCommitteeSelection(),
Expand Down
10 changes: 5 additions & 5 deletions core/tracker/inclusion_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func TestInclusion(t *testing.T) {
att3 := testutil.RandomAttestation()
att3Duty := core.NewAttesterDuty(uint64(att3.Data.Slot))

block4 := testutil.RandomVersionedSignedProposal()
block4Duty := core.NewProposerDuty(uint64(block4.Capella.Message.Slot))
block4 := testutil.RandomDenebVersionedSignedProposal()
block4Duty := core.NewProposerDuty(uint64(block4.Deneb.SignedBlock.Message.Slot))

block5 := testutil.RandomCapellaVersionedSignedBlindedProposal()
block5.Capella.Message.Body.Graffiti = eth2wrap.GetSyntheticGraffiti() // Ignored, not included or missed.
block5Duty := core.NewBuilderProposerDuty(uint64(block5.Capella.Message.Slot))
block5 := testutil.RandomDenebVersionedSignedBlindedProposal()
block5.Deneb.SignedBlindedBlock.Message.Body.Graffiti = eth2wrap.GetSyntheticGraffiti() // Ignored, not included or missed.
block5Duty := core.NewBuilderProposerDuty(uint64(block5.Deneb.SignedBlindedBlock.Message.Slot))

// Submit all duties
err := incl.Submitted(att1Duty, "", core.NewAttestation(att1), 0)
Expand Down
29 changes: 26 additions & 3 deletions core/validatorapi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
eth2bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
eth2capella "github.com/attestantio/go-eth2-client/api/v1/capella"
deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
eth2spec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/altair"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
Expand Down Expand Up @@ -718,8 +719,19 @@ func proposeBlindedBlock(p eth2client.BlindedProposalProvider) handlerFunc {

func submitProposal(p eth2client.ProposalSubmitter) handlerFunc {
return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) {
denebBlock := new(deneb.SignedBlockContents)
err := unmarshal(typ, body, denebBlock)
if err == nil {
block := &eth2api.VersionedSignedProposal{
Version: eth2spec.DataVersionDeneb,
Deneb: denebBlock,
}

return nil, nil, p.SubmitProposal(ctx, block)
}

capellaBlock := new(capella.SignedBeaconBlock)
err := unmarshal(typ, body, capellaBlock)
err = unmarshal(typ, body, capellaBlock)
if err == nil {
block := &eth2api.VersionedSignedProposal{
Version: eth2spec.DataVersionCapella,
Expand Down Expand Up @@ -768,9 +780,20 @@ func submitProposal(p eth2client.ProposalSubmitter) handlerFunc {

func submitBlindedBlock(p eth2client.BlindedProposalSubmitter) handlerFunc {
return func(ctx context.Context, _ map[string]string, _ url.Values, typ contentType, body []byte) (any, http.Header, error) {
// The blinded block maybe either bellatrix or capella.
// The blinded block maybe either bellatrix, capella or deneb.
denebBlock := new(deneb.SignedBlindedBlockContents)
err := unmarshal(typ, body, denebBlock)
if err == nil {
block := &eth2api.VersionedSignedBlindedProposal{
Version: eth2spec.DataVersionDeneb,
Deneb: denebBlock,
}

return nil, nil, p.SubmitBlindedProposal(ctx, block)
}

capellaBlock := new(eth2capella.SignedBlindedBeaconBlock)
err := unmarshal(typ, body, capellaBlock)
err = unmarshal(typ, body, capellaBlock)
if err == nil {
block := &eth2api.VersionedSignedBlindedProposal{
Version: eth2spec.DataVersionCapella,
Expand Down
Loading

0 comments on commit ad79ed6

Please sign in to comment.