mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
beacon: Initial Beacon P2P Protobufs, Subscriptions (#327)
This commit is contained in:
@@ -4,14 +4,15 @@ http_archive(
|
||||
name = "io_bazel_rules_go",
|
||||
# in order to be able to enable race detection we need to use a version
|
||||
# < 0.13.0 until this bug is fixed: https://github.com/bazelbuild/rules_go/issues/1592
|
||||
# We are using 0.12 here until bazelbuild/bazel-gazelle#272 is resolved, as we cannot import
|
||||
# protobuf/ptypes normally until this issue is fixed
|
||||
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.12.1/rules_go-0.12.1.tar.gz"],
|
||||
sha256 = "8b68d0630d63d95dacc0016c3bb4b76154fe34fca93efd65d1c366de3fcb4294",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "bazel_gazelle",
|
||||
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.13.0/bazel-gazelle-0.13.0.tar.gz"],
|
||||
sha256 = "bc653d3e058964a5a26dcad02b6c72d7d63e6bb88d94704990b908a1445b8758",
|
||||
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.12.0/bazel-gazelle-0.12.0.tar.gz"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package blockchain
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"hash"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -13,7 +11,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/params"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -90,7 +87,7 @@ func (b *BeaconChain) ExitedValidatorCount() int {
|
||||
}
|
||||
|
||||
// GenesisBlock returns the canonical, genesis block.
|
||||
func (b *BeaconChain) GenesisBlock() *types.Block {
|
||||
func (b *BeaconChain) GenesisBlock() (*types.Block, error) {
|
||||
return types.NewGenesisBlock()
|
||||
}
|
||||
|
||||
@@ -111,8 +108,8 @@ func (b *BeaconChain) MutateCrystallizedState(crystallizedState *types.Crystalli
|
||||
}
|
||||
|
||||
// CanProcessBlock decides if an incoming p2p block can be processed into the chain's block trie.
|
||||
func (b *BeaconChain) CanProcessBlock(fetcher powchain.POWBlockFetcher, block *types.Block) (bool, error) {
|
||||
mainchainBlock, err := fetcher.BlockByHash(context.Background(), block.Data().MainChainRef)
|
||||
func (b *BeaconChain) CanProcessBlock(fetcher types.POWBlockFetcher, block *types.Block) (bool, error) {
|
||||
mainchainBlock, err := fetcher.BlockByHash(context.Background(), block.MainChainRef())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -123,26 +120,42 @@ func (b *BeaconChain) CanProcessBlock(fetcher powchain.POWBlockFetcher, block *t
|
||||
// TODO: check if the parentHash pointed by the beacon block is in the beaconDB.
|
||||
|
||||
// Calculate the timestamp validity condition.
|
||||
slotDuration := time.Duration(block.Data().SlotNumber*params.SlotLength) * time.Second
|
||||
validTime := time.Now().After(b.GenesisBlock().Data().Timestamp.Add(slotDuration))
|
||||
slotDuration := time.Duration(block.SlotNumber()*params.SlotLength) * time.Second
|
||||
genesis, err := b.GenesisBlock()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
genesisTime, err := genesis.Timestamp()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Verify state hashes from the block are correct
|
||||
hash, err := hashActiveState(*b.ActiveState())
|
||||
hash, err := hashActiveState(b.ActiveState())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if !bytes.Equal(block.Data().ActiveStateHash.Sum(nil), hash.Sum(nil)) {
|
||||
return false, fmt.Errorf("Active state hash mismatched, wanted: %v, got: %v", hash.Sum(nil), block.Data().ActiveStateHash.Sum(nil))
|
||||
blockActiveStateHash := block.ActiveStateHash()
|
||||
|
||||
if blockActiveStateHash != hash {
|
||||
return false, fmt.Errorf("active state hash mismatched, wanted: %v, got: %v", blockActiveStateHash, hash)
|
||||
}
|
||||
hash, err = hashCrystallizedState(*b.CrystallizedState())
|
||||
|
||||
hash, err = hashCrystallizedState(b.CrystallizedState())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !bytes.Equal(block.Data().CrystallizedStateHash.Sum(nil), hash.Sum(nil)) {
|
||||
return false, fmt.Errorf("Crystallized state hash mismatched, wanted: %v, got: %v", hash.Sum(nil), block.Data().CrystallizedStateHash.Sum(nil))
|
||||
|
||||
blockCrystallizedStateHash := block.CrystallizedStateHash()
|
||||
|
||||
if blockCrystallizedStateHash != hash {
|
||||
return false, fmt.Errorf("crystallized state hash mismatched, wanted: %v, got: %v", blockCrystallizedStateHash, hash)
|
||||
}
|
||||
|
||||
validTime := time.Now().After(genesisTime.Add(slotDuration))
|
||||
|
||||
return validTime, nil
|
||||
}
|
||||
|
||||
@@ -222,22 +235,22 @@ func (b *BeaconChain) computeNewActiveState(seed common.Hash) (*types.ActiveStat
|
||||
|
||||
// hashActiveState serializes the active state object then uses
|
||||
// blake2b to hash the serialized object.
|
||||
func hashActiveState(state types.ActiveState) (hash.Hash, error) {
|
||||
func hashActiveState(state *types.ActiveState) ([32]byte, error) {
|
||||
serializedState, err := rlp.EncodeToBytes(state)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return [32]byte{}, err
|
||||
}
|
||||
return blake2b.New256(serializedState)
|
||||
return blake2b.Sum256(serializedState), nil
|
||||
}
|
||||
|
||||
// hashCrystallizedState serializes the crystallized state object
|
||||
// then uses blake2b to hash the serialized object.
|
||||
func hashCrystallizedState(state types.CrystallizedState) (hash.Hash, error) {
|
||||
func hashCrystallizedState(state *types.CrystallizedState) ([32]byte, error) {
|
||||
serializedState, err := rlp.EncodeToBytes(state)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return [32]byte{}, err
|
||||
}
|
||||
return blake2b.New256(serializedState)
|
||||
return blake2b.Sum256(serializedState), nil
|
||||
}
|
||||
|
||||
// getAttestersProposer returns lists of random sampled attesters and proposer indices.
|
||||
|
||||
@@ -199,18 +199,18 @@ func TestCanProcessBlock(t *testing.T) {
|
||||
activeState := &types.ActiveState{TotalAttesterDeposits: 10000}
|
||||
beaconChain.state.ActiveState = activeState
|
||||
|
||||
activeHash, err := hashActiveState(*activeState)
|
||||
activeHash, err := hashActiveState(activeState)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot hash active state: %v", err)
|
||||
}
|
||||
|
||||
block.InsertActiveHash(activeHash)
|
||||
|
||||
crystallizedHash, err := hashCrystallizedState(types.CrystallizedState{})
|
||||
crystallizedHash, err := hashCrystallizedState(&types.CrystallizedState{})
|
||||
if err != nil {
|
||||
t.Fatalf("Compute crystallized state hash failed: %v", err)
|
||||
}
|
||||
block.InsertCrystallizedHash(crystallizedHash)
|
||||
|
||||
canProcess, err := beaconChain.CanProcessBlock(&mockFetcher{}, block)
|
||||
if err != nil {
|
||||
t.Fatalf("CanProcessBlocks failed: %v", err)
|
||||
@@ -248,7 +248,7 @@ func TestProcessBlockWithBadHashes(t *testing.T) {
|
||||
// Test negative scenario where active state hash is different than node's compute
|
||||
block := types.NewBlock(1)
|
||||
activeState := &types.ActiveState{TotalAttesterDeposits: 10000}
|
||||
stateHash, err := hashActiveState(*activeState)
|
||||
stateHash, err := hashActiveState(activeState)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot hash active state: %v", err)
|
||||
}
|
||||
@@ -266,7 +266,7 @@ func TestProcessBlockWithBadHashes(t *testing.T) {
|
||||
|
||||
// Test negative scenario where crystallized state hash is different than node's compute
|
||||
crystallizedState := &types.CrystallizedState{CurrentEpoch: 10000}
|
||||
stateHash, err = hashCrystallizedState(*crystallizedState)
|
||||
stateHash, err = hashCrystallizedState(crystallizedState)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot hash crystallized state: %v", err)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package blockchain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hash"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/database"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
||||
@@ -21,13 +20,14 @@ type ChainService struct {
|
||||
chain *BeaconChain
|
||||
web3Service *powchain.Web3Service
|
||||
latestBeaconBlock chan *types.Block
|
||||
processedHashes [][32]byte
|
||||
}
|
||||
|
||||
// NewChainService instantiates a new service instance that will
|
||||
// be registered into a running beacon node.
|
||||
func NewChainService(ctx context.Context, beaconDB *database.BeaconDB, web3Service *powchain.Web3Service) (*ChainService, error) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
return &ChainService{ctx, cancel, beaconDB, nil, web3Service, nil}, nil
|
||||
return &ChainService{ctx, cancel, beaconDB, nil, web3Service, nil, nil}, nil
|
||||
}
|
||||
|
||||
// Start a blockchain service's main event loop.
|
||||
@@ -49,6 +49,11 @@ func (c *ChainService) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProcessedHashes by the chain service.
|
||||
func (c *ChainService) ProcessedHashes() [][32]byte {
|
||||
return c.processedHashes
|
||||
}
|
||||
|
||||
// ProcessBlock accepts a new block for inclusion in the chain.
|
||||
func (c *ChainService) ProcessBlock(b *types.Block) error {
|
||||
c.latestBeaconBlock <- b
|
||||
@@ -57,7 +62,7 @@ func (c *ChainService) ProcessBlock(b *types.Block) error {
|
||||
|
||||
// ContainsBlock checks if a block for the hash exists in the chain.
|
||||
// This method must be safe to call from a goroutine
|
||||
func (c *ChainService) ContainsBlock(h hash.Hash) bool {
|
||||
func (c *ChainService) ContainsBlock(h [32]byte) bool {
|
||||
// TODO
|
||||
return false
|
||||
}
|
||||
@@ -67,7 +72,8 @@ func (c *ChainService) updateActiveState() {
|
||||
for {
|
||||
select {
|
||||
case block := <-c.latestBeaconBlock:
|
||||
log.WithFields(logrus.Fields{"activeStateHash": block.Data().ActiveStateHash}).Debug("Received beacon block")
|
||||
activeStateHash := block.ActiveStateHash()
|
||||
log.WithFields(logrus.Fields{"activeStateHash": activeStateHash}).Debug("Received beacon block")
|
||||
|
||||
// TODO: Using latest block hash for seed, this will eventually be replaced by randao
|
||||
activeState, err := c.chain.computeNewActiveState(c.web3Service.LatestBlockHash())
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestStartStop(t *testing.T) {
|
||||
}
|
||||
db.Start()
|
||||
endpoint := "ws://127.0.0.1"
|
||||
web3Service, err := powchain.NewWeb3Service(ctx, &powchain.Web3ServiceConfig{endpoint, "", common.Address{}})
|
||||
web3Service, err := powchain.NewWeb3Service(ctx, &powchain.Web3ServiceConfig{Endpoint: endpoint, Pubkey: "", VrcAddr: common.Address{}})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to set up web3 service: %v", err)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func TestStartStop(t *testing.T) {
|
||||
}
|
||||
|
||||
msg := hook.AllEntries()[0].Message
|
||||
want := "Starting beaconDB service"
|
||||
want := "Starting service"
|
||||
if msg != want {
|
||||
t.Errorf("incorrect log, expected %s, got %s", want, msg)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func NewBeaconDB(config *BeaconDBConfig) (*BeaconDB, error) {
|
||||
|
||||
// Start the beacon DB service.
|
||||
func (b *BeaconDB) Start() {
|
||||
log.Info("Starting beaconDB service")
|
||||
log.Info("Starting service")
|
||||
if !b.inmemory {
|
||||
db, err := ethdb.NewLDBDatabase(filepath.Join(b.dataDir, b.name), b.cache, b.handles)
|
||||
if err != nil {
|
||||
@@ -64,7 +64,7 @@ func (b *BeaconDB) Start() {
|
||||
|
||||
// Stop the beaconDB service gracefully.
|
||||
func (b *BeaconDB) Stop() error {
|
||||
log.Info("Stopping beaconDB service")
|
||||
log.Info("Stopping service")
|
||||
b.db.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ func TestLifecycle(t *testing.T) {
|
||||
|
||||
b.Start()
|
||||
msg := hook.LastEntry().Message
|
||||
if msg != "Starting beaconDB service" {
|
||||
if msg != "Starting service" {
|
||||
t.Errorf("incorrect log, expected %s, got %s", "Starting beaconDB service", msg)
|
||||
}
|
||||
|
||||
b.Stop()
|
||||
msg = hook.LastEntry().Message
|
||||
if msg != "Stopping beaconDB service" {
|
||||
if msg != "Stopping service" {
|
||||
t.Errorf("incorrect log, expected %s, got %s", "Stopping beaconDB service", msg)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["service.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/network",
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/types:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -1,62 +0,0 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"hash"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "network")
|
||||
|
||||
// Service is the middleware between the application-agnostic p2p service and subscribers to the network.
|
||||
type Service struct {
|
||||
syncService SyncService
|
||||
}
|
||||
|
||||
// SyncService is the interface for the sync service.
|
||||
type SyncService interface {
|
||||
ReceiveBlockHash(hash.Hash)
|
||||
ReceiveBlock(*types.Block) error
|
||||
}
|
||||
|
||||
// NewNetworkService instantiates a new network service.
|
||||
func NewNetworkService() *Service {
|
||||
return &Service{}
|
||||
}
|
||||
|
||||
// SetSyncService sets a concrete value for the sync service.
|
||||
func (ns *Service) SetSyncService(ss SyncService) {
|
||||
ns.syncService = ss
|
||||
}
|
||||
|
||||
// Start launches the service's goroutine.
|
||||
func (ns *Service) Start() {
|
||||
log.Info("Starting service")
|
||||
go run()
|
||||
}
|
||||
|
||||
// Stop kills the service's goroutine (unimplemented).
|
||||
func (ns *Service) Stop() error {
|
||||
log.Info("Stopping service")
|
||||
return nil
|
||||
}
|
||||
|
||||
// BroadcastBlockHash sends the block hash to other peers in the network.
|
||||
func (ns *Service) BroadcastBlockHash(h hash.Hash) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BroadcastBlock sends the block to other peers in the network.
|
||||
func (ns *Service) BroadcastBlock(b *types.Block) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RequestBlock requests the contents of the block given the block hash.
|
||||
func (ns *Service) RequestBlock(hash.Hash) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func run() {
|
||||
select {}
|
||||
}
|
||||
@@ -8,13 +8,13 @@ go_library(
|
||||
deps = [
|
||||
"//beacon-chain/blockchain:go_default_library",
|
||||
"//beacon-chain/database:go_default_library",
|
||||
"//beacon-chain/network:go_default_library",
|
||||
"//beacon-chain/powchain:go_default_library",
|
||||
"//beacon-chain/sync:go_default_library",
|
||||
"//beacon-chain/utils:go_default_library",
|
||||
"//shared:go_default_library",
|
||||
"//shared/cmd:go_default_library",
|
||||
"//shared/debug:go_default_library",
|
||||
"//shared/p2p:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/database"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/network"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
||||
rbcSync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
|
||||
rbcsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/utils"
|
||||
"github.com/prysmaticlabs/prysm/shared"
|
||||
"github.com/prysmaticlabs/prysm/shared/cmd"
|
||||
"github.com/prysmaticlabs/prysm/shared/debug"
|
||||
"github.com/prysmaticlabs/prysm/shared/p2p"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@@ -51,6 +51,10 @@ func New(ctx *cli.Context) (*BeaconNode, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := beacon.registerP2P(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := beacon.registerPOWChainService(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -59,10 +63,6 @@ func New(ctx *cli.Context) (*BeaconNode, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := beacon.registerNetworkService(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := beacon.registerSyncService(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -121,6 +121,14 @@ func (b *BeaconNode) registerBeaconDB(path string) error {
|
||||
return b.services.RegisterService(beaconDB)
|
||||
}
|
||||
|
||||
func (b *BeaconNode) registerP2P() error {
|
||||
beaconp2p, err := p2p.NewServer()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not register p2p service: %v", err)
|
||||
}
|
||||
return b.services.RegisterService(beaconp2p)
|
||||
}
|
||||
|
||||
func (b *BeaconNode) registerBlockchainService() error {
|
||||
var beaconDB *database.BeaconDB
|
||||
if err := b.services.FetchService(&beaconDB); err != nil {
|
||||
@@ -151,24 +159,13 @@ func (b *BeaconNode) registerPOWChainService() error {
|
||||
return b.services.RegisterService(web3Service)
|
||||
}
|
||||
|
||||
func (b *BeaconNode) registerNetworkService() error {
|
||||
networkService := network.NewNetworkService()
|
||||
|
||||
return b.services.RegisterService(networkService)
|
||||
}
|
||||
|
||||
func (b *BeaconNode) registerSyncService() error {
|
||||
var chainService *blockchain.ChainService
|
||||
b.services.FetchService(&chainService)
|
||||
|
||||
var networkService *network.Service
|
||||
b.services.FetchService(&networkService)
|
||||
|
||||
syncService := rbcSync.NewSyncService(context.Background(), rbcSync.DefaultConfig())
|
||||
syncService.SetChainService(chainService)
|
||||
syncService.SetNetworkService(networkService)
|
||||
|
||||
networkService.SetSyncService(syncService)
|
||||
var p2pService *p2p.Server
|
||||
b.services.FetchService(&p2pService)
|
||||
|
||||
syncService := rbcsync.NewSyncService(context.Background(), rbcsync.DefaultConfig(), p2pService, chainService)
|
||||
return b.services.RegisterService(syncService)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/powchain",
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/types:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
|
||||
|
||||
@@ -11,26 +11,12 @@ import (
|
||||
gethTypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "powchain")
|
||||
|
||||
// Reader defines a struct that can fetch latest header events from a web3 endpoint.
|
||||
type Reader interface {
|
||||
SubscribeNewHead(ctx context.Context, ch chan<- *gethTypes.Header) (ethereum.Subscription, error)
|
||||
}
|
||||
|
||||
// POWBlockFetcher defines a struct that can retrieve mainchain blocks.
|
||||
type POWBlockFetcher interface {
|
||||
BlockByHash(ctx context.Context, hash common.Hash) (*gethTypes.Block, error)
|
||||
}
|
||||
|
||||
// Logger subscribe filtered log on the PoW chain
|
||||
type Logger interface {
|
||||
SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- gethTypes.Log) (ethereum.Subscription, error)
|
||||
}
|
||||
|
||||
// Web3Service fetches important information about the canonical
|
||||
// Ethereum PoW chain via a web3 endpoint using an ethclient. The Random
|
||||
// Beacon Chain requires synchronization with the PoW chain's current
|
||||
@@ -82,7 +68,7 @@ func NewWeb3Service(ctx context.Context, config *Web3ServiceConfig) (*Web3Servic
|
||||
func (w *Web3Service) Start() {
|
||||
log.WithFields(logrus.Fields{
|
||||
"endpoint": w.endpoint,
|
||||
}).Info("Starting web3 proof-of-work chain service")
|
||||
}).Info("Starting service")
|
||||
rpcClient, err := rpc.Dial(w.endpoint)
|
||||
if err != nil {
|
||||
log.Errorf("Cannot connect to PoW chain RPC client: %v", err)
|
||||
@@ -96,11 +82,11 @@ func (w *Web3Service) Start() {
|
||||
func (w *Web3Service) Stop() error {
|
||||
defer w.cancel()
|
||||
defer close(w.headerChan)
|
||||
log.Info("Stopping web3 proof-of-work chain service")
|
||||
log.Info("Stopping service")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *Web3Service) fetchChainInfo(ctx context.Context, reader Reader, logger Logger) {
|
||||
func (w *Web3Service) fetchChainInfo(ctx context.Context, reader types.Reader, logger types.Logger) {
|
||||
if _, err := reader.SubscribeNewHead(w.ctx, w.headerChan); err != nil {
|
||||
log.Errorf("Unable to subscribe to incoming PoW chain headers: %v", err)
|
||||
return
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestStop(t *testing.T) {
|
||||
}
|
||||
|
||||
msg := hook.LastEntry().Message
|
||||
want := "Stopping web3 proof-of-work chain service"
|
||||
want := "Stopping service"
|
||||
if msg != want {
|
||||
t.Errorf("incorrect log, expected %s, got %s", want, msg)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ go_library(
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/types:go_default_library",
|
||||
"//proto/sharding/v1:go_default_library",
|
||||
"//shared/p2p:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -17,8 +19,11 @@ go_test(
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//beacon-chain/types:go_default_library",
|
||||
"//proto/sharding/v1:go_default_library",
|
||||
"//shared/p2p:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//event:go_default_library",
|
||||
"@com_github_minio_blake2b_simd//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
"@org_golang_x_crypto//blake2b:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -2,9 +2,11 @@ package sync
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hash"
|
||||
"fmt"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/types"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/sharding/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/p2p"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -23,63 +25,42 @@ var log = logrus.WithField("prefix", "sync")
|
||||
// * Drop peers that send invalid data
|
||||
// * Trottle incoming requests
|
||||
type Service struct {
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
networkService NetworkService
|
||||
chainService ChainService
|
||||
hashBuf chan hash.Hash
|
||||
blockBuf chan *types.Block
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
p2p types.P2P
|
||||
chainService types.ChainService
|
||||
announceBlockHashBuf chan p2p.Message
|
||||
blockBuf chan p2p.Message
|
||||
}
|
||||
|
||||
// Config allows the channel's buffer sizes to be changed
|
||||
// Config allows the channel's buffer sizes to be changed.
|
||||
type Config struct {
|
||||
HashBufferSize int
|
||||
BlockBufferSize int
|
||||
}
|
||||
|
||||
// DefaultConfig provides the default configuration for a sync service
|
||||
// DefaultConfig provides the default configuration for a sync service.
|
||||
func DefaultConfig() Config {
|
||||
return Config{100, 100}
|
||||
}
|
||||
|
||||
// NetworkService is the interface for the p2p network.
|
||||
type NetworkService interface {
|
||||
BroadcastBlockHash(hash.Hash) error
|
||||
BroadcastBlock(*types.Block) error
|
||||
RequestBlock(hash.Hash) error
|
||||
}
|
||||
|
||||
// ChainService is the interface for the local beacon chain.
|
||||
type ChainService interface {
|
||||
ProcessBlock(*types.Block) error
|
||||
ContainsBlock(hash.Hash) bool
|
||||
}
|
||||
|
||||
// NewSyncService accepts a context and returns a new Service.
|
||||
func NewSyncService(ctx context.Context, cfg Config) *Service {
|
||||
func NewSyncService(ctx context.Context, cfg Config, beaconp2p types.P2P, cs types.ChainService) *Service {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
return &Service{
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
hashBuf: make(chan hash.Hash, cfg.HashBufferSize),
|
||||
blockBuf: make(chan *types.Block, cfg.BlockBufferSize),
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
p2p: beaconp2p,
|
||||
chainService: cs,
|
||||
announceBlockHashBuf: make(chan p2p.Message, cfg.HashBufferSize),
|
||||
blockBuf: make(chan p2p.Message, cfg.BlockBufferSize),
|
||||
}
|
||||
}
|
||||
|
||||
// SetNetworkService sets a concrete value for the p2p layer.
|
||||
func (ss *Service) SetNetworkService(ps NetworkService) {
|
||||
ss.networkService = ps
|
||||
}
|
||||
|
||||
// SetChainService sets a concrete value for the local beacon chain.
|
||||
func (ss *Service) SetChainService(cs ChainService) {
|
||||
ss.chainService = cs
|
||||
}
|
||||
|
||||
// Start begins the block processing goroutine.
|
||||
func (ss *Service) Start() {
|
||||
log.Info("Starting service")
|
||||
go run(ss.ctx.Done(), ss.hashBuf, ss.blockBuf, ss.networkService, ss.chainService)
|
||||
go ss.run(ss.ctx.Done())
|
||||
}
|
||||
|
||||
// Stop kills the block processing goroutine, but does not wait until the goroutine exits.
|
||||
@@ -92,43 +73,69 @@ func (ss *Service) Stop() error {
|
||||
// ReceiveBlockHash accepts a block hash.
|
||||
// New hashes are forwarded to other peers in the network (unimplemented), and
|
||||
// the contents of the block are requested if the local chain doesn't have the block.
|
||||
func (ss *Service) ReceiveBlockHash(h hash.Hash) {
|
||||
func (ss *Service) ReceiveBlockHash(data *pb.BeaconBlockHashAnnounce) error {
|
||||
var h [32]byte
|
||||
copy(h[:], data.Hash[:32])
|
||||
if ss.chainService.ContainsBlock(h) {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
ss.hashBuf <- h
|
||||
ss.networkService.BroadcastBlockHash(h)
|
||||
log.Info("Requesting full block data from sender")
|
||||
// TODO: Request the full block data from peer that sent the block hash.
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReceiveBlock accepts a block to potentially be included in the local chain.
|
||||
// The service will filter blocks that have not been requested (unimplemented).
|
||||
func (ss *Service) ReceiveBlock(b *types.Block) error {
|
||||
h, err := b.Hash()
|
||||
func (ss *Service) ReceiveBlock(data *pb.BeaconBlockResponse) error {
|
||||
block, err := types.NewBlockWithData(data)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("could not instantiate new block from proto: %v", err)
|
||||
}
|
||||
h, err := block.Hash()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not hash block: %v", err)
|
||||
}
|
||||
|
||||
if ss.chainService.ContainsBlock(h) {
|
||||
return nil
|
||||
}
|
||||
|
||||
ss.blockBuf <- b
|
||||
ss.networkService.BroadcastBlock(b)
|
||||
|
||||
log.Infof("Broadcasting block hash to peers: %x", h)
|
||||
ss.p2p.Broadcast(&pb.BeaconBlockHashAnnounce{
|
||||
Hash: h[:],
|
||||
})
|
||||
ss.chainService.ProcessBlock(block)
|
||||
return nil
|
||||
}
|
||||
|
||||
func run(done <-chan struct{}, hashBuf <-chan hash.Hash, blockBuf <-chan *types.Block, ps NetworkService, cs ChainService) {
|
||||
func (ss *Service) run(done <-chan struct{}) {
|
||||
announceBlockHashSub := ss.p2p.Feed(pb.BeaconBlockHashAnnounce{}).Subscribe(ss.announceBlockHashBuf)
|
||||
blockSub := ss.p2p.Feed(pb.BeaconBlockResponse{}).Subscribe(ss.blockBuf)
|
||||
defer announceBlockHashSub.Unsubscribe()
|
||||
defer blockSub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
log.Infof("exiting goroutine")
|
||||
log.Infof("Exiting goroutine")
|
||||
return
|
||||
case h := <-hashBuf:
|
||||
ps.RequestBlock(h)
|
||||
case b := <-blockBuf:
|
||||
cs.ProcessBlock(b)
|
||||
case msg := <-ss.announceBlockHashBuf:
|
||||
data, ok := msg.Data.(pb.BeaconBlockHashAnnounce)
|
||||
// TODO: Handle this at p2p layer.
|
||||
if !ok {
|
||||
log.Error("Received malformed beacon block hash announcement p2p message")
|
||||
continue
|
||||
}
|
||||
if err := ss.ReceiveBlockHash(&data); err != nil {
|
||||
log.Errorf("Could not receive incoming block hash: %v", err)
|
||||
}
|
||||
case msg := <-ss.blockBuf:
|
||||
data, ok := msg.Data.(pb.BeaconBlockResponse)
|
||||
// TODO: Handle this at p2p layer.
|
||||
if !ok {
|
||||
log.Errorf("Received malformed beacon block p2p message")
|
||||
continue
|
||||
}
|
||||
if err := ss.ReceiveBlock(&data); err != nil {
|
||||
log.Errorf("Could not receive incoming block: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,231 +1,248 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"hash"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
blake2b "github.com/minio/blake2b-simd"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/types"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/sharding/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/p2p"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
"golang.org/x/crypto/blake2b"
|
||||
)
|
||||
|
||||
var testLog = log.WithField("prefix", "sync_test")
|
||||
type mockP2P struct{}
|
||||
|
||||
type MockNetworkService struct{}
|
||||
|
||||
func (ns *MockNetworkService) BroadcastBlockHash(h hash.Hash) error {
|
||||
testLog.Infof("broadcasting hash: %x", h.Sum(nil))
|
||||
return nil
|
||||
func (mp *mockP2P) Feed(msg interface{}) *event.Feed {
|
||||
return new(event.Feed)
|
||||
}
|
||||
|
||||
func (ns *MockNetworkService) BroadcastBlock(b *types.Block) error {
|
||||
func (mp *mockP2P) Broadcast(msg interface{}) {}
|
||||
|
||||
type mockChainService struct {
|
||||
processedHashes [][32]byte
|
||||
}
|
||||
|
||||
func (ms *mockChainService) ProcessBlock(b *types.Block) error {
|
||||
h, err := b.Hash()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
testLog.Infof("broadcasting block: %x", h.Sum(nil))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ns *MockNetworkService) RequestBlock(h hash.Hash) error {
|
||||
testLog.Infof("requesting block: %x", h.Sum(nil))
|
||||
return nil
|
||||
}
|
||||
|
||||
// MockChainService implements a simplified local chain that stores blocks in a slice
|
||||
type MockChainService struct {
|
||||
processedHashes []hash.Hash
|
||||
}
|
||||
|
||||
func (ms *MockChainService) ProcessBlock(b *types.Block) error {
|
||||
h, err := b.Hash()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
testLog.Infof("forwarding block: %x", h.Sum(nil))
|
||||
if ms.processedHashes == nil {
|
||||
ms.processedHashes = []hash.Hash{}
|
||||
ms.processedHashes = [][32]byte{}
|
||||
}
|
||||
|
||||
ms.processedHashes = append(ms.processedHashes, h)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MockChainService) ContainsBlock(h hash.Hash) bool {
|
||||
func (ms *mockChainService) ContainsBlock(h [32]byte) bool {
|
||||
for _, h1 := range ms.processedHashes {
|
||||
if bytes.Equal(h.Sum(nil), h1.Sum(nil)) {
|
||||
if h == h1 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (ms *mockChainService) ProcessedHashes() [][32]byte {
|
||||
return ms.processedHashes
|
||||
}
|
||||
|
||||
func TestProcessBlockHash(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
// set the channel's buffer to 0 to make channel interactions blocking
|
||||
cfg := Config{HashBufferSize: 0, BlockBufferSize: 0}
|
||||
ss := NewSyncService(context.Background(), cfg)
|
||||
|
||||
ns := MockNetworkService{}
|
||||
cs := MockChainService{}
|
||||
ss.SetNetworkService(&ns)
|
||||
ss.SetChainService(&cs)
|
||||
ss := NewSyncService(context.Background(), cfg, &mockP2P{}, &mockChainService{})
|
||||
|
||||
exitRoutine := make(chan bool)
|
||||
|
||||
go func() {
|
||||
run(ss.ctx.Done(), ss.hashBuf, ss.blockBuf, &ns, &cs)
|
||||
ss.run(ss.ctx.Done())
|
||||
exitRoutine <- true
|
||||
}()
|
||||
|
||||
h, err := blake2b.New256(nil)
|
||||
if err != nil {
|
||||
t.Errorf("failed to intialize hash: %v", err)
|
||||
announceHash := blake2b.Sum256([]byte{})
|
||||
hashAnnounce := pb.BeaconBlockHashAnnounce{
|
||||
Hash: announceHash[:],
|
||||
}
|
||||
|
||||
msg := p2p.Message{
|
||||
Peer: p2p.Peer{},
|
||||
Data: hashAnnounce,
|
||||
}
|
||||
|
||||
// if a new hash is processed
|
||||
ss.ReceiveBlockHash(h)
|
||||
ss.announceBlockHashBuf <- msg
|
||||
|
||||
ss.cancel()
|
||||
<-exitRoutine
|
||||
|
||||
// sync service requests the contents of the block and broadcasts the hash to peers
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("requesting block: %x", h.Sum(nil)))
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("broadcasting hash: %x", h.Sum(nil)))
|
||||
testutil.AssertLogsContain(t, hook, "Requesting full block data from sender")
|
||||
hook.Reset()
|
||||
}
|
||||
|
||||
func TestProcessBlock(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
cfg := Config{HashBufferSize: 0, BlockBufferSize: 0}
|
||||
ss := NewSyncService(context.Background(), cfg)
|
||||
|
||||
ns := MockNetworkService{}
|
||||
cs := MockChainService{}
|
||||
|
||||
ss.SetNetworkService(&ns)
|
||||
ss.SetChainService(&cs)
|
||||
ms := &mockChainService{}
|
||||
ss := NewSyncService(context.Background(), cfg, &mockP2P{}, ms)
|
||||
|
||||
exitRoutine := make(chan bool)
|
||||
|
||||
go func() {
|
||||
run(ss.ctx.Done(), ss.hashBuf, ss.blockBuf, &ns, &cs)
|
||||
ss.run(ss.ctx.Done())
|
||||
exitRoutine <- true
|
||||
}()
|
||||
|
||||
b := types.NewBlock(0)
|
||||
h, err := b.Hash()
|
||||
blockResponse := pb.BeaconBlockResponse{
|
||||
MainChainRef: []byte{1, 2, 3, 4, 5},
|
||||
}
|
||||
|
||||
msg := p2p.Message{
|
||||
Peer: p2p.Peer{},
|
||||
Data: blockResponse,
|
||||
}
|
||||
|
||||
ss.blockBuf <- msg
|
||||
ss.cancel()
|
||||
<-exitRoutine
|
||||
|
||||
block, err := types.NewBlockWithData(&blockResponse)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not instantiate new block from proto: %v", err)
|
||||
}
|
||||
h, err := block.Hash()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// if the hash and the block are processed in order
|
||||
ss.ReceiveBlockHash(h)
|
||||
ss.ReceiveBlock(b)
|
||||
ss.cancel()
|
||||
<-exitRoutine
|
||||
// Sync service broadcasts the block and forwards the block to to the local chain.
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("Broadcasting block hash to peers: %x", h))
|
||||
|
||||
// sync service broadcasts the block and forwards the block to to the local chain
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("broadcasting block: %x", h.Sum(nil)))
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("forwarding block: %x", h.Sum(nil)))
|
||||
if ms.processedHashes[0] != h {
|
||||
t.Errorf("Expected processed hash to be equal to block hash. wanted=%x, got=%x", h, ms.processedHashes[0])
|
||||
}
|
||||
hook.Reset()
|
||||
}
|
||||
|
||||
func TestProcessMultipleBlocks(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
cfg := Config{HashBufferSize: 0, BlockBufferSize: 0}
|
||||
ss := NewSyncService(context.Background(), cfg)
|
||||
|
||||
ns := MockNetworkService{}
|
||||
cs := MockChainService{}
|
||||
|
||||
ss.SetNetworkService(&ns)
|
||||
ss.SetChainService(&cs)
|
||||
ms := &mockChainService{}
|
||||
ss := NewSyncService(context.Background(), cfg, &mockP2P{}, ms)
|
||||
|
||||
exitRoutine := make(chan bool)
|
||||
|
||||
go func() {
|
||||
run(ss.ctx.Done(), ss.hashBuf, ss.blockBuf, &ns, &cs)
|
||||
ss.run(ss.ctx.Done())
|
||||
exitRoutine <- true
|
||||
}()
|
||||
|
||||
b1 := types.NewBlock(0)
|
||||
h1, err := b1.Hash()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
blockResponse1 := pb.BeaconBlockResponse{
|
||||
MainChainRef: []byte{1, 2, 3, 4, 5},
|
||||
}
|
||||
|
||||
b2 := types.NewBlock(1)
|
||||
h2, err := b2.Hash()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
msg1 := p2p.Message{
|
||||
Peer: p2p.Peer{},
|
||||
Data: blockResponse1,
|
||||
}
|
||||
|
||||
if bytes.Equal(h1.Sum(nil), h2.Sum(nil)) {
|
||||
t.Fatalf("two blocks should not have the same hash:\n%x\n%x", h1.Sum(nil), h2.Sum(nil))
|
||||
blockResponse2 := pb.BeaconBlockResponse{
|
||||
MainChainRef: []byte{6, 7, 8, 9, 10},
|
||||
}
|
||||
|
||||
// if two different blocks are submitted
|
||||
ss.ReceiveBlockHash(h1)
|
||||
ss.ReceiveBlock(b1)
|
||||
ss.ReceiveBlockHash(h2)
|
||||
ss.ReceiveBlock(b2)
|
||||
msg2 := p2p.Message{
|
||||
Peer: p2p.Peer{},
|
||||
Data: blockResponse2,
|
||||
}
|
||||
|
||||
ss.blockBuf <- msg1
|
||||
ss.blockBuf <- msg2
|
||||
ss.cancel()
|
||||
<-exitRoutine
|
||||
|
||||
// both blocks are processed
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("broadcasting block: %x", h1.Sum(nil)))
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("forwarding block: %x", h1.Sum(nil)))
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("broadcasting block: %x", h2.Sum(nil)))
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("forwarding block: %x", h2.Sum(nil)))
|
||||
block1, err := types.NewBlockWithData(&blockResponse1)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not instantiate new block from proto: %v", err)
|
||||
}
|
||||
h1, err := block1.Hash()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
block2, err := types.NewBlockWithData(&blockResponse2)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not instantiate new block from proto: %v", err)
|
||||
}
|
||||
h2, err := block2.Hash()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Sync service broadcasts the two separate blocks
|
||||
// and forwards them to to the local chain.
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("Broadcasting block hash to peers: %x", h1))
|
||||
if ms.processedHashes[0] != h1 {
|
||||
t.Errorf("Expected processed hash to be equal to block hash. wanted=%x, got=%x", h1, ms.processedHashes[0])
|
||||
}
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("Broadcasting block hash to peers: %x", h2))
|
||||
if ms.processedHashes[1] != h2 {
|
||||
t.Errorf("Expected processed hash to be equal to block hash. wanted=%x, got=%x", h2, ms.processedHashes[1])
|
||||
}
|
||||
hook.Reset()
|
||||
}
|
||||
|
||||
func TestProcessSameBlock(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
cfg := Config{HashBufferSize: 0, BlockBufferSize: 0}
|
||||
ss := NewSyncService(context.Background(), cfg)
|
||||
|
||||
ns := MockNetworkService{}
|
||||
cs := MockChainService{}
|
||||
|
||||
ss.SetNetworkService(&ns)
|
||||
ss.SetChainService(&cs)
|
||||
ms := &mockChainService{}
|
||||
ss := NewSyncService(context.Background(), cfg, &mockP2P{}, ms)
|
||||
|
||||
exitRoutine := make(chan bool)
|
||||
|
||||
go func() {
|
||||
run(ss.ctx.Done(), ss.hashBuf, ss.blockBuf, &ns, &cs)
|
||||
ss.run(ss.ctx.Done())
|
||||
exitRoutine <- true
|
||||
}()
|
||||
|
||||
b := types.NewBlock(0)
|
||||
h, err := b.Hash()
|
||||
blockResponse := pb.BeaconBlockResponse{
|
||||
MainChainRef: []byte{1, 2, 3},
|
||||
}
|
||||
|
||||
msg := p2p.Message{
|
||||
Peer: p2p.Peer{},
|
||||
Data: blockResponse,
|
||||
}
|
||||
ss.blockBuf <- msg
|
||||
ss.blockBuf <- msg
|
||||
ss.cancel()
|
||||
<-exitRoutine
|
||||
|
||||
block, err := types.NewBlockWithData(&blockResponse)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not instantiate new block from proto: %v", err)
|
||||
}
|
||||
h, err := block.Hash()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// if the same block is processed twice
|
||||
ss.ReceiveBlockHash(h)
|
||||
ss.ReceiveBlock(b)
|
||||
ss.ReceiveBlockHash(h)
|
||||
// there's a tricky race condition where the second hash can sneak into the goroutine
|
||||
// before the first block inserts itself into the chain. therefore, its important
|
||||
// for hook.Reset() to be called after the second ProcessBlockHash call
|
||||
// Sync service broadcasts the two separate blocks
|
||||
// and forwards them to to the local chain.
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprintf("Broadcasting block hash to peers: %x", h))
|
||||
if len(ms.processedHashes) > 1 {
|
||||
t.Error("should have only processed one block, processed both instead")
|
||||
}
|
||||
if ms.processedHashes[0] != h {
|
||||
t.Errorf("Expected processed hash to be equal to block hash. wanted=%x, got=%x", h, ms.processedHashes[0])
|
||||
}
|
||||
hook.Reset()
|
||||
ss.ReceiveBlock(b)
|
||||
ss.cancel()
|
||||
<-exitRoutine
|
||||
|
||||
// the block isn't processed the second time
|
||||
testutil.AssertLogsDoNotContain(t, hook, fmt.Sprintf("broadcasting block: %x", h.Sum(nil)))
|
||||
testutil.AssertLogsDoNotContain(t, hook, fmt.Sprintf("forwarding block: %x", h.Sum(nil)))
|
||||
}
|
||||
|
||||
@@ -4,14 +4,20 @@ go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"block.go",
|
||||
"interfaces.go",
|
||||
"state.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/types",
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
deps = [
|
||||
"//proto/sharding/v1:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//event:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//rlp:go_default_library",
|
||||
"@com_github_golang_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_protobuf//ptypes:go_default_library",
|
||||
"@org_golang_x_crypto//blake2b:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,72 +1,109 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"hash"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/sharding/v1"
|
||||
"golang.org/x/crypto/blake2b"
|
||||
)
|
||||
|
||||
// Block defines a beacon chain core primitive.
|
||||
type Block struct {
|
||||
data *Data
|
||||
}
|
||||
|
||||
// Hash generates the BLAKE2b hash of the block
|
||||
func (b Block) Hash() (hash.Hash, error) {
|
||||
data, err := rlp.EncodeToBytes(b.Data())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return blake2b.New256(data)
|
||||
}
|
||||
|
||||
// Data getter makes the block's properties read-only.
|
||||
func (b *Block) Data() *Data {
|
||||
return b.data
|
||||
}
|
||||
|
||||
// NewBlock creates a new beacon block given certain arguments.
|
||||
func NewBlock(slotNumber uint64) *Block {
|
||||
data := &Data{Timestamp: time.Now(), SlotNumber: slotNumber}
|
||||
return &Block{data}
|
||||
}
|
||||
|
||||
// NewGenesisBlock returns the canonical, genesis block for the beacon chain protocol.
|
||||
func NewGenesisBlock() *Block {
|
||||
timestamp := time.Date(2018, time.July, 21, 12, 0, 0, 0, time.UTC)
|
||||
// TODO: Add more default fields.
|
||||
return &Block{data: &Data{Timestamp: timestamp}}
|
||||
}
|
||||
|
||||
// Data contains the fields in a beacon chain block.
|
||||
type Data struct {
|
||||
ParentHash hash.Hash // ParentHash is the hash of the parent beacon block.
|
||||
SlotNumber uint64 // Slot number is the number a client should check to know when it creates block.
|
||||
RandaoReveal hash.Hash // RandaoReveal is used for Randao commitment reveal.
|
||||
AttestationBitmask []byte // AttestationBitmask is the bit field of who from the attestation committee participated.
|
||||
AttestationAggregateSig []uint // AttestationAggregateSig is validator's aggregate sig.
|
||||
ShardAggregateVotes []AggregateVote // ShardAggregateVotes is shard aggregate votes.
|
||||
MainChainRef common.Hash // MainChainRef is the reference to main chain block.
|
||||
ActiveStateHash hash.Hash // ActiveStateHash is the state that changes every block.
|
||||
CrystallizedStateHash hash.Hash // CrystallizedStateHash is the state that changes every epoch.
|
||||
Timestamp time.Time
|
||||
data *pb.BeaconBlockResponse
|
||||
}
|
||||
|
||||
// AggregateVote contains the fields of aggregate vote in individual shard.
|
||||
type AggregateVote struct {
|
||||
ShardID uint16 // Shard ID of the voted shard.
|
||||
ShardBlockHash common.Hash // ShardBlockHash is the shard block hash of the voted shard.
|
||||
SignerBitmask []byte // SignerBitmask is the bit mask of every validator that signed.
|
||||
AggregateSig []uint // AggregateSig is the aggregated signatures of individual shard.
|
||||
ShardID uint32 // Shard ID of the voted shard.
|
||||
ShardBlockHash []byte // ShardBlockHash is the shard block hash of the voted shard.
|
||||
SignerBitmask []byte // SignerBitmask is the bit mask of every validator that signed.
|
||||
AggregateSig []uint // AggregateSig is the aggregated signatures of individual shard.
|
||||
}
|
||||
|
||||
func (b *Block) InsertActiveHash(hash hash.Hash) {
|
||||
b.data.ActiveStateHash = hash
|
||||
// NewBlock creates a new beacon block given certain arguments.
|
||||
func NewBlock(slotNumber uint64) *Block {
|
||||
data := &pb.BeaconBlockResponse{Timestamp: ptypes.TimestampNow(), SlotNumber: slotNumber}
|
||||
return &Block{data: data}
|
||||
}
|
||||
|
||||
func (b *Block) InsertCrystallizedHash(hash hash.Hash) {
|
||||
b.data.CrystallizedStateHash = hash
|
||||
// NewBlockWithData explicitly sets the data field of a block.
|
||||
func NewBlockWithData(data *pb.BeaconBlockResponse) (*Block, error) {
|
||||
return &Block{data}, nil
|
||||
}
|
||||
|
||||
// NewGenesisBlock returns the canonical, genesis block for the beacon chain protocol.
|
||||
func NewGenesisBlock() (*Block, error) {
|
||||
genesisTime := time.Date(2018, time.July, 21, 12, 0, 0, 0, time.UTC)
|
||||
protoGenesis, err := ptypes.TimestampProto(genesisTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// TODO: Add more default fields.
|
||||
return &Block{data: &pb.BeaconBlockResponse{Timestamp: protoGenesis}}, nil
|
||||
}
|
||||
|
||||
// Hash generates the blake2b hash of the block
|
||||
func (b *Block) Hash() ([32]byte, error) {
|
||||
data, err := proto.Marshal(b.data)
|
||||
if err != nil {
|
||||
return [32]byte{}, fmt.Errorf("could not marshal block proto data: %v", err)
|
||||
}
|
||||
return blake2b.Sum256(data), nil
|
||||
}
|
||||
|
||||
// ParentHash corresponding to parent beacon block.
|
||||
func (b *Block) ParentHash() [32]byte {
|
||||
var h [32]byte
|
||||
copy(h[:], b.data.ParentHash[:32])
|
||||
return h
|
||||
}
|
||||
|
||||
// SlotNumber of the beacon block.
|
||||
func (b *Block) SlotNumber() uint64 {
|
||||
return b.data.SlotNumber
|
||||
}
|
||||
|
||||
// MainChainRef returns a keccak256 hash corresponding to a PoW chain block.
|
||||
func (b *Block) MainChainRef() common.Hash {
|
||||
return common.BytesToHash(b.data.MainChainRef)
|
||||
}
|
||||
|
||||
// RandaoReveal returns the blake2b randao hash.
|
||||
func (b *Block) RandaoReveal() [32]byte {
|
||||
var h [32]byte
|
||||
copy(h[:], b.data.RandaoReveal[:32])
|
||||
return h
|
||||
}
|
||||
|
||||
// ActiveStateHash blake2b value.
|
||||
func (b *Block) ActiveStateHash() [32]byte {
|
||||
var h [32]byte
|
||||
copy(h[:], b.data.ActiveStateHash[:32])
|
||||
return h
|
||||
}
|
||||
|
||||
// CrystallizedStateHash blake2b value.
|
||||
func (b *Block) CrystallizedStateHash() [32]byte {
|
||||
var h [32]byte
|
||||
copy(h[:], b.data.CrystallizedStateHash[:32])
|
||||
return h
|
||||
}
|
||||
|
||||
// Timestamp returns the Go type time.Time from the protobuf type contained in the block.
|
||||
func (b *Block) Timestamp() (time.Time, error) {
|
||||
return ptypes.Timestamp(b.data.Timestamp)
|
||||
}
|
||||
|
||||
// InsertActiveHash updates the activeStateHash property in the data of a beacon block.
|
||||
func (b *Block) InsertActiveHash(h [32]byte) {
|
||||
b.data.ActiveStateHash = h[:]
|
||||
}
|
||||
|
||||
// InsertCrystallizedHash updates the crystallizedStateHash property in the data of a beacon block.
|
||||
func (b *Block) InsertCrystallizedHash(h [32]byte) {
|
||||
b.data.CrystallizedStateHash = h[:]
|
||||
}
|
||||
|
||||
38
beacon-chain/types/interfaces.go
Normal file
38
beacon-chain/types/interfaces.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
ethereum "github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
gethTypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
)
|
||||
|
||||
// P2P defines a struct that can subscribe to feeds, request data, and broadcast data.
|
||||
type P2P interface {
|
||||
Feed(msg interface{}) *event.Feed
|
||||
Broadcast(msg interface{})
|
||||
}
|
||||
|
||||
// ChainService is the interface for the local beacon chain.
|
||||
type ChainService interface {
|
||||
ProcessedHashes() [][32]byte
|
||||
ProcessBlock(b *Block) error
|
||||
ContainsBlock(h [32]byte) bool
|
||||
}
|
||||
|
||||
// Reader defines a struct that can fetch latest header events from a web3 endpoint.
|
||||
type Reader interface {
|
||||
SubscribeNewHead(ctx context.Context, ch chan<- *gethTypes.Header) (ethereum.Subscription, error)
|
||||
}
|
||||
|
||||
// POWBlockFetcher defines a struct that can retrieve mainchain blocks.
|
||||
type POWBlockFetcher interface {
|
||||
BlockByHash(ctx context.Context, hash common.Hash) (*gethTypes.Block, error)
|
||||
}
|
||||
|
||||
// Logger subscribe filtered log on the PoW chain
|
||||
type Logger interface {
|
||||
SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- gethTypes.Log) (ethereum.Subscription, error)
|
||||
}
|
||||
@@ -12,7 +12,7 @@ go_library(
|
||||
"//beacon-chain/params:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@org_golang_x_crypto//blake2s:go_default_library",
|
||||
"@org_golang_x_crypto//blake2b:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/params"
|
||||
"golang.org/x/crypto/blake2s"
|
||||
"golang.org/x/crypto/blake2b"
|
||||
)
|
||||
|
||||
// ShuffleIndices returns a list of pseudorandomly sampled
|
||||
@@ -21,18 +21,13 @@ func ShuffleIndices(seed common.Hash, validatorCount int) ([]int, error) {
|
||||
validatorList[i] = i
|
||||
}
|
||||
|
||||
hashSeed, err := blake2s.New256(seed[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hashSeedByte := hashSeed.Sum(nil)
|
||||
hashSeed := blake2b.Sum256(seed[:])
|
||||
|
||||
// shuffle stops at the second to last index.
|
||||
for i := 0; i < validatorCount-1; i++ {
|
||||
// convert every 3 bytes to random number, replace validator index with that number.
|
||||
for j := 0; j+3 < len(hashSeedByte); j += 3 {
|
||||
swapNum := int(hashSeedByte[j] + hashSeedByte[j+1] + hashSeedByte[j+2])
|
||||
for j := 0; j+3 < len(hashSeed); j += 3 {
|
||||
swapNum := int(hashSeed[j] + hashSeed[j+1] + hashSeed[j+2])
|
||||
remaining := validatorCount - i
|
||||
swapPos := swapNum%remaining + i
|
||||
validatorList[i], validatorList[swapPos] = validatorList[swapPos], validatorList[i]
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
|
||||
|
||||
proto_library(
|
||||
name = "messages_proto",
|
||||
srcs = ["messages.proto"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_proto_library(
|
||||
name = "messages_go_proto",
|
||||
importpath = "github.com/prysmaticlabs/prysm/proto/sharding/v1",
|
||||
@@ -25,4 +19,5 @@ proto_library(
|
||||
name = "ethereum_messages_v1_proto",
|
||||
srcs = ["messages.proto"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@com_google_protobuf//:timestamp_proto"],
|
||||
)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: messages.proto
|
||||
// source: proto/sharding/v1/messages.proto
|
||||
|
||||
package ethereum_messages_v1
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import timestamp "github.com/golang/protobuf/ptypes/timestamp"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
@@ -21,10 +22,13 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
type Topic int32
|
||||
|
||||
const (
|
||||
Topic_UNKNOWN Topic = 0
|
||||
Topic_COLLATION_BODY_REQUEST Topic = 1
|
||||
Topic_COLLATION_BODY_RESPONSE Topic = 2
|
||||
Topic_TRANSACTIONS Topic = 3
|
||||
Topic_UNKNOWN Topic = 0
|
||||
Topic_COLLATION_BODY_REQUEST Topic = 1
|
||||
Topic_COLLATION_BODY_RESPONSE Topic = 2
|
||||
Topic_TRANSACTIONS Topic = 3
|
||||
Topic_BEACON_BLOCK_HASH_ANNOUNCE Topic = 4
|
||||
Topic_BEACON_BLOCK_REQUEST Topic = 5
|
||||
Topic_BEACON_BLOCK_RESPONSE Topic = 6
|
||||
)
|
||||
|
||||
var Topic_name = map[int32]string{
|
||||
@@ -32,19 +36,273 @@ var Topic_name = map[int32]string{
|
||||
1: "COLLATION_BODY_REQUEST",
|
||||
2: "COLLATION_BODY_RESPONSE",
|
||||
3: "TRANSACTIONS",
|
||||
4: "BEACON_BLOCK_HASH_ANNOUNCE",
|
||||
5: "BEACON_BLOCK_REQUEST",
|
||||
6: "BEACON_BLOCK_RESPONSE",
|
||||
}
|
||||
var Topic_value = map[string]int32{
|
||||
"UNKNOWN": 0,
|
||||
"COLLATION_BODY_REQUEST": 1,
|
||||
"COLLATION_BODY_RESPONSE": 2,
|
||||
"TRANSACTIONS": 3,
|
||||
"UNKNOWN": 0,
|
||||
"COLLATION_BODY_REQUEST": 1,
|
||||
"COLLATION_BODY_RESPONSE": 2,
|
||||
"TRANSACTIONS": 3,
|
||||
"BEACON_BLOCK_HASH_ANNOUNCE": 4,
|
||||
"BEACON_BLOCK_REQUEST": 5,
|
||||
"BEACON_BLOCK_RESPONSE": 6,
|
||||
}
|
||||
|
||||
func (x Topic) String() string {
|
||||
return proto.EnumName(Topic_name, int32(x))
|
||||
}
|
||||
func (Topic) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_messages_b2b448a5e8345e4f, []int{0}
|
||||
return fileDescriptor_messages_ebbb8b6f046bbe65, []int{0}
|
||||
}
|
||||
|
||||
type BeaconBlockHashAnnounce struct {
|
||||
Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *BeaconBlockHashAnnounce) Reset() { *m = BeaconBlockHashAnnounce{} }
|
||||
func (m *BeaconBlockHashAnnounce) String() string { return proto.CompactTextString(m) }
|
||||
func (*BeaconBlockHashAnnounce) ProtoMessage() {}
|
||||
func (*BeaconBlockHashAnnounce) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_messages_ebbb8b6f046bbe65, []int{0}
|
||||
}
|
||||
func (m *BeaconBlockHashAnnounce) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_BeaconBlockHashAnnounce.Unmarshal(m, b)
|
||||
}
|
||||
func (m *BeaconBlockHashAnnounce) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_BeaconBlockHashAnnounce.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *BeaconBlockHashAnnounce) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_BeaconBlockHashAnnounce.Merge(dst, src)
|
||||
}
|
||||
func (m *BeaconBlockHashAnnounce) XXX_Size() int {
|
||||
return xxx_messageInfo_BeaconBlockHashAnnounce.Size(m)
|
||||
}
|
||||
func (m *BeaconBlockHashAnnounce) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_BeaconBlockHashAnnounce.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_BeaconBlockHashAnnounce proto.InternalMessageInfo
|
||||
|
||||
func (m *BeaconBlockHashAnnounce) GetHash() []byte {
|
||||
if m != nil {
|
||||
return m.Hash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type BeaconBlockRequest struct {
|
||||
Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *BeaconBlockRequest) Reset() { *m = BeaconBlockRequest{} }
|
||||
func (m *BeaconBlockRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*BeaconBlockRequest) ProtoMessage() {}
|
||||
func (*BeaconBlockRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_messages_ebbb8b6f046bbe65, []int{1}
|
||||
}
|
||||
func (m *BeaconBlockRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_BeaconBlockRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *BeaconBlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_BeaconBlockRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *BeaconBlockRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_BeaconBlockRequest.Merge(dst, src)
|
||||
}
|
||||
func (m *BeaconBlockRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_BeaconBlockRequest.Size(m)
|
||||
}
|
||||
func (m *BeaconBlockRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_BeaconBlockRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_BeaconBlockRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *BeaconBlockRequest) GetHash() []byte {
|
||||
if m != nil {
|
||||
return m.Hash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type BeaconBlockResponse struct {
|
||||
ParentHash []byte `protobuf:"bytes,1,opt,name=parent_hash,json=parentHash,proto3" json:"parent_hash,omitempty"`
|
||||
SlotNumber uint64 `protobuf:"varint,2,opt,name=slot_number,json=slotNumber,proto3" json:"slot_number,omitempty"`
|
||||
RandaoReveal []byte `protobuf:"bytes,3,opt,name=randao_reveal,json=randaoReveal,proto3" json:"randao_reveal,omitempty"`
|
||||
AttestationBitmask []byte `protobuf:"bytes,4,opt,name=attestation_bitmask,json=attestationBitmask,proto3" json:"attestation_bitmask,omitempty"`
|
||||
AttestationAggregateSig []uint32 `protobuf:"varint,5,rep,packed,name=attestation_aggregate_sig,json=attestationAggregateSig,proto3" json:"attestation_aggregate_sig,omitempty"`
|
||||
ShardAggregateVotes []*AggregateVote `protobuf:"bytes,6,rep,name=shard_aggregate_votes,json=shardAggregateVotes,proto3" json:"shard_aggregate_votes,omitempty"`
|
||||
MainChainRef []byte `protobuf:"bytes,7,opt,name=main_chain_ref,json=mainChainRef,proto3" json:"main_chain_ref,omitempty"`
|
||||
ActiveStateHash []byte `protobuf:"bytes,8,opt,name=active_state_hash,json=activeStateHash,proto3" json:"active_state_hash,omitempty"`
|
||||
CrystallizedStateHash []byte `protobuf:"bytes,9,opt,name=crystallized_state_hash,json=crystallizedStateHash,proto3" json:"crystallized_state_hash,omitempty"`
|
||||
Timestamp *timestamp.Timestamp `protobuf:"bytes,10,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *BeaconBlockResponse) Reset() { *m = BeaconBlockResponse{} }
|
||||
func (m *BeaconBlockResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*BeaconBlockResponse) ProtoMessage() {}
|
||||
func (*BeaconBlockResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_messages_ebbb8b6f046bbe65, []int{2}
|
||||
}
|
||||
func (m *BeaconBlockResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_BeaconBlockResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *BeaconBlockResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_BeaconBlockResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *BeaconBlockResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_BeaconBlockResponse.Merge(dst, src)
|
||||
}
|
||||
func (m *BeaconBlockResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_BeaconBlockResponse.Size(m)
|
||||
}
|
||||
func (m *BeaconBlockResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_BeaconBlockResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_BeaconBlockResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *BeaconBlockResponse) GetParentHash() []byte {
|
||||
if m != nil {
|
||||
return m.ParentHash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BeaconBlockResponse) GetSlotNumber() uint64 {
|
||||
if m != nil {
|
||||
return m.SlotNumber
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *BeaconBlockResponse) GetRandaoReveal() []byte {
|
||||
if m != nil {
|
||||
return m.RandaoReveal
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BeaconBlockResponse) GetAttestationBitmask() []byte {
|
||||
if m != nil {
|
||||
return m.AttestationBitmask
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BeaconBlockResponse) GetAttestationAggregateSig() []uint32 {
|
||||
if m != nil {
|
||||
return m.AttestationAggregateSig
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BeaconBlockResponse) GetShardAggregateVotes() []*AggregateVote {
|
||||
if m != nil {
|
||||
return m.ShardAggregateVotes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BeaconBlockResponse) GetMainChainRef() []byte {
|
||||
if m != nil {
|
||||
return m.MainChainRef
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BeaconBlockResponse) GetActiveStateHash() []byte {
|
||||
if m != nil {
|
||||
return m.ActiveStateHash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BeaconBlockResponse) GetCrystallizedStateHash() []byte {
|
||||
if m != nil {
|
||||
return m.CrystallizedStateHash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BeaconBlockResponse) GetTimestamp() *timestamp.Timestamp {
|
||||
if m != nil {
|
||||
return m.Timestamp
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AggregateVote struct {
|
||||
ShardId uint32 `protobuf:"varint,1,opt,name=shard_id,json=shardId,proto3" json:"shard_id,omitempty"`
|
||||
ShardBlockHash []byte `protobuf:"bytes,2,opt,name=shard_block_hash,json=shardBlockHash,proto3" json:"shard_block_hash,omitempty"`
|
||||
SignerBitmask []byte `protobuf:"bytes,3,opt,name=signer_bitmask,json=signerBitmask,proto3" json:"signer_bitmask,omitempty"`
|
||||
AggregateSig []uint32 `protobuf:"varint,4,rep,packed,name=aggregate_sig,json=aggregateSig,proto3" json:"aggregate_sig,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *AggregateVote) Reset() { *m = AggregateVote{} }
|
||||
func (m *AggregateVote) String() string { return proto.CompactTextString(m) }
|
||||
func (*AggregateVote) ProtoMessage() {}
|
||||
func (*AggregateVote) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_messages_ebbb8b6f046bbe65, []int{3}
|
||||
}
|
||||
func (m *AggregateVote) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_AggregateVote.Unmarshal(m, b)
|
||||
}
|
||||
func (m *AggregateVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_AggregateVote.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *AggregateVote) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_AggregateVote.Merge(dst, src)
|
||||
}
|
||||
func (m *AggregateVote) XXX_Size() int {
|
||||
return xxx_messageInfo_AggregateVote.Size(m)
|
||||
}
|
||||
func (m *AggregateVote) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_AggregateVote.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_AggregateVote proto.InternalMessageInfo
|
||||
|
||||
func (m *AggregateVote) GetShardId() uint32 {
|
||||
if m != nil {
|
||||
return m.ShardId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *AggregateVote) GetShardBlockHash() []byte {
|
||||
if m != nil {
|
||||
return m.ShardBlockHash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *AggregateVote) GetSignerBitmask() []byte {
|
||||
if m != nil {
|
||||
return m.SignerBitmask
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *AggregateVote) GetAggregateSig() []uint32 {
|
||||
if m != nil {
|
||||
return m.AggregateSig
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type CollationBodyRequest struct {
|
||||
@@ -62,7 +320,7 @@ func (m *CollationBodyRequest) Reset() { *m = CollationBodyRequest{} }
|
||||
func (m *CollationBodyRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*CollationBodyRequest) ProtoMessage() {}
|
||||
func (*CollationBodyRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_messages_b2b448a5e8345e4f, []int{0}
|
||||
return fileDescriptor_messages_ebbb8b6f046bbe65, []int{4}
|
||||
}
|
||||
func (m *CollationBodyRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_CollationBodyRequest.Unmarshal(m, b)
|
||||
@@ -129,7 +387,7 @@ func (m *CollationBodyResponse) Reset() { *m = CollationBodyResponse{} }
|
||||
func (m *CollationBodyResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*CollationBodyResponse) ProtoMessage() {}
|
||||
func (*CollationBodyResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_messages_b2b448a5e8345e4f, []int{1}
|
||||
return fileDescriptor_messages_ebbb8b6f046bbe65, []int{5}
|
||||
}
|
||||
func (m *CollationBodyResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_CollationBodyResponse.Unmarshal(m, b)
|
||||
@@ -164,23 +422,23 @@ func (m *CollationBodyResponse) GetBody() []byte {
|
||||
}
|
||||
|
||||
type Transaction struct {
|
||||
Nonce uint64 `protobuf:"varint,1,opt,name=nonce,proto3" json:"nonce,omitempty"`
|
||||
GasPrice uint64 `protobuf:"varint,2,opt,name=gas_price,json=gasPrice,proto3" json:"gas_price,omitempty"`
|
||||
GasLimit uint64 `protobuf:"varint,3,opt,name=gas_limit,json=gasLimit,proto3" json:"gas_limit,omitempty"`
|
||||
Recipient []byte `protobuf:"bytes,4,opt,name=recipient,proto3" json:"recipient,omitempty"`
|
||||
Value uint64 `protobuf:"varint,5,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Input []byte `protobuf:"bytes,6,opt,name=input,proto3" json:"input,omitempty"`
|
||||
Signature *Signture `protobuf:"bytes,7,opt,name=signature,proto3" json:"signature,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
Nonce uint64 `protobuf:"varint,1,opt,name=nonce,proto3" json:"nonce,omitempty"`
|
||||
GasPrice uint64 `protobuf:"varint,2,opt,name=gas_price,json=gasPrice,proto3" json:"gas_price,omitempty"`
|
||||
GasLimit uint64 `protobuf:"varint,3,opt,name=gas_limit,json=gasLimit,proto3" json:"gas_limit,omitempty"`
|
||||
Recipient []byte `protobuf:"bytes,4,opt,name=recipient,proto3" json:"recipient,omitempty"`
|
||||
Value uint64 `protobuf:"varint,5,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Input []byte `protobuf:"bytes,6,opt,name=input,proto3" json:"input,omitempty"`
|
||||
Signature *Signature `protobuf:"bytes,7,opt,name=signature,proto3" json:"signature,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Transaction) Reset() { *m = Transaction{} }
|
||||
func (m *Transaction) String() string { return proto.CompactTextString(m) }
|
||||
func (*Transaction) ProtoMessage() {}
|
||||
func (*Transaction) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_messages_b2b448a5e8345e4f, []int{2}
|
||||
return fileDescriptor_messages_ebbb8b6f046bbe65, []int{6}
|
||||
}
|
||||
func (m *Transaction) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Transaction.Unmarshal(m, b)
|
||||
@@ -242,14 +500,14 @@ func (m *Transaction) GetInput() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Transaction) GetSignature() *Signture {
|
||||
func (m *Transaction) GetSignature() *Signature {
|
||||
if m != nil {
|
||||
return m.Signature
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Signture struct {
|
||||
type Signature struct {
|
||||
V uint64 `protobuf:"varint,1,opt,name=v,proto3" json:"v,omitempty"`
|
||||
R uint64 `protobuf:"varint,2,opt,name=r,proto3" json:"r,omitempty"`
|
||||
S uint64 `protobuf:"varint,3,opt,name=s,proto3" json:"s,omitempty"`
|
||||
@@ -258,45 +516,45 @@ type Signture struct {
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Signture) Reset() { *m = Signture{} }
|
||||
func (m *Signture) String() string { return proto.CompactTextString(m) }
|
||||
func (*Signture) ProtoMessage() {}
|
||||
func (*Signture) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_messages_b2b448a5e8345e4f, []int{3}
|
||||
func (m *Signature) Reset() { *m = Signature{} }
|
||||
func (m *Signature) String() string { return proto.CompactTextString(m) }
|
||||
func (*Signature) ProtoMessage() {}
|
||||
func (*Signature) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_messages_ebbb8b6f046bbe65, []int{7}
|
||||
}
|
||||
func (m *Signture) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Signture.Unmarshal(m, b)
|
||||
func (m *Signature) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Signature.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Signture) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Signture.Marshal(b, m, deterministic)
|
||||
func (m *Signature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Signature.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *Signture) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Signture.Merge(dst, src)
|
||||
func (dst *Signature) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Signature.Merge(dst, src)
|
||||
}
|
||||
func (m *Signture) XXX_Size() int {
|
||||
return xxx_messageInfo_Signture.Size(m)
|
||||
func (m *Signature) XXX_Size() int {
|
||||
return xxx_messageInfo_Signature.Size(m)
|
||||
}
|
||||
func (m *Signture) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Signture.DiscardUnknown(m)
|
||||
func (m *Signature) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Signature.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Signture proto.InternalMessageInfo
|
||||
var xxx_messageInfo_Signature proto.InternalMessageInfo
|
||||
|
||||
func (m *Signture) GetV() uint64 {
|
||||
func (m *Signature) GetV() uint64 {
|
||||
if m != nil {
|
||||
return m.V
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Signture) GetR() uint64 {
|
||||
func (m *Signature) GetR() uint64 {
|
||||
if m != nil {
|
||||
return m.R
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Signture) GetS() uint64 {
|
||||
func (m *Signature) GetS() uint64 {
|
||||
if m != nil {
|
||||
return m.S
|
||||
}
|
||||
@@ -304,43 +562,74 @@ func (m *Signture) GetS() uint64 {
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*BeaconBlockHashAnnounce)(nil), "ethereum.messages.v1.BeaconBlockHashAnnounce")
|
||||
proto.RegisterType((*BeaconBlockRequest)(nil), "ethereum.messages.v1.BeaconBlockRequest")
|
||||
proto.RegisterType((*BeaconBlockResponse)(nil), "ethereum.messages.v1.BeaconBlockResponse")
|
||||
proto.RegisterType((*AggregateVote)(nil), "ethereum.messages.v1.AggregateVote")
|
||||
proto.RegisterType((*CollationBodyRequest)(nil), "ethereum.messages.v1.CollationBodyRequest")
|
||||
proto.RegisterType((*CollationBodyResponse)(nil), "ethereum.messages.v1.CollationBodyResponse")
|
||||
proto.RegisterType((*Transaction)(nil), "ethereum.messages.v1.Transaction")
|
||||
proto.RegisterType((*Signture)(nil), "ethereum.messages.v1.Signture")
|
||||
proto.RegisterType((*Signature)(nil), "ethereum.messages.v1.Signature")
|
||||
proto.RegisterEnum("ethereum.messages.v1.Topic", Topic_name, Topic_value)
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("messages.proto", fileDescriptor_messages_b2b448a5e8345e4f) }
|
||||
|
||||
var fileDescriptor_messages_b2b448a5e8345e4f = []byte{
|
||||
// 445 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0xcd, 0x6e, 0xd3, 0x4c,
|
||||
0x14, 0x86, 0xbf, 0x69, 0xf3, 0x7b, 0x62, 0x7d, 0x58, 0xa3, 0x50, 0x0c, 0xe5, 0x27, 0xca, 0x2a,
|
||||
0xb0, 0x88, 0xc4, 0xcf, 0x92, 0x4d, 0x1a, 0x22, 0x51, 0x11, 0xd9, 0xc5, 0x76, 0x85, 0x58, 0x59,
|
||||
0x53, 0xfb, 0xc8, 0x1e, 0x91, 0xcc, 0x98, 0x39, 0x76, 0xa4, 0x5e, 0x16, 0x17, 0xc5, 0x7d, 0xa0,
|
||||
0xb1, 0x9d, 0x52, 0x01, 0x3b, 0x3f, 0xef, 0x7b, 0x34, 0x3e, 0xcf, 0xd8, 0xf0, 0xff, 0x1e, 0x89,
|
||||
0x44, 0x8e, 0xb4, 0x2c, 0x8d, 0xae, 0x34, 0x9f, 0x62, 0x55, 0xa0, 0xc1, 0x7a, 0xbf, 0xbc, 0x2b,
|
||||
0x0e, 0xaf, 0xe7, 0x3f, 0x18, 0x4c, 0xd7, 0x7a, 0xb7, 0x13, 0x95, 0xd4, 0xea, 0x42, 0x67, 0xb7,
|
||||
0x21, 0x7e, 0xaf, 0x91, 0x2a, 0xfe, 0x18, 0x46, 0x54, 0x08, 0x93, 0x25, 0x32, 0xf3, 0xd8, 0x8c,
|
||||
0x2d, 0x7a, 0xe1, 0xb0, 0xe1, 0xcb, 0x8c, 0x9f, 0xc1, 0xa0, 0x44, 0x23, 0x75, 0xe6, 0x9d, 0x34,
|
||||
0x45, 0x47, 0xfc, 0x19, 0x40, 0x5a, 0xd4, 0xea, 0x5b, 0x62, 0xb4, 0xae, 0xbc, 0xd3, 0x19, 0x5b,
|
||||
0x38, 0xe1, 0xb8, 0x49, 0x42, 0xad, 0x2b, 0xfe, 0x12, 0xdc, 0xd2, 0xe8, 0x52, 0x13, 0x9a, 0x44,
|
||||
0x64, 0x99, 0x41, 0x22, 0xaf, 0xd7, 0x0c, 0x3d, 0x38, 0xe6, 0xab, 0x36, 0xe6, 0x4f, 0x61, 0x4c,
|
||||
0x32, 0x57, 0xa2, 0xaa, 0x0d, 0x7a, 0xfd, 0xf6, 0xa0, 0xbb, 0x60, 0xbe, 0x85, 0x87, 0x7f, 0xac,
|
||||
0x4c, 0xa5, 0x56, 0x84, 0xfc, 0x05, 0x4c, 0x0a, 0x14, 0x19, 0x9a, 0xa4, 0x10, 0x54, 0x34, 0x6b,
|
||||
0x3b, 0x21, 0xb4, 0xd1, 0x47, 0x41, 0x05, 0xe7, 0xd0, 0xbb, 0xd1, 0xd9, 0x6d, 0xb3, 0xb7, 0x13,
|
||||
0x36, 0xcf, 0xf3, 0x9f, 0x0c, 0x26, 0xb1, 0x11, 0x8a, 0x44, 0x6a, 0x0f, 0xe4, 0x53, 0xe8, 0x2b,
|
||||
0xad, 0x52, 0xec, 0xac, 0x5b, 0xe0, 0xe7, 0x30, 0xce, 0x05, 0x25, 0xa5, 0x91, 0x29, 0x76, 0xda,
|
||||
0xa3, 0x5c, 0xd0, 0x95, 0xe5, 0x63, 0xb9, 0x93, 0x7b, 0xd9, 0x7a, 0xb7, 0xe5, 0xd6, 0xb2, 0x75,
|
||||
0x31, 0x98, 0xca, 0x52, 0xa2, 0xaa, 0x3a, 0xdf, 0xdf, 0x81, 0x7d, 0xdb, 0x41, 0xec, 0xea, 0xd6,
|
||||
0xb2, 0x17, 0xb6, 0x60, 0x53, 0xa9, 0xca, 0xba, 0xf2, 0x06, 0xcd, 0x7c, 0x0b, 0xfc, 0xfd, 0xfd,
|
||||
0x5b, 0x19, 0xce, 0xd8, 0x62, 0xf2, 0xe6, 0xf9, 0xf2, 0x5f, 0x5f, 0x75, 0x19, 0xc9, 0x5c, 0xd9,
|
||||
0xa9, 0xfb, 0xb7, 0xf6, 0x0e, 0x46, 0xc7, 0x98, 0x3b, 0xc0, 0x0e, 0x9d, 0x1f, 0x3b, 0x58, 0x32,
|
||||
0x9d, 0x13, 0x33, 0x96, 0xa8, 0x93, 0x60, 0xf4, 0x2a, 0x81, 0x7e, 0xac, 0x4b, 0x99, 0xf2, 0x09,
|
||||
0x0c, 0xaf, 0xfd, 0x4f, 0x7e, 0xf0, 0xc5, 0x77, 0xff, 0xe3, 0x4f, 0xe0, 0x6c, 0x1d, 0x6c, 0xb7,
|
||||
0xab, 0xf8, 0x32, 0xf0, 0x93, 0x8b, 0xe0, 0xc3, 0xd7, 0x24, 0xdc, 0x7c, 0xbe, 0xde, 0x44, 0xb1,
|
||||
0xcb, 0xf8, 0x39, 0x3c, 0xfa, 0xab, 0x8b, 0xae, 0x02, 0x3f, 0xda, 0xb8, 0x27, 0xdc, 0x05, 0x27,
|
||||
0x0e, 0x57, 0x7e, 0xb4, 0x5a, 0xdb, 0x3a, 0x72, 0x4f, 0x6f, 0x06, 0xcd, 0xdf, 0xf9, 0xf6, 0x57,
|
||||
0x00, 0x00, 0x00, 0xff, 0xff, 0x27, 0xa7, 0xf1, 0x57, 0xaf, 0x02, 0x00, 0x00,
|
||||
func init() {
|
||||
proto.RegisterFile("proto/sharding/v1/messages.proto", fileDescriptor_messages_ebbb8b6f046bbe65)
|
||||
}
|
||||
|
||||
var fileDescriptor_messages_ebbb8b6f046bbe65 = []byte{
|
||||
// 839 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x54, 0xed, 0x6e, 0xe2, 0x46,
|
||||
0x14, 0xad, 0x13, 0x20, 0xe1, 0x02, 0x59, 0x3a, 0x49, 0x36, 0x4e, 0xb6, 0x6d, 0x10, 0x69, 0x25,
|
||||
0xba, 0x52, 0x41, 0xbb, 0x55, 0xab, 0xaa, 0x52, 0x7f, 0x00, 0x45, 0xca, 0x6a, 0x91, 0xd9, 0x1a,
|
||||
0xd2, 0x55, 0x7f, 0x59, 0x83, 0x3d, 0x31, 0xa3, 0x98, 0x19, 0x77, 0x66, 0x8c, 0x94, 0x3e, 0x40,
|
||||
0x9f, 0xa3, 0xaf, 0x50, 0xa9, 0xcf, 0xd4, 0xe7, 0xa8, 0x66, 0xc6, 0x06, 0x93, 0xe6, 0x0f, 0xf2,
|
||||
0x3d, 0xe7, 0xdc, 0x99, 0xfb, 0x71, 0x06, 0xe8, 0xa4, 0x82, 0x2b, 0x3e, 0x90, 0x2b, 0x2c, 0x22,
|
||||
0xca, 0xe2, 0xc1, 0xe6, 0xcd, 0x60, 0x4d, 0xa4, 0xc4, 0x31, 0x91, 0x7d, 0x43, 0xa1, 0x33, 0xa2,
|
||||
0x56, 0x44, 0x90, 0x6c, 0xdd, 0xdf, 0x12, 0x9b, 0x37, 0x57, 0xd7, 0x31, 0xe7, 0x71, 0x42, 0x06,
|
||||
0x46, 0xb3, 0xcc, 0xee, 0x07, 0x8a, 0xae, 0x89, 0x54, 0x78, 0x9d, 0xda, 0xb4, 0xee, 0x37, 0x70,
|
||||
0x31, 0x22, 0x38, 0xe4, 0x6c, 0x94, 0xf0, 0xf0, 0xe1, 0x16, 0xcb, 0xd5, 0x90, 0x31, 0x9e, 0xb1,
|
||||
0x90, 0x20, 0x04, 0x95, 0x15, 0x96, 0x2b, 0xd7, 0xe9, 0x38, 0xbd, 0xa6, 0x6f, 0xbe, 0xbb, 0x3d,
|
||||
0x40, 0x25, 0xb9, 0x4f, 0x7e, 0xcf, 0x88, 0x54, 0xcf, 0x2a, 0xff, 0xac, 0xc0, 0xe9, 0x9e, 0x54,
|
||||
0xa6, 0x9c, 0x49, 0x82, 0xae, 0xa1, 0x91, 0x62, 0x41, 0x98, 0x0a, 0x4a, 0x29, 0x60, 0x21, 0x7d,
|
||||
0xbd, 0x16, 0xc8, 0x84, 0xab, 0x80, 0x65, 0xeb, 0x25, 0x11, 0xee, 0x41, 0xc7, 0xe9, 0x55, 0x7c,
|
||||
0xd0, 0x90, 0x67, 0x10, 0x74, 0x03, 0x2d, 0x81, 0x59, 0x84, 0x79, 0x20, 0xc8, 0x86, 0xe0, 0xc4,
|
||||
0x3d, 0x34, 0x67, 0x34, 0x2d, 0xe8, 0x1b, 0x0c, 0x0d, 0xe0, 0x14, 0x2b, 0xa5, 0x5b, 0x55, 0x94,
|
||||
0xb3, 0x60, 0x49, 0xd5, 0x1a, 0xcb, 0x07, 0xb7, 0x62, 0xa4, 0xa8, 0x44, 0x8d, 0x2c, 0x83, 0x7e,
|
||||
0x84, 0xcb, 0x72, 0x02, 0x8e, 0x63, 0x41, 0x62, 0xac, 0x48, 0x20, 0x69, 0xec, 0x56, 0x3b, 0x87,
|
||||
0xbd, 0x96, 0x7f, 0x51, 0x12, 0x0c, 0x0b, 0x7e, 0x4e, 0x63, 0xf4, 0x11, 0xce, 0xcd, 0x66, 0x4a,
|
||||
0x59, 0x1b, 0xae, 0x88, 0x74, 0x6b, 0x9d, 0xc3, 0x5e, 0xe3, 0xed, 0x4d, 0xff, 0xb9, 0xdd, 0xf4,
|
||||
0xb7, 0x47, 0xfc, 0xca, 0x15, 0xf1, 0x4f, 0xcd, 0x09, 0x7b, 0x98, 0x44, 0x5f, 0xc2, 0xc9, 0x1a,
|
||||
0x53, 0x16, 0x84, 0x2b, 0xfd, 0x2b, 0xc8, 0xbd, 0x7b, 0x64, 0x7b, 0xd5, 0xe8, 0x58, 0x83, 0x3e,
|
||||
0xb9, 0x47, 0xaf, 0xe1, 0x53, 0x1c, 0x2a, 0xba, 0x21, 0x81, 0x2e, 0x8e, 0xd8, 0xc1, 0x1e, 0x1b,
|
||||
0xe1, 0x0b, 0x4b, 0xcc, 0x35, 0x6e, 0xa6, 0xfb, 0x3d, 0x5c, 0x84, 0xe2, 0x51, 0x2a, 0x9c, 0x24,
|
||||
0xf4, 0x0f, 0x12, 0x95, 0x33, 0xea, 0x26, 0xe3, 0xbc, 0x4c, 0xef, 0xf2, 0x7e, 0x80, 0xfa, 0xd6,
|
||||
0x3a, 0x2e, 0x74, 0x9c, 0x5e, 0xe3, 0xed, 0x55, 0xdf, 0x9a, 0xab, 0x5f, 0x98, 0xab, 0xbf, 0x28,
|
||||
0x14, 0xfe, 0x4e, 0xdc, 0xfd, 0xcb, 0x81, 0xd6, 0x5e, 0x5b, 0xe8, 0x12, 0x8e, 0xed, 0xb8, 0x68,
|
||||
0x64, 0xf6, 0xdf, 0xf2, 0x8f, 0x4c, 0xfc, 0x2e, 0x42, 0x3d, 0x68, 0x5b, 0x6a, 0xa9, 0x4d, 0x63,
|
||||
0xeb, 0x3a, 0x30, 0x75, 0x9d, 0x18, 0x7c, 0xeb, 0x52, 0xf4, 0x15, 0x9c, 0x48, 0x1a, 0x33, 0x22,
|
||||
0xb6, 0xbb, 0xb5, 0x36, 0x68, 0x59, 0xb4, 0x58, 0xeb, 0x0d, 0xb4, 0xf6, 0x57, 0x59, 0x31, 0xab,
|
||||
0x6c, 0xe2, 0xd2, 0xfe, 0xba, 0x7f, 0x3b, 0x70, 0x36, 0xe6, 0x49, 0x62, 0x0d, 0xc1, 0xa3, 0xc7,
|
||||
0xc2, 0xd8, 0x4f, 0x2b, 0xad, 0xec, 0x2a, 0x7d, 0x09, 0xb5, 0x94, 0x08, 0xca, 0xa3, 0xdc, 0xa1,
|
||||
0x79, 0x84, 0x3e, 0x07, 0x08, 0x57, 0x19, 0x7b, 0x08, 0x04, 0xe7, 0x2a, 0xaf, 0xa9, 0x6e, 0x10,
|
||||
0x9f, 0x73, 0x85, 0xbe, 0x86, 0x76, 0x2a, 0x78, 0xca, 0x25, 0x11, 0x01, 0x8e, 0x22, 0x41, 0xa4,
|
||||
0xcc, 0x4d, 0xf9, 0xa2, 0xc0, 0x87, 0x16, 0x46, 0x9f, 0x41, 0x5d, 0xf7, 0x82, 0x55, 0x26, 0x88,
|
||||
0x5b, 0xb5, 0x07, 0x6d, 0x81, 0xee, 0x14, 0xce, 0x9f, 0x94, 0xbc, 0x7b, 0x60, 0x2b, 0x82, 0x23,
|
||||
0x22, 0xf6, 0x1e, 0x98, 0x85, 0xcc, 0xe4, 0x10, 0x54, 0x96, 0x3c, 0x7a, 0xcc, 0xe7, 0x6a, 0xbe,
|
||||
0xbb, 0xff, 0x3a, 0xd0, 0x58, 0x08, 0xcc, 0xa4, 0xf6, 0x0b, 0x67, 0xe8, 0x0c, 0xaa, 0x8c, 0xb3,
|
||||
0x90, 0xe4, 0x5d, 0xdb, 0x00, 0xbd, 0x82, 0x7a, 0x8c, 0x65, 0x90, 0x0a, 0x1a, 0x92, 0xbc, 0xed,
|
||||
0xe3, 0x18, 0xcb, 0x0f, 0x3a, 0x2e, 0xc8, 0x84, 0xae, 0xa9, 0xed, 0xdb, 0x92, 0x53, 0x1d, 0xeb,
|
||||
0x5e, 0x04, 0x09, 0x69, 0x4a, 0x09, 0x53, 0x79, 0xbf, 0x3b, 0x40, 0xdf, 0xb6, 0xc1, 0x49, 0x66,
|
||||
0xbb, 0xac, 0xf8, 0x36, 0xd0, 0x28, 0x65, 0x69, 0xa6, 0xdc, 0x9a, 0xd1, 0xdb, 0x00, 0xfd, 0x54,
|
||||
0x9e, 0xca, 0x91, 0x31, 0xe2, 0xf5, 0xf3, 0xef, 0x6b, 0x5e, 0xc8, 0xca, 0x63, 0xfb, 0x0e, 0xea,
|
||||
0x5b, 0x1c, 0x35, 0xc1, 0xd9, 0xe4, 0x1d, 0x3a, 0x1b, 0x1d, 0x15, 0x7f, 0x37, 0x8e, 0xd0, 0x91,
|
||||
0xcc, 0xdb, 0x70, 0xe4, 0xeb, 0x7f, 0x1c, 0xa8, 0x2e, 0x78, 0x4a, 0x43, 0xd4, 0x80, 0xa3, 0x3b,
|
||||
0xef, 0xbd, 0x37, 0xfb, 0xe8, 0xb5, 0x3f, 0x41, 0x57, 0xf0, 0x72, 0x3c, 0x9b, 0x4e, 0x87, 0x8b,
|
||||
0x77, 0x33, 0x2f, 0x18, 0xcd, 0x7e, 0xfe, 0x2d, 0xf0, 0x27, 0xbf, 0xdc, 0x4d, 0xe6, 0x8b, 0xb6,
|
||||
0x83, 0x5e, 0xc1, 0xc5, 0xff, 0xb8, 0xf9, 0x87, 0x99, 0x37, 0x9f, 0xb4, 0x0f, 0x50, 0x1b, 0x9a,
|
||||
0x0b, 0x7f, 0xe8, 0xcd, 0x87, 0x63, 0x4d, 0xcf, 0xdb, 0x87, 0xe8, 0x0b, 0xb8, 0x1a, 0x4d, 0x86,
|
||||
0x63, 0xad, 0x9d, 0xce, 0xc6, 0xef, 0x83, 0xdb, 0xe1, 0xfc, 0x36, 0x18, 0x7a, 0xde, 0xec, 0xce,
|
||||
0x1b, 0x4f, 0xda, 0x15, 0xe4, 0xc2, 0xd9, 0x1e, 0x5f, 0x5c, 0x54, 0x45, 0x97, 0x70, 0xfe, 0x84,
|
||||
0xc9, 0xaf, 0xa9, 0x2d, 0x6b, 0xe6, 0x69, 0x7e, 0xfb, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf2,
|
||||
0x0d, 0xab, 0x2f, 0x3f, 0x06, 0x00, 0x00,
|
||||
}
|
||||
|
||||
@@ -2,13 +2,46 @@ syntax = "proto3";
|
||||
|
||||
package ethereum.messages.v1;
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
enum Topic {
|
||||
UNKNOWN = 0;
|
||||
COLLATION_BODY_REQUEST = 1;
|
||||
COLLATION_BODY_RESPONSE = 2;
|
||||
TRANSACTIONS = 3;
|
||||
BEACON_BLOCK_HASH_ANNOUNCE = 4;
|
||||
BEACON_BLOCK_REQUEST = 5;
|
||||
BEACON_BLOCK_RESPONSE = 6;
|
||||
}
|
||||
|
||||
message BeaconBlockHashAnnounce {
|
||||
bytes hash = 1;
|
||||
}
|
||||
|
||||
message BeaconBlockRequest {
|
||||
bytes hash = 1;
|
||||
}
|
||||
|
||||
message BeaconBlockResponse {
|
||||
bytes parent_hash = 1;
|
||||
uint64 slot_number = 2;
|
||||
bytes randao_reveal = 3;
|
||||
bytes attestation_bitmask = 4;
|
||||
repeated uint32 attestation_aggregate_sig = 5;
|
||||
repeated AggregateVote shard_aggregate_votes = 6;
|
||||
bytes main_chain_ref = 7;
|
||||
bytes active_state_hash = 8;
|
||||
bytes crystallized_state_hash = 9;
|
||||
google.protobuf.Timestamp timestamp = 10;
|
||||
}
|
||||
|
||||
message AggregateVote {
|
||||
uint32 shard_id = 1;
|
||||
bytes shard_block_hash = 2;
|
||||
bytes signer_bitmask = 3;
|
||||
repeated uint32 aggregate_sig = 4;
|
||||
}
|
||||
|
||||
message CollationBodyRequest {
|
||||
uint64 shard_id = 1;
|
||||
uint64 period = 2;
|
||||
@@ -29,10 +62,10 @@ message Transaction {
|
||||
bytes recipient = 4;
|
||||
uint64 value = 5;
|
||||
bytes input = 6;
|
||||
Signture signature = 7;
|
||||
Signature signature = 7;
|
||||
}
|
||||
|
||||
message Signture {
|
||||
message Signature {
|
||||
uint64 v = 1;
|
||||
uint64 r = 2;
|
||||
uint64 s = 3;
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
)
|
||||
|
||||
// P2P feed is a one to many subscription feed of the argument type.
|
||||
// Feed is a one to many subscription feed of the argument type.
|
||||
//
|
||||
// Messages received via p2p protocol are sent to subscribers by these event
|
||||
// feeds. Message consumers should not use event feeds to reply to or broadcast
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package p2p
|
||||
|
||||
// Peer
|
||||
// TODO - Design and implement.
|
||||
// Peer TODO - Design and implement.
|
||||
// See design doc: https://docs.google.com/document/d/1cthKuGPreOSQH96Ujt7sArcT-IRICk6b-QcdD0EnLsI/edit
|
||||
// https://github.com/prysmaticlabs/prysm/issues/175
|
||||
type Peer struct{}
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
pb "github.com/prysmaticlabs/prysm/proto/sharding/v1"
|
||||
)
|
||||
|
||||
// Sender represents a struct that is able to relay information via shardp2p.
|
||||
// Sender represents a struct that is able to relay information via p2p.
|
||||
// Server implements this interface.
|
||||
type Sender interface {
|
||||
Send(msg interface{}, peer Peer)
|
||||
@@ -68,7 +68,7 @@ func NewServer() (*Server, error) {
|
||||
|
||||
// Start the main routine for an p2p server.
|
||||
func (s *Server) Start() {
|
||||
log.Info("Starting shardp2p server")
|
||||
log.Info("Starting service")
|
||||
if err := startDiscovery(s.ctx, s.host, s.gsub); err != nil {
|
||||
log.Errorf("Could not start p2p discovery! %v", err)
|
||||
return
|
||||
@@ -85,7 +85,7 @@ func (s *Server) Start() {
|
||||
|
||||
// Stop the main p2p loop.
|
||||
func (s *Server) Stop() error {
|
||||
log.Info("Stopping shardp2p server")
|
||||
log.Info("Stopping service")
|
||||
|
||||
s.cancel()
|
||||
return nil
|
||||
|
||||
@@ -38,14 +38,14 @@ func TestLifecycle(t *testing.T) {
|
||||
|
||||
s.Start()
|
||||
msg := hook.Entries[0].Message
|
||||
want := "Starting shardp2p server"
|
||||
want := "Starting service"
|
||||
if msg != want {
|
||||
t.Errorf("incorrect log. wanted: %s. got: %v", want, msg)
|
||||
}
|
||||
|
||||
s.Stop()
|
||||
msg = hook.LastEntry().Message
|
||||
want = "Stopping shardp2p server"
|
||||
want = "Stopping service"
|
||||
if msg != want {
|
||||
t.Errorf("incorrect log. wanted: %s. got: %v", want, msg)
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func testSubscribe(t *testing.T, s Server, gsub *floodsub.PubSub, ch chan Messag
|
||||
|
||||
b, err := proto.Marshal(pbMsg)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to marshal pbMsg: %v", err)
|
||||
t.Errorf("Failed to marshal service %v", err)
|
||||
}
|
||||
if err = gsub.Publish(topic.String(), b); err != nil {
|
||||
t.Errorf("Failed to publish message: %v", err)
|
||||
|
||||
@@ -8,9 +8,12 @@ import (
|
||||
|
||||
// Mapping of message topic enums to protobuf types.
|
||||
var topicTypeMapping = map[pb.Topic]reflect.Type{
|
||||
pb.Topic_COLLATION_BODY_REQUEST: reflect.TypeOf(pb.CollationBodyRequest{}),
|
||||
pb.Topic_COLLATION_BODY_RESPONSE: reflect.TypeOf(pb.CollationBodyResponse{}),
|
||||
pb.Topic_TRANSACTIONS: reflect.TypeOf(pb.Transaction{}),
|
||||
pb.Topic_BEACON_BLOCK_HASH_ANNOUNCE: reflect.TypeOf(pb.BeaconBlockHashAnnounce{}),
|
||||
pb.Topic_BEACON_BLOCK_REQUEST: reflect.TypeOf(pb.BeaconBlockRequest{}),
|
||||
pb.Topic_BEACON_BLOCK_RESPONSE: reflect.TypeOf(pb.BeaconBlockResponse{}),
|
||||
pb.Topic_COLLATION_BODY_REQUEST: reflect.TypeOf(pb.CollationBodyRequest{}),
|
||||
pb.Topic_COLLATION_BODY_RESPONSE: reflect.TypeOf(pb.CollationBodyResponse{}),
|
||||
pb.Topic_TRANSACTIONS: reflect.TypeOf(pb.Transaction{}),
|
||||
}
|
||||
|
||||
// Mapping of message types to topic enums.
|
||||
|
||||
Reference in New Issue
Block a user