Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Block Interface Across Prysm #8918

Merged
merged 53 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b4e8c2b
commit initial work
nisdas May 21, 2021
ee2e4af
checkpoint current work
nisdas May 21, 2021
4d82c1a
gaz
nisdas May 21, 2021
6872b20
checkpoint
nisdas May 21, 2021
2fd5e66
req/resp changes
nisdas May 21, 2021
e0b54c7
initial-sync
nisdas May 21, 2021
1ff779a
finally works
nisdas May 21, 2021
b32d16e
fix error
nisdas May 21, 2021
96204c7
fix bugs
nisdas May 21, 2021
7b8aecc
fix issue
nisdas May 22, 2021
588774b
fix issues
nisdas May 22, 2021
46be72e
Merge branch 'develop' of https://github.com/prysmaticlabs/geth-shard…
nisdas May 24, 2021
38a237d
Merge branch 'develop' of https://github.com/prysmaticlabs/geth-shard…
nisdas May 24, 2021
ee33eea
fix refs
nisdas May 24, 2021
4e60370
tests
nisdas May 25, 2021
f890977
more text fixes
nisdas May 25, 2021
0d12504
more text fixes
nisdas May 25, 2021
237b785
more text fixes
nisdas May 25, 2021
db29b95
fix tests
nisdas May 25, 2021
5e234a1
fix tests
nisdas May 25, 2021
f058514
tests
nisdas May 25, 2021
78cd401
finally fix builds
nisdas May 25, 2021
bd6dcce
finally
nisdas May 25, 2021
cf97730
comments
nisdas May 25, 2021
b021a29
Merge branch 'develop' into blockInterface
nisdas May 25, 2021
c2919f4
fix fuzz
nisdas May 25, 2021
6d9bee3
share common library
nisdas May 25, 2021
28cd19c
fix
nisdas May 26, 2021
19ee4d4
Merge branch 'develop' of https://github.com/prysmaticlabs/geth-shard…
nisdas May 26, 2021
27a91a1
fix
nisdas May 26, 2021
0c6ad93
add in more defensive nil checks
nisdas May 26, 2021
fc3e41b
add in more defensive nil checks
nisdas May 26, 2021
951192c
imports
nisdas May 26, 2021
5a706f8
Apply suggestions from code review
nisdas May 26, 2021
c550d68
Apply suggestions from code review
nisdas May 26, 2021
88b693d
Update shared/interfaces/block_interface.go
nisdas May 26, 2021
eec67cc
Update shared/interfaces/block_wrapper.go
nisdas May 26, 2021
cb6dd0b
Update shared/interfaces/block_interface.go
nisdas May 26, 2021
07ac83e
imports
nisdas May 26, 2021
19fb5b0
fix bad changes
nisdas May 26, 2021
c267677
fix
nisdas May 26, 2021
cda2757
Merge branch 'blockInterface' of https://github.com/prysmaticlabs/get…
nisdas May 26, 2021
eb05917
terence's review
nisdas May 26, 2021
2792b56
terence's review
nisdas May 26, 2021
778c6ca
Merge branch 'develop' into blockInterface
nisdas May 26, 2021
a4a684f
fmt
nisdas May 26, 2021
a259b9d
Merge branch 'blockInterface' of https://github.com/prysmaticlabs/get…
nisdas May 26, 2021
8c54db1
Update beacon-chain/rpc/beacon/blocks.go
nisdas May 26, 2021
86a3b0e
fix tests
nisdas May 26, 2021
33d3033
Merge branch 'blockInterface' of https://github.com/prysmaticlabs/get…
nisdas May 26, 2021
b380223
fix
nisdas May 26, 2021
0798bfe
fix all tests
nisdas May 26, 2021
ff3b8a2
Merge branch 'develop' into blockInterface
nisdas May 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion beacon-chain/blockchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ go_library(
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/powchain:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state/stateV0:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//cmd/beacon-chain/flags:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/attestationutil:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bls:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/interfaces:go_default_library",
"//shared/mputil:go_default_library",
"//shared/params:go_default_library",
"//shared/slotutil:go_default_library",
Expand Down Expand Up @@ -104,6 +105,7 @@ go_test(
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/powchain:go_default_library",
"//beacon-chain/state/stateV0:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//proto/beacon/db:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
Expand Down
17 changes: 9 additions & 8 deletions beacon-chain/blockchain/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/interfaces"
"github.com/prysmaticlabs/prysm/shared/params"
"go.opencensus.io/trace"
)
Expand Down Expand Up @@ -41,7 +42,7 @@ type GenesisFetcher interface {
type HeadFetcher interface {
HeadSlot() types.Slot
HeadRoot(ctx context.Context) ([]byte, error)
HeadBlock(ctx context.Context) (*ethpb.SignedBeaconBlock, error)
HeadBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error)
HeadState(ctx context.Context) (iface.BeaconState, error)
HeadValidatorsIndices(ctx context.Context, epoch types.Epoch) ([]types.ValidatorIndex, error)
HeadSeed(ctx context.Context, epoch types.Epoch) ([32]byte, error)
Expand Down Expand Up @@ -76,7 +77,7 @@ func (s *Service) FinalizedCheckpt() *ethpb.Checkpoint {
return &ethpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
}

return stateV0.CopyCheckpoint(s.finalizedCheckpt)
return blockutil.CopyCheckpoint(s.finalizedCheckpt)
}

// CurrentJustifiedCheckpt returns the current justified checkpoint from head state.
Expand All @@ -85,7 +86,7 @@ func (s *Service) CurrentJustifiedCheckpt() *ethpb.Checkpoint {
return &ethpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
}

return stateV0.CopyCheckpoint(s.justifiedCheckpt)
return blockutil.CopyCheckpoint(s.justifiedCheckpt)
}

