mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
Use Single Code Path for Receiving Blocks and Fork Choice (#2514)
* insert canonical * one path * single entry * travis * lint
This commit is contained in:
parent
a818564b8d
commit
4954ed0221
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ func init() {
|
||||
type chainService interface {
|
||||
StateInitializedFeed() *event.Feed
|
||||
blockchain.BlockReceiver
|
||||
blockchain.ForkChoice
|
||||
}
|
||||
|
||||
type operationService interface {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user