mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 22:54:17 -05:00
Add Gloas consensus type block package (#15618)
Co-authored-by: Bastin <43618253+Inspector-Butters@users.noreply.github.com>
This commit is contained in:
@@ -61,3 +61,116 @@ func CopySyncCommitteeContribution(c *SyncCommitteeContribution) *SyncCommitteeC
|
||||
Signature: bytesutil.SafeCopyBytes(c.Signature),
|
||||
}
|
||||
}
|
||||
|
||||
// CopySignedBeaconBlockGloas copies the provided signed beacon block Gloas object.
|
||||
func CopySignedBeaconBlockGloas(sb *SignedBeaconBlockGloas) *SignedBeaconBlockGloas {
|
||||
if sb == nil {
|
||||
return nil
|
||||
}
|
||||
return &SignedBeaconBlockGloas{
|
||||
Block: copyBeaconBlockGloas(sb.Block),
|
||||
Signature: bytesutil.SafeCopyBytes(sb.Signature),
|
||||
}
|
||||
}
|
||||
|
||||
// copyBeaconBlockGloas copies the provided beacon block Gloas object.
|
||||
func copyBeaconBlockGloas(b *BeaconBlockGloas) *BeaconBlockGloas {
|
||||
if b == nil {
|
||||
return nil
|
||||
}
|
||||
return &BeaconBlockGloas{
|
||||
Slot: b.Slot,
|
||||
ProposerIndex: b.ProposerIndex,
|
||||
ParentRoot: bytesutil.SafeCopyBytes(b.ParentRoot),
|
||||
StateRoot: bytesutil.SafeCopyBytes(b.StateRoot),
|
||||
Body: copyBeaconBlockBodyGloas(b.Body),
|
||||
}
|
||||
}
|
||||
|
||||
// copyPayloadAttestation copies the provided payload attestation object.
|
||||
func copyPayloadAttestation(pa *PayloadAttestation) *PayloadAttestation {
|
||||
if pa == nil {
|
||||
return nil
|
||||
}
|
||||
copied := &PayloadAttestation{
|
||||
AggregationBits: pa.AggregationBits,
|
||||
Signature: bytesutil.SafeCopyBytes(pa.Signature),
|
||||
}
|
||||
if pa.Data != nil {
|
||||
copied.Data = &PayloadAttestationData{
|
||||
BeaconBlockRoot: bytesutil.SafeCopyBytes(pa.Data.BeaconBlockRoot),
|
||||
Slot: pa.Data.Slot,
|
||||
PayloadPresent: pa.Data.PayloadPresent,
|
||||
BlobDataAvailable: pa.Data.BlobDataAvailable,
|
||||
}
|
||||
}
|
||||
return copied
|
||||
}
|
||||
|
||||
// copyPayloadAttestations copies a slice of payload attestations.
|
||||
func copyPayloadAttestations(pas []*PayloadAttestation) []*PayloadAttestation {
|
||||
if len(pas) == 0 {
|
||||
return nil
|
||||
}
|
||||
copied := make([]*PayloadAttestation, len(pas))
|
||||
for i, pa := range pas {
|
||||
copied[i] = copyPayloadAttestation(pa)
|
||||
}
|
||||
return copied
|
||||
}
|
||||
|
||||
// copySignedExecutionPayloadBid copies the provided signed execution payload header.
|
||||
func copySignedExecutionPayloadBid(header *SignedExecutionPayloadBid) *SignedExecutionPayloadBid {
|
||||
if header == nil {
|
||||
return nil
|
||||
}
|
||||
copied := &SignedExecutionPayloadBid{
|
||||
Signature: bytesutil.SafeCopyBytes(header.Signature),
|
||||
}
|
||||
if header.Message != nil {
|
||||
copied.Message = &ExecutionPayloadBid{
|
||||
ParentBlockHash: bytesutil.SafeCopyBytes(header.Message.ParentBlockHash),
|
||||
ParentBlockRoot: bytesutil.SafeCopyBytes(header.Message.ParentBlockRoot),
|
||||
BlockHash: bytesutil.SafeCopyBytes(header.Message.BlockHash),
|
||||
FeeRecipient: bytesutil.SafeCopyBytes(header.Message.FeeRecipient),
|
||||
GasLimit: header.Message.GasLimit,
|
||||
BuilderIndex: header.Message.BuilderIndex,
|
||||
Slot: header.Message.Slot,
|
||||
Value: header.Message.Value,
|
||||
BlobKzgCommitmentsRoot: bytesutil.SafeCopyBytes(header.Message.BlobKzgCommitmentsRoot),
|
||||
}
|
||||
}
|
||||
return copied
|
||||
}
|
||||
|
||||
// copyBeaconBlockBodyGloas copies the provided beacon block body Gloas object.
|
||||
func copyBeaconBlockBodyGloas(body *BeaconBlockBodyGloas) *BeaconBlockBodyGloas {
|
||||
if body == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
copied := &BeaconBlockBodyGloas{
|
||||
RandaoReveal: bytesutil.SafeCopyBytes(body.RandaoReveal),
|
||||
Graffiti: bytesutil.SafeCopyBytes(body.Graffiti),
|
||||
}
|
||||
|
||||
if body.Eth1Data != nil {
|
||||
copied.Eth1Data = body.Eth1Data.Copy()
|
||||
}
|
||||
|
||||
if body.SyncAggregate != nil {
|
||||
copied.SyncAggregate = body.SyncAggregate.Copy()
|
||||
}
|
||||
|
||||
copied.ProposerSlashings = CopySlice(body.ProposerSlashings)
|
||||
copied.AttesterSlashings = CopySlice(body.AttesterSlashings)
|
||||
copied.Attestations = CopySlice(body.Attestations)
|
||||
copied.Deposits = CopySlice(body.Deposits)
|
||||
copied.VoluntaryExits = CopySlice(body.VoluntaryExits)
|
||||
copied.BlsToExecutionChanges = CopySlice(body.BlsToExecutionChanges)
|
||||
|
||||
copied.SignedExecutionPayloadBid = copySignedExecutionPayloadBid(body.SignedExecutionPayloadBid)
|
||||
copied.PayloadAttestations = copyPayloadAttestations(body.PayloadAttestations)
|
||||
|
||||
return copied
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
bitfield "github.com/OffchainLabs/go-bitfield"
|
||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
||||
v1alpha1 "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||
"github.com/OffchainLabs/prysm/v7/testing/assert"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func TestCopySignedBeaconBlock(t *testing.T) {
|
||||
@@ -100,6 +103,49 @@ func TestCopySyncCommitteeContribution(t *testing.T) {
|
||||
assert.NotEmpty(t, got, "Copied sync committee contribution has empty fields")
|
||||
}
|
||||
|
||||
func TestCopySignedBeaconBlockGloasNil(t *testing.T) {
|
||||
if got := v1alpha1.CopySignedBeaconBlockGloas(nil); got != nil {
|
||||
t.Fatalf("CopySignedBeaconBlockGloas(nil) = %v, want nil", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCopySignedBeaconBlockGloasDeepCopy(t *testing.T) {
|
||||
original := genSignedBeaconBlockGloas()
|
||||
|
||||
copied := v1alpha1.CopySignedBeaconBlockGloas(original)
|
||||
if copied == original {
|
||||
t.Fatalf("CopySignedBeaconBlockGloas returned the original pointer")
|
||||
}
|
||||
if !reflect.DeepEqual(copied, original) {
|
||||
t.Fatalf("CopySignedBeaconBlockGloas() = %v, want %v", copied, original)
|
||||
}
|
||||
|
||||
want := proto.Clone(copied).(*v1alpha1.SignedBeaconBlockGloas)
|
||||
|
||||
original.Signature[0] ^= 0xFF
|
||||
original.Block.ParentRoot[0] ^= 0xFF
|
||||
original.Block.StateRoot[0] ^= 0xFF
|
||||
original.Block.Body.RandaoReveal[0] ^= 0xFF
|
||||
original.Block.Body.Graffiti[0] ^= 0xFF
|
||||
original.Block.Body.SyncAggregate.SyncCommitteeSignature[0] ^= 0xFF
|
||||
original.Block.Body.SignedExecutionPayloadBid.Signature[0] ^= 0xFF
|
||||
original.Block.Body.SignedExecutionPayloadBid.Message.BlockHash[0] ^= 0xFF
|
||||
original.Block.Body.PayloadAttestations[0].Signature[0] ^= 0xFF
|
||||
original.Block.Body.PayloadAttestations[0].Data.BeaconBlockRoot[0] ^= 0xFF
|
||||
original.Block.Body.PayloadAttestations = append(original.Block.Body.PayloadAttestations, &v1alpha1.PayloadAttestation{})
|
||||
original.Block.Body.BlsToExecutionChanges[0].Message.ValidatorIndex++
|
||||
|
||||
if !reflect.DeepEqual(want, copied) {
|
||||
t.Fatalf("copy mutated after modifying source: got %v, want %v", copied, want)
|
||||
}
|
||||
if copied.Block == original.Block {
|
||||
t.Fatal("expected copied block pointer to differ from original")
|
||||
}
|
||||
if copied.Block.Body == original.Block.Body {
|
||||
t.Fatal("expected copied block body pointer to differ from original")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCopyPendingAttestationSlice(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -1125,3 +1171,78 @@ func genConsolidationRequest() *enginev1.ConsolidationRequest {
|
||||
TargetPubkey: bytes(48),
|
||||
}
|
||||
}
|
||||
|
||||
func genSignedBeaconBlockGloas() *v1alpha1.SignedBeaconBlockGloas {
|
||||
return &v1alpha1.SignedBeaconBlockGloas{
|
||||
Block: genBeaconBlockGloas(),
|
||||
Signature: bytes(96),
|
||||
}
|
||||
}
|
||||
|
||||
func genBeaconBlockGloas() *v1alpha1.BeaconBlockGloas {
|
||||
return &v1alpha1.BeaconBlockGloas{
|
||||
Slot: primitives.Slot(rand.Uint64()),
|
||||
ProposerIndex: primitives.ValidatorIndex(rand.Uint64()),
|
||||
ParentRoot: bytes(32),
|
||||
StateRoot: bytes(32),
|
||||
Body: genBeaconBlockBodyGloas(),
|
||||
}
|
||||
}
|
||||
|
||||
func genBeaconBlockBodyGloas() *v1alpha1.BeaconBlockBodyGloas {
|
||||
return &v1alpha1.BeaconBlockBodyGloas{
|
||||
RandaoReveal: bytes(96),
|
||||
Eth1Data: genEth1Data(),
|
||||
Graffiti: bytes(32),
|
||||
ProposerSlashings: genProposerSlashings(3),
|
||||
AttesterSlashings: genAttesterSlashingsElectra(3),
|
||||
Attestations: genAttestationsElectra(3),
|
||||
Deposits: genDeposits(3),
|
||||
VoluntaryExits: genSignedVoluntaryExits(3),
|
||||
SyncAggregate: genSyncAggregate(),
|
||||
BlsToExecutionChanges: genBLSToExecutionChanges(2),
|
||||
SignedExecutionPayloadBid: genSignedExecutionPayloadBidGloas(),
|
||||
PayloadAttestations: genPayloadAttestations(2),
|
||||
}
|
||||
}
|
||||
|
||||
func genSignedExecutionPayloadBidGloas() *v1alpha1.SignedExecutionPayloadBid {
|
||||
return &v1alpha1.SignedExecutionPayloadBid{
|
||||
Message: genExecutionPayloadBidGloas(),
|
||||
Signature: bytes(96),
|
||||
}
|
||||
}
|
||||
|
||||
func genExecutionPayloadBidGloas() *v1alpha1.ExecutionPayloadBid {
|
||||
return &v1alpha1.ExecutionPayloadBid{
|
||||
ParentBlockHash: bytes(32),
|
||||
ParentBlockRoot: bytes(32),
|
||||
BlockHash: bytes(32),
|
||||
FeeRecipient: bytes(20),
|
||||
GasLimit: rand.Uint64(),
|
||||
BuilderIndex: primitives.ValidatorIndex(rand.Uint64()),
|
||||
Slot: primitives.Slot(rand.Uint64()),
|
||||
Value: primitives.Gwei(rand.Uint64()),
|
||||
BlobKzgCommitmentsRoot: bytes(32),
|
||||
}
|
||||
}
|
||||
|
||||
func genPayloadAttestations(num int) []*v1alpha1.PayloadAttestation {
|
||||
pas := make([]*v1alpha1.PayloadAttestation, num)
|
||||
for i := range pas {
|
||||
bits := bitfield.NewBitvector512()
|
||||
bits.SetBitAt(uint64(i%512), true)
|
||||
|
||||
pas[i] = &v1alpha1.PayloadAttestation{
|
||||
AggregationBits: bits,
|
||||
Data: &v1alpha1.PayloadAttestationData{
|
||||
BeaconBlockRoot: bytes(32),
|
||||
Slot: primitives.Slot(rand.Uint64()),
|
||||
PayloadPresent: i%2 == 0,
|
||||
BlobDataAvailable: i%2 == 1,
|
||||
},
|
||||
Signature: bytes(96),
|
||||
}
|
||||
}
|
||||
return pas
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user