// PreviousJustifiedCheckpt returns the previous justified checkpoint from head state.
Expand All @@ -94,7 +95,7 @@ func (s *Service) PreviousJustifiedCheckpt() *ethpb.Checkpoint {
return &ethpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
}

return stateV0.CopyCheckpoint(s.prevJustifiedCheckpt)
return blockutil.CopyCheckpoint(s.prevJustifiedCheckpt)
}

// HeadSlot returns the slot of the head of the chain.
Expand Down Expand Up @@ -123,11 +124,11 @@ func (s *Service) HeadRoot(ctx context.Context) ([]byte, error) {
if err != nil {
return nil, err
}
if b == nil {
if b == nil || b.IsNil() {
return params.BeaconConfig().ZeroHash[:], nil
}

r, err := b.Block.HashTreeRoot()
r, err := b.Block().HashTreeRoot()
if err != nil {
return nil, err
}
Expand All @@ -138,7 +139,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) (*ethpb.SignedBeaconBlock, error) {
func (s *Service) HeadBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error) {
s.headLock.RLock()
defer s.headLock.RUnlock()

Expand Down
3 changes: 2 additions & 1 deletion beacon-chain/blockchain/chain_info_norace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/shared/interfaces"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)

Expand Down Expand Up @@ -38,7 +39,7 @@ func TestHeadBlock_DataRace(t *testing.T) {
beaconDB := testDB.SetupDB(t)
s := &Service{
cfg: &Config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)},
head: &head{block: &ethpb.SignedBeaconBlock{}},
head: &head{block: interfaces.NewWrappedSignedBeaconBlock(&ethpb.SignedBeaconBlock{})},
}
go func() {
require.NoError(t, s.saveHead(context.Background(), [32]byte{}))
Expand Down
9 changes: 5 additions & 4 deletions beacon-chain/blockchain/chain_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/interfaces"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestHeadRoot_UseDB(t *testing.T) {
b := testutil.NewBeaconBlock()
br, err := b.Block.HashTreeRoot()
require.NoError(t, err)
require.NoError(t, beaconDB.SaveBlock(context.Background(), b))
require.NoError(t, beaconDB.SaveBlock(context.Background(), interfaces.NewWrappedSignedBeaconBlock(b)))
require.NoError(t, beaconDB.SaveStateSummary(context.Background(), &pb.StateSummary{Root: br[:]}))
require.NoError(t, beaconDB.SaveHeadBlockRoot(context.Background(), br))
r, err := c.HeadRoot(context.Background())
Expand All @@ -139,11 +140,11 @@ func TestHeadBlock_CanRetrieve(t *testing.T) {
s, err := stateV0.InitializeFromProto(&pb.BeaconState{})
require.NoError(t, err)
c := &Service{}
c.head = &head{block: b, state: s}
c.head = &head{block: interfaces.NewWrappedSignedBeaconBlock(b), state: s}

recevied, err := c.HeadBlock(context.Background())
require.NoError(t, err)
assert.DeepEqual(t, b, recevied, "Incorrect head block received")
assert.DeepEqual(t, b, recevied.Proto(), "Incorrect head block received")
}

func TestHeadState_CanRetrieve(t *testing.T) {
Expand Down Expand Up @@ -221,7 +222,7 @@ func TestIsCanonical_Ok(t *testing.T) {
blk.Block.Slot = 0
root, err := blk.Block.HashTreeRoot()
require.NoError(t, err)
require.NoError(t, beaconDB.SaveBlock(ctx, blk))
require.NoError(t, beaconDB.SaveBlock(ctx, interfaces.NewWrappedSignedBeaconBlock(blk)))
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, root))
can, err := c.IsCanonical(ctx, root)
require.NoError(t, err)
Expand Down
41 changes: 20 additions & 21 deletions beacon-chain/blockchain/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@ import (

"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/interfaces"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
)

// 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 *ethpb.SignedBeaconBlock // current head block.
state iface.BeaconState // current head state.
slot types.Slot // current head slot.
root [32]byte // current head root.
block interfaces.SignedBeaconBlock // current head block.
state iface.BeaconState // current head state.
}

// Determined the head from the fork choice service and saves its new data
Expand Down Expand Up @@ -64,7 +63,7 @@ func (s *Service) updateHead(ctx context.Context, balances []uint64) error {
return err
}
s.cfg.ForkChoiceStore = protoarray.New(j.Epoch, f.Epoch, bytesutil.ToBytes32(f.Root))
if err := s.insertBlockToForkChoiceStore(ctx, jb.Block, headStartRoot, f, j); err != nil {
if err := s.insertBlockToForkChoiceStore(ctx, jb.Block(), headStartRoot, f, j); err != nil {
return err
}
}
Expand Down Expand Up @@ -104,7 +103,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
if err != nil {
return err
}
if newHeadBlock == nil || newHeadBlock.Block == nil {
if newHeadBlock == nil || newHeadBlock.IsNil() || newHeadBlock.Block().IsNil() {
Copy link
Contributor

@rkapka rkapka May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this change?

func (w WrappedSignedBeaconBlock) IsNil() bool {
	return w.b == nil || w.Block() == nil || w.Block().IsNil()
}

It allows to write a single IsNil() check, and I am afraid most of the time the second check will be forgotten. You also never verify if w.Block() == nil in this PR (I don't either in my suggestions because this was an afterthought) and you already missed several w.Block().IsNil() checks. I'm sure this will happen more often. The downside is that we couple both checks together. Would we ever not care if the underlying beacon block is nil or not though?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal was to not add in additional nil block checks unless that particular function requires it. I have tried to strictly mimick existing behaviour and minimize any additional logic changes added into an already large PR. I just wanted to replace what were existing nil checks for a block struct with an interface. Adding in an inner block check would differ from what is the current behaviour (if signedBlock == nil) . We can add it in a follow up PR in that case, it would only be a one line change for both the SignedBeaconBlock and BeaconBlock.

return errors.New("cannot save nil head block")
}

Expand All @@ -119,15 +118,15 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {

// A chain re-org occurred, so we fire an event notifying the rest of the services.
headSlot := s.HeadSlot()
if bytesutil.ToBytes32(newHeadBlock.Block.ParentRoot) != bytesutil.ToBytes32(r) {
if bytesutil.ToBytes32(newHeadBlock.Block().ParentRoot()) != bytesutil.ToBytes32(r) {
log.WithFields(logrus.Fields{
"newSlot": fmt.Sprintf("%d", newHeadBlock.Block.Slot),
"newSlot": fmt.Sprintf("%d", newHeadBlock.Block().Slot()),
"oldSlot": fmt.Sprintf("%d", headSlot),
}).Debug("Chain reorg occurred")
s.cfg.StateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.Reorg,
Data: &statefeed.ReorgData{
NewSlot: newHeadBlock.Block.Slot,
NewSlot: newHeadBlock.Block().Slot(),
OldSlot: headSlot,
},
})
Expand All @@ -149,7 +148,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
// 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 *ethpb.SignedBeaconBlock, r [32]byte, hs iface.BeaconState) error {
func (s *Service) saveHeadNoDB(ctx context.Context, b interfaces.SignedBeaconBlock, r [32]byte, hs iface.BeaconState) error {
if err := helpers.VerifyNilBeaconBlock(b); err != nil {
return err
}
Expand All @@ -161,36 +160,36 @@ func (s *Service) saveHeadNoDB(ctx context.Context, b *ethpb.SignedBeaconBlock,
return nil
}

s.setHeadInitialSync(r, stateV0.CopySignedBeaconBlock(b), hs)
s.setHeadInitialSync(r, b.Copy(), hs)
return nil
}

// 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 *ethpb.SignedBeaconBlock, state iface.BeaconState) {
func (s *Service) setHead(root [32]byte, block interfaces.SignedBeaconBlock, state iface.BeaconState) {
s.headLock.Lock()
defer s.headLock.Unlock()

// This does a full copy of the block and state.
s.head = &head{
slot: block.Block.Slot,
slot: block.Block().Slot(),
root: root,
block: stateV0.CopySignedBeaconBlock(block),
block: block.Copy(),
state: state.Copy(),
}
}

// 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 *ethpb.SignedBeaconBlock, state iface.BeaconState) {
func (s *Service) setHeadInitialSync(root [32]byte, block interfaces.SignedBeaconBlock, state iface.BeaconState) {
s.headLock.Lock()
defer s.headLock.Unlock()

// This does a full copy of the block only.
s.head = &head{
slot: block.Block.Slot,
slot: block.Block().Slot(),
root: root,
block: stateV0.CopySignedBeaconBlock(block),
block: block.Copy(),
state: state,
}
}
Expand All @@ -215,8 +214,8 @@ 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() *ethpb.SignedBeaconBlock {
return stateV0.CopySignedBeaconBlock(s.head.block)
func (s *Service) headBlock() interfaces.SignedBeaconBlock {
return s.head.block.Copy()
}

// This returns the head state.
Expand Down
11 changes: 6 additions & 5 deletions beacon-chain/blockchain/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/interfaces"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
Expand Down Expand Up @@ -39,7 +40,7 @@ func TestSaveHead_Different(t *testing.T) {
newHeadSignedBlock.Block.Slot = 1
newHeadBlock := newHeadSignedBlock.Block

require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), newHeadSignedBlock))
require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), interfaces.NewWrappedSignedBeaconBlock(newHeadSignedBlock)))
newRoot, err := newHeadBlock.HashTreeRoot()
require.NoError(t, err)
headState, err := testutil.NewBeaconState()
Expand All @@ -54,7 +55,7 @@ func TestSaveHead_Different(t *testing.T) {
cachedRoot, err := service.HeadRoot(context.Background())
require.NoError(t, err)
assert.DeepEqual(t, cachedRoot, newRoot[:], "Head did not change")
assert.DeepEqual(t, newHeadSignedBlock, service.headBlock(), "Head did not change")
assert.DeepEqual(t, newHeadSignedBlock, service.headBlock().Proto(), "Head did not change")
assert.DeepSSZEqual(t, headState.CloneInnerState(), service.headState(ctx).CloneInnerState(), "Head did not change")
}

