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(
"//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/rpc/apimiddleware:go_default_library", "//beacon-chain/rpc/apimiddleware:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",
"//encoding/ssz/detect:go_default_library", "//encoding/ssz/detect:go_default_library",

View File

@@ -8,7 +8,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/ssz/detect" "github.com/prysmaticlabs/prysm/encoding/ssz/detect"
"github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/io/file"
@@ -25,7 +25,7 @@ type OriginData struct {
sb []byte sb []byte
bb []byte bb []byte
st state.BeaconState st state.BeaconState
b block.SignedBeaconBlock b interfaces.SignedBeaconBlock
cf *detect.VersionedUnmarshaler cf *detect.VersionedUnmarshaler
} }

View File

@@ -64,7 +64,7 @@ go_library(
"//config/features:go_default_library", "//config/features:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//crypto/bls:go_default_library", "//crypto/bls:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",

View File

@@ -11,7 +11,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -47,7 +47,7 @@ type GenesisFetcher interface {
type HeadFetcher interface { type HeadFetcher interface {
HeadSlot() types.Slot HeadSlot() types.Slot
HeadRoot(ctx context.Context) ([]byte, error) HeadRoot(ctx context.Context) ([]byte, error)
HeadBlock(ctx context.Context) (block.SignedBeaconBlock, error) HeadBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error)
HeadState(ctx context.Context) (state.BeaconState, error) HeadState(ctx context.Context) (state.BeaconState, error)
HeadValidatorsIndices(ctx context.Context, epoch types.Epoch) ([]types.ValidatorIndex, error) HeadValidatorsIndices(ctx context.Context, epoch types.Epoch) ([]types.ValidatorIndex, error)
HeadGenesisValidatorsRoot() [32]byte HeadGenesisValidatorsRoot() [32]byte
@@ -163,7 +163,7 @@ func (s *Service) HeadRoot(ctx context.Context) ([]byte, error) {
// HeadBlock returns the head block of the chain. // HeadBlock returns the head block of the chain.
// If the head is nil from service struct, // If the head is nil from service struct,
// it will attempt to get the head block from DB. // it will attempt to get the head block from DB.
func (s *Service) HeadBlock(ctx context.Context) (block.SignedBeaconBlock, error) { func (s *Service) HeadBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error) {
s.headLock.RLock() s.headLock.RLock()
defer s.headLock.RUnlock() defer s.headLock.RUnlock()

View File

@@ -14,7 +14,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
@@ -29,7 +29,7 @@ var ErrUndefinedExecutionEngineError = errors.New("received an undefined ee erro
// notifyForkchoiceUpdate signals execution engine the fork choice updates. Execution engine should: // notifyForkchoiceUpdate signals execution engine the fork choice updates. Execution engine should:
// 1. Re-organizes the execution payload chain and corresponding state to make head_block_hash the head. // 1. Re-organizes the execution payload chain and corresponding state to make head_block_hash the head.
// 2. Applies finality to the execution state: it irreversibly persists the chain of all execution payloads and corresponding state, up to and including finalized_block_hash. // 2. Applies finality to the execution state: it irreversibly persists the chain of all execution payloads and corresponding state, up to and including finalized_block_hash.
func (s *Service) notifyForkchoiceUpdate(ctx context.Context, headState state.BeaconState, headBlk block.BeaconBlock, headRoot [32]byte, finalizedRoot [32]byte) (*enginev1.PayloadIDBytes, error) { func (s *Service) notifyForkchoiceUpdate(ctx context.Context, headState state.BeaconState, headBlk interfaces.BeaconBlock, headRoot [32]byte, finalizedRoot [32]byte) (*enginev1.PayloadIDBytes, error) {
ctx, span := trace.StartSpan(ctx, "blockChain.notifyForkchoiceUpdate") ctx, span := trace.StartSpan(ctx, "blockChain.notifyForkchoiceUpdate")
defer span.End() defer span.End()
@@ -105,7 +105,7 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, headState state.Be
// notifyForkchoiceUpdate signals execution engine on a new payload. // notifyForkchoiceUpdate signals execution engine on a new payload.
// It returns true if the EL has returned VALID for the block // It returns true if the EL has returned VALID for the block
func (s *Service) notifyNewPayload(ctx context.Context, postStateVersion int, func (s *Service) notifyNewPayload(ctx context.Context, postStateVersion int,
postStateHeader *ethpb.ExecutionPayloadHeader, blk block.SignedBeaconBlock) (bool, error) { postStateHeader *ethpb.ExecutionPayloadHeader, blk interfaces.SignedBeaconBlock) (bool, error) {
ctx, span := trace.StartSpan(ctx, "blockChain.notifyNewPayload") ctx, span := trace.StartSpan(ctx, "blockChain.notifyNewPayload")
defer span.End() defer span.End()
@@ -172,7 +172,7 @@ func (s *Service) notifyNewPayload(ctx context.Context, postStateVersion int,
// return True // return True
// //
// return False // return False
func (s *Service) optimisticCandidateBlock(ctx context.Context, blk block.BeaconBlock) error { func (s *Service) optimisticCandidateBlock(ctx context.Context, blk interfaces.BeaconBlock) error {
if blk.Slot()+params.BeaconConfig().SafeSlotsToImportOptimistically <= s.CurrentSlot() { if blk.Slot()+params.BeaconConfig().SafeSlotsToImportOptimistically <= s.CurrentSlot() {
return nil return nil
} }
@@ -181,7 +181,7 @@ func (s *Service) optimisticCandidateBlock(ctx context.Context, blk block.Beacon
if err != nil { if err != nil {
return err return err
} }
if parent == nil { if parent == nil || parent.IsNil() {
return errNilParentInDB return errNilParentInDB
} }
parentIsExecutionBlock, err := blocks.IsExecutionBlock(parent.Block().Body()) parentIsExecutionBlock, err := blocks.IsExecutionBlock(parent.Block().Body())

View File

@@ -16,7 +16,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -59,7 +59,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
blk block.BeaconBlock blk interfaces.BeaconBlock
finalizedRoot [32]byte finalizedRoot [32]byte
newForkchoiceErr error newForkchoiceErr error
errString string errString string
@@ -70,7 +70,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) {
}, },
{ {
name: "phase0 block", name: "phase0 block",
blk: func() block.BeaconBlock { blk: func() interfaces.BeaconBlock {
b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlock{Body: &ethpb.BeaconBlockBody{}}) b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlock{Body: &ethpb.BeaconBlockBody{}})
require.NoError(t, err) require.NoError(t, err)
return b return b
@@ -78,7 +78,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) {
}, },
{ {
name: "altair block", name: "altair block",
blk: func() block.BeaconBlock { blk: func() interfaces.BeaconBlock {
b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockAltair{Body: &ethpb.BeaconBlockBodyAltair{}}) b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockAltair{Body: &ethpb.BeaconBlockBodyAltair{}})
require.NoError(t, err) require.NoError(t, err)
return b return b
@@ -86,7 +86,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) {
}, },
{ {
name: "not execution block", name: "not execution block",
blk: func() block.BeaconBlock { blk: func() interfaces.BeaconBlock {
b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockBellatrix{ b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockBellatrix{
Body: &ethpb.BeaconBlockBodyBellatrix{ Body: &ethpb.BeaconBlockBodyBellatrix{
ExecutionPayload: &v1.ExecutionPayload{ ExecutionPayload: &v1.ExecutionPayload{
@@ -107,7 +107,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) {
}, },
{ {
name: "happy case: finalized root is altair block", name: "happy case: finalized root is altair block",
blk: func() block.BeaconBlock { blk: func() interfaces.BeaconBlock {
b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockBellatrix{ b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockBellatrix{
Body: &ethpb.BeaconBlockBodyBellatrix{ Body: &ethpb.BeaconBlockBodyBellatrix{
ExecutionPayload: &v1.ExecutionPayload{}, ExecutionPayload: &v1.ExecutionPayload{},
@@ -120,7 +120,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) {
}, },
{ {
name: "happy case: finalized root is bellatrix block", name: "happy case: finalized root is bellatrix block",
blk: func() block.BeaconBlock { blk: func() interfaces.BeaconBlock {
b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockBellatrix{ b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockBellatrix{
Body: &ethpb.BeaconBlockBodyBellatrix{ Body: &ethpb.BeaconBlockBodyBellatrix{
ExecutionPayload: &v1.ExecutionPayload{}, ExecutionPayload: &v1.ExecutionPayload{},
@@ -133,7 +133,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) {
}, },
{ {
name: "forkchoice updated with optimistic block", name: "forkchoice updated with optimistic block",
blk: func() block.BeaconBlock { blk: func() interfaces.BeaconBlock {
b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockBellatrix{ b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockBellatrix{
Body: &ethpb.BeaconBlockBodyBellatrix{ Body: &ethpb.BeaconBlockBodyBellatrix{
ExecutionPayload: &v1.ExecutionPayload{}, ExecutionPayload: &v1.ExecutionPayload{},
@@ -147,7 +147,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) {
}, },
{ {
name: "forkchoice updated with invalid block", name: "forkchoice updated with invalid block",
blk: func() block.BeaconBlock { blk: func() interfaces.BeaconBlock {
b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockBellatrix{ b, err := wrapper.WrappedBeaconBlock(&ethpb.BeaconBlockBellatrix{
Body: &ethpb.BeaconBlockBodyBellatrix{ Body: &ethpb.BeaconBlockBodyBellatrix{
ExecutionPayload: &v1.ExecutionPayload{}, ExecutionPayload: &v1.ExecutionPayload{},
@@ -230,7 +230,7 @@ func Test_NotifyNewPayload(t *testing.T) {
name string name string
postState state.BeaconState postState state.BeaconState
isValidPayload bool isValidPayload bool
blk block.SignedBeaconBlock blk interfaces.SignedBeaconBlock
newPayloadErr error newPayloadErr error
errString string errString string
}{ }{
@@ -274,7 +274,7 @@ func Test_NotifyNewPayload(t *testing.T) {
{ {
name: "altair pre state, happy case", name: "altair pre state, happy case",
postState: bellatrixState, postState: bellatrixState,
blk: func() block.SignedBeaconBlock { blk: func() interfaces.SignedBeaconBlock {
blk := &ethpb.SignedBeaconBlockBellatrix{ blk := &ethpb.SignedBeaconBlockBellatrix{
Block: &ethpb.BeaconBlockBellatrix{ Block: &ethpb.BeaconBlockBellatrix{
Body: &ethpb.BeaconBlockBodyBellatrix{ Body: &ethpb.BeaconBlockBodyBellatrix{
@@ -293,7 +293,7 @@ func Test_NotifyNewPayload(t *testing.T) {
{ {
name: "not at merge transition", name: "not at merge transition",
postState: bellatrixState, postState: bellatrixState,
blk: func() block.SignedBeaconBlock { blk: func() interfaces.SignedBeaconBlock {
blk := &ethpb.SignedBeaconBlockBellatrix{ blk := &ethpb.SignedBeaconBlockBellatrix{
Block: &ethpb.BeaconBlockBellatrix{ Block: &ethpb.BeaconBlockBellatrix{
Body: &ethpb.BeaconBlockBodyBellatrix{ Body: &ethpb.BeaconBlockBodyBellatrix{
@@ -319,7 +319,7 @@ func Test_NotifyNewPayload(t *testing.T) {
{ {
name: "happy case", name: "happy case",
postState: bellatrixState, postState: bellatrixState,
blk: func() block.SignedBeaconBlock { blk: func() interfaces.SignedBeaconBlock {
blk := &ethpb.SignedBeaconBlockBellatrix{ blk := &ethpb.SignedBeaconBlockBellatrix{
Block: &ethpb.BeaconBlockBellatrix{ Block: &ethpb.BeaconBlockBellatrix{
Body: &ethpb.BeaconBlockBodyBellatrix{ Body: &ethpb.BeaconBlockBodyBellatrix{
@@ -338,7 +338,7 @@ func Test_NotifyNewPayload(t *testing.T) {
{ {
name: "undefined error from ee", name: "undefined error from ee",
postState: bellatrixState, postState: bellatrixState,
blk: func() block.SignedBeaconBlock { blk: func() interfaces.SignedBeaconBlock {
blk := &ethpb.SignedBeaconBlockBellatrix{ blk := &ethpb.SignedBeaconBlockBellatrix{
Block: &ethpb.BeaconBlockBellatrix{ Block: &ethpb.BeaconBlockBellatrix{
Body: &ethpb.BeaconBlockBodyBellatrix{ Body: &ethpb.BeaconBlockBodyBellatrix{
@@ -453,13 +453,13 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
blk block.BeaconBlock blk interfaces.BeaconBlock
justified block.SignedBeaconBlock justified interfaces.SignedBeaconBlock
err error err error
}{ }{
{ {
name: "deep block", name: "deep block",
blk: func(tt *testing.T) block.BeaconBlock { blk: func(tt *testing.T) interfaces.BeaconBlock {
blk := util.NewBeaconBlockBellatrix() blk := util.NewBeaconBlockBellatrix()
blk.Block.Slot = 1 blk.Block.Slot = 1
blk.Block.ParentRoot = parentRoot[:] blk.Block.ParentRoot = parentRoot[:]
@@ -467,7 +467,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) {
require.NoError(tt, err) require.NoError(tt, err)
return wr return wr
}(t), }(t),
justified: func(tt *testing.T) block.SignedBeaconBlock { justified: func(tt *testing.T) interfaces.SignedBeaconBlock {
blk := util.NewBeaconBlockBellatrix() blk := util.NewBeaconBlockBellatrix()
blk.Block.Slot = 32 blk.Block.Slot = 32
blk.Block.ParentRoot = parentRoot[:] blk.Block.ParentRoot = parentRoot[:]
@@ -479,7 +479,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) {
}, },
{ {
name: "shallow block, Altair justified chkpt", name: "shallow block, Altair justified chkpt",
blk: func(tt *testing.T) block.BeaconBlock { blk: func(tt *testing.T) interfaces.BeaconBlock {
blk := util.NewBeaconBlockAltair() blk := util.NewBeaconBlockAltair()
blk.Block.Slot = 200 blk.Block.Slot = 200
blk.Block.ParentRoot = parentRoot[:] blk.Block.ParentRoot = parentRoot[:]
@@ -487,7 +487,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) {
require.NoError(tt, err) require.NoError(tt, err)
return wr return wr
}(t), }(t),
justified: func(tt *testing.T) block.SignedBeaconBlock { justified: func(tt *testing.T) interfaces.SignedBeaconBlock {
blk := util.NewBeaconBlockAltair() blk := util.NewBeaconBlockAltair()
blk.Block.Slot = 32 blk.Block.Slot = 32
blk.Block.ParentRoot = parentRoot[:] blk.Block.ParentRoot = parentRoot[:]
@@ -499,7 +499,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) {
}, },
{ {
name: "shallow block, Bellatrix justified chkpt without execution", name: "shallow block, Bellatrix justified chkpt without execution",
blk: func(tt *testing.T) block.BeaconBlock { blk: func(tt *testing.T) interfaces.BeaconBlock {
blk := util.NewBeaconBlockBellatrix() blk := util.NewBeaconBlockBellatrix()
blk.Block.Slot = 200 blk.Block.Slot = 200
blk.Block.ParentRoot = parentRoot[:] blk.Block.ParentRoot = parentRoot[:]
@@ -507,7 +507,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) {
require.NoError(tt, err) require.NoError(tt, err)
return wr return wr
}(t), }(t),
justified: func(tt *testing.T) block.SignedBeaconBlock { justified: func(tt *testing.T) interfaces.SignedBeaconBlock {
blk := util.NewBeaconBlockBellatrix() blk := util.NewBeaconBlockBellatrix()
blk.Block.Slot = 32 blk.Block.Slot = 32
blk.Block.ParentRoot = parentRoot[:] blk.Block.ParentRoot = parentRoot[:]

View File

@@ -15,7 +15,7 @@ import (
"github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/features"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1" ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1"
@@ -53,10 +53,10 @@ func (s *Service) UpdateAndSaveHeadWithBalances(ctx context.Context) error {
// This defines the current chain service's view of head. // This defines the current chain service's view of head.
type head struct { type head struct {
slot types.Slot // current head slot. slot types.Slot // current head slot.
root [32]byte // current head root. root [32]byte // current head root.
block block.SignedBeaconBlock // current head block. block interfaces.SignedBeaconBlock // current head block.
state state.BeaconState // current head state. state state.BeaconState // current head state.
} }
// Determined the head from the fork choice service and saves its new data // Determined the head from the fork choice service and saves its new data
@@ -105,7 +105,7 @@ func (s *Service) updateHead(ctx context.Context, balances []uint64) ([32]byte,
// This saves head info to the local service cache, it also saves the // This saves head info to the local service cache, it also saves the
// new head root to the DB. // new head root to the DB.
func (s *Service) saveHead(ctx context.Context, headRoot [32]byte, headBlock block.SignedBeaconBlock, headState state.BeaconState) error { func (s *Service) saveHead(ctx context.Context, headRoot [32]byte, headBlock interfaces.SignedBeaconBlock, headState state.BeaconState) error {
ctx, span := trace.StartSpan(ctx, "blockChain.saveHead") ctx, span := trace.StartSpan(ctx, "blockChain.saveHead")
defer span.End() defer span.End()
@@ -189,7 +189,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte, headBlock blo
// This gets called to update canonical root mapping. It does not save head block // This gets called to update canonical root mapping. It does not save head block
// root in DB. With the inception of initial-sync-cache-state flag, it uses finalized // root in DB. With the inception of initial-sync-cache-state flag, it uses finalized
// check point as anchors to resume sync therefore head is no longer needed to be saved on per slot basis. // check point as anchors to resume sync therefore head is no longer needed to be saved on per slot basis.
func (s *Service) saveHeadNoDB(ctx context.Context, b block.SignedBeaconBlock, r [32]byte, hs state.BeaconState) error { func (s *Service) saveHeadNoDB(ctx context.Context, b interfaces.SignedBeaconBlock, r [32]byte, hs state.BeaconState) error {
if err := helpers.BeaconBlockIsNil(b); err != nil { if err := helpers.BeaconBlockIsNil(b); err != nil {
return err return err
} }
@@ -206,7 +206,7 @@ func (s *Service) saveHeadNoDB(ctx context.Context, b block.SignedBeaconBlock, r
} }
// This sets head view object which is used to track the head slot, root, block and state. // This sets head view object which is used to track the head slot, root, block and state.
func (s *Service) setHead(root [32]byte, block block.SignedBeaconBlock, state state.BeaconState) { func (s *Service) setHead(root [32]byte, block interfaces.SignedBeaconBlock, state state.BeaconState) {
s.headLock.Lock() s.headLock.Lock()
defer s.headLock.Unlock() defer s.headLock.Unlock()
@@ -222,7 +222,7 @@ func (s *Service) setHead(root [32]byte, block block.SignedBeaconBlock, state st
// This sets head view object which is used to track the head slot, root, block and state. The method // This sets head view object which is used to track the head slot, root, block and state. The method
// assumes that state being passed into the method will not be modified by any other alternate // assumes that state being passed into the method will not be modified by any other alternate
// caller which holds the state's reference. // caller which holds the state's reference.
func (s *Service) setHeadInitialSync(root [32]byte, block block.SignedBeaconBlock, state state.BeaconState) { func (s *Service) setHeadInitialSync(root [32]byte, block interfaces.SignedBeaconBlock, state state.BeaconState) {
s.headLock.Lock() s.headLock.Lock()
defer s.headLock.Unlock() defer s.headLock.Unlock()
@@ -255,7 +255,7 @@ func (s *Service) headRoot() [32]byte {
// This returns the head block. // This returns the head block.
// It does a full copy on head block for immutability. // It does a full copy on head block for immutability.
// This is a lock free version. // This is a lock free version.
func (s *Service) headBlock() block.SignedBeaconBlock { func (s *Service) headBlock() interfaces.SignedBeaconBlock {
return s.head.block.Copy() return s.head.block.Copy()
} }

View File

@@ -5,13 +5,13 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
) )
var errBlockNotFoundInCacheOrDB = errors.New("block not found in cache or db") var errBlockNotFoundInCacheOrDB = errors.New("block not found in cache or db")
// This saves a beacon block to the initial sync blocks cache. // This saves a beacon block to the initial sync blocks cache.
func (s *Service) saveInitSyncBlock(r [32]byte, b block.SignedBeaconBlock) { func (s *Service) saveInitSyncBlock(r [32]byte, b interfaces.SignedBeaconBlock) {
s.initSyncBlocksLock.Lock() s.initSyncBlocksLock.Lock()
defer s.initSyncBlocksLock.Unlock() defer s.initSyncBlocksLock.Unlock()
s.initSyncBlocks[r] = b s.initSyncBlocks[r] = b
@@ -36,7 +36,7 @@ func (s *Service) hasBlockInInitSyncOrDB(ctx context.Context, r [32]byte) bool {
// Returns block for a given root `r` from either the initial sync blocks cache or the DB. // Returns block for a given root `r` from either the initial sync blocks cache or the DB.
// Error is returned if the block is not found in either cache or DB. // Error is returned if the block is not found in either cache or DB.
func (s *Service) getBlock(ctx context.Context, r [32]byte) (block.SignedBeaconBlock, error) { func (s *Service) getBlock(ctx context.Context, r [32]byte) (interfaces.SignedBeaconBlock, error) {
s.initSyncBlocksLock.RLock() s.initSyncBlocksLock.RLock()
// Check cache first because it's faster. // Check cache first because it's faster.
@@ -57,11 +57,11 @@ func (s *Service) getBlock(ctx context.Context, r [32]byte) (block.SignedBeaconB
// This retrieves all the beacon blocks from the initial sync blocks cache, the returned // This retrieves all the beacon blocks from the initial sync blocks cache, the returned
// blocks are unordered. // blocks are unordered.
func (s *Service) getInitSyncBlocks() []block.SignedBeaconBlock { func (s *Service) getInitSyncBlocks() []interfaces.SignedBeaconBlock {
s.initSyncBlocksLock.RLock() s.initSyncBlocksLock.RLock()
defer s.initSyncBlocksLock.RUnlock() defer s.initSyncBlocksLock.RUnlock()
blks := make([]block.SignedBeaconBlock, 0, len(s.initSyncBlocks)) blks := make([]interfaces.SignedBeaconBlock, 0, len(s.initSyncBlocks))
for _, b := range s.initSyncBlocks { for _, b := range s.initSyncBlocks {
blks = append(blks, b) blks = append(blks, b)
} }
@@ -72,5 +72,5 @@ func (s *Service) getInitSyncBlocks() []block.SignedBeaconBlock {
func (s *Service) clearInitSyncBlocks() { func (s *Service) clearInitSyncBlocks() {
s.initSyncBlocksLock.Lock() s.initSyncBlocksLock.Lock()
defer s.initSyncBlocksLock.Unlock() defer s.initSyncBlocksLock.Unlock()
s.initSyncBlocks = make(map[[32]byte]block.SignedBeaconBlock) s.initSyncBlocks = make(map[[32]byte]interfaces.SignedBeaconBlock)
} }

View File

@@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/runtime/version" "github.com/prysmaticlabs/prysm/runtime/version"
@@ -18,7 +18,7 @@ import (
var log = logrus.WithField("prefix", "blockchain") var log = logrus.WithField("prefix", "blockchain")
// logs state transition related data every slot. // logs state transition related data every slot.
func logStateTransitionData(b block.BeaconBlock) error { func logStateTransitionData(b interfaces.BeaconBlock) error {
log := log.WithField("slot", b.Slot()) log := log.WithField("slot", b.Slot())
if len(b.Body().Attestations()) > 0 { if len(b.Body().Attestations()) > 0 {
log = log.WithField("attestations", len(b.Body().Attestations())) log = log.WithField("attestations", len(b.Body().Attestations()))
@@ -54,7 +54,7 @@ func logStateTransitionData(b block.BeaconBlock) error {
return nil return nil
} }
func logBlockSyncStatus(block block.BeaconBlock, blockRoot [32]byte, finalized *ethpb.Checkpoint, receivedTime time.Time, genesisTime uint64) error { func logBlockSyncStatus(block interfaces.BeaconBlock, blockRoot [32]byte, finalized *ethpb.Checkpoint, receivedTime time.Time, genesisTime uint64) error {
startTime, err := slots.ToTime(genesisTime, block.Slot()) startTime, err := slots.ToTime(genesisTime, block.Slot())
if err != nil { if err != nil {
return err return err

View File

@@ -3,7 +3,7 @@ package blockchain
import ( import (
"testing" "testing"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -25,7 +25,7 @@ func Test_logStateTransitionData(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
tests := []struct { tests := []struct {
name string name string
b block.BeaconBlock b interfaces.BeaconBlock
want string want string
}{ }{
{name: "empty block body", {name: "empty block body",

View File

@@ -10,7 +10,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -298,7 +298,7 @@ func reportEpochMetrics(ctx context.Context, postState, headState state.BeaconSt
return nil return nil
} }
func reportAttestationInclusion(blk block.BeaconBlock) { func reportAttestationInclusion(blk interfaces.BeaconBlock) {
for _, att := range blk.Body().Attestations() { for _, att := range blk.Body().Attestations() {
attestationInclusionDelay.Observe(float64(blk.Slot() - att.Data.Slot)) attestationInclusionDelay.Observe(float64(blk.Slot() - att.Data.Slot))
} }

View File

@@ -12,7 +12,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
@@ -37,7 +37,7 @@ import (
// assert pow_parent is not None // assert pow_parent is not None
// # Check if `pow_block` is a valid terminal PoW block // # Check if `pow_block` is a valid terminal PoW block
// assert is_valid_terminal_pow_block(pow_block, pow_parent) // assert is_valid_terminal_pow_block(pow_block, pow_parent)
func (s *Service) validateMergeBlock(ctx context.Context, b block.SignedBeaconBlock) error { func (s *Service) validateMergeBlock(ctx context.Context, b interfaces.SignedBeaconBlock) error {
if err := helpers.BeaconBlockIsNil(b); err != nil { if err := helpers.BeaconBlockIsNil(b); err != nil {
return err return err
} }

View File

@@ -16,7 +16,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/features"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/crypto/bls"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/monitoring/tracing"
@@ -88,7 +88,7 @@ var initialSyncBlockCacheSize = uint64(2 * params.BeaconConfig().SlotsPerEpoch)
// ancestor_at_finalized_slot = get_ancestor(store, store.justified_checkpoint.root, finalized_slot) // ancestor_at_finalized_slot = get_ancestor(store, store.justified_checkpoint.root, finalized_slot)
// if ancestor_at_finalized_slot != store.finalized_checkpoint.root: // if ancestor_at_finalized_slot != store.finalized_checkpoint.root:
// store.justified_checkpoint = state.current_justified_checkpoint // store.justified_checkpoint = state.current_justified_checkpoint
func (s *Service) onBlock(ctx context.Context, signed block.SignedBeaconBlock, blockRoot [32]byte) error { func (s *Service) onBlock(ctx context.Context, signed interfaces.SignedBeaconBlock, blockRoot [32]byte) error {
ctx, span := trace.StartSpan(ctx, "blockChain.onBlock") ctx, span := trace.StartSpan(ctx, "blockChain.onBlock")
defer span.End() defer span.End()
if err := helpers.BeaconBlockIsNil(signed); err != nil { if err := helpers.BeaconBlockIsNil(signed); err != nil {
@@ -316,7 +316,7 @@ func getStateVersionAndPayload(st state.BeaconState) (int, *ethpb.ExecutionPaylo
return preStateVersion, preStateHeader, nil return preStateVersion, preStateHeader, nil
} }
func (s *Service) onBlockBatch(ctx context.Context, blks []block.SignedBeaconBlock, func (s *Service) onBlockBatch(ctx context.Context, blks []interfaces.SignedBeaconBlock,
blockRoots [][32]byte) ([]*ethpb.Checkpoint, []*ethpb.Checkpoint, error) { blockRoots [][32]byte) ([]*ethpb.Checkpoint, []*ethpb.Checkpoint, error) {
ctx, span := trace.StartSpan(ctx, "blockChain.onBlockBatch") ctx, span := trace.StartSpan(ctx, "blockChain.onBlockBatch")
defer span.End() defer span.End()
@@ -449,7 +449,7 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []block.SignedBeaconBlo
// handles a block after the block's batch has been verified, where we can save blocks // handles a block after the block's batch has been verified, where we can save blocks
// their state summaries and split them off to relative hot/cold storage. // their state summaries and split them off to relative hot/cold storage.
func (s *Service) handleBlockAfterBatchVerify(ctx context.Context, signed block.SignedBeaconBlock, func (s *Service) handleBlockAfterBatchVerify(ctx context.Context, signed interfaces.SignedBeaconBlock,
blockRoot [32]byte, fCheckpoint, jCheckpoint *ethpb.Checkpoint) error { blockRoot [32]byte, fCheckpoint, jCheckpoint *ethpb.Checkpoint) error {
if err := s.cfg.BeaconDB.SaveStateSummary(ctx, &ethpb.StateSummary{ if err := s.cfg.BeaconDB.SaveStateSummary(ctx, &ethpb.StateSummary{
@@ -535,7 +535,7 @@ func (s *Service) handleEpochBoundary(ctx context.Context, postState state.Beaco
// This feeds in the block and block's attestations to fork choice store. It's allows fork choice store // This feeds in the block and block's attestations to fork choice store. It's allows fork choice store
// to gain information on the most current chain. // to gain information on the most current chain.
func (s *Service) insertBlockAndAttestationsToForkChoiceStore(ctx context.Context, blk block.BeaconBlock, root [32]byte, func (s *Service) insertBlockAndAttestationsToForkChoiceStore(ctx context.Context, blk interfaces.BeaconBlock, root [32]byte,
st state.BeaconState) error { st state.BeaconState) error {
ctx, span := trace.StartSpan(ctx, "blockChain.insertBlockAndAttestationsToForkChoiceStore") ctx, span := trace.StartSpan(ctx, "blockChain.insertBlockAndAttestationsToForkChoiceStore")
defer span.End() defer span.End()
@@ -560,7 +560,7 @@ func (s *Service) insertBlockAndAttestationsToForkChoiceStore(ctx context.Contex
return nil return nil
} }
func (s *Service) insertBlockToForkChoiceStore(ctx context.Context, blk block.BeaconBlock, func (s *Service) insertBlockToForkChoiceStore(ctx context.Context, blk interfaces.BeaconBlock,
root [32]byte, fCheckpoint, jCheckpoint *ethpb.Checkpoint) error { root [32]byte, fCheckpoint, jCheckpoint *ethpb.Checkpoint) error {
if err := s.fillInForkChoiceMissingBlocks(ctx, blk, fCheckpoint, jCheckpoint); err != nil { if err := s.fillInForkChoiceMissingBlocks(ctx, blk, fCheckpoint, jCheckpoint); err != nil {
return err return err
@@ -577,7 +577,7 @@ func (s *Service) insertBlockToForkChoiceStore(ctx context.Context, blk block.Be
fCheckpoint.Epoch) fCheckpoint.Epoch)
} }
func getBlockPayloadHash(blk block.BeaconBlock) ([32]byte, error) { func getBlockPayloadHash(blk interfaces.BeaconBlock) ([32]byte, error) {
payloadHash := [32]byte{} payloadHash := [32]byte{}
if blocks.IsPreBellatrixVersion(blk.Version()) { if blocks.IsPreBellatrixVersion(blk.Version()) {
return payloadHash, nil return payloadHash, nil
@@ -591,7 +591,7 @@ func getBlockPayloadHash(blk block.BeaconBlock) ([32]byte, error) {
// This saves post state info to DB or cache. This also saves post state info to fork choice store. // This saves post state info to DB or cache. This also saves post state info to fork choice store.
// Post state info consists of processed block and state. Do not call this method unless the block and state are verified. // Post state info consists of processed block and state. Do not call this method unless the block and state are verified.
func (s *Service) savePostStateInfo(ctx context.Context, r [32]byte, b block.SignedBeaconBlock, st state.BeaconState) error { func (s *Service) savePostStateInfo(ctx context.Context, r [32]byte, b interfaces.SignedBeaconBlock, st state.BeaconState) error {
ctx, span := trace.StartSpan(ctx, "blockChain.savePostStateInfo") ctx, span := trace.StartSpan(ctx, "blockChain.savePostStateInfo")
defer span.End() defer span.End()
if err := s.cfg.BeaconDB.SaveBlock(ctx, b); err != nil { if err := s.cfg.BeaconDB.SaveBlock(ctx, b); err != nil {
@@ -605,7 +605,7 @@ func (s *Service) savePostStateInfo(ctx context.Context, r [32]byte, b block.Sig
// This removes the attestations from the mem pool. It will only remove the attestations if input root `r` is canonical, // This removes the attestations from the mem pool. It will only remove the attestations if input root `r` is canonical,
// meaning the block `b` is part of the canonical chain. // meaning the block `b` is part of the canonical chain.
func (s *Service) pruneCanonicalAttsFromPool(ctx context.Context, r [32]byte, b block.SignedBeaconBlock) error { func (s *Service) pruneCanonicalAttsFromPool(ctx context.Context, r [32]byte, b interfaces.SignedBeaconBlock) error {
if !features.Get().CorrectlyPruneCanonicalAtts { if !features.Get().CorrectlyPruneCanonicalAtts {
return nil return nil
} }
@@ -634,7 +634,7 @@ func (s *Service) pruneCanonicalAttsFromPool(ctx context.Context, r [32]byte, b
} }
// validateMergeTransitionBlock validates the merge transition block. // validateMergeTransitionBlock validates the merge transition block.
func (s *Service) validateMergeTransitionBlock(ctx context.Context, stateVersion int, stateHeader *ethpb.ExecutionPayloadHeader, blk block.SignedBeaconBlock) error { func (s *Service) validateMergeTransitionBlock(ctx context.Context, stateVersion int, stateHeader *ethpb.ExecutionPayloadHeader, blk interfaces.SignedBeaconBlock) error {
// Skip validation if block is older than Bellatrix. // Skip validation if block is older than Bellatrix.
if blocks.IsPreBellatrixVersion(blk.Block().Version()) { if blocks.IsPreBellatrixVersion(blk.Block().Version()) {
return nil return nil

View File

@@ -9,7 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
mathutil "github.com/prysmaticlabs/prysm/math" mathutil "github.com/prysmaticlabs/prysm/math"
@@ -27,7 +27,7 @@ func (s *Service) CurrentSlot() types.Slot {
// getBlockPreState returns the pre state of an incoming block. It uses the parent root of the block // getBlockPreState returns the pre state of an incoming block. It uses the parent root of the block
// to retrieve the state in DB. It verifies the pre state's validity and the incoming block // to retrieve the state in DB. It verifies the pre state's validity and the incoming block
// is in the correct time window. // is in the correct time window.
func (s *Service) getBlockPreState(ctx context.Context, b block.BeaconBlock) (state.BeaconState, error) { func (s *Service) getBlockPreState(ctx context.Context, b interfaces.BeaconBlock) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "blockChain.getBlockPreState") ctx, span := trace.StartSpan(ctx, "blockChain.getBlockPreState")
defer span.End() defer span.End()
@@ -58,7 +58,7 @@ func (s *Service) getBlockPreState(ctx context.Context, b block.BeaconBlock) (st
} }
// verifyBlkPreState validates input block has a valid pre-state. // verifyBlkPreState validates input block has a valid pre-state.
func (s *Service) verifyBlkPreState(ctx context.Context, b block.BeaconBlock) error { func (s *Service) verifyBlkPreState(ctx context.Context, b interfaces.BeaconBlock) error {
ctx, span := trace.StartSpan(ctx, "blockChain.verifyBlkPreState") ctx, span := trace.StartSpan(ctx, "blockChain.verifyBlkPreState")
defer span.End() defer span.End()
@@ -125,7 +125,7 @@ func (s *Service) VerifyFinalizedBlkDescendant(ctx context.Context, root [32]byt
// verifyBlkFinalizedSlot validates input block is not less than or equal // verifyBlkFinalizedSlot validates input block is not less than or equal
// to current finalized slot. // to current finalized slot.
func (s *Service) verifyBlkFinalizedSlot(b block.BeaconBlock) error { func (s *Service) verifyBlkFinalizedSlot(b interfaces.BeaconBlock) error {
finalized := s.store.FinalizedCheckpt() finalized := s.store.FinalizedCheckpt()
if finalized == nil { if finalized == nil {
return errNilFinalizedInStore return errNilFinalizedInStore
@@ -331,9 +331,9 @@ func (s *Service) ancestorByDB(ctx context.Context, r [32]byte, slot types.Slot)
// This retrieves missing blocks from DB (ie. the blocks that couldn't be received over sync) and inserts them to fork choice store. // This retrieves missing blocks from DB (ie. the blocks that couldn't be received over sync) and inserts them to fork choice store.
// This is useful for block tree visualizer and additional vote accounting. // This is useful for block tree visualizer and additional vote accounting.
func (s *Service) fillInForkChoiceMissingBlocks(ctx context.Context, blk block.BeaconBlock, func (s *Service) fillInForkChoiceMissingBlocks(ctx context.Context, blk interfaces.BeaconBlock,
fCheckpoint, jCheckpoint *ethpb.Checkpoint) error { fCheckpoint, jCheckpoint *ethpb.Checkpoint) error {
pendingNodes := make([]block.BeaconBlock, 0) pendingNodes := make([]interfaces.BeaconBlock, 0)
pendingRoots := make([][32]byte, 0) pendingRoots := make([][32]byte, 0)
parentRoot := bytesutil.ToBytes32(blk.ParentRoot()) parentRoot := bytesutil.ToBytes32(blk.ParentRoot())

View File

@@ -26,7 +26,7 @@ import (
"github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/features"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -298,7 +298,7 @@ func TestStore_OnBlockBatch_ProtoArray(t *testing.T) {
bState := st.Copy() bState := st.Copy()
var blks []block.SignedBeaconBlock var blks []interfaces.SignedBeaconBlock
var blkRoots [][32]byte var blkRoots [][32]byte
var firstState state.BeaconState var firstState state.BeaconState
for i := 1; i < 10; i++ { for i := 1; i < 10; i++ {
@@ -362,7 +362,7 @@ func TestStore_OnBlockBatch_DoublyLinkedTree(t *testing.T) {
bState := st.Copy() bState := st.Copy()
var blks []block.SignedBeaconBlock var blks []interfaces.SignedBeaconBlock
var blkRoots [][32]byte var blkRoots [][32]byte
var firstState state.BeaconState var firstState state.BeaconState
for i := 1; i < 10; i++ { for i := 1; i < 10; i++ {
@@ -419,7 +419,7 @@ func TestStore_OnBlockBatch_NotifyNewPayload(t *testing.T) {
st, keys := util.DeterministicGenesisState(t, 64) st, keys := util.DeterministicGenesisState(t, 64)
bState := st.Copy() bState := st.Copy()
var blks []block.SignedBeaconBlock var blks []interfaces.SignedBeaconBlock
var blkRoots [][32]byte var blkRoots [][32]byte
var firstState state.BeaconState var firstState state.BeaconState
blkCount := 4 blkCount := 4

View File

@@ -6,7 +6,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/monitoring/tracing"
"github.com/prysmaticlabs/prysm/time" "github.com/prysmaticlabs/prysm/time"
@@ -19,8 +19,8 @@ var epochsSinceFinalitySaveHotStateDB = types.Epoch(100)
// BlockReceiver interface defines the methods of chain service for receiving and processing new blocks. // BlockReceiver interface defines the methods of chain service for receiving and processing new blocks.
type BlockReceiver interface { type BlockReceiver interface {
ReceiveBlock(ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error ReceiveBlock(ctx context.Context, block interfaces.SignedBeaconBlock, blockRoot [32]byte) error
ReceiveBlockBatch(ctx context.Context, blocks []block.SignedBeaconBlock, blkRoots [][32]byte) error ReceiveBlockBatch(ctx context.Context, blocks []interfaces.SignedBeaconBlock, blkRoots [][32]byte) error
HasInitSyncBlock(root [32]byte) bool HasInitSyncBlock(root [32]byte) bool
} }
@@ -29,7 +29,7 @@ type BlockReceiver interface {
// 1. Validate block, apply state transition and update check points // 1. Validate block, apply state transition and update check points
// 2. Apply fork choice to the processed block // 2. Apply fork choice to the processed block
// 3. Save latest head info // 3. Save latest head info
func (s *Service) ReceiveBlock(ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error { func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.SignedBeaconBlock, blockRoot [32]byte) error {
ctx, span := trace.StartSpan(ctx, "blockChain.ReceiveBlock") ctx, span := trace.StartSpan(ctx, "blockChain.ReceiveBlock")
defer span.End() defer span.End()
receivedTime := time.Now() receivedTime := time.Now()
@@ -74,7 +74,7 @@ func (s *Service) ReceiveBlock(ctx context.Context, block block.SignedBeaconBloc
// ReceiveBlockBatch processes the whole block batch at once, assuming the block batch is linear ,transitioning // ReceiveBlockBatch processes the whole block batch at once, assuming the block batch is linear ,transitioning
// the state, performing batch verification of all collected signatures and then performing the appropriate // the state, performing batch verification of all collected signatures and then performing the appropriate
// actions for a block post-transition. // actions for a block post-transition.
func (s *Service) ReceiveBlockBatch(ctx context.Context, blocks []block.SignedBeaconBlock, blkRoots [][32]byte) error { func (s *Service) ReceiveBlockBatch(ctx context.Context, blocks []interfaces.SignedBeaconBlock, blkRoots [][32]byte) error {
ctx, span := trace.StartSpan(ctx, "blockChain.ReceiveBlockBatch") ctx, span := trace.StartSpan(ctx, "blockChain.ReceiveBlockBatch")
defer span.End() defer span.End()
@@ -133,7 +133,7 @@ func (s *Service) HasInitSyncBlock(root [32]byte) bool {
return s.hasInitSyncBlock(root) return s.hasInitSyncBlock(root)
} }
func (s *Service) handlePostBlockOperations(b block.BeaconBlock) error { func (s *Service) handlePostBlockOperations(b interfaces.BeaconBlock) error {
// Delete the processed block attestations from attestation pool. // Delete the processed block attestations from attestation pool.
if err := s.deletePoolAtts(b.Body().Attestations()); err != nil { if err := s.deletePoolAtts(b.Body().Attestations()); err != nil {
return err return err

View File

@@ -13,7 +13,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits" "github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -267,7 +267,7 @@ func TestService_ReceiveBlockBatch(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
wsb, err := wrapper.WrappedSignedBeaconBlock(tt.args.block) wsb, err := wrapper.WrappedSignedBeaconBlock(tt.args.block)
require.NoError(t, err) require.NoError(t, err)
blks := []block.SignedBeaconBlock{wsb} blks := []interfaces.SignedBeaconBlock{wsb}
roots := [][32]byte{root} roots := [][32]byte{root}
err = s.ReceiveBlockBatch(ctx, blks, roots) err = s.ReceiveBlockBatch(ctx, blks, roots)
if tt.wantedErr != "" { if tt.wantedErr != "" {

View File

@@ -33,7 +33,7 @@ import (
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/features"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -60,7 +60,7 @@ type Service struct {
nextEpochBoundarySlot types.Slot nextEpochBoundarySlot types.Slot
boundaryRoots [][32]byte boundaryRoots [][32]byte
checkpointStateCache *cache.CheckpointStateCache checkpointStateCache *cache.CheckpointStateCache
initSyncBlocks map[[32]byte]block.SignedBeaconBlock initSyncBlocks map[[32]byte]interfaces.SignedBeaconBlock
initSyncBlocksLock sync.RWMutex initSyncBlocksLock sync.RWMutex
justifiedBalances *stateBalanceCache justifiedBalances *stateBalanceCache
wsVerifier *WeakSubjectivityVerifier wsVerifier *WeakSubjectivityVerifier
@@ -99,7 +99,7 @@ func NewService(ctx context.Context, opts ...Option) (*Service, error) {
cancel: cancel, cancel: cancel,
boundaryRoots: [][32]byte{}, boundaryRoots: [][32]byte{},
checkpointStateCache: cache.NewCheckpointStateCache(), checkpointStateCache: cache.NewCheckpointStateCache(),
initSyncBlocks: make(map[[32]byte]block.SignedBeaconBlock), initSyncBlocks: make(map[[32]byte]interfaces.SignedBeaconBlock),
cfg: &config{}, cfg: &config{},
store: &store.Store{}, store: &store.Store{},
} }
@@ -203,7 +203,7 @@ func (s *Service) StartFromSavedState(saved state.BeaconState) error {
if err != nil { if err != nil {
return errors.Wrap(err, "could not get finalized checkpoint block") return errors.Wrap(err, "could not get finalized checkpoint block")
} }
if fb == nil { if fb == nil || fb.IsNil() {
return errNilFinalizedInStore return errNilFinalizedInStore
} }
payloadHash, err := getBlockPayloadHash(fb.Block()) payloadHash, err := getBlockPayloadHash(fb.Block())

View File

@@ -29,7 +29,7 @@ import (
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -542,7 +542,7 @@ func TestServiceStop_SaveCachedBlocks(t *testing.T) {
cfg: &config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)}, cfg: &config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)},
ctx: ctx, ctx: ctx,
cancel: cancel, cancel: cancel,
initSyncBlocks: make(map[[32]byte]block.SignedBeaconBlock), initSyncBlocks: make(map[[32]byte]interfaces.SignedBeaconBlock),
} }
b := util.NewBeaconBlock() b := util.NewBeaconBlock()
r, err := b.Block.HashTreeRoot() r, err := b.Block.HashTreeRoot()

View File

@@ -22,7 +22,7 @@ go_library(
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1:go_default_library",

View File

@@ -21,7 +21,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -47,10 +47,10 @@ type ChainService struct {
InitSyncBlockRoots map[[32]byte]bool InitSyncBlockRoots map[[32]byte]bool
DB db.Database DB db.Database
State state.BeaconState State state.BeaconState
Block block.SignedBeaconBlock Block interfaces.SignedBeaconBlock
VerifyBlkDescendantErr error VerifyBlkDescendantErr error
stateNotifier statefeed.Notifier stateNotifier statefeed.Notifier
BlocksReceived []block.SignedBeaconBlock BlocksReceived []interfaces.SignedBeaconBlock
SyncCommitteeIndices []types.CommitteeIndex SyncCommitteeIndices []types.CommitteeIndex
blockNotifier blockfeed.Notifier blockNotifier blockfeed.Notifier
opNotifier opfeed.Notifier opNotifier opfeed.Notifier
@@ -165,7 +165,7 @@ func (mon *MockOperationNotifier) OperationFeed() *event.Feed {
} }
// ReceiveBlockInitialSync mocks ReceiveBlockInitialSync method in chain service. // ReceiveBlockInitialSync mocks ReceiveBlockInitialSync method in chain service.
func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block block.SignedBeaconBlock, _ [32]byte) error { func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block interfaces.SignedBeaconBlock, _ [32]byte) error {
if s.State == nil { if s.State == nil {
return ErrNilState return ErrNilState
} }
@@ -192,7 +192,7 @@ func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block block.
} }
// ReceiveBlockBatch processes blocks in batches from initial-sync. // ReceiveBlockBatch processes blocks in batches from initial-sync.
func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []block.SignedBeaconBlock, _ [][32]byte) error { func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []interfaces.SignedBeaconBlock, _ [][32]byte) error {
if s.State == nil { if s.State == nil {
return ErrNilState return ErrNilState
} }
@@ -221,7 +221,7 @@ func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []block.Signe
} }
// ReceiveBlock mocks ReceiveBlock method in chain service. // ReceiveBlock mocks ReceiveBlock method in chain service.
func (s *ChainService) ReceiveBlock(ctx context.Context, block block.SignedBeaconBlock, _ [32]byte) error { func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.SignedBeaconBlock, _ [32]byte) error {
if s.ReceiveBlockMockErr != nil { if s.ReceiveBlockMockErr != nil {
return s.ReceiveBlockMockErr return s.ReceiveBlockMockErr
} }
@@ -267,7 +267,7 @@ func (s *ChainService) HeadRoot(_ context.Context) ([]byte, error) {
} }
// HeadBlock mocks HeadBlock method in chain service. // HeadBlock mocks HeadBlock method in chain service.
func (s *ChainService) HeadBlock(context.Context) (block.SignedBeaconBlock, error) { func (s *ChainService) HeadBlock(context.Context) (interfaces.SignedBeaconBlock, error) {
return s.Block, nil return s.Block, nil
} }

View File

@@ -32,7 +32,7 @@ go_library(
"//beacon-chain/state/v2:go_default_library", "//beacon-chain/state/v2:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//crypto/bls:go_default_library", "//crypto/bls:go_default_library",
"//crypto/hash:go_default_library", "//crypto/hash:go_default_library",

View File

@@ -11,7 +11,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/attestation" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/attestation"
@@ -23,7 +23,7 @@ import (
func ProcessAttestationsNoVerifySignature( func ProcessAttestationsNoVerifySignature(
ctx context.Context, ctx context.Context,
beaconState state.BeaconState, beaconState state.BeaconState,
b block.SignedBeaconBlock, b interfaces.SignedBeaconBlock,
) (state.BeaconState, error) { ) (state.BeaconState, error) {
if err := helpers.BeaconBlockIsNil(b); err != nil { if err := helpers.BeaconBlockIsNil(b); err != nil {
return nil, err return nil, err

View File

@@ -31,7 +31,7 @@ go_library(
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//container/slice:go_default_library", "//container/slice:go_default_library",

View File

@@ -10,7 +10,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/crypto/bls"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -23,7 +23,7 @@ import (
func ProcessAttestationsNoVerifySignature( func ProcessAttestationsNoVerifySignature(
ctx context.Context, ctx context.Context,
beaconState state.BeaconState, beaconState state.BeaconState,
b block.SignedBeaconBlock, b interfaces.SignedBeaconBlock,
) (state.BeaconState, error) { ) (state.BeaconState, error) {
if err := helpers.BeaconBlockIsNil(b); err != nil { if err := helpers.BeaconBlockIsNil(b); err != nil {
return nil, err return nil, err

View File

@@ -8,7 +8,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
) )
@@ -41,7 +41,7 @@ import (
func ProcessBlockHeader( func ProcessBlockHeader(
ctx context.Context, ctx context.Context,
beaconState state.BeaconState, beaconState state.BeaconState,
block block.SignedBeaconBlock, block interfaces.SignedBeaconBlock,
) (state.BeaconState, error) { ) (state.BeaconState, error) {
if err := helpers.BeaconBlockIsNil(block); err != nil { if err := helpers.BeaconBlockIsNil(block); err != nil {
return nil, err return nil, err

View File

@@ -8,7 +8,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/encoding/ssz" "github.com/prysmaticlabs/prysm/encoding/ssz"
@@ -47,7 +47,7 @@ func IsMergeTransitionComplete(st state.BeaconState) (bool, error) {
// IsMergeTransitionBlockUsingPreStatePayloadHeader returns true if the input block is the terminal merge block. // IsMergeTransitionBlockUsingPreStatePayloadHeader returns true if the input block is the terminal merge block.
// Terminal merge block must be associated with an empty payload header. // Terminal merge block must be associated with an empty payload header.
// This assumes the header `h` is referenced as the parent state for block body `body. // This assumes the header `h` is referenced as the parent state for block body `body.
func IsMergeTransitionBlockUsingPreStatePayloadHeader(h *ethpb.ExecutionPayloadHeader, body block.BeaconBlockBody) (bool, error) { func IsMergeTransitionBlockUsingPreStatePayloadHeader(h *ethpb.ExecutionPayloadHeader, body interfaces.BeaconBlockBody) (bool, error) {
if h == nil || body == nil { if h == nil || body == nil {
return false, errors.New("nil header or block body") return false, errors.New("nil header or block body")
} }
@@ -62,7 +62,7 @@ func IsMergeTransitionBlockUsingPreStatePayloadHeader(h *ethpb.ExecutionPayloadH
// Spec code: // Spec code:
// def is_execution_block(block: BeaconBlock) -> bool: // def is_execution_block(block: BeaconBlock) -> bool:
// return block.body.execution_payload != ExecutionPayload() // return block.body.execution_payload != ExecutionPayload()
func IsExecutionBlock(body block.BeaconBlockBody) (bool, error) { func IsExecutionBlock(body interfaces.BeaconBlockBody) (bool, error) {
if body == nil { if body == nil {
return false, errors.New("nil block body") return false, errors.New("nil block body")
} }
@@ -83,7 +83,7 @@ func IsExecutionBlock(body block.BeaconBlockBody) (bool, error) {
// Spec code: // Spec code:
// def is_execution_enabled(state: BeaconState, body: BeaconBlockBody) -> bool: // def is_execution_enabled(state: BeaconState, body: BeaconBlockBody) -> bool:
// return is_merge_block(state, body) or is_merge_complete(state) // return is_merge_block(state, body) or is_merge_complete(state)
func IsExecutionEnabled(st state.BeaconState, body block.BeaconBlockBody) (bool, error) { func IsExecutionEnabled(st state.BeaconState, body interfaces.BeaconBlockBody) (bool, error) {
if st == nil || body == nil { if st == nil || body == nil {
return false, errors.New("nil state or block body") return false, errors.New("nil state or block body")
} }
@@ -99,7 +99,7 @@ func IsExecutionEnabled(st state.BeaconState, body block.BeaconBlockBody) (bool,
// IsExecutionEnabledUsingHeader returns true if the execution is enabled using post processed payload header and block body. // IsExecutionEnabledUsingHeader returns true if the execution is enabled using post processed payload header and block body.
// This is an optimized version of IsExecutionEnabled where beacon state is not required as an argument. // This is an optimized version of IsExecutionEnabled where beacon state is not required as an argument.
func IsExecutionEnabledUsingHeader(header *ethpb.ExecutionPayloadHeader, body block.BeaconBlockBody) (bool, error) { func IsExecutionEnabledUsingHeader(header *ethpb.ExecutionPayloadHeader, body interfaces.BeaconBlockBody) (bool, error) {
if !isEmptyHeader(header) { if !isEmptyHeader(header) {
return true, nil return true, nil
} }

View File

@@ -7,7 +7,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/crypto/hash" "github.com/prysmaticlabs/prysm/crypto/hash"
"github.com/prysmaticlabs/prysm/time/slots" "github.com/prysmaticlabs/prysm/time/slots"
) )
@@ -29,7 +29,7 @@ import (
func ProcessRandao( func ProcessRandao(
ctx context.Context, ctx context.Context,
beaconState state.BeaconState, beaconState state.BeaconState,
b block.SignedBeaconBlock, b interfaces.SignedBeaconBlock,
) (state.BeaconState, error) { ) (state.BeaconState, error) {
if err := helpers.BeaconBlockIsNil(b); err != nil { if err := helpers.BeaconBlockIsNil(b); err != nil {
return nil, err return nil, err

View File

@@ -9,7 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/crypto/bls"
"github.com/prysmaticlabs/prysm/network/forks" "github.com/prysmaticlabs/prysm/network/forks"
@@ -98,7 +98,7 @@ func VerifyBlockHeaderSignature(beaconState state.BeaconState, header *ethpb.Sig
// VerifyBlockSignatureUsingCurrentFork verifies the proposer signature of a beacon block. This differs // VerifyBlockSignatureUsingCurrentFork verifies the proposer signature of a beacon block. This differs
// from the above method by not using fork data from the state and instead retrieving it // from the above method by not using fork data from the state and instead retrieving it
// via the respective epoch. // via the respective epoch.
func VerifyBlockSignatureUsingCurrentFork(beaconState state.ReadOnlyBeaconState, blk block.SignedBeaconBlock) error { func VerifyBlockSignatureUsingCurrentFork(beaconState state.ReadOnlyBeaconState, blk interfaces.SignedBeaconBlock) error {
currentEpoch := slots.ToEpoch(blk.Block().Slot()) currentEpoch := slots.ToEpoch(blk.Block().Slot())
fork, err := forks.Fork(currentEpoch) fork, err := forks.Fork(currentEpoch)
if err != nil { if err != nil {

View File

@@ -10,6 +10,6 @@ go_library(
visibility = ["//beacon-chain:__subpackages__"], visibility = ["//beacon-chain:__subpackages__"],
deps = [ deps = [
"//async/event:go_default_library", "//async/event:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
], ],
) )

View File

@@ -2,9 +2,7 @@
// during the runtime of a beacon node. // during the runtime of a beacon node.
package block package block
import ( import "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/consensus-types/block"
)
const ( const (
// ReceivedBlock is sent after a block has been received by the beacon node via p2p or RPC. // ReceivedBlock is sent after a block has been received by the beacon node via p2p or RPC.
@@ -13,6 +11,6 @@ const (
// ReceivedBlockData is the data sent with ReceivedBlock events. // ReceivedBlockData is the data sent with ReceivedBlock events.
type ReceivedBlockData struct { type ReceivedBlockData struct {
SignedBlock block.SignedBeaconBlock SignedBlock interfaces.SignedBeaconBlock
IsOptimistic bool IsOptimistic bool
} }

View File

@@ -13,7 +13,7 @@ go_library(
], ],
deps = [ deps = [
"//async/event:go_default_library", "//async/event:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
], ],
) )

View File

@@ -6,7 +6,7 @@ package state
import ( import (
"time" "time"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
) )
@@ -35,7 +35,7 @@ type BlockProcessedData struct {
// BlockRoot of the processed block. // BlockRoot of the processed block.
BlockRoot [32]byte BlockRoot [32]byte
// SignedBlock is the physical processed block. // SignedBlock is the physical processed block.
SignedBlock block.SignedBeaconBlock SignedBlock interfaces.SignedBeaconBlock
// Verified is true if the block's BLS contents have been verified. // Verified is true if the block's BLS contents have been verified.
Verified bool Verified bool
} }

View File

@@ -22,7 +22,7 @@ go_library(
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//container/slice:go_default_library", "//container/slice:go_default_library",
"//container/trie:go_default_library", "//container/trie:go_default_library",

View File

@@ -6,7 +6,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/time/slots" "github.com/prysmaticlabs/prysm/time/slots"
) )
@@ -18,7 +18,7 @@ var ErrNilBeaconBlockBody = errors.New("beacon block body can't be nil")
// BeaconBlockIsNil checks if any composite field of input signed beacon block is nil. // BeaconBlockIsNil checks if any composite field of input signed beacon block is nil.
// Access to these nil fields will result in run time panic, // Access to these nil fields will result in run time panic,
// it is recommended to run these checks as first line of defense. // it is recommended to run these checks as first line of defense.
func BeaconBlockIsNil(b block.SignedBeaconBlock) error { func BeaconBlockIsNil(b interfaces.SignedBeaconBlock) error {
if b == nil || b.IsNil() { if b == nil || b.IsNil() {
return ErrNilSignedBeaconBlock return ErrNilSignedBeaconBlock
} }

View File

@@ -36,7 +36,7 @@ go_library(
"//beacon-chain/state/stateutil:go_default_library", "//beacon-chain/state/stateutil:go_default_library",
"//beacon-chain/state/v1:go_default_library", "//beacon-chain/state/v1:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//crypto/bls:go_default_library", "//crypto/bls:go_default_library",
"//crypto/hash:go_default_library", "//crypto/hash:go_default_library",

View File

@@ -15,7 +15,7 @@ go_library(
deps = [ deps = [
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//config/features:go_default_library", "//config/features:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//io/file:go_default_library", "//io/file:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library",
], ],

View File

@@ -6,12 +6,12 @@ import (
"path" "path"
"github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/features"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/io/file"
) )
// WriteBlockToDisk as a block ssz. Writes to temp directory. Debug! // WriteBlockToDisk as a block ssz. Writes to temp directory. Debug!
func WriteBlockToDisk(block block.SignedBeaconBlock, failed bool) { func WriteBlockToDisk(block interfaces.SignedBeaconBlock, failed bool) {
if !features.Get().WriteSSZStateTransitions { if !features.Get().WriteSSZStateTransitions {
return return
} }

View File

@@ -18,7 +18,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/math" "github.com/prysmaticlabs/prysm/math"
"github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/monitoring/tracing"
@@ -47,7 +47,7 @@ import (
func ExecuteStateTransition( func ExecuteStateTransition(
ctx context.Context, ctx context.Context,
state state.BeaconState, state state.BeaconState,
signed block.SignedBeaconBlock, signed interfaces.SignedBeaconBlock,
) (state.BeaconState, error) { ) (state.BeaconState, error) {
if ctx.Err() != nil { if ctx.Err() != nil {
return nil, ctx.Err() return nil, ctx.Err()
@@ -295,7 +295,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot)
} }
// VerifyOperationLengths verifies that block operation lengths are valid. // VerifyOperationLengths verifies that block operation lengths are valid.
func VerifyOperationLengths(_ context.Context, state state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { func VerifyOperationLengths(_ context.Context, state state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
if err := helpers.BeaconBlockIsNil(b); err != nil { if err := helpers.BeaconBlockIsNil(b); err != nil {
return nil, err return nil, err
} }

View File

@@ -12,7 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop"
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/crypto/bls"
"github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/monitoring/tracing"
"github.com/prysmaticlabs/prysm/runtime/version" "github.com/prysmaticlabs/prysm/runtime/version"
@@ -43,7 +43,7 @@ import (
func ExecuteStateTransitionNoVerifyAnySig( func ExecuteStateTransitionNoVerifyAnySig(
ctx context.Context, ctx context.Context,
state state.BeaconState, state state.BeaconState,
signed block.SignedBeaconBlock, signed interfaces.SignedBeaconBlock,
) (*bls.SignatureBatch, state.BeaconState, error) { ) (*bls.SignatureBatch, state.BeaconState, error) {
if ctx.Err() != nil { if ctx.Err() != nil {
return nil, nil, ctx.Err() return nil, nil, ctx.Err()
@@ -107,7 +107,7 @@ func ExecuteStateTransitionNoVerifyAnySig(
func CalculateStateRoot( func CalculateStateRoot(
ctx context.Context, ctx context.Context,
state state.BeaconState, state state.BeaconState,
signed block.SignedBeaconBlock, signed interfaces.SignedBeaconBlock,
) ([32]byte, error) { ) ([32]byte, error) {
ctx, span := trace.StartSpan(ctx, "core.state.CalculateStateRoot") ctx, span := trace.StartSpan(ctx, "core.state.CalculateStateRoot")
defer span.End() defer span.End()
@@ -156,7 +156,7 @@ func CalculateStateRoot(
func ProcessBlockNoVerifyAnySig( func ProcessBlockNoVerifyAnySig(
ctx context.Context, ctx context.Context,
state state.BeaconState, state state.BeaconState,
signed block.SignedBeaconBlock, signed interfaces.SignedBeaconBlock,
) (*bls.SignatureBatch, state.BeaconState, error) { ) (*bls.SignatureBatch, state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessBlockNoVerifyAnySig") ctx, span := trace.StartSpan(ctx, "core.state.ProcessBlockNoVerifyAnySig")
defer span.End() defer span.End()
@@ -220,7 +220,7 @@ func ProcessBlockNoVerifyAnySig(
func ProcessOperationsNoVerifyAttsSigs( func ProcessOperationsNoVerifyAttsSigs(
ctx context.Context, ctx context.Context,
state state.BeaconState, state state.BeaconState,
signedBeaconBlock block.SignedBeaconBlock) (state.BeaconState, error) { signedBeaconBlock interfaces.SignedBeaconBlock) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessOperationsNoVerifyAttsSigs") ctx, span := trace.StartSpan(ctx, "core.state.ProcessOperationsNoVerifyAttsSigs")
defer span.End() defer span.End()
if err := helpers.BeaconBlockIsNil(signedBeaconBlock); err != nil { if err := helpers.BeaconBlockIsNil(signedBeaconBlock); err != nil {
@@ -265,7 +265,7 @@ func ProcessOperationsNoVerifyAttsSigs(
func ProcessBlockForStateRoot( func ProcessBlockForStateRoot(
ctx context.Context, ctx context.Context,
state state.BeaconState, state state.BeaconState,
signed block.SignedBeaconBlock, signed interfaces.SignedBeaconBlock,
) (state.BeaconState, error) { ) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessBlockForStateRoot") ctx, span := trace.StartSpan(ctx, "core.state.ProcessBlockForStateRoot")
defer span.End() defer span.End()
@@ -349,7 +349,7 @@ func ProcessBlockForStateRoot(
func altairOperations( func altairOperations(
ctx context.Context, ctx context.Context,
state state.BeaconState, state state.BeaconState,
signedBeaconBlock block.SignedBeaconBlock) (state.BeaconState, error) { signedBeaconBlock interfaces.SignedBeaconBlock) (state.BeaconState, error) {
state, err := b.ProcessProposerSlashings(ctx, state, signedBeaconBlock.Block().Body().ProposerSlashings(), v.SlashValidator) state, err := b.ProcessProposerSlashings(ctx, state, signedBeaconBlock.Block().Body().ProposerSlashings(), v.SlashValidator)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not process altair proposer slashing") return nil, errors.Wrap(err, "could not process altair proposer slashing")
@@ -372,7 +372,7 @@ func altairOperations(
func phase0Operations( func phase0Operations(
ctx context.Context, ctx context.Context,
state state.BeaconStateAltair, state state.BeaconStateAltair,
signedBeaconBlock block.SignedBeaconBlock) (state.BeaconState, error) { signedBeaconBlock interfaces.SignedBeaconBlock) (state.BeaconState, error) {
state, err := b.ProcessProposerSlashings(ctx, state, signedBeaconBlock.Block().Body().ProposerSlashings(), v.SlashValidator) state, err := b.ProcessProposerSlashings(ctx, state, signedBeaconBlock.Block().Body().ProposerSlashings(), v.SlashValidator)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not process block proposer slashings") return nil, errors.Wrap(err, "could not process block proposer slashings")

View File

@@ -13,7 +13,7 @@ go_library(
"//beacon-chain/db/filters:go_default_library", "//beacon-chain/db/filters:go_default_library",
"//beacon-chain/slasher/types:go_default_library", "//beacon-chain/slasher/types:go_default_library",
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//monitoring/backup:go_default_library", "//monitoring/backup:go_default_library",
"//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1:go_default_library",

View File

@@ -11,7 +11,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
slashertypes "github.com/prysmaticlabs/prysm/beacon-chain/slasher/types" slashertypes "github.com/prysmaticlabs/prysm/beacon-chain/slasher/types"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/monitoring/backup" "github.com/prysmaticlabs/prysm/monitoring/backup"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -20,17 +20,17 @@ import (
// ReadOnlyDatabase defines a struct which only has read access to database methods. // ReadOnlyDatabase defines a struct which only has read access to database methods.
type ReadOnlyDatabase interface { type ReadOnlyDatabase interface {
// Block related methods. // Block related methods.
Block(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) Block(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error)
Blocks(ctx context.Context, f *filters.QueryFilter) ([]block.SignedBeaconBlock, [][32]byte, error) Blocks(ctx context.Context, f *filters.QueryFilter) ([]interfaces.SignedBeaconBlock, [][32]byte, error)
BlockRoots(ctx context.Context, f *filters.QueryFilter) ([][32]byte, error) BlockRoots(ctx context.Context, f *filters.QueryFilter) ([][32]byte, error)
BlocksBySlot(ctx context.Context, slot types.Slot) (bool, []block.SignedBeaconBlock, error) BlocksBySlot(ctx context.Context, slot types.Slot) (bool, []interfaces.SignedBeaconBlock, error)
BlockRootsBySlot(ctx context.Context, slot types.Slot) (bool, [][32]byte, error) BlockRootsBySlot(ctx context.Context, slot types.Slot) (bool, [][32]byte, error)
HasBlock(ctx context.Context, blockRoot [32]byte) bool HasBlock(ctx context.Context, blockRoot [32]byte) bool
GenesisBlock(ctx context.Context) (block.SignedBeaconBlock, error) GenesisBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error)
GenesisBlockRoot(ctx context.Context) ([32]byte, error) GenesisBlockRoot(ctx context.Context) ([32]byte, error)
IsFinalizedBlock(ctx context.Context, blockRoot [32]byte) bool IsFinalizedBlock(ctx context.Context, blockRoot [32]byte) bool
FinalizedChildBlock(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) FinalizedChildBlock(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error)
HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]block.SignedBeaconBlock, error) HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]interfaces.SignedBeaconBlock, error)
// State related methods. // State related methods.
State(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error) State(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error)
StateOrError(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error) StateOrError(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error)
@@ -64,8 +64,8 @@ type NoHeadAccessDatabase interface {
// Block related methods. // Block related methods.
DeleteBlock(ctx context.Context, root [32]byte) error DeleteBlock(ctx context.Context, root [32]byte) error
SaveBlock(ctx context.Context, block block.SignedBeaconBlock) error SaveBlock(ctx context.Context, block interfaces.SignedBeaconBlock) error
SaveBlocks(ctx context.Context, blocks []block.SignedBeaconBlock) error SaveBlocks(ctx context.Context, blocks []interfaces.SignedBeaconBlock) error
SaveGenesisBlockRoot(ctx context.Context, blockRoot [32]byte) error SaveGenesisBlockRoot(ctx context.Context, blockRoot [32]byte) error
// State related methods. // State related methods.
SaveState(ctx context.Context, state state.ReadOnlyBeaconState, blockRoot [32]byte) error SaveState(ctx context.Context, state state.ReadOnlyBeaconState, blockRoot [32]byte) error
@@ -95,7 +95,7 @@ type HeadAccessDatabase interface {
NoHeadAccessDatabase NoHeadAccessDatabase
// Block related methods. // Block related methods.
HeadBlock(ctx context.Context) (block.SignedBeaconBlock, error) HeadBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error)
SaveHeadBlockRoot(ctx context.Context, blockRoot [32]byte) error SaveHeadBlockRoot(ctx context.Context, blockRoot [32]byte) error
// Genesis operations. // Genesis operations.

View File

@@ -45,7 +45,7 @@ go_library(
"//beacon-chain/state/v3:go_default_library", "//beacon-chain/state/v3:go_default_library",
"//config/features:go_default_library", "//config/features:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//container/slice:go_default_library", "//container/slice:go_default_library",
@@ -108,7 +108,7 @@ go_test(
"//config/features:go_default_library", "//config/features:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",

View File

@@ -11,7 +11,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/container/slice" "github.com/prysmaticlabs/prysm/container/slice"
@@ -27,14 +27,14 @@ import (
var errInvalidSlotRange = errors.New("invalid end slot and start slot provided") var errInvalidSlotRange = errors.New("invalid end slot and start slot provided")
// Block retrieval by root. // Block retrieval by root.
func (s *Store) Block(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) { func (s *Store) Block(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.Block") ctx, span := trace.StartSpan(ctx, "BeaconDB.Block")
defer span.End() defer span.End()
// Return block from cache if it exists. // Return block from cache if it exists.
if v, ok := s.blockCache.Get(string(blockRoot[:])); v != nil && ok { if v, ok := s.blockCache.Get(string(blockRoot[:])); v != nil && ok {
return v.(block.SignedBeaconBlock), nil return v.(interfaces.SignedBeaconBlock), nil
} }
var blk block.SignedBeaconBlock var blk interfaces.SignedBeaconBlock
err := s.db.View(func(tx *bolt.Tx) error { err := s.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(blocksBucket) bkt := tx.Bucket(blocksBucket)
enc := bkt.Get(blockRoot[:]) enc := bkt.Get(blockRoot[:])
@@ -90,10 +90,10 @@ func (s *Store) BackfillBlockRoot(ctx context.Context) ([32]byte, error) {
} }
// HeadBlock returns the latest canonical block in the Ethereum Beacon Chain. // HeadBlock returns the latest canonical block in the Ethereum Beacon Chain.
func (s *Store) HeadBlock(ctx context.Context) (block.SignedBeaconBlock, error) { func (s *Store) HeadBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.HeadBlock") ctx, span := trace.StartSpan(ctx, "BeaconDB.HeadBlock")
defer span.End() defer span.End()
var headBlock block.SignedBeaconBlock var headBlock interfaces.SignedBeaconBlock
err := s.db.View(func(tx *bolt.Tx) error { err := s.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(blocksBucket) bkt := tx.Bucket(blocksBucket)
headRoot := bkt.Get(headBlockRootKey) headRoot := bkt.Get(headBlockRootKey)
@@ -112,10 +112,10 @@ func (s *Store) HeadBlock(ctx context.Context) (block.SignedBeaconBlock, error)
} }
// Blocks retrieves a list of beacon blocks and its respective roots by filter criteria. // Blocks retrieves a list of beacon blocks and its respective roots by filter criteria.
func (s *Store) Blocks(ctx context.Context, f *filters.QueryFilter) ([]block.SignedBeaconBlock, [][32]byte, error) { func (s *Store) Blocks(ctx context.Context, f *filters.QueryFilter) ([]interfaces.SignedBeaconBlock, [][32]byte, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.Blocks") ctx, span := trace.StartSpan(ctx, "BeaconDB.Blocks")
defer span.End() defer span.End()
blocks := make([]block.SignedBeaconBlock, 0) blocks := make([]interfaces.SignedBeaconBlock, 0)
blockRoots := make([][32]byte, 0) blockRoots := make([][32]byte, 0)
err := s.db.View(func(tx *bolt.Tx) error { err := s.db.View(func(tx *bolt.Tx) error {
@@ -185,10 +185,10 @@ func (s *Store) HasBlock(ctx context.Context, blockRoot [32]byte) bool {
} }
// BlocksBySlot retrieves a list of beacon blocks and its respective roots by slot. // BlocksBySlot retrieves a list of beacon blocks and its respective roots by slot.
func (s *Store) BlocksBySlot(ctx context.Context, slot types.Slot) (bool, []block.SignedBeaconBlock, error) { func (s *Store) BlocksBySlot(ctx context.Context, slot types.Slot) (bool, []interfaces.SignedBeaconBlock, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.BlocksBySlot") ctx, span := trace.StartSpan(ctx, "BeaconDB.BlocksBySlot")
defer span.End() defer span.End()
blocks := make([]block.SignedBeaconBlock, 0) blocks := make([]interfaces.SignedBeaconBlock, 0)
err := s.db.View(func(tx *bolt.Tx) error { err := s.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(blocksBucket) bkt := tx.Bucket(blocksBucket)
@@ -258,7 +258,7 @@ func (s *Store) DeleteBlock(ctx context.Context, root [32]byte) error {
} }
// SaveBlock to the db. // SaveBlock to the db.
func (s *Store) SaveBlock(ctx context.Context, signed block.SignedBeaconBlock) error { func (s *Store) SaveBlock(ctx context.Context, signed interfaces.SignedBeaconBlock) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveBlock") ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveBlock")
defer span.End() defer span.End()
blockRoot, err := signed.Block().HashTreeRoot() blockRoot, err := signed.Block().HashTreeRoot()
@@ -268,11 +268,11 @@ func (s *Store) SaveBlock(ctx context.Context, signed block.SignedBeaconBlock) e
if v, ok := s.blockCache.Get(string(blockRoot[:])); v != nil && ok { if v, ok := s.blockCache.Get(string(blockRoot[:])); v != nil && ok {
return nil return nil
} }
return s.SaveBlocks(ctx, []block.SignedBeaconBlock{signed}) return s.SaveBlocks(ctx, []interfaces.SignedBeaconBlock{signed})
} }
// SaveBlocks via bulk updates to the db. // SaveBlocks via bulk updates to the db.
func (s *Store) SaveBlocks(ctx context.Context, blocks []block.SignedBeaconBlock) error { func (s *Store) SaveBlocks(ctx context.Context, blocks []interfaces.SignedBeaconBlock) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveBlocks") ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveBlocks")
defer span.End() defer span.End()
@@ -330,10 +330,10 @@ func (s *Store) SaveHeadBlockRoot(ctx context.Context, blockRoot [32]byte) error
} }
// GenesisBlock retrieves the genesis block of the beacon chain. // GenesisBlock retrieves the genesis block of the beacon chain.
func (s *Store) GenesisBlock(ctx context.Context) (block.SignedBeaconBlock, error) { func (s *Store) GenesisBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.GenesisBlock") ctx, span := trace.StartSpan(ctx, "BeaconDB.GenesisBlock")
defer span.End() defer span.End()
var blk block.SignedBeaconBlock var blk interfaces.SignedBeaconBlock
err := s.db.View(func(tx *bolt.Tx) error { err := s.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(blocksBucket) bkt := tx.Bucket(blocksBucket)
root := bkt.Get(genesisBlockRootKey) root := bkt.Get(genesisBlockRootKey)
@@ -399,7 +399,7 @@ func (s *Store) SaveBackfillBlockRoot(ctx context.Context, blockRoot [32]byte) e
} }
// HighestSlotBlocksBelow returns the block with the highest slot below the input slot from the db. // HighestSlotBlocksBelow returns the block with the highest slot below the input slot from the db.
func (s *Store) HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]block.SignedBeaconBlock, error) { func (s *Store) HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]interfaces.SignedBeaconBlock, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.HighestSlotBlocksBelow") ctx, span := trace.StartSpan(ctx, "BeaconDB.HighestSlotBlocksBelow")
defer span.End() defer span.End()
@@ -426,7 +426,7 @@ func (s *Store) HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]
return nil, err return nil, err
} }
var blk block.SignedBeaconBlock var blk interfaces.SignedBeaconBlock
var err error var err error
if best != nil { if best != nil {
blk, err = s.Block(ctx, bytesutil.ToBytes32(best)) blk, err = s.Block(ctx, bytesutil.ToBytes32(best))
@@ -441,7 +441,7 @@ func (s *Store) HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]
} }
} }
return []block.SignedBeaconBlock{blk}, nil return []interfaces.SignedBeaconBlock{blk}, nil
} }
// FeeRecipientByValidatorID returns the fee recipient for a validator id. // FeeRecipientByValidatorID returns the fee recipient for a validator id.
@@ -631,7 +631,7 @@ func blockRootsBySlot(ctx context.Context, tx *bolt.Tx, slot types.Slot) [][]byt
// createBlockIndicesFromBlock takes in a beacon block and returns // createBlockIndicesFromBlock takes in a beacon block and returns
// a map of bolt DB index buckets corresponding to each particular key for indices for // a map of bolt DB index buckets corresponding to each particular key for indices for
// data, such as (shard indices bucket -> shard 5). // data, such as (shard indices bucket -> shard 5).
func createBlockIndicesFromBlock(ctx context.Context, block block.BeaconBlock) map[string][]byte { func createBlockIndicesFromBlock(ctx context.Context, block interfaces.BeaconBlock) map[string][]byte {
_, span := trace.StartSpan(ctx, "BeaconDB.createBlockIndicesFromBlock") _, span := trace.StartSpan(ctx, "BeaconDB.createBlockIndicesFromBlock")
defer span.End() defer span.End()
indicesByBucket := make(map[string][]byte) indicesByBucket := make(map[string][]byte)
@@ -686,7 +686,7 @@ func createBlockIndicesFromFilters(ctx context.Context, f *filters.QueryFilter)
} }
// unmarshal block from marshaled proto beacon block bytes to versioned beacon block struct type. // unmarshal block from marshaled proto beacon block bytes to versioned beacon block struct type.
func unmarshalBlock(_ context.Context, enc []byte) (block.SignedBeaconBlock, error) { func unmarshalBlock(_ context.Context, enc []byte) (interfaces.SignedBeaconBlock, error) {
var err error var err error
enc, err = snappy.Decode(nil, enc) enc, err = snappy.Decode(nil, enc)
if err != nil { if err != nil {
@@ -716,7 +716,7 @@ func unmarshalBlock(_ context.Context, enc []byte) (block.SignedBeaconBlock, err
} }
// marshal versioned beacon block from struct type down to bytes. // marshal versioned beacon block from struct type down to bytes.
func marshalBlock(_ context.Context, blk block.SignedBeaconBlock) ([]byte, error) { func marshalBlock(_ context.Context, blk interfaces.SignedBeaconBlock) ([]byte, error) {
obj, err := blk.MarshalSSZ() obj, err := blk.MarshalSSZ()
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -8,7 +8,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -21,11 +21,11 @@ import (
var blockTests = []struct { var blockTests = []struct {
name string name string
newBlock func(types.Slot, []byte) (block.SignedBeaconBlock, error) newBlock func(types.Slot, []byte) (interfaces.SignedBeaconBlock, error)
}{ }{
{ {
name: "phase0", name: "phase0",
newBlock: func(slot types.Slot, root []byte) (block.SignedBeaconBlock, error) { newBlock: func(slot types.Slot, root []byte) (interfaces.SignedBeaconBlock, error) {
b := util.NewBeaconBlock() b := util.NewBeaconBlock()
b.Block.Slot = slot b.Block.Slot = slot
if root != nil { if root != nil {
@@ -36,7 +36,7 @@ var blockTests = []struct {
}, },
{ {
name: "altair", name: "altair",
newBlock: func(slot types.Slot, root []byte) (block.SignedBeaconBlock, error) { newBlock: func(slot types.Slot, root []byte) (interfaces.SignedBeaconBlock, error) {
b := util.NewBeaconBlockAltair() b := util.NewBeaconBlockAltair()
b.Block.Slot = slot b.Block.Slot = slot
if root != nil { if root != nil {
@@ -47,7 +47,7 @@ var blockTests = []struct {
}, },
{ {
name: "bellatrix", name: "bellatrix",
newBlock: func(slot types.Slot, root []byte) (block.SignedBeaconBlock, error) { newBlock: func(slot types.Slot, root []byte) (interfaces.SignedBeaconBlock, error) {
b := util.NewBeaconBlockBellatrix() b := util.NewBeaconBlockBellatrix()
b.Block.Slot = slot b.Block.Slot = slot
if root != nil { if root != nil {
@@ -138,7 +138,7 @@ func TestStore_BlocksHandleZeroCase(t *testing.T) {
db := setupDB(t) db := setupDB(t)
ctx := context.Background() ctx := context.Background()
numBlocks := 10 numBlocks := 10
totalBlocks := make([]block.SignedBeaconBlock, numBlocks) totalBlocks := make([]interfaces.SignedBeaconBlock, numBlocks)
for i := 0; i < len(totalBlocks); i++ { for i := 0; i < len(totalBlocks); i++ {
b, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32)) b, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32))
require.NoError(t, err) require.NoError(t, err)
@@ -161,7 +161,7 @@ func TestStore_BlocksHandleInvalidEndSlot(t *testing.T) {
db := setupDB(t) db := setupDB(t)
ctx := context.Background() ctx := context.Background()
numBlocks := 10 numBlocks := 10
totalBlocks := make([]block.SignedBeaconBlock, numBlocks) totalBlocks := make([]interfaces.SignedBeaconBlock, numBlocks)
// Save blocks from slot 1 onwards. // Save blocks from slot 1 onwards.
for i := 0; i < len(totalBlocks); i++ { for i := 0; i < len(totalBlocks); i++ {
b, err := tt.newBlock(types.Slot(i+1), bytesutil.PadTo([]byte("parent"), 32)) b, err := tt.newBlock(types.Slot(i+1), bytesutil.PadTo([]byte("parent"), 32))
@@ -322,7 +322,7 @@ func TestStore_Blocks_FiltersCorrectly(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
b8, err := tt.newBlock(types.Slot(8), bytesutil.PadTo([]byte("parent4"), 32)) b8, err := tt.newBlock(types.Slot(8), bytesutil.PadTo([]byte("parent4"), 32))
require.NoError(t, err) require.NoError(t, err)
blocks := []block.SignedBeaconBlock{ blocks := []interfaces.SignedBeaconBlock{
b4, b4,
b5, b5,
b6, b6,
@@ -426,7 +426,7 @@ func TestStore_Blocks_Retrieve_SlotRange(t *testing.T) {
for _, tt := range blockTests { for _, tt := range blockTests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
db := setupDB(t) db := setupDB(t)
totalBlocks := make([]block.SignedBeaconBlock, 500) totalBlocks := make([]interfaces.SignedBeaconBlock, 500)
for i := 0; i < 500; i++ { for i := 0; i < 500; i++ {
b, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32)) b, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32))
require.NoError(t, err) require.NoError(t, err)
@@ -446,7 +446,7 @@ func TestStore_Blocks_Retrieve_Epoch(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
db := setupDB(t) db := setupDB(t)
slots := params.BeaconConfig().SlotsPerEpoch.Mul(7) slots := params.BeaconConfig().SlotsPerEpoch.Mul(7)
totalBlocks := make([]block.SignedBeaconBlock, slots) totalBlocks := make([]interfaces.SignedBeaconBlock, slots)
for i := types.Slot(0); i < slots; i++ { for i := types.Slot(0); i < slots; i++ {
b, err := tt.newBlock(i, bytesutil.PadTo([]byte("parent"), 32)) b, err := tt.newBlock(i, bytesutil.PadTo([]byte("parent"), 32))
require.NoError(t, err) require.NoError(t, err)
@@ -470,7 +470,7 @@ func TestStore_Blocks_Retrieve_SlotRangeWithStep(t *testing.T) {
for _, tt := range blockTests { for _, tt := range blockTests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
db := setupDB(t) db := setupDB(t)
totalBlocks := make([]block.SignedBeaconBlock, 500) totalBlocks := make([]interfaces.SignedBeaconBlock, 500)
for i := 0; i < 500; i++ { for i := 0; i < 500; i++ {
b, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32)) b, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32))
require.NoError(t, err) require.NoError(t, err)
@@ -557,7 +557,7 @@ func TestStore_SaveBlocks_HasCachedBlocks(t *testing.T) {
db := setupDB(t) db := setupDB(t)
ctx := context.Background() ctx := context.Background()
b := make([]block.SignedBeaconBlock, 500) b := make([]interfaces.SignedBeaconBlock, 500)
for i := 0; i < 500; i++ { for i := 0; i < 500; i++ {
blk, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32)) blk, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32))
require.NoError(t, err) require.NoError(t, err)
@@ -581,7 +581,7 @@ func TestStore_SaveBlocks_HasRootsMatched(t *testing.T) {
db := setupDB(t) db := setupDB(t)
ctx := context.Background() ctx := context.Background()
b := make([]block.SignedBeaconBlock, 500) b := make([]interfaces.SignedBeaconBlock, 500)
for i := 0; i < 500; i++ { for i := 0; i < 500; i++ {
blk, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32)) blk, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32))
require.NoError(t, err) require.NoError(t, err)

View File

@@ -6,7 +6,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/monitoring/tracing"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -182,11 +182,11 @@ func (s *Store) IsFinalizedBlock(ctx context.Context, blockRoot [32]byte) bool {
// FinalizedChildBlock returns the child block of a provided finalized block. If // FinalizedChildBlock returns the child block of a provided finalized block. If
// no finalized block or its respective child block exists we return with a nil // no finalized block or its respective child block exists we return with a nil
// block. // block.
func (s *Store) FinalizedChildBlock(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) { func (s *Store) FinalizedChildBlock(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.FinalizedChildBlock") ctx, span := trace.StartSpan(ctx, "BeaconDB.FinalizedChildBlock")
defer span.End() defer span.End()
var blk block.SignedBeaconBlock var blk interfaces.SignedBeaconBlock
err := s.db.View(func(tx *bolt.Tx) error { err := s.db.View(func(tx *bolt.Tx) error {
blkBytes := tx.Bucket(finalizedBlockRootsIndexBucket).Get(blockRoot[:]) blkBytes := tx.Bucket(finalizedBlockRootsIndexBucket).Get(blockRoot[:])
if blkBytes == nil { if blkBytes == nil {

View File

@@ -6,7 +6,7 @@ import (
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -140,7 +140,7 @@ func TestStore_IsFinalizedChildBlock(t *testing.T) {
slotsPerEpoch := uint64(params.BeaconConfig().SlotsPerEpoch) slotsPerEpoch := uint64(params.BeaconConfig().SlotsPerEpoch)
ctx := context.Background() ctx := context.Background()
eval := func(t testing.TB, ctx context.Context, db *Store, blks []block.SignedBeaconBlock) { eval := func(t testing.TB, ctx context.Context, db *Store, blks []interfaces.SignedBeaconBlock) {
require.NoError(t, db.SaveBlocks(ctx, blks)) require.NoError(t, db.SaveBlocks(ctx, blks))
root, err := blks[slotsPerEpoch].Block().HashTreeRoot() root, err := blks[slotsPerEpoch].Block().HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
@@ -191,15 +191,15 @@ func TestStore_IsFinalizedChildBlock(t *testing.T) {
}) })
} }
func sszRootOrDie(t *testing.T, block block.SignedBeaconBlock) []byte { func sszRootOrDie(t *testing.T, block interfaces.SignedBeaconBlock) []byte {
root, err := block.Block().HashTreeRoot() root, err := block.Block().HashTreeRoot()
require.NoError(t, err) require.NoError(t, err)
return root[:] return root[:]
} }
func makeBlocks(t *testing.T, i, n uint64, previousRoot [32]byte) []block.SignedBeaconBlock { func makeBlocks(t *testing.T, i, n uint64, previousRoot [32]byte) []interfaces.SignedBeaconBlock {
blocks := make([]*ethpb.SignedBeaconBlock, n) blocks := make([]*ethpb.SignedBeaconBlock, n)
ifaceBlocks := make([]block.SignedBeaconBlock, n) ifaceBlocks := make([]interfaces.SignedBeaconBlock, n)
for j := i; j < n+i; j++ { for j := i; j < n+i; j++ {
parentRoot := make([]byte, fieldparams.RootLength) parentRoot := make([]byte, fieldparams.RootLength)
copy(parentRoot, previousRoot[:]) copy(parentRoot, previousRoot[:])
@@ -215,9 +215,9 @@ func makeBlocks(t *testing.T, i, n uint64, previousRoot [32]byte) []block.Signed
return ifaceBlocks return ifaceBlocks
} }
func makeBlocksAltair(t *testing.T, startIdx, num uint64, previousRoot [32]byte) []block.SignedBeaconBlock { func makeBlocksAltair(t *testing.T, startIdx, num uint64, previousRoot [32]byte) []interfaces.SignedBeaconBlock {
blocks := make([]*ethpb.SignedBeaconBlockAltair, num) blocks := make([]*ethpb.SignedBeaconBlockAltair, num)
ifaceBlocks := make([]block.SignedBeaconBlock, num) ifaceBlocks := make([]interfaces.SignedBeaconBlock, num)
for j := startIdx; j < num+startIdx; j++ { for j := startIdx; j < num+startIdx; j++ {
parentRoot := make([]byte, fieldparams.RootLength) parentRoot := make([]byte, fieldparams.RootLength)
copy(parentRoot, previousRoot[:]) copy(parentRoot, previousRoot[:])

View File

@@ -10,7 +10,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/features"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -368,7 +368,7 @@ func TestStore_StatesBatchDelete(t *testing.T) {
db := setupDB(t) db := setupDB(t)
ctx := context.Background() ctx := context.Background()
numBlocks := 100 numBlocks := 100
totalBlocks := make([]block.SignedBeaconBlock, numBlocks) totalBlocks := make([]interfaces.SignedBeaconBlock, numBlocks)
blockRoots := make([][32]byte, 0) blockRoots := make([][32]byte, 0)
evenBlockRoots := make([][32]byte, 0) evenBlockRoots := make([][32]byte, 0)
for i := 0; i < len(totalBlocks); i++ { for i := 0; i < len(totalBlocks); i++ {

View File

@@ -25,7 +25,7 @@ go_library(
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stategen:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1:go_default_library",

View File

@@ -8,7 +8,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -53,7 +53,7 @@ func logMessageTimelyFlagsForIndex(idx types.ValidatorIndex, data *ethpb.Attesta
} }
// processAttestations logs the event for the tracked validators' attestations inclusion in block // processAttestations logs the event for the tracked validators' attestations inclusion in block
func (s *Service) processAttestations(ctx context.Context, state state.BeaconState, blk block.BeaconBlock) { func (s *Service) processAttestations(ctx context.Context, state state.BeaconState, blk interfaces.BeaconBlock) {
if blk == nil || blk.Body() == nil { if blk == nil || blk.Body() == nil {
return return
} }

View File

@@ -7,7 +7,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/time/slots" "github.com/prysmaticlabs/prysm/time/slots"
@@ -23,7 +23,7 @@ const AggregateReportingPeriod = 5
// - An Exit by one of our validators was included // - An Exit by one of our validators was included
// - A Slashing by one of our tracked validators was included // - A Slashing by one of our tracked validators was included
// - A Sync Committee Contribution by one of our tracked validators was included // - A Sync Committee Contribution by one of our tracked validators was included
func (s *Service) processBlock(ctx context.Context, b block.SignedBeaconBlock) { func (s *Service) processBlock(ctx context.Context, b interfaces.SignedBeaconBlock) {
if b == nil || b.Block() == nil { if b == nil || b.Block() == nil {
return return
} }
@@ -64,7 +64,7 @@ func (s *Service) processBlock(ctx context.Context, b block.SignedBeaconBlock) {
} }
// processProposedBlock logs when the beacon node observes a beacon block from a tracked validator. // processProposedBlock logs when the beacon node observes a beacon block from a tracked validator.
func (s *Service) processProposedBlock(state state.BeaconState, root [32]byte, blk block.BeaconBlock) { func (s *Service) processProposedBlock(state state.BeaconState, root [32]byte, blk interfaces.BeaconBlock) {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
if s.trackedIndex(blk.ProposerIndex()) { if s.trackedIndex(blk.ProposerIndex()) {
@@ -101,7 +101,7 @@ func (s *Service) processProposedBlock(state state.BeaconState, root [32]byte, b
} }
// processSlashings logs the event when tracked validators was slashed // processSlashings logs the event when tracked validators was slashed
func (s *Service) processSlashings(blk block.BeaconBlock) { func (s *Service) processSlashings(blk interfaces.BeaconBlock) {
s.RLock() s.RLock()
defer s.RUnlock() defer s.RUnlock()
for _, slashing := range blk.Body().ProposerSlashings() { for _, slashing := range blk.Body().ProposerSlashings() {

View File

@@ -1,13 +1,13 @@
package monitor package monitor
import ( import (
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
// processExitsFromBlock logs the event when a tracked validators' exit was included in a block // processExitsFromBlock logs the event when a tracked validators' exit was included in a block
func (s *Service) processExitsFromBlock(blk block.BeaconBlock) { func (s *Service) processExitsFromBlock(blk interfaces.BeaconBlock) {
s.RLock() s.RLock()
defer s.RUnlock() defer s.RUnlock()
for _, exit := range blk.Body().VoluntaryExits() { for _, exit := range blk.Body().VoluntaryExits() {

View File

@@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@@ -25,7 +25,7 @@ func (s *Service) processSyncCommitteeContribution(contribution *ethpb.SignedCon
} }
// processSyncAggregate logs the event when tracked validators is a sync-committee member and its contribution has been included // processSyncAggregate logs the event when tracked validators is a sync-committee member and its contribution has been included
func (s *Service) processSyncAggregate(state state.BeaconState, blk block.BeaconBlock) { func (s *Service) processSyncAggregate(state state.BeaconState, blk interfaces.BeaconBlock) {
if blk == nil || blk.Body() == nil { if blk == nil || blk.Body() == nil {
return return
} }

View File

@@ -17,7 +17,7 @@ go_library(
], ],
deps = [ deps = [
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",

View File

@@ -2,7 +2,7 @@ package types
import ( import (
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -21,7 +21,7 @@ func init() {
var ( var (
// BlockMap maps the fork-version to the underlying data type for that // BlockMap maps the fork-version to the underlying data type for that
// particular fork period. // particular fork period.
BlockMap map[[4]byte]func() (block.SignedBeaconBlock, error) BlockMap map[[4]byte]func() (interfaces.SignedBeaconBlock, error)
// MetaDataMap maps the fork-version to the underlying data type for that // MetaDataMap maps the fork-version to the underlying data type for that
// particular fork period. // particular fork period.
MetaDataMap map[[4]byte]func() metadata.Metadata MetaDataMap map[[4]byte]func() metadata.Metadata
@@ -31,14 +31,14 @@ var (
// reset maps and reinitialize them. // reset maps and reinitialize them.
func InitializeDataMaps() { func InitializeDataMaps() {
// Reset our block map. // Reset our block map.
BlockMap = map[[4]byte]func() (block.SignedBeaconBlock, error){ BlockMap = map[[4]byte]func() (interfaces.SignedBeaconBlock, error){
bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion): func() (block.SignedBeaconBlock, error) { bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion): func() (interfaces.SignedBeaconBlock, error) {
return wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlock{}) return wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlock{})
}, },
bytesutil.ToBytes4(params.BeaconConfig().AltairForkVersion): func() (block.SignedBeaconBlock, error) { bytesutil.ToBytes4(params.BeaconConfig().AltairForkVersion): func() (interfaces.SignedBeaconBlock, error) {
return wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlockAltair{Block: &ethpb.BeaconBlockAltair{}}) return wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlockAltair{Block: &ethpb.BeaconBlockAltair{}})
}, },
bytesutil.ToBytes4(params.BeaconConfig().BellatrixForkVersion): func() (block.SignedBeaconBlock, error) { bytesutil.ToBytes4(params.BeaconConfig().BellatrixForkVersion): func() (interfaces.SignedBeaconBlock, error) {
return wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlockBellatrix{Block: &ethpb.BeaconBlockBellatrix{}}) return wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlockBellatrix{Block: &ethpb.BeaconBlockBellatrix{}})
}, },
} }

View File

@@ -39,7 +39,7 @@ go_library(
"//config/features:go_default_library", "//config/features:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//crypto/bls:go_default_library", "//crypto/bls:go_default_library",
@@ -93,7 +93,7 @@ go_test(
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library", "//beacon-chain/state/v1:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//crypto/bls:go_default_library", "//crypto/bls:go_default_library",

View File

@@ -14,7 +14,7 @@ import (
rpchelpers "github.com/prysmaticlabs/prysm/beacon-chain/rpc/eth/helpers" rpchelpers "github.com/prysmaticlabs/prysm/beacon-chain/rpc/eth/helpers"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -133,7 +133,7 @@ func (bs *Server) ListBlockHeaders(ctx context.Context, req *ethpbv1.BlockHeader
defer span.End() defer span.End()
var err error var err error
var blks []block.SignedBeaconBlock var blks []interfaces.SignedBeaconBlock
var blkRoots [][32]byte var blkRoots [][32]byte
if len(req.ParentRoot) == 32 { if len(req.ParentRoot) == 32 {
blks, blkRoots, err = bs.BeaconDB.Blocks(ctx, filters.NewFilter().SetParentRoot(req.ParentRoot)) blks, blkRoots, err = bs.BeaconDB.Blocks(ctx, filters.NewFilter().SetParentRoot(req.ParentRoot))
@@ -629,9 +629,9 @@ func (bs *Server) ListBlockAttestations(ctx context.Context, req *ethpbv1.BlockR
return nil, status.Errorf(codes.Internal, "Could not get signed beacon block: %v", err) return nil, status.Errorf(codes.Internal, "Could not get signed beacon block: %v", err)
} }
func (bs *Server) blockFromBlockID(ctx context.Context, blockId []byte) (block.SignedBeaconBlock, error) { func (bs *Server) blockFromBlockID(ctx context.Context, blockId []byte) (interfaces.SignedBeaconBlock, error) {
var err error var err error
var blk block.SignedBeaconBlock var blk interfaces.SignedBeaconBlock
switch string(blockId) { switch string(blockId) {
case "head": case "head":
blk, err = bs.ChainInfoFetcher.HeadBlock(ctx) blk, err = bs.ChainInfoFetcher.HeadBlock(ctx)
@@ -694,7 +694,7 @@ func (bs *Server) blockFromBlockID(ctx context.Context, blockId []byte) (block.S
return blk, nil return blk, nil
} }
func handleGetBlockError(blk block.SignedBeaconBlock, err error) error { func handleGetBlockError(blk interfaces.SignedBeaconBlock, err error) error {
if invalidBlockIdErr, ok := err.(*blockIdParseError); ok { if invalidBlockIdErr, ok := err.(*blockIdParseError); ok {
return status.Errorf(codes.InvalidArgument, "Invalid block ID: %v", invalidBlockIdErr) return status.Errorf(codes.InvalidArgument, "Invalid block ID: %v", invalidBlockIdErr)
} }
@@ -781,7 +781,7 @@ func (bs *Server) submitBlindedBellatrixBlock(ctx context.Context, blindedBellat
return bs.submitBlock(ctx, root, wrappedBellatrixSignedBlk) return bs.submitBlock(ctx, root, wrappedBellatrixSignedBlk)
} }
func (bs *Server) submitBlock(ctx context.Context, blockRoot [fieldparams.RootLength]byte, block block.SignedBeaconBlock) error { func (bs *Server) submitBlock(ctx context.Context, blockRoot [fieldparams.RootLength]byte, block interfaces.SignedBeaconBlock) error {
// Do not block proposal critical path with debug logging or block feed updates. // Do not block proposal critical path with debug logging or block feed updates.
defer func() { defer func() {
log.WithField("blockRoot", fmt.Sprintf("%#x", bytesutil.Trunc(blockRoot[:]))).Debugf( log.WithField("blockRoot", fmt.Sprintf("%#x", bytesutil.Trunc(blockRoot[:]))).Debugf(

View File

@@ -9,7 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/db"
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
mockp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" mockp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -35,7 +35,7 @@ func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) (
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, root)) require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, root))
count := types.Slot(100) count := types.Slot(100)
blks := make([]block.SignedBeaconBlock, count) blks := make([]interfaces.SignedBeaconBlock, count)
blkContainers := make([]*ethpbalpha.BeaconBlockContainer, count) blkContainers := make([]*ethpbalpha.BeaconBlockContainer, count)
for i := types.Slot(0); i < count; i++ { for i := types.Slot(0); i < count; i++ {
b := util.NewBeaconBlock() b := util.NewBeaconBlock()
@@ -80,7 +80,7 @@ func fillDBTestBlocksAltair(ctx context.Context, t *testing.T, beaconDB db.Datab
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, root)) require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, root))
count := types.Slot(100) count := types.Slot(100)
blks := make([]block.SignedBeaconBlock, count) blks := make([]interfaces.SignedBeaconBlock, count)
blkContainers := make([]*ethpbalpha.BeaconBlockContainer, count) blkContainers := make([]*ethpbalpha.BeaconBlockContainer, count)
for i := types.Slot(0); i < count; i++ { for i := types.Slot(0); i < count; i++ {
b := util.NewBeaconBlockAltair() b := util.NewBeaconBlockAltair()
@@ -124,7 +124,7 @@ func fillDBTestBlocksBellatrix(ctx context.Context, t *testing.T, beaconDB db.Da
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, root)) require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, root))
count := types.Slot(100) count := types.Slot(100)
blks := make([]block.SignedBeaconBlock, count) blks := make([]interfaces.SignedBeaconBlock, count)
blkContainers := make([]*ethpbalpha.BeaconBlockContainer, count) blkContainers := make([]*ethpbalpha.BeaconBlockContainer, count)
for i := types.Slot(0); i < count; i++ { for i := types.Slot(0); i < count; i++ {
b := util.NewBeaconBlockBellatrix() b := util.NewBeaconBlockBellatrix()

View File

@@ -45,7 +45,7 @@ go_library(
"//config/features:go_default_library", "//config/features:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//container/slice:go_default_library", "//container/slice:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",
@@ -108,7 +108,7 @@ go_test(
"//config/features:go_default_library", "//config/features:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",

View File

@@ -13,7 +13,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/cmd" "github.com/prysmaticlabs/prysm/cmd"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/attestation" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/attestation"
@@ -63,7 +63,7 @@ func (bs *Server) ListAttestations(
return nil, status.Errorf(codes.InvalidArgument, "Requested page size %d can not be greater than max size %d", return nil, status.Errorf(codes.InvalidArgument, "Requested page size %d can not be greater than max size %d",
req.PageSize, cmd.Get().MaxRPCPageSize) req.PageSize, cmd.Get().MaxRPCPageSize)
} }
var blocks []block.SignedBeaconBlock var blocks []interfaces.SignedBeaconBlock
var err error var err error
switch q := req.QueryFilter.(type) { switch q := req.QueryFilter.(type) {
case *ethpb.ListAttestationsRequest_GenesisEpoch: case *ethpb.ListAttestationsRequest_GenesisEpoch:
@@ -117,7 +117,7 @@ func (bs *Server) ListAttestations(
func (bs *Server) ListIndexedAttestations( func (bs *Server) ListIndexedAttestations(
ctx context.Context, req *ethpb.ListIndexedAttestationsRequest, ctx context.Context, req *ethpb.ListIndexedAttestationsRequest,
) (*ethpb.ListIndexedAttestationsResponse, error) { ) (*ethpb.ListIndexedAttestationsResponse, error) {
var blocks []block.SignedBeaconBlock var blocks []interfaces.SignedBeaconBlock
var err error var err error
switch q := req.QueryFilter.(type) { switch q := req.QueryFilter.(type) {
case *ethpb.ListIndexedAttestationsRequest_GenesisEpoch: case *ethpb.ListIndexedAttestationsRequest_GenesisEpoch:

View File

@@ -22,7 +22,7 @@ import (
"github.com/prysmaticlabs/prysm/cmd" "github.com/prysmaticlabs/prysm/cmd"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -243,7 +243,7 @@ func TestServer_ListAttestations_FiltersCorrectly(t *testing.T) {
}), }),
} }
var blocks []block.SignedBeaconBlock var blocks []interfaces.SignedBeaconBlock
for _, b := range unwrappedBlocks { for _, b := range unwrappedBlocks {
wsb, err := wrapper.WrappedSignedBeaconBlock(b) wsb, err := wrapper.WrappedSignedBeaconBlock(b)
require.NoError(t, err) require.NoError(t, err)

View File

@@ -15,7 +15,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/cmd" "github.com/prysmaticlabs/prysm/cmd"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/runtime/version" "github.com/prysmaticlabs/prysm/runtime/version"
@@ -28,7 +28,7 @@ import (
// blockContainer represents an instance of // blockContainer represents an instance of
// block along with its relevant metadata. // block along with its relevant metadata.
type blockContainer struct { type blockContainer struct {
blk block.SignedBeaconBlock blk interfaces.SignedBeaconBlock
root [32]byte root [32]byte
isCanonical bool isCanonical bool
} }
@@ -114,7 +114,7 @@ func convertFromV1Containers(ctrs []blockContainer) ([]*ethpb.BeaconBlockContain
return protoCtrs, nil return protoCtrs, nil
} }
func convertToBlockContainer(blk block.SignedBeaconBlock, root [32]byte, isCanonical bool) (*ethpb.BeaconBlockContainer, error) { func convertToBlockContainer(blk interfaces.SignedBeaconBlock, root [32]byte, isCanonical bool) (*ethpb.BeaconBlockContainer, error) {
ctr := &ethpb.BeaconBlockContainer{ ctr := &ethpb.BeaconBlockContainer{
BlockRoot: root[:], BlockRoot: root[:],
Canonical: isCanonical, Canonical: isCanonical,

View File

@@ -16,7 +16,7 @@ import (
"github.com/prysmaticlabs/prysm/cmd" "github.com/prysmaticlabs/prysm/cmd"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -138,7 +138,7 @@ func TestServer_ListBlocks_Genesis_MultiBlocks(t *testing.T) {
require.NoError(t, db.SaveGenesisBlockRoot(ctx, root)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, root))
count := types.Slot(100) count := types.Slot(100)
blks := make([]block.SignedBeaconBlock, count) blks := make([]interfaces.SignedBeaconBlock, count)
for i := types.Slot(0); i < count; i++ { for i := types.Slot(0); i < count; i++ {
b := util.NewBeaconBlock() b := util.NewBeaconBlock()
b.Block.Slot = i b.Block.Slot = i
@@ -168,7 +168,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
ctx := context.Background() ctx := context.Background()
count := types.Slot(100) count := types.Slot(100)
blks := make([]block.SignedBeaconBlock, count) blks := make([]interfaces.SignedBeaconBlock, count)
blkContainers := make([]*ethpb.BeaconBlockContainer, count) blkContainers := make([]*ethpb.BeaconBlockContainer, count)
for i := types.Slot(0); i < count; i++ { for i := types.Slot(0); i < count; i++ {
b := util.NewBeaconBlock() b := util.NewBeaconBlock()
@@ -897,7 +897,7 @@ func TestServer_ListBeaconBlocks_Genesis(t *testing.T) {
}) })
} }
func runListBlocksGenesis(t *testing.T, blk block.SignedBeaconBlock, blkContainer *ethpb.BeaconBlockContainer) { func runListBlocksGenesis(t *testing.T, blk interfaces.SignedBeaconBlock, blkContainer *ethpb.BeaconBlockContainer) {
db := dbTest.SetupDB(t) db := dbTest.SetupDB(t)
ctx := context.Background() ctx := context.Background()
@@ -941,7 +941,7 @@ func TestServer_ListBeaconBlocks_Genesis_MultiBlocks(t *testing.T) {
parentRoot := [32]byte{1, 2, 3} parentRoot := [32]byte{1, 2, 3}
blk := util.NewBeaconBlock() blk := util.NewBeaconBlock()
blk.Block.ParentRoot = parentRoot[:] blk.Block.ParentRoot = parentRoot[:]
blockCreator := func(i types.Slot) block.SignedBeaconBlock { blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock {
b := util.NewBeaconBlock() b := util.NewBeaconBlock()
b.Block.Slot = i b.Block.Slot = i
wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) wrappedB, err := wrapper.WrappedSignedBeaconBlock(b)
@@ -956,7 +956,7 @@ func TestServer_ListBeaconBlocks_Genesis_MultiBlocks(t *testing.T) {
parentRoot := [32]byte{1, 2, 3} parentRoot := [32]byte{1, 2, 3}
blk := util.NewBeaconBlockAltair() blk := util.NewBeaconBlockAltair()
blk.Block.ParentRoot = parentRoot[:] blk.Block.ParentRoot = parentRoot[:]
blockCreator := func(i types.Slot) block.SignedBeaconBlock { blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock {
b := util.NewBeaconBlockAltair() b := util.NewBeaconBlockAltair()
b.Block.Slot = i b.Block.Slot = i
wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) wrappedB, err := wrapper.WrappedSignedBeaconBlock(b)
@@ -971,7 +971,7 @@ func TestServer_ListBeaconBlocks_Genesis_MultiBlocks(t *testing.T) {
parentRoot := [32]byte{1, 2, 3} parentRoot := [32]byte{1, 2, 3}
blk := util.NewBeaconBlockBellatrix() blk := util.NewBeaconBlockBellatrix()
blk.Block.ParentRoot = parentRoot[:] blk.Block.ParentRoot = parentRoot[:]
blockCreator := func(i types.Slot) block.SignedBeaconBlock { blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock {
b := util.NewBeaconBlockBellatrix() b := util.NewBeaconBlockBellatrix()
b.Block.Slot = i b.Block.Slot = i
wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) wrappedB, err := wrapper.WrappedSignedBeaconBlock(b)
@@ -984,8 +984,8 @@ func TestServer_ListBeaconBlocks_Genesis_MultiBlocks(t *testing.T) {
}) })
} }
func runListBeaconBlocksGenesisMultiBlocks(t *testing.T, genBlock block.SignedBeaconBlock, func runListBeaconBlocksGenesisMultiBlocks(t *testing.T, genBlock interfaces.SignedBeaconBlock,
blockCreator func(i types.Slot) block.SignedBeaconBlock) { blockCreator func(i types.Slot) interfaces.SignedBeaconBlock) {
db := dbTest.SetupDB(t) db := dbTest.SetupDB(t)
ctx := context.Background() ctx := context.Background()
@@ -999,7 +999,7 @@ func runListBeaconBlocksGenesisMultiBlocks(t *testing.T, genBlock block.SignedBe
require.NoError(t, db.SaveGenesisBlockRoot(ctx, root)) require.NoError(t, db.SaveGenesisBlockRoot(ctx, root))
count := types.Slot(100) count := types.Slot(100)
blks := make([]block.SignedBeaconBlock, count) blks := make([]interfaces.SignedBeaconBlock, count)
for i := types.Slot(0); i < count; i++ { for i := types.Slot(0); i < count; i++ {
blks[i] = blockCreator(i) blks[i] = blockCreator(i)
} }
@@ -1020,7 +1020,7 @@ func TestServer_ListBeaconBlocks_Pagination(t *testing.T) {
t.Run("phase 0 block", func(t *testing.T) { t.Run("phase 0 block", func(t *testing.T) {
blk := util.NewBeaconBlock() blk := util.NewBeaconBlock()
blk.Block.Slot = 300 blk.Block.Slot = 300
blockCreator := func(i types.Slot) block.SignedBeaconBlock { blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock {
b := util.NewBeaconBlock() b := util.NewBeaconBlock()
b.Block.Slot = i b.Block.Slot = i
wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) wrappedB, err := wrapper.WrappedSignedBeaconBlock(b)
@@ -1044,7 +1044,7 @@ func TestServer_ListBeaconBlocks_Pagination(t *testing.T) {
t.Run("altair block", func(t *testing.T) { t.Run("altair block", func(t *testing.T) {
blk := util.NewBeaconBlockAltair() blk := util.NewBeaconBlockAltair()
blk.Block.Slot = 300 blk.Block.Slot = 300
blockCreator := func(i types.Slot) block.SignedBeaconBlock { blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock {
b := util.NewBeaconBlockAltair() b := util.NewBeaconBlockAltair()
b.Block.Slot = i b.Block.Slot = i
wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) wrappedB, err := wrapper.WrappedSignedBeaconBlock(b)
@@ -1068,7 +1068,7 @@ func TestServer_ListBeaconBlocks_Pagination(t *testing.T) {
t.Run("bellatrix block", func(t *testing.T) { t.Run("bellatrix block", func(t *testing.T) {
blk := util.NewBeaconBlockBellatrix() blk := util.NewBeaconBlockBellatrix()
blk.Block.Slot = 300 blk.Block.Slot = 300
blockCreator := func(i types.Slot) block.SignedBeaconBlock { blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock {
b := util.NewBeaconBlockBellatrix() b := util.NewBeaconBlockBellatrix()
b.Block.Slot = i b.Block.Slot = i
wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) wrappedB, err := wrapper.WrappedSignedBeaconBlock(b)
@@ -1091,8 +1091,8 @@ func TestServer_ListBeaconBlocks_Pagination(t *testing.T) {
}) })
} }
func runListBeaconBlocksPagination(t *testing.T, orphanedBlk block.SignedBeaconBlock, func runListBeaconBlocksPagination(t *testing.T, orphanedBlk interfaces.SignedBeaconBlock,
blockCreator func(i types.Slot) block.SignedBeaconBlock, containerCreator func(i types.Slot, root []byte, canonical bool) *ethpb.BeaconBlockContainer) { blockCreator func(i types.Slot) interfaces.SignedBeaconBlock, containerCreator func(i types.Slot, root []byte, canonical bool) *ethpb.BeaconBlockContainer) {
db := dbTest.SetupDB(t) db := dbTest.SetupDB(t)
chain := &chainMock.ChainService{ chain := &chainMock.ChainService{
@@ -1101,7 +1101,7 @@ func runListBeaconBlocksPagination(t *testing.T, orphanedBlk block.SignedBeaconB
ctx := context.Background() ctx := context.Background()
count := types.Slot(100) count := types.Slot(100)
blks := make([]block.SignedBeaconBlock, count) blks := make([]interfaces.SignedBeaconBlock, count)
blkContainers := make([]*ethpb.BeaconBlockContainer, count) blkContainers := make([]*ethpb.BeaconBlockContainer, count)
for i := types.Slot(0); i < count; i++ { for i := types.Slot(0); i < count; i++ {
b := blockCreator(i) b := blockCreator(i)

View File

@@ -26,7 +26,7 @@ import (
"github.com/prysmaticlabs/prysm/cmd" "github.com/prysmaticlabs/prysm/cmd"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -1723,7 +1723,7 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpochWithBits(t *testing
}) })
} }
func runGetValidatorParticipationCurrentAndPrevEpoch(t *testing.T, genState state.BeaconState, gb block.SignedBeaconBlock) { func runGetValidatorParticipationCurrentAndPrevEpoch(t *testing.T, genState state.BeaconState, gb interfaces.SignedBeaconBlock) {
helpers.ClearCache() helpers.ClearCache()
beaconDB := dbTest.SetupDB(t) beaconDB := dbTest.SetupDB(t)

View File

@@ -54,7 +54,7 @@ go_library(
"//beacon-chain/sync:go_default_library", "//beacon-chain/sync:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//container/trie:go_default_library", "//container/trie:go_default_library",

View File

@@ -14,7 +14,7 @@ import (
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block" blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block"
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -133,7 +133,7 @@ func (vs *Server) PrepareBeaconProposer(
return &emptypb.Empty{}, nil return &emptypb.Empty{}, nil
} }
func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk block.SignedBeaconBlock) (*ethpb.ProposeResponse, error) { func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk interfaces.SignedBeaconBlock) (*ethpb.ProposeResponse, error) {
ctx, span := trace.StartSpan(ctx, "ProposerServer.proposeGenericBeaconBlock") ctx, span := trace.StartSpan(ctx, "ProposerServer.proposeGenericBeaconBlock")
defer span.End() defer span.End()
root, err := blk.Block().HashTreeRoot() root, err := blk.Block().HashTreeRoot()
@@ -170,7 +170,7 @@ func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk block.Signe
// computeStateRoot computes the state root after a block has been processed through a state transition and // computeStateRoot computes the state root after a block has been processed through a state transition and
// returns it to the validator client. // returns it to the validator client.
func (vs *Server) computeStateRoot(ctx context.Context, block block.SignedBeaconBlock) ([]byte, error) { func (vs *Server) computeStateRoot(ctx context.Context, block interfaces.SignedBeaconBlock) ([]byte, error) {
beaconState, err := vs.StateGen.StateByRoot(ctx, bytesutil.ToBytes32(block.Block().ParentRoot())) beaconState, err := vs.StateGen.StateByRoot(ctx, bytesutil.ToBytes32(block.Block().ParentRoot()))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not retrieve beacon state") return nil, errors.Wrap(err, "could not retrieve beacon state")

View File

@@ -31,7 +31,7 @@ go_library(
"//beacon-chain/sync/backfill:go_default_library", "//beacon-chain/sync/backfill:go_default_library",
"//cache/lru:go_default_library", "//cache/lru:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",
"//monitoring/tracing:go_default_library", "//monitoring/tracing:go_default_library",
@@ -73,8 +73,8 @@ go_test(
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library", "//beacon-chain/state/v1:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/block/mock:go_default_library", "//consensus-types/mock:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",

View File

@@ -9,7 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
"go.opencensus.io/trace" "go.opencensus.io/trace"
@@ -46,7 +46,7 @@ func (ch *CanonicalHistory) ReplayerForSlot(target types.Slot) Replayer {
return &stateReplayer{chainer: ch, method: forSlot, target: target} return &stateReplayer{chainer: ch, method: forSlot, target: target}
} }
func (c *CanonicalHistory) BlockForSlot(ctx context.Context, target types.Slot) ([32]byte, block.SignedBeaconBlock, error) { func (c *CanonicalHistory) BlockForSlot(ctx context.Context, target types.Slot) ([32]byte, interfaces.SignedBeaconBlock, error) {
currentSlot := c.cs.CurrentSlot() currentSlot := c.cs.CurrentSlot()
if target > currentSlot { if target > currentSlot {
return [32]byte{}, nil, errors.Wrap(ErrFutureSlotRequested, fmt.Sprintf("requested=%d, current=%d", target, currentSlot)) return [32]byte{}, nil, errors.Wrap(ErrFutureSlotRequested, fmt.Sprintf("requested=%d, current=%d", target, currentSlot))
@@ -83,7 +83,7 @@ func (c *CanonicalHistory) BlockForSlot(ctx context.Context, target types.Slot)
if err != nil { if err != nil {
return [32]byte{}, nil, errors.Wrap(err, "db error while retrieving genesis block") return [32]byte{}, nil, errors.Wrap(err, "db error while retrieving genesis block")
} }
root, _, err := c.bestForSlot(ctx, []block.SignedBeaconBlock{b}) root, _, err := c.bestForSlot(ctx, []interfaces.SignedBeaconBlock{b})
if err != nil { if err != nil {
return [32]byte{}, nil, errors.Wrap(err, "problem retrieving genesis block") return [32]byte{}, nil, errors.Wrap(err, "problem retrieving genesis block")
} }
@@ -92,7 +92,7 @@ func (c *CanonicalHistory) BlockForSlot(ctx context.Context, target types.Slot)
// bestForSlot encapsulates several messy realities of the underlying db code, looping through multiple blocks, // bestForSlot encapsulates several messy realities of the underlying db code, looping through multiple blocks,
// performing null/validity checks, and using CanonicalChecker to only pick canonical blocks. // performing null/validity checks, and using CanonicalChecker to only pick canonical blocks.
func (c *CanonicalHistory) bestForSlot(ctx context.Context, hbs []block.SignedBeaconBlock) ([32]byte, block.SignedBeaconBlock, error) { func (c *CanonicalHistory) bestForSlot(ctx context.Context, hbs []interfaces.SignedBeaconBlock) ([32]byte, interfaces.SignedBeaconBlock, error) {
for _, b := range hbs { for _, b := range hbs {
if helpers.BeaconBlockIsNil(b) != nil { if helpers.BeaconBlockIsNil(b) != nil {
continue continue
@@ -119,7 +119,7 @@ func (c *CanonicalHistory) bestForSlot(ctx context.Context, hbs []block.SignedBe
// and the stategen transition helper methods. This implementation uses the following algorithm: // and the stategen transition helper methods. This implementation uses the following algorithm:
// - find the highest canonical block <= the target slot // - find the highest canonical block <= the target slot
// - starting with this block, recursively search backwards for a stored state, and accumulate intervening blocks // - starting with this block, recursively search backwards for a stored state, and accumulate intervening blocks
func (c *CanonicalHistory) chainForSlot(ctx context.Context, target types.Slot) (state.BeaconState, []block.SignedBeaconBlock, error) { func (c *CanonicalHistory) chainForSlot(ctx context.Context, target types.Slot) (state.BeaconState, []interfaces.SignedBeaconBlock, error) {
ctx, span := trace.StartSpan(ctx, "canonicalChainer.chainForSlot") ctx, span := trace.StartSpan(ctx, "canonicalChainer.chainForSlot")
defer span.End() defer span.End()
_, b, err := c.BlockForSlot(ctx, target) _, b, err := c.BlockForSlot(ctx, target)
@@ -152,10 +152,10 @@ func (c *CanonicalHistory) getState(ctx context.Context, root [32]byte) (state.B
// all blocks in the lineage, including the tail block. Blocks are returned in ascending order. // all blocks in the lineage, including the tail block. Blocks are returned in ascending order.
// Note that this function assumes that the tail is a canonical block, and therefore assumes that // Note that this function assumes that the tail is a canonical block, and therefore assumes that
// all ancestors are also canonical. // all ancestors are also canonical.
func (c *CanonicalHistory) ancestorChain(ctx context.Context, tail block.SignedBeaconBlock) (state.BeaconState, []block.SignedBeaconBlock, error) { func (c *CanonicalHistory) ancestorChain(ctx context.Context, tail interfaces.SignedBeaconBlock) (state.BeaconState, []interfaces.SignedBeaconBlock, error) {
ctx, span := trace.StartSpan(ctx, "canonicalChainer.ancestorChain") ctx, span := trace.StartSpan(ctx, "canonicalChainer.ancestorChain")
defer span.End() defer span.End()
chain := make([]block.SignedBeaconBlock, 0) chain := make([]interfaces.SignedBeaconBlock, 0)
for { for {
if err := ctx.Err(); err != nil { if err := ctx.Err(); err != nil {
msg := fmt.Sprintf("context canceled while finding ancestors of block at slot %d", tail.Block().Slot()) msg := fmt.Sprintf("context canceled while finding ancestors of block at slot %d", tail.Block().Slot())
@@ -197,7 +197,7 @@ func (c *CanonicalHistory) ancestorChain(ctx context.Context, tail block.SignedB
} }
} }
func reverseChain(c []block.SignedBeaconBlock) { func reverseChain(c []interfaces.SignedBeaconBlock) {
last := len(c) - 1 last := len(c) - 1
swaps := (last + 1) / 2 swaps := (last + 1) / 2
for i := 0; i < swaps; i++ { for i := 0; i < swaps; i++ {

View File

@@ -7,11 +7,11 @@ import (
"testing" "testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/consensus-types/mock"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/consensus-types/block"
"github.com/prysmaticlabs/prysm/consensus-types/block/mock"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/require"
@@ -50,65 +50,65 @@ func TestBestForSlot(t *testing.T) {
cases := []struct { cases := []struct {
name string name string
err error err error
blocks []block.SignedBeaconBlock blocks []interfaces.SignedBeaconBlock
best block.SignedBeaconBlock best interfaces.SignedBeaconBlock
root [32]byte root [32]byte
cc CanonicalChecker cc CanonicalChecker
}{ }{
{ {
name: "empty list", name: "empty list",
err: ErrNoCanonicalBlockForSlot, err: ErrNoCanonicalBlockForSlot,
blocks: []block.SignedBeaconBlock{}, blocks: []interfaces.SignedBeaconBlock{},
}, },
{ {
name: "empty SignedBeaconBlock", name: "empty SignedBeaconBlock",
err: ErrNoCanonicalBlockForSlot, err: ErrNoCanonicalBlockForSlot,
blocks: []block.SignedBeaconBlock{nil}, blocks: []interfaces.SignedBeaconBlock{nil},
}, },
{ {
name: "empty BeaconBlock", name: "empty BeaconBlock",
err: ErrNoCanonicalBlockForSlot, err: ErrNoCanonicalBlockForSlot,
blocks: []block.SignedBeaconBlock{nilBlock}, blocks: []interfaces.SignedBeaconBlock{nilBlock},
}, },
{ {
name: "empty BeaconBlockBody", name: "empty BeaconBlockBody",
err: ErrNoCanonicalBlockForSlot, err: ErrNoCanonicalBlockForSlot,
blocks: []block.SignedBeaconBlock{nilBody}, blocks: []interfaces.SignedBeaconBlock{nilBody},
}, },
{ {
name: "bad HTR", name: "bad HTR",
err: ErrInvalidDBBlock, err: ErrInvalidDBBlock,
blocks: []block.SignedBeaconBlock{badHTR}, blocks: []interfaces.SignedBeaconBlock{badHTR},
}, },
{ {
name: "IsCanonical fail", name: "IsCanonical fail",
blocks: []block.SignedBeaconBlock{good, better}, blocks: []interfaces.SignedBeaconBlock{good, better},
cc: &mockCanonicalChecker{is: true, err: derp}, cc: &mockCanonicalChecker{is: true, err: derp},
err: derp, err: derp,
}, },
{ {
name: "all non-canonical", name: "all non-canonical",
err: ErrNoCanonicalBlockForSlot, err: ErrNoCanonicalBlockForSlot,
blocks: []block.SignedBeaconBlock{good, better}, blocks: []interfaces.SignedBeaconBlock{good, better},
cc: &mockCanonicalChecker{is: false}, cc: &mockCanonicalChecker{is: false},
}, },
{ {
name: "one canonical", name: "one canonical",
blocks: []block.SignedBeaconBlock{good}, blocks: []interfaces.SignedBeaconBlock{good},
cc: &mockCanonicalChecker{is: true}, cc: &mockCanonicalChecker{is: true},
root: goodHTR, root: goodHTR,
best: good, best: good,
}, },
{ {
name: "all canonical", name: "all canonical",
blocks: []block.SignedBeaconBlock{better, good}, blocks: []interfaces.SignedBeaconBlock{better, good},
cc: &mockCanonicalChecker{is: true}, cc: &mockCanonicalChecker{is: true},
root: betterHTR, root: betterHTR,
best: better, best: better,
}, },
{ {
name: "first wins", name: "first wins",
blocks: []block.SignedBeaconBlock{good, better}, blocks: []interfaces.SignedBeaconBlock{good, better},
cc: &mockCanonicalChecker{is: true}, cc: &mockCanonicalChecker{is: true},
root: goodHTR, root: goodHTR,
best: good, best: good,
@@ -195,14 +195,14 @@ func TestCanonicalBlockForSlotNonHappy(t *testing.T) {
name string name string
slot types.Slot slot types.Slot
canon CanonicalChecker canon CanonicalChecker
overrideHighest func(context.Context, types.Slot) ([]block.SignedBeaconBlock, error) overrideHighest func(context.Context, types.Slot) ([]interfaces.SignedBeaconBlock, error)
slotOrderExpected []types.Slot slotOrderExpected []types.Slot
err error err error
root [32]byte root [32]byte
}{ }{
{ {
name: "HighestSlotBlocksBelow not called for genesis", name: "HighestSlotBlocksBelow not called for genesis",
overrideHighest: func(_ context.Context, _ types.Slot) ([]block.SignedBeaconBlock, error) { overrideHighest: func(_ context.Context, _ types.Slot) ([]interfaces.SignedBeaconBlock, error) {
return nil, derp return nil, derp
}, },
root: hist.slotMap[0], root: hist.slotMap[0],
@@ -210,7 +210,7 @@ func TestCanonicalBlockForSlotNonHappy(t *testing.T) {
{ {
name: "wrapped error from HighestSlotBlocksBelow returned", name: "wrapped error from HighestSlotBlocksBelow returned",
err: derp, err: derp,
overrideHighest: func(_ context.Context, _ types.Slot) ([]block.SignedBeaconBlock, error) { overrideHighest: func(_ context.Context, _ types.Slot) ([]interfaces.SignedBeaconBlock, error) {
return nil, derp return nil, derp
}, },
slot: end, slot: end,
@@ -218,8 +218,8 @@ func TestCanonicalBlockForSlotNonHappy(t *testing.T) {
{ {
name: "HighestSlotBlocksBelow empty list", name: "HighestSlotBlocksBelow empty list",
err: ErrNoBlocksBelowSlot, err: ErrNoBlocksBelowSlot,
overrideHighest: func(_ context.Context, _ types.Slot) ([]block.SignedBeaconBlock, error) { overrideHighest: func(_ context.Context, _ types.Slot) ([]interfaces.SignedBeaconBlock, error) {
return []block.SignedBeaconBlock{}, nil return []interfaces.SignedBeaconBlock{}, nil
}, },
slot: end, slot: end,
}, },
@@ -237,7 +237,7 @@ func TestCanonicalBlockForSlotNonHappy(t *testing.T) {
} }
return false, nil return false, nil
}}, }},
overrideHighest: func(_ context.Context, s types.Slot) ([]block.SignedBeaconBlock, error) { overrideHighest: func(_ context.Context, s types.Slot) ([]interfaces.SignedBeaconBlock, error) {
slotOrderObserved = append(slotOrderObserved, s) slotOrderObserved = append(slotOrderObserved, s)
// this allows the mock HighestSlotBlocksBelow to continue to execute now that we've recorded // this allows the mock HighestSlotBlocksBelow to continue to execute now that we've recorded
// the slot in our channel // the slot in our channel
@@ -255,7 +255,7 @@ func TestCanonicalBlockForSlotNonHappy(t *testing.T) {
} }
return false, nil return false, nil
}}, }},
overrideHighest: func(_ context.Context, s types.Slot) ([]block.SignedBeaconBlock, error) { overrideHighest: func(_ context.Context, s types.Slot) ([]interfaces.SignedBeaconBlock, error) {
slotOrderObserved = append(slotOrderObserved, s) slotOrderObserved = append(slotOrderObserved, s)
// this allows the mock HighestSlotBlocksBelow to continue to execute now that we've recorded // this allows the mock HighestSlotBlocksBelow to continue to execute now that we've recorded
// the slot in our channel // the slot in our channel
@@ -601,10 +601,10 @@ func incrFwd(n int, c chan uint32) {
close(c) close(c)
} }
func mockBlocks(n int, iter func(int, chan uint32)) []block.SignedBeaconBlock { func mockBlocks(n int, iter func(int, chan uint32)) []interfaces.SignedBeaconBlock {
bchan := make(chan uint32) bchan := make(chan uint32)
go iter(n, bchan) go iter(n, bchan)
mb := make([]block.SignedBeaconBlock, 0) mb := make([]interfaces.SignedBeaconBlock, 0)
for i := range bchan { for i := range bchan {
h := [32]byte{} h := [32]byte{}
binary.LittleEndian.PutUint32(h[:], i) binary.LittleEndian.PutUint32(h[:], i)

View File

@@ -12,7 +12,7 @@ go_library(
deps = [ deps = [
"//beacon-chain/state:go_default_library", "//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stategen:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1:go_default_library",
], ],

View File

@@ -4,7 +4,7 @@ import (
"context" "context"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
) )
@@ -47,7 +47,7 @@ func (_ *MockStateManager) MigrateToCold(_ context.Context, _ [32]byte) error {
func (_ *MockStateManager) ReplayBlocks( func (_ *MockStateManager) ReplayBlocks(
_ context.Context, _ context.Context,
_ state.BeaconState, _ state.BeaconState,
_ []block.SignedBeaconBlock, _ []interfaces.SignedBeaconBlock,
_ types.Slot, _ types.Slot,
) (state.BeaconState, error) { ) (state.BeaconState, error) {
panic("implement me") panic("implement me")
@@ -58,7 +58,7 @@ func (_ *MockStateManager) LoadBlocks(
_ context.Context, _ context.Context,
_, _ types.Slot, _, _ types.Slot,
_ [32]byte, _ [32]byte,
) ([]block.SignedBeaconBlock, error) { ) ([]interfaces.SignedBeaconBlock, error) {
panic("implement me") panic("implement me")
} }

View File

@@ -12,7 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
"github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -74,14 +74,14 @@ type mockHistorySpec struct {
} }
type mockHistory struct { type mockHistory struct {
blocks map[[32]byte]block.SignedBeaconBlock blocks map[[32]byte]interfaces.SignedBeaconBlock
slotMap map[types.Slot][32]byte slotMap map[types.Slot][32]byte
slotIndex slotList slotIndex slotList
canonical map[[32]byte]bool canonical map[[32]byte]bool
states map[[32]byte]state.BeaconState states map[[32]byte]state.BeaconState
hiddenStates map[[32]byte]state.BeaconState hiddenStates map[[32]byte]state.BeaconState
current types.Slot current types.Slot
overrideHighestSlotBlocksBelow func(context.Context, types.Slot) ([]block.SignedBeaconBlock, error) overrideHighestSlotBlocksBelow func(context.Context, types.Slot) ([]interfaces.SignedBeaconBlock, error)
} }
type slotList []types.Slot type slotList []types.Slot
@@ -100,7 +100,7 @@ func (m slotList) Swap(i, j int) {
var errFallThroughOverride = errors.New("override yielding control back to real HighestSlotBlocksBelow") var errFallThroughOverride = errors.New("override yielding control back to real HighestSlotBlocksBelow")
func (m *mockHistory) HighestSlotBlocksBelow(_ context.Context, slot types.Slot) ([]block.SignedBeaconBlock, error) { func (m *mockHistory) HighestSlotBlocksBelow(_ context.Context, slot types.Slot) ([]interfaces.SignedBeaconBlock, error) {
if m.overrideHighestSlotBlocksBelow != nil { if m.overrideHighestSlotBlocksBelow != nil {
s, err := m.overrideHighestSlotBlocksBelow(context.Background(), slot) s, err := m.overrideHighestSlotBlocksBelow(context.Background(), slot)
if !errors.Is(err, errFallThroughOverride) { if !errors.Is(err, errFallThroughOverride) {
@@ -115,15 +115,15 @@ func (m *mockHistory) HighestSlotBlocksBelow(_ context.Context, slot types.Slot)
} }
for _, s := range m.slotIndex { for _, s := range m.slotIndex {
if s < slot { if s < slot {
return []block.SignedBeaconBlock{m.blocks[m.slotMap[s]]}, nil return []interfaces.SignedBeaconBlock{m.blocks[m.slotMap[s]]}, nil
} }
} }
return []block.SignedBeaconBlock{}, nil return []interfaces.SignedBeaconBlock{}, nil
} }
var errGenesisBlockNotFound = errors.New("canonical genesis block not found in db") var errGenesisBlockNotFound = errors.New("canonical genesis block not found in db")
func (m *mockHistory) GenesisBlock(_ context.Context) (block.SignedBeaconBlock, error) { func (m *mockHistory) GenesisBlock(_ context.Context) (interfaces.SignedBeaconBlock, error) {
genesisRoot, ok := m.slotMap[0] genesisRoot, ok := m.slotMap[0]
if !ok { if !ok {
return nil, errGenesisBlockNotFound return nil, errGenesisBlockNotFound
@@ -131,7 +131,7 @@ func (m *mockHistory) GenesisBlock(_ context.Context) (block.SignedBeaconBlock,
return m.blocks[genesisRoot], nil return m.blocks[genesisRoot], nil
} }
func (m *mockHistory) Block(_ context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) { func (m *mockHistory) Block(_ context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error) {
if b, ok := m.blocks[blockRoot]; ok { if b, ok := m.blocks[blockRoot]; ok {
return b, nil return b, nil
} }
@@ -154,7 +154,7 @@ func (m *mockHistory) CurrentSlot() types.Slot {
return m.current return m.current
} }
func (h *mockHistory) addBlock(root [32]byte, b block.SignedBeaconBlock, canon bool) { func (h *mockHistory) addBlock(root [32]byte, b interfaces.SignedBeaconBlock, canon bool) {
h.blocks[root] = b h.blocks[root] = b
h.slotMap[b.Block().Slot()] = root h.slotMap[b.Block().Slot()] = root
h.canonical[root] = canon h.canonical[root] = canon
@@ -190,7 +190,7 @@ func (h *mockHistory) validateRoots() error {
func newMockHistory(t *testing.T, hist []mockHistorySpec, current types.Slot) *mockHistory { func newMockHistory(t *testing.T, hist []mockHistorySpec, current types.Slot) *mockHistory {
ctx := context.Background() ctx := context.Background()
mh := &mockHistory{ mh := &mockHistory{
blocks: map[[32]byte]block.SignedBeaconBlock{}, blocks: map[[32]byte]interfaces.SignedBeaconBlock{},
canonical: map[[32]byte]bool{}, canonical: map[[32]byte]bool{},
states: map[[32]byte]state.BeaconState{}, states: map[[32]byte]state.BeaconState{},
hiddenStates: map[[32]byte]state.BeaconState{}, hiddenStates: map[[32]byte]state.BeaconState{},

View File

@@ -13,7 +13,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/monitoring/tracing"
@@ -26,7 +26,7 @@ import (
func (_ *State) ReplayBlocks( func (_ *State) ReplayBlocks(
ctx context.Context, ctx context.Context,
state state.BeaconState, state state.BeaconState,
signed []block.SignedBeaconBlock, signed []interfaces.SignedBeaconBlock,
targetSlot types.Slot, targetSlot types.Slot,
) (state.BeaconState, error) { ) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "stateGen.ReplayBlocks") ctx, span := trace.StartSpan(ctx, "stateGen.ReplayBlocks")
@@ -77,7 +77,7 @@ func (_ *State) ReplayBlocks(
// LoadBlocks loads the blocks between start slot and end slot by recursively fetching from end block root. // LoadBlocks loads the blocks between start slot and end slot by recursively fetching from end block root.
// The Blocks are returned in slot-descending order. // The Blocks are returned in slot-descending order.
func (s *State) LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, endBlockRoot [32]byte) ([]block.SignedBeaconBlock, error) { func (s *State) LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, endBlockRoot [32]byte) ([]interfaces.SignedBeaconBlock, error) {
// Nothing to load for invalid range. // Nothing to load for invalid range.
if endSlot < startSlot { if endSlot < startSlot {
return nil, fmt.Errorf("start slot %d >= end slot %d", startSlot, endSlot) return nil, fmt.Errorf("start slot %d >= end slot %d", startSlot, endSlot)
@@ -115,7 +115,7 @@ func (s *State) LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, e
return nil, errors.New("end block roots don't match") return nil, errors.New("end block roots don't match")
} }
filteredBlocks := []block.SignedBeaconBlock{blocks[length-1]} filteredBlocks := []interfaces.SignedBeaconBlock{blocks[length-1]}
// Starting from second to last index because the last block is already in the filtered block list. // Starting from second to last index because the last block is already in the filtered block list.
for i := length - 2; i >= 0; i-- { for i := length - 2; i >= 0; i-- {
if ctx.Err() != nil { if ctx.Err() != nil {
@@ -138,7 +138,7 @@ func (s *State) LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, e
func executeStateTransitionStateGen( func executeStateTransitionStateGen(
ctx context.Context, ctx context.Context,
state state.BeaconState, state state.BeaconState,
signed block.SignedBeaconBlock, signed interfaces.SignedBeaconBlock,
) (state.BeaconState, error) { ) (state.BeaconState, error) {
if ctx.Err() != nil { if ctx.Err() != nil {
return nil, ctx.Err() return nil, ctx.Err()
@@ -237,7 +237,7 @@ func ReplayProcessSlots(ctx context.Context, state state.BeaconState, slot types
// Given the start slot and the end slot, this returns the finalized beacon blocks in between. // Given the start slot and the end slot, this returns the finalized beacon blocks in between.
// Since hot states don't have finalized blocks, this should ONLY be used for replaying cold state. // Since hot states don't have finalized blocks, this should ONLY be used for replaying cold state.
func (s *State) loadFinalizedBlocks(ctx context.Context, startSlot, endSlot types.Slot) ([]block.SignedBeaconBlock, error) { func (s *State) loadFinalizedBlocks(ctx context.Context, startSlot, endSlot types.Slot) ([]interfaces.SignedBeaconBlock, error) {
f := filters.NewFilter().SetStartSlot(startSlot).SetEndSlot(endSlot) f := filters.NewFilter().SetStartSlot(startSlot).SetEndSlot(endSlot)
bs, bRoots, err := s.beaconDB.Blocks(ctx, f) bs, bRoots, err := s.beaconDB.Blocks(ctx, f)
if err != nil { if err != nil {
@@ -246,7 +246,7 @@ func (s *State) loadFinalizedBlocks(ctx context.Context, startSlot, endSlot type
if len(bs) != len(bRoots) { if len(bs) != len(bRoots) {
return nil, errors.New("length of blocks and roots don't match") return nil, errors.New("length of blocks and roots don't match")
} }
fbs := make([]block.SignedBeaconBlock, 0, len(bs)) fbs := make([]interfaces.SignedBeaconBlock, 0, len(bs))
for i := len(bs) - 1; i >= 0; i-- { for i := len(bs) - 1; i >= 0; i-- {
if s.beaconDB.IsFinalizedBlock(ctx, bRoots[i]) { if s.beaconDB.IsFinalizedBlock(ctx, bRoots[i]) {
fbs = append(fbs, bs[i]) fbs = append(fbs, bs[i])

View File

@@ -8,7 +8,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/db"
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -43,7 +43,7 @@ func TestReplayBlocks_AllSkipSlots(t *testing.T) {
service := New(beaconDB) service := New(beaconDB)
targetSlot := params.BeaconConfig().SlotsPerEpoch - 1 targetSlot := params.BeaconConfig().SlotsPerEpoch - 1
newState, err := service.ReplayBlocks(context.Background(), beaconState, []block.SignedBeaconBlock{}, targetSlot) newState, err := service.ReplayBlocks(context.Background(), beaconState, []interfaces.SignedBeaconBlock{}, targetSlot)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, targetSlot, newState.Slot(), "Did not advance slots") assert.Equal(t, targetSlot, newState.Slot(), "Did not advance slots")
} }
@@ -72,7 +72,7 @@ func TestReplayBlocks_SameSlot(t *testing.T) {
service := New(beaconDB) service := New(beaconDB)
targetSlot := beaconState.Slot() targetSlot := beaconState.Slot()
newState, err := service.ReplayBlocks(context.Background(), beaconState, []block.SignedBeaconBlock{}, targetSlot) newState, err := service.ReplayBlocks(context.Background(), beaconState, []interfaces.SignedBeaconBlock{}, targetSlot)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, targetSlot, newState.Slot(), "Did not advance slots") assert.Equal(t, targetSlot, newState.Slot(), "Did not advance slots")
} }
@@ -106,7 +106,7 @@ func TestReplayBlocks_LowerSlotBlock(t *testing.T) {
b.Block.Slot = beaconState.Slot() - 1 b.Block.Slot = beaconState.Slot() - 1
wsb, err := wrapper.WrappedSignedBeaconBlock(b) wsb, err := wrapper.WrappedSignedBeaconBlock(b)
require.NoError(t, err) require.NoError(t, err)
newState, err := service.ReplayBlocks(context.Background(), beaconState, []block.SignedBeaconBlock{wsb}, targetSlot) newState, err := service.ReplayBlocks(context.Background(), beaconState, []interfaces.SignedBeaconBlock{wsb}, targetSlot)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, targetSlot, newState.Slot(), "Did not advance slots") assert.Equal(t, targetSlot, newState.Slot(), "Did not advance slots")
} }
@@ -132,7 +132,7 @@ func TestReplayBlocks_ThroughForkBoundary(t *testing.T) {
service := New(testDB.SetupDB(t)) service := New(testDB.SetupDB(t))
targetSlot := params.BeaconConfig().SlotsPerEpoch targetSlot := params.BeaconConfig().SlotsPerEpoch
newState, err := service.ReplayBlocks(context.Background(), beaconState, []block.SignedBeaconBlock{}, targetSlot) newState, err := service.ReplayBlocks(context.Background(), beaconState, []interfaces.SignedBeaconBlock{}, targetSlot)
require.NoError(t, err) require.NoError(t, err)
// Verify state is version Altair. // Verify state is version Altair.
@@ -162,7 +162,7 @@ func TestReplayBlocks_ThroughBellatrixForkBoundary(t *testing.T) {
service := New(testDB.SetupDB(t)) service := New(testDB.SetupDB(t))
targetSlot := params.BeaconConfig().SlotsPerEpoch * 2 targetSlot := params.BeaconConfig().SlotsPerEpoch * 2
newState, err := service.ReplayBlocks(context.Background(), beaconState, []block.SignedBeaconBlock{}, targetSlot) newState, err := service.ReplayBlocks(context.Background(), beaconState, []interfaces.SignedBeaconBlock{}, targetSlot)
require.NoError(t, err) require.NoError(t, err)
// Verify state is version Altair. // Verify state is version Altair.

View File

@@ -7,7 +7,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"go.opencensus.io/trace" "go.opencensus.io/trace"
@@ -27,9 +27,9 @@ const (
// HistoryAccessor describes the minimum set of database methods needed to support the ReplayerBuilder. // HistoryAccessor describes the minimum set of database methods needed to support the ReplayerBuilder.
type HistoryAccessor interface { type HistoryAccessor interface {
HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]block.SignedBeaconBlock, error) HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]interfaces.SignedBeaconBlock, error)
GenesisBlock(ctx context.Context) (block.SignedBeaconBlock, error) GenesisBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error)
Block(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) Block(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error)
StateOrError(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error) StateOrError(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error)
} }
@@ -60,7 +60,7 @@ var _ Replayer = &stateReplayer{}
// chainer is responsible for supplying the chain components necessary to rebuild a state, // chainer is responsible for supplying the chain components necessary to rebuild a state,
// namely a starting BeaconState and all available blocks from the starting state up to and including the target slot // namely a starting BeaconState and all available blocks from the starting state up to and including the target slot
type chainer interface { type chainer interface {
chainForSlot(ctx context.Context, target types.Slot) (state.BeaconState, []block.SignedBeaconBlock, error) chainForSlot(ctx context.Context, target types.Slot) (state.BeaconState, []interfaces.SignedBeaconBlock, error)
} }
type stateReplayer struct { type stateReplayer struct {
@@ -77,7 +77,7 @@ func (rs *stateReplayer) ReplayBlocks(ctx context.Context) (state.BeaconState, e
defer span.End() defer span.End()
var s state.BeaconState var s state.BeaconState
var descendants []block.SignedBeaconBlock var descendants []interfaces.SignedBeaconBlock
var err error var err error
switch rs.method { switch rs.method {
case forSlot: case forSlot:

View File

@@ -4,14 +4,14 @@ import (
"context" "context"
"testing" "testing"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/require"
) )
func headerFromBlock(b block.SignedBeaconBlock) (*ethpb.BeaconBlockHeader, error) { func headerFromBlock(b interfaces.SignedBeaconBlock) (*ethpb.BeaconBlockHeader, error) {
bodyRoot, err := b.Block().Body().HashTreeRoot() bodyRoot, err := b.Block().Body().HashTreeRoot()
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -12,7 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/sync/backfill" "github.com/prysmaticlabs/prysm/beacon-chain/sync/backfill"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -27,8 +27,8 @@ type StateManager interface {
Resume(ctx context.Context, fState state.BeaconState) (state.BeaconState, error) Resume(ctx context.Context, fState state.BeaconState) (state.BeaconState, error)
SaveFinalizedState(fSlot types.Slot, fRoot [32]byte, fState state.BeaconState) SaveFinalizedState(fSlot types.Slot, fRoot [32]byte, fState state.BeaconState)
MigrateToCold(ctx context.Context, fRoot [32]byte) error MigrateToCold(ctx context.Context, fRoot [32]byte) error
ReplayBlocks(ctx context.Context, state state.BeaconState, signed []block.SignedBeaconBlock, targetSlot types.Slot) (state.BeaconState, error) ReplayBlocks(ctx context.Context, state state.BeaconState, signed []interfaces.SignedBeaconBlock, targetSlot types.Slot) (state.BeaconState, error)
LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, endBlockRoot [32]byte) ([]block.SignedBeaconBlock, error) LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, endBlockRoot [32]byte) ([]interfaces.SignedBeaconBlock, error)
HasState(ctx context.Context, blockRoot [32]byte) (bool, error) HasState(ctx context.Context, blockRoot [32]byte) (bool, error)
HasStateInCache(ctx context.Context, blockRoot [32]byte) (bool, error) HasStateInCache(ctx context.Context, blockRoot [32]byte) (bool, error)
StateByRoot(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error) StateByRoot(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error)

View File

@@ -83,7 +83,7 @@ go_library(
"//cmd/beacon-chain/flags:go_default_library", "//cmd/beacon-chain/flags:go_default_library",
"//config/features:go_default_library", "//config/features:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//container/slice:go_default_library", "//container/slice:go_default_library",
@@ -194,7 +194,7 @@ go_test(
"//cmd/beacon-chain/flags:go_default_library", "//cmd/beacon-chain/flags:go_default_library",
"//config/fieldparams:go_default_library", "//config/fieldparams:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//crypto/bls:go_default_library", "//crypto/bls:go_default_library",

View File

@@ -8,7 +8,7 @@ go_library(
deps = [ deps = [
"//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/db:go_default_library", "//beacon-chain/db:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"@com_github_pkg_errors//:go_default_library", "@com_github_pkg_errors//:go_default_library",
], ],
@@ -22,7 +22,7 @@ go_test(
"//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/db:go_default_library", "//beacon-chain/db:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//testing/require:go_default_library", "//testing/require:go_default_library",

View File

@@ -6,7 +6,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
) )
@@ -118,5 +118,5 @@ type BackfillDB interface {
GenesisBlockRoot(ctx context.Context) ([32]byte, error) GenesisBlockRoot(ctx context.Context) ([32]byte, error)
OriginCheckpointBlockRoot(ctx context.Context) ([32]byte, error) OriginCheckpointBlockRoot(ctx context.Context) ([32]byte, error)
BackfillBlockRoot(ctx context.Context) ([32]byte, error) BackfillBlockRoot(ctx context.Context) ([32]byte, error)
Block(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) Block(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error)
} }

View File

@@ -6,10 +6,10 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/require"
@@ -23,7 +23,7 @@ type mockBackfillDB struct {
genesisBlockRoot func(ctx context.Context) ([32]byte, error) genesisBlockRoot func(ctx context.Context) ([32]byte, error)
originCheckpointBlockRoot func(ctx context.Context) ([32]byte, error) originCheckpointBlockRoot func(ctx context.Context) ([32]byte, error)
backfillBlockRoot func(ctx context.Context) ([32]byte, error) backfillBlockRoot func(ctx context.Context) ([32]byte, error)
block func(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) block func(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error)
} }
var _ BackfillDB = &mockBackfillDB{} var _ BackfillDB = &mockBackfillDB{}
@@ -56,7 +56,7 @@ func (db *mockBackfillDB) BackfillBlockRoot(ctx context.Context) ([32]byte, erro
return [32]byte{}, errEmptyMockDBMethod return [32]byte{}, errEmptyMockDBMethod
} }
func (db *mockBackfillDB) Block(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) { func (db *mockBackfillDB) Block(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error) {
if db.block != nil { if db.block != nil {
return db.block(ctx, blockRoot) return db.block(ctx, blockRoot)
} }
@@ -143,7 +143,7 @@ func goodBlockRoot(root [32]byte) func(ctx context.Context) ([32]byte, error) {
} }
} }
func setupTestBlock(slot types.Slot) (block.SignedBeaconBlock, error) { func setupTestBlock(slot types.Slot) (interfaces.SignedBeaconBlock, error) {
bRaw := util.NewBeaconBlock() bRaw := util.NewBeaconBlock()
b, err := wrapper.WrappedSignedBeaconBlock(bRaw) b, err := wrapper.WrappedSignedBeaconBlock(bRaw)
if err != nil { if err != nil {
@@ -191,7 +191,7 @@ func TestReload(t *testing.T) {
return [32]byte{}, db.ErrNotFoundGenesisBlockRoot return [32]byte{}, db.ErrNotFoundGenesisBlockRoot
}, },
originCheckpointBlockRoot: goodBlockRoot(originRoot), originCheckpointBlockRoot: goodBlockRoot(originRoot),
block: func(ctx context.Context, root [32]byte) (block.SignedBeaconBlock, error) { block: func(ctx context.Context, root [32]byte) (interfaces.SignedBeaconBlock, error) {
switch root { switch root {
case originRoot: case originRoot:
return originBlock, nil return originBlock, nil
@@ -208,7 +208,7 @@ func TestReload(t *testing.T) {
return [32]byte{}, derp return [32]byte{}, derp
}, },
originCheckpointBlockRoot: goodBlockRoot(originRoot), originCheckpointBlockRoot: goodBlockRoot(originRoot),
block: func(ctx context.Context, root [32]byte) (block.SignedBeaconBlock, error) { block: func(ctx context.Context, root [32]byte) (interfaces.SignedBeaconBlock, error) {
switch root { switch root {
case originRoot: case originRoot:
return originBlock, nil return originBlock, nil
@@ -231,7 +231,7 @@ func TestReload(t *testing.T) {
db: &mockBackfillDB{ db: &mockBackfillDB{
genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash),
originCheckpointBlockRoot: goodBlockRoot(originRoot), originCheckpointBlockRoot: goodBlockRoot(originRoot),
block: func(ctx context.Context, root [32]byte) (block.SignedBeaconBlock, error) { block: func(ctx context.Context, root [32]byte) (interfaces.SignedBeaconBlock, error) {
return nil, nil return nil, nil
}, },
}, },
@@ -242,7 +242,7 @@ func TestReload(t *testing.T) {
db: &mockBackfillDB{ db: &mockBackfillDB{
genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash),
originCheckpointBlockRoot: goodBlockRoot(originRoot), originCheckpointBlockRoot: goodBlockRoot(originRoot),
block: func(ctx context.Context, root [32]byte) (block.SignedBeaconBlock, error) { block: func(ctx context.Context, root [32]byte) (interfaces.SignedBeaconBlock, error) {
return nil, derp return nil, derp
}, },
}, },
@@ -253,7 +253,7 @@ func TestReload(t *testing.T) {
db: &mockBackfillDB{ db: &mockBackfillDB{
genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash),
originCheckpointBlockRoot: goodBlockRoot(originRoot), originCheckpointBlockRoot: goodBlockRoot(originRoot),
block: func(ctx context.Context, root [32]byte) (block.SignedBeaconBlock, error) { block: func(ctx context.Context, root [32]byte) (interfaces.SignedBeaconBlock, error) {
return originBlock, nil return originBlock, nil
}, },
backfillBlockRoot: func(ctx context.Context) ([32]byte, error) { backfillBlockRoot: func(ctx context.Context) ([32]byte, error) {
@@ -267,7 +267,7 @@ func TestReload(t *testing.T) {
db: &mockBackfillDB{ db: &mockBackfillDB{
genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash),
originCheckpointBlockRoot: goodBlockRoot(originRoot), originCheckpointBlockRoot: goodBlockRoot(originRoot),
block: func(ctx context.Context, root [32]byte) (block.SignedBeaconBlock, error) { block: func(ctx context.Context, root [32]byte) (interfaces.SignedBeaconBlock, error) {
switch root { switch root {
case originRoot: case originRoot:
return originBlock, nil return originBlock, nil
@@ -287,7 +287,7 @@ func TestReload(t *testing.T) {
db: &mockBackfillDB{ db: &mockBackfillDB{
genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash),
originCheckpointBlockRoot: goodBlockRoot(originRoot), originCheckpointBlockRoot: goodBlockRoot(originRoot),
block: func(ctx context.Context, root [32]byte) (block.SignedBeaconBlock, error) { block: func(ctx context.Context, root [32]byte) (interfaces.SignedBeaconBlock, error) {
switch root { switch root {
case originRoot: case originRoot:
return originBlock, nil return originBlock, nil
@@ -305,7 +305,7 @@ func TestReload(t *testing.T) {
db: &mockBackfillDB{ db: &mockBackfillDB{
genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash),
originCheckpointBlockRoot: goodBlockRoot(originRoot), originCheckpointBlockRoot: goodBlockRoot(originRoot),
block: func(ctx context.Context, root [32]byte) (block.SignedBeaconBlock, error) { block: func(ctx context.Context, root [32]byte) (interfaces.SignedBeaconBlock, error) {
switch root { switch root {
case originRoot: case originRoot:
return originBlock, nil return originBlock, nil
@@ -323,7 +323,7 @@ func TestReload(t *testing.T) {
db: &mockBackfillDB{ db: &mockBackfillDB{
genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash),
originCheckpointBlockRoot: goodBlockRoot(originRoot), originCheckpointBlockRoot: goodBlockRoot(originRoot),
block: func(ctx context.Context, root [32]byte) (block.SignedBeaconBlock, error) { block: func(ctx context.Context, root [32]byte) (interfaces.SignedBeaconBlock, error) {
switch root { switch root {
case originRoot: case originRoot:
return originBlock, nil return originBlock, nil

View File

@@ -16,7 +16,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/p2p"
p2ptesting "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" p2ptesting "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/require"
@@ -72,7 +72,7 @@ func TestService_decodePubsubMessage(t *testing.T) {
}, },
}, },
wantErr: nil, wantErr: nil,
want: func() block.SignedBeaconBlock { want: func() interfaces.SignedBeaconBlock {
wsb, err := wrapper.WrappedSignedBeaconBlock(util.NewBeaconBlock()) wsb, err := wrapper.WrappedSignedBeaconBlock(util.NewBeaconBlock())
require.NoError(t, err) require.NoError(t, err)
return wsb return wsb

View File

@@ -29,7 +29,7 @@ go_library(
"//beacon-chain/sync:go_default_library", "//beacon-chain/sync:go_default_library",
"//cmd/beacon-chain/flags:go_default_library", "//cmd/beacon-chain/flags:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//crypto/rand:go_default_library", "//crypto/rand:go_default_library",
"//encoding/bytesutil:go_default_library", "//encoding/bytesutil:go_default_library",
@@ -125,7 +125,7 @@ go_test(
"//cmd/beacon-chain/flags:go_default_library", "//cmd/beacon-chain/flags:go_default_library",
"//config/features:go_default_library", "//config/features:go_default_library",
"//config/params:go_default_library", "//config/params:go_default_library",
"//consensus-types/block:go_default_library", "//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library", "//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library", "//consensus-types/wrapper:go_default_library",
"//container/slice:go_default_library", "//container/slice:go_default_library",

View File

@@ -15,7 +15,7 @@ import (
prysmsync "github.com/prysmaticlabs/prysm/beacon-chain/sync" prysmsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/crypto/rand" "github.com/prysmaticlabs/prysm/crypto/rand"
p2ppb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" p2ppb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -103,7 +103,7 @@ type fetchRequestResponse struct {
pid peer.ID pid peer.ID
start types.Slot start types.Slot
count uint64 count uint64
blocks []block.SignedBeaconBlock blocks []interfaces.SignedBeaconBlock
err error err error
} }
@@ -244,7 +244,7 @@ func (f *blocksFetcher) handleRequest(ctx context.Context, start types.Slot, cou
response := &fetchRequestResponse{ response := &fetchRequestResponse{
start: start, start: start,
count: count, count: count,
blocks: []block.SignedBeaconBlock{}, blocks: []interfaces.SignedBeaconBlock{},
err: nil, err: nil,
} }
@@ -278,7 +278,7 @@ func (f *blocksFetcher) fetchBlocksFromPeer(
ctx context.Context, ctx context.Context,
start types.Slot, count uint64, start types.Slot, count uint64,
peers []peer.ID, peers []peer.ID,
) ([]block.SignedBeaconBlock, peer.ID, error) { ) ([]interfaces.SignedBeaconBlock, peer.ID, error) {
ctx, span := trace.StartSpan(ctx, "initialsync.fetchBlocksFromPeer") ctx, span := trace.StartSpan(ctx, "initialsync.fetchBlocksFromPeer")
defer span.End() defer span.End()
@@ -302,7 +302,7 @@ func (f *blocksFetcher) requestBlocks(
ctx context.Context, ctx context.Context,
req *p2ppb.BeaconBlocksByRangeRequest, req *p2ppb.BeaconBlocksByRangeRequest,
pid peer.ID, pid peer.ID,
) ([]block.SignedBeaconBlock, error) { ) ([]interfaces.SignedBeaconBlock, error) {
if ctx.Err() != nil { if ctx.Err() != nil {
return nil, ctx.Err() return nil, ctx.Err()
} }
@@ -331,7 +331,7 @@ func (f *blocksFetcher) requestBlocksByRoot(
ctx context.Context, ctx context.Context,
req *p2pTypes.BeaconBlockByRootsReq, req *p2pTypes.BeaconBlockByRootsReq,
pid peer.ID, pid peer.ID,
) ([]block.SignedBeaconBlock, error) { ) ([]interfaces.SignedBeaconBlock, error) {
if ctx.Err() != nil { if ctx.Err() != nil {
return nil, ctx.Err() return nil, ctx.Err()
} }

View File

@@ -18,7 +18,7 @@ import (
beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync" beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/container/slice" "github.com/prysmaticlabs/prysm/container/slice"
@@ -301,9 +301,9 @@ func TestBlocksFetcher_RoundRobin(t *testing.T) {
fetcher.stop() fetcher.stop()
}() }()
processFetchedBlocks := func() ([]block.SignedBeaconBlock, error) { processFetchedBlocks := func() ([]interfaces.SignedBeaconBlock, error) {
defer cancel() defer cancel()
var unionRespBlocks []block.SignedBeaconBlock var unionRespBlocks []interfaces.SignedBeaconBlock
for { for {
select { select {
@@ -449,7 +449,7 @@ func TestBlocksFetcher_handleRequest(t *testing.T) {
} }
}() }()
var blocks []block.SignedBeaconBlock var blocks []interfaces.SignedBeaconBlock
select { select {
case <-ctx.Done(): case <-ctx.Done():
t.Error(ctx.Err()) t.Error(ctx.Err())
@@ -600,7 +600,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
req *ethpb.BeaconBlocksByRangeRequest req *ethpb.BeaconBlocksByRangeRequest
handlerGenFn func(req *ethpb.BeaconBlocksByRangeRequest) func(stream network.Stream) handlerGenFn func(req *ethpb.BeaconBlocksByRangeRequest) func(stream network.Stream)
wantedErr string wantedErr string
validate func(req *ethpb.BeaconBlocksByRangeRequest, blocks []block.SignedBeaconBlock) validate func(req *ethpb.BeaconBlocksByRangeRequest, blocks []interfaces.SignedBeaconBlock)
}{ }{
{ {
name: "no error", name: "no error",
@@ -622,7 +622,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
assert.NoError(t, stream.Close()) assert.NoError(t, stream.Close())
} }
}, },
validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []block.SignedBeaconBlock) { validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []interfaces.SignedBeaconBlock) {
assert.Equal(t, req.Count, uint64(len(blocks))) assert.Equal(t, req.Count, uint64(len(blocks)))
}, },
}, },
@@ -646,7 +646,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
assert.NoError(t, stream.Close()) assert.NoError(t, stream.Close())
} }
}, },
validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []block.SignedBeaconBlock) { validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []interfaces.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks)) assert.Equal(t, 0, len(blocks))
}, },
wantedErr: beaconsync.ErrInvalidFetchedData.Error(), wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
@@ -675,7 +675,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
assert.NoError(t, stream.Close()) assert.NoError(t, stream.Close())
} }
}, },
validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []block.SignedBeaconBlock) { validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []interfaces.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks)) assert.Equal(t, 0, len(blocks))
}, },
wantedErr: beaconsync.ErrInvalidFetchedData.Error(), wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
@@ -705,7 +705,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
assert.NoError(t, stream.Close()) assert.NoError(t, stream.Close())
} }
}, },
validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []block.SignedBeaconBlock) { validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []interfaces.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks)) assert.Equal(t, 0, len(blocks))
}, },
wantedErr: beaconsync.ErrInvalidFetchedData.Error(), wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
@@ -741,7 +741,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
} }
}, },
wantedErr: beaconsync.ErrInvalidFetchedData.Error(), wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []block.SignedBeaconBlock) { validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []interfaces.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks)) assert.Equal(t, 0, len(blocks))
}, },
}, },
@@ -776,7 +776,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
} }
}, },
wantedErr: beaconsync.ErrInvalidFetchedData.Error(), wantedErr: beaconsync.ErrInvalidFetchedData.Error(),
validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []block.SignedBeaconBlock) { validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []interfaces.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks)) assert.Equal(t, 0, len(blocks))
}, },
}, },
@@ -804,7 +804,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
assert.NoError(t, stream.Close()) assert.NoError(t, stream.Close())
} }
}, },
validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []block.SignedBeaconBlock) { validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []interfaces.SignedBeaconBlock) {
assert.Equal(t, 2, len(blocks)) assert.Equal(t, 2, len(blocks))
}, },
}, },
@@ -832,7 +832,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T)
assert.NoError(t, stream.Close()) assert.NoError(t, stream.Close())
} }
}, },
validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []block.SignedBeaconBlock) { validate: func(req *ethpb.BeaconBlocksByRangeRequest, blocks []interfaces.SignedBeaconBlock) {
assert.Equal(t, 0, len(blocks)) assert.Equal(t, 0, len(blocks))
}, },
wantedErr: beaconsync.ErrInvalidFetchedData.Error(), wantedErr: beaconsync.ErrInvalidFetchedData.Error(),

View File

@@ -10,7 +10,7 @@ import (
p2pTypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" p2pTypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
p2ppb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" p2ppb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -24,7 +24,7 @@ import (
// either in DB or initial sync cache. // either in DB or initial sync cache.
type forkData struct { type forkData struct {
peer peer.ID peer peer.ID
blocks []block.SignedBeaconBlock blocks []interfaces.SignedBeaconBlock
} }
// nonSkippedSlotAfter checks slots after the given one in an attempt to find a non-empty future slot. // nonSkippedSlotAfter checks slots after the given one in an attempt to find a non-empty future slot.
@@ -257,8 +257,8 @@ func (f *blocksFetcher) findForkWithPeer(ctx context.Context, pid peer.ID, slot
} }
// findAncestor tries to figure out common ancestor slot that connects a given root to known block. // findAncestor tries to figure out common ancestor slot that connects a given root to known block.
func (f *blocksFetcher) findAncestor(ctx context.Context, pid peer.ID, b block.SignedBeaconBlock) (*forkData, error) { func (f *blocksFetcher) findAncestor(ctx context.Context, pid peer.ID, b interfaces.SignedBeaconBlock) (*forkData, error) {
outBlocks := []block.SignedBeaconBlock{b} outBlocks := []interfaces.SignedBeaconBlock{b}
for i := uint64(0); i < backtrackingMaxHops; i++ { for i := uint64(0); i < backtrackingMaxHops; i++ {
parentRoot := bytesutil.ToBytes32(outBlocks[len(outBlocks)-1].Block().ParentRoot()) parentRoot := bytesutil.ToBytes32(outBlocks[len(outBlocks)-1].Block().ParentRoot())
if f.db.HasBlock(ctx, parentRoot) || f.chain.HasInitSyncBlock(parentRoot) { if f.db.HasBlock(ctx, parentRoot) || f.chain.HasInitSyncBlock(parentRoot) {

View File

@@ -9,7 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/p2p"
beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync" beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/time/slots" "github.com/prysmaticlabs/prysm/time/slots"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@@ -89,7 +89,7 @@ type blocksQueue struct {
// blocksQueueFetchedData is a data container that is returned from a queue on each step. // blocksQueueFetchedData is a data container that is returned from a queue on each step.
type blocksQueueFetchedData struct { type blocksQueueFetchedData struct {
pid peer.ID pid peer.ID
blocks []block.SignedBeaconBlock blocks []interfaces.SignedBeaconBlock
} }
// newBlocksQueue creates initialized priority queue. // newBlocksQueue creates initialized priority queue.

View File

@@ -14,7 +14,7 @@ import (
p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync" beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/container/slice" "github.com/prysmaticlabs/prysm/container/slice"
@@ -254,7 +254,7 @@ func TestBlocksQueue_Loop(t *testing.T) {
highestExpectedSlot: tt.highestExpectedSlot, highestExpectedSlot: tt.highestExpectedSlot,
}) })
assert.NoError(t, queue.start()) assert.NoError(t, queue.start())
processBlock := func(block block.SignedBeaconBlock) error { processBlock := func(block interfaces.SignedBeaconBlock) error {
if !beaconDB.HasBlock(ctx, bytesutil.ToBytes32(block.Block().ParentRoot())) { if !beaconDB.HasBlock(ctx, bytesutil.ToBytes32(block.Block().ParentRoot())) {
return fmt.Errorf("%w: %#x", errParentDoesNotExist, block.Block().ParentRoot()) return fmt.Errorf("%w: %#x", errParentDoesNotExist, block.Block().ParentRoot())
} }
@@ -265,7 +265,7 @@ func TestBlocksQueue_Loop(t *testing.T) {
return mc.ReceiveBlock(ctx, block, root) return mc.ReceiveBlock(ctx, block, root)
} }
var blocks []block.SignedBeaconBlock var blocks []interfaces.SignedBeaconBlock
for data := range queue.fetchedData { for data := range queue.fetchedData {
for _, block := range data.blocks { for _, block := range data.blocks {
if err := processBlock(block); err != nil { if err := processBlock(block); err != nil {
@@ -526,7 +526,7 @@ func TestBlocksQueue_onDataReceivedEvent(t *testing.T) {
handlerFn := queue.onDataReceivedEvent(ctx) handlerFn := queue.onDataReceivedEvent(ctx)
response := &fetchRequestResponse{ response := &fetchRequestResponse{
pid: "abc", pid: "abc",
blocks: []block.SignedBeaconBlock{ blocks: []interfaces.SignedBeaconBlock{
wsb, wsb,
wsb.Copy(), wsb.Copy(),
}, },
@@ -535,7 +535,7 @@ func TestBlocksQueue_onDataReceivedEvent(t *testing.T) {
state: stateScheduled, state: stateScheduled,
} }
assert.Equal(t, peer.ID(""), fsm.pid) assert.Equal(t, peer.ID(""), fsm.pid)
assert.DeepSSZEqual(t, []block.SignedBeaconBlock(nil), fsm.blocks) assert.DeepSSZEqual(t, []interfaces.SignedBeaconBlock(nil), fsm.blocks)
updatedState, err := handlerFn(fsm, response) updatedState, err := handlerFn(fsm, response)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, stateDataParsed, updatedState) assert.Equal(t, stateDataParsed, updatedState)
@@ -624,7 +624,7 @@ func TestBlocksQueue_onReadyToSendEvent(t *testing.T) {
queue.smm.addStateMachine(320) queue.smm.addStateMachine(320)
queue.smm.machines[256].state = stateDataParsed queue.smm.machines[256].state = stateDataParsed
queue.smm.machines[256].pid = pidDataParsed queue.smm.machines[256].pid = pidDataParsed
queue.smm.machines[256].blocks = []block.SignedBeaconBlock{ queue.smm.machines[256].blocks = []interfaces.SignedBeaconBlock{
wsb, wsb,
} }
@@ -656,7 +656,7 @@ func TestBlocksQueue_onReadyToSendEvent(t *testing.T) {
queue.smm.addStateMachine(320) queue.smm.addStateMachine(320)
queue.smm.machines[320].state = stateDataParsed queue.smm.machines[320].state = stateDataParsed
queue.smm.machines[320].pid = pidDataParsed queue.smm.machines[320].pid = pidDataParsed
queue.smm.machines[320].blocks = []block.SignedBeaconBlock{ queue.smm.machines[320].blocks = []interfaces.SignedBeaconBlock{
wsb, wsb,
} }
@@ -685,7 +685,7 @@ func TestBlocksQueue_onReadyToSendEvent(t *testing.T) {
queue.smm.addStateMachine(320) queue.smm.addStateMachine(320)
queue.smm.machines[320].state = stateDataParsed queue.smm.machines[320].state = stateDataParsed
queue.smm.machines[320].pid = pidDataParsed queue.smm.machines[320].pid = pidDataParsed
queue.smm.machines[320].blocks = []block.SignedBeaconBlock{ queue.smm.machines[320].blocks = []interfaces.SignedBeaconBlock{
wsb, wsb,
} }
@@ -1320,7 +1320,7 @@ func TestBlocksQueue_stuckWhenHeadIsSetToOrphanedBlock(t *testing.T) {
}) })
require.NoError(t, queue.start()) require.NoError(t, queue.start())
isProcessedBlock := func(ctx context.Context, blk block.SignedBeaconBlock, blkRoot [32]byte) bool { isProcessedBlock := func(ctx context.Context, blk interfaces.SignedBeaconBlock, blkRoot [32]byte) bool {
finalizedSlot, err := slots.EpochStart(mc.FinalizedCheckpt().Epoch) finalizedSlot, err := slots.EpochStart(mc.FinalizedCheckpt().Epoch)
if err != nil { if err != nil {
return false return false

View File

@@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
prysmTime "github.com/prysmaticlabs/prysm/time" prysmTime "github.com/prysmaticlabs/prysm/time"
"github.com/prysmaticlabs/prysm/time/slots" "github.com/prysmaticlabs/prysm/time/slots"
@@ -46,7 +46,7 @@ type stateMachine struct {
start types.Slot start types.Slot
state stateID state stateID
pid peer.ID pid peer.ID
blocks []block.SignedBeaconBlock blocks []interfaces.SignedBeaconBlock
updated time.Time updated time.Time
} }
@@ -78,7 +78,7 @@ func (smm *stateMachineManager) addStateMachine(startSlot types.Slot) *stateMach
smm: smm, smm: smm,
start: startSlot, start: startSlot,
state: stateNew, state: stateNew,
blocks: []block.SignedBeaconBlock{}, blocks: []interfaces.SignedBeaconBlock{},
updated: prysmTime.Now(), updated: prysmTime.Now(),
} }
smm.recalculateMachineAttribs() smm.recalculateMachineAttribs()

View File

@@ -11,7 +11,7 @@ import (
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
"github.com/paulbellamy/ratecounter" "github.com/paulbellamy/ratecounter"
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/time/slots" "github.com/prysmaticlabs/prysm/time/slots"
@@ -24,10 +24,10 @@ const (
) )
// blockReceiverFn defines block receiving function. // blockReceiverFn defines block receiving function.
type blockReceiverFn func(ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error type blockReceiverFn func(ctx context.Context, block interfaces.SignedBeaconBlock, blockRoot [32]byte) error
// batchBlockReceiverFn defines batch receiving function. // batchBlockReceiverFn defines batch receiving function.
type batchBlockReceiverFn func(ctx context.Context, blks []block.SignedBeaconBlock, roots [][32]byte) error type batchBlockReceiverFn func(ctx context.Context, blks []interfaces.SignedBeaconBlock, roots [][32]byte) error
// Round Robin sync looks at the latest peer statuses and syncs up to the highest known epoch. // Round Robin sync looks at the latest peer statuses and syncs up to the highest known epoch.
// //
@@ -178,7 +178,7 @@ func (s *Service) highestFinalizedEpoch() types.Epoch {
} }
// logSyncStatus and increment block processing counter. // logSyncStatus and increment block processing counter.
func (s *Service) logSyncStatus(genesis time.Time, blk block.BeaconBlock, blkRoot [32]byte) { func (s *Service) logSyncStatus(genesis time.Time, blk interfaces.BeaconBlock, blkRoot [32]byte) {
s.counter.Incr(1) s.counter.Incr(1)
rate := float64(s.counter.Rate()) / counterSeconds rate := float64(s.counter.Rate()) / counterSeconds
if rate == 0 { if rate == 0 {
@@ -198,7 +198,7 @@ func (s *Service) logSyncStatus(genesis time.Time, blk block.BeaconBlock, blkRoo
} }
// logBatchSyncStatus and increments the block processing counter. // logBatchSyncStatus and increments the block processing counter.
func (s *Service) logBatchSyncStatus(genesis time.Time, blks []block.SignedBeaconBlock, blkRoot [32]byte) { func (s *Service) logBatchSyncStatus(genesis time.Time, blks []interfaces.SignedBeaconBlock, blkRoot [32]byte) {
s.counter.Incr(int64(len(blks))) s.counter.Incr(int64(len(blks)))
rate := float64(s.counter.Rate()) / counterSeconds rate := float64(s.counter.Rate()) / counterSeconds
if rate == 0 { if rate == 0 {
@@ -220,7 +220,7 @@ func (s *Service) logBatchSyncStatus(genesis time.Time, blks []block.SignedBeaco
func (s *Service) processBlock( func (s *Service) processBlock(
ctx context.Context, ctx context.Context,
genesis time.Time, genesis time.Time,
blk block.SignedBeaconBlock, blk interfaces.SignedBeaconBlock,
blockReceiver blockReceiverFn, blockReceiver blockReceiverFn,
) error { ) error {
blkRoot, err := blk.Block().HashTreeRoot() blkRoot, err := blk.Block().HashTreeRoot()
@@ -240,7 +240,7 @@ func (s *Service) processBlock(
} }
func (s *Service) processBatchedBlocks(ctx context.Context, genesis time.Time, func (s *Service) processBatchedBlocks(ctx context.Context, genesis time.Time,
blks []block.SignedBeaconBlock, bFunc batchBlockReceiverFn) error { blks []interfaces.SignedBeaconBlock, bFunc batchBlockReceiverFn) error {
if len(blks) == 0 { if len(blks) == 0 {
return errors.New("0 blocks provided into method") return errors.New("0 blocks provided into method")
} }
@@ -299,7 +299,7 @@ func (s *Service) updatePeerScorerStats(pid peer.ID, startSlot types.Slot) {
} }
// isProcessedBlock checks DB and local cache for presence of a given block, to avoid duplicates. // isProcessedBlock checks DB and local cache for presence of a given block, to avoid duplicates.
func (s *Service) isProcessedBlock(ctx context.Context, blk block.SignedBeaconBlock, blkRoot [32]byte) bool { func (s *Service) isProcessedBlock(ctx context.Context, blk interfaces.SignedBeaconBlock, blkRoot [32]byte) bool {
finalizedSlot, err := slots.EpochStart(s.cfg.Chain.FinalizedCheckpt().Epoch) finalizedSlot, err := slots.EpochStart(s.cfg.Chain.FinalizedCheckpt().Epoch)
if err != nil { if err != nil {
return false return false

View File

@@ -10,7 +10,7 @@ import (
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/container/slice" "github.com/prysmaticlabs/prysm/container/slice"
@@ -366,7 +366,7 @@ func TestService_processBlock(t *testing.T) {
wsb, err := wrapper.WrappedSignedBeaconBlock(blk1) wsb, err := wrapper.WrappedSignedBeaconBlock(blk1)
require.NoError(t, err) require.NoError(t, err)
err = s.processBlock(ctx, genesis, wsb, func( err = s.processBlock(ctx, genesis, wsb, func(
ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error { ctx context.Context, block interfaces.SignedBeaconBlock, blockRoot [32]byte) error {
assert.NoError(t, s.cfg.Chain.ReceiveBlock(ctx, block, blockRoot)) assert.NoError(t, s.cfg.Chain.ReceiveBlock(ctx, block, blockRoot))
return nil return nil
}) })
@@ -376,7 +376,7 @@ func TestService_processBlock(t *testing.T) {
wsb, err = wrapper.WrappedSignedBeaconBlock(blk1) wsb, err = wrapper.WrappedSignedBeaconBlock(blk1)
require.NoError(t, err) require.NoError(t, err)
err = s.processBlock(ctx, genesis, wsb, func( err = s.processBlock(ctx, genesis, wsb, func(
ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error { ctx context.Context, block interfaces.SignedBeaconBlock, blockRoot [32]byte) error {
return nil return nil
}) })
assert.ErrorContains(t, errBlockAlreadyProcessed.Error(), err) assert.ErrorContains(t, errBlockAlreadyProcessed.Error(), err)
@@ -385,7 +385,7 @@ func TestService_processBlock(t *testing.T) {
wsb, err = wrapper.WrappedSignedBeaconBlock(blk2) wsb, err = wrapper.WrappedSignedBeaconBlock(blk2)
require.NoError(t, err) require.NoError(t, err)
err = s.processBlock(ctx, genesis, wsb, func( err = s.processBlock(ctx, genesis, wsb, func(
ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error { ctx context.Context, block interfaces.SignedBeaconBlock, blockRoot [32]byte) error {
assert.NoError(t, s.cfg.Chain.ReceiveBlock(ctx, block, blockRoot)) assert.NoError(t, s.cfg.Chain.ReceiveBlock(ctx, block, blockRoot))
return nil return nil
}) })
@@ -422,7 +422,7 @@ func TestService_processBlockBatch(t *testing.T) {
genesis := makeGenesisTime(32) genesis := makeGenesisTime(32)
t.Run("process non-linear batch", func(t *testing.T) { t.Run("process non-linear batch", func(t *testing.T) {
var batch []block.SignedBeaconBlock var batch []interfaces.SignedBeaconBlock
currBlockRoot := genesisBlkRoot currBlockRoot := genesisBlkRoot
for i := types.Slot(1); i < 10; i++ { for i := types.Slot(1); i < 10; i++ {
parentRoot := currBlockRoot parentRoot := currBlockRoot
@@ -441,7 +441,7 @@ func TestService_processBlockBatch(t *testing.T) {
currBlockRoot = blk1Root currBlockRoot = blk1Root
} }
var batch2 []block.SignedBeaconBlock var batch2 []interfaces.SignedBeaconBlock
for i := types.Slot(10); i < 20; i++ { for i := types.Slot(10); i < 20; i++ {
parentRoot := currBlockRoot parentRoot := currBlockRoot
blk1 := util.NewBeaconBlock() blk1 := util.NewBeaconBlock()
@@ -461,7 +461,7 @@ func TestService_processBlockBatch(t *testing.T) {
// Process block normally. // Process block normally.
err = s.processBatchedBlocks(ctx, genesis, batch, func( err = s.processBatchedBlocks(ctx, genesis, batch, func(
ctx context.Context, blks []block.SignedBeaconBlock, blockRoots [][32]byte) error { ctx context.Context, blks []interfaces.SignedBeaconBlock, blockRoots [][32]byte) error {
assert.NoError(t, s.cfg.Chain.ReceiveBlockBatch(ctx, blks, blockRoots)) assert.NoError(t, s.cfg.Chain.ReceiveBlockBatch(ctx, blks, blockRoots))
return nil return nil
}) })
@@ -469,12 +469,12 @@ func TestService_processBlockBatch(t *testing.T) {
// Duplicate processing should trigger error. // Duplicate processing should trigger error.
err = s.processBatchedBlocks(ctx, genesis, batch, func( err = s.processBatchedBlocks(ctx, genesis, batch, func(
ctx context.Context, blocks []block.SignedBeaconBlock, blockRoots [][32]byte) error { ctx context.Context, blocks []interfaces.SignedBeaconBlock, blockRoots [][32]byte) error {
return nil return nil
}) })
assert.ErrorContains(t, "no good blocks in batch", err) assert.ErrorContains(t, "no good blocks in batch", err)
var badBatch2 []block.SignedBeaconBlock var badBatch2 []interfaces.SignedBeaconBlock
for i, b := range batch2 { for i, b := range batch2 {
// create a non-linear batch // create a non-linear batch
if i%3 == 0 && i != 0 { if i%3 == 0 && i != 0 {
@@ -485,7 +485,7 @@ func TestService_processBlockBatch(t *testing.T) {
// Bad batch should fail because it is non linear // Bad batch should fail because it is non linear
err = s.processBatchedBlocks(ctx, genesis, badBatch2, func( err = s.processBatchedBlocks(ctx, genesis, badBatch2, func(
ctx context.Context, blks []block.SignedBeaconBlock, blockRoots [][32]byte) error { ctx context.Context, blks []interfaces.SignedBeaconBlock, blockRoots [][32]byte) error {
return nil return nil
}) })
expectedSubErr := "expected linear block list" expectedSubErr := "expected linear block list"
@@ -493,7 +493,7 @@ func TestService_processBlockBatch(t *testing.T) {
// Continue normal processing, should proceed w/o errors. // Continue normal processing, should proceed w/o errors.
err = s.processBatchedBlocks(ctx, genesis, batch2, func( err = s.processBatchedBlocks(ctx, genesis, batch2, func(
ctx context.Context, blks []block.SignedBeaconBlock, blockRoots [][32]byte) error { ctx context.Context, blks []interfaces.SignedBeaconBlock, blockRoots [][32]byte) error {
assert.NoError(t, s.cfg.Chain.ReceiveBlockBatch(ctx, blks, blockRoots)) assert.NoError(t, s.cfg.Chain.ReceiveBlockBatch(ctx, blks, blockRoots))
return nil return nil
}) })

View File

@@ -14,7 +14,7 @@ import (
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain" "github.com/prysmaticlabs/prysm/beacon-chain/powchain"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/crypto/rand" "github.com/prysmaticlabs/prysm/crypto/rand"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -323,7 +323,7 @@ func (s *Service) clearPendingSlots() {
// Delete block from the list from the pending queue using the slot as key. // Delete block from the list from the pending queue using the slot as key.
// Note: this helper is not thread safe. // Note: this helper is not thread safe.
func (s *Service) deleteBlockFromPendingQueue(slot types.Slot, b block.SignedBeaconBlock, r [32]byte) error { func (s *Service) deleteBlockFromPendingQueue(slot types.Slot, b interfaces.SignedBeaconBlock, r [32]byte) error {
mutexasserts.AssertRWMutexLocked(&s.pendingQueueLock) mutexasserts.AssertRWMutexLocked(&s.pendingQueueLock)
blks := s.pendingBlocksInCache(slot) blks := s.pendingBlocksInCache(slot)
@@ -336,7 +336,7 @@ func (s *Service) deleteBlockFromPendingQueue(slot types.Slot, b block.SignedBea
return err return err
} }
newBlks := make([]block.SignedBeaconBlock, 0, len(blks)) newBlks := make([]interfaces.SignedBeaconBlock, 0, len(blks))
for _, blk := range blks { for _, blk := range blks {
if equality.DeepEqual(blk.Proto(), b.Proto()) { if equality.DeepEqual(blk.Proto(), b.Proto()) {
continue continue
@@ -360,7 +360,7 @@ func (s *Service) deleteBlockFromPendingQueue(slot types.Slot, b block.SignedBea
// Insert block to the list in the pending queue using the slot as key. // Insert block to the list in the pending queue using the slot as key.
// Note: this helper is not thread safe. // Note: this helper is not thread safe.
func (s *Service) insertBlockToPendingQueue(_ types.Slot, b block.SignedBeaconBlock, r [32]byte) error { func (s *Service) insertBlockToPendingQueue(_ types.Slot, b interfaces.SignedBeaconBlock, r [32]byte) error {
mutexasserts.AssertRWMutexLocked(&s.pendingQueueLock) mutexasserts.AssertRWMutexLocked(&s.pendingQueueLock)
if s.seenPendingBlocks[r] { if s.seenPendingBlocks[r] {
@@ -376,21 +376,21 @@ func (s *Service) insertBlockToPendingQueue(_ types.Slot, b block.SignedBeaconBl
} }
// This returns signed beacon blocks given input key from slotToPendingBlocks. // This returns signed beacon blocks given input key from slotToPendingBlocks.
func (s *Service) pendingBlocksInCache(slot types.Slot) []block.SignedBeaconBlock { func (s *Service) pendingBlocksInCache(slot types.Slot) []interfaces.SignedBeaconBlock {
k := slotToCacheKey(slot) k := slotToCacheKey(slot)
value, ok := s.slotToPendingBlocks.Get(k) value, ok := s.slotToPendingBlocks.Get(k)
if !ok { if !ok {
return []block.SignedBeaconBlock{} return []interfaces.SignedBeaconBlock{}
} }
blks, ok := value.([]block.SignedBeaconBlock) blks, ok := value.([]interfaces.SignedBeaconBlock)
if !ok { if !ok {
return []block.SignedBeaconBlock{} return []interfaces.SignedBeaconBlock{}
} }
return blks return blks
} }
// This adds input signed beacon block to slotToPendingBlocks cache. // This adds input signed beacon block to slotToPendingBlocks cache.
func (s *Service) addPendingBlockToCache(b block.SignedBeaconBlock) error { func (s *Service) addPendingBlockToCache(b interfaces.SignedBeaconBlock) error {
if err := helpers.BeaconBlockIsNil(b); err != nil { if err := helpers.BeaconBlockIsNil(b); err != nil {
return err return err
} }

View File

@@ -10,7 +10,7 @@ import (
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/monitoring/tracing"
@@ -139,7 +139,7 @@ func (s *Service) writeBlockRangeToStream(ctx context.Context, startSlot, endSlo
tracing.AnnotateError(span, err) tracing.AnnotateError(span, err)
return err return err
} }
blks = append([]block.SignedBeaconBlock{genBlock}, blks...) blks = append([]interfaces.SignedBeaconBlock{genBlock}, blks...)
roots = append([][32]byte{genRoot}, roots...) roots = append([][32]byte{genRoot}, roots...)
} }
// Filter and sort our retrieved blocks, so that // Filter and sort our retrieved blocks, so that
@@ -207,13 +207,13 @@ func (s *Service) validateRangeRequest(r *pb.BeaconBlocksByRangeRequest) error {
// filters all the provided blocks to ensure they are canonical // filters all the provided blocks to ensure they are canonical
// and are strictly linear. // and are strictly linear.
func (s *Service) filterBlocks(ctx context.Context, blks []block.SignedBeaconBlock, roots [][32]byte, prevRoot *[32]byte, func (s *Service) filterBlocks(ctx context.Context, blks []interfaces.SignedBeaconBlock, roots [][32]byte, prevRoot *[32]byte,
step uint64, startSlot types.Slot) ([]block.SignedBeaconBlock, error) { step uint64, startSlot types.Slot) ([]interfaces.SignedBeaconBlock, error) {
if len(blks) != len(roots) { if len(blks) != len(roots) {
return nil, errors.New("input blks and roots are diff lengths") return nil, errors.New("input blks and roots are diff lengths")
} }
newBlks := make([]block.SignedBeaconBlock, 0, len(blks)) newBlks := make([]interfaces.SignedBeaconBlock, 0, len(blks))
for i, b := range blks { for i, b := range blks {
isCanonical, err := s.cfg.chain.IsCanonical(ctx, roots[i]) isCanonical, err := s.cfg.chain.IsCanonical(ctx, roots[i])
if err != nil { if err != nil {
@@ -250,7 +250,7 @@ func (s *Service) writeErrorResponseToStream(responseCode byte, reason string, s
writeErrorResponseToStream(responseCode, reason, stream, s.cfg.p2p) writeErrorResponseToStream(responseCode, reason, stream, s.cfg.p2p)
} }
func (s *Service) retrieveGenesisBlock(ctx context.Context) (block.SignedBeaconBlock, [32]byte, error) { func (s *Service) retrieveGenesisBlock(ctx context.Context) (interfaces.SignedBeaconBlock, [32]byte, error) {
genBlock, err := s.cfg.beaconDB.GenesisBlock(ctx) genBlock, err := s.cfg.beaconDB.GenesisBlock(ctx)
if err != nil { if err != nil {
return nil, [32]byte{}, err return nil, [32]byte{}, err

View File

@@ -8,7 +8,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
) )
// sendRecentBeaconBlocksRequest sends a recent beacon blocks request to a peer to get // sendRecentBeaconBlocksRequest sends a recent beacon blocks request to a peer to get
@@ -17,7 +17,7 @@ func (s *Service) sendRecentBeaconBlocksRequest(ctx context.Context, blockRoots
ctx, cancel := context.WithTimeout(ctx, respTimeout) ctx, cancel := context.WithTimeout(ctx, respTimeout)
defer cancel() defer cancel()
_, err := SendBeaconBlocksByRootRequest(ctx, s.cfg.chain, s.cfg.p2p, id, blockRoots, func(blk block.SignedBeaconBlock) error { _, err := SendBeaconBlocksByRootRequest(ctx, s.cfg.chain, s.cfg.p2p, id, blockRoots, func(blk interfaces.SignedBeaconBlock) error {
blkRoot, err := blk.Block().HashTreeRoot() blkRoot, err := blk.Block().HashTreeRoot()
if err != nil { if err != nil {
return err return err

View File

@@ -9,7 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/network/forks" "github.com/prysmaticlabs/prysm/network/forks"
"github.com/prysmaticlabs/prysm/runtime/version" "github.com/prysmaticlabs/prysm/runtime/version"
@@ -18,14 +18,14 @@ import (
// chunkBlockWriter writes the given message as a chunked response to the given network // chunkBlockWriter writes the given message as a chunked response to the given network
// stream. // stream.
// response_chunk ::= <result> | <context-bytes> | <encoding-dependent-header> | <encoded-payload> // response_chunk ::= <result> | <context-bytes> | <encoding-dependent-header> | <encoded-payload>
func (s *Service) chunkBlockWriter(stream libp2pcore.Stream, blk block.SignedBeaconBlock) error { func (s *Service) chunkBlockWriter(stream libp2pcore.Stream, blk interfaces.SignedBeaconBlock) error {
SetStreamWriteDeadline(stream, defaultWriteDuration) SetStreamWriteDeadline(stream, defaultWriteDuration)
return WriteBlockChunk(stream, s.cfg.chain, s.cfg.p2p.Encoding(), blk) return WriteBlockChunk(stream, s.cfg.chain, s.cfg.p2p.Encoding(), blk)
} }
// WriteBlockChunk writes block chunk object to stream. // WriteBlockChunk writes block chunk object to stream.
// response_chunk ::= <result> | <context-bytes> | <encoding-dependent-header> | <encoded-payload> // response_chunk ::= <result> | <context-bytes> | <encoding-dependent-header> | <encoded-payload>
func WriteBlockChunk(stream libp2pcore.Stream, chain blockchain.ChainInfoFetcher, encoding encoder.NetworkEncoding, blk block.SignedBeaconBlock) error { func WriteBlockChunk(stream libp2pcore.Stream, chain blockchain.ChainInfoFetcher, encoding encoder.NetworkEncoding, blk interfaces.SignedBeaconBlock) error {
if _, err := stream.Write([]byte{responseCodeSuccess}); err != nil { if _, err := stream.Write([]byte{responseCodeSuccess}); err != nil {
return err return err
} }
@@ -63,7 +63,7 @@ func WriteBlockChunk(stream libp2pcore.Stream, chain blockchain.ChainInfoFetcher
// ReadChunkedBlock handles each response chunk that is sent by the // ReadChunkedBlock handles each response chunk that is sent by the
// peer and converts it into a beacon block. // peer and converts it into a beacon block.
func ReadChunkedBlock(stream libp2pcore.Stream, chain blockchain.ChainInfoFetcher, p2p p2p.P2P, isFirstChunk bool) (block.SignedBeaconBlock, error) { func ReadChunkedBlock(stream libp2pcore.Stream, chain blockchain.ChainInfoFetcher, p2p p2p.P2P, isFirstChunk bool) (interfaces.SignedBeaconBlock, error) {
// Handle deadlines differently for first chunk // Handle deadlines differently for first chunk
if isFirstChunk { if isFirstChunk {
return readFirstChunkedBlock(stream, chain, p2p) return readFirstChunkedBlock(stream, chain, p2p)
@@ -74,7 +74,7 @@ func ReadChunkedBlock(stream libp2pcore.Stream, chain blockchain.ChainInfoFetche
// readFirstChunkedBlock reads the first chunked block and applies the appropriate deadlines to // readFirstChunkedBlock reads the first chunked block and applies the appropriate deadlines to
// it. // it.
func readFirstChunkedBlock(stream libp2pcore.Stream, chain blockchain.ChainInfoFetcher, p2p p2p.P2P) (block.SignedBeaconBlock, error) { func readFirstChunkedBlock(stream libp2pcore.Stream, chain blockchain.ChainInfoFetcher, p2p p2p.P2P) (interfaces.SignedBeaconBlock, error) {
code, errMsg, err := ReadStatusCode(stream, p2p.Encoding()) code, errMsg, err := ReadStatusCode(stream, p2p.Encoding())
if err != nil { if err != nil {
return nil, err return nil, err
@@ -96,7 +96,7 @@ func readFirstChunkedBlock(stream libp2pcore.Stream, chain blockchain.ChainInfoF
// readResponseChunk reads the response from the stream and decodes it into the // readResponseChunk reads the response from the stream and decodes it into the
// provided message type. // provided message type.
func readResponseChunk(stream libp2pcore.Stream, chain blockchain.ChainInfoFetcher, p2p p2p.P2P) (block.SignedBeaconBlock, error) { func readResponseChunk(stream libp2pcore.Stream, chain blockchain.ChainInfoFetcher, p2p p2p.P2P) (interfaces.SignedBeaconBlock, error) {
SetStreamReadDeadline(stream, respTimeout) SetStreamReadDeadline(stream, respTimeout)
code, errMsg, err := readStatusCodeNoDeadline(stream, p2p.Encoding()) code, errMsg, err := readStatusCodeNoDeadline(stream, p2p.Encoding())
if err != nil { if err != nil {
@@ -118,7 +118,7 @@ func readResponseChunk(stream libp2pcore.Stream, chain blockchain.ChainInfoFetch
return blk, err return blk, err
} }
func extractBlockDataType(digest []byte, chain blockchain.ChainInfoFetcher) (block.SignedBeaconBlock, error) { func extractBlockDataType(digest []byte, chain blockchain.ChainInfoFetcher) (interfaces.SignedBeaconBlock, error) {
if len(digest) == 0 { if len(digest) == 0 {
bFunc, ok := types.BlockMap[bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)] bFunc, ok := types.BlockMap[bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)]
if !ok { if !ok {

View File

@@ -8,7 +8,7 @@ import (
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/require"
@@ -30,7 +30,7 @@ func TestExtractBlockDataType(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args args args args
want block.SignedBeaconBlock want interfaces.SignedBeaconBlock
wantErr bool wantErr bool
}{ }{
{ {
@@ -40,7 +40,7 @@ func TestExtractBlockDataType(t *testing.T) {
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}}, chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
}, },
want: func() block.SignedBeaconBlock { want: func() interfaces.SignedBeaconBlock {
wsb, err := wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlock{}) wsb, err := wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlock{})
require.NoError(t, err) require.NoError(t, err)
return wsb return wsb
@@ -71,7 +71,7 @@ func TestExtractBlockDataType(t *testing.T) {
digest: genDigest[:], digest: genDigest[:],
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}}, chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
}, },
want: func() block.SignedBeaconBlock { want: func() interfaces.SignedBeaconBlock {
wsb, err := wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlock{}) wsb, err := wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlock{})
require.NoError(t, err) require.NoError(t, err)
return wsb return wsb
@@ -84,7 +84,7 @@ func TestExtractBlockDataType(t *testing.T) {
digest: altairDigest[:], digest: altairDigest[:],
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}}, chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
}, },
want: func() block.SignedBeaconBlock { want: func() interfaces.SignedBeaconBlock {
wsb, err := wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlockAltair{Block: &ethpb.BeaconBlockAltair{}}) wsb, err := wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlockAltair{Block: &ethpb.BeaconBlockAltair{}})
require.NoError(t, err) require.NoError(t, err)
return wsb return wsb
@@ -97,7 +97,7 @@ func TestExtractBlockDataType(t *testing.T) {
digest: bellatrixDigest[:], digest: bellatrixDigest[:],
chain: &mock.ChainService{ValidatorsRoot: [32]byte{}}, chain: &mock.ChainService{ValidatorsRoot: [32]byte{}},
}, },
want: func() block.SignedBeaconBlock { want: func() interfaces.SignedBeaconBlock {
wsb, err := wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlockBellatrix{Block: &ethpb.BeaconBlockBellatrix{}}) wsb, err := wrapper.WrappedSignedBeaconBlock(&ethpb.SignedBeaconBlockBellatrix{Block: &ethpb.BeaconBlockBellatrix{}})
require.NoError(t, err) require.NoError(t, err)
return wsb return wsb

View File

@@ -10,7 +10,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/p2p"
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/time/slots" "github.com/prysmaticlabs/prysm/time/slots"
@@ -21,13 +21,13 @@ var ErrInvalidFetchedData = errors.New("invalid data returned from peer")
// BeaconBlockProcessor defines a block processing function, which allows to start utilizing // BeaconBlockProcessor defines a block processing function, which allows to start utilizing
// blocks even before all blocks are ready. // blocks even before all blocks are ready.
type BeaconBlockProcessor func(block block.SignedBeaconBlock) error type BeaconBlockProcessor func(block interfaces.SignedBeaconBlock) error
// SendBeaconBlocksByRangeRequest sends BeaconBlocksByRange and returns fetched blocks, if any. // SendBeaconBlocksByRangeRequest sends BeaconBlocksByRange and returns fetched blocks, if any.
func SendBeaconBlocksByRangeRequest( func SendBeaconBlocksByRangeRequest(
ctx context.Context, chain blockchain.ChainInfoFetcher, p2pProvider p2p.P2P, pid peer.ID, ctx context.Context, chain blockchain.ChainInfoFetcher, p2pProvider p2p.P2P, pid peer.ID,
req *pb.BeaconBlocksByRangeRequest, blockProcessor BeaconBlockProcessor, req *pb.BeaconBlocksByRangeRequest, blockProcessor BeaconBlockProcessor,
) ([]block.SignedBeaconBlock, error) { ) ([]interfaces.SignedBeaconBlock, error) {
topic, err := p2p.TopicFromMessage(p2p.BeaconBlocksByRangeMessageName, slots.ToEpoch(chain.CurrentSlot())) topic, err := p2p.TopicFromMessage(p2p.BeaconBlocksByRangeMessageName, slots.ToEpoch(chain.CurrentSlot()))
if err != nil { if err != nil {
return nil, err return nil, err
@@ -39,8 +39,8 @@ func SendBeaconBlocksByRangeRequest(
defer closeStream(stream, log) defer closeStream(stream, log)
// Augment block processing function, if non-nil block processor is provided. // Augment block processing function, if non-nil block processor is provided.
blocks := make([]block.SignedBeaconBlock, 0, req.Count) blocks := make([]interfaces.SignedBeaconBlock, 0, req.Count)
process := func(blk block.SignedBeaconBlock) error { process := func(blk interfaces.SignedBeaconBlock) error {
blocks = append(blocks, blk) blocks = append(blocks, blk)
if blockProcessor != nil { if blockProcessor != nil {
return blockProcessor(blk) return blockProcessor(blk)
@@ -89,7 +89,7 @@ func SendBeaconBlocksByRangeRequest(
func SendBeaconBlocksByRootRequest( func SendBeaconBlocksByRootRequest(
ctx context.Context, chain blockchain.ChainInfoFetcher, p2pProvider p2p.P2P, pid peer.ID, ctx context.Context, chain blockchain.ChainInfoFetcher, p2pProvider p2p.P2P, pid peer.ID,
req *p2ptypes.BeaconBlockByRootsReq, blockProcessor BeaconBlockProcessor, req *p2ptypes.BeaconBlockByRootsReq, blockProcessor BeaconBlockProcessor,
) ([]block.SignedBeaconBlock, error) { ) ([]interfaces.SignedBeaconBlock, error) {
topic, err := p2p.TopicFromMessage(p2p.BeaconBlocksByRootsMessageName, slots.ToEpoch(chain.CurrentSlot())) topic, err := p2p.TopicFromMessage(p2p.BeaconBlocksByRootsMessageName, slots.ToEpoch(chain.CurrentSlot()))
if err != nil { if err != nil {
return nil, err return nil, err
@@ -101,8 +101,8 @@ func SendBeaconBlocksByRootRequest(
defer closeStream(stream, log) defer closeStream(stream, log)
// Augment block processing function, if non-nil block processor is provided. // Augment block processing function, if non-nil block processor is provided.
blocks := make([]block.SignedBeaconBlock, 0, len(*req)) blocks := make([]interfaces.SignedBeaconBlock, 0, len(*req))
process := func(block block.SignedBeaconBlock) error { process := func(block interfaces.SignedBeaconBlock) error {
blocks = append(blocks, block) blocks = append(blocks, block)
if blockProcessor != nil { if blockProcessor != nil {
return blockProcessor(block) return blockProcessor(block)

View File

@@ -15,7 +15,7 @@ import (
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
p2pTypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" p2pTypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -124,9 +124,9 @@ func TestSendRequest_SendBeaconBlocksByRangeRequest(t *testing.T) {
Count: 128, Count: 128,
Step: 1, Step: 1,
} }
blocksFromProcessor := make([]block.SignedBeaconBlock, 0) blocksFromProcessor := make([]interfaces.SignedBeaconBlock, 0)
chain := &mock.ChainService{Genesis: time.Now(), ValidatorsRoot: [32]byte{}} chain := &mock.ChainService{Genesis: time.Now(), ValidatorsRoot: [32]byte{}}
blocks, err := SendBeaconBlocksByRangeRequest(ctx, chain, p1, p2.PeerID(), req, func(block block.SignedBeaconBlock) error { blocks, err := SendBeaconBlocksByRangeRequest(ctx, chain, p1, p2.PeerID(), req, func(block interfaces.SignedBeaconBlock) error {
blocksFromProcessor = append(blocksFromProcessor, block) blocksFromProcessor = append(blocksFromProcessor, block)
return nil return nil
}) })
@@ -149,7 +149,7 @@ func TestSendRequest_SendBeaconBlocksByRangeRequest(t *testing.T) {
} }
errFromProcessor := errors.New("processor error") errFromProcessor := errors.New("processor error")
chain := &mock.ChainService{Genesis: time.Now(), ValidatorsRoot: [32]byte{}} chain := &mock.ChainService{Genesis: time.Now(), ValidatorsRoot: [32]byte{}}
_, err := SendBeaconBlocksByRangeRequest(ctx, chain, p1, p2.PeerID(), req, func(block block.SignedBeaconBlock) error { _, err := SendBeaconBlocksByRangeRequest(ctx, chain, p1, p2.PeerID(), req, func(block interfaces.SignedBeaconBlock) error {
return errFromProcessor return errFromProcessor
}) })
assert.ErrorContains(t, errFromProcessor.Error(), err) assert.ErrorContains(t, errFromProcessor.Error(), err)
@@ -179,7 +179,7 @@ func TestSendRequest_SendBeaconBlocksByRangeRequest(t *testing.T) {
cfg.MaxRequestBlocks = maxRequestBlocks cfg.MaxRequestBlocks = maxRequestBlocks
params.OverrideBeaconNetworkConfig(cfg) params.OverrideBeaconNetworkConfig(cfg)
}() }()
blocks, err = SendBeaconBlocksByRangeRequest(ctx, chain, p1, p2.PeerID(), req, func(block block.SignedBeaconBlock) error { blocks, err = SendBeaconBlocksByRangeRequest(ctx, chain, p1, p2.PeerID(), req, func(block interfaces.SignedBeaconBlock) error {
// Since ssz checks the boundaries, and doesn't normally allow to send requests bigger than // Since ssz checks the boundaries, and doesn't normally allow to send requests bigger than
// the max request size, we are updating max request size dynamically. Even when updated dynamically, // the max request size, we are updating max request size dynamically. Even when updated dynamically,
// no more than max request size of blocks is expected on return. // no more than max request size of blocks is expected on return.
@@ -197,7 +197,7 @@ func TestSendRequest_SendBeaconBlocksByRangeRequest(t *testing.T) {
p1.Connect(p2) p1.Connect(p2)
blocksProcessed := 0 blocksProcessed := 0
expectedErr := errors.New("some error") expectedErr := errors.New("some error")
p2.SetStreamHandler(pcl, knownBlocksProvider(p2, func(block block.SignedBeaconBlock) error { p2.SetStreamHandler(pcl, knownBlocksProvider(p2, func(block interfaces.SignedBeaconBlock) error {
if blocksProcessed > 2 { if blocksProcessed > 2 {
return expectedErr return expectedErr
} }
@@ -392,9 +392,9 @@ func TestSendRequest_SendBeaconBlocksByRootRequest(t *testing.T) {
// No error from block processor. // No error from block processor.
req := &p2pTypes.BeaconBlockByRootsReq{knownRoots[0], knownRoots[1]} req := &p2pTypes.BeaconBlockByRootsReq{knownRoots[0], knownRoots[1]}
blocksFromProcessor := make([]block.SignedBeaconBlock, 0) blocksFromProcessor := make([]interfaces.SignedBeaconBlock, 0)
chain := &mock.ChainService{Genesis: time.Now(), ValidatorsRoot: [32]byte{}} chain := &mock.ChainService{Genesis: time.Now(), ValidatorsRoot: [32]byte{}}
blocks, err := SendBeaconBlocksByRootRequest(ctx, chain, p1, p2.PeerID(), req, func(block block.SignedBeaconBlock) error { blocks, err := SendBeaconBlocksByRootRequest(ctx, chain, p1, p2.PeerID(), req, func(block interfaces.SignedBeaconBlock) error {
blocksFromProcessor = append(blocksFromProcessor, block) blocksFromProcessor = append(blocksFromProcessor, block)
return nil return nil
}) })
@@ -413,7 +413,7 @@ func TestSendRequest_SendBeaconBlocksByRootRequest(t *testing.T) {
req := &p2pTypes.BeaconBlockByRootsReq{knownRoots[0], knownRoots[1]} req := &p2pTypes.BeaconBlockByRootsReq{knownRoots[0], knownRoots[1]}
errFromProcessor := errors.New("processor error") errFromProcessor := errors.New("processor error")
chain := &mock.ChainService{Genesis: time.Now(), ValidatorsRoot: [32]byte{}} chain := &mock.ChainService{Genesis: time.Now(), ValidatorsRoot: [32]byte{}}
_, err := SendBeaconBlocksByRootRequest(ctx, chain, p1, p2.PeerID(), req, func(block block.SignedBeaconBlock) error { _, err := SendBeaconBlocksByRootRequest(ctx, chain, p1, p2.PeerID(), req, func(block interfaces.SignedBeaconBlock) error {
return errFromProcessor return errFromProcessor
}) })
assert.ErrorContains(t, errFromProcessor.Error(), err) assert.ErrorContains(t, errFromProcessor.Error(), err)
@@ -439,7 +439,7 @@ func TestSendRequest_SendBeaconBlocksByRootRequest(t *testing.T) {
cfg.MaxRequestBlocks = maxRequestBlocks cfg.MaxRequestBlocks = maxRequestBlocks
params.OverrideBeaconNetworkConfig(cfg) params.OverrideBeaconNetworkConfig(cfg)
}() }()
blocks, err = SendBeaconBlocksByRootRequest(ctx, chain, p1, p2.PeerID(), req, func(block block.SignedBeaconBlock) error { blocks, err = SendBeaconBlocksByRootRequest(ctx, chain, p1, p2.PeerID(), req, func(block interfaces.SignedBeaconBlock) error {
// Since ssz checks the boundaries, and doesn't normally allow to send requests bigger than // Since ssz checks the boundaries, and doesn't normally allow to send requests bigger than
// the max request size, we are updating max request size dynamically. Even when updated dynamically, // the max request size, we are updating max request size dynamically. Even when updated dynamically,
// no more than max request size of blocks is expected on return. // no more than max request size of blocks is expected on return.
@@ -457,7 +457,7 @@ func TestSendRequest_SendBeaconBlocksByRootRequest(t *testing.T) {
p1.Connect(p2) p1.Connect(p2)
blocksProcessed := 0 blocksProcessed := 0
expectedErr := errors.New("some error") expectedErr := errors.New("some error")
p2.SetStreamHandler(pcl, knownBlocksProvider(p2, func(block block.SignedBeaconBlock) error { p2.SetStreamHandler(pcl, knownBlocksProvider(p2, func(block interfaces.SignedBeaconBlock) error {
if blocksProcessed > 2 { if blocksProcessed > 2 {
return expectedErr return expectedErr
} }
@@ -478,7 +478,7 @@ func TestSendRequest_SendBeaconBlocksByRootRequest(t *testing.T) {
p1.Connect(p2) p1.Connect(p2)
blocksProcessed := 0 blocksProcessed := 0
expectedErr := io.EOF expectedErr := io.EOF
p2.SetStreamHandler(pcl, knownBlocksProvider(p2, func(block block.SignedBeaconBlock) error { p2.SetStreamHandler(pcl, knownBlocksProvider(p2, func(block interfaces.SignedBeaconBlock) error {
if blocksProcessed > 2 { if blocksProcessed > 2 {
return expectedErr return expectedErr
} }

View File

@@ -21,7 +21,7 @@ import (
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing" mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
"github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives" types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -935,9 +935,9 @@ func TestShouldResync(t *testing.T) {
} }
} }
func makeBlocks(t *testing.T, i, n uint64, previousRoot [32]byte) []block.SignedBeaconBlock { func makeBlocks(t *testing.T, i, n uint64, previousRoot [32]byte) []interfaces.SignedBeaconBlock {
blocks := make([]*ethpb.SignedBeaconBlock, n) blocks := make([]*ethpb.SignedBeaconBlock, n)
ifaceBlocks := make([]block.SignedBeaconBlock, n) ifaceBlocks := make([]interfaces.SignedBeaconBlock, n)
for j := i; j < n+i; j++ { for j := i; j < n+i; j++ {
parentRoot := make([]byte, 32) parentRoot := make([]byte, 32)
copy(parentRoot, previousRoot[:]) copy(parentRoot, previousRoot[:])

View File

@@ -4,14 +4,14 @@ import (
"errors" "errors"
"sort" "sort"
"github.com/prysmaticlabs/prysm/consensus-types/block" "github.com/prysmaticlabs/prysm/consensus-types/interfaces"
) )
// A type to represent beacon blocks and roots which have methods // A type to represent beacon blocks and roots which have methods
// which satisfy the Interface in `Sort` so that this type can // which satisfy the Interface in `Sort` so that this type can
// be sorted in ascending order. // be sorted in ascending order.
type sortedObj struct { type sortedObj struct {
blks []block.SignedBeaconBlock blks []interfaces.SignedBeaconBlock
roots [][32]byte roots [][32]byte
} }
@@ -32,14 +32,14 @@ func (s sortedObj) Len() int {
} }
// removes duplicates from provided blocks and roots. // removes duplicates from provided blocks and roots.
func (_ *Service) dedupBlocksAndRoots(blks []block.SignedBeaconBlock, roots [][32]byte) ([]block.SignedBeaconBlock, [][32]byte, error) { func (_ *Service) dedupBlocksAndRoots(blks []interfaces.SignedBeaconBlock, roots [][32]byte) ([]interfaces.SignedBeaconBlock, [][32]byte, error) {
if len(blks) != len(roots) { if len(blks) != len(roots) {
return nil, nil, errors.New("input blks and roots are diff lengths") return nil, nil, errors.New("input blks and roots are diff lengths")
} }
// Remove duplicate blocks received // Remove duplicate blocks received
rootMap := make(map[[32]byte]bool, len(blks)) rootMap := make(map[[32]byte]bool, len(blks))
newBlks := make([]block.SignedBeaconBlock, 0, len(blks)) newBlks := make([]interfaces.SignedBeaconBlock, 0, len(blks))
newRoots := make([][32]byte, 0, len(roots)) newRoots := make([][32]byte, 0, len(roots))
for i, r := range roots { for i, r := range roots {
if rootMap[r] { if rootMap[r] {
@@ -67,7 +67,7 @@ func (_ *Service) dedupRoots(roots [][32]byte) [][32]byte {
// sort the provided blocks and roots in ascending order. This method assumes that the size of // sort the provided blocks and roots in ascending order. This method assumes that the size of
// block slice and root slice is equal. // block slice and root slice is equal.
func (_ *Service) sortBlocksAndRoots(blks []block.SignedBeaconBlock, roots [][32]byte) ([]block.SignedBeaconBlock, [][32]byte) { func (_ *Service) sortBlocksAndRoots(blks []interfaces.SignedBeaconBlock, roots [][32]byte) ([]interfaces.SignedBeaconBlock, [][32]byte) {
obj := sortedObj{ obj := sortedObj{
blks: blks, blks: blks,
roots: roots, roots: roots,

Some files were not shown because too many files have changed in this diff Show More