diff --git a/api/client/beacon/BUILD.bazel b/api/client/beacon/BUILD.bazel index 86c1a206dd..106ad028c3 100644 --- a/api/client/beacon/BUILD.bazel +++ b/api/client/beacon/BUILD.bazel @@ -14,7 +14,7 @@ go_library( "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/rpc/apimiddleware: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", "//encoding/bytesutil:go_default_library", "//encoding/ssz/detect:go_default_library", diff --git a/api/client/beacon/checkpoint.go b/api/client/beacon/checkpoint.go index 0e68e7837a..6a0daefe3b 100644 --- a/api/client/beacon/checkpoint.go +++ b/api/client/beacon/checkpoint.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "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" "github.com/prysmaticlabs/prysm/encoding/ssz/detect" "github.com/prysmaticlabs/prysm/io/file" @@ -25,7 +25,7 @@ type OriginData struct { sb []byte bb []byte st state.BeaconState - b block.SignedBeaconBlock + b interfaces.SignedBeaconBlock cf *detect.VersionedUnmarshaler } diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 8c0afaec46..f21e55b54b 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -64,7 +64,7 @@ go_library( "//config/features:go_default_library", "//config/fieldparams: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", "//crypto/bls:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/beacon-chain/blockchain/chain_info.go b/beacon-chain/blockchain/chain_info.go index 7eafeaaa13..2e4354ba82 100644 --- a/beacon-chain/blockchain/chain_info.go +++ b/beacon-chain/blockchain/chain_info.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -47,7 +47,7 @@ type GenesisFetcher interface { type HeadFetcher interface { HeadSlot() types.Slot 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) HeadValidatorsIndices(ctx context.Context, epoch types.Epoch) ([]types.ValidatorIndex, error) HeadGenesisValidatorsRoot() [32]byte @@ -163,7 +163,7 @@ func (s *Service) HeadRoot(ctx context.Context) ([]byte, error) { // HeadBlock returns the head block of the chain. // If the head is nil from service struct, // 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() defer s.headLock.RUnlock() diff --git a/beacon-chain/blockchain/execution_engine.go b/beacon-chain/blockchain/execution_engine.go index 06500be2bb..75795e1024 100644 --- a/beacon-chain/blockchain/execution_engine.go +++ b/beacon-chain/blockchain/execution_engine.go @@ -14,7 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" 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: // 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. -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") 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. // It returns true if the EL has returned VALID for the block 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") defer span.End() @@ -172,7 +172,7 @@ func (s *Service) notifyNewPayload(ctx context.Context, postStateVersion int, // return True // // 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() { return nil } @@ -181,7 +181,7 @@ func (s *Service) optimisticCandidateBlock(ctx context.Context, blk block.Beacon if err != nil { return err } - if parent == nil { + if parent == nil || parent.IsNil() { return errNilParentInDB } parentIsExecutionBlock, err := blocks.IsExecutionBlock(parent.Block().Body()) diff --git a/beacon-chain/blockchain/execution_engine_test.go b/beacon-chain/blockchain/execution_engine_test.go index 4294159102..d9c7ab71bc 100644 --- a/beacon-chain/blockchain/execution_engine_test.go +++ b/beacon-chain/blockchain/execution_engine_test.go @@ -16,7 +16,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -59,7 +59,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) { tests := []struct { name string - blk block.BeaconBlock + blk interfaces.BeaconBlock finalizedRoot [32]byte newForkchoiceErr error errString string @@ -70,7 +70,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) { }, { name: "phase0 block", - blk: func() block.BeaconBlock { + blk: func() interfaces.BeaconBlock { b, err := wrapper.WrappedBeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}) require.NoError(t, err) return b @@ -78,7 +78,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) { }, { name: "altair block", - blk: func() block.BeaconBlock { + blk: func() interfaces.BeaconBlock { b, err := wrapper.WrappedBeaconBlock(ðpb.BeaconBlockAltair{Body: ðpb.BeaconBlockBodyAltair{}}) require.NoError(t, err) return b @@ -86,7 +86,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) { }, { name: "not execution block", - blk: func() block.BeaconBlock { + blk: func() interfaces.BeaconBlock { b, err := wrapper.WrappedBeaconBlock(ðpb.BeaconBlockBellatrix{ Body: ðpb.BeaconBlockBodyBellatrix{ ExecutionPayload: &v1.ExecutionPayload{ @@ -107,7 +107,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) { }, { name: "happy case: finalized root is altair block", - blk: func() block.BeaconBlock { + blk: func() interfaces.BeaconBlock { b, err := wrapper.WrappedBeaconBlock(ðpb.BeaconBlockBellatrix{ Body: ðpb.BeaconBlockBodyBellatrix{ ExecutionPayload: &v1.ExecutionPayload{}, @@ -120,7 +120,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) { }, { name: "happy case: finalized root is bellatrix block", - blk: func() block.BeaconBlock { + blk: func() interfaces.BeaconBlock { b, err := wrapper.WrappedBeaconBlock(ðpb.BeaconBlockBellatrix{ Body: ðpb.BeaconBlockBodyBellatrix{ ExecutionPayload: &v1.ExecutionPayload{}, @@ -133,7 +133,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) { }, { name: "forkchoice updated with optimistic block", - blk: func() block.BeaconBlock { + blk: func() interfaces.BeaconBlock { b, err := wrapper.WrappedBeaconBlock(ðpb.BeaconBlockBellatrix{ Body: ðpb.BeaconBlockBodyBellatrix{ ExecutionPayload: &v1.ExecutionPayload{}, @@ -147,7 +147,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) { }, { name: "forkchoice updated with invalid block", - blk: func() block.BeaconBlock { + blk: func() interfaces.BeaconBlock { b, err := wrapper.WrappedBeaconBlock(ðpb.BeaconBlockBellatrix{ Body: ðpb.BeaconBlockBodyBellatrix{ ExecutionPayload: &v1.ExecutionPayload{}, @@ -230,7 +230,7 @@ func Test_NotifyNewPayload(t *testing.T) { name string postState state.BeaconState isValidPayload bool - blk block.SignedBeaconBlock + blk interfaces.SignedBeaconBlock newPayloadErr error errString string }{ @@ -274,7 +274,7 @@ func Test_NotifyNewPayload(t *testing.T) { { name: "altair pre state, happy case", postState: bellatrixState, - blk: func() block.SignedBeaconBlock { + blk: func() interfaces.SignedBeaconBlock { blk := ðpb.SignedBeaconBlockBellatrix{ Block: ðpb.BeaconBlockBellatrix{ Body: ðpb.BeaconBlockBodyBellatrix{ @@ -293,7 +293,7 @@ func Test_NotifyNewPayload(t *testing.T) { { name: "not at merge transition", postState: bellatrixState, - blk: func() block.SignedBeaconBlock { + blk: func() interfaces.SignedBeaconBlock { blk := ðpb.SignedBeaconBlockBellatrix{ Block: ðpb.BeaconBlockBellatrix{ Body: ðpb.BeaconBlockBodyBellatrix{ @@ -319,7 +319,7 @@ func Test_NotifyNewPayload(t *testing.T) { { name: "happy case", postState: bellatrixState, - blk: func() block.SignedBeaconBlock { + blk: func() interfaces.SignedBeaconBlock { blk := ðpb.SignedBeaconBlockBellatrix{ Block: ðpb.BeaconBlockBellatrix{ Body: ðpb.BeaconBlockBodyBellatrix{ @@ -338,7 +338,7 @@ func Test_NotifyNewPayload(t *testing.T) { { name: "undefined error from ee", postState: bellatrixState, - blk: func() block.SignedBeaconBlock { + blk: func() interfaces.SignedBeaconBlock { blk := ðpb.SignedBeaconBlockBellatrix{ Block: ðpb.BeaconBlockBellatrix{ Body: ðpb.BeaconBlockBodyBellatrix{ @@ -453,13 +453,13 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) { tests := []struct { name string - blk block.BeaconBlock - justified block.SignedBeaconBlock + blk interfaces.BeaconBlock + justified interfaces.SignedBeaconBlock err error }{ { name: "deep block", - blk: func(tt *testing.T) block.BeaconBlock { + blk: func(tt *testing.T) interfaces.BeaconBlock { blk := util.NewBeaconBlockBellatrix() blk.Block.Slot = 1 blk.Block.ParentRoot = parentRoot[:] @@ -467,7 +467,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) { require.NoError(tt, err) return wr }(t), - justified: func(tt *testing.T) block.SignedBeaconBlock { + justified: func(tt *testing.T) interfaces.SignedBeaconBlock { blk := util.NewBeaconBlockBellatrix() blk.Block.Slot = 32 blk.Block.ParentRoot = parentRoot[:] @@ -479,7 +479,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) { }, { name: "shallow block, Altair justified chkpt", - blk: func(tt *testing.T) block.BeaconBlock { + blk: func(tt *testing.T) interfaces.BeaconBlock { blk := util.NewBeaconBlockAltair() blk.Block.Slot = 200 blk.Block.ParentRoot = parentRoot[:] @@ -487,7 +487,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) { require.NoError(tt, err) return wr }(t), - justified: func(tt *testing.T) block.SignedBeaconBlock { + justified: func(tt *testing.T) interfaces.SignedBeaconBlock { blk := util.NewBeaconBlockAltair() blk.Block.Slot = 32 blk.Block.ParentRoot = parentRoot[:] @@ -499,7 +499,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) { }, { 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.Block.Slot = 200 blk.Block.ParentRoot = parentRoot[:] @@ -507,7 +507,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) { require.NoError(tt, err) return wr }(t), - justified: func(tt *testing.T) block.SignedBeaconBlock { + justified: func(tt *testing.T) interfaces.SignedBeaconBlock { blk := util.NewBeaconBlockBellatrix() blk.Block.Slot = 32 blk.Block.ParentRoot = parentRoot[:] diff --git a/beacon-chain/blockchain/head.go b/beacon-chain/blockchain/head.go index 146dfac2c6..eb01c6a260 100644 --- a/beacon-chain/blockchain/head.go +++ b/beacon-chain/blockchain/head.go @@ -15,7 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/config/features" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" 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. type head struct { - slot types.Slot // current head slot. - root [32]byte // current head root. - block block.SignedBeaconBlock // current head block. - state state.BeaconState // current head state. + slot types.Slot // current head slot. + root [32]byte // current head root. + block interfaces.SignedBeaconBlock // current head block. + state state.BeaconState // current head state. } // 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 // 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") 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 // 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. -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 { 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. -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() 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 // assumes that state being passed into the method will not be modified by any other alternate // 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() defer s.headLock.Unlock() @@ -255,7 +255,7 @@ func (s *Service) headRoot() [32]byte { // This returns the head block. // It does a full copy on head block for immutability. // This is a lock free version. -func (s *Service) headBlock() block.SignedBeaconBlock { +func (s *Service) headBlock() interfaces.SignedBeaconBlock { return s.head.block.Copy() } diff --git a/beacon-chain/blockchain/init_sync_process_block.go b/beacon-chain/blockchain/init_sync_process_block.go index d58ecf1979..d27e6dc864 100644 --- a/beacon-chain/blockchain/init_sync_process_block.go +++ b/beacon-chain/blockchain/init_sync_process_block.go @@ -5,13 +5,13 @@ import ( "github.com/pkg/errors" "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") // 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() defer s.initSyncBlocksLock.Unlock() 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. // 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() // 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 // blocks are unordered. -func (s *Service) getInitSyncBlocks() []block.SignedBeaconBlock { +func (s *Service) getInitSyncBlocks() []interfaces.SignedBeaconBlock { s.initSyncBlocksLock.RLock() 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 { blks = append(blks, b) } @@ -72,5 +72,5 @@ func (s *Service) getInitSyncBlocks() []block.SignedBeaconBlock { func (s *Service) clearInitSyncBlocks() { s.initSyncBlocksLock.Lock() defer s.initSyncBlocksLock.Unlock() - s.initSyncBlocks = make(map[[32]byte]block.SignedBeaconBlock) + s.initSyncBlocks = make(map[[32]byte]interfaces.SignedBeaconBlock) } diff --git a/beacon-chain/blockchain/log.go b/beacon-chain/blockchain/log.go index 7e5aba13c4..078991982c 100644 --- a/beacon-chain/blockchain/log.go +++ b/beacon-chain/blockchain/log.go @@ -6,7 +6,7 @@ import ( "time" "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" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/runtime/version" @@ -18,7 +18,7 @@ import ( var log = logrus.WithField("prefix", "blockchain") // 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()) if len(b.Body().Attestations()) > 0 { log = log.WithField("attestations", len(b.Body().Attestations())) @@ -54,7 +54,7 @@ func logStateTransitionData(b block.BeaconBlock) error { 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()) if err != nil { return err diff --git a/beacon-chain/blockchain/log_test.go b/beacon-chain/blockchain/log_test.go index cf61347cb0..352cdc1cd0 100644 --- a/beacon-chain/blockchain/log_test.go +++ b/beacon-chain/blockchain/log_test.go @@ -3,7 +3,7 @@ package blockchain import ( "testing" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -25,7 +25,7 @@ func Test_logStateTransitionData(t *testing.T) { require.NoError(t, err) tests := []struct { name string - b block.BeaconBlock + b interfaces.BeaconBlock want string }{ {name: "empty block body", diff --git a/beacon-chain/blockchain/metrics.go b/beacon-chain/blockchain/metrics.go index d3ffde41c2..f51954ffc6 100644 --- a/beacon-chain/blockchain/metrics.go +++ b/beacon-chain/blockchain/metrics.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -298,7 +298,7 @@ func reportEpochMetrics(ctx context.Context, postState, headState state.BeaconSt return nil } -func reportAttestationInclusion(blk block.BeaconBlock) { +func reportAttestationInclusion(blk interfaces.BeaconBlock) { for _, att := range blk.Body().Attestations() { attestationInclusionDelay.Observe(float64(blk.Slot() - att.Data.Slot)) } diff --git a/beacon-chain/blockchain/pow_block.go b/beacon-chain/blockchain/pow_block.go index b2616185f4..14a46c3c22 100644 --- a/beacon-chain/blockchain/pow_block.go +++ b/beacon-chain/blockchain/pow_block.go @@ -12,7 +12,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" @@ -37,7 +37,7 @@ import ( // assert pow_parent is not None // # Check if `pow_block` is a valid terminal PoW block // 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 { return err } diff --git a/beacon-chain/blockchain/process_block.go b/beacon-chain/blockchain/process_block.go index f530d4446b..a96ec88d17 100644 --- a/beacon-chain/blockchain/process_block.go +++ b/beacon-chain/blockchain/process_block.go @@ -16,7 +16,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/features" "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/encoding/bytesutil" "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) // if ancestor_at_finalized_slot != store.finalized_checkpoint.root: // 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") defer span.End() if err := helpers.BeaconBlockIsNil(signed); err != nil { @@ -316,7 +316,7 @@ func getStateVersionAndPayload(st state.BeaconState) (int, *ethpb.ExecutionPaylo 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) { ctx, span := trace.StartSpan(ctx, "blockChain.onBlockBatch") 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 // 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 { if err := s.cfg.BeaconDB.SaveStateSummary(ctx, ðpb.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 // 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 { ctx, span := trace.StartSpan(ctx, "blockChain.insertBlockAndAttestationsToForkChoiceStore") defer span.End() @@ -560,7 +560,7 @@ func (s *Service) insertBlockAndAttestationsToForkChoiceStore(ctx context.Contex 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 { if err := s.fillInForkChoiceMissingBlocks(ctx, blk, fCheckpoint, jCheckpoint); err != nil { return err @@ -577,7 +577,7 @@ func (s *Service) insertBlockToForkChoiceStore(ctx context.Context, blk block.Be fCheckpoint.Epoch) } -func getBlockPayloadHash(blk block.BeaconBlock) ([32]byte, error) { +func getBlockPayloadHash(blk interfaces.BeaconBlock) ([32]byte, error) { payloadHash := [32]byte{} if blocks.IsPreBellatrixVersion(blk.Version()) { 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. // 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") defer span.End() 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, // 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 { return nil } @@ -634,7 +634,7 @@ func (s *Service) pruneCanonicalAttsFromPool(ctx context.Context, r [32]byte, b } // 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. if blocks.IsPreBellatrixVersion(blk.Block().Version()) { return nil diff --git a/beacon-chain/blockchain/process_block_helpers.go b/beacon-chain/blockchain/process_block_helpers.go index c22221d32e..345c7b3a8e 100644 --- a/beacon-chain/blockchain/process_block_helpers.go +++ b/beacon-chain/blockchain/process_block_helpers.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" 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 // to retrieve the state in DB. It verifies the pre state's validity and the incoming block // 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") 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. -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") 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 // to current finalized slot. -func (s *Service) verifyBlkFinalizedSlot(b block.BeaconBlock) error { +func (s *Service) verifyBlkFinalizedSlot(b interfaces.BeaconBlock) error { finalized := s.store.FinalizedCheckpt() if finalized == nil { 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 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 { - pendingNodes := make([]block.BeaconBlock, 0) + pendingNodes := make([]interfaces.BeaconBlock, 0) pendingRoots := make([][32]byte, 0) parentRoot := bytesutil.ToBytes32(blk.ParentRoot()) diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index db4388fd45..b093803418 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -26,7 +26,7 @@ import ( "github.com/prysmaticlabs/prysm/config/features" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -298,7 +298,7 @@ func TestStore_OnBlockBatch_ProtoArray(t *testing.T) { bState := st.Copy() - var blks []block.SignedBeaconBlock + var blks []interfaces.SignedBeaconBlock var blkRoots [][32]byte var firstState state.BeaconState for i := 1; i < 10; i++ { @@ -362,7 +362,7 @@ func TestStore_OnBlockBatch_DoublyLinkedTree(t *testing.T) { bState := st.Copy() - var blks []block.SignedBeaconBlock + var blks []interfaces.SignedBeaconBlock var blkRoots [][32]byte var firstState state.BeaconState for i := 1; i < 10; i++ { @@ -419,7 +419,7 @@ func TestStore_OnBlockBatch_NotifyNewPayload(t *testing.T) { st, keys := util.DeterministicGenesisState(t, 64) bState := st.Copy() - var blks []block.SignedBeaconBlock + var blks []interfaces.SignedBeaconBlock var blkRoots [][32]byte var firstState state.BeaconState blkCount := 4 diff --git a/beacon-chain/blockchain/receive_block.go b/beacon-chain/blockchain/receive_block.go index 0e9985f807..41af633bf8 100644 --- a/beacon-chain/blockchain/receive_block.go +++ b/beacon-chain/blockchain/receive_block.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" 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" "github.com/prysmaticlabs/prysm/monitoring/tracing" "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. type BlockReceiver interface { - ReceiveBlock(ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error - ReceiveBlockBatch(ctx context.Context, blocks []block.SignedBeaconBlock, blkRoots [][32]byte) error + ReceiveBlock(ctx context.Context, block interfaces.SignedBeaconBlock, blockRoot [32]byte) error + ReceiveBlockBatch(ctx context.Context, blocks []interfaces.SignedBeaconBlock, blkRoots [][32]byte) error HasInitSyncBlock(root [32]byte) bool } @@ -29,7 +29,7 @@ type BlockReceiver interface { // 1. Validate block, apply state transition and update check points // 2. Apply fork choice to the processed block // 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") defer span.End() 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 // the state, performing batch verification of all collected signatures and then performing the appropriate // 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") defer span.End() @@ -133,7 +133,7 @@ func (s *Service) HasInitSyncBlock(root [32]byte) bool { 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. if err := s.deletePoolAtts(b.Body().Attestations()); err != nil { return err diff --git a/beacon-chain/blockchain/receive_block_test.go b/beacon-chain/blockchain/receive_block_test.go index 6fe939a5ce..303fb1d084 100644 --- a/beacon-chain/blockchain/receive_block_test.go +++ b/beacon-chain/blockchain/receive_block_test.go @@ -13,7 +13,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -267,7 +267,7 @@ func TestService_ReceiveBlockBatch(t *testing.T) { require.NoError(t, err) wsb, err := wrapper.WrappedSignedBeaconBlock(tt.args.block) require.NoError(t, err) - blks := []block.SignedBeaconBlock{wsb} + blks := []interfaces.SignedBeaconBlock{wsb} roots := [][32]byte{root} err = s.ReceiveBlockBatch(ctx, blks, roots) if tt.wantedErr != "" { diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index f3caaa96d2..5ff8e4cd6d 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -33,7 +33,7 @@ import ( "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/config/features" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -60,7 +60,7 @@ type Service struct { nextEpochBoundarySlot types.Slot boundaryRoots [][32]byte checkpointStateCache *cache.CheckpointStateCache - initSyncBlocks map[[32]byte]block.SignedBeaconBlock + initSyncBlocks map[[32]byte]interfaces.SignedBeaconBlock initSyncBlocksLock sync.RWMutex justifiedBalances *stateBalanceCache wsVerifier *WeakSubjectivityVerifier @@ -99,7 +99,7 @@ func NewService(ctx context.Context, opts ...Option) (*Service, error) { cancel: cancel, boundaryRoots: [][32]byte{}, checkpointStateCache: cache.NewCheckpointStateCache(), - initSyncBlocks: make(map[[32]byte]block.SignedBeaconBlock), + initSyncBlocks: make(map[[32]byte]interfaces.SignedBeaconBlock), cfg: &config{}, store: &store.Store{}, } @@ -203,7 +203,7 @@ func (s *Service) StartFromSavedState(saved state.BeaconState) error { if err != nil { return errors.Wrap(err, "could not get finalized checkpoint block") } - if fb == nil { + if fb == nil || fb.IsNil() { return errNilFinalizedInStore } payloadHash, err := getBlockPayloadHash(fb.Block()) diff --git a/beacon-chain/blockchain/service_test.go b/beacon-chain/blockchain/service_test.go index 0bf3848236..9da1fb0b2c 100644 --- a/beacon-chain/blockchain/service_test.go +++ b/beacon-chain/blockchain/service_test.go @@ -29,7 +29,7 @@ import ( v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "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/encoding/bytesutil" 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)}, ctx: ctx, cancel: cancel, - initSyncBlocks: make(map[[32]byte]block.SignedBeaconBlock), + initSyncBlocks: make(map[[32]byte]interfaces.SignedBeaconBlock), } b := util.NewBeaconBlock() r, err := b.Block.HashTreeRoot() diff --git a/beacon-chain/blockchain/testing/BUILD.bazel b/beacon-chain/blockchain/testing/BUILD.bazel index 608d9a8ab3..e216d1902b 100644 --- a/beacon-chain/blockchain/testing/BUILD.bazel +++ b/beacon-chain/blockchain/testing/BUILD.bazel @@ -22,7 +22,7 @@ go_library( "//beacon-chain/state:go_default_library", "//config/fieldparams: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", "//encoding/bytesutil:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/blockchain/testing/mock.go b/beacon-chain/blockchain/testing/mock.go index 864cbf3a86..b499f0c08b 100644 --- a/beacon-chain/blockchain/testing/mock.go +++ b/beacon-chain/blockchain/testing/mock.go @@ -21,7 +21,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -47,10 +47,10 @@ type ChainService struct { InitSyncBlockRoots map[[32]byte]bool DB db.Database State state.BeaconState - Block block.SignedBeaconBlock + Block interfaces.SignedBeaconBlock VerifyBlkDescendantErr error stateNotifier statefeed.Notifier - BlocksReceived []block.SignedBeaconBlock + BlocksReceived []interfaces.SignedBeaconBlock SyncCommitteeIndices []types.CommitteeIndex blockNotifier blockfeed.Notifier opNotifier opfeed.Notifier @@ -165,7 +165,7 @@ func (mon *MockOperationNotifier) OperationFeed() *event.Feed { } // 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 { return ErrNilState } @@ -192,7 +192,7 @@ func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block block. } // 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 { return ErrNilState } @@ -221,7 +221,7 @@ func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []block.Signe } // 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 { return s.ReceiveBlockMockErr } @@ -267,7 +267,7 @@ func (s *ChainService) HeadRoot(_ context.Context) ([]byte, error) { } // 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 } diff --git a/beacon-chain/core/altair/BUILD.bazel b/beacon-chain/core/altair/BUILD.bazel index 4ede16db64..c9ef984f31 100644 --- a/beacon-chain/core/altair/BUILD.bazel +++ b/beacon-chain/core/altair/BUILD.bazel @@ -32,7 +32,7 @@ go_library( "//beacon-chain/state/v2:go_default_library", "//config/fieldparams: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", "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", diff --git a/beacon-chain/core/altair/attestation.go b/beacon-chain/core/altair/attestation.go index 502d8b6e99..d9650fb58c 100644 --- a/beacon-chain/core/altair/attestation.go +++ b/beacon-chain/core/altair/attestation.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/attestation" @@ -23,7 +23,7 @@ import ( func ProcessAttestationsNoVerifySignature( ctx context.Context, beaconState state.BeaconState, - b block.SignedBeaconBlock, + b interfaces.SignedBeaconBlock, ) (state.BeaconState, error) { if err := helpers.BeaconBlockIsNil(b); err != nil { return nil, err diff --git a/beacon-chain/core/blocks/BUILD.bazel b/beacon-chain/core/blocks/BUILD.bazel index 8a5aa23cd0..097a93ca4a 100644 --- a/beacon-chain/core/blocks/BUILD.bazel +++ b/beacon-chain/core/blocks/BUILD.bazel @@ -31,7 +31,7 @@ go_library( "//beacon-chain/state:go_default_library", "//config/fieldparams: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/wrapper:go_default_library", "//container/slice:go_default_library", diff --git a/beacon-chain/core/blocks/attestation.go b/beacon-chain/core/blocks/attestation.go index eb0b0e610d..d96ce28caa 100644 --- a/beacon-chain/core/blocks/attestation.go +++ b/beacon-chain/core/blocks/attestation.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" "github.com/prysmaticlabs/prysm/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -23,7 +23,7 @@ import ( func ProcessAttestationsNoVerifySignature( ctx context.Context, beaconState state.BeaconState, - b block.SignedBeaconBlock, + b interfaces.SignedBeaconBlock, ) (state.BeaconState, error) { if err := helpers.BeaconBlockIsNil(b); err != nil { return nil, err diff --git a/beacon-chain/core/blocks/header.go b/beacon-chain/core/blocks/header.go index 17e3dbefde..1d97a0e88e 100644 --- a/beacon-chain/core/blocks/header.go +++ b/beacon-chain/core/blocks/header.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ) @@ -41,7 +41,7 @@ import ( func ProcessBlockHeader( ctx context.Context, beaconState state.BeaconState, - block block.SignedBeaconBlock, + block interfaces.SignedBeaconBlock, ) (state.BeaconState, error) { if err := helpers.BeaconBlockIsNil(block); err != nil { return nil, err diff --git a/beacon-chain/core/blocks/payload.go b/beacon-chain/core/blocks/payload.go index ea9267791b..4a7912f362 100644 --- a/beacon-chain/core/blocks/payload.go +++ b/beacon-chain/core/blocks/payload.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" 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/encoding/bytesutil" "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. // 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. -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 { return false, errors.New("nil header or block body") } @@ -62,7 +62,7 @@ func IsMergeTransitionBlockUsingPreStatePayloadHeader(h *ethpb.ExecutionPayloadH // Spec code: // def is_execution_block(block: BeaconBlock) -> bool: // return block.body.execution_payload != ExecutionPayload() -func IsExecutionBlock(body block.BeaconBlockBody) (bool, error) { +func IsExecutionBlock(body interfaces.BeaconBlockBody) (bool, error) { if body == nil { return false, errors.New("nil block body") } @@ -83,7 +83,7 @@ func IsExecutionBlock(body block.BeaconBlockBody) (bool, error) { // Spec code: // def is_execution_enabled(state: BeaconState, body: BeaconBlockBody) -> bool: // 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 { 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. // 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) { return true, nil } diff --git a/beacon-chain/core/blocks/randao.go b/beacon-chain/core/blocks/randao.go index f2746c1858..7f89aaf80e 100644 --- a/beacon-chain/core/blocks/randao.go +++ b/beacon-chain/core/blocks/randao.go @@ -7,7 +7,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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/time/slots" ) @@ -29,7 +29,7 @@ import ( func ProcessRandao( ctx context.Context, beaconState state.BeaconState, - b block.SignedBeaconBlock, + b interfaces.SignedBeaconBlock, ) (state.BeaconState, error) { if err := helpers.BeaconBlockIsNil(b); err != nil { return nil, err diff --git a/beacon-chain/core/blocks/signature.go b/beacon-chain/core/blocks/signature.go index e40573c5e2..5ad9403451 100644 --- a/beacon-chain/core/blocks/signature.go +++ b/beacon-chain/core/blocks/signature.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" "github.com/prysmaticlabs/prysm/crypto/bls" "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 // from the above method by not using fork data from the state and instead retrieving it // 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()) fork, err := forks.Fork(currentEpoch) if err != nil { diff --git a/beacon-chain/core/feed/block/BUILD.bazel b/beacon-chain/core/feed/block/BUILD.bazel index b5fbb3c43e..83fcf66926 100644 --- a/beacon-chain/core/feed/block/BUILD.bazel +++ b/beacon-chain/core/feed/block/BUILD.bazel @@ -10,6 +10,6 @@ go_library( visibility = ["//beacon-chain:__subpackages__"], deps = [ "//async/event:go_default_library", - "//consensus-types/block:go_default_library", + "//consensus-types/interfaces:go_default_library", ], ) diff --git a/beacon-chain/core/feed/block/events.go b/beacon-chain/core/feed/block/events.go index 8e1b138a2a..48a709cea8 100644 --- a/beacon-chain/core/feed/block/events.go +++ b/beacon-chain/core/feed/block/events.go @@ -2,9 +2,7 @@ // during the runtime of a beacon node. package block -import ( - "github.com/prysmaticlabs/prysm/consensus-types/block" -) +import "github.com/prysmaticlabs/prysm/consensus-types/interfaces" const ( // 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. type ReceivedBlockData struct { - SignedBlock block.SignedBeaconBlock + SignedBlock interfaces.SignedBeaconBlock IsOptimistic bool } diff --git a/beacon-chain/core/feed/state/BUILD.bazel b/beacon-chain/core/feed/state/BUILD.bazel index 679e1fcee5..6f87509c56 100644 --- a/beacon-chain/core/feed/state/BUILD.bazel +++ b/beacon-chain/core/feed/state/BUILD.bazel @@ -13,7 +13,7 @@ go_library( ], deps = [ "//async/event:go_default_library", - "//consensus-types/block:go_default_library", + "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", ], ) diff --git a/beacon-chain/core/feed/state/events.go b/beacon-chain/core/feed/state/events.go index 4d3a45206a..4f612d60dd 100644 --- a/beacon-chain/core/feed/state/events.go +++ b/beacon-chain/core/feed/state/events.go @@ -6,7 +6,7 @@ package state import ( "time" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" ) @@ -35,7 +35,7 @@ type BlockProcessedData struct { // BlockRoot of the processed block. BlockRoot [32]byte // 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 bool } diff --git a/beacon-chain/core/helpers/BUILD.bazel b/beacon-chain/core/helpers/BUILD.bazel index f5ad33190b..a346b40216 100644 --- a/beacon-chain/core/helpers/BUILD.bazel +++ b/beacon-chain/core/helpers/BUILD.bazel @@ -22,7 +22,7 @@ go_library( "//beacon-chain/state:go_default_library", "//config/fieldparams: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", "//container/slice:go_default_library", "//container/trie:go_default_library", diff --git a/beacon-chain/core/helpers/block.go b/beacon-chain/core/helpers/block.go index 1609fe6c1a..d6f79d8dc2 100644 --- a/beacon-chain/core/helpers/block.go +++ b/beacon-chain/core/helpers/block.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" "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. // Access to these nil fields will result in run time panic, // 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() { return ErrNilSignedBeaconBlock } diff --git a/beacon-chain/core/transition/BUILD.bazel b/beacon-chain/core/transition/BUILD.bazel index 25f7a81c5c..0ea47dfd77 100644 --- a/beacon-chain/core/transition/BUILD.bazel +++ b/beacon-chain/core/transition/BUILD.bazel @@ -36,7 +36,7 @@ go_library( "//beacon-chain/state/stateutil:go_default_library", "//beacon-chain/state/v1: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", "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", diff --git a/beacon-chain/core/transition/interop/BUILD.bazel b/beacon-chain/core/transition/interop/BUILD.bazel index b3b086449b..5c15ce5665 100644 --- a/beacon-chain/core/transition/interop/BUILD.bazel +++ b/beacon-chain/core/transition/interop/BUILD.bazel @@ -15,7 +15,7 @@ go_library( deps = [ "//beacon-chain/state: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", "@com_github_sirupsen_logrus//:go_default_library", ], diff --git a/beacon-chain/core/transition/interop/write_block_to_disk.go b/beacon-chain/core/transition/interop/write_block_to_disk.go index c5c6c8f8b9..fcd75cc685 100644 --- a/beacon-chain/core/transition/interop/write_block_to_disk.go +++ b/beacon-chain/core/transition/interop/write_block_to_disk.go @@ -6,12 +6,12 @@ import ( "path" "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" ) // 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 { return } diff --git a/beacon-chain/core/transition/transition.go b/beacon-chain/core/transition/transition.go index 0b14f3220b..ea69cc9f42 100644 --- a/beacon-chain/core/transition/transition.go +++ b/beacon-chain/core/transition/transition.go @@ -18,7 +18,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" "github.com/prysmaticlabs/prysm/math" "github.com/prysmaticlabs/prysm/monitoring/tracing" @@ -47,7 +47,7 @@ import ( func ExecuteStateTransition( ctx context.Context, state state.BeaconState, - signed block.SignedBeaconBlock, + signed interfaces.SignedBeaconBlock, ) (state.BeaconState, error) { if ctx.Err() != nil { 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. -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 { return nil, err } diff --git a/beacon-chain/core/transition/transition_no_verify_sig.go b/beacon-chain/core/transition/transition_no_verify_sig.go index 6e943c2be4..46e2bebf4c 100644 --- a/beacon-chain/core/transition/transition_no_verify_sig.go +++ b/beacon-chain/core/transition/transition_no_verify_sig.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop" v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "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/monitoring/tracing" "github.com/prysmaticlabs/prysm/runtime/version" @@ -43,7 +43,7 @@ import ( func ExecuteStateTransitionNoVerifyAnySig( ctx context.Context, state state.BeaconState, - signed block.SignedBeaconBlock, + signed interfaces.SignedBeaconBlock, ) (*bls.SignatureBatch, state.BeaconState, error) { if ctx.Err() != nil { return nil, nil, ctx.Err() @@ -107,7 +107,7 @@ func ExecuteStateTransitionNoVerifyAnySig( func CalculateStateRoot( ctx context.Context, state state.BeaconState, - signed block.SignedBeaconBlock, + signed interfaces.SignedBeaconBlock, ) ([32]byte, error) { ctx, span := trace.StartSpan(ctx, "core.state.CalculateStateRoot") defer span.End() @@ -156,7 +156,7 @@ func CalculateStateRoot( func ProcessBlockNoVerifyAnySig( ctx context.Context, state state.BeaconState, - signed block.SignedBeaconBlock, + signed interfaces.SignedBeaconBlock, ) (*bls.SignatureBatch, state.BeaconState, error) { ctx, span := trace.StartSpan(ctx, "core.state.ProcessBlockNoVerifyAnySig") defer span.End() @@ -220,7 +220,7 @@ func ProcessBlockNoVerifyAnySig( func ProcessOperationsNoVerifyAttsSigs( ctx context.Context, state state.BeaconState, - signedBeaconBlock block.SignedBeaconBlock) (state.BeaconState, error) { + signedBeaconBlock interfaces.SignedBeaconBlock) (state.BeaconState, error) { ctx, span := trace.StartSpan(ctx, "core.state.ProcessOperationsNoVerifyAttsSigs") defer span.End() if err := helpers.BeaconBlockIsNil(signedBeaconBlock); err != nil { @@ -265,7 +265,7 @@ func ProcessOperationsNoVerifyAttsSigs( func ProcessBlockForStateRoot( ctx context.Context, state state.BeaconState, - signed block.SignedBeaconBlock, + signed interfaces.SignedBeaconBlock, ) (state.BeaconState, error) { ctx, span := trace.StartSpan(ctx, "core.state.ProcessBlockForStateRoot") defer span.End() @@ -349,7 +349,7 @@ func ProcessBlockForStateRoot( func altairOperations( ctx context.Context, 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) if err != nil { return nil, errors.Wrap(err, "could not process altair proposer slashing") @@ -372,7 +372,7 @@ func altairOperations( func phase0Operations( ctx context.Context, 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) if err != nil { return nil, errors.Wrap(err, "could not process block proposer slashings") diff --git a/beacon-chain/db/iface/BUILD.bazel b/beacon-chain/db/iface/BUILD.bazel index 92a2ac7664..49b243b49f 100644 --- a/beacon-chain/db/iface/BUILD.bazel +++ b/beacon-chain/db/iface/BUILD.bazel @@ -13,7 +13,7 @@ go_library( "//beacon-chain/db/filters:go_default_library", "//beacon-chain/slasher/types: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", "//monitoring/backup:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/db/iface/interface.go b/beacon-chain/db/iface/interface.go index b3c5210c5f..fa11c76786 100644 --- a/beacon-chain/db/iface/interface.go +++ b/beacon-chain/db/iface/interface.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" slashertypes "github.com/prysmaticlabs/prysm/beacon-chain/slasher/types" "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" "github.com/prysmaticlabs/prysm/monitoring/backup" 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. type ReadOnlyDatabase interface { // Block related methods. - Block(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) - Blocks(ctx context.Context, f *filters.QueryFilter) ([]block.SignedBeaconBlock, [][32]byte, error) + Block(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error) + Blocks(ctx context.Context, f *filters.QueryFilter) ([]interfaces.SignedBeaconBlock, [][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) 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) IsFinalizedBlock(ctx context.Context, blockRoot [32]byte) bool - FinalizedChildBlock(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) - HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]block.SignedBeaconBlock, error) + FinalizedChildBlock(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error) + HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]interfaces.SignedBeaconBlock, error) // State related methods. State(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. DeleteBlock(ctx context.Context, root [32]byte) error - SaveBlock(ctx context.Context, block block.SignedBeaconBlock) error - SaveBlocks(ctx context.Context, blocks []block.SignedBeaconBlock) error + SaveBlock(ctx context.Context, block interfaces.SignedBeaconBlock) error + SaveBlocks(ctx context.Context, blocks []interfaces.SignedBeaconBlock) error SaveGenesisBlockRoot(ctx context.Context, blockRoot [32]byte) error // State related methods. SaveState(ctx context.Context, state state.ReadOnlyBeaconState, blockRoot [32]byte) error @@ -95,7 +95,7 @@ type HeadAccessDatabase interface { NoHeadAccessDatabase // 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 // Genesis operations. diff --git a/beacon-chain/db/kv/BUILD.bazel b/beacon-chain/db/kv/BUILD.bazel index 5bf305af1f..bdb627e617 100644 --- a/beacon-chain/db/kv/BUILD.bazel +++ b/beacon-chain/db/kv/BUILD.bazel @@ -45,7 +45,7 @@ go_library( "//beacon-chain/state/v3:go_default_library", "//config/features: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/wrapper:go_default_library", "//container/slice:go_default_library", @@ -108,7 +108,7 @@ go_test( "//config/features:go_default_library", "//config/fieldparams: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/wrapper:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/beacon-chain/db/kv/blocks.go b/beacon-chain/db/kv/blocks.go index 60de41f8c7..69974de560 100644 --- a/beacon-chain/db/kv/blocks.go +++ b/beacon-chain/db/kv/blocks.go @@ -11,7 +11,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/container/slice" @@ -27,14 +27,14 @@ import ( var errInvalidSlotRange = errors.New("invalid end slot and start slot provided") // 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") defer span.End() // Return block from cache if it exists. 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 { bkt := tx.Bucket(blocksBucket) 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. -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") defer span.End() - var headBlock block.SignedBeaconBlock + var headBlock interfaces.SignedBeaconBlock err := s.db.View(func(tx *bolt.Tx) error { bkt := tx.Bucket(blocksBucket) 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. -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") defer span.End() - blocks := make([]block.SignedBeaconBlock, 0) + blocks := make([]interfaces.SignedBeaconBlock, 0) blockRoots := make([][32]byte, 0) 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. -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") defer span.End() - blocks := make([]block.SignedBeaconBlock, 0) + blocks := make([]interfaces.SignedBeaconBlock, 0) err := s.db.View(func(tx *bolt.Tx) error { bkt := tx.Bucket(blocksBucket) @@ -258,7 +258,7 @@ func (s *Store) DeleteBlock(ctx context.Context, root [32]byte) error { } // 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") defer span.End() 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 { return nil } - return s.SaveBlocks(ctx, []block.SignedBeaconBlock{signed}) + return s.SaveBlocks(ctx, []interfaces.SignedBeaconBlock{signed}) } // 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") 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. -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") defer span.End() - var blk block.SignedBeaconBlock + var blk interfaces.SignedBeaconBlock err := s.db.View(func(tx *bolt.Tx) error { bkt := tx.Bucket(blocksBucket) 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. -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") defer span.End() @@ -426,7 +426,7 @@ func (s *Store) HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([] return nil, err } - var blk block.SignedBeaconBlock + var blk interfaces.SignedBeaconBlock var err error if best != nil { 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. @@ -631,7 +631,7 @@ func blockRootsBySlot(ctx context.Context, tx *bolt.Tx, slot types.Slot) [][]byt // createBlockIndicesFromBlock takes in a beacon block and returns // a map of bolt DB index buckets corresponding to each particular key for indices for // 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") defer span.End() 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. -func unmarshalBlock(_ context.Context, enc []byte) (block.SignedBeaconBlock, error) { +func unmarshalBlock(_ context.Context, enc []byte) (interfaces.SignedBeaconBlock, error) { var err error enc, err = snappy.Decode(nil, enc) 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. -func marshalBlock(_ context.Context, blk block.SignedBeaconBlock) ([]byte, error) { +func marshalBlock(_ context.Context, blk interfaces.SignedBeaconBlock) ([]byte, error) { obj, err := blk.MarshalSSZ() if err != nil { return nil, err diff --git a/beacon-chain/db/kv/blocks_test.go b/beacon-chain/db/kv/blocks_test.go index 5e2190d5ae..8d43b24336 100644 --- a/beacon-chain/db/kv/blocks_test.go +++ b/beacon-chain/db/kv/blocks_test.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -21,11 +21,11 @@ import ( var blockTests = []struct { name string - newBlock func(types.Slot, []byte) (block.SignedBeaconBlock, error) + newBlock func(types.Slot, []byte) (interfaces.SignedBeaconBlock, error) }{ { 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.Block.Slot = slot if root != nil { @@ -36,7 +36,7 @@ var blockTests = []struct { }, { 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.Block.Slot = slot if root != nil { @@ -47,7 +47,7 @@ var blockTests = []struct { }, { 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.Block.Slot = slot if root != nil { @@ -138,7 +138,7 @@ func TestStore_BlocksHandleZeroCase(t *testing.T) { db := setupDB(t) ctx := context.Background() numBlocks := 10 - totalBlocks := make([]block.SignedBeaconBlock, numBlocks) + totalBlocks := make([]interfaces.SignedBeaconBlock, numBlocks) for i := 0; i < len(totalBlocks); i++ { b, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32)) require.NoError(t, err) @@ -161,7 +161,7 @@ func TestStore_BlocksHandleInvalidEndSlot(t *testing.T) { db := setupDB(t) ctx := context.Background() numBlocks := 10 - totalBlocks := make([]block.SignedBeaconBlock, numBlocks) + totalBlocks := make([]interfaces.SignedBeaconBlock, numBlocks) // Save blocks from slot 1 onwards. for i := 0; i < len(totalBlocks); i++ { 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) b8, err := tt.newBlock(types.Slot(8), bytesutil.PadTo([]byte("parent4"), 32)) require.NoError(t, err) - blocks := []block.SignedBeaconBlock{ + blocks := []interfaces.SignedBeaconBlock{ b4, b5, b6, @@ -426,7 +426,7 @@ func TestStore_Blocks_Retrieve_SlotRange(t *testing.T) { for _, tt := range blockTests { t.Run(tt.name, func(t *testing.T) { db := setupDB(t) - totalBlocks := make([]block.SignedBeaconBlock, 500) + totalBlocks := make([]interfaces.SignedBeaconBlock, 500) for i := 0; i < 500; i++ { b, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32)) require.NoError(t, err) @@ -446,7 +446,7 @@ func TestStore_Blocks_Retrieve_Epoch(t *testing.T) { t.Run(tt.name, func(t *testing.T) { db := setupDB(t) slots := params.BeaconConfig().SlotsPerEpoch.Mul(7) - totalBlocks := make([]block.SignedBeaconBlock, slots) + totalBlocks := make([]interfaces.SignedBeaconBlock, slots) for i := types.Slot(0); i < slots; i++ { b, err := tt.newBlock(i, bytesutil.PadTo([]byte("parent"), 32)) require.NoError(t, err) @@ -470,7 +470,7 @@ func TestStore_Blocks_Retrieve_SlotRangeWithStep(t *testing.T) { for _, tt := range blockTests { t.Run(tt.name, func(t *testing.T) { db := setupDB(t) - totalBlocks := make([]block.SignedBeaconBlock, 500) + totalBlocks := make([]interfaces.SignedBeaconBlock, 500) for i := 0; i < 500; i++ { b, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32)) require.NoError(t, err) @@ -557,7 +557,7 @@ func TestStore_SaveBlocks_HasCachedBlocks(t *testing.T) { db := setupDB(t) ctx := context.Background() - b := make([]block.SignedBeaconBlock, 500) + b := make([]interfaces.SignedBeaconBlock, 500) for i := 0; i < 500; i++ { blk, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32)) require.NoError(t, err) @@ -581,7 +581,7 @@ func TestStore_SaveBlocks_HasRootsMatched(t *testing.T) { db := setupDB(t) ctx := context.Background() - b := make([]block.SignedBeaconBlock, 500) + b := make([]interfaces.SignedBeaconBlock, 500) for i := 0; i < 500; i++ { blk, err := tt.newBlock(types.Slot(i), bytesutil.PadTo([]byte("parent"), 32)) require.NoError(t, err) diff --git a/beacon-chain/db/kv/finalized_block_roots.go b/beacon-chain/db/kv/finalized_block_roots.go index 6f4f000758..f33d469560 100644 --- a/beacon-chain/db/kv/finalized_block_roots.go +++ b/beacon-chain/db/kv/finalized_block_roots.go @@ -6,7 +6,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "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/monitoring/tracing" 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 // no finalized block or its respective child block exists we return with a nil // 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") defer span.End() - var blk block.SignedBeaconBlock + var blk interfaces.SignedBeaconBlock err := s.db.View(func(tx *bolt.Tx) error { blkBytes := tx.Bucket(finalizedBlockRootsIndexBucket).Get(blockRoot[:]) if blkBytes == nil { diff --git a/beacon-chain/db/kv/finalized_block_roots_test.go b/beacon-chain/db/kv/finalized_block_roots_test.go index ebb9cfc3cb..67a50db438 100644 --- a/beacon-chain/db/kv/finalized_block_roots_test.go +++ b/beacon-chain/db/kv/finalized_block_roots_test.go @@ -6,7 +6,7 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -140,7 +140,7 @@ func TestStore_IsFinalizedChildBlock(t *testing.T) { slotsPerEpoch := uint64(params.BeaconConfig().SlotsPerEpoch) 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)) root, err := blks[slotsPerEpoch].Block().HashTreeRoot() 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() require.NoError(t, err) 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) - ifaceBlocks := make([]block.SignedBeaconBlock, n) + ifaceBlocks := make([]interfaces.SignedBeaconBlock, n) for j := i; j < n+i; j++ { parentRoot := make([]byte, fieldparams.RootLength) copy(parentRoot, previousRoot[:]) @@ -215,9 +215,9 @@ func makeBlocks(t *testing.T, i, n uint64, previousRoot [32]byte) []block.Signed 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) - ifaceBlocks := make([]block.SignedBeaconBlock, num) + ifaceBlocks := make([]interfaces.SignedBeaconBlock, num) for j := startIdx; j < num+startIdx; j++ { parentRoot := make([]byte, fieldparams.RootLength) copy(parentRoot, previousRoot[:]) diff --git a/beacon-chain/db/kv/state_test.go b/beacon-chain/db/kv/state_test.go index 4d4a2a4522..28e0cf5d83 100644 --- a/beacon-chain/db/kv/state_test.go +++ b/beacon-chain/db/kv/state_test.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/features" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -368,7 +368,7 @@ func TestStore_StatesBatchDelete(t *testing.T) { db := setupDB(t) ctx := context.Background() numBlocks := 100 - totalBlocks := make([]block.SignedBeaconBlock, numBlocks) + totalBlocks := make([]interfaces.SignedBeaconBlock, numBlocks) blockRoots := make([][32]byte, 0) evenBlockRoots := make([][32]byte, 0) for i := 0; i < len(totalBlocks); i++ { diff --git a/beacon-chain/monitor/BUILD.bazel b/beacon-chain/monitor/BUILD.bazel index c5a3cc629b..7193169dc9 100644 --- a/beacon-chain/monitor/BUILD.bazel +++ b/beacon-chain/monitor/BUILD.bazel @@ -25,7 +25,7 @@ go_library( "//beacon-chain/state:go_default_library", "//beacon-chain/state/stategen: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", "//encoding/bytesutil:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/monitor/process_attestation.go b/beacon-chain/monitor/process_attestation.go index 5bc99f9913..cbdde2d0fb 100644 --- a/beacon-chain/monitor/process_attestation.go +++ b/beacon-chain/monitor/process_attestation.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" 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 -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 { return } diff --git a/beacon-chain/monitor/process_block.go b/beacon-chain/monitor/process_block.go index 20e03a9ef7..87fc27efab 100644 --- a/beacon-chain/monitor/process_block.go +++ b/beacon-chain/monitor/process_block.go @@ -7,7 +7,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/time/slots" @@ -23,7 +23,7 @@ const AggregateReportingPeriod = 5 // - An Exit by one of our 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 -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 { 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. -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() defer s.Unlock() 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 -func (s *Service) processSlashings(blk block.BeaconBlock) { +func (s *Service) processSlashings(blk interfaces.BeaconBlock) { s.RLock() defer s.RUnlock() for _, slashing := range blk.Body().ProposerSlashings() { diff --git a/beacon-chain/monitor/process_exit.go b/beacon-chain/monitor/process_exit.go index 2b6ea0ca4e..50a522b637 100644 --- a/beacon-chain/monitor/process_exit.go +++ b/beacon-chain/monitor/process_exit.go @@ -1,13 +1,13 @@ package monitor import ( - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/sirupsen/logrus" ) // 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() defer s.RUnlock() for _, exit := range blk.Body().VoluntaryExits() { diff --git a/beacon-chain/monitor/process_sync_committee.go b/beacon-chain/monitor/process_sync_committee.go index 41c9da9396..7d7b46402c 100644 --- a/beacon-chain/monitor/process_sync_committee.go +++ b/beacon-chain/monitor/process_sync_committee.go @@ -4,7 +4,7 @@ import ( "fmt" "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" "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 -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 { return } diff --git a/beacon-chain/p2p/types/BUILD.bazel b/beacon-chain/p2p/types/BUILD.bazel index 6100972b40..97d53ccded 100644 --- a/beacon-chain/p2p/types/BUILD.bazel +++ b/beacon-chain/p2p/types/BUILD.bazel @@ -17,7 +17,7 @@ go_library( ], deps = [ "//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/wrapper:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/beacon-chain/p2p/types/object_mapping.go b/beacon-chain/p2p/types/object_mapping.go index b67cf39c47..ec238adcbe 100644 --- a/beacon-chain/p2p/types/object_mapping.go +++ b/beacon-chain/p2p/types/object_mapping.go @@ -2,7 +2,7 @@ package types import ( "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/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -21,7 +21,7 @@ func init() { var ( // BlockMap maps the fork-version to the underlying data type for that // 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 // particular fork period. MetaDataMap map[[4]byte]func() metadata.Metadata @@ -31,14 +31,14 @@ var ( // reset maps and reinitialize them. func InitializeDataMaps() { // Reset our block map. - BlockMap = map[[4]byte]func() (block.SignedBeaconBlock, error){ - bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion): func() (block.SignedBeaconBlock, error) { + BlockMap = map[[4]byte]func() (interfaces.SignedBeaconBlock, error){ + bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion): func() (interfaces.SignedBeaconBlock, error) { return wrapper.WrappedSignedBeaconBlock(ðpb.SignedBeaconBlock{}) }, - bytesutil.ToBytes4(params.BeaconConfig().AltairForkVersion): func() (block.SignedBeaconBlock, error) { + bytesutil.ToBytes4(params.BeaconConfig().AltairForkVersion): func() (interfaces.SignedBeaconBlock, error) { return wrapper.WrappedSignedBeaconBlock(ðpb.SignedBeaconBlockAltair{Block: ðpb.BeaconBlockAltair{}}) }, - bytesutil.ToBytes4(params.BeaconConfig().BellatrixForkVersion): func() (block.SignedBeaconBlock, error) { + bytesutil.ToBytes4(params.BeaconConfig().BellatrixForkVersion): func() (interfaces.SignedBeaconBlock, error) { return wrapper.WrappedSignedBeaconBlock(ðpb.SignedBeaconBlockBellatrix{Block: ðpb.BeaconBlockBellatrix{}}) }, } diff --git a/beacon-chain/rpc/eth/beacon/BUILD.bazel b/beacon-chain/rpc/eth/beacon/BUILD.bazel index 230b010e85..f490d733b2 100644 --- a/beacon-chain/rpc/eth/beacon/BUILD.bazel +++ b/beacon-chain/rpc/eth/beacon/BUILD.bazel @@ -39,7 +39,7 @@ go_library( "//config/features:go_default_library", "//config/fieldparams: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/wrapper:go_default_library", "//crypto/bls:go_default_library", @@ -93,7 +93,7 @@ go_test( "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1: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/wrapper:go_default_library", "//crypto/bls:go_default_library", diff --git a/beacon-chain/rpc/eth/beacon/blocks.go b/beacon-chain/rpc/eth/beacon/blocks.go index 1191b29df1..3fccd3ed22 100644 --- a/beacon-chain/rpc/eth/beacon/blocks.go +++ b/beacon-chain/rpc/eth/beacon/blocks.go @@ -14,7 +14,7 @@ import ( rpchelpers "github.com/prysmaticlabs/prysm/beacon-chain/rpc/eth/helpers" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -133,7 +133,7 @@ func (bs *Server) ListBlockHeaders(ctx context.Context, req *ethpbv1.BlockHeader defer span.End() var err error - var blks []block.SignedBeaconBlock + var blks []interfaces.SignedBeaconBlock var blkRoots [][32]byte if len(req.ParentRoot) == 32 { 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) } -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 blk block.SignedBeaconBlock + var blk interfaces.SignedBeaconBlock switch string(blockId) { case "head": blk, err = bs.ChainInfoFetcher.HeadBlock(ctx) @@ -694,7 +694,7 @@ func (bs *Server) blockFromBlockID(ctx context.Context, blockId []byte) (block.S 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 { 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) } -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. defer func() { log.WithField("blockRoot", fmt.Sprintf("%#x", bytesutil.Trunc(blockRoot[:]))).Debugf( diff --git a/beacon-chain/rpc/eth/beacon/blocks_test.go b/beacon-chain/rpc/eth/beacon/blocks_test.go index b2f350e6c7..4b3adb8781 100644 --- a/beacon-chain/rpc/eth/beacon/blocks_test.go +++ b/beacon-chain/rpc/eth/beacon/blocks_test.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/db" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "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)) count := types.Slot(100) - blks := make([]block.SignedBeaconBlock, count) + blks := make([]interfaces.SignedBeaconBlock, count) blkContainers := make([]*ethpbalpha.BeaconBlockContainer, count) for i := types.Slot(0); i < count; i++ { 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)) count := types.Slot(100) - blks := make([]block.SignedBeaconBlock, count) + blks := make([]interfaces.SignedBeaconBlock, count) blkContainers := make([]*ethpbalpha.BeaconBlockContainer, count) for i := types.Slot(0); i < count; i++ { 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)) count := types.Slot(100) - blks := make([]block.SignedBeaconBlock, count) + blks := make([]interfaces.SignedBeaconBlock, count) blkContainers := make([]*ethpbalpha.BeaconBlockContainer, count) for i := types.Slot(0); i < count; i++ { b := util.NewBeaconBlockBellatrix() diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel index e64474e5b5..ee5684271e 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel @@ -45,7 +45,7 @@ go_library( "//config/features:go_default_library", "//config/fieldparams: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", "//container/slice:go_default_library", "//encoding/bytesutil:go_default_library", @@ -108,7 +108,7 @@ go_test( "//config/features:go_default_library", "//config/fieldparams: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/wrapper:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go index 7b88690932..83ffb8533a 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go @@ -13,7 +13,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/cmd" "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" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "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", req.PageSize, cmd.Get().MaxRPCPageSize) } - var blocks []block.SignedBeaconBlock + var blocks []interfaces.SignedBeaconBlock var err error switch q := req.QueryFilter.(type) { case *ethpb.ListAttestationsRequest_GenesisEpoch: @@ -117,7 +117,7 @@ func (bs *Server) ListAttestations( func (bs *Server) ListIndexedAttestations( ctx context.Context, req *ethpb.ListIndexedAttestationsRequest, ) (*ethpb.ListIndexedAttestationsResponse, error) { - var blocks []block.SignedBeaconBlock + var blocks []interfaces.SignedBeaconBlock var err error switch q := req.QueryFilter.(type) { case *ethpb.ListIndexedAttestationsRequest_GenesisEpoch: diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go index 860acbdea7..90b3c49718 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go @@ -22,7 +22,7 @@ import ( "github.com/prysmaticlabs/prysm/cmd" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "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 { wsb, err := wrapper.WrappedSignedBeaconBlock(b) require.NoError(t, err) diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go index d7c2e9483a..cc43c35621 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go @@ -15,7 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/cmd" "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" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/runtime/version" @@ -28,7 +28,7 @@ import ( // blockContainer represents an instance of // block along with its relevant metadata. type blockContainer struct { - blk block.SignedBeaconBlock + blk interfaces.SignedBeaconBlock root [32]byte isCanonical bool } @@ -114,7 +114,7 @@ func convertFromV1Containers(ctrs []blockContainer) ([]*ethpb.BeaconBlockContain 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 := ðpb.BeaconBlockContainer{ BlockRoot: root[:], Canonical: isCanonical, diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go index eed1e11fdb..1488dc2f01 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go @@ -16,7 +16,7 @@ import ( "github.com/prysmaticlabs/prysm/cmd" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "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)) count := types.Slot(100) - blks := make([]block.SignedBeaconBlock, count) + blks := make([]interfaces.SignedBeaconBlock, count) for i := types.Slot(0); i < count; i++ { b := util.NewBeaconBlock() b.Block.Slot = i @@ -168,7 +168,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) { ctx := context.Background() count := types.Slot(100) - blks := make([]block.SignedBeaconBlock, count) + blks := make([]interfaces.SignedBeaconBlock, count) blkContainers := make([]*ethpb.BeaconBlockContainer, count) for i := types.Slot(0); i < count; i++ { 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) ctx := context.Background() @@ -941,7 +941,7 @@ func TestServer_ListBeaconBlocks_Genesis_MultiBlocks(t *testing.T) { parentRoot := [32]byte{1, 2, 3} blk := util.NewBeaconBlock() blk.Block.ParentRoot = parentRoot[:] - blockCreator := func(i types.Slot) block.SignedBeaconBlock { + blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock { b := util.NewBeaconBlock() b.Block.Slot = i wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) @@ -956,7 +956,7 @@ func TestServer_ListBeaconBlocks_Genesis_MultiBlocks(t *testing.T) { parentRoot := [32]byte{1, 2, 3} blk := util.NewBeaconBlockAltair() blk.Block.ParentRoot = parentRoot[:] - blockCreator := func(i types.Slot) block.SignedBeaconBlock { + blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock { b := util.NewBeaconBlockAltair() b.Block.Slot = i wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) @@ -971,7 +971,7 @@ func TestServer_ListBeaconBlocks_Genesis_MultiBlocks(t *testing.T) { parentRoot := [32]byte{1, 2, 3} blk := util.NewBeaconBlockBellatrix() blk.Block.ParentRoot = parentRoot[:] - blockCreator := func(i types.Slot) block.SignedBeaconBlock { + blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock { b := util.NewBeaconBlockBellatrix() b.Block.Slot = i 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, - blockCreator func(i types.Slot) block.SignedBeaconBlock) { +func runListBeaconBlocksGenesisMultiBlocks(t *testing.T, genBlock interfaces.SignedBeaconBlock, + blockCreator func(i types.Slot) interfaces.SignedBeaconBlock) { db := dbTest.SetupDB(t) ctx := context.Background() @@ -999,7 +999,7 @@ func runListBeaconBlocksGenesisMultiBlocks(t *testing.T, genBlock block.SignedBe require.NoError(t, db.SaveGenesisBlockRoot(ctx, root)) count := types.Slot(100) - blks := make([]block.SignedBeaconBlock, count) + blks := make([]interfaces.SignedBeaconBlock, count) for i := types.Slot(0); i < count; 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) { blk := util.NewBeaconBlock() blk.Block.Slot = 300 - blockCreator := func(i types.Slot) block.SignedBeaconBlock { + blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock { b := util.NewBeaconBlock() b.Block.Slot = i wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) @@ -1044,7 +1044,7 @@ func TestServer_ListBeaconBlocks_Pagination(t *testing.T) { t.Run("altair block", func(t *testing.T) { blk := util.NewBeaconBlockAltair() blk.Block.Slot = 300 - blockCreator := func(i types.Slot) block.SignedBeaconBlock { + blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock { b := util.NewBeaconBlockAltair() b.Block.Slot = i wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) @@ -1068,7 +1068,7 @@ func TestServer_ListBeaconBlocks_Pagination(t *testing.T) { t.Run("bellatrix block", func(t *testing.T) { blk := util.NewBeaconBlockBellatrix() blk.Block.Slot = 300 - blockCreator := func(i types.Slot) block.SignedBeaconBlock { + blockCreator := func(i types.Slot) interfaces.SignedBeaconBlock { b := util.NewBeaconBlockBellatrix() b.Block.Slot = i wrappedB, err := wrapper.WrappedSignedBeaconBlock(b) @@ -1091,8 +1091,8 @@ func TestServer_ListBeaconBlocks_Pagination(t *testing.T) { }) } -func runListBeaconBlocksPagination(t *testing.T, orphanedBlk block.SignedBeaconBlock, - blockCreator func(i types.Slot) block.SignedBeaconBlock, containerCreator func(i types.Slot, root []byte, canonical bool) *ethpb.BeaconBlockContainer) { +func runListBeaconBlocksPagination(t *testing.T, orphanedBlk interfaces.SignedBeaconBlock, + blockCreator func(i types.Slot) interfaces.SignedBeaconBlock, containerCreator func(i types.Slot, root []byte, canonical bool) *ethpb.BeaconBlockContainer) { db := dbTest.SetupDB(t) chain := &chainMock.ChainService{ @@ -1101,7 +1101,7 @@ func runListBeaconBlocksPagination(t *testing.T, orphanedBlk block.SignedBeaconB ctx := context.Background() count := types.Slot(100) - blks := make([]block.SignedBeaconBlock, count) + blks := make([]interfaces.SignedBeaconBlock, count) blkContainers := make([]*ethpb.BeaconBlockContainer, count) for i := types.Slot(0); i < count; i++ { b := blockCreator(i) diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go index 82a087d672..98a0bd8e60 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go @@ -26,7 +26,7 @@ import ( "github.com/prysmaticlabs/prysm/cmd" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "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() beaconDB := dbTest.SetupDB(t) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel index 82e85f7736..6a6b8d5891 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel @@ -54,7 +54,7 @@ go_library( "//beacon-chain/sync:go_default_library", "//config/fieldparams: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/wrapper:go_default_library", "//container/trie:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go index 0f1949bb21..dcbeda2a83 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go @@ -14,7 +14,7 @@ import ( blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -133,7 +133,7 @@ func (vs *Server) PrepareBeaconProposer( 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") defer span.End() 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 // 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())) if err != nil { return nil, errors.Wrap(err, "could not retrieve beacon state") diff --git a/beacon-chain/state/stategen/BUILD.bazel b/beacon-chain/state/stategen/BUILD.bazel index 0a249ff26d..c18758b012 100644 --- a/beacon-chain/state/stategen/BUILD.bazel +++ b/beacon-chain/state/stategen/BUILD.bazel @@ -31,7 +31,7 @@ go_library( "//beacon-chain/sync/backfill:go_default_library", "//cache/lru: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", "//encoding/bytesutil:go_default_library", "//monitoring/tracing:go_default_library", @@ -73,8 +73,8 @@ go_test( "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", "//config/params:go_default_library", - "//consensus-types/block:go_default_library", - "//consensus-types/block/mock:go_default_library", + "//consensus-types/interfaces:go_default_library", + "//consensus-types/mock:go_default_library", "//consensus-types/primitives:go_default_library", "//consensus-types/wrapper:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/beacon-chain/state/stategen/history.go b/beacon-chain/state/stategen/history.go index bdc55d48b1..fcb57eb74b 100644 --- a/beacon-chain/state/stategen/history.go +++ b/beacon-chain/state/stategen/history.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/state" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "go.opencensus.io/trace" @@ -46,7 +46,7 @@ func (ch *CanonicalHistory) ReplayerForSlot(target types.Slot) Replayer { 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() if 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 { 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 { 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, // 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 { if helpers.BeaconBlockIsNil(b) != nil { 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: // - find the highest canonical block <= the target slot // - 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") defer span.End() _, 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. // Note that this function assumes that the tail is a canonical block, and therefore assumes that // 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") defer span.End() - chain := make([]block.SignedBeaconBlock, 0) + chain := make([]interfaces.SignedBeaconBlock, 0) for { if err := ctx.Err(); err != nil { 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 swaps := (last + 1) / 2 for i := 0; i < swaps; i++ { diff --git a/beacon-chain/state/stategen/history_test.go b/beacon-chain/state/stategen/history_test.go index d8d14e5541..4c7314887c 100644 --- a/beacon-chain/state/stategen/history_test.go +++ b/beacon-chain/state/stategen/history_test.go @@ -7,11 +7,11 @@ import ( "testing" "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" "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" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/require" @@ -50,65 +50,65 @@ func TestBestForSlot(t *testing.T) { cases := []struct { name string err error - blocks []block.SignedBeaconBlock - best block.SignedBeaconBlock + blocks []interfaces.SignedBeaconBlock + best interfaces.SignedBeaconBlock root [32]byte cc CanonicalChecker }{ { name: "empty list", err: ErrNoCanonicalBlockForSlot, - blocks: []block.SignedBeaconBlock{}, + blocks: []interfaces.SignedBeaconBlock{}, }, { name: "empty SignedBeaconBlock", err: ErrNoCanonicalBlockForSlot, - blocks: []block.SignedBeaconBlock{nil}, + blocks: []interfaces.SignedBeaconBlock{nil}, }, { name: "empty BeaconBlock", err: ErrNoCanonicalBlockForSlot, - blocks: []block.SignedBeaconBlock{nilBlock}, + blocks: []interfaces.SignedBeaconBlock{nilBlock}, }, { name: "empty BeaconBlockBody", err: ErrNoCanonicalBlockForSlot, - blocks: []block.SignedBeaconBlock{nilBody}, + blocks: []interfaces.SignedBeaconBlock{nilBody}, }, { name: "bad HTR", err: ErrInvalidDBBlock, - blocks: []block.SignedBeaconBlock{badHTR}, + blocks: []interfaces.SignedBeaconBlock{badHTR}, }, { name: "IsCanonical fail", - blocks: []block.SignedBeaconBlock{good, better}, + blocks: []interfaces.SignedBeaconBlock{good, better}, cc: &mockCanonicalChecker{is: true, err: derp}, err: derp, }, { name: "all non-canonical", err: ErrNoCanonicalBlockForSlot, - blocks: []block.SignedBeaconBlock{good, better}, + blocks: []interfaces.SignedBeaconBlock{good, better}, cc: &mockCanonicalChecker{is: false}, }, { name: "one canonical", - blocks: []block.SignedBeaconBlock{good}, + blocks: []interfaces.SignedBeaconBlock{good}, cc: &mockCanonicalChecker{is: true}, root: goodHTR, best: good, }, { name: "all canonical", - blocks: []block.SignedBeaconBlock{better, good}, + blocks: []interfaces.SignedBeaconBlock{better, good}, cc: &mockCanonicalChecker{is: true}, root: betterHTR, best: better, }, { name: "first wins", - blocks: []block.SignedBeaconBlock{good, better}, + blocks: []interfaces.SignedBeaconBlock{good, better}, cc: &mockCanonicalChecker{is: true}, root: goodHTR, best: good, @@ -195,14 +195,14 @@ func TestCanonicalBlockForSlotNonHappy(t *testing.T) { name string slot types.Slot canon CanonicalChecker - overrideHighest func(context.Context, types.Slot) ([]block.SignedBeaconBlock, error) + overrideHighest func(context.Context, types.Slot) ([]interfaces.SignedBeaconBlock, error) slotOrderExpected []types.Slot err error root [32]byte }{ { 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 }, root: hist.slotMap[0], @@ -210,7 +210,7 @@ func TestCanonicalBlockForSlotNonHappy(t *testing.T) { { name: "wrapped error from HighestSlotBlocksBelow returned", err: derp, - overrideHighest: func(_ context.Context, _ types.Slot) ([]block.SignedBeaconBlock, error) { + overrideHighest: func(_ context.Context, _ types.Slot) ([]interfaces.SignedBeaconBlock, error) { return nil, derp }, slot: end, @@ -218,8 +218,8 @@ func TestCanonicalBlockForSlotNonHappy(t *testing.T) { { name: "HighestSlotBlocksBelow empty list", err: ErrNoBlocksBelowSlot, - overrideHighest: func(_ context.Context, _ types.Slot) ([]block.SignedBeaconBlock, error) { - return []block.SignedBeaconBlock{}, nil + overrideHighest: func(_ context.Context, _ types.Slot) ([]interfaces.SignedBeaconBlock, error) { + return []interfaces.SignedBeaconBlock{}, nil }, slot: end, }, @@ -237,7 +237,7 @@ func TestCanonicalBlockForSlotNonHappy(t *testing.T) { } 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) // this allows the mock HighestSlotBlocksBelow to continue to execute now that we've recorded // the slot in our channel @@ -255,7 +255,7 @@ func TestCanonicalBlockForSlotNonHappy(t *testing.T) { } 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) // this allows the mock HighestSlotBlocksBelow to continue to execute now that we've recorded // the slot in our channel @@ -601,10 +601,10 @@ func incrFwd(n int, c chan uint32) { 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) go iter(n, bchan) - mb := make([]block.SignedBeaconBlock, 0) + mb := make([]interfaces.SignedBeaconBlock, 0) for i := range bchan { h := [32]byte{} binary.LittleEndian.PutUint32(h[:], i) diff --git a/beacon-chain/state/stategen/mock/BUILD.bazel b/beacon-chain/state/stategen/mock/BUILD.bazel index cc23ea97e9..fd8a870288 100644 --- a/beacon-chain/state/stategen/mock/BUILD.bazel +++ b/beacon-chain/state/stategen/mock/BUILD.bazel @@ -12,7 +12,7 @@ go_library( deps = [ "//beacon-chain/state: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", "//proto/prysm/v1alpha1:go_default_library", ], diff --git a/beacon-chain/state/stategen/mock/mock.go b/beacon-chain/state/stategen/mock/mock.go index e7fcb7bbcf..ba99f895db 100644 --- a/beacon-chain/state/stategen/mock/mock.go +++ b/beacon-chain/state/stategen/mock/mock.go @@ -4,7 +4,7 @@ import ( "context" "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" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ) @@ -47,7 +47,7 @@ func (_ *MockStateManager) MigrateToCold(_ context.Context, _ [32]byte) error { func (_ *MockStateManager) ReplayBlocks( _ context.Context, _ state.BeaconState, - _ []block.SignedBeaconBlock, + _ []interfaces.SignedBeaconBlock, _ types.Slot, ) (state.BeaconState, error) { panic("implement me") @@ -58,7 +58,7 @@ func (_ *MockStateManager) LoadBlocks( _ context.Context, _, _ types.Slot, _ [32]byte, -) ([]block.SignedBeaconBlock, error) { +) ([]interfaces.SignedBeaconBlock, error) { panic("implement me") } diff --git a/beacon-chain/state/stategen/mock_test.go b/beacon-chain/state/stategen/mock_test.go index f96c6fdee8..d5f1bcb7ab 100644 --- a/beacon-chain/state/stategen/mock_test.go +++ b/beacon-chain/state/stategen/mock_test.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/db" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -74,14 +74,14 @@ type mockHistorySpec struct { } type mockHistory struct { - blocks map[[32]byte]block.SignedBeaconBlock + blocks map[[32]byte]interfaces.SignedBeaconBlock slotMap map[types.Slot][32]byte slotIndex slotList canonical map[[32]byte]bool states map[[32]byte]state.BeaconState hiddenStates map[[32]byte]state.BeaconState 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 @@ -100,7 +100,7 @@ func (m slotList) Swap(i, j int) { 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 { s, err := m.overrideHighestSlotBlocksBelow(context.Background(), slot) if !errors.Is(err, errFallThroughOverride) { @@ -115,15 +115,15 @@ func (m *mockHistory) HighestSlotBlocksBelow(_ context.Context, slot types.Slot) } for _, s := range m.slotIndex { 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") -func (m *mockHistory) GenesisBlock(_ context.Context) (block.SignedBeaconBlock, error) { +func (m *mockHistory) GenesisBlock(_ context.Context) (interfaces.SignedBeaconBlock, error) { genesisRoot, ok := m.slotMap[0] if !ok { return nil, errGenesisBlockNotFound @@ -131,7 +131,7 @@ func (m *mockHistory) GenesisBlock(_ context.Context) (block.SignedBeaconBlock, 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 { return b, nil } @@ -154,7 +154,7 @@ func (m *mockHistory) CurrentSlot() types.Slot { 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.slotMap[b.Block().Slot()] = root h.canonical[root] = canon @@ -190,7 +190,7 @@ func (h *mockHistory) validateRoots() error { func newMockHistory(t *testing.T, hist []mockHistorySpec, current types.Slot) *mockHistory { ctx := context.Background() mh := &mockHistory{ - blocks: map[[32]byte]block.SignedBeaconBlock{}, + blocks: map[[32]byte]interfaces.SignedBeaconBlock{}, canonical: map[[32]byte]bool{}, states: map[[32]byte]state.BeaconState{}, hiddenStates: map[[32]byte]state.BeaconState{}, diff --git a/beacon-chain/state/stategen/replay.go b/beacon-chain/state/stategen/replay.go index 6c91f99f1b..4a2de29fa7 100644 --- a/beacon-chain/state/stategen/replay.go +++ b/beacon-chain/state/stategen/replay.go @@ -13,7 +13,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/monitoring/tracing" @@ -26,7 +26,7 @@ import ( func (_ *State) ReplayBlocks( ctx context.Context, state state.BeaconState, - signed []block.SignedBeaconBlock, + signed []interfaces.SignedBeaconBlock, targetSlot types.Slot, ) (state.BeaconState, error) { 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. // 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. if endSlot < startSlot { 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") } - 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. for i := length - 2; i >= 0; i-- { if ctx.Err() != nil { @@ -138,7 +138,7 @@ func (s *State) LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, e func executeStateTransitionStateGen( ctx context.Context, state state.BeaconState, - signed block.SignedBeaconBlock, + signed interfaces.SignedBeaconBlock, ) (state.BeaconState, error) { if ctx.Err() != nil { 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. // 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) bs, bRoots, err := s.beaconDB.Blocks(ctx, f) if err != nil { @@ -246,7 +246,7 @@ func (s *State) loadFinalizedBlocks(ctx context.Context, startSlot, endSlot type if len(bs) != len(bRoots) { 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-- { if s.beaconDB.IsFinalizedBlock(ctx, bRoots[i]) { fbs = append(fbs, bs[i]) diff --git a/beacon-chain/state/stategen/replay_test.go b/beacon-chain/state/stategen/replay_test.go index 8616734903..92bde89c56 100644 --- a/beacon-chain/state/stategen/replay_test.go +++ b/beacon-chain/state/stategen/replay_test.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/db" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "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/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -43,7 +43,7 @@ func TestReplayBlocks_AllSkipSlots(t *testing.T) { service := New(beaconDB) 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) assert.Equal(t, targetSlot, newState.Slot(), "Did not advance slots") } @@ -72,7 +72,7 @@ func TestReplayBlocks_SameSlot(t *testing.T) { service := New(beaconDB) 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) 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 wsb, err := wrapper.WrappedSignedBeaconBlock(b) 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) 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)) 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) // Verify state is version Altair. @@ -162,7 +162,7 @@ func TestReplayBlocks_ThroughBellatrixForkBoundary(t *testing.T) { service := New(testDB.SetupDB(t)) 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) // Verify state is version Altair. diff --git a/beacon-chain/state/stategen/replayer.go b/beacon-chain/state/stategen/replayer.go index a9b3de834d..04f2e78b9f 100644 --- a/beacon-chain/state/stategen/replayer.go +++ b/beacon-chain/state/stategen/replayer.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" "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" "github.com/sirupsen/logrus" "go.opencensus.io/trace" @@ -27,9 +27,9 @@ const ( // HistoryAccessor describes the minimum set of database methods needed to support the ReplayerBuilder. type HistoryAccessor interface { - HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]block.SignedBeaconBlock, error) - GenesisBlock(ctx context.Context) (block.SignedBeaconBlock, error) - Block(ctx context.Context, blockRoot [32]byte) (block.SignedBeaconBlock, error) + HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]interfaces.SignedBeaconBlock, error) + GenesisBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error) + Block(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, 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, // namely a starting BeaconState and all available blocks from the starting state up to and including the target slot 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 { @@ -77,7 +77,7 @@ func (rs *stateReplayer) ReplayBlocks(ctx context.Context) (state.BeaconState, e defer span.End() var s state.BeaconState - var descendants []block.SignedBeaconBlock + var descendants []interfaces.SignedBeaconBlock var err error switch rs.method { case forSlot: diff --git a/beacon-chain/state/stategen/replayer_test.go b/beacon-chain/state/stategen/replayer_test.go index afaa460bcd..9d0c30b760 100644 --- a/beacon-chain/state/stategen/replayer_test.go +++ b/beacon-chain/state/stategen/replayer_test.go @@ -4,14 +4,14 @@ import ( "context" "testing" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "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() if err != nil { return nil, err diff --git a/beacon-chain/state/stategen/service.go b/beacon-chain/state/stategen/service.go index 2d021998f3..5b58643569 100644 --- a/beacon-chain/state/stategen/service.go +++ b/beacon-chain/state/stategen/service.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/sync/backfill" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" 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) SaveFinalizedState(fSlot types.Slot, fRoot [32]byte, fState state.BeaconState) MigrateToCold(ctx context.Context, fRoot [32]byte) error - ReplayBlocks(ctx context.Context, state state.BeaconState, signed []block.SignedBeaconBlock, targetSlot types.Slot) (state.BeaconState, error) - LoadBlocks(ctx context.Context, startSlot, endSlot types.Slot, endBlockRoot [32]byte) ([]block.SignedBeaconBlock, 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) ([]interfaces.SignedBeaconBlock, error) HasState(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) diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index cb0c3bdc8e..3c4e990754 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -83,7 +83,7 @@ go_library( "//cmd/beacon-chain/flags:go_default_library", "//config/features: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/wrapper:go_default_library", "//container/slice:go_default_library", @@ -194,7 +194,7 @@ go_test( "//cmd/beacon-chain/flags:go_default_library", "//config/fieldparams: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/wrapper:go_default_library", "//crypto/bls:go_default_library", diff --git a/beacon-chain/sync/backfill/BUILD.bazel b/beacon-chain/sync/backfill/BUILD.bazel index 00fe917746..e5a2294b41 100644 --- a/beacon-chain/sync/backfill/BUILD.bazel +++ b/beacon-chain/sync/backfill/BUILD.bazel @@ -8,7 +8,7 @@ go_library( deps = [ "//beacon-chain/core/helpers: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", "@com_github_pkg_errors//:go_default_library", ], @@ -22,7 +22,7 @@ go_test( "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/db: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/wrapper:go_default_library", "//testing/require:go_default_library", diff --git a/beacon-chain/sync/backfill/status.go b/beacon-chain/sync/backfill/status.go index f35d42397f..20a7e8c147 100644 --- a/beacon-chain/sync/backfill/status.go +++ b/beacon-chain/sync/backfill/status.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "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" ) @@ -118,5 +118,5 @@ type BackfillDB interface { GenesisBlockRoot(ctx context.Context) ([32]byte, error) OriginCheckpointBlockRoot(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) } diff --git a/beacon-chain/sync/backfill/status_test.go b/beacon-chain/sync/backfill/status_test.go index dba368ef75..44a312a9ba 100644 --- a/beacon-chain/sync/backfill/status_test.go +++ b/beacon-chain/sync/backfill/status_test.go @@ -6,10 +6,10 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/db" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/config/params" - "github.com/prysmaticlabs/prysm/consensus-types/block" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/testing/require" @@ -23,7 +23,7 @@ type mockBackfillDB struct { genesisBlockRoot func(ctx context.Context) ([32]byte, error) originCheckpointBlockRoot 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{} @@ -56,7 +56,7 @@ func (db *mockBackfillDB) BackfillBlockRoot(ctx context.Context) ([32]byte, erro 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 { 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() b, err := wrapper.WrappedSignedBeaconBlock(bRaw) if err != nil { @@ -191,7 +191,7 @@ func TestReload(t *testing.T) { return [32]byte{}, db.ErrNotFoundGenesisBlockRoot }, 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 { case originRoot: return originBlock, nil @@ -208,7 +208,7 @@ func TestReload(t *testing.T) { return [32]byte{}, derp }, 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 { case originRoot: return originBlock, nil @@ -231,7 +231,7 @@ func TestReload(t *testing.T) { db: &mockBackfillDB{ genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), 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 }, }, @@ -242,7 +242,7 @@ func TestReload(t *testing.T) { db: &mockBackfillDB{ genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), 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 }, }, @@ -253,7 +253,7 @@ func TestReload(t *testing.T) { db: &mockBackfillDB{ genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), 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 }, backfillBlockRoot: func(ctx context.Context) ([32]byte, error) { @@ -267,7 +267,7 @@ func TestReload(t *testing.T) { db: &mockBackfillDB{ genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), 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 { case originRoot: return originBlock, nil @@ -287,7 +287,7 @@ func TestReload(t *testing.T) { db: &mockBackfillDB{ genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), 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 { case originRoot: return originBlock, nil @@ -305,7 +305,7 @@ func TestReload(t *testing.T) { db: &mockBackfillDB{ genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), 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 { case originRoot: return originBlock, nil @@ -323,7 +323,7 @@ func TestReload(t *testing.T) { db: &mockBackfillDB{ genesisBlockRoot: goodBlockRoot(params.BeaconConfig().ZeroHash), 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 { case originRoot: return originBlock, nil diff --git a/beacon-chain/sync/decode_pubsub_test.go b/beacon-chain/sync/decode_pubsub_test.go index 5528a129bc..a8e1b198a5 100644 --- a/beacon-chain/sync/decode_pubsub_test.go +++ b/beacon-chain/sync/decode_pubsub_test.go @@ -16,7 +16,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2ptesting "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" "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" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/require" @@ -72,7 +72,7 @@ func TestService_decodePubsubMessage(t *testing.T) { }, }, wantErr: nil, - want: func() block.SignedBeaconBlock { + want: func() interfaces.SignedBeaconBlock { wsb, err := wrapper.WrappedSignedBeaconBlock(util.NewBeaconBlock()) require.NoError(t, err) return wsb diff --git a/beacon-chain/sync/initial-sync/BUILD.bazel b/beacon-chain/sync/initial-sync/BUILD.bazel index 3965bd236d..a11626be76 100644 --- a/beacon-chain/sync/initial-sync/BUILD.bazel +++ b/beacon-chain/sync/initial-sync/BUILD.bazel @@ -29,7 +29,7 @@ go_library( "//beacon-chain/sync:go_default_library", "//cmd/beacon-chain/flags: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", "//crypto/rand:go_default_library", "//encoding/bytesutil:go_default_library", @@ -125,7 +125,7 @@ go_test( "//cmd/beacon-chain/flags:go_default_library", "//config/features: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/wrapper:go_default_library", "//container/slice:go_default_library", diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher.go b/beacon-chain/sync/initial-sync/blocks_fetcher.go index de9329ff41..d4c4d61482 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher.go @@ -15,7 +15,7 @@ import ( prysmsync "github.com/prysmaticlabs/prysm/beacon-chain/sync" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "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" "github.com/prysmaticlabs/prysm/crypto/rand" p2ppb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -103,7 +103,7 @@ type fetchRequestResponse struct { pid peer.ID start types.Slot count uint64 - blocks []block.SignedBeaconBlock + blocks []interfaces.SignedBeaconBlock err error } @@ -244,7 +244,7 @@ func (f *blocksFetcher) handleRequest(ctx context.Context, start types.Slot, cou response := &fetchRequestResponse{ start: start, count: count, - blocks: []block.SignedBeaconBlock{}, + blocks: []interfaces.SignedBeaconBlock{}, err: nil, } @@ -278,7 +278,7 @@ func (f *blocksFetcher) fetchBlocksFromPeer( ctx context.Context, start types.Slot, count uint64, peers []peer.ID, -) ([]block.SignedBeaconBlock, peer.ID, error) { +) ([]interfaces.SignedBeaconBlock, peer.ID, error) { ctx, span := trace.StartSpan(ctx, "initialsync.fetchBlocksFromPeer") defer span.End() @@ -302,7 +302,7 @@ func (f *blocksFetcher) requestBlocks( ctx context.Context, req *p2ppb.BeaconBlocksByRangeRequest, pid peer.ID, -) ([]block.SignedBeaconBlock, error) { +) ([]interfaces.SignedBeaconBlock, error) { if ctx.Err() != nil { return nil, ctx.Err() } @@ -331,7 +331,7 @@ func (f *blocksFetcher) requestBlocksByRoot( ctx context.Context, req *p2pTypes.BeaconBlockByRootsReq, pid peer.ID, -) ([]block.SignedBeaconBlock, error) { +) ([]interfaces.SignedBeaconBlock, error) { if ctx.Err() != nil { return nil, ctx.Err() } diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_test.go b/beacon-chain/sync/initial-sync/blocks_fetcher_test.go index 2d0fa3afdf..8fa19921e4 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_test.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_test.go @@ -18,7 +18,7 @@ import ( beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/container/slice" @@ -301,9 +301,9 @@ func TestBlocksFetcher_RoundRobin(t *testing.T) { fetcher.stop() }() - processFetchedBlocks := func() ([]block.SignedBeaconBlock, error) { + processFetchedBlocks := func() ([]interfaces.SignedBeaconBlock, error) { defer cancel() - var unionRespBlocks []block.SignedBeaconBlock + var unionRespBlocks []interfaces.SignedBeaconBlock for { select { @@ -449,7 +449,7 @@ func TestBlocksFetcher_handleRequest(t *testing.T) { } }() - var blocks []block.SignedBeaconBlock + var blocks []interfaces.SignedBeaconBlock select { case <-ctx.Done(): t.Error(ctx.Err()) @@ -600,7 +600,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T) req *ethpb.BeaconBlocksByRangeRequest handlerGenFn func(req *ethpb.BeaconBlocksByRangeRequest) func(stream network.Stream) wantedErr string - validate func(req *ethpb.BeaconBlocksByRangeRequest, blocks []block.SignedBeaconBlock) + validate func(req *ethpb.BeaconBlocksByRangeRequest, blocks []interfaces.SignedBeaconBlock) }{ { name: "no error", @@ -622,7 +622,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T) 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))) }, }, @@ -646,7 +646,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T) 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)) }, wantedErr: beaconsync.ErrInvalidFetchedData.Error(), @@ -675,7 +675,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T) 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)) }, wantedErr: beaconsync.ErrInvalidFetchedData.Error(), @@ -705,7 +705,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T) 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)) }, wantedErr: beaconsync.ErrInvalidFetchedData.Error(), @@ -741,7 +741,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T) } }, 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)) }, }, @@ -776,7 +776,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T) } }, 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)) }, }, @@ -804,7 +804,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T) 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)) }, }, @@ -832,7 +832,7 @@ func TestBlocksFetcher_requestBlocksFromPeerReturningInvalidBlocks(t *testing.T) 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)) }, wantedErr: beaconsync.ErrInvalidFetchedData.Error(), diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go b/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go index 1a01d22c59..24cf651386 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go @@ -10,7 +10,7 @@ import ( p2pTypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" p2ppb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -24,7 +24,7 @@ import ( // either in DB or initial sync cache. type forkData struct { 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. @@ -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. -func (f *blocksFetcher) findAncestor(ctx context.Context, pid peer.ID, b block.SignedBeaconBlock) (*forkData, error) { - outBlocks := []block.SignedBeaconBlock{b} +func (f *blocksFetcher) findAncestor(ctx context.Context, pid peer.ID, b interfaces.SignedBeaconBlock) (*forkData, error) { + outBlocks := []interfaces.SignedBeaconBlock{b} for i := uint64(0); i < backtrackingMaxHops; i++ { parentRoot := bytesutil.ToBytes32(outBlocks[len(outBlocks)-1].Block().ParentRoot()) if f.db.HasBlock(ctx, parentRoot) || f.chain.HasInitSyncBlock(parentRoot) { diff --git a/beacon-chain/sync/initial-sync/blocks_queue.go b/beacon-chain/sync/initial-sync/blocks_queue.go index 4658c03f39..c682958a83 100644 --- a/beacon-chain/sync/initial-sync/blocks_queue.go +++ b/beacon-chain/sync/initial-sync/blocks_queue.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" 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" "github.com/prysmaticlabs/prysm/time/slots" "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. type blocksQueueFetchedData struct { pid peer.ID - blocks []block.SignedBeaconBlock + blocks []interfaces.SignedBeaconBlock } // newBlocksQueue creates initialized priority queue. diff --git a/beacon-chain/sync/initial-sync/blocks_queue_test.go b/beacon-chain/sync/initial-sync/blocks_queue_test.go index 1566f343e2..d0275817ad 100644 --- a/beacon-chain/sync/initial-sync/blocks_queue_test.go +++ b/beacon-chain/sync/initial-sync/blocks_queue_test.go @@ -14,7 +14,7 @@ import ( p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/container/slice" @@ -254,7 +254,7 @@ func TestBlocksQueue_Loop(t *testing.T) { highestExpectedSlot: tt.highestExpectedSlot, }) 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())) { 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) } - var blocks []block.SignedBeaconBlock + var blocks []interfaces.SignedBeaconBlock for data := range queue.fetchedData { for _, block := range data.blocks { if err := processBlock(block); err != nil { @@ -526,7 +526,7 @@ func TestBlocksQueue_onDataReceivedEvent(t *testing.T) { handlerFn := queue.onDataReceivedEvent(ctx) response := &fetchRequestResponse{ pid: "abc", - blocks: []block.SignedBeaconBlock{ + blocks: []interfaces.SignedBeaconBlock{ wsb, wsb.Copy(), }, @@ -535,7 +535,7 @@ func TestBlocksQueue_onDataReceivedEvent(t *testing.T) { state: stateScheduled, } 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) assert.NoError(t, err) assert.Equal(t, stateDataParsed, updatedState) @@ -624,7 +624,7 @@ func TestBlocksQueue_onReadyToSendEvent(t *testing.T) { queue.smm.addStateMachine(320) queue.smm.machines[256].state = stateDataParsed queue.smm.machines[256].pid = pidDataParsed - queue.smm.machines[256].blocks = []block.SignedBeaconBlock{ + queue.smm.machines[256].blocks = []interfaces.SignedBeaconBlock{ wsb, } @@ -656,7 +656,7 @@ func TestBlocksQueue_onReadyToSendEvent(t *testing.T) { queue.smm.addStateMachine(320) queue.smm.machines[320].state = stateDataParsed queue.smm.machines[320].pid = pidDataParsed - queue.smm.machines[320].blocks = []block.SignedBeaconBlock{ + queue.smm.machines[320].blocks = []interfaces.SignedBeaconBlock{ wsb, } @@ -685,7 +685,7 @@ func TestBlocksQueue_onReadyToSendEvent(t *testing.T) { queue.smm.addStateMachine(320) queue.smm.machines[320].state = stateDataParsed queue.smm.machines[320].pid = pidDataParsed - queue.smm.machines[320].blocks = []block.SignedBeaconBlock{ + queue.smm.machines[320].blocks = []interfaces.SignedBeaconBlock{ wsb, } @@ -1320,7 +1320,7 @@ func TestBlocksQueue_stuckWhenHeadIsSetToOrphanedBlock(t *testing.T) { }) 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) if err != nil { return false diff --git a/beacon-chain/sync/initial-sync/fsm.go b/beacon-chain/sync/initial-sync/fsm.go index 3cfbd05e70..e6f7912647 100644 --- a/beacon-chain/sync/initial-sync/fsm.go +++ b/beacon-chain/sync/initial-sync/fsm.go @@ -7,7 +7,7 @@ import ( "time" "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" prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/prysmaticlabs/prysm/time/slots" @@ -46,7 +46,7 @@ type stateMachine struct { start types.Slot state stateID pid peer.ID - blocks []block.SignedBeaconBlock + blocks []interfaces.SignedBeaconBlock updated time.Time } @@ -78,7 +78,7 @@ func (smm *stateMachineManager) addStateMachine(startSlot types.Slot) *stateMach smm: smm, start: startSlot, state: stateNew, - blocks: []block.SignedBeaconBlock{}, + blocks: []interfaces.SignedBeaconBlock{}, updated: prysmTime.Now(), } smm.recalculateMachineAttribs() diff --git a/beacon-chain/sync/initial-sync/round_robin.go b/beacon-chain/sync/initial-sync/round_robin.go index ddd8776c9c..e0ecef92af 100644 --- a/beacon-chain/sync/initial-sync/round_robin.go +++ b/beacon-chain/sync/initial-sync/round_robin.go @@ -11,7 +11,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" "github.com/paulbellamy/ratecounter" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/time/slots" @@ -24,10 +24,10 @@ const ( ) // 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. -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. // @@ -178,7 +178,7 @@ func (s *Service) highestFinalizedEpoch() types.Epoch { } // 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) rate := float64(s.counter.Rate()) / counterSeconds 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. -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))) rate := float64(s.counter.Rate()) / counterSeconds if rate == 0 { @@ -220,7 +220,7 @@ func (s *Service) logBatchSyncStatus(genesis time.Time, blks []block.SignedBeaco func (s *Service) processBlock( ctx context.Context, genesis time.Time, - blk block.SignedBeaconBlock, + blk interfaces.SignedBeaconBlock, blockReceiver blockReceiverFn, ) error { blkRoot, err := blk.Block().HashTreeRoot() @@ -240,7 +240,7 @@ func (s *Service) processBlock( } 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 { 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. -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) if err != nil { return false diff --git a/beacon-chain/sync/initial-sync/round_robin_test.go b/beacon-chain/sync/initial-sync/round_robin_test.go index 0c8cc8fe71..6b64b9c7a7 100644 --- a/beacon-chain/sync/initial-sync/round_robin_test.go +++ b/beacon-chain/sync/initial-sync/round_robin_test.go @@ -10,7 +10,7 @@ import ( mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/container/slice" @@ -366,7 +366,7 @@ func TestService_processBlock(t *testing.T) { wsb, err := wrapper.WrappedSignedBeaconBlock(blk1) require.NoError(t, err) 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)) return nil }) @@ -376,7 +376,7 @@ func TestService_processBlock(t *testing.T) { wsb, err = wrapper.WrappedSignedBeaconBlock(blk1) require.NoError(t, err) 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 }) assert.ErrorContains(t, errBlockAlreadyProcessed.Error(), err) @@ -385,7 +385,7 @@ func TestService_processBlock(t *testing.T) { wsb, err = wrapper.WrappedSignedBeaconBlock(blk2) require.NoError(t, err) 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)) return nil }) @@ -422,7 +422,7 @@ func TestService_processBlockBatch(t *testing.T) { genesis := makeGenesisTime(32) t.Run("process non-linear batch", func(t *testing.T) { - var batch []block.SignedBeaconBlock + var batch []interfaces.SignedBeaconBlock currBlockRoot := genesisBlkRoot for i := types.Slot(1); i < 10; i++ { parentRoot := currBlockRoot @@ -441,7 +441,7 @@ func TestService_processBlockBatch(t *testing.T) { currBlockRoot = blk1Root } - var batch2 []block.SignedBeaconBlock + var batch2 []interfaces.SignedBeaconBlock for i := types.Slot(10); i < 20; i++ { parentRoot := currBlockRoot blk1 := util.NewBeaconBlock() @@ -461,7 +461,7 @@ func TestService_processBlockBatch(t *testing.T) { // Process block normally. 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)) return nil }) @@ -469,12 +469,12 @@ func TestService_processBlockBatch(t *testing.T) { // Duplicate processing should trigger error. 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 }) assert.ErrorContains(t, "no good blocks in batch", err) - var badBatch2 []block.SignedBeaconBlock + var badBatch2 []interfaces.SignedBeaconBlock for i, b := range batch2 { // create a non-linear batch 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 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 }) expectedSubErr := "expected linear block list" @@ -493,7 +493,7 @@ func TestService_processBlockBatch(t *testing.T) { // Continue normal processing, should proceed w/o errors. 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)) return nil }) diff --git a/beacon-chain/sync/pending_blocks_queue.go b/beacon-chain/sync/pending_blocks_queue.go index 38767531eb..6d0b6dc3f6 100644 --- a/beacon-chain/sync/pending_blocks_queue.go +++ b/beacon-chain/sync/pending_blocks_queue.go @@ -14,7 +14,7 @@ import ( p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/beacon-chain/powchain" "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" "github.com/prysmaticlabs/prysm/crypto/rand" "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. // 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) blks := s.pendingBlocksInCache(slot) @@ -336,7 +336,7 @@ func (s *Service) deleteBlockFromPendingQueue(slot types.Slot, b block.SignedBea return err } - newBlks := make([]block.SignedBeaconBlock, 0, len(blks)) + newBlks := make([]interfaces.SignedBeaconBlock, 0, len(blks)) for _, blk := range blks { if equality.DeepEqual(blk.Proto(), b.Proto()) { 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. // 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) 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. -func (s *Service) pendingBlocksInCache(slot types.Slot) []block.SignedBeaconBlock { +func (s *Service) pendingBlocksInCache(slot types.Slot) []interfaces.SignedBeaconBlock { k := slotToCacheKey(slot) value, ok := s.slotToPendingBlocks.Get(k) if !ok { - return []block.SignedBeaconBlock{} + return []interfaces.SignedBeaconBlock{} } - blks, ok := value.([]block.SignedBeaconBlock) + blks, ok := value.([]interfaces.SignedBeaconBlock) if !ok { - return []block.SignedBeaconBlock{} + return []interfaces.SignedBeaconBlock{} } return blks } // 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 { return err } diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range.go b/beacon-chain/sync/rpc_beacon_blocks_by_range.go index 4a01fff02a..c844286c8e 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range.go @@ -10,7 +10,7 @@ import ( p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/monitoring/tracing" @@ -139,7 +139,7 @@ func (s *Service) writeBlockRangeToStream(ctx context.Context, startSlot, endSlo tracing.AnnotateError(span, err) return err } - blks = append([]block.SignedBeaconBlock{genBlock}, blks...) + blks = append([]interfaces.SignedBeaconBlock{genBlock}, blks...) roots = append([][32]byte{genRoot}, roots...) } // 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 // and are strictly linear. -func (s *Service) filterBlocks(ctx context.Context, blks []block.SignedBeaconBlock, roots [][32]byte, prevRoot *[32]byte, - step uint64, startSlot types.Slot) ([]block.SignedBeaconBlock, error) { +func (s *Service) filterBlocks(ctx context.Context, blks []interfaces.SignedBeaconBlock, roots [][32]byte, prevRoot *[32]byte, + step uint64, startSlot types.Slot) ([]interfaces.SignedBeaconBlock, error) { if len(blks) != len(roots) { 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 { isCanonical, err := s.cfg.chain.IsCanonical(ctx, roots[i]) if err != nil { @@ -250,7 +250,7 @@ func (s *Service) writeErrorResponseToStream(responseCode byte, reason string, s 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) if err != nil { return nil, [32]byte{}, err diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_root.go b/beacon-chain/sync/rpc_beacon_blocks_by_root.go index c6d1f14a4b..1cefcdabf0 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_root.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_root.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "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 @@ -17,7 +17,7 @@ func (s *Service) sendRecentBeaconBlocksRequest(ctx context.Context, blockRoots ctx, cancel := context.WithTimeout(ctx, respTimeout) 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() if err != nil { return err diff --git a/beacon-chain/sync/rpc_chunked_response.go b/beacon-chain/sync/rpc_chunked_response.go index 9a3eed0aa1..f5ad7b9448 100644 --- a/beacon-chain/sync/rpc_chunked_response.go +++ b/beacon-chain/sync/rpc_chunked_response.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "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/network/forks" "github.com/prysmaticlabs/prysm/runtime/version" @@ -18,14 +18,14 @@ import ( // chunkBlockWriter writes the given message as a chunked response to the given network // stream. // response_chunk ::= | | | -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) return WriteBlockChunk(stream, s.cfg.chain, s.cfg.p2p.Encoding(), blk) } // WriteBlockChunk writes block chunk object to stream. // response_chunk ::= | | | -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 { return err } @@ -63,7 +63,7 @@ func WriteBlockChunk(stream libp2pcore.Stream, chain blockchain.ChainInfoFetcher // ReadChunkedBlock handles each response chunk that is sent by the // 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 if isFirstChunk { 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 // 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()) if err != nil { 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 // 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) code, errMsg, err := readStatusCodeNoDeadline(stream, p2p.Encoding()) if err != nil { @@ -118,7 +118,7 @@ func readResponseChunk(stream libp2pcore.Stream, chain blockchain.ChainInfoFetch 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 { bFunc, ok := types.BlockMap[bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)] if !ok { diff --git a/beacon-chain/sync/rpc_chunked_response_test.go b/beacon-chain/sync/rpc_chunked_response_test.go index f9007b2320..3be7a44fb0 100644 --- a/beacon-chain/sync/rpc_chunked_response_test.go +++ b/beacon-chain/sync/rpc_chunked_response_test.go @@ -8,7 +8,7 @@ import ( mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" "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" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/require" @@ -30,7 +30,7 @@ func TestExtractBlockDataType(t *testing.T) { tests := []struct { name string args args - want block.SignedBeaconBlock + want interfaces.SignedBeaconBlock wantErr bool }{ { @@ -40,7 +40,7 @@ func TestExtractBlockDataType(t *testing.T) { chain: &mock.ChainService{ValidatorsRoot: [32]byte{}}, }, - want: func() block.SignedBeaconBlock { + want: func() interfaces.SignedBeaconBlock { wsb, err := wrapper.WrappedSignedBeaconBlock(ðpb.SignedBeaconBlock{}) require.NoError(t, err) return wsb @@ -71,7 +71,7 @@ func TestExtractBlockDataType(t *testing.T) { digest: genDigest[:], chain: &mock.ChainService{ValidatorsRoot: [32]byte{}}, }, - want: func() block.SignedBeaconBlock { + want: func() interfaces.SignedBeaconBlock { wsb, err := wrapper.WrappedSignedBeaconBlock(ðpb.SignedBeaconBlock{}) require.NoError(t, err) return wsb @@ -84,7 +84,7 @@ func TestExtractBlockDataType(t *testing.T) { digest: altairDigest[:], chain: &mock.ChainService{ValidatorsRoot: [32]byte{}}, }, - want: func() block.SignedBeaconBlock { + want: func() interfaces.SignedBeaconBlock { wsb, err := wrapper.WrappedSignedBeaconBlock(ðpb.SignedBeaconBlockAltair{Block: ðpb.BeaconBlockAltair{}}) require.NoError(t, err) return wsb @@ -97,7 +97,7 @@ func TestExtractBlockDataType(t *testing.T) { digest: bellatrixDigest[:], chain: &mock.ChainService{ValidatorsRoot: [32]byte{}}, }, - want: func() block.SignedBeaconBlock { + want: func() interfaces.SignedBeaconBlock { wsb, err := wrapper.WrappedSignedBeaconBlock(ðpb.SignedBeaconBlockBellatrix{Block: ðpb.BeaconBlockBellatrix{}}) require.NoError(t, err) return wsb diff --git a/beacon-chain/sync/rpc_send_request.go b/beacon-chain/sync/rpc_send_request.go index bb274ef997..2df41155b3 100644 --- a/beacon-chain/sync/rpc_send_request.go +++ b/beacon-chain/sync/rpc_send_request.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "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" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "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 // 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. func SendBeaconBlocksByRangeRequest( ctx context.Context, chain blockchain.ChainInfoFetcher, p2pProvider p2p.P2P, pid peer.ID, req *pb.BeaconBlocksByRangeRequest, blockProcessor BeaconBlockProcessor, -) ([]block.SignedBeaconBlock, error) { +) ([]interfaces.SignedBeaconBlock, error) { topic, err := p2p.TopicFromMessage(p2p.BeaconBlocksByRangeMessageName, slots.ToEpoch(chain.CurrentSlot())) if err != nil { return nil, err @@ -39,8 +39,8 @@ func SendBeaconBlocksByRangeRequest( defer closeStream(stream, log) // Augment block processing function, if non-nil block processor is provided. - blocks := make([]block.SignedBeaconBlock, 0, req.Count) - process := func(blk block.SignedBeaconBlock) error { + blocks := make([]interfaces.SignedBeaconBlock, 0, req.Count) + process := func(blk interfaces.SignedBeaconBlock) error { blocks = append(blocks, blk) if blockProcessor != nil { return blockProcessor(blk) @@ -89,7 +89,7 @@ func SendBeaconBlocksByRangeRequest( func SendBeaconBlocksByRootRequest( ctx context.Context, chain blockchain.ChainInfoFetcher, p2pProvider p2p.P2P, pid peer.ID, req *p2ptypes.BeaconBlockByRootsReq, blockProcessor BeaconBlockProcessor, -) ([]block.SignedBeaconBlock, error) { +) ([]interfaces.SignedBeaconBlock, error) { topic, err := p2p.TopicFromMessage(p2p.BeaconBlocksByRootsMessageName, slots.ToEpoch(chain.CurrentSlot())) if err != nil { return nil, err @@ -101,8 +101,8 @@ func SendBeaconBlocksByRootRequest( defer closeStream(stream, log) // Augment block processing function, if non-nil block processor is provided. - blocks := make([]block.SignedBeaconBlock, 0, len(*req)) - process := func(block block.SignedBeaconBlock) error { + blocks := make([]interfaces.SignedBeaconBlock, 0, len(*req)) + process := func(block interfaces.SignedBeaconBlock) error { blocks = append(blocks, block) if blockProcessor != nil { return blockProcessor(block) diff --git a/beacon-chain/sync/rpc_send_request_test.go b/beacon-chain/sync/rpc_send_request_test.go index 56f7252da6..797f3479d7 100644 --- a/beacon-chain/sync/rpc_send_request_test.go +++ b/beacon-chain/sync/rpc_send_request_test.go @@ -15,7 +15,7 @@ import ( p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" p2pTypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -124,9 +124,9 @@ func TestSendRequest_SendBeaconBlocksByRangeRequest(t *testing.T) { Count: 128, Step: 1, } - blocksFromProcessor := make([]block.SignedBeaconBlock, 0) + blocksFromProcessor := make([]interfaces.SignedBeaconBlock, 0) 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) return nil }) @@ -149,7 +149,7 @@ func TestSendRequest_SendBeaconBlocksByRangeRequest(t *testing.T) { } errFromProcessor := errors.New("processor error") 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 }) assert.ErrorContains(t, errFromProcessor.Error(), err) @@ -179,7 +179,7 @@ func TestSendRequest_SendBeaconBlocksByRangeRequest(t *testing.T) { cfg.MaxRequestBlocks = maxRequestBlocks 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 // 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. @@ -197,7 +197,7 @@ func TestSendRequest_SendBeaconBlocksByRangeRequest(t *testing.T) { p1.Connect(p2) blocksProcessed := 0 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 { return expectedErr } @@ -392,9 +392,9 @@ func TestSendRequest_SendBeaconBlocksByRootRequest(t *testing.T) { // No error from block processor. 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{}} - 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) return nil }) @@ -413,7 +413,7 @@ func TestSendRequest_SendBeaconBlocksByRootRequest(t *testing.T) { req := &p2pTypes.BeaconBlockByRootsReq{knownRoots[0], knownRoots[1]} errFromProcessor := errors.New("processor error") 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 }) assert.ErrorContains(t, errFromProcessor.Error(), err) @@ -439,7 +439,7 @@ func TestSendRequest_SendBeaconBlocksByRootRequest(t *testing.T) { cfg.MaxRequestBlocks = maxRequestBlocks 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 // 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. @@ -457,7 +457,7 @@ func TestSendRequest_SendBeaconBlocksByRootRequest(t *testing.T) { p1.Connect(p2) blocksProcessed := 0 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 { return expectedErr } @@ -478,7 +478,7 @@ func TestSendRequest_SendBeaconBlocksByRootRequest(t *testing.T) { p1.Connect(p2) blocksProcessed := 0 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 { return expectedErr } diff --git a/beacon-chain/sync/rpc_status_test.go b/beacon-chain/sync/rpc_status_test.go index 6e2d47da8b..102a673fc7 100644 --- a/beacon-chain/sync/rpc_status_test.go +++ b/beacon-chain/sync/rpc_status_test.go @@ -21,7 +21,7 @@ import ( v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "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) - ifaceBlocks := make([]block.SignedBeaconBlock, n) + ifaceBlocks := make([]interfaces.SignedBeaconBlock, n) for j := i; j < n+i; j++ { parentRoot := make([]byte, 32) copy(parentRoot, previousRoot[:]) diff --git a/beacon-chain/sync/utils.go b/beacon-chain/sync/utils.go index ca7c9a9029..0cdbe064be 100644 --- a/beacon-chain/sync/utils.go +++ b/beacon-chain/sync/utils.go @@ -4,14 +4,14 @@ import ( "errors" "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 // which satisfy the Interface in `Sort` so that this type can // be sorted in ascending order. type sortedObj struct { - blks []block.SignedBeaconBlock + blks []interfaces.SignedBeaconBlock roots [][32]byte } @@ -32,14 +32,14 @@ func (s sortedObj) Len() int { } // 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) { return nil, nil, errors.New("input blks and roots are diff lengths") } // Remove duplicate blocks received 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)) for i, r := range roots { 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 // 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{ blks: blks, roots: roots, diff --git a/beacon-chain/sync/utils_test.go b/beacon-chain/sync/utils_test.go index 24e37e5ff9..b691651d70 100644 --- a/beacon-chain/sync/utils_test.go +++ b/beacon-chain/sync/utils_test.go @@ -4,7 +4,7 @@ import ( "math/rand" "testing" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -15,7 +15,7 @@ import ( func TestSortedObj_SortBlocksRoots(t *testing.T) { source := rand.NewSource(33) randGen := rand.New(source) - var blks []block.SignedBeaconBlock + var blks []interfaces.SignedBeaconBlock var roots [][32]byte randFunc := func() int64 { return randGen.Int63n(50) @@ -49,7 +49,7 @@ func TestSortedObj_SortBlocksRoots(t *testing.T) { func TestSortedObj_NoDuplicates(t *testing.T) { source := rand.NewSource(33) randGen := rand.New(source) - var blks []block.SignedBeaconBlock + var blks []interfaces.SignedBeaconBlock var roots [][32]byte randFunc := func() int64 { return randGen.Int63n(50) diff --git a/beacon-chain/sync/validate_beacon_blocks.go b/beacon-chain/sync/validate_beacon_blocks.go index 83d0ff1ba6..e5ea3f069d 100644 --- a/beacon-chain/sync/validate_beacon_blocks.go +++ b/beacon-chain/sync/validate_beacon_blocks.go @@ -17,7 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/features" "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" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/monitoring/tracing" @@ -59,7 +59,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms s.validateBlockLock.Lock() defer s.validateBlockLock.Unlock() - blk, ok := m.(block.SignedBeaconBlock) + blk, ok := m.(interfaces.SignedBeaconBlock) if !ok { return pubsub.ValidationReject, errors.New("msg is not ethpb.SignedBeaconBlock") } @@ -81,7 +81,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms // Feed the block header to slasher if enabled. This action // is done in the background to avoid adding more load to this critical code path. go func() { - blockHeader, err := block.SignedBeaconBlockHeaderFromBlockInterface(blk) + blockHeader, err := interfaces.SignedBeaconBlockHeaderFromBlockInterface(blk) if err != nil { log.WithError(err).WithField("blockSlot", blk.Block().Slot()).Warn("Could not extract block header") } @@ -192,7 +192,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms return pubsub.ValidationAccept, nil } -func (s *Service) validateBeaconBlock(ctx context.Context, blk block.SignedBeaconBlock, blockRoot [32]byte) error { +func (s *Service) validateBeaconBlock(ctx context.Context, blk interfaces.SignedBeaconBlock, blockRoot [32]byte) error { ctx, span := trace.StartSpan(ctx, "sync.validateBeaconBlock") defer span.End() @@ -255,7 +255,7 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk block.SignedBeaco // otherwise: // [IGNORE] The block's parent (defined by block.parent_root) passes all validation (including execution // node verification of the block.body.execution_payload). -func (s *Service) validateBellatrixBeaconBlock(ctx context.Context, parentState state.BeaconState, blk block.BeaconBlock) error { +func (s *Service) validateBellatrixBeaconBlock(ctx context.Context, parentState state.BeaconState, blk interfaces.BeaconBlock) error { // Error if block and state are not the same version if parentState.Version() != blk.Version() { return errors.New("block and state are not the same version") diff --git a/consensus-types/block/BUILD.bazel b/consensus-types/interfaces/BUILD.bazel similarity index 91% rename from consensus-types/block/BUILD.bazel rename to consensus-types/interfaces/BUILD.bazel index 13bbbee38c..9768ad2962 100644 --- a/consensus-types/block/BUILD.bazel +++ b/consensus-types/interfaces/BUILD.bazel @@ -3,10 +3,10 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", srcs = [ - "block_interfaces.go", - "block_utils.go", + "beacon_block.go", + "utils.go", ], - importpath = "github.com/prysmaticlabs/prysm/consensus-types/block", + importpath = "github.com/prysmaticlabs/prysm/consensus-types/interfaces", visibility = ["//visibility:public"], deps = [ "//consensus-types/primitives:go_default_library", @@ -21,7 +21,7 @@ go_library( go_test( name = "go_default_test", - srcs = ["block_utils_test.go"], + srcs = ["utils_test.go"], deps = [ ":go_default_library", "//config/fieldparams:go_default_library", diff --git a/consensus-types/block/block_interfaces.go b/consensus-types/interfaces/beacon_block.go similarity index 99% rename from consensus-types/block/block_interfaces.go rename to consensus-types/interfaces/beacon_block.go index dfb4015738..fdeff9ae5b 100644 --- a/consensus-types/block/block_interfaces.go +++ b/consensus-types/interfaces/beacon_block.go @@ -1,4 +1,4 @@ -package block +package interfaces import ( ssz "github.com/ferranbt/fastssz" diff --git a/consensus-types/block/block_utils.go b/consensus-types/interfaces/utils.go similarity index 99% rename from consensus-types/block/block_utils.go rename to consensus-types/interfaces/utils.go index 7c96915159..ae5bcc726c 100644 --- a/consensus-types/block/block_utils.go +++ b/consensus-types/interfaces/utils.go @@ -1,4 +1,4 @@ -package block +package interfaces import ( "github.com/pkg/errors" diff --git a/consensus-types/block/block_utils_test.go b/consensus-types/interfaces/utils_test.go similarity index 93% rename from consensus-types/block/block_utils_test.go rename to consensus-types/interfaces/utils_test.go index 28252f2700..0cf7811bd2 100644 --- a/consensus-types/block/block_utils_test.go +++ b/consensus-types/interfaces/utils_test.go @@ -1,10 +1,10 @@ -package block_test +package interfaces_test import ( "testing" 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/encoding/bytesutil" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -44,7 +44,7 @@ func TestBeaconBlockHeaderFromBlock(t *testing.T) { BodyRoot: bodyRoot[:], } - bh, err := block.BeaconBlockHeaderFromBlock(blk) + bh, err := interfaces.BeaconBlockHeaderFromBlock(blk) require.NoError(t, err) assert.DeepEqual(t, want, bh) } @@ -81,7 +81,7 @@ func TestBeaconBlockHeaderFromBlockInterface(t *testing.T) { BodyRoot: bodyRoot[:], } - bh, err := block.BeaconBlockHeaderFromBlockInterface(wrapper.WrappedPhase0BeaconBlock(blk)) + bh, err := interfaces.BeaconBlockHeaderFromBlockInterface(wrapper.WrappedPhase0BeaconBlock(blk)) require.NoError(t, err) assert.DeepEqual(t, want, bh) } @@ -94,7 +94,7 @@ func TestBeaconBlockHeaderFromBlock_NilBlockBody(t *testing.T) { ParentRoot: bytesutil.PadTo([]byte("parent root"), hashLen), StateRoot: bytesutil.PadTo([]byte("state root"), hashLen), } - _, err := block.BeaconBlockHeaderFromBlock(blk) + _, err := interfaces.BeaconBlockHeaderFromBlock(blk) require.ErrorContains(t, "nil block body", err) } @@ -134,7 +134,7 @@ func TestSignedBeaconBlockHeaderFromBlock(t *testing.T) { Signature: blk.Signature, } - bh, err := block.SignedBeaconBlockHeaderFromBlock(blk) + bh, err := interfaces.SignedBeaconBlockHeaderFromBlock(blk) require.NoError(t, err) assert.DeepEqual(t, want, bh) } @@ -176,7 +176,7 @@ func TestSignedBeaconBlockHeaderFromBlockInterface(t *testing.T) { } wsb, err := wrapper.WrappedSignedBeaconBlock(blk) require.NoError(t, err) - bh, err := block.SignedBeaconBlockHeaderFromBlockInterface(wsb) + bh, err := interfaces.SignedBeaconBlockHeaderFromBlockInterface(wsb) require.NoError(t, err) assert.DeepEqual(t, want, bh) } @@ -191,6 +191,6 @@ func TestSignedBeaconBlockHeaderFromBlock_NilBlockBody(t *testing.T) { }, Signature: bytesutil.PadTo([]byte("signature"), fieldparams.BLSSignatureLength), } - _, err := block.SignedBeaconBlockHeaderFromBlock(blk) + _, err := interfaces.SignedBeaconBlockHeaderFromBlock(blk) require.ErrorContains(t, "nil block", err) } diff --git a/consensus-types/block/mock/BUILD.bazel b/consensus-types/mock/BUILD.bazel similarity index 89% rename from consensus-types/block/mock/BUILD.bazel rename to consensus-types/mock/BUILD.bazel index 86cd199fe3..dcbdd2e110 100644 --- a/consensus-types/block/mock/BUILD.bazel +++ b/consensus-types/mock/BUILD.bazel @@ -3,10 +3,10 @@ load("@prysm//tools/go:def.bzl", "go_library") go_library( name = "go_default_library", srcs = ["block.go"], - importpath = "github.com/prysmaticlabs/prysm/consensus-types/block/mock", + importpath = "github.com/prysmaticlabs/prysm/consensus-types/mock", visibility = ["//visibility:public"], deps = [ - "//consensus-types/block:go_default_library", + "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//proto/engine/v1:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/consensus-types/block/mock/block.go b/consensus-types/mock/block.go similarity index 89% rename from consensus-types/block/mock/block.go rename to consensus-types/mock/block.go index 05b6f0685c..c23397630f 100644 --- a/consensus-types/block/mock/block.go +++ b/consensus-types/mock/block.go @@ -2,7 +2,7 @@ package mock import ( ssz "github.com/ferranbt/fastssz" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -11,14 +11,14 @@ import ( ) type SignedBeaconBlock struct { - BeaconBlock block.BeaconBlock + BeaconBlock interfaces.BeaconBlock } func (SignedBeaconBlock) PbGenericBlock() (*eth.GenericSignedBeaconBlock, error) { panic("implement me") } -func (m SignedBeaconBlock) Block() block.BeaconBlock { +func (m SignedBeaconBlock) Block() interfaces.BeaconBlock { return m.BeaconBlock } @@ -30,7 +30,7 @@ func (m SignedBeaconBlock) IsNil() bool { return m.BeaconBlock == nil || m.Block().IsNil() } -func (SignedBeaconBlock) Copy() block.SignedBeaconBlock { +func (SignedBeaconBlock) Copy() interfaces.SignedBeaconBlock { panic("implement me") } @@ -81,7 +81,7 @@ func (SignedBeaconBlock) Header() (*eth.SignedBeaconBlockHeader, error) { type BeaconBlock struct { Htr [32]byte HtrErr error - BeaconBlockBody block.BeaconBlockBody + BeaconBlockBody interfaces.BeaconBlockBody BlockSlot types.Slot } @@ -109,7 +109,7 @@ func (BeaconBlock) StateRoot() []byte { panic("implement me") } -func (m BeaconBlock) Body() block.BeaconBlockBody { +func (m BeaconBlock) Body() interfaces.BeaconBlockBody { return m.BeaconBlockBody } @@ -207,6 +207,6 @@ func (BeaconBlockBody) ExecutionPayloadHeader() (*eth.ExecutionPayloadHeader, er panic("implement me") } -var _ block.SignedBeaconBlock = &SignedBeaconBlock{} -var _ block.BeaconBlock = &BeaconBlock{} -var _ block.BeaconBlockBody = &BeaconBlockBody{} +var _ interfaces.SignedBeaconBlock = &SignedBeaconBlock{} +var _ interfaces.BeaconBlock = &BeaconBlock{} +var _ interfaces.BeaconBlockBody = &BeaconBlockBody{} diff --git a/consensus-types/wrapper/BUILD.bazel b/consensus-types/wrapper/BUILD.bazel index a89484987e..0844897733 100644 --- a/consensus-types/wrapper/BUILD.bazel +++ b/consensus-types/wrapper/BUILD.bazel @@ -14,7 +14,7 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/consensus-types/wrapper", visibility = ["//visibility:public"], deps = [ - "//consensus-types/block:go_default_library", + "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//proto/engine/v1:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/consensus-types/wrapper/beacon_block.go b/consensus-types/wrapper/beacon_block.go index e52fb2e8f4..4f8e4acc8c 100644 --- a/consensus-types/wrapper/beacon_block.go +++ b/consensus-types/wrapper/beacon_block.go @@ -2,7 +2,7 @@ package wrapper import ( "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ) @@ -34,7 +34,7 @@ var ( // WrappedSignedBeaconBlock will wrap a signed beacon block to conform to the // signed beacon block interface. -func WrappedSignedBeaconBlock(i interface{}) (block.SignedBeaconBlock, error) { +func WrappedSignedBeaconBlock(i interface{}) (interfaces.SignedBeaconBlock, error) { switch b := i.(type) { case *eth.GenericSignedBeaconBlock_Phase0: return wrappedPhase0SignedBeaconBlock(b.Phase0), nil @@ -61,7 +61,7 @@ func WrappedSignedBeaconBlock(i interface{}) (block.SignedBeaconBlock, error) { // WrappedBeaconBlock will wrap a signed beacon block to conform to the // signed beacon block interface. -func WrappedBeaconBlock(i interface{}) (block.BeaconBlock, error) { +func WrappedBeaconBlock(i interface{}) (interfaces.BeaconBlock, error) { switch b := i.(type) { case *eth.GenericBeaconBlock_Phase0: return WrappedPhase0BeaconBlock(b.Phase0), nil @@ -87,7 +87,7 @@ func WrappedBeaconBlock(i interface{}) (block.BeaconBlock, error) { // BuildSignedBeaconBlock assembles a block.SignedBeaconBlock interface compatible struct from a // given beacon block an the appropriate signature. This method may be used to easily create a // signed beacon block. -func BuildSignedBeaconBlock(blk block.BeaconBlock, signature []byte) (block.SignedBeaconBlock, error) { +func BuildSignedBeaconBlock(blk interfaces.BeaconBlock, signature []byte) (interfaces.SignedBeaconBlock, error) { switch b := blk.(type) { case Phase0BeaconBlock: pb, ok := b.Proto().(*eth.BeaconBlock) @@ -118,7 +118,7 @@ func BuildSignedBeaconBlock(blk block.BeaconBlock, signature []byte) (block.Sign } } -func UnwrapGenericSignedBeaconBlock(gb *eth.GenericSignedBeaconBlock) (block.SignedBeaconBlock, error) { +func UnwrapGenericSignedBeaconBlock(gb *eth.GenericSignedBeaconBlock) (interfaces.SignedBeaconBlock, error) { if gb == nil { return nil, ErrNilObjectWrapped } diff --git a/consensus-types/wrapper/beacon_block_altair.go b/consensus-types/wrapper/beacon_block_altair.go index dc978de781..cce4162f96 100644 --- a/consensus-types/wrapper/beacon_block_altair.go +++ b/consensus-types/wrapper/beacon_block_altair.go @@ -3,7 +3,7 @@ package wrapper import ( ssz "github.com/ferranbt/fastssz" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -13,9 +13,9 @@ import ( ) var ( - _ = block.SignedBeaconBlock(&altairSignedBeaconBlock{}) - _ = block.BeaconBlock(&altairBeaconBlock{}) - _ = block.BeaconBlockBody(&altairBeaconBlockBody{}) + _ = interfaces.SignedBeaconBlock(&altairSignedBeaconBlock{}) + _ = interfaces.BeaconBlock(&altairBeaconBlock{}) + _ = interfaces.BeaconBlockBody(&altairBeaconBlockBody{}) ) // altairSignedBeaconBlock is a convenience wrapper around a altair beacon block @@ -27,7 +27,7 @@ type altairSignedBeaconBlock struct { // wrappedAltairSignedBeaconBlock is constructor which wraps a protobuf altair block // with the block wrapper. -func wrappedAltairSignedBeaconBlock(b *eth.SignedBeaconBlockAltair) (block.SignedBeaconBlock, error) { +func wrappedAltairSignedBeaconBlock(b *eth.SignedBeaconBlockAltair) (interfaces.SignedBeaconBlock, error) { w := altairSignedBeaconBlock{b: b} if w.IsNil() { return nil, ErrNilObjectWrapped @@ -41,7 +41,7 @@ func (w altairSignedBeaconBlock) Signature() []byte { } // Block returns the underlying beacon block object. -func (w altairSignedBeaconBlock) Block() block.BeaconBlock { +func (w altairSignedBeaconBlock) Block() interfaces.BeaconBlock { return altairBeaconBlock{b: w.b.Block} } @@ -53,7 +53,7 @@ func (w altairSignedBeaconBlock) IsNil() bool { // Copy performs a deep copy of the signed beacon block // object. -func (w altairSignedBeaconBlock) Copy() block.SignedBeaconBlock { +func (w altairSignedBeaconBlock) Copy() interfaces.SignedBeaconBlock { return altairSignedBeaconBlock{b: eth.CopySignedBeaconBlockAltair(w.b)} } @@ -145,7 +145,7 @@ type altairBeaconBlock struct { // with the block wrapper. // // Deprecated: Use WrappedBeaconBlock. -func WrappedAltairBeaconBlock(b *eth.BeaconBlockAltair) (block.BeaconBlock, error) { +func WrappedAltairBeaconBlock(b *eth.BeaconBlockAltair) (interfaces.BeaconBlock, error) { w := altairBeaconBlock{b: b} if w.IsNil() { return nil, ErrNilObjectWrapped @@ -174,7 +174,7 @@ func (w altairBeaconBlock) StateRoot() []byte { } // Body returns the underlying block body. -func (w altairBeaconBlock) Body() block.BeaconBlockBody { +func (w altairBeaconBlock) Body() interfaces.BeaconBlockBody { return altairBeaconBlockBody{b: w.b.Body} } @@ -246,7 +246,7 @@ type altairBeaconBlockBody struct { // WrappedAltairBeaconBlockBody is constructor which wraps a protobuf altair object // with the block wrapper. -func WrappedAltairBeaconBlockBody(b *eth.BeaconBlockBodyAltair) (block.BeaconBlockBody, error) { +func WrappedAltairBeaconBlockBody(b *eth.BeaconBlockBodyAltair) (interfaces.BeaconBlockBody, error) { w := altairBeaconBlockBody{b: b} if w.IsNil() { return nil, ErrNilObjectWrapped diff --git a/consensus-types/wrapper/beacon_block_bellatrix.go b/consensus-types/wrapper/beacon_block_bellatrix.go index 5751e7b780..45685919cb 100644 --- a/consensus-types/wrapper/beacon_block_bellatrix.go +++ b/consensus-types/wrapper/beacon_block_bellatrix.go @@ -3,7 +3,7 @@ package wrapper import ( ssz "github.com/ferranbt/fastssz" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -13,9 +13,9 @@ import ( ) var ( - _ = block.SignedBeaconBlock(&bellatrixSignedBeaconBlock{}) - _ = block.BeaconBlock(&bellatrixBeaconBlock{}) - _ = block.BeaconBlockBody(&bellatrixBeaconBlockBody{}) + _ = interfaces.SignedBeaconBlock(&bellatrixSignedBeaconBlock{}) + _ = interfaces.BeaconBlock(&bellatrixBeaconBlock{}) + _ = interfaces.BeaconBlockBody(&bellatrixBeaconBlockBody{}) ) // bellatrixSignedBeaconBlock is a convenience wrapper around a Bellatrix blinded beacon block @@ -26,7 +26,7 @@ type bellatrixSignedBeaconBlock struct { } // wrappedBellatrixSignedBeaconBlock is a constructor which wraps a protobuf Bellatrix block with the block wrapper. -func wrappedBellatrixSignedBeaconBlock(b *eth.SignedBeaconBlockBellatrix) (block.SignedBeaconBlock, error) { +func wrappedBellatrixSignedBeaconBlock(b *eth.SignedBeaconBlockBellatrix) (interfaces.SignedBeaconBlock, error) { w := bellatrixSignedBeaconBlock{b: b} if w.IsNil() { return nil, ErrNilObjectWrapped @@ -40,7 +40,7 @@ func (w bellatrixSignedBeaconBlock) Signature() []byte { } // Block returns the underlying beacon block object. -func (w bellatrixSignedBeaconBlock) Block() block.BeaconBlock { +func (w bellatrixSignedBeaconBlock) Block() interfaces.BeaconBlock { return bellatrixBeaconBlock{b: w.b.Block} } @@ -50,7 +50,7 @@ func (w bellatrixSignedBeaconBlock) IsNil() bool { } // Copy performs a deep copy of the signed beacon block object. -func (w bellatrixSignedBeaconBlock) Copy() block.SignedBeaconBlock { +func (w bellatrixSignedBeaconBlock) Copy() interfaces.SignedBeaconBlock { return bellatrixSignedBeaconBlock{b: eth.CopySignedBeaconBlockBellatrix(w.b)} } @@ -140,7 +140,7 @@ type bellatrixBeaconBlock struct { // with the block wrapper. // // Deprecated: Use WrappedBeaconBlock. -func WrappedBellatrixBeaconBlock(b *eth.BeaconBlockBellatrix) (block.BeaconBlock, error) { +func WrappedBellatrixBeaconBlock(b *eth.BeaconBlockBellatrix) (interfaces.BeaconBlock, error) { w := bellatrixBeaconBlock{b: b} if w.IsNil() { return nil, ErrNilObjectWrapped @@ -169,7 +169,7 @@ func (w bellatrixBeaconBlock) StateRoot() []byte { } // Body returns the underlying block body. -func (w bellatrixBeaconBlock) Body() block.BeaconBlockBody { +func (w bellatrixBeaconBlock) Body() interfaces.BeaconBlockBody { return bellatrixBeaconBlockBody{b: w.b.Body} } @@ -241,7 +241,7 @@ type bellatrixBeaconBlockBody struct { // WrappedBellatrixBeaconBlockBody is a constructor which wraps a protobuf bellatrix object // with the block wrapper. -func WrappedBellatrixBeaconBlockBody(b *eth.BeaconBlockBodyBellatrix) (block.BeaconBlockBody, error) { +func WrappedBellatrixBeaconBlockBody(b *eth.BeaconBlockBodyBellatrix) (interfaces.BeaconBlockBody, error) { w := bellatrixBeaconBlockBody{b: b} if w.IsNil() { return nil, ErrNilObjectWrapped diff --git a/consensus-types/wrapper/beacon_block_phase0.go b/consensus-types/wrapper/beacon_block_phase0.go index 301168a215..02f03d7c98 100644 --- a/consensus-types/wrapper/beacon_block_phase0.go +++ b/consensus-types/wrapper/beacon_block_phase0.go @@ -3,7 +3,7 @@ package wrapper import ( ssz "github.com/ferranbt/fastssz" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -13,9 +13,9 @@ import ( ) var ( - _ = block.SignedBeaconBlock(&Phase0SignedBeaconBlock{}) - _ = block.BeaconBlock(&Phase0BeaconBlock{}) - _ = block.BeaconBlockBody(&Phase0BeaconBlockBody{}) + _ = interfaces.SignedBeaconBlock(&Phase0SignedBeaconBlock{}) + _ = interfaces.BeaconBlock(&Phase0BeaconBlock{}) + _ = interfaces.BeaconBlockBody(&Phase0BeaconBlockBody{}) ) // Phase0SignedBeaconBlock is a convenience wrapper around a phase 0 beacon block @@ -27,7 +27,7 @@ type Phase0SignedBeaconBlock struct { // wrappedPhase0SignedBeaconBlock is constructor which wraps a protobuf phase 0 block // with the block wrapper. -func wrappedPhase0SignedBeaconBlock(b *eth.SignedBeaconBlock) block.SignedBeaconBlock { +func wrappedPhase0SignedBeaconBlock(b *eth.SignedBeaconBlock) interfaces.SignedBeaconBlock { return Phase0SignedBeaconBlock{b: b} } @@ -37,7 +37,7 @@ func (w Phase0SignedBeaconBlock) Signature() []byte { } // Block returns the underlying beacon block object. -func (w Phase0SignedBeaconBlock) Block() block.BeaconBlock { +func (w Phase0SignedBeaconBlock) Block() interfaces.BeaconBlock { return WrappedPhase0BeaconBlock(w.b.Block) } @@ -49,7 +49,7 @@ func (w Phase0SignedBeaconBlock) IsNil() bool { // Copy performs a deep copy of the signed beacon block // object. -func (w Phase0SignedBeaconBlock) Copy() block.SignedBeaconBlock { +func (w Phase0SignedBeaconBlock) Copy() interfaces.SignedBeaconBlock { return wrappedPhase0SignedBeaconBlock(eth.CopySignedBeaconBlock(w.b)) } @@ -141,7 +141,7 @@ type Phase0BeaconBlock struct { // with the block wrapper. // // Deprecated: Use WrappedBeaconBlock. -func WrappedPhase0BeaconBlock(b *eth.BeaconBlock) block.BeaconBlock { +func WrappedPhase0BeaconBlock(b *eth.BeaconBlock) interfaces.BeaconBlock { return Phase0BeaconBlock{b: b} } @@ -166,7 +166,7 @@ func (w Phase0BeaconBlock) StateRoot() []byte { } // Body returns the underlying block body. -func (w Phase0BeaconBlock) Body() block.BeaconBlockBody { +func (w Phase0BeaconBlock) Body() interfaces.BeaconBlockBody { return WrappedPhase0BeaconBlockBody(w.b.Body) } @@ -238,7 +238,7 @@ type Phase0BeaconBlockBody struct { // WrappedPhase0BeaconBlockBody is constructor which wraps a protobuf phase 0 object // with the block wrapper. -func WrappedPhase0BeaconBlockBody(b *eth.BeaconBlockBody) block.BeaconBlockBody { +func WrappedPhase0BeaconBlockBody(b *eth.BeaconBlockBody) interfaces.BeaconBlockBody { return Phase0BeaconBlockBody{b: b} } diff --git a/consensus-types/wrapper/blinded_beacon_block_bellatrix.go b/consensus-types/wrapper/blinded_beacon_block_bellatrix.go index 91c16edead..d38ba20ce7 100644 --- a/consensus-types/wrapper/blinded_beacon_block_bellatrix.go +++ b/consensus-types/wrapper/blinded_beacon_block_bellatrix.go @@ -3,7 +3,7 @@ package wrapper import ( ssz "github.com/ferranbt/fastssz" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -13,9 +13,9 @@ import ( ) var ( - _ = block.SignedBeaconBlock(&signedBlindedBeaconBlockBellatrix{}) - _ = block.BeaconBlock(&blindedBeaconBlockBellatrix{}) - _ = block.BeaconBlockBody(&blindedBeaconBlockBodyBellatrix{}) + _ = interfaces.SignedBeaconBlock(&signedBlindedBeaconBlockBellatrix{}) + _ = interfaces.BeaconBlock(&blindedBeaconBlockBellatrix{}) + _ = interfaces.BeaconBlockBody(&blindedBeaconBlockBodyBellatrix{}) ) // signedBlindedBeaconBlockBellatrix is a convenience wrapper around a Bellatrix blinded beacon block @@ -26,7 +26,7 @@ type signedBlindedBeaconBlockBellatrix struct { } // wrappedBellatrixSignedBlindedBeaconBlock is a constructor which wraps a protobuf Bellatrix blinded block with the block wrapper. -func wrappedBellatrixSignedBlindedBeaconBlock(b *eth.SignedBlindedBeaconBlockBellatrix) (block.SignedBeaconBlock, error) { +func wrappedBellatrixSignedBlindedBeaconBlock(b *eth.SignedBlindedBeaconBlockBellatrix) (interfaces.SignedBeaconBlock, error) { w := signedBlindedBeaconBlockBellatrix{b: b} if w.IsNil() { return nil, ErrNilObjectWrapped @@ -40,7 +40,7 @@ func (w signedBlindedBeaconBlockBellatrix) Signature() []byte { } // Block returns the underlying beacon block object. -func (w signedBlindedBeaconBlockBellatrix) Block() block.BeaconBlock { +func (w signedBlindedBeaconBlockBellatrix) Block() interfaces.BeaconBlock { return blindedBeaconBlockBellatrix{b: w.b.Block} } @@ -50,7 +50,7 @@ func (w signedBlindedBeaconBlockBellatrix) IsNil() bool { } // Copy performs a deep copy of the signed beacon block object. -func (w signedBlindedBeaconBlockBellatrix) Copy() block.SignedBeaconBlock { +func (w signedBlindedBeaconBlockBellatrix) Copy() interfaces.SignedBeaconBlock { return signedBlindedBeaconBlockBellatrix{b: eth.CopySignedBlindedBeaconBlockBellatrix(w.b)} } @@ -141,7 +141,7 @@ type blindedBeaconBlockBellatrix struct { // with the block wrapper. // // Deprecated: Use WrappedBeaconBlock. -func WrappedBellatrixBlindedBeaconBlock(b *eth.BlindedBeaconBlockBellatrix) (block.BeaconBlock, error) { +func WrappedBellatrixBlindedBeaconBlock(b *eth.BlindedBeaconBlockBellatrix) (interfaces.BeaconBlock, error) { w := blindedBeaconBlockBellatrix{b: b} if w.IsNil() { return nil, ErrNilObjectWrapped @@ -170,7 +170,7 @@ func (w blindedBeaconBlockBellatrix) StateRoot() []byte { } // Body returns the underlying block body. -func (w blindedBeaconBlockBellatrix) Body() block.BeaconBlockBody { +func (w blindedBeaconBlockBellatrix) Body() interfaces.BeaconBlockBody { return blindedBeaconBlockBodyBellatrix{b: w.b.Body} } @@ -242,7 +242,7 @@ type blindedBeaconBlockBodyBellatrix struct { // WrappedBellatrixBlindedBeaconBlockBody is a constructor which wraps a protobuf bellatrix object // with the block wrapper. -func WrappedBellatrixBlindedBeaconBlockBody(b *eth.BlindedBeaconBlockBodyBellatrix) (block.BeaconBlockBody, error) { +func WrappedBellatrixBlindedBeaconBlockBody(b *eth.BlindedBeaconBlockBodyBellatrix) (interfaces.BeaconBlockBody, error) { w := blindedBeaconBlockBodyBellatrix{b: b} if w.IsNil() { return nil, ErrNilObjectWrapped diff --git a/consensus-types/wrapper/mutator.go b/consensus-types/wrapper/mutator.go index df561d21c7..9db5f54980 100644 --- a/consensus-types/wrapper/mutator.go +++ b/consensus-types/wrapper/mutator.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/runtime/version" @@ -16,7 +16,7 @@ type BlockMutator struct { Bellatrix func(beaconBlock *eth.SignedBeaconBlockBellatrix) } -func (m BlockMutator) Apply(b block.SignedBeaconBlock) error { +func (m BlockMutator) Apply(b interfaces.SignedBeaconBlock) error { switch b.Version() { case version.Phase0: bb, err := b.PbPhase0Block() @@ -44,7 +44,7 @@ func (m BlockMutator) Apply(b block.SignedBeaconBlock) error { return errors.Wrap(ErrUnsupportedSignedBeaconBlock, msg) } -func SetBlockStateRoot(b block.SignedBeaconBlock, sr [32]byte) error { +func SetBlockStateRoot(b interfaces.SignedBeaconBlock, sr [32]byte) error { return BlockMutator{ Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.StateRoot = sr[:] }, Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.StateRoot = sr[:] }, @@ -52,7 +52,7 @@ func SetBlockStateRoot(b block.SignedBeaconBlock, sr [32]byte) error { }.Apply(b) } -func SetBlockParentRoot(b block.SignedBeaconBlock, pr [32]byte) error { +func SetBlockParentRoot(b interfaces.SignedBeaconBlock, pr [32]byte) error { return BlockMutator{ Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.ParentRoot = pr[:] }, Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.ParentRoot = pr[:] }, @@ -60,7 +60,7 @@ func SetBlockParentRoot(b block.SignedBeaconBlock, pr [32]byte) error { }.Apply(b) } -func SetBlockSlot(b block.SignedBeaconBlock, s types.Slot) error { +func SetBlockSlot(b interfaces.SignedBeaconBlock, s types.Slot) error { return BlockMutator{ Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.Slot = s }, Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.Slot = s }, @@ -68,7 +68,7 @@ func SetBlockSlot(b block.SignedBeaconBlock, s types.Slot) error { }.Apply(b) } -func SetProposerIndex(b block.SignedBeaconBlock, idx types.ValidatorIndex) error { +func SetProposerIndex(b interfaces.SignedBeaconBlock, idx types.ValidatorIndex) error { return BlockMutator{ Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.ProposerIndex = idx }, Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.ProposerIndex = idx }, diff --git a/encoding/ssz/detect/BUILD.bazel b/encoding/ssz/detect/BUILD.bazel index b53ddf50c2..9d11e3fcd9 100644 --- a/encoding/ssz/detect/BUILD.bazel +++ b/encoding/ssz/detect/BUILD.bazel @@ -15,7 +15,7 @@ go_library( "//beacon-chain/state/v3:go_default_library", "//config/fieldparams: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/wrapper:go_default_library", "//encoding/bytesutil:go_default_library", @@ -38,7 +38,7 @@ go_test( deps = [ "//beacon-chain/state: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/wrapper:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/encoding/ssz/detect/configfork.go b/encoding/ssz/detect/configfork.go index a4345014f7..98cceadb13 100644 --- a/encoding/ssz/detect/configfork.go +++ b/encoding/ssz/detect/configfork.go @@ -3,6 +3,7 @@ package detect import ( "fmt" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/network/forks" @@ -14,7 +15,6 @@ import ( v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" - "github.com/prysmaticlabs/prysm/consensus-types/block" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -140,7 +140,7 @@ var errBlockForkMismatch = errors.New("fork or config detected from state is dif // UnmarshalBeaconBlock uses internal knowledge in the VersionedUnmarshaler to pick the right concrete SignedBeaconBlock type, // then Unmarshal()s the type and returns an instance of block.SignedBeaconBlock if successful. -func (cf *VersionedUnmarshaler) UnmarshalBeaconBlock(marshaled []byte) (block.SignedBeaconBlock, error) { +func (cf *VersionedUnmarshaler) UnmarshalBeaconBlock(marshaled []byte) (interfaces.SignedBeaconBlock, error) { slot, err := slotFromBlock(marshaled) if err != nil { return nil, err diff --git a/encoding/ssz/detect/configfork_test.go b/encoding/ssz/detect/configfork_test.go index db42b8e418..3d80807095 100644 --- a/encoding/ssz/detect/configfork_test.go +++ b/encoding/ssz/detect/configfork_test.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "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/encoding/bytesutil" "github.com/prysmaticlabs/prysm/runtime/version" @@ -199,7 +199,7 @@ func TestUnmarshalBlock(t *testing.T) { bellaS, err := slots.EpochStart(bc.BellatrixForkEpoch) require.NoError(t, err) cases := []struct { - b func(*testing.T, types.Slot) block.SignedBeaconBlock + b func(*testing.T, types.Slot) interfaces.SignedBeaconBlock name string version [4]byte slot types.Slot @@ -277,7 +277,7 @@ func TestUnmarshalBlock(t *testing.T) { } } -func signedTestBlockGenesis(t *testing.T, slot types.Slot) block.SignedBeaconBlock { +func signedTestBlockGenesis(t *testing.T, slot types.Slot) interfaces.SignedBeaconBlock { b := testBlockGenesis() b.Block.Slot = slot s, err := wrapper.WrappedSignedBeaconBlock(b) @@ -310,7 +310,7 @@ func testBlockGenesis() *ethpb.SignedBeaconBlock { } } -func signedTestBlockAltair(t *testing.T, slot types.Slot) block.SignedBeaconBlock { +func signedTestBlockAltair(t *testing.T, slot types.Slot) interfaces.SignedBeaconBlock { b := testBlockAltair() b.Block.Slot = slot s, err := wrapper.WrappedSignedBeaconBlock(b) @@ -347,7 +347,7 @@ func testBlockAltair() *ethpb.SignedBeaconBlockAltair { } } -func signedTestBlockBellatrix(t *testing.T, slot types.Slot) block.SignedBeaconBlock { +func signedTestBlockBellatrix(t *testing.T, slot types.Slot) interfaces.SignedBeaconBlock { b := testBlockBellatrix() b.Block.Slot = slot s, err := wrapper.WrappedSignedBeaconBlock(b) diff --git a/proto/migration/BUILD.bazel b/proto/migration/BUILD.bazel index ba8ceef852..598ae16fa5 100644 --- a/proto/migration/BUILD.bazel +++ b/proto/migration/BUILD.bazel @@ -11,7 +11,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//beacon-chain/state:go_default_library", - "//consensus-types/block:go_default_library", + "//consensus-types/interfaces:go_default_library", "//encoding/bytesutil:go_default_library", "//encoding/ssz:go_default_library", "//proto/engine/v1:go_default_library", diff --git a/proto/migration/v1alpha1_to_v1.go b/proto/migration/v1alpha1_to_v1.go index c561bce044..2efbfa0a9b 100644 --- a/proto/migration/v1alpha1_to_v1.go +++ b/proto/migration/v1alpha1_to_v1.go @@ -3,7 +3,7 @@ package migration import ( "github.com/pkg/errors" "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/encoding/bytesutil" ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1" ethpbalpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -11,7 +11,7 @@ import ( ) // BlockIfaceToV1BlockHeader converts a signed beacon block interface into a signed beacon block header. -func BlockIfaceToV1BlockHeader(block block.SignedBeaconBlock) (*ethpbv1.SignedBeaconBlockHeader, error) { +func BlockIfaceToV1BlockHeader(block interfaces.SignedBeaconBlock) (*ethpbv1.SignedBeaconBlockHeader, error) { bodyRoot, err := block.Block().Body().HashTreeRoot() if err != nil { return nil, errors.Wrap(err, "failed to get body root of block") @@ -335,7 +335,7 @@ func V1ValidatorToV1Alpha1(v1Validator *ethpbv1.Validator) *ethpbalpha.Validator } // SignedBeaconBlock converts a signed beacon block interface to a v1alpha1 block. -func SignedBeaconBlock(block block.SignedBeaconBlock) (*ethpbv1.SignedBeaconBlock, error) { +func SignedBeaconBlock(block interfaces.SignedBeaconBlock) (*ethpbv1.SignedBeaconBlock, error) { if block == nil || block.IsNil() { return nil, errors.New("could not find requested block") } diff --git a/testing/endtoend/evaluators/BUILD.bazel b/testing/endtoend/evaluators/BUILD.bazel index a43ddcc383..fa986abfa3 100644 --- a/testing/endtoend/evaluators/BUILD.bazel +++ b/testing/endtoend/evaluators/BUILD.bazel @@ -25,7 +25,7 @@ go_library( "//beacon-chain/p2p:go_default_library", "//config/fieldparams: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/wrapper:go_default_library", "//container/slice:go_default_library", diff --git a/testing/endtoend/evaluators/operations.go b/testing/endtoend/evaluators/operations.go index e9b2be863e..7781075f4a 100644 --- a/testing/endtoend/evaluators/operations.go +++ b/testing/endtoend/evaluators/operations.go @@ -10,7 +10,7 @@ import ( corehelpers "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -409,7 +409,7 @@ func validatorsVoteWithTheMajority(conns ...*grpc.ClientConn) error { var expectedEth1DataVote []byte -func convertToBlockInterface(obj *ethpb.BeaconBlockContainer) (block.SignedBeaconBlock, error) { +func convertToBlockInterface(obj *ethpb.BeaconBlockContainer) (interfaces.SignedBeaconBlock, error) { if obj.GetPhase0Block() != nil { return wrapper.WrappedSignedBeaconBlock(obj.GetPhase0Block()) } diff --git a/testing/endtoend/evaluators/validator.go b/testing/endtoend/evaluators/validator.go index 893b5b2546..ce728c9993 100644 --- a/testing/endtoend/evaluators/validator.go +++ b/testing/endtoend/evaluators/validator.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/config/params" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" ethtypes "github.com/prysmaticlabs/prysm/consensus-types/primitives" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -212,7 +212,7 @@ func validatorsSyncParticipation(conns ...*grpc.ClientConn) error { return nil } -func syncCompatibleBlockFromCtr(container *ethpb.BeaconBlockContainer) (block.SignedBeaconBlock, error) { +func syncCompatibleBlockFromCtr(container *ethpb.BeaconBlockContainer) (interfaces.SignedBeaconBlock, error) { if container.GetPhase0Block() != nil { return nil, errors.New("block doesn't support sync committees") } diff --git a/testing/spectest/shared/altair/operations/BUILD.bazel b/testing/spectest/shared/altair/operations/BUILD.bazel index 111d0252a7..12eeb4dd47 100644 --- a/testing/spectest/shared/altair/operations/BUILD.bazel +++ b/testing/spectest/shared/altair/operations/BUILD.bazel @@ -22,7 +22,7 @@ go_library( "//beacon-chain/core/validators:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v2:go_default_library", - "//consensus-types/block:go_default_library", + "//consensus-types/interfaces:go_default_library", "//consensus-types/wrapper:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//testing/require:go_default_library", diff --git a/testing/spectest/shared/altair/operations/attestation.go b/testing/spectest/shared/altair/operations/attestation.go index 029ca85a2f..d6540ffef3 100644 --- a/testing/spectest/shared/altair/operations/attestation.go +++ b/testing/spectest/shared/altair/operations/attestation.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -31,7 +31,7 @@ func RunAttestationTest(t *testing.T, config string) { require.NoError(t, att.UnmarshalSSZ(attestationSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyAltair{Attestations: []*ethpb.Attestation{att}} - processAtt := func(ctx context.Context, st state.BeaconState, blk block.SignedBeaconBlock) (state.BeaconState, error) { + processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.SignedBeaconBlock) (state.BeaconState, error) { st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk) if err != nil { return nil, err diff --git a/testing/spectest/shared/altair/operations/attester_slashing.go b/testing/spectest/shared/altair/operations/attester_slashing.go index 1e63e3f5b3..6801a95ee7 100644 --- a/testing/spectest/shared/altair/operations/attester_slashing.go +++ b/testing/spectest/shared/altair/operations/attester_slashing.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -30,7 +30,7 @@ func RunAttesterSlashingTest(t *testing.T, config string) { require.NoError(t, attSlashing.UnmarshalSSZ(attSlashingSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyAltair{AttesterSlashings: []*ethpb.AttesterSlashing{attSlashing}} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return blocks.ProcessAttesterSlashings(ctx, s, b.Block().Body().AttesterSlashings(), validators.SlashValidator) }) }) diff --git a/testing/spectest/shared/altair/operations/deposit.go b/testing/spectest/shared/altair/operations/deposit.go index d48a0a30e5..1f84cbb19a 100644 --- a/testing/spectest/shared/altair/operations/deposit.go +++ b/testing/spectest/shared/altair/operations/deposit.go @@ -8,7 +8,7 @@ import ( "github.com/golang/snappy" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -29,7 +29,7 @@ func RunDepositTest(t *testing.T, config string) { require.NoError(t, deposit.UnmarshalSSZ(depositSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyAltair{Deposits: []*ethpb.Deposit{deposit}} - processDepositsFunc := func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + processDepositsFunc := func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return altair.ProcessDeposits(ctx, s, b.Block().Body().Deposits()) } RunBlockOperationTest(t, folderPath, body, processDepositsFunc) diff --git a/testing/spectest/shared/altair/operations/helpers.go b/testing/spectest/shared/altair/operations/helpers.go index 3b00b907cb..bb43329429 100644 --- a/testing/spectest/shared/altair/operations/helpers.go +++ b/testing/spectest/shared/altair/operations/helpers.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" stateAltair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/require" @@ -21,7 +21,7 @@ import ( "gopkg.in/d4l3k/messagediff.v1" ) -type blockOperation func(context.Context, state.BeaconState, block.SignedBeaconBlock) (state.BeaconState, error) +type blockOperation func(context.Context, state.BeaconState, interfaces.SignedBeaconBlock) (state.BeaconState, error) // RunBlockOperationTest takes in the prestate and the beacon block body, processes it through the // passed in block operation function and checks the post state with the expected post state. diff --git a/testing/spectest/shared/altair/operations/proposer_slashing.go b/testing/spectest/shared/altair/operations/proposer_slashing.go index 546728ff58..a819910348 100644 --- a/testing/spectest/shared/altair/operations/proposer_slashing.go +++ b/testing/spectest/shared/altair/operations/proposer_slashing.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -30,7 +30,7 @@ func RunProposerSlashingTest(t *testing.T, config string) { require.NoError(t, proposerSlashing.UnmarshalSSZ(proposerSlashingSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyAltair{ProposerSlashings: []*ethpb.ProposerSlashing{proposerSlashing}} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return blocks.ProcessProposerSlashings(ctx, s, b.Block().Body().ProposerSlashings(), validators.SlashValidator) }) }) diff --git a/testing/spectest/shared/altair/operations/sync_committee.go b/testing/spectest/shared/altair/operations/sync_committee.go index 04cff5a317..ba66fd1a6d 100644 --- a/testing/spectest/shared/altair/operations/sync_committee.go +++ b/testing/spectest/shared/altair/operations/sync_committee.go @@ -8,7 +8,7 @@ import ( "github.com/golang/snappy" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -29,7 +29,7 @@ func RunSyncCommitteeTest(t *testing.T, config string) { require.NoError(t, sc.UnmarshalSSZ(syncCommitteeSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyAltair{SyncAggregate: sc} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return altair.ProcessSyncAggregate(context.Background(), s, body.SyncAggregate) }) }) diff --git a/testing/spectest/shared/altair/operations/voluntary_exit.go b/testing/spectest/shared/altair/operations/voluntary_exit.go index 1c0c73bc68..04664508d3 100644 --- a/testing/spectest/shared/altair/operations/voluntary_exit.go +++ b/testing/spectest/shared/altair/operations/voluntary_exit.go @@ -8,7 +8,7 @@ import ( "github.com/golang/snappy" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -29,7 +29,7 @@ func RunVoluntaryExitTest(t *testing.T, config string) { require.NoError(t, voluntaryExit.UnmarshalSSZ(exitSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyAltair{VoluntaryExits: []*ethpb.SignedVoluntaryExit{voluntaryExit}} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return blocks.ProcessVoluntaryExits(ctx, s, b.Block().Body().VoluntaryExits()) }) }) diff --git a/testing/spectest/shared/bellatrix/operations/BUILD.bazel b/testing/spectest/shared/bellatrix/operations/BUILD.bazel index 4e56a37f0d..086e735f2c 100644 --- a/testing/spectest/shared/bellatrix/operations/BUILD.bazel +++ b/testing/spectest/shared/bellatrix/operations/BUILD.bazel @@ -22,7 +22,7 @@ go_library( "//beacon-chain/core/validators:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v3:go_default_library", - "//consensus-types/block:go_default_library", + "//consensus-types/interfaces:go_default_library", "//consensus-types/wrapper:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//testing/require:go_default_library", diff --git a/testing/spectest/shared/bellatrix/operations/attestation.go b/testing/spectest/shared/bellatrix/operations/attestation.go index 83dc440173..ef663312a2 100644 --- a/testing/spectest/shared/bellatrix/operations/attestation.go +++ b/testing/spectest/shared/bellatrix/operations/attestation.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -31,7 +31,7 @@ func RunAttestationTest(t *testing.T, config string) { require.NoError(t, att.UnmarshalSSZ(attestationSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyBellatrix{Attestations: []*ethpb.Attestation{att}} - processAtt := func(ctx context.Context, st state.BeaconState, blk block.SignedBeaconBlock) (state.BeaconState, error) { + processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.SignedBeaconBlock) (state.BeaconState, error) { st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk) if err != nil { return nil, err diff --git a/testing/spectest/shared/bellatrix/operations/attester_slashing.go b/testing/spectest/shared/bellatrix/operations/attester_slashing.go index ea34c466f9..6cefa71547 100644 --- a/testing/spectest/shared/bellatrix/operations/attester_slashing.go +++ b/testing/spectest/shared/bellatrix/operations/attester_slashing.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -30,7 +30,7 @@ func RunAttesterSlashingTest(t *testing.T, config string) { require.NoError(t, attSlashing.UnmarshalSSZ(attSlashingSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyBellatrix{AttesterSlashings: []*ethpb.AttesterSlashing{attSlashing}} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return blocks.ProcessAttesterSlashings(ctx, s, b.Block().Body().AttesterSlashings(), validators.SlashValidator) }) }) diff --git a/testing/spectest/shared/bellatrix/operations/deposit.go b/testing/spectest/shared/bellatrix/operations/deposit.go index aed336710d..0cb9c3e3e9 100644 --- a/testing/spectest/shared/bellatrix/operations/deposit.go +++ b/testing/spectest/shared/bellatrix/operations/deposit.go @@ -8,7 +8,7 @@ import ( "github.com/golang/snappy" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -29,7 +29,7 @@ func RunDepositTest(t *testing.T, config string) { require.NoError(t, deposit.UnmarshalSSZ(depositSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyBellatrix{Deposits: []*ethpb.Deposit{deposit}} - processDepositsFunc := func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + processDepositsFunc := func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return altair.ProcessDeposits(ctx, s, b.Block().Body().Deposits()) } RunBlockOperationTest(t, folderPath, body, processDepositsFunc) diff --git a/testing/spectest/shared/bellatrix/operations/helpers.go b/testing/spectest/shared/bellatrix/operations/helpers.go index 2782d02ec0..5743eba152 100644 --- a/testing/spectest/shared/bellatrix/operations/helpers.go +++ b/testing/spectest/shared/bellatrix/operations/helpers.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/require" @@ -21,7 +21,7 @@ import ( "gopkg.in/d4l3k/messagediff.v1" ) -type blockOperation func(context.Context, state.BeaconState, block.SignedBeaconBlock) (state.BeaconState, error) +type blockOperation func(context.Context, state.BeaconState, interfaces.SignedBeaconBlock) (state.BeaconState, error) // RunBlockOperationTest takes in the prestate and the beacon block body, processes it through the // passed in block operation function and checks the post state with the expected post state. diff --git a/testing/spectest/shared/bellatrix/operations/proposer_slashing.go b/testing/spectest/shared/bellatrix/operations/proposer_slashing.go index 4741f1a98b..8411f29c0d 100644 --- a/testing/spectest/shared/bellatrix/operations/proposer_slashing.go +++ b/testing/spectest/shared/bellatrix/operations/proposer_slashing.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -30,7 +30,7 @@ func RunProposerSlashingTest(t *testing.T, config string) { require.NoError(t, proposerSlashing.UnmarshalSSZ(proposerSlashingSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyBellatrix{ProposerSlashings: []*ethpb.ProposerSlashing{proposerSlashing}} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return blocks.ProcessProposerSlashings(ctx, s, b.Block().Body().ProposerSlashings(), validators.SlashValidator) }) }) diff --git a/testing/spectest/shared/bellatrix/operations/sync_committee.go b/testing/spectest/shared/bellatrix/operations/sync_committee.go index a0b058be84..1c039acd91 100644 --- a/testing/spectest/shared/bellatrix/operations/sync_committee.go +++ b/testing/spectest/shared/bellatrix/operations/sync_committee.go @@ -8,7 +8,7 @@ import ( "github.com/golang/snappy" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -29,7 +29,7 @@ func RunSyncCommitteeTest(t *testing.T, config string) { require.NoError(t, sc.UnmarshalSSZ(syncCommitteeSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyBellatrix{SyncAggregate: sc} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return altair.ProcessSyncAggregate(context.Background(), s, body.SyncAggregate) }) }) diff --git a/testing/spectest/shared/bellatrix/operations/voluntary_exit.go b/testing/spectest/shared/bellatrix/operations/voluntary_exit.go index ef6d12c894..6a9ebe5933 100644 --- a/testing/spectest/shared/bellatrix/operations/voluntary_exit.go +++ b/testing/spectest/shared/bellatrix/operations/voluntary_exit.go @@ -8,7 +8,7 @@ import ( "github.com/golang/snappy" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -29,7 +29,7 @@ func RunVoluntaryExitTest(t *testing.T, config string) { require.NoError(t, voluntaryExit.UnmarshalSSZ(exitSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBodyBellatrix{VoluntaryExits: []*ethpb.SignedVoluntaryExit{voluntaryExit}} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return blocks.ProcessVoluntaryExits(ctx, s, b.Block().Body().VoluntaryExits()) }) }) diff --git a/testing/spectest/shared/common/forkchoice/BUILD.bazel b/testing/spectest/shared/common/forkchoice/BUILD.bazel index 4be3e28e46..5fd3adeec6 100644 --- a/testing/spectest/shared/common/forkchoice/BUILD.bazel +++ b/testing/spectest/shared/common/forkchoice/BUILD.bazel @@ -27,7 +27,7 @@ go_library( "//beacon-chain/state/v3:go_default_library", "//config/fieldparams: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/wrapper:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/testing/spectest/shared/common/forkchoice/runner.go b/testing/spectest/shared/common/forkchoice/runner.go index c4e1a8d65b..35c1a21f91 100644 --- a/testing/spectest/shared/common/forkchoice/runner.go +++ b/testing/spectest/shared/common/forkchoice/runner.go @@ -17,7 +17,7 @@ import ( v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -57,7 +57,7 @@ func Run(t *testing.T, config string, fork int) { require.NoError(t, err) var beaconState state.BeaconState - var beaconBlock block.SignedBeaconBlock + var beaconBlock interfaces.SignedBeaconBlock switch fork { case version.Phase0: beaconState = unmarshalPhase0State(t, preBeaconStateSSZ) @@ -92,7 +92,7 @@ func Run(t *testing.T, config string, fork int) { require.NoError(t, err) blockSSZ, err := snappy.Decode(nil /* dst */, blockFile) require.NoError(t, err) - var beaconBlock block.SignedBeaconBlock + var beaconBlock interfaces.SignedBeaconBlock switch fork { case version.Phase0: beaconBlock = unmarshalSignedPhase0Block(t, blockSSZ) @@ -190,7 +190,7 @@ func unmarshalPhase0State(t *testing.T, raw []byte) state.BeaconState { return st } -func unmarshalPhase0Block(t *testing.T, raw []byte) block.SignedBeaconBlock { +func unmarshalPhase0Block(t *testing.T, raw []byte) interfaces.SignedBeaconBlock { base := ðpb.BeaconBlock{} require.NoError(t, base.UnmarshalSSZ(raw)) blk, err := wrapper.WrappedSignedBeaconBlock(ðpb.SignedBeaconBlock{Block: base, Signature: make([]byte, fieldparams.BLSSignatureLength)}) @@ -198,7 +198,7 @@ func unmarshalPhase0Block(t *testing.T, raw []byte) block.SignedBeaconBlock { return blk } -func unmarshalSignedPhase0Block(t *testing.T, raw []byte) block.SignedBeaconBlock { +func unmarshalSignedPhase0Block(t *testing.T, raw []byte) interfaces.SignedBeaconBlock { base := ðpb.SignedBeaconBlock{} require.NoError(t, base.UnmarshalSSZ(raw)) blk, err := wrapper.WrappedSignedBeaconBlock(base) @@ -214,7 +214,7 @@ func unmarshalAltairState(t *testing.T, raw []byte) state.BeaconState { return st } -func unmarshalAltairBlock(t *testing.T, raw []byte) block.SignedBeaconBlock { +func unmarshalAltairBlock(t *testing.T, raw []byte) interfaces.SignedBeaconBlock { base := ðpb.BeaconBlockAltair{} require.NoError(t, base.UnmarshalSSZ(raw)) blk, err := wrapper.WrappedSignedBeaconBlock(ðpb.SignedBeaconBlockAltair{Block: base, Signature: make([]byte, fieldparams.BLSSignatureLength)}) @@ -222,7 +222,7 @@ func unmarshalAltairBlock(t *testing.T, raw []byte) block.SignedBeaconBlock { return blk } -func unmarshalSignedAltairBlock(t *testing.T, raw []byte) block.SignedBeaconBlock { +func unmarshalSignedAltairBlock(t *testing.T, raw []byte) interfaces.SignedBeaconBlock { base := ðpb.SignedBeaconBlockAltair{} require.NoError(t, base.UnmarshalSSZ(raw)) blk, err := wrapper.WrappedSignedBeaconBlock(base) @@ -238,7 +238,7 @@ func unmarshalBellatrixState(t *testing.T, raw []byte) state.BeaconState { return st } -func unmarshalBellatrixBlock(t *testing.T, raw []byte) block.SignedBeaconBlock { +func unmarshalBellatrixBlock(t *testing.T, raw []byte) interfaces.SignedBeaconBlock { base := ðpb.BeaconBlockBellatrix{} require.NoError(t, base.UnmarshalSSZ(raw)) blk, err := wrapper.WrappedSignedBeaconBlock(ðpb.SignedBeaconBlockBellatrix{Block: base, Signature: make([]byte, fieldparams.BLSSignatureLength)}) @@ -246,7 +246,7 @@ func unmarshalBellatrixBlock(t *testing.T, raw []byte) block.SignedBeaconBlock { return blk } -func unmarshalSignedBellatrixBlock(t *testing.T, raw []byte) block.SignedBeaconBlock { +func unmarshalSignedBellatrixBlock(t *testing.T, raw []byte) interfaces.SignedBeaconBlock { base := ðpb.SignedBeaconBlockBellatrix{} require.NoError(t, base.UnmarshalSSZ(raw)) blk, err := wrapper.WrappedSignedBeaconBlock(base) diff --git a/testing/spectest/shared/common/forkchoice/service.go b/testing/spectest/shared/common/forkchoice/service.go index f57a220e7f..d2e108b587 100644 --- a/testing/spectest/shared/common/forkchoice/service.go +++ b/testing/spectest/shared/common/forkchoice/service.go @@ -18,14 +18,14 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "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" pb "github.com/prysmaticlabs/prysm/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/require" ) -func startChainService(t *testing.T, st state.BeaconState, block block.SignedBeaconBlock, engineMock *engineMock) *blockchain.Service { +func startChainService(t *testing.T, st state.BeaconState, block interfaces.SignedBeaconBlock, engineMock *engineMock) *blockchain.Service { db := testDB.SetupDB(t) ctx := context.Background() require.NoError(t, db.SaveBlock(ctx, block)) diff --git a/testing/spectest/shared/phase0/operations/BUILD.bazel b/testing/spectest/shared/phase0/operations/BUILD.bazel index 12032e1175..679649fc45 100644 --- a/testing/spectest/shared/phase0/operations/BUILD.bazel +++ b/testing/spectest/shared/phase0/operations/BUILD.bazel @@ -20,7 +20,7 @@ go_library( "//beacon-chain/core/validators:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", - "//consensus-types/block:go_default_library", + "//consensus-types/interfaces:go_default_library", "//consensus-types/wrapper:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//testing/require:go_default_library", diff --git a/testing/spectest/shared/phase0/operations/attestation.go b/testing/spectest/shared/phase0/operations/attestation.go index a5602542b1..2636f7dd7a 100644 --- a/testing/spectest/shared/phase0/operations/attestation.go +++ b/testing/spectest/shared/phase0/operations/attestation.go @@ -9,7 +9,7 @@ import ( "github.com/pkg/errors" b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -31,7 +31,7 @@ func RunAttestationTest(t *testing.T, config string) { require.NoError(t, att.UnmarshalSSZ(attestationSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBody{Attestations: []*ethpb.Attestation{att}} - processAtt := func(ctx context.Context, st state.BeaconState, blk block.SignedBeaconBlock) (state.BeaconState, error) { + processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.SignedBeaconBlock) (state.BeaconState, error) { st, err = b.ProcessAttestationsNoVerifySignature(ctx, st, blk) if err != nil { return nil, err diff --git a/testing/spectest/shared/phase0/operations/attester_slashing.go b/testing/spectest/shared/phase0/operations/attester_slashing.go index 877130dbbf..2896176751 100644 --- a/testing/spectest/shared/phase0/operations/attester_slashing.go +++ b/testing/spectest/shared/phase0/operations/attester_slashing.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -31,7 +31,7 @@ func RunAttesterSlashingTest(t *testing.T, config string) { require.NoError(t, attSlashing.UnmarshalSSZ(attSlashingSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBody{AttesterSlashings: []*ethpb.AttesterSlashing{attSlashing}} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return blocks.ProcessAttesterSlashings(ctx, s, b.Block().Body().AttesterSlashings(), v.SlashValidator) }) }) diff --git a/testing/spectest/shared/phase0/operations/deposit.go b/testing/spectest/shared/phase0/operations/deposit.go index 8ff57ac981..bf0da96d28 100644 --- a/testing/spectest/shared/phase0/operations/deposit.go +++ b/testing/spectest/shared/phase0/operations/deposit.go @@ -8,7 +8,7 @@ import ( "github.com/golang/snappy" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -30,7 +30,7 @@ func RunDepositTest(t *testing.T, config string) { require.NoError(t, deposit.UnmarshalSSZ(depositSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBody{Deposits: []*ethpb.Deposit{deposit}} - processDepositsFunc := func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + processDepositsFunc := func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return blocks.ProcessDeposits(ctx, s, b.Block().Body().Deposits()) } RunBlockOperationTest(t, folderPath, body, processDepositsFunc) diff --git a/testing/spectest/shared/phase0/operations/helpers.go b/testing/spectest/shared/phase0/operations/helpers.go index bd3230cc94..4c169b4971 100644 --- a/testing/spectest/shared/phase0/operations/helpers.go +++ b/testing/spectest/shared/phase0/operations/helpers.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/require" @@ -21,7 +21,7 @@ import ( "gopkg.in/d4l3k/messagediff.v1" ) -type blockOperation func(context.Context, state.BeaconState, block.SignedBeaconBlock) (state.BeaconState, error) +type blockOperation func(context.Context, state.BeaconState, interfaces.SignedBeaconBlock) (state.BeaconState, error) // RunBlockOperationTest takes in the prestate and the beacon block body, processes it through the // passed in block operation function and checks the post state with the expected post state. diff --git a/testing/spectest/shared/phase0/operations/proposer_slashing.go b/testing/spectest/shared/phase0/operations/proposer_slashing.go index 8ab462061f..c277b7d5d4 100644 --- a/testing/spectest/shared/phase0/operations/proposer_slashing.go +++ b/testing/spectest/shared/phase0/operations/proposer_slashing.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -31,7 +31,7 @@ func RunProposerSlashingTest(t *testing.T, config string) { require.NoError(t, proposerSlashing.UnmarshalSSZ(proposerSlashingSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBody{ProposerSlashings: []*ethpb.ProposerSlashing{proposerSlashing}} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return blocks.ProcessProposerSlashings(ctx, s, b.Block().Body().ProposerSlashings(), v.SlashValidator) }) }) diff --git a/testing/spectest/shared/phase0/operations/voluntary_exit.go b/testing/spectest/shared/phase0/operations/voluntary_exit.go index 1a4a98149a..59eb25f97d 100644 --- a/testing/spectest/shared/phase0/operations/voluntary_exit.go +++ b/testing/spectest/shared/phase0/operations/voluntary_exit.go @@ -8,7 +8,7 @@ import ( "github.com/golang/snappy" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "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" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/spectest/utils" @@ -30,7 +30,7 @@ func RunVoluntaryExitTest(t *testing.T, config string) { require.NoError(t, voluntaryExit.UnmarshalSSZ(exitSSZ), "Failed to unmarshal") body := ðpb.BeaconBlockBody{VoluntaryExits: []*ethpb.SignedVoluntaryExit{voluntaryExit}} - RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) { + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { return blocks.ProcessVoluntaryExits(ctx, s, b.Block().Body().VoluntaryExits()) }) }) diff --git a/testing/util/BUILD.bazel b/testing/util/BUILD.bazel index b519412fb6..89cf4a6672 100644 --- a/testing/util/BUILD.bazel +++ b/testing/util/BUILD.bazel @@ -35,7 +35,7 @@ go_library( "//beacon-chain/state/v3:go_default_library", "//config/fieldparams: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/wrapper:go_default_library", "//container/trie:go_default_library", diff --git a/testing/util/state.go b/testing/util/state.go index cfa9363a17..1d97c51706 100644 --- a/testing/util/state.go +++ b/testing/util/state.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/testing/require" "github.com/ethereum/go-ethereum/common/hexutil" @@ -65,7 +65,7 @@ func WithStateSlot(slot types.Slot) NewBeaconStateOption { } } -func WithLatestHeaderFromBlock(t *testing.T, b block.SignedBeaconBlock) NewBeaconStateOption { +func WithLatestHeaderFromBlock(t *testing.T, b interfaces.SignedBeaconBlock) NewBeaconStateOption { return func(st *ethpb.BeaconState) error { sh, err := b.Header() require.NoError(t, err) diff --git a/tools/eth1voting/BUILD.bazel b/tools/eth1voting/BUILD.bazel index 4a08e5536f..5ac7b56edc 100644 --- a/tools/eth1voting/BUILD.bazel +++ b/tools/eth1voting/BUILD.bazel @@ -11,7 +11,7 @@ go_library( visibility = ["//visibility:private"], deps = [ "//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/wrapper:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/tools/eth1voting/main.go b/tools/eth1voting/main.go index e104976f6a..69fdf0848c 100644 --- a/tools/eth1voting/main.go +++ b/tools/eth1voting/main.go @@ -7,7 +7,7 @@ import ( "time" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" v1alpha1 "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -72,7 +72,7 @@ func main() { fmt.Println(v.Report()) } -func wrapBlock(b *v1alpha1.BeaconBlockContainer) block.BeaconBlock { +func wrapBlock(b *v1alpha1.BeaconBlockContainer) interfaces.BeaconBlock { if bb := b.GetAltairBlock(); bb != nil { wb, err := wrapper.WrappedAltairBeaconBlock(bb.Block) if err != nil { diff --git a/tools/eth1voting/votes.go b/tools/eth1voting/votes.go index 4a02169f68..f773ac61ae 100644 --- a/tools/eth1voting/votes.go +++ b/tools/eth1voting/votes.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/encoding/bytesutil" v1alpha1 "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ) @@ -30,7 +30,7 @@ func NewVotes() *votes { } } -func (v *votes) Insert(blk block.BeaconBlock) { +func (v *votes) Insert(blk interfaces.BeaconBlock) { v.l.Lock() defer v.l.Unlock() diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index 94b7eb7f1d..0ce1752200 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -34,7 +34,7 @@ go_library( "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//config/validator/service:go_default_library", - "//consensus-types/block:go_default_library", + "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//consensus-types/wrapper:go_default_library", "//crypto/bls:go_default_library", @@ -116,7 +116,7 @@ go_test( "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//config/validator/service:go_default_library", - "//consensus-types/block:go_default_library", + "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//consensus-types/wrapper:go_default_library", "//crypto/bls:go_default_library", diff --git a/validator/client/attest.go b/validator/client/attest.go index 17147a95ee..03603f2d0b 100644 --- a/validator/client/attest.go +++ b/validator/client/attest.go @@ -14,7 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/config/features" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/crypto/hash" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -268,7 +268,7 @@ func (v *validator) waitOneThirdOrValidBlock(ctx context.Context, slot types.Slo t := time.NewTimer(wait) defer t.Stop() - bChannel := make(chan block.SignedBeaconBlock, 1) + bChannel := make(chan interfaces.SignedBeaconBlock, 1) sub := v.blockFeed.Subscribe(bChannel) defer sub.Unsubscribe() diff --git a/validator/client/propose.go b/validator/client/propose.go index f8932b57cb..9325adc1d1 100644 --- a/validator/client/propose.go +++ b/validator/client/propose.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -244,7 +244,7 @@ func (v *validator) signRandaoReveal(ctx context.Context, pubKey [fieldparams.BL // Sign block with proposer domain and private key. // Returns the signature, block signing root, and any error. -func (v *validator) signBlock(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, epoch types.Epoch, slot types.Slot, b block.BeaconBlock) ([]byte, [32]byte, error) { +func (v *validator) signBlock(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, epoch types.Epoch, slot types.Slot, b interfaces.BeaconBlock) ([]byte, [32]byte, error) { domain, err := v.domainData(ctx, epoch, params.BeaconConfig().DomainBeaconProposer[:]) if err != nil { return nil, [32]byte{}, errors.Wrap(err, domainDataErr) diff --git a/validator/client/propose_protect.go b/validator/client/propose_protect.go index 13a3b51c4a..b169f12d9c 100644 --- a/validator/client/propose_protect.go +++ b/validator/client/propose_protect.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/config/features" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" "github.com/sirupsen/logrus" ) @@ -16,7 +16,7 @@ var failedBlockSignLocalErr = "attempted to sign a double proposal, block reject var failedBlockSignExternalErr = "attempted a double proposal, block rejected by remote slashing protection" func (v *validator) slashableProposalCheck( - ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signedBlock block.SignedBeaconBlock, signingRoot [32]byte, + ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signedBlock interfaces.SignedBeaconBlock, signingRoot [32]byte, ) error { fmtKey := fmt.Sprintf("%#x", pubKey[:]) @@ -59,7 +59,7 @@ func (v *validator) slashableProposalCheck( } if features.Get().RemoteSlasherProtection { - blockHdr, err := block.SignedBeaconBlockHeaderFromBlockInterface(signedBlock) + blockHdr, err := interfaces.SignedBeaconBlockHeaderFromBlockInterface(signedBlock) if err != nil { return errors.Wrap(err, "failed to get block header from block") } @@ -83,7 +83,7 @@ func (v *validator) slashableProposalCheck( return nil } -func blockLogFields(pubKey [fieldparams.BLSPubkeyLength]byte, blk block.BeaconBlock, sig []byte) logrus.Fields { +func blockLogFields(pubKey [fieldparams.BLSPubkeyLength]byte, blk interfaces.BeaconBlock, sig []byte) logrus.Fields { fields := logrus.Fields{ "proposerPublicKey": fmt.Sprintf("%#x", pubKey), "proposerIndex": blk.ProposerIndex(), diff --git a/validator/client/propose_protect_test.go b/validator/client/propose_protect_test.go index 9675ccf14b..6dc09c7253 100644 --- a/validator/client/propose_protect_test.go +++ b/validator/client/propose_protect_test.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/config/features" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -113,7 +113,7 @@ func Test_slashableProposalCheck(t *testing.T) { copy(pubKey[:], validatorKey.PublicKey().Marshal()) sBlock, err := wrapper.WrappedSignedBeaconBlock(blk) require.NoError(t, err) - blockHdr, err := block.SignedBeaconBlockHeaderFromBlockInterface(sBlock) + blockHdr, err := interfaces.SignedBeaconBlockHeaderFromBlockInterface(sBlock) require.NoError(t, err) mocks.slasherClient.EXPECT().IsSlashableBlock( @@ -146,7 +146,7 @@ func Test_slashableProposalCheck(t *testing.T) { blk.Block.Slot = 9 sBlock, err = wrapper.WrappedSignedBeaconBlock(blk) require.NoError(t, err) - blockHdr, err = block.SignedBeaconBlockHeaderFromBlockInterface(sBlock) + blockHdr, err = interfaces.SignedBeaconBlockHeaderFromBlockInterface(sBlock) require.NoError(t, err) mocks.slasherClient.EXPECT().IsSlashableBlock( gomock.Any(), // ctx @@ -171,7 +171,7 @@ func Test_slashableProposalCheck_RemoteProtection(t *testing.T) { blk.Block.Slot = 10 sBlock, err := wrapper.WrappedSignedBeaconBlock(blk) require.NoError(t, err) - blockHdr, err := block.SignedBeaconBlockHeaderFromBlockInterface(sBlock) + blockHdr, err := interfaces.SignedBeaconBlockHeaderFromBlockInterface(sBlock) require.NoError(t, err) m.slasherClient.EXPECT().IsSlashableBlock( gomock.Any(), // ctx diff --git a/validator/client/propose_test.go b/validator/client/propose_test.go index 830a110c3e..669c7cc411 100644 --- a/validator/client/propose_test.go +++ b/validator/client/propose_test.go @@ -13,7 +13,7 @@ import ( lruwrpr "github.com/prysmaticlabs/prysm/cache/lru" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "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" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -578,7 +578,7 @@ func testProposeBlock(t *testing.T, graffiti []byte) { gomock.Any(), // epoch ).Return(ðpb.DomainResponse{SignatureDomain: make([]byte, 32)}, nil /*err*/) - var sentBlock block.SignedBeaconBlock + var sentBlock interfaces.SignedBeaconBlock var err error m.validatorClient.EXPECT().ProposeBeaconBlock( diff --git a/validator/client/service.go b/validator/client/service.go index 795aee5db8..65b177d398 100644 --- a/validator/client/service.go +++ b/validator/client/service.go @@ -17,7 +17,7 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" validator_service_config "github.com/prysmaticlabs/prysm/config/validator/service" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" @@ -214,7 +214,7 @@ func (v *ValidatorService) Start() { // the inner type of the feed before hand. So that // during future accesses, there will be no panics here // from type incompatibility. - tempChan := make(chan block.SignedBeaconBlock) + tempChan := make(chan interfaces.SignedBeaconBlock) sub := valStruct.blockFeed.Subscribe(tempChan) sub.Unsubscribe() close(tempChan) diff --git a/validator/client/validator.go b/validator/client/validator.go index 78e316d897..7d7e912bf1 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -26,7 +26,7 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/config/params" validator_service_config "github.com/prysmaticlabs/prysm/config/validator/service" - "github.com/prysmaticlabs/prysm/consensus-types/block" + "github.com/prysmaticlabs/prysm/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" "github.com/prysmaticlabs/prysm/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/crypto/hash" @@ -340,7 +340,7 @@ func (v *validator) ReceiveBlocks(ctx context.Context, connectionErrorChannel ch if res == nil || res.Block == nil { continue } - var blk block.SignedBeaconBlock + var blk interfaces.SignedBeaconBlock switch b := res.Block.(type) { case *ethpb.StreamBlocksResponse_Phase0Block: blk, err = wrapper.WrappedSignedBeaconBlock(b.Phase0Block)