Expand All @@ -73,7 +74,7 @@ func TestSaveHead_Different_Reorg(t *testing.T) {
newHeadSignedBlock.Block.ParentRoot = reorgChainParent[:]
newHeadBlock := newHeadSignedBlock.Block

require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), newHeadSignedBlock))
require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), interfaces.NewWrappedSignedBeaconBlock(newHeadSignedBlock)))
newRoot, err := newHeadBlock.HashTreeRoot()
require.NoError(t, err)
headState, err := testutil.NewBeaconState()
Expand All @@ -90,7 +91,7 @@ func TestSaveHead_Different_Reorg(t *testing.T) {
if !bytes.Equal(cachedRoot, newRoot[:]) {
t.Error("Head did not change")
}
assert.DeepEqual(t, newHeadSignedBlock, service.headBlock(), "Head did not change")
assert.DeepEqual(t, newHeadSignedBlock, service.headBlock().Proto(), "Head did not change")
assert.DeepSSZEqual(t, headState.CloneInnerState(), service.headState(ctx).CloneInnerState(), "Head did not change")
require.LogsContain(t, hook, "Chain reorg occurred")
}
Expand All @@ -112,7 +113,7 @@ func TestUpdateHead_MissingJustifiedRoot(t *testing.T) {
service := setupBeaconChain(t, beaconDB)

b := testutil.NewBeaconBlock()
require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), b))
require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), interfaces.NewWrappedSignedBeaconBlock(b)))
r, err := b.Block.HashTreeRoot()
require.NoError(t, err)

