Rename Block Package in Consensus-Types to Interfaces (#10605)

* interfaces package

* builds

* gaz
This commit is contained in:
Raul Jordan
2022-05-02 18:32:37 +00:00
committed by GitHub
parent 16bbf5602f
commit 20ab988a4a
162 changed files with 658 additions and 660 deletions

View File

@@ -14,7 +14,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/consensus-types/wrapper",
visibility = ["//visibility:public"],
deps = [
"//consensus-types/block:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",

View File

@@ -2,7 +2,7 @@ package wrapper
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/consensus-types/block"
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)
@@ -34,7 +34,7 @@ var (
// WrappedSignedBeaconBlock will wrap a signed beacon block to conform to the
// signed beacon block interface.
func WrappedSignedBeaconBlock(i interface{}) (block.SignedBeaconBlock, error) {
func WrappedSignedBeaconBlock(i interface{}) (interfaces.SignedBeaconBlock, error) {
switch b := i.(type) {
case *eth.GenericSignedBeaconBlock_Phase0:
return wrappedPhase0SignedBeaconBlock(b.Phase0), nil
@@ -61,7 +61,7 @@ func WrappedSignedBeaconBlock(i interface{}) (block.SignedBeaconBlock, error) {
// WrappedBeaconBlock will wrap a signed beacon block to conform to the
// signed beacon block interface.
func WrappedBeaconBlock(i interface{}) (block.BeaconBlock, error) {
func WrappedBeaconBlock(i interface{}) (interfaces.BeaconBlock, error) {
switch b := i.(type) {
case *eth.GenericBeaconBlock_Phase0:
return WrappedPhase0BeaconBlock(b.Phase0), nil
@@ -87,7 +87,7 @@ func WrappedBeaconBlock(i interface{}) (block.BeaconBlock, error) {
// BuildSignedBeaconBlock assembles a block.SignedBeaconBlock interface compatible struct from a
// given beacon block an the appropriate signature. This method may be used to easily create a
// signed beacon block.
func BuildSignedBeaconBlock(blk block.BeaconBlock, signature []byte) (block.SignedBeaconBlock, error) {
func BuildSignedBeaconBlock(blk interfaces.BeaconBlock, signature []byte) (interfaces.SignedBeaconBlock, error) {
switch b := blk.(type) {
case Phase0BeaconBlock:
pb, ok := b.Proto().(*eth.BeaconBlock)
@@ -118,7 +118,7 @@ func BuildSignedBeaconBlock(blk block.BeaconBlock, signature []byte) (block.Sign
}
}
func UnwrapGenericSignedBeaconBlock(gb *eth.GenericSignedBeaconBlock) (block.SignedBeaconBlock, error) {
func UnwrapGenericSignedBeaconBlock(gb *eth.GenericSignedBeaconBlock) (interfaces.SignedBeaconBlock, error) {
if gb == nil {
return nil, ErrNilObjectWrapped
}

View File

@@ -3,7 +3,7 @@ package wrapper
import (
ssz "github.com/ferranbt/fastssz"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/consensus-types/block"
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -13,9 +13,9 @@ import (
)
var (
_ = block.SignedBeaconBlock(&altairSignedBeaconBlock{})
_ = block.BeaconBlock(&altairBeaconBlock{})
_ = block.BeaconBlockBody(&altairBeaconBlockBody{})
_ = interfaces.SignedBeaconBlock(&altairSignedBeaconBlock{})
_ = interfaces.BeaconBlock(&altairBeaconBlock{})
_ = interfaces.BeaconBlockBody(&altairBeaconBlockBody{})
)
// altairSignedBeaconBlock is a convenience wrapper around a altair beacon block
@@ -27,7 +27,7 @@ type altairSignedBeaconBlock struct {
// wrappedAltairSignedBeaconBlock is constructor which wraps a protobuf altair block
// with the block wrapper.
func wrappedAltairSignedBeaconBlock(b *eth.SignedBeaconBlockAltair) (block.SignedBeaconBlock, error) {
func wrappedAltairSignedBeaconBlock(b *eth.SignedBeaconBlockAltair) (interfaces.SignedBeaconBlock, error) {
w := altairSignedBeaconBlock{b: b}
if w.IsNil() {
return nil, ErrNilObjectWrapped
@@ -41,7 +41,7 @@ func (w altairSignedBeaconBlock) Signature() []byte {
}
// Block returns the underlying beacon block object.
func (w altairSignedBeaconBlock) Block() block.BeaconBlock {
func (w altairSignedBeaconBlock) Block() interfaces.BeaconBlock {
return altairBeaconBlock{b: w.b.Block}
}
@@ -53,7 +53,7 @@ func (w altairSignedBeaconBlock) IsNil() bool {
// Copy performs a deep copy of the signed beacon block
// object.
func (w altairSignedBeaconBlock) Copy() block.SignedBeaconBlock {
func (w altairSignedBeaconBlock) Copy() interfaces.SignedBeaconBlock {
return altairSignedBeaconBlock{b: eth.CopySignedBeaconBlockAltair(w.b)}
}
@@ -145,7 +145,7 @@ type altairBeaconBlock struct {
// with the block wrapper.
//
// Deprecated: Use WrappedBeaconBlock.
func WrappedAltairBeaconBlock(b *eth.BeaconBlockAltair) (block.BeaconBlock, error) {
func WrappedAltairBeaconBlock(b *eth.BeaconBlockAltair) (interfaces.BeaconBlock, error) {
w := altairBeaconBlock{b: b}
if w.IsNil() {
return nil, ErrNilObjectWrapped
@@ -174,7 +174,7 @@ func (w altairBeaconBlock) StateRoot() []byte {
}
// Body returns the underlying block body.
func (w altairBeaconBlock) Body() block.BeaconBlockBody {
func (w altairBeaconBlock) Body() interfaces.BeaconBlockBody {
return altairBeaconBlockBody{b: w.b.Body}
}
@@ -246,7 +246,7 @@ type altairBeaconBlockBody struct {
// WrappedAltairBeaconBlockBody is constructor which wraps a protobuf altair object
// with the block wrapper.
func WrappedAltairBeaconBlockBody(b *eth.BeaconBlockBodyAltair) (block.BeaconBlockBody, error) {
func WrappedAltairBeaconBlockBody(b *eth.BeaconBlockBodyAltair) (interfaces.BeaconBlockBody, error) {
w := altairBeaconBlockBody{b: b}
if w.IsNil() {
return nil, ErrNilObjectWrapped

View File

@@ -3,7 +3,7 @@ package wrapper
import (
ssz "github.com/ferranbt/fastssz"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/consensus-types/block"
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -13,9 +13,9 @@ import (
)
var (
_ = block.SignedBeaconBlock(&bellatrixSignedBeaconBlock{})
_ = block.BeaconBlock(&bellatrixBeaconBlock{})
_ = block.BeaconBlockBody(&bellatrixBeaconBlockBody{})
_ = interfaces.SignedBeaconBlock(&bellatrixSignedBeaconBlock{})
_ = interfaces.BeaconBlock(&bellatrixBeaconBlock{})
_ = interfaces.BeaconBlockBody(&bellatrixBeaconBlockBody{})
)
// bellatrixSignedBeaconBlock is a convenience wrapper around a Bellatrix blinded beacon block
@@ -26,7 +26,7 @@ type bellatrixSignedBeaconBlock struct {
}
// wrappedBellatrixSignedBeaconBlock is a constructor which wraps a protobuf Bellatrix block with the block wrapper.
func wrappedBellatrixSignedBeaconBlock(b *eth.SignedBeaconBlockBellatrix) (block.SignedBeaconBlock, error) {
func wrappedBellatrixSignedBeaconBlock(b *eth.SignedBeaconBlockBellatrix) (interfaces.SignedBeaconBlock, error) {
w := bellatrixSignedBeaconBlock{b: b}
if w.IsNil() {
return nil, ErrNilObjectWrapped
@@ -40,7 +40,7 @@ func (w bellatrixSignedBeaconBlock) Signature() []byte {
}
// Block returns the underlying beacon block object.
func (w bellatrixSignedBeaconBlock) Block() block.BeaconBlock {
func (w bellatrixSignedBeaconBlock) Block() interfaces.BeaconBlock {
return bellatrixBeaconBlock{b: w.b.Block}
}
@@ -50,7 +50,7 @@ func (w bellatrixSignedBeaconBlock) IsNil() bool {
}
// Copy performs a deep copy of the signed beacon block object.
func (w bellatrixSignedBeaconBlock) Copy() block.SignedBeaconBlock {
func (w bellatrixSignedBeaconBlock) Copy() interfaces.SignedBeaconBlock {
return bellatrixSignedBeaconBlock{b: eth.CopySignedBeaconBlockBellatrix(w.b)}
}
@@ -140,7 +140,7 @@ type bellatrixBeaconBlock struct {
// with the block wrapper.
//
// Deprecated: Use WrappedBeaconBlock.
func WrappedBellatrixBeaconBlock(b *eth.BeaconBlockBellatrix) (block.BeaconBlock, error) {
func WrappedBellatrixBeaconBlock(b *eth.BeaconBlockBellatrix) (interfaces.BeaconBlock, error) {
w := bellatrixBeaconBlock{b: b}
if w.IsNil() {
return nil, ErrNilObjectWrapped
@@ -169,7 +169,7 @@ func (w bellatrixBeaconBlock) StateRoot() []byte {
}
// Body returns the underlying block body.
func (w bellatrixBeaconBlock) Body() block.BeaconBlockBody {
func (w bellatrixBeaconBlock) Body() interfaces.BeaconBlockBody {
return bellatrixBeaconBlockBody{b: w.b.Body}
}
@@ -241,7 +241,7 @@ type bellatrixBeaconBlockBody struct {
// WrappedBellatrixBeaconBlockBody is a constructor which wraps a protobuf bellatrix object
// with the block wrapper.
func WrappedBellatrixBeaconBlockBody(b *eth.BeaconBlockBodyBellatrix) (block.BeaconBlockBody, error) {
func WrappedBellatrixBeaconBlockBody(b *eth.BeaconBlockBodyBellatrix) (interfaces.BeaconBlockBody, error) {
w := bellatrixBeaconBlockBody{b: b}
if w.IsNil() {
return nil, ErrNilObjectWrapped

View File

@@ -3,7 +3,7 @@ package wrapper
import (
ssz "github.com/ferranbt/fastssz"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/consensus-types/block"
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -13,9 +13,9 @@ import (
)
var (
_ = block.SignedBeaconBlock(&Phase0SignedBeaconBlock{})
_ = block.BeaconBlock(&Phase0BeaconBlock{})
_ = block.BeaconBlockBody(&Phase0BeaconBlockBody{})
_ = interfaces.SignedBeaconBlock(&Phase0SignedBeaconBlock{})
_ = interfaces.BeaconBlock(&Phase0BeaconBlock{})
_ = interfaces.BeaconBlockBody(&Phase0BeaconBlockBody{})
)
// Phase0SignedBeaconBlock is a convenience wrapper around a phase 0 beacon block
@@ -27,7 +27,7 @@ type Phase0SignedBeaconBlock struct {
// wrappedPhase0SignedBeaconBlock is constructor which wraps a protobuf phase 0 block
// with the block wrapper.
func wrappedPhase0SignedBeaconBlock(b *eth.SignedBeaconBlock) block.SignedBeaconBlock {
func wrappedPhase0SignedBeaconBlock(b *eth.SignedBeaconBlock) interfaces.SignedBeaconBlock {
return Phase0SignedBeaconBlock{b: b}
}
@@ -37,7 +37,7 @@ func (w Phase0SignedBeaconBlock) Signature() []byte {
}
// Block returns the underlying beacon block object.
func (w Phase0SignedBeaconBlock) Block() block.BeaconBlock {
func (w Phase0SignedBeaconBlock) Block() interfaces.BeaconBlock {
return WrappedPhase0BeaconBlock(w.b.Block)
}
@@ -49,7 +49,7 @@ func (w Phase0SignedBeaconBlock) IsNil() bool {
// Copy performs a deep copy of the signed beacon block
// object.
func (w Phase0SignedBeaconBlock) Copy() block.SignedBeaconBlock {
func (w Phase0SignedBeaconBlock) Copy() interfaces.SignedBeaconBlock {
return wrappedPhase0SignedBeaconBlock(eth.CopySignedBeaconBlock(w.b))
}
@@ -141,7 +141,7 @@ type Phase0BeaconBlock struct {
// with the block wrapper.
//
// Deprecated: Use WrappedBeaconBlock.
func WrappedPhase0BeaconBlock(b *eth.BeaconBlock) block.BeaconBlock {
func WrappedPhase0BeaconBlock(b *eth.BeaconBlock) interfaces.BeaconBlock {
return Phase0BeaconBlock{b: b}
}
@@ -166,7 +166,7 @@ func (w Phase0BeaconBlock) StateRoot() []byte {
}
// Body returns the underlying block body.
func (w Phase0BeaconBlock) Body() block.BeaconBlockBody {
func (w Phase0BeaconBlock) Body() interfaces.BeaconBlockBody {
return WrappedPhase0BeaconBlockBody(w.b.Body)
}
@@ -238,7 +238,7 @@ type Phase0BeaconBlockBody struct {
// WrappedPhase0BeaconBlockBody is constructor which wraps a protobuf phase 0 object
// with the block wrapper.
func WrappedPhase0BeaconBlockBody(b *eth.BeaconBlockBody) block.BeaconBlockBody {
func WrappedPhase0BeaconBlockBody(b *eth.BeaconBlockBody) interfaces.BeaconBlockBody {
return Phase0BeaconBlockBody{b: b}
}

View File

@@ -3,7 +3,7 @@ package wrapper
import (
ssz "github.com/ferranbt/fastssz"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/consensus-types/block"
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -13,9 +13,9 @@ import (
)
var (
_ = block.SignedBeaconBlock(&signedBlindedBeaconBlockBellatrix{})
_ = block.BeaconBlock(&blindedBeaconBlockBellatrix{})
_ = block.BeaconBlockBody(&blindedBeaconBlockBodyBellatrix{})
_ = interfaces.SignedBeaconBlock(&signedBlindedBeaconBlockBellatrix{})
_ = interfaces.BeaconBlock(&blindedBeaconBlockBellatrix{})
_ = interfaces.BeaconBlockBody(&blindedBeaconBlockBodyBellatrix{})
)
// signedBlindedBeaconBlockBellatrix is a convenience wrapper around a Bellatrix blinded beacon block
@@ -26,7 +26,7 @@ type signedBlindedBeaconBlockBellatrix struct {
}
// wrappedBellatrixSignedBlindedBeaconBlock is a constructor which wraps a protobuf Bellatrix blinded block with the block wrapper.
func wrappedBellatrixSignedBlindedBeaconBlock(b *eth.SignedBlindedBeaconBlockBellatrix) (block.SignedBeaconBlock, error) {
func wrappedBellatrixSignedBlindedBeaconBlock(b *eth.SignedBlindedBeaconBlockBellatrix) (interfaces.SignedBeaconBlock, error) {
w := signedBlindedBeaconBlockBellatrix{b: b}
if w.IsNil() {
return nil, ErrNilObjectWrapped
@@ -40,7 +40,7 @@ func (w signedBlindedBeaconBlockBellatrix) Signature() []byte {
}
// Block returns the underlying beacon block object.
func (w signedBlindedBeaconBlockBellatrix) Block() block.BeaconBlock {
func (w signedBlindedBeaconBlockBellatrix) Block() interfaces.BeaconBlock {
return blindedBeaconBlockBellatrix{b: w.b.Block}
}
@@ -50,7 +50,7 @@ func (w signedBlindedBeaconBlockBellatrix) IsNil() bool {
}
// Copy performs a deep copy of the signed beacon block object.
func (w signedBlindedBeaconBlockBellatrix) Copy() block.SignedBeaconBlock {
func (w signedBlindedBeaconBlockBellatrix) Copy() interfaces.SignedBeaconBlock {
return signedBlindedBeaconBlockBellatrix{b: eth.CopySignedBlindedBeaconBlockBellatrix(w.b)}
}
@@ -141,7 +141,7 @@ type blindedBeaconBlockBellatrix struct {
// with the block wrapper.
//
// Deprecated: Use WrappedBeaconBlock.
func WrappedBellatrixBlindedBeaconBlock(b *eth.BlindedBeaconBlockBellatrix) (block.BeaconBlock, error) {
func WrappedBellatrixBlindedBeaconBlock(b *eth.BlindedBeaconBlockBellatrix) (interfaces.BeaconBlock, error) {
w := blindedBeaconBlockBellatrix{b: b}
if w.IsNil() {
return nil, ErrNilObjectWrapped
@@ -170,7 +170,7 @@ func (w blindedBeaconBlockBellatrix) StateRoot() []byte {
}
// Body returns the underlying block body.
func (w blindedBeaconBlockBellatrix) Body() block.BeaconBlockBody {
func (w blindedBeaconBlockBellatrix) Body() interfaces.BeaconBlockBody {
return blindedBeaconBlockBodyBellatrix{b: w.b.Body}
}
@@ -242,7 +242,7 @@ type blindedBeaconBlockBodyBellatrix struct {
// WrappedBellatrixBlindedBeaconBlockBody is a constructor which wraps a protobuf bellatrix object
// with the block wrapper.
func WrappedBellatrixBlindedBeaconBlockBody(b *eth.BlindedBeaconBlockBodyBellatrix) (block.BeaconBlockBody, error) {
func WrappedBellatrixBlindedBeaconBlockBody(b *eth.BlindedBeaconBlockBodyBellatrix) (interfaces.BeaconBlockBody, error) {
w := blindedBeaconBlockBodyBellatrix{b: b}
if w.IsNil() {
return nil, ErrNilObjectWrapped

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/consensus-types/block"
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/runtime/version"
@@ -16,7 +16,7 @@ type BlockMutator struct {
Bellatrix func(beaconBlock *eth.SignedBeaconBlockBellatrix)
}
func (m BlockMutator) Apply(b block.SignedBeaconBlock) error {
func (m BlockMutator) Apply(b interfaces.SignedBeaconBlock) error {
switch b.Version() {
case version.Phase0:
bb, err := b.PbPhase0Block()
@@ -44,7 +44,7 @@ func (m BlockMutator) Apply(b block.SignedBeaconBlock) error {
return errors.Wrap(ErrUnsupportedSignedBeaconBlock, msg)
}
func SetBlockStateRoot(b block.SignedBeaconBlock, sr [32]byte) error {
func SetBlockStateRoot(b interfaces.SignedBeaconBlock, sr [32]byte) 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 block.SignedBeaconBlock, sr [32]byte) error {
}.Apply(b)
}
func SetBlockParentRoot(b block.SignedBeaconBlock, pr [32]byte) error {
func SetBlockParentRoot(b interfaces.SignedBeaconBlock, pr [32]byte) error {
return BlockMutator{
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.ParentRoot = pr[:] },
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.ParentRoot = pr[:] },
@@ -60,7 +60,7 @@ func SetBlockParentRoot(b block.SignedBeaconBlock, pr [32]byte) error {
}.Apply(b)
}
func SetBlockSlot(b block.SignedBeaconBlock, s types.Slot) error {
func SetBlockSlot(b interfaces.SignedBeaconBlock, s types.Slot) error {
return BlockMutator{
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.Slot = s },
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.Slot = s },
@@ -68,7 +68,7 @@ func SetBlockSlot(b block.SignedBeaconBlock, s types.Slot) error {
}.Apply(b)
}
func SetProposerIndex(b block.SignedBeaconBlock, idx types.ValidatorIndex) error {
func SetProposerIndex(b interfaces.SignedBeaconBlock, idx types.ValidatorIndex) error {
return BlockMutator{
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.ProposerIndex = idx },
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.ProposerIndex = idx },