2018-07-19 16:31:50 +00:00
|
|
|
package blockchain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-09-18 13:06:28 +00:00
|
|
|
"errors"
|
2018-08-18 03:34:56 +00:00
|
|
|
"io/ioutil"
|
2018-09-11 05:09:41 +00:00
|
|
|
"math/big"
|
2019-02-09 20:35:51 +00:00
|
|
|
"strconv"
|
2018-07-19 16:31:50 +00:00
|
|
|
"testing"
|
2019-01-05 05:39:34 +00:00
|
|
|
"time"
|
2018-07-19 16:31:50 +00:00
|
|
|
|
2018-12-01 22:09:12 +00:00
|
|
|
ethereum "github.com/ethereum/go-ethereum"
|
2018-07-22 16:58:14 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-08-15 04:49:59 +00:00
|
|
|
gethTypes "github.com/ethereum/go-ethereum/core/types"
|
2018-12-01 22:09:12 +00:00
|
|
|
"github.com/ethereum/go-ethereum/event"
|
2018-12-23 22:51:04 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2018-12-20 22:00:38 +00:00
|
|
|
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
2018-12-23 22:51:04 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
2019-02-06 16:44:27 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
|
2018-10-05 17:14:50 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
2018-11-07 19:07:41 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
|
2018-07-22 16:58:14 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
|
2018-08-15 04:49:59 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
2019-01-31 02:53:58 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
2018-12-23 22:51:04 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
2018-12-19 05:18:42 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2018-08-18 03:34:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
2019-02-09 14:07:30 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
2018-08-18 03:34:56 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-07-19 16:31:50 +00:00
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
2018-08-18 03:34:56 +00:00
|
|
|
func init() {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
logrus.SetOutput(ioutil.Discard)
|
|
|
|
}
|
|
|
|
|
2018-08-15 04:49:59 +00:00
|
|
|
type mockClient struct{}
|
|
|
|
|
2019-01-16 14:01:21 +00:00
|
|
|
func (m *mockClient) SubscribeNewHead(ctx context.Context, ch chan<- *gethTypes.Header) (ethereum.Subscription, error) {
|
2018-08-15 04:49:59 +00:00
|
|
|
return new(event.Feed).Subscribe(ch), nil
|
|
|
|
}
|
|
|
|
|
2019-01-16 14:01:21 +00:00
|
|
|
func (m *mockClient) BlockByHash(ctx context.Context, hash common.Hash) (*gethTypes.Block, error) {
|
2018-09-11 05:09:41 +00:00
|
|
|
head := &gethTypes.Header{Number: big.NewInt(0), Difficulty: big.NewInt(100)}
|
|
|
|
return gethTypes.NewBlockWithHeader(head), nil
|
2018-08-15 04:49:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 14:01:21 +00:00
|
|
|
func (m *mockClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- gethTypes.Log) (ethereum.Subscription, error) {
|
2018-08-15 04:49:59 +00:00
|
|
|
return new(event.Feed).Subscribe(ch), nil
|
|
|
|
}
|
|
|
|
|
2019-01-16 14:01:21 +00:00
|
|
|
func (m *mockClient) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
|
|
|
|
return []byte{'t', 'e', 's', 't'}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
|
|
|
|
return []byte{'t', 'e', 's', 't'}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]gethTypes.Log, error) {
|
|
|
|
logs := make([]gethTypes.Log, 3)
|
|
|
|
for i := 0; i < len(logs); i++ {
|
|
|
|
logs[i].Address = common.Address{}
|
|
|
|
logs[i].Topics = make([]common.Hash, 5)
|
|
|
|
logs[i].Topics[0] = common.Hash{'a'}
|
|
|
|
logs[i].Topics[1] = common.Hash{'b'}
|
|
|
|
logs[i].Topics[2] = common.Hash{'c'}
|
|
|
|
|
|
|
|
}
|
|
|
|
return logs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockClient) LatestBlockHash() common.Hash {
|
2018-08-15 04:49:59 +00:00
|
|
|
return common.BytesToHash([]byte{'A'})
|
|
|
|
}
|
|
|
|
|
2018-09-18 13:06:28 +00:00
|
|
|
type faultyClient struct{}
|
|
|
|
|
|
|
|
func (f *faultyClient) SubscribeNewHead(ctx context.Context, ch chan<- *gethTypes.Header) (ethereum.Subscription, error) {
|
|
|
|
return new(event.Feed).Subscribe(ch), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *faultyClient) BlockByHash(ctx context.Context, hash common.Hash) (*gethTypes.Block, error) {
|
|
|
|
return nil, errors.New("failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *faultyClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- gethTypes.Log) (ethereum.Subscription, error) {
|
|
|
|
return new(event.Feed).Subscribe(ch), nil
|
|
|
|
}
|
|
|
|
|
2019-01-16 14:01:21 +00:00
|
|
|
func (f *faultyClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]gethTypes.Log, error) {
|
|
|
|
return nil, errors.New("unable to retrieve logs")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *faultyClient) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
|
|
|
|
return []byte{}, errors.New("unable to retrieve contract code")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *faultyClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
|
|
|
|
return []byte{}, errors.New("unable to retrieve contract code")
|
|
|
|
}
|
|
|
|
|
2018-09-18 13:06:28 +00:00
|
|
|
func (f *faultyClient) LatestBlockHash() common.Hash {
|
|
|
|
return common.BytesToHash([]byte{'A'})
|
|
|
|
}
|
|
|
|
|
2019-02-03 22:44:48 +00:00
|
|
|
func setupInitialDeposits(t *testing.T) []*pb.Deposit {
|
|
|
|
genesisValidatorRegistry := validators.InitialValidatorRegistry()
|
|
|
|
deposits := make([]*pb.Deposit, len(genesisValidatorRegistry))
|
|
|
|
for i := 0; i < len(deposits); i++ {
|
2019-02-09 14:07:30 +00:00
|
|
|
deposits[i] = createPreChainStartDeposit(t, genesisValidatorRegistry[i].Pubkey)
|
2019-02-03 22:44:48 +00:00
|
|
|
}
|
|
|
|
return deposits
|
|
|
|
}
|
|
|
|
|
2019-02-09 14:07:30 +00:00
|
|
|
func createPreChainStartDeposit(t *testing.T, pk []byte) *pb.Deposit {
|
|
|
|
depositInput := &pb.DepositInput{Pubkey: pk}
|
|
|
|
balance := params.BeaconConfig().MaxDepositAmount
|
|
|
|
depositData, err := b.EncodeDepositData(depositInput, balance, time.Now().Unix())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot encode data: %v", err)
|
|
|
|
}
|
|
|
|
return &pb.Deposit{DepositData: depositData}
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:11:18 +00:00
|
|
|
func setupBeaconChain(t *testing.T, faultyPoWClient bool, beaconDB *db.BeaconDB, enablePOWChain bool) *ChainService {
|
2018-07-22 16:58:14 +00:00
|
|
|
endpoint := "ws://127.0.0.1"
|
2018-10-05 17:14:50 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
var web3Service *powchain.Web3Service
|
2018-10-17 06:11:24 +00:00
|
|
|
var err error
|
2019-02-07 16:11:18 +00:00
|
|
|
if enablePOWChain {
|
|
|
|
if faultyPoWClient {
|
|
|
|
client := &faultyClient{}
|
|
|
|
web3Service, err = powchain.NewWeb3Service(ctx, &powchain.Web3ServiceConfig{
|
|
|
|
Endpoint: endpoint,
|
|
|
|
DepositContract: common.Address{},
|
|
|
|
Reader: client,
|
|
|
|
Client: client,
|
|
|
|
Logger: client,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
client := &mockClient{}
|
|
|
|
web3Service, err = powchain.NewWeb3Service(ctx, &powchain.Web3ServiceConfig{
|
|
|
|
Endpoint: endpoint,
|
|
|
|
DepositContract: common.Address{},
|
|
|
|
Reader: client,
|
|
|
|
Client: client,
|
|
|
|
Logger: client,
|
|
|
|
})
|
|
|
|
}
|
2018-10-05 17:14:50 +00:00
|
|
|
}
|
2018-07-22 16:58:14 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to set up web3 service: %v", err)
|
|
|
|
}
|
2018-10-17 06:11:24 +00:00
|
|
|
|
2018-08-09 22:54:59 +00:00
|
|
|
cfg := &Config{
|
|
|
|
BeaconBlockBuf: 0,
|
2018-10-17 06:11:24 +00:00
|
|
|
BeaconDB: beaconDB,
|
2018-10-05 17:14:50 +00:00
|
|
|
Web3Service: web3Service,
|
2019-02-07 16:11:18 +00:00
|
|
|
EnablePOWChain: enablePOWChain,
|
2018-08-09 22:54:59 +00:00
|
|
|
}
|
2018-08-15 04:49:59 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not register blockchain service: %v", err)
|
|
|
|
}
|
2018-08-24 04:09:59 +00:00
|
|
|
chainService, err := NewChainService(ctx, cfg)
|
2018-07-19 16:31:50 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to setup chain service: %v", err)
|
|
|
|
}
|
2018-09-18 13:06:28 +00:00
|
|
|
|
2018-10-05 17:14:50 +00:00
|
|
|
return chainService
|
|
|
|
}
|
|
|
|
|
2018-12-19 05:18:42 +00:00
|
|
|
func SetSlotInState(service *ChainService, slot uint64) error {
|
2019-01-21 09:34:11 +00:00
|
|
|
bState, err := service.beaconDB.State()
|
2018-12-19 05:18:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-12-23 22:51:04 +00:00
|
|
|
bState.Slot = slot
|
2018-12-19 05:18:42 +00:00
|
|
|
return service.beaconDB.SaveState(bState)
|
|
|
|
}
|
|
|
|
|
2019-01-28 11:59:37 +00:00
|
|
|
func TestStartStopUninitializedChain(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
2018-11-07 19:07:41 +00:00
|
|
|
db := internal.SetupDB(t)
|
|
|
|
defer internal.TeardownDB(t, db)
|
2019-02-07 16:11:18 +00:00
|
|
|
chainService := setupBeaconChain(t, false, db, true)
|
2018-09-27 02:34:35 +00:00
|
|
|
|
2018-09-18 13:06:28 +00:00
|
|
|
chainService.IncomingBlockFeed()
|
|
|
|
|
2019-01-28 11:59:37 +00:00
|
|
|
// Test the start function.
|
2019-02-13 17:51:57 +00:00
|
|
|
genesisChan := make(chan time.Time, 0)
|
|
|
|
sub := chainService.stateInitializedFeed.Subscribe(genesisChan)
|
|
|
|
defer sub.Unsubscribe()
|
2019-01-28 11:59:37 +00:00
|
|
|
chainService.Start()
|
2019-02-13 17:51:57 +00:00
|
|
|
chainService.chainStartChan <- time.Unix(0, 0)
|
|
|
|
genesisTime := <-genesisChan
|
|
|
|
if genesisTime != time.Unix(0, 0) {
|
|
|
|
t.Errorf(
|
|
|
|
"Expected genesis time to equal chainstart time (%v), received %v",
|
|
|
|
time.Unix(0, 0),
|
|
|
|
genesisTime,
|
|
|
|
)
|
2019-01-28 11:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := chainService.Stop(); err != nil {
|
|
|
|
t.Fatalf("Unable to stop chain service: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// The context should have been canceled.
|
|
|
|
if chainService.ctx.Err() != context.Canceled {
|
|
|
|
t.Error("Context was not canceled")
|
|
|
|
}
|
|
|
|
testutil.AssertLogsContain(t, hook, "Waiting for ChainStart log from the Validator Deposit Contract to start the beacon chain...")
|
|
|
|
testutil.AssertLogsContain(t, hook, "ChainStart time reached, starting the beacon chain!")
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:11:18 +00:00
|
|
|
func TestStartUninitializedChainWithoutConfigPOWChain(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
db := internal.SetupDB(t)
|
|
|
|
defer internal.TeardownDB(t, db)
|
|
|
|
chainService := setupBeaconChain(t, false, db, false)
|
|
|
|
|
|
|
|
origExitFunc := logrus.StandardLogger().ExitFunc
|
|
|
|
defer func() { logrus.StandardLogger().ExitFunc = origExitFunc }()
|
|
|
|
fatal := false
|
|
|
|
logrus.StandardLogger().ExitFunc = func(int) { fatal = true }
|
|
|
|
// Test the start function.
|
|
|
|
chainService.Start()
|
|
|
|
|
|
|
|
if !fatal {
|
|
|
|
t.Fatalf("Not exists fatal for init BeaconChain without POW chain")
|
|
|
|
}
|
|
|
|
testutil.AssertLogsContain(t, hook, "Not configured web3Service for POW chain")
|
|
|
|
}
|
|
|
|
|
2019-01-28 11:59:37 +00:00
|
|
|
func TestStartStopInitializedChain(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
db := internal.SetupDB(t)
|
|
|
|
defer internal.TeardownDB(t, db)
|
2019-02-07 16:11:18 +00:00
|
|
|
chainService := setupBeaconChain(t, false, db, true)
|
2019-01-28 11:59:37 +00:00
|
|
|
|
|
|
|
unixTime := uint64(time.Now().Unix())
|
2019-02-03 22:44:48 +00:00
|
|
|
deposits := setupInitialDeposits(t)
|
|
|
|
if err := db.InitializeState(unixTime, deposits); err != nil {
|
2019-01-28 11:59:37 +00:00
|
|
|
t.Fatalf("Could not initialize beacon state to disk: %v", err)
|
|
|
|
}
|
|
|
|
beaconState, err := db.State()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not fetch beacon state: %v", err)
|
|
|
|
}
|
|
|
|
// TODO(#1389): Replace by state tree hashing algorithm to determine root instead of a hash.
|
|
|
|
hash, err := state.Hash(beaconState)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not hash beacon state: %v", err)
|
|
|
|
}
|
|
|
|
if err := db.SaveBlock(b.NewGenesisBlock(hash[:])); err != nil {
|
|
|
|
t.Fatalf("Could not save genesis block to disk: %v", err)
|
|
|
|
}
|
2018-09-18 13:06:28 +00:00
|
|
|
// Test the start function.
|
2018-08-20 15:50:11 +00:00
|
|
|
chainService.Start()
|
2018-07-19 16:31:50 +00:00
|
|
|
|
2018-08-15 04:49:59 +00:00
|
|
|
if err := chainService.Stop(); err != nil {
|
|
|
|
t.Fatalf("unable to stop chain service: %v", err)
|
2018-07-31 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
2018-07-19 16:31:50 +00:00
|
|
|
// The context should have been canceled.
|
2019-01-28 11:59:37 +00:00
|
|
|
if chainService.ctx.Err() != context.Canceled {
|
2018-07-19 16:31:50 +00:00
|
|
|
t.Error("context was not canceled")
|
|
|
|
}
|
2019-01-28 11:59:37 +00:00
|
|
|
testutil.AssertLogsContain(t, hook, "Beacon chain data already exists, starting service")
|
2018-07-19 16:31:50 +00:00
|
|
|
}
|
2018-08-15 04:49:59 +00:00
|
|
|
|
2018-09-18 13:06:28 +00:00
|
|
|
func TestRunningChainServiceFaultyPOWChain(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
2018-11-07 19:07:41 +00:00
|
|
|
db := internal.SetupDB(t)
|
|
|
|
defer internal.TeardownDB(t, db)
|
2019-02-07 16:11:18 +00:00
|
|
|
chainService := setupBeaconChain(t, true, db, true)
|
2019-01-28 11:59:37 +00:00
|
|
|
unixTime := uint64(time.Now().Unix())
|
2019-02-03 22:44:48 +00:00
|
|
|
deposits := setupInitialDeposits(t)
|
|
|
|
if err := db.InitializeState(unixTime, deposits); err != nil {
|
2019-01-28 11:59:37 +00:00
|
|
|
t.Fatalf("Could not initialize beacon state to disk: %v", err)
|
|
|
|
}
|
2018-09-18 13:06:28 +00:00
|
|
|
|
2018-12-19 05:18:42 +00:00
|
|
|
if err := SetSlotInState(chainService, 1); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-12-20 22:00:38 +00:00
|
|
|
parentBlock := &pb.BeaconBlock{
|
2018-12-19 05:18:42 +00:00
|
|
|
Slot: 1,
|
2018-12-20 22:00:38 +00:00
|
|
|
}
|
2018-12-19 05:18:42 +00:00
|
|
|
|
2019-01-14 16:41:20 +00:00
|
|
|
parentHash, err := hashutil.HashBeaconBlock(parentBlock)
|
2018-12-19 05:18:42 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to hash block %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := chainService.beaconDB.SaveBlock(parentBlock); err != nil {
|
|
|
|
t.Fatalf("Unable to save block %v", err)
|
|
|
|
}
|
|
|
|
|
2018-12-20 22:00:38 +00:00
|
|
|
block := &pb.BeaconBlock{
|
2019-02-02 21:24:42 +00:00
|
|
|
Slot: 2,
|
|
|
|
ParentRootHash32: parentHash[:],
|
|
|
|
Eth1Data: &pb.Eth1Data{
|
|
|
|
DepositRootHash32: []byte("a"),
|
|
|
|
BlockHash32: []byte("b"),
|
|
|
|
},
|
2018-12-20 22:00:38 +00:00
|
|
|
}
|
2018-09-18 13:06:28 +00:00
|
|
|
|
|
|
|
exitRoutine := make(chan bool)
|
|
|
|
go func() {
|
2019-01-28 11:59:37 +00:00
|
|
|
chainService.blockProcessing()
|
2018-09-18 13:06:28 +00:00
|
|
|
<-exitRoutine
|
|
|
|
}()
|
|
|
|
|
2018-10-05 17:14:50 +00:00
|
|
|
if err := chainService.beaconDB.SaveBlock(block); err != nil {
|
2018-09-18 13:06:28 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
chainService.incomingBlockChan <- block
|
|
|
|
chainService.cancel()
|
|
|
|
exitRoutine <- true
|
|
|
|
|
2018-12-19 05:18:42 +00:00
|
|
|
testutil.AssertLogsContain(t, hook, "unable to retrieve POW chain reference block failed")
|
2018-09-18 13:06:28 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 14:07:30 +00:00
|
|
|
func setupGenesisState(t *testing.T, cs *ChainService, beaconState *pb.BeaconState) ([32]byte, *pb.BeaconState) {
|
|
|
|
genesis := b.NewGenesisBlock([]byte{})
|
|
|
|
if err := cs.beaconDB.SaveBlock(genesis); err != nil {
|
|
|
|
t.Fatalf("could not save block to db: %v", err)
|
|
|
|
}
|
|
|
|
parentHash, err := hashutil.HashBeaconBlock(genesis)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to get hash of canonical head: %v", err)
|
|
|
|
}
|
|
|
|
if err := cs.beaconDB.SaveState(beaconState); err != nil {
|
|
|
|
t.Fatalf("Can't save state to db %v", err)
|
|
|
|
}
|
|
|
|
beaconState, err = cs.beaconDB.State()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't get state from db %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return parentHash, beaconState
|
|
|
|
}
|
2018-08-29 00:55:56 +00:00
|
|
|
func TestRunningChainService(t *testing.T) {
|
2018-08-18 03:34:56 +00:00
|
|
|
hook := logTest.NewGlobal()
|
2018-11-07 19:07:41 +00:00
|
|
|
db := internal.SetupDB(t)
|
|
|
|
defer internal.TeardownDB(t, db)
|
2019-02-07 16:11:18 +00:00
|
|
|
chainService := setupBeaconChain(t, false, db, true)
|
2019-01-28 11:59:37 +00:00
|
|
|
unixTime := uint64(time.Now().Unix())
|
2019-02-03 22:44:48 +00:00
|
|
|
deposits := setupInitialDeposits(t)
|
|
|
|
if err := db.InitializeState(unixTime, deposits); err != nil {
|
2019-01-28 11:59:37 +00:00
|
|
|
t.Fatalf("Could not initialize beacon state to disk: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-01-01 17:17:44 +00:00
|
|
|
beaconState, err := state.InitialBeaconState(deposits, 0, nil)
|
2018-08-18 03:34:56 +00:00
|
|
|
if err != nil {
|
2018-09-04 23:18:55 +00:00
|
|
|
t.Fatalf("Can't generate genesis state: %v", err)
|
2018-08-18 03:34:56 +00:00
|
|
|
}
|
2018-12-27 03:15:12 +00:00
|
|
|
beaconState.Slot = 5
|
2018-08-18 03:34:56 +00:00
|
|
|
|
2018-12-23 22:51:04 +00:00
|
|
|
enc, _ := proto.Marshal(beaconState)
|
|
|
|
stateRoot := hashutil.Hash(enc)
|
2019-02-09 14:07:30 +00:00
|
|
|
parentHash, beaconState := setupGenesisState(t, chainService, beaconState)
|
2018-12-19 05:18:42 +00:00
|
|
|
|
2019-02-06 21:46:05 +00:00
|
|
|
validators := make([]*pb.Validator, params.BeaconConfig().DepositsForChainStart)
|
2019-01-30 19:59:33 +00:00
|
|
|
for i := 0; i < len(validators); i++ {
|
2019-02-06 21:46:05 +00:00
|
|
|
validators[i] = &pb.Validator{
|
2019-02-09 20:35:51 +00:00
|
|
|
Pubkey: []byte(strconv.Itoa(i)),
|
|
|
|
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
2019-01-30 19:59:33 +00:00
|
|
|
}
|
2018-12-19 05:18:42 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 19:59:33 +00:00
|
|
|
beaconState.ValidatorRegistry = validators
|
2018-12-19 05:18:42 +00:00
|
|
|
if err := chainService.beaconDB.SaveState(beaconState); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-02-10 22:09:35 +00:00
|
|
|
currentSlot := params.BeaconConfig().GenesisSlot + 5
|
|
|
|
attestationSlot := params.BeaconConfig().GenesisSlot
|
2018-09-21 19:33:53 +00:00
|
|
|
|
2018-12-20 22:00:38 +00:00
|
|
|
block := &pb.BeaconBlock{
|
2019-02-02 21:24:42 +00:00
|
|
|
Slot: currentSlot + 1,
|
|
|
|
StateRootHash32: stateRoot[:],
|
|
|
|
ParentRootHash32: parentHash[:],
|
|
|
|
Eth1Data: &pb.Eth1Data{
|
|
|
|
DepositRootHash32: []byte("a"),
|
|
|
|
BlockHash32: []byte("b"),
|
|
|
|
},
|
2018-12-22 20:30:59 +00:00
|
|
|
Body: &pb.BeaconBlockBody{
|
|
|
|
Attestations: []*pb.Attestation{{
|
2019-02-06 16:20:38 +00:00
|
|
|
AggregationBitfield: []byte{128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2018-12-22 20:30:59 +00:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
|
|
Data: &pb.AttestationData{
|
2019-02-10 17:59:17 +00:00
|
|
|
Slot: attestationSlot,
|
|
|
|
JustifiedBlockRootHash32: params.BeaconConfig().ZeroHash[:],
|
2019-02-10 22:09:35 +00:00
|
|
|
JustifiedEpoch: currentSlot / params.BeaconConfig().EpochLength,
|
|
|
|
LatestCrosslink: &pb.Crosslink{
|
|
|
|
Epoch: currentSlot / params.BeaconConfig().EpochLength,
|
|
|
|
ShardBlockRootHash32: params.BeaconConfig().ZeroHash[:]},
|
2018-12-22 20:30:59 +00:00
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
2018-12-20 22:00:38 +00:00
|
|
|
}
|
2018-08-15 04:49:59 +00:00
|
|
|
|
2018-12-19 05:18:42 +00:00
|
|
|
if err := SetSlotInState(chainService, currentSlot); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-08-25 18:59:46 +00:00
|
|
|
exitRoutine := make(chan bool)
|
|
|
|
go func() {
|
2019-01-28 11:59:37 +00:00
|
|
|
chainService.blockProcessing()
|
2018-08-25 18:59:46 +00:00
|
|
|
<-exitRoutine
|
|
|
|
}()
|
2018-09-18 13:06:28 +00:00
|
|
|
|
2018-10-05 17:14:50 +00:00
|
|
|
if err := chainService.beaconDB.SaveBlock(block); err != nil {
|
2018-08-24 04:09:59 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
chainService.incomingBlockChan <- block
|
2018-08-15 04:49:59 +00:00
|
|
|
chainService.cancel()
|
|
|
|
exitRoutine <- true
|
2018-12-19 05:18:42 +00:00
|
|
|
|
2018-10-14 15:29:57 +00:00
|
|
|
testutil.AssertLogsContain(t, hook, "Chain service context closed, exiting goroutine")
|
2018-12-01 22:09:12 +00:00
|
|
|
testutil.AssertLogsContain(t, hook, "Processed beacon block")
|
2018-09-18 13:06:28 +00:00
|
|
|
}
|
2018-08-25 18:59:46 +00:00
|
|
|
|
2019-02-09 14:07:30 +00:00
|
|
|
func TestReceiveBlock_RemovesPendingDeposits(t *testing.T) {
|
|
|
|
db := internal.SetupDB(t)
|
|
|
|
defer internal.TeardownDB(t, db)
|
|
|
|
chainService := setupBeaconChain(t, false, db, true)
|
|
|
|
unixTime := uint64(time.Now().Unix())
|
|
|
|
deposits := setupInitialDeposits(t)
|
|
|
|
if err := db.InitializeState(unixTime, deposits); err != nil {
|
|
|
|
t.Fatalf("Could not initialize beacon state to disk: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
beaconState, err := state.InitialBeaconState(deposits, 0, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't generate genesis state: %v", err)
|
|
|
|
}
|
2019-02-10 22:09:35 +00:00
|
|
|
beaconState.Slot = params.BeaconConfig().GenesisSlot + 5
|
2019-02-09 14:07:30 +00:00
|
|
|
|
|
|
|
enc, _ := proto.Marshal(beaconState)
|
|
|
|
stateRoot := hashutil.Hash(enc)
|
|
|
|
parentHash, beaconState := setupGenesisState(t, chainService, beaconState)
|
|
|
|
|
|
|
|
validators := make([]*pb.Validator, params.BeaconConfig().DepositsForChainStart)
|
|
|
|
for i := 0; i < len(validators); i++ {
|
|
|
|
validators[i] = &pb.Validator{
|
2019-02-09 20:35:51 +00:00
|
|
|
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
2019-02-09 14:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
beaconState.ValidatorRegistry = validators
|
|
|
|
if err := chainService.beaconDB.SaveState(beaconState); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-02-10 22:09:35 +00:00
|
|
|
currentSlot := params.BeaconConfig().GenesisSlot + 5
|
|
|
|
attestationSlot := params.BeaconConfig().GenesisSlot
|
2019-02-09 14:07:30 +00:00
|
|
|
|
|
|
|
pendingDeposits := []*pb.Deposit{
|
|
|
|
createPreChainStartDeposit(t, []byte{'F'}),
|
|
|
|
}
|
|
|
|
depositTrie := trieutil.NewDepositTrie()
|
|
|
|
for _, pd := range pendingDeposits {
|
|
|
|
depositTrie.UpdateDepositTrie(pd.DepositData)
|
|
|
|
pd.MerkleBranchHash32S = depositTrie.Branch()
|
|
|
|
}
|
|
|
|
depositRoot := depositTrie.Root()
|
|
|
|
beaconState.LatestEth1Data.DepositRootHash32 = depositRoot[:]
|
|
|
|
|
|
|
|
block := &pb.BeaconBlock{
|
|
|
|
Slot: currentSlot + 1,
|
|
|
|
StateRootHash32: stateRoot[:],
|
|
|
|
ParentRootHash32: parentHash[:],
|
|
|
|
Eth1Data: &pb.Eth1Data{
|
|
|
|
DepositRootHash32: []byte("a"),
|
|
|
|
BlockHash32: []byte("b"),
|
|
|
|
},
|
|
|
|
Body: &pb.BeaconBlockBody{
|
|
|
|
Deposits: pendingDeposits,
|
|
|
|
Attestations: []*pb.Attestation{{
|
|
|
|
AggregationBitfield: []byte{128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
|
|
Data: &pb.AttestationData{
|
2019-02-10 17:59:17 +00:00
|
|
|
Slot: attestationSlot,
|
|
|
|
JustifiedBlockRootHash32: params.BeaconConfig().ZeroHash[:],
|
2019-02-10 22:09:35 +00:00
|
|
|
JustifiedEpoch: currentSlot / params.BeaconConfig().EpochLength,
|
|
|
|
LatestCrosslink: &pb.Crosslink{
|
|
|
|
Epoch: currentSlot / params.BeaconConfig().EpochLength,
|
|
|
|
ShardBlockRootHash32: params.BeaconConfig().ZeroHash[:]},
|
2019-02-09 14:07:30 +00:00
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := SetSlotInState(chainService, currentSlot); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, dep := range pendingDeposits {
|
|
|
|
db.InsertPendingDeposit(chainService.ctx, dep, big.NewInt(0))
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(db.PendingDeposits(chainService.ctx, nil)) != len(pendingDeposits) || len(pendingDeposits) == 0 {
|
|
|
|
t.Fatalf("Expected %d pending deposits", len(pendingDeposits))
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = chainService.ReceiveBlock(block, beaconState)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(db.PendingDeposits(chainService.ctx, nil)) != 0 {
|
|
|
|
t.Fatalf("Expected 0 pending deposits, but there are %+v", db.PendingDeposits(chainService.ctx, nil))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 13:06:28 +00:00
|
|
|
func TestDoesPOWBlockExist(t *testing.T) {
|
2018-08-24 04:09:59 +00:00
|
|
|
hook := logTest.NewGlobal()
|
2018-11-07 19:07:41 +00:00
|
|
|
db := internal.SetupDB(t)
|
|
|
|
defer internal.TeardownDB(t, db)
|
2019-02-07 16:11:18 +00:00
|
|
|
chainService := setupBeaconChain(t, true, db, true)
|
2019-01-28 11:59:37 +00:00
|
|
|
unixTime := uint64(time.Now().Unix())
|
2019-02-03 22:44:48 +00:00
|
|
|
deposits := setupInitialDeposits(t)
|
|
|
|
if err := db.InitializeState(unixTime, deposits); err != nil {
|
2019-01-28 11:59:37 +00:00
|
|
|
t.Fatalf("Could not initialize beacon state to disk: %v", err)
|
|
|
|
}
|
2018-08-24 04:09:59 +00:00
|
|
|
|
2019-01-21 09:34:11 +00:00
|
|
|
beaconState, err := chainService.beaconDB.State()
|
2018-12-19 05:18:42 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to retrieve beacon state %v", err)
|
|
|
|
}
|
2018-08-24 04:09:59 +00:00
|
|
|
|
2018-09-18 13:06:28 +00:00
|
|
|
// Using a faulty client should throw error.
|
2019-02-02 21:24:42 +00:00
|
|
|
powHash := bytesutil.ToBytes32(beaconState.LatestEth1Data.DepositRootHash32)
|
2018-12-23 22:51:04 +00:00
|
|
|
exists := chainService.doesPoWBlockExist(powHash)
|
2018-09-18 13:06:28 +00:00
|
|
|
if exists {
|
|
|
|
t.Error("Block corresponding to nil powchain reference should not exist")
|
2018-09-02 16:44:03 +00:00
|
|
|
}
|
2018-09-18 13:06:28 +00:00
|
|
|
testutil.AssertLogsContain(t, hook, "fetching PoW block corresponding to mainchain reference failed")
|
2018-08-15 04:49:59 +00:00
|
|
|
}
|
2018-08-24 16:07:23 +00:00
|
|
|
|
2018-10-18 04:23:18 +00:00
|
|
|
func TestUpdateHead(t *testing.T) {
|
2019-01-01 17:17:44 +00:00
|
|
|
beaconState, err := state.InitialBeaconState(nil, 0, nil)
|
2018-10-18 04:23:18 +00:00
|
|
|
if err != nil {
|
2018-12-23 22:51:04 +00:00
|
|
|
t.Fatalf("Cannot create genesis beacon state: %v", err)
|
2018-10-18 04:23:18 +00:00
|
|
|
}
|
2018-12-23 22:51:04 +00:00
|
|
|
enc, _ := proto.Marshal(beaconState)
|
|
|
|
stateRoot := hashutil.Hash(enc)
|
2018-10-18 04:23:18 +00:00
|
|
|
|
2018-12-20 22:00:38 +00:00
|
|
|
genesis := b.NewGenesisBlock(stateRoot[:])
|
2019-01-14 16:41:20 +00:00
|
|
|
genesisHash, err := hashutil.HashBeaconBlock(genesis)
|
2018-10-18 04:23:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not get genesis block hash: %v", err)
|
|
|
|
}
|
|
|
|
// Table driven tests for various fork choice scenarios.
|
|
|
|
tests := []struct {
|
|
|
|
blockSlot uint64
|
2018-12-23 22:51:04 +00:00
|
|
|
state *pb.BeaconState
|
2018-10-18 04:23:18 +00:00
|
|
|
logAssert string
|
|
|
|
}{
|
|
|
|
// Higher slot but same crystallized state should trigger chain update.
|
|
|
|
{
|
|
|
|
blockSlot: 64,
|
2018-12-01 22:09:12 +00:00
|
|
|
state: beaconState,
|
2018-10-18 04:23:18 +00:00
|
|
|
logAssert: "Chain head block and state updated",
|
|
|
|
},
|
|
|
|
// Higher slot, different crystallized state, but higher last finalized slot.
|
|
|
|
{
|
|
|
|
blockSlot: 64,
|
2019-02-06 16:44:27 +00:00
|
|
|
state: &pb.BeaconState{FinalizedEpoch: 2},
|
2018-10-18 04:23:18 +00:00
|
|
|
logAssert: "Chain head block and state updated",
|
|
|
|
},
|
|
|
|
// Higher slot, different crystallized state, same last finalized slot,
|
|
|
|
// but last justified slot.
|
|
|
|
{
|
|
|
|
blockSlot: 64,
|
2018-12-23 22:51:04 +00:00
|
|
|
state: &pb.BeaconState{
|
2019-02-06 16:44:27 +00:00
|
|
|
FinalizedEpoch: 0,
|
|
|
|
JustifiedEpoch: 2,
|
2018-12-23 22:51:04 +00:00
|
|
|
},
|
2018-10-18 04:23:18 +00:00
|
|
|
logAssert: "Chain head block and state updated",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
hook := logTest.NewGlobal()
|
2018-11-07 19:07:41 +00:00
|
|
|
db := internal.SetupDB(t)
|
|
|
|
defer internal.TeardownDB(t, db)
|
2019-02-07 16:11:18 +00:00
|
|
|
chainService := setupBeaconChain(t, false, db, true)
|
2019-01-28 11:59:37 +00:00
|
|
|
unixTime := uint64(time.Now().Unix())
|
2019-02-03 22:44:48 +00:00
|
|
|
deposits := setupInitialDeposits(t)
|
|
|
|
if err := db.InitializeState(unixTime, deposits); err != nil {
|
2019-01-28 11:59:37 +00:00
|
|
|
t.Fatalf("Could not initialize beacon state to disk: %v", err)
|
|
|
|
}
|
2018-10-18 04:23:18 +00:00
|
|
|
|
2018-12-23 22:51:04 +00:00
|
|
|
enc, _ := proto.Marshal(tt.state)
|
|
|
|
stateRoot := hashutil.Hash(enc)
|
2018-12-20 22:00:38 +00:00
|
|
|
block := &pb.BeaconBlock{
|
2019-02-02 21:24:42 +00:00
|
|
|
Slot: tt.blockSlot,
|
|
|
|
StateRootHash32: stateRoot[:],
|
|
|
|
ParentRootHash32: genesisHash[:],
|
|
|
|
Eth1Data: &pb.Eth1Data{
|
|
|
|
DepositRootHash32: []byte("a"),
|
|
|
|
BlockHash32: []byte("b"),
|
|
|
|
},
|
2018-12-20 22:00:38 +00:00
|
|
|
}
|
2019-01-28 11:59:37 +00:00
|
|
|
if err := chainService.beaconDB.SaveBlock(block); err != nil {
|
2018-10-18 04:23:18 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-01-28 11:59:37 +00:00
|
|
|
if err := chainService.ApplyForkChoiceRule(block, tt.state); err != nil {
|
|
|
|
t.Errorf("Expected head to update, received %v", err)
|
|
|
|
}
|
2018-10-18 04:23:18 +00:00
|
|
|
|
|
|
|
if err := chainService.beaconDB.SaveBlock(block); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
chainService.cancel()
|
|
|
|
testutil.AssertLogsContain(t, hook, tt.logAssert)
|
|
|
|
}
|
|
|
|
}
|
2018-11-11 16:54:17 +00:00
|
|
|
|
2018-12-19 05:18:42 +00:00
|
|
|
func TestIsBlockReadyForProcessing(t *testing.T) {
|
|
|
|
db := internal.SetupDB(t)
|
|
|
|
defer internal.TeardownDB(t, db)
|
2019-02-07 16:11:18 +00:00
|
|
|
chainService := setupBeaconChain(t, false, db, true)
|
2019-01-28 11:59:37 +00:00
|
|
|
unixTime := uint64(time.Now().Unix())
|
2019-02-03 22:44:48 +00:00
|
|
|
deposits := setupInitialDeposits(t)
|
|
|
|
if err := db.InitializeState(unixTime, deposits); err != nil {
|
2019-01-28 11:59:37 +00:00
|
|
|
t.Fatalf("Could not initialize beacon state to disk: %v", err)
|
2019-01-09 23:49:50 +00:00
|
|
|
}
|
2019-01-21 09:34:11 +00:00
|
|
|
beaconState, err := db.State()
|
2019-01-09 23:49:50 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't get genesis state: %v", err)
|
2018-12-19 05:18:42 +00:00
|
|
|
}
|
2018-12-20 22:00:38 +00:00
|
|
|
block := &pb.BeaconBlock{
|
2018-12-19 05:18:42 +00:00
|
|
|
ParentRootHash32: []byte{'a'},
|
2018-12-20 22:00:38 +00:00
|
|
|
}
|
2018-12-19 05:18:42 +00:00
|
|
|
|
2019-01-06 05:05:16 +00:00
|
|
|
if err := chainService.isBlockReadyForProcessing(block, beaconState); err == nil {
|
2018-12-19 05:18:42 +00:00
|
|
|
t.Fatal("block processing succeeded despite block having no parent saved")
|
|
|
|
}
|
|
|
|
|
2018-12-23 22:51:04 +00:00
|
|
|
beaconState.Slot = 10
|
2018-12-19 05:18:42 +00:00
|
|
|
|
2018-12-23 22:51:04 +00:00
|
|
|
enc, _ := proto.Marshal(beaconState)
|
|
|
|
stateRoot := hashutil.Hash(enc)
|
2018-12-20 22:00:38 +00:00
|
|
|
genesis := b.NewGenesisBlock([]byte{})
|
2018-12-23 22:51:04 +00:00
|
|
|
if err := chainService.beaconDB.SaveBlock(genesis); err != nil {
|
|
|
|
t.Fatalf("cannot save block: %v", err)
|
|
|
|
}
|
2019-01-14 16:41:20 +00:00
|
|
|
parentHash, err := hashutil.HashBeaconBlock(genesis)
|
2018-12-19 05:18:42 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to get hash of canonical head: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-12-20 22:00:38 +00:00
|
|
|
block2 := &pb.BeaconBlock{
|
2018-12-19 05:18:42 +00:00
|
|
|
ParentRootHash32: parentHash[:],
|
|
|
|
Slot: 10,
|
2018-12-20 22:00:38 +00:00
|
|
|
}
|
2018-12-19 05:18:42 +00:00
|
|
|
|
2019-01-06 05:05:16 +00:00
|
|
|
if err := chainService.isBlockReadyForProcessing(block2, beaconState); err == nil {
|
2018-12-19 05:18:42 +00:00
|
|
|
t.Fatal("block processing succeeded despite block slot being invalid")
|
|
|
|
}
|
|
|
|
|
2019-02-02 21:24:42 +00:00
|
|
|
beaconState.LatestEth1Data = &pb.Eth1Data{
|
|
|
|
DepositRootHash32: []byte{2},
|
|
|
|
BlockHash32: []byte{3},
|
|
|
|
}
|
2018-12-23 22:51:04 +00:00
|
|
|
beaconState.Slot = 0
|
2018-12-19 05:18:42 +00:00
|
|
|
|
2018-12-23 22:51:04 +00:00
|
|
|
currentSlot := uint64(1)
|
2018-12-19 05:18:42 +00:00
|
|
|
attestationSlot := uint64(0)
|
|
|
|
|
2018-12-20 22:00:38 +00:00
|
|
|
block3 := &pb.BeaconBlock{
|
2019-02-02 21:24:42 +00:00
|
|
|
Slot: currentSlot,
|
|
|
|
StateRootHash32: stateRoot[:],
|
|
|
|
ParentRootHash32: parentHash[:],
|
|
|
|
Eth1Data: &pb.Eth1Data{
|
|
|
|
DepositRootHash32: []byte("a"),
|
|
|
|
BlockHash32: []byte("b"),
|
|
|
|
},
|
2018-12-22 20:30:59 +00:00
|
|
|
Body: &pb.BeaconBlockBody{
|
|
|
|
Attestations: []*pb.Attestation{{
|
2019-02-06 16:20:38 +00:00
|
|
|
AggregationBitfield: []byte{128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2018-12-22 20:30:59 +00:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
|
|
Data: &pb.AttestationData{
|
|
|
|
Slot: attestationSlot,
|
|
|
|
JustifiedBlockRootHash32: parentHash[:],
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
2018-12-20 22:00:38 +00:00
|
|
|
}
|
2018-12-19 05:18:42 +00:00
|
|
|
|
|
|
|
chainService.enablePOWChain = true
|
|
|
|
|
2019-01-06 05:05:16 +00:00
|
|
|
if err := chainService.isBlockReadyForProcessing(block3, beaconState); err != nil {
|
2018-12-23 22:51:04 +00:00
|
|
|
t.Fatalf("block processing failed despite being a valid block: %v", err)
|
2018-12-19 05:18:42 +00:00
|
|
|
}
|
|
|
|
}
|