Remove getPayloadAttributes from FCU call (#13399)

This commit is contained in:
Potuz
2024-01-02 14:37:18 -03:00
committed by GitHub
parent 1b6547de6a
commit a602acf492
6 changed files with 123 additions and 23 deletions

View File

@@ -94,3 +94,23 @@ func (a *data) PbV3() (*enginev1.PayloadAttributesV3, error) {
ParentBeaconBlockRoot: a.parentBeaconBlockRoot,
}, nil
}
// IsEmpty returns whether the given payload attribute is empty
func (a *data) IsEmpty() bool {
if len(a.PrevRandao()) != 0 {
return false
}
if a.Timestamps() != 0 {
return false
}
if len(a.SuggestedFeeRecipient()) != 0 {
return false
}
if a.Version() >= version.Capella && len(a.withdrawals) != 0 {
return false
}
if a.Version() >= version.Deneb && len(a.parentBeaconBlockRoot) != 0 {
return false
}
return true
}

View File

@@ -204,3 +204,72 @@ func TestPayloadAttributeGetters(t *testing.T) {
t.Run(test.name, test.tc)
}
}
func TestIsEmpty(t *testing.T) {
tests := []struct {
name string
a Attributer
empty bool
}{
{
name: "Empty V1",
a: EmptyWithVersion(version.Bellatrix),
empty: true,
},
{
name: "Empty V2",
a: EmptyWithVersion(version.Capella),
empty: true,
},
{
name: "Empty V3",
a: EmptyWithVersion(version.Deneb),
empty: true,
},
{
name: "non empty prevrandao",
a: &data{
version: version.Bellatrix,
prevRandao: []byte{0x01},
},
empty: false,
},
{
name: "non zero Timestamps",
a: &data{
version: version.Bellatrix,
timeStamp: 1,
},
empty: false,
},
{
name: "non empty fee recipient",
a: &data{
version: version.Bellatrix,
suggestedFeeRecipient: []byte{0x01},
},
empty: false,
},
{
name: "non empty withdrawals",
a: &data{
version: version.Capella,
withdrawals: make([]*enginev1.Withdrawal, 1),
},
empty: false,
},
{
name: "non empty parent block root",
a: &data{
version: version.Deneb,
parentBeaconBlockRoot: []byte{0x01},
},
empty: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.empty, tt.a.IsEmpty())
})
}
}

View File

@@ -13,4 +13,5 @@ type Attributer interface {
PbV1() (*enginev1.PayloadAttributes, error)
PbV2() (*enginev1.PayloadAttributesV2, error)
PbV3() (*enginev1.PayloadAttributesV3, error)
IsEmpty() bool
}