Skip to content

Commit

Permalink
Conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Nov 6, 2019
1 parent b20fc61 commit 03f2cb0
Show file tree
Hide file tree
Showing 126 changed files with 3,240 additions and 857 deletions.
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,26 @@ To understand the role that both the beacon node and validator play in Prysm, se
To start your beacon node, issue the following command:

```
docker run -v $HOME/prysm-data:/data -p 4000:4000 --name beacon-node \
docker run -v $HOME/prysm-data:/data -p 4000:4000 \
--name beacon-node \
gcr.io/prysmaticlabs/prysm/beacon-chain:latest \
--no-genesis-delay \
--datadir=/data
```

The beacon node can be halted by either using `Ctrl+c` or with the command:
(Optional) If you want to enable gRPC, then run this command instead of the one above:

```
docker run -v $HOME/prysm-data:/data -p 4000:4000 -p 7000:7000 \
--name beacon-node \
gcr.io/prysmaticlabs/prysm/beacon-chain:latest \
--datadir=/data \
--no-genesis-delay \
--grpc-gateway-port=7000
```

You can stop the beacon node using `Ctrl+c` or with the following command:
=======

```
docker stop beacon-node
Expand All @@ -121,13 +135,13 @@ To delete a corrupted container, issue the command:
docker rm beacon-node
```

To recreate a deleted container and refresh the chain database, issue the start command with an additional `--clear-db` parameter:
To recreate a deleted container and refresh the chain database, issue the start command with an additional `--force-clear-db` parameter:

```
docker run -it -v $HOME/prysm-data:/data -p 4000:4000 --name beacon-node \
gcr.io/prysmaticlabs/prysm/beacon-chain:latest \
--datadir=/data \
--clear-db
--force-clear-db
```

**Docker on Windows:**
Expand All @@ -142,14 +156,14 @@ docker run -it -v $HOME/prysm-data:/data -p 4000:4000 --name beacon-node \

4) To run the beacon node, issue the command:
```
docker run -it -v c:/tmp/prysm-data:/data -p 4000:4000 gcr.io/prysmaticlabs/prysm/beacon-chain:latest --datadir=/data --clear-db
docker run -it -v c:/tmp/prysm-data:/data -p 4000:4000 gcr.io/prysmaticlabs/prysm/beacon-chain:latest --datadir=/data
```

### Running via Bazel

