mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Native Blocks Ep. 2 - Switch usages to new package (#10885)
* panic in SizeSSZ
* moving slowly
* adapt old code to new interfaces
* return interfaces from factory functions
* replace the rest of WrappedSignedBeaconBlock
* WrappedBeaconBlock
* WrappedBeaconBlockBody
* miscellaneous
* Test_BeaconBlockIsNil
* replace usages of BeaconBlockIsNil
* replace usages of mutator
* fix all build errors
* fix some more issues
* mutator changes
* relax assertions when initializing
* revert changes in object_mapping.go
* allow calling Proto on nil
* Revert "allow calling Proto on nil"
This reverts commit ecc84e4553.
* modify Copy and Proto methods
* remove unused var
* fix block batch tests
* correct BUILD file
* Error when initializing nil objects
* one more error fix
* add missing comma
* rename alias to blocktest
* add logging
* error when SignedBeaconBlock is nil
* fix last test
* import fix
* broken
* working
* test fixes
* reduce complexity of processPendingBlocks
* simplified
This commit is contained in:
@@ -3,14 +3,15 @@ package testing
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/consensus-types/blocks"
|
||||
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
|
||||
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
// NewSignedBeaconBlockFromGeneric creates a signed beacon block
|
||||
// from a protobuf generic signed beacon block.
|
||||
func NewSignedBeaconBlockFromGeneric(gb *eth.GenericSignedBeaconBlock) (*blocks.SignedBeaconBlock, error) {
|
||||
func NewSignedBeaconBlockFromGeneric(gb *eth.GenericSignedBeaconBlock) (interfaces.SignedBeaconBlock, error) {
|
||||
if gb == nil {
|
||||
return nil, blocks.ErrNilObjectWrapped
|
||||
return nil, blocks.ErrNilObject
|
||||
}
|
||||
switch bb := gb.Block.(type) {
|
||||
case *eth.GenericSignedBeaconBlock_Phase0:
|
||||
|
||||
@@ -14,36 +14,36 @@ type blockMutator struct {
|
||||
Bellatrix func(beaconBlock *eth.SignedBeaconBlockBellatrix)
|
||||
}
|
||||
|
||||
func (m blockMutator) apply(b interfaces.SignedBeaconBlock) error {
|
||||
func (m blockMutator) apply(b interfaces.SignedBeaconBlock) (interfaces.SignedBeaconBlock, error) {
|
||||
switch b.Version() {
|
||||
case version.Phase0:
|
||||
bb, err := b.PbPhase0Block()
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
m.Phase0(bb)
|
||||
return nil
|
||||
return blocks.NewSignedBeaconBlock(bb)
|
||||
case version.Altair:
|
||||
bb, err := b.PbAltairBlock()
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
m.Altair(bb)
|
||||
return nil
|
||||
return blocks.NewSignedBeaconBlock(bb)
|
||||
case version.Bellatrix:
|
||||
bb, err := b.PbBellatrixBlock()
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
m.Bellatrix(bb)
|
||||
return nil
|
||||
return blocks.NewSignedBeaconBlock(bb)
|
||||
default:
|
||||
return blocks.ErrUnsupportedSignedBeaconBlock
|
||||
return nil, blocks.ErrUnsupportedSignedBeaconBlock
|
||||
}
|
||||
}
|
||||
|
||||
// SetBlockStateRoot modifies the block's state root.
|
||||
func SetBlockStateRoot(b interfaces.SignedBeaconBlock, sr [32]byte) error {
|
||||
func SetBlockStateRoot(b interfaces.SignedBeaconBlock, sr [32]byte) (interfaces.SignedBeaconBlock, error) {
|
||||
return blockMutator{
|
||||
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.StateRoot = sr[:] },
|
||||
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.StateRoot = sr[:] },
|
||||
@@ -52,7 +52,7 @@ func SetBlockStateRoot(b interfaces.SignedBeaconBlock, sr [32]byte) error {
|
||||
}
|
||||
|
||||
// SetBlockParentRoot modifies the block's parent root.
|
||||
func SetBlockParentRoot(b interfaces.SignedBeaconBlock, pr [32]byte) error {
|
||||
func SetBlockParentRoot(b interfaces.SignedBeaconBlock, pr [32]byte) (interfaces.SignedBeaconBlock, error) {
|
||||
return blockMutator{
|
||||
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.ParentRoot = pr[:] },
|
||||
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.ParentRoot = pr[:] },
|
||||
@@ -61,7 +61,7 @@ func SetBlockParentRoot(b interfaces.SignedBeaconBlock, pr [32]byte) error {
|
||||
}
|
||||
|
||||
// SetBlockSlot modifies the block's slot.
|
||||
func SetBlockSlot(b interfaces.SignedBeaconBlock, s types.Slot) error {
|
||||
func SetBlockSlot(b interfaces.SignedBeaconBlock, s types.Slot) (interfaces.SignedBeaconBlock, error) {
|
||||
return blockMutator{
|
||||
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.Slot = s },
|
||||
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.Slot = s },
|
||||
@@ -70,7 +70,7 @@ func SetBlockSlot(b interfaces.SignedBeaconBlock, s types.Slot) error {
|
||||
}
|
||||
|
||||
// SetProposerIndex modifies the block's proposer index.
|
||||
func SetProposerIndex(b interfaces.SignedBeaconBlock, idx types.ValidatorIndex) error {
|
||||
func SetProposerIndex(b interfaces.SignedBeaconBlock, idx types.ValidatorIndex) (interfaces.SignedBeaconBlock, error) {
|
||||
return blockMutator{
|
||||
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.ProposerIndex = idx },
|
||||
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.ProposerIndex = idx },
|
||||
|
||||
Reference in New Issue
Block a user