diff --git a/beacon-chain/blockchain/block_processing.go b/beacon-chain/blockchain/block_processing.go index f1da428a1..25310852d 100644 --- a/beacon-chain/blockchain/block_processing.go +++ b/beacon-chain/blockchain/block_processing.go @@ -28,7 +28,6 @@ type BlockReceiver interface { ReceiveBlock(ctx context.Context, block *pb.BeaconBlock) (*pb.BeaconState, error) IsCanonical(slot uint64, hash []byte) bool CanonicalBlock(slot uint64) (*pb.BeaconBlock, error) - InsertsCanonical(slot uint64, hash []byte) RecentCanonicalRoots(count uint64) []*pbrpc.BlockRoot } diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index baeb409fd..6d9ab8881 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -280,11 +280,3 @@ func (c *ChainService) RecentCanonicalRoots(count uint64) []*pbrpc.BlockRoot { } return blockRoots } - -// InsertsCanonical inserts a canonical block hash to its corresponding slot. -// This is used for testing purpose. -func (c *ChainService) InsertsCanonical(slot uint64, hash []byte) { - c.canonicalBlocksLock.Lock() - defer c.canonicalBlocksLock.Unlock() - c.canonicalBlocks[slot] = hash -} diff --git a/beacon-chain/rpc/proposer_server.go b/beacon-chain/rpc/proposer_server.go index eaa0ddb0c..062c5ecbc 100644 --- a/beacon-chain/rpc/proposer_server.go +++ b/beacon-chain/rpc/proposer_server.go @@ -14,7 +14,6 @@ import ( "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/sirupsen/logrus" ) // ProposerServer defines a server implementation of the gRPC Proposer service, @@ -80,18 +79,9 @@ func (ps *ProposerServer) ProposeBlock(ctx context.Context, blk *pbp2p.BeaconBlo if err != nil { return nil, fmt.Errorf("could not process beacon block: %v", err) } - if err := ps.beaconDB.UpdateChainHead(ctx, blk, beaconState); err != nil { + if err := ps.chainService.ApplyForkChoiceRule(ctx, blk, beaconState); err != nil { return nil, fmt.Errorf("failed to update chain: %v", err) } - log.WithFields(logrus.Fields{ - "headRoot": fmt.Sprintf("0x%x", bytesutil.Trunc(h[:])), - "headSlot": blk.Slot - params.BeaconConfig().GenesisSlot, - "stateSlot": beaconState.Slot - params.BeaconConfig().GenesisSlot, - }).Info("Chain head block and state updated") - - if err := ps.beaconDB.SaveHistoricalState(ctx, beaconState); err != nil { - log.Errorf("Could not save new historical state: %v", err) - } return &pb.ProposeResponse{BlockRootHash32: h[:]}, nil } diff --git a/beacon-chain/rpc/service.go b/beacon-chain/rpc/service.go index 712999cd8..0b27e0b68 100644 --- a/beacon-chain/rpc/service.go +++ b/beacon-chain/rpc/service.go @@ -36,6 +36,7 @@ func init() { type chainService interface { StateInitializedFeed() *event.Feed blockchain.BlockReceiver + blockchain.ForkChoice } type operationService interface { diff --git a/beacon-chain/rpc/service_test.go b/beacon-chain/rpc/service_test.go index d15b1463b..8a1db53dc 100644 --- a/beacon-chain/rpc/service_test.go +++ b/beacon-chain/rpc/service_test.go @@ -109,10 +109,6 @@ func (m mockChainService) IsCanonical(slot uint64, hash []byte) bool { return bytes.Equal(m.canonicalBlocks[slot], hash) } -func (m mockChainService) InsertsCanonical(slot uint64, hash []byte) { - m.canonicalBlocks[slot] = hash -} - func (m mockChainService) RecentCanonicalRoots(count uint64) []*pbrpc.BlockRoot { return nil } diff --git a/beacon-chain/sync/regular_sync_test.go b/beacon-chain/sync/regular_sync_test.go index 9c79d013b..138032e54 100644 --- a/beacon-chain/sync/regular_sync_test.go +++ b/beacon-chain/sync/regular_sync_test.go @@ -49,10 +49,9 @@ func (mp *mockP2P) Send(ctx context.Context, msg proto.Message, peerID peer.ID) } type mockChainService struct { - sFeed *event.Feed - cFeed *event.Feed - db *db.BeaconDB - canonicalBlocks map[uint64][]byte + sFeed *event.Feed + cFeed *event.Feed + db *db.BeaconDB } func (ms *mockChainService) StateInitializedFeed() *event.Feed { @@ -104,10 +103,6 @@ func (ms *mockChainService) RecentCanonicalRoots(count uint64) []*pbrpc.BlockRoo return nil } -func (ms mockChainService) InsertsCanonical(slot uint64, hash []byte) { - ms.canonicalBlocks[slot] = hash -} - type mockOperationService struct{} func (ms *mockOperationService) IncomingProcessedBlockFeed() *event.Feed {