1) To start your Beacon Node with Bazel, issue the command:
```
bazel run //beacon-chain -- --clear-db --datadir=/tmp/prysm-data
bazel run //beacon-chain -- --datadir=/tmp/prysm-data
```
This will sync up the Beacon Node with the latest head block in the network. Note that the beacon node must be **completely synced** before attempting to initialise a validator client, otherwise the validator will not be able to complete the deposit and funds will be lost.

Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ go_repository(

go_repository(
name = "grpc_ecosystem_grpc_gateway",
commit = "e652ba06e9067ef41c199af59b9c6c67724850d4",
commit = "da7a886035e25b2f274f89b6f3c64bf70a9f6780",
importpath = "github.com/grpc-ecosystem/grpc-gateway",
)

Expand Down Expand Up @@ -1201,7 +1201,7 @@ go_repository(

go_repository(
name = "com_github_prysmaticlabs_ethereumapis",
commit = "b4ca5785e074dd8fed39f18a61aae0318b57b4b0",
commit = "1205871db17ccc2fb824fc6dfa40d01c48fb6a7e",
importpath = "github.com/prysmaticlabs/ethereumapis",
)

Expand Down
6 changes: 6 additions & 0 deletions beacon-chain/blockchain/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,11 @@ func (s *Service) GenesisTime() time.Time {

// CurrentFork retrieves the latest fork information of the beacon chain.
func (s *Service) CurrentFork() *pb.Fork {
if s.headState == nil {
return &pb.Fork{
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
}
}
return proto.Clone(s.headState.Fork).(*pb.Fork)
}
23 changes: 17 additions & 6 deletions beacon-chain/blockchain/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,9 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database) *Service {
ctx := context.Background()
var web3Service *powchain.Service
var err error
client := &mockClient{}
web3Service, err = powchain.NewService(ctx, &powchain.Web3ServiceConfig{
Endpoint: endpoint,
ETH1Endpoint: endpoint,
DepositContract: common.Address{},
Reader: client,
Client: client,
Logger: client,
})
if err != nil {
t.Fatalf("unable to set up web3 service: %v", err)
Expand Down Expand Up @@ -354,13 +350,28 @@ func TestChainService_InitializeChainInfo(t *testing.T) {
defer testDB.TeardownDB(t, db)
ctx := context.Background()

genesis := b.NewGenesisBlock([]byte{})
genesisRoot, err := ssz.SigningRoot(genesis)
if err != nil {
t.Fatal(err)
}
if err := db.SaveGenesisBlockRoot(ctx, genesisRoot); err != nil {
t.Fatal(err)
}
if err := db.SaveBlock(ctx, genesis); err != nil {
t.Fatal(err)
}

finalizedSlot := params.BeaconConfig().SlotsPerEpoch*2 + 1
headBlock := &ethpb.BeaconBlock{Slot: finalizedSlot}
headBlock := &ethpb.BeaconBlock{Slot: finalizedSlot, ParentRoot: genesisRoot[:]}
headState := &pb.BeaconState{Slot: finalizedSlot}
headRoot, _ := ssz.SigningRoot(headBlock)
if err := db.SaveState(ctx, headState, headRoot); err != nil {
t.Fatal(err)
}
if err := db.SaveBlock(ctx, headBlock); err != nil {
t.Fatal(err)
}
if err := db.SaveFinalizedCheckpoint(ctx, &ethpb.Checkpoint{
Epoch: helpers.SlotToEpoch(finalizedSlot),
Root: headRoot[:],
Expand Down
4 changes: 4 additions & 0 deletions beacon-chain/blockchain/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//beacon-chain/db:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//proto/eth/v1alpha1:go_default_library",
"//shared/event:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)
27 changes: 27 additions & 0 deletions beacon-chain/blockchain/testing/mock.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package testing

import (
"bytes"
"context"
"time"

"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/sirupsen/logrus"
)

// ChainService defines the mock interface for testing
Expand All @@ -18,6 +23,8 @@ type ChainService struct {
StateFeed *event.Feed
BlocksReceived []*ethpb.BeaconBlock
Genesis time.Time
Fork *pb.Fork
DB db.Database
}

// ReceiveBlock mocks ReceiveBlock method in chain service.
Expand All @@ -40,8 +47,23 @@ func (ms *ChainService) ReceiveBlockNoPubsubForkchoice(ctx context.Context, bloc
if ms.State == nil {
ms.State = &pb.BeaconState{}
}
if !bytes.Equal(ms.Root, block.ParentRoot) {
return errors.Errorf("wanted %#x but got %#x", ms.Root, block.ParentRoot)
}
ms.State.Slot = block.Slot
ms.BlocksReceived = append(ms.BlocksReceived, block)
signingRoot, err := ssz.SigningRoot(block)
if err != nil {
return err
}
if ms.DB != nil {
if err := ms.DB.SaveBlock(ctx, block); err != nil {
return err
}
logrus.Infof("Saved block with root: %#x at slot %d", signingRoot, block.Slot)
}
ms.Root = signingRoot[:]
ms.Block = block
return nil
}

Expand All @@ -67,6 +89,11 @@ func (ms *ChainService) HeadState() *pb.BeaconState {
return ms.State
}

// CurrentFork mocks HeadState method in chain service.
func (ms *ChainService) CurrentFork() *pb.Fork {
return ms.Fork
}

// FinalizedCheckpt mocks FinalizedCheckpt method in chain service.
func (ms *ChainService) FinalizedCheckpt() *ethpb.Checkpoint {
return ms.FinalizedCheckPoint
Expand Down
4 changes: 4 additions & 0 deletions beacon-chain/cache/active_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -62,6 +63,9 @@ func NewActiveCountCache() *ActiveCountCache {
// ActiveCountInEpoch fetches ActiveCountByEpoch by epoch. Returns true with a
// reference to the ActiveCountInEpoch info, if exists. Otherwise returns false, nil.
func (c *ActiveCountCache) ActiveCountInEpoch(epoch uint64) (uint64, error) {
if !featureconfig.Get().EnableActiveCountCache {
return params.BeaconConfig().FarFutureEpoch, nil
}
c.lock.RLock()
defer c.lock.RUnlock()
obj, exists, err := c.activeCountCache.GetByKey(strconv.Itoa(int(epoch)))
Expand Down
4 changes: 4 additions & 0 deletions beacon-chain/cache/active_indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"k8s.io/client-go/tools/cache"
)

Expand Down Expand Up @@ -61,6 +62,9 @@ func NewActiveIndicesCache() *ActiveIndicesCache {
// ActiveIndicesInEpoch fetches ActiveIndicesByEpoch by epoch. Returns true with a
// reference to the ActiveIndicesInEpoch info, if exists. Otherwise returns false, nil.
func (c *ActiveIndicesCache) ActiveIndicesInEpoch(epoch uint64) ([]uint64, error) {
if !featureconfig.Get().EnableActiveIndicesCache {
return nil, nil
}
c.lock.RLock()
defer c.lock.RUnlock()
obj, exists, err := c.activeIndicesCache.GetByKey(strconv.Itoa(int(epoch)))
Expand Down
24 changes: 24 additions & 0 deletions beacon-chain/cache/committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/sliceutil"
"k8s.io/client-go/tools/cache"
)
Expand Down Expand Up @@ -66,6 +67,10 @@ func NewCommitteeCache() *CommitteeCache {
// ShuffledIndices fetches the shuffled indices by epoch and shard. Every list of indices
// represent one committee. Returns true if the list exists with epoch and shard. Otherwise returns false, nil.
func (c *CommitteeCache) ShuffledIndices(epoch uint64, index uint64) ([]uint64, error) {
if !featureconfig.Get().EnableShuffledIndexCache && !featureconfig.Get().EnableNewCache {
return nil, nil
}

c.lock.RLock()
defer c.lock.RUnlock()
obj, exists, err := c.CommitteeCache.GetByKey(strconv.Itoa(int(epoch)))
Expand All @@ -92,6 +97,9 @@ func (c *CommitteeCache) ShuffledIndices(epoch uint64, index uint64) ([]uint64,
// AddCommitteeShuffledList adds Committee shuffled list object to the cache. T
// his method also trims the least recently list if the cache size has ready the max cache size limit.
func (c *CommitteeCache) AddCommitteeShuffledList(committee *Committee) error {
if !featureconfig.Get().EnableShuffledIndexCache && !featureconfig.Get().EnableNewCache {
return nil
}
c.lock.Lock()
defer c.lock.Unlock()
if err := c.CommitteeCache.AddIfNotPresent(committee); err != nil {
Expand All @@ -103,6 +111,9 @@ func (c *CommitteeCache) AddCommitteeShuffledList(committee *Committee) error {

// Epochs returns the epochs stored in the committee cache. These are the keys to the cache.
func (c *CommitteeCache) Epochs() ([]uint64, error) {
if !featureconfig.Get().EnableShuffledIndexCache {
return nil, nil
}
c.lock.RLock()
defer c.lock.RUnlock()

Expand All @@ -119,6 +130,9 @@ func (c *CommitteeCache) Epochs() ([]uint64, error) {

// EpochInCache returns true if an input epoch is part of keys in cache.
func (c *CommitteeCache) EpochInCache(wantedEpoch uint64) (bool, error) {
if !featureconfig.Get().EnableShuffledIndexCache && !featureconfig.Get().EnableNewCache {
return false, nil
}
c.lock.RLock()
defer c.lock.RUnlock()

Expand All @@ -136,6 +150,9 @@ func (c *CommitteeCache) EpochInCache(wantedEpoch uint64) (bool, error) {

// CommitteeCount returns the total number of committees in a given epoch as stored in cache.
func (c *CommitteeCache) CommitteeCount(epoch uint64) (uint64, bool, error) {
if !featureconfig.Get().EnableShuffledIndexCache && !featureconfig.Get().EnableNewCache {
return 0, false, nil
}
c.lock.RLock()
defer c.lock.RUnlock()
obj, exists, err := c.CommitteeCache.GetByKey(strconv.Itoa(int(epoch)))
Expand All @@ -160,6 +177,9 @@ func (c *CommitteeCache) CommitteeCount(epoch uint64) (uint64, bool, error) {

// StartShard returns the start shard number in a given epoch as stored in cache.
func (c *CommitteeCache) StartShard(epoch uint64) (uint64, bool, error) {
if !featureconfig.Get().EnableShuffledIndexCache && !featureconfig.Get().EnableNewCache {
return 0, false, nil
}
c.lock.RLock()
defer c.lock.RUnlock()
obj, exists, err := c.CommitteeCache.GetByKey(strconv.Itoa(int(epoch)))
Expand All @@ -184,6 +204,10 @@ func (c *CommitteeCache) StartShard(epoch uint64) (uint64, bool, error) {

// ActiveIndices returns the active indices of a given epoch stored in cache.
func (c *CommitteeCache) ActiveIndices(epoch uint64) ([]uint64, error) {
if !featureconfig.Get().EnableShuffledIndexCache && !featureconfig.Get().EnableNewCache {
return nil, nil
}

c.lock.RLock()
defer c.lock.RUnlock()
obj, exists, err := c.CommitteeCache.GetByKey(strconv.Itoa(int(epoch)))
Expand Down
8 changes: 6 additions & 2 deletions beacon-chain/cache/feature_flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import "github.com/prysmaticlabs/prysm/shared/featureconfig"

func init() {
featureconfig.Init(&featureconfig.Flag{
EnableAttestationCache: true,
EnableEth1DataVoteCache: true,
EnableAttestationCache: true,
EnableEth1DataVoteCache: true,
EnableShuffledIndexCache: true,
EnableCommitteeCache: true,
EnableActiveCountCache: true,
EnableActiveIndicesCache: true,
})
}
7 changes: 7 additions & 0 deletions beacon-chain/cache/shuffled_indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"k8s.io/client-go/tools/cache"
)

Expand Down Expand Up @@ -62,6 +63,9 @@ func NewShuffledIndicesCache() *ShuffledIndicesCache {
// IndicesByIndexSeed fetches IndicesByIndexSeed by epoch and seed. Returns true with a
// reference to the ShuffledIndicesInEpoch info, if exists. Otherwise returns false, nil.
func (c *ShuffledIndicesCache) IndicesByIndexSeed(index uint64, seed []byte) ([]uint64, error) {
if !featureconfig.Get().EnableShuffledIndexCache {
return nil, nil
}
c.lock.RLock()
defer c.lock.RUnlock()
key := string(seed) + strconv.Itoa(int(index))
Expand All @@ -88,6 +92,9 @@ func (c *ShuffledIndicesCache) IndicesByIndexSeed(index uint64, seed []byte) ([]
// AddShuffledValidatorList adds IndicesByIndexSeed object to the cache. This method also trims the least
// recently added IndicesByIndexSeed object if the cache size has ready the max cache size limit.
func (c *ShuffledIndicesCache) AddShuffledValidatorList(shuffledIndices *IndicesByIndexSeed) error {
if !featureconfig.Get().EnableShuffledIndexCache {
return nil
}
c.lock.Lock()
defer c.lock.Unlock()
if err := c.shuffledIndicesCache.AddIfNotPresent(shuffledIndices); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions beacon-chain/cache/shuffled_indices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ import (
"reflect"
"strconv"
"testing"

"github.com/prysmaticlabs/prysm/shared/featureconfig"
)

func init() {
fc := featureconfig.Get()
fc.EnableShuffledIndexCache = true
featureconfig.Init(fc)
}

func TestShuffleKeyFn_OK(t *testing.T) {
sInfo := &IndicesByIndexSeed{
Index: 999,
Expand Down
Loading

0 comments on commit 03f2cb0

Please sign in to comment.