moving cloner functions to beacon_block.go (#14265)

* moving cloner functions for beacon block and adding fuzzing tests

* fixing test
This commit is contained in:
james-prysm
2024-07-29 10:13:21 -05:00
committed by GitHub
parent 5c369361b0
commit 6f7976766d
6 changed files with 548 additions and 526 deletions

View File

@@ -52,40 +52,29 @@ func (b *SignedBeaconBlock) Copy() (interfaces.SignedBeaconBlock, error) {
}
switch b.version {
case version.Phase0:
cp := eth.CopySignedBeaconBlock(pb.(*eth.SignedBeaconBlock))
return initSignedBlockFromProtoPhase0(cp)
return initSignedBlockFromProtoPhase0(pb.(*eth.SignedBeaconBlock).Copy())
case version.Altair:
cp := eth.CopySignedBeaconBlockAltair(pb.(*eth.SignedBeaconBlockAltair))
return initSignedBlockFromProtoAltair(cp)
return initSignedBlockFromProtoAltair(pb.(*eth.SignedBeaconBlockAltair).Copy())
case version.Bellatrix:
if b.IsBlinded() {
cp := eth.CopySignedBlindedBeaconBlockBellatrix(pb.(*eth.SignedBlindedBeaconBlockBellatrix))
return initBlindedSignedBlockFromProtoBellatrix(cp)
return initBlindedSignedBlockFromProtoBellatrix(pb.(*eth.SignedBlindedBeaconBlockBellatrix).Copy())
}
cp := eth.CopySignedBeaconBlockBellatrix(pb.(*eth.SignedBeaconBlockBellatrix))
return initSignedBlockFromProtoBellatrix(cp)
return initSignedBlockFromProtoBellatrix(pb.(*eth.SignedBeaconBlockBellatrix).Copy())
case version.Capella:
if b.IsBlinded() {
cp := eth.CopySignedBlindedBeaconBlockCapella(pb.(*eth.SignedBlindedBeaconBlockCapella))
return initBlindedSignedBlockFromProtoCapella(cp)
return initBlindedSignedBlockFromProtoCapella(pb.(*eth.SignedBlindedBeaconBlockCapella).Copy())
}
cp := eth.CopySignedBeaconBlockCapella(pb.(*eth.SignedBeaconBlockCapella))
return initSignedBlockFromProtoCapella(cp)
return initSignedBlockFromProtoCapella(pb.(*eth.SignedBeaconBlockCapella).Copy())
case version.Deneb:
if b.IsBlinded() {
cp := eth.CopySignedBlindedBeaconBlockDeneb(pb.(*eth.SignedBlindedBeaconBlockDeneb))
return initBlindedSignedBlockFromProtoDeneb(cp)
return initBlindedSignedBlockFromProtoDeneb(pb.(*eth.SignedBlindedBeaconBlockDeneb).Copy())
}
cp := eth.CopySignedBeaconBlockDeneb(pb.(*eth.SignedBeaconBlockDeneb))
return initSignedBlockFromProtoDeneb(cp)
return initSignedBlockFromProtoDeneb(pb.(*eth.SignedBeaconBlockDeneb).Copy())
case version.Electra:
if b.IsBlinded() {
cp := eth.CopySignedBlindedBeaconBlockElectra(pb.(*eth.SignedBlindedBeaconBlockElectra))
return initBlindedSignedBlockFromProtoElectra(cp)
return initBlindedSignedBlockFromProtoElectra(pb.(*eth.SignedBlindedBeaconBlockElectra).Copy())
}
cp := eth.CopySignedBeaconBlockElectra(pb.(*eth.SignedBeaconBlockElectra))
return initSignedBlockFromProtoElectra(cp)
return initSignedBlockFromProtoElectra(pb.(*eth.SignedBeaconBlockElectra).Copy())
default:
return nil, errIncorrectBlockVersion
}
@@ -972,39 +961,29 @@ func (b *BeaconBlock) Copy() (interfaces.ReadOnlyBeaconBlock, error) {
}
switch b.version {
case version.Phase0:
cp := eth.CopyBeaconBlock(pb.(*eth.BeaconBlock))
return initBlockFromProtoPhase0(cp)
return initBlockFromProtoPhase0(pb.(*eth.BeaconBlock).Copy())
case version.Altair:
cp := eth.CopyBeaconBlockAltair(pb.(*eth.BeaconBlockAltair))
return initBlockFromProtoAltair(cp)
return initBlockFromProtoAltair(pb.(*eth.BeaconBlockAltair).Copy())
case version.Bellatrix:
if b.IsBlinded() {
cp := eth.CopyBlindedBeaconBlockBellatrix(pb.(*eth.BlindedBeaconBlockBellatrix))
return initBlindedBlockFromProtoBellatrix(cp)
return initBlindedBlockFromProtoBellatrix(pb.(*eth.BlindedBeaconBlockBellatrix).Copy())
}
cp := eth.CopyBeaconBlockBellatrix(pb.(*eth.BeaconBlockBellatrix))
return initBlockFromProtoBellatrix(cp)
return initBlockFromProtoBellatrix(pb.(*eth.BeaconBlockBellatrix).Copy())
case version.Capella:
if b.IsBlinded() {
cp := eth.CopyBlindedBeaconBlockCapella(pb.(*eth.BlindedBeaconBlockCapella))
return initBlindedBlockFromProtoCapella(cp)
return initBlindedBlockFromProtoCapella(pb.(*eth.BlindedBeaconBlockCapella).Copy())
}
cp := eth.CopyBeaconBlockCapella(pb.(*eth.BeaconBlockCapella))
return initBlockFromProtoCapella(cp)
return initBlockFromProtoCapella(pb.(*eth.BeaconBlockCapella).Copy())
case version.Deneb:
if b.IsBlinded() {
cp := eth.CopyBlindedBeaconBlockDeneb(pb.(*eth.BlindedBeaconBlockDeneb))
return initBlindedBlockFromProtoDeneb(cp)
return initBlindedBlockFromProtoDeneb(pb.(*eth.BlindedBeaconBlockDeneb).Copy())
}
cp := eth.CopyBeaconBlockDeneb(pb.(*eth.BeaconBlockDeneb))
return initBlockFromProtoDeneb(cp)
return initBlockFromProtoDeneb(pb.(*eth.BeaconBlockDeneb).Copy())
case version.Electra:
if b.IsBlinded() {
cp := eth.CopyBlindedBeaconBlockElectra(pb.(*eth.BlindedBeaconBlockElectra))
return initBlindedBlockFromProtoElectra(cp)
return initBlindedBlockFromProtoElectra(pb.(*eth.BlindedBeaconBlockElectra).Copy())
}
cp := eth.CopyBeaconBlockElectra(pb.(*eth.BeaconBlockElectra))
return initBlockFromProtoElectra(cp)
return initBlockFromProtoElectra(pb.(*eth.BeaconBlockElectra).Copy())
default:
return nil, errIncorrectBlockVersion
}