Expand Down
3 changes: 2 additions & 1 deletion beacon-chain/blockchain/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/shared/interfaces"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
Expand Down Expand Up @@ -37,7 +38,7 @@ func TestService_TreeHandler(t *testing.T) {
require.NoError(t, err)
require.NoError(t, s.cfg.ForkChoiceStore.ProcessBlock(ctx, 0, [32]byte{'a'}, [32]byte{'g'}, [32]byte{'c'}, 0, 0))
require.NoError(t, s.cfg.ForkChoiceStore.ProcessBlock(ctx, 1, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'c'}, 0, 0))
s.setHead([32]byte{'a'}, testutil.NewBeaconBlock(), headState)
s.setHead([32]byte{'a'}, interfaces.NewWrappedSignedBeaconBlock(testutil.NewBeaconBlock()), headState)

rr := httptest.NewRecorder()
handler := http.HandlerFunc(s.TreeHandler)
Expand Down
12 changes: 6 additions & 6 deletions beacon-chain/blockchain/init_sync_process_block.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package blockchain

import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/interfaces"
)

// This saves a beacon block to the initial sync blocks cache.
func (s *Service) saveInitSyncBlock(r [32]byte, b *ethpb.SignedBeaconBlock) {
func (s *Service) saveInitSyncBlock(r [32]byte, b interfaces.SignedBeaconBlock) {
s.initSyncBlocksLock.Lock()
defer s.initSyncBlocksLock.Unlock()
s.initSyncBlocks[r] = b
Expand All @@ -22,7 +22,7 @@ func (s *Service) hasInitSyncBlock(r [32]byte) bool {

// This retrieves a beacon block from the initial sync blocks cache using the root of
// the block.
func (s *Service) getInitSyncBlock(r [32]byte) *ethpb.SignedBeaconBlock {
func (s *Service) getInitSyncBlock(r [32]byte) interfaces.SignedBeaconBlock {
s.initSyncBlocksLock.RLock()
defer s.initSyncBlocksLock.RUnlock()
b := s.initSyncBlocks[r]
Expand All @@ -31,11 +31,11 @@ func (s *Service) getInitSyncBlock(r [32]byte) *ethpb.SignedBeaconBlock {

// This retrieves all the beacon blocks from the initial sync blocks cache, the returned
// blocks are unordered.
func (s *Service) getInitSyncBlocks() []*ethpb.SignedBeaconBlock {
func (s *Service) getInitSyncBlocks() []interfaces.SignedBeaconBlock {
s.initSyncBlocksLock.RLock()
defer s.initSyncBlocksLock.RUnlock()

blks := make([]*ethpb.SignedBeaconBlock, 0, len(s.initSyncBlocks))
blks := make([]interfaces.SignedBeaconBlock, 0, len(s.initSyncBlocks))
for _, b := range s.initSyncBlocks {
blks = append(blks, b)
}
Expand All @@ -46,5 +46,5 @@ func (s *Service) getInitSyncBlocks() []*ethpb.SignedBeaconBlock {
func (s *Service) clearInitSyncBlocks() {
s.initSyncBlocksLock.Lock()
defer s.initSyncBlocksLock.Unlock()
s.initSyncBlocks = make(map[[32]byte]*ethpb.SignedBeaconBlock)
s.initSyncBlocks = make(map[[32]byte]interfaces.SignedBeaconBlock)
}
Loading