Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rm signing root #4381

Merged
merged 8 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "069880d4864e303ad8fca0ecbe61a1e0f2174a7935bbd22bfdfdd7cad34ae9cd",
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.9.2/general.tar.gz",
sha256 = "72c6ee3c20d19736b1203f364a6eb0ddee2c173073e20bee2beccd288fdc42be",
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.9.4/general.tar.gz",
)

http_archive(
Expand All @@ -165,8 +165,8 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "e71a8b5bef94bba04b8897101a3eb76f2c6de14295eb8b23261b570b3ba1e485",
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.9.2/minimal.tar.gz",
sha256 = "a3cc860a3679f6f62ee57b65677a9b48a65fdebb151cdcbf50f23852632845ef",
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.9.4/minimal.tar.gz",
)

http_archive(
Expand All @@ -181,8 +181,8 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
sha256 = "32c8921bdd469b7de99b8f4d3128e8fbb7da7212fd4aaecec69be42f7ed5493a",
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.9.2/mainnet.tar.gz",
sha256 = "8fc1b6220973ca30fa4ddc4ed24d66b1719abadca8bedb5e06c3bd9bc0df28e9",
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v0.9.4/mainnet.tar.gz",
)

http_archive(
Expand Down Expand Up @@ -259,7 +259,7 @@ go_repository(

go_repository(
name = "com_github_prysmaticlabs_go_ssz",
commit = "142dfef39d12ed28360b7d2467b056b0578684f5",
commit = "e24db4d9e9637cf88ee9e4a779e339a1686a84ee",
importpath = "github.com/prysmaticlabs/go-ssz",
)

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

go_repository(
name = "com_github_prysmaticlabs_ethereumapis",
commit = "7f7fdda3e5aff8b262f6260657c31b7d633eadf2",
commit = "87118fb893cc6f32b25793d819790fd3bcce3221",
importpath = "github.com/prysmaticlabs/ethereumapis",
patch_args = ["-p1"],
patches = [
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/blockchain/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GenesisTimeFetcher interface {
type HeadFetcher interface {
HeadSlot() uint64
HeadRoot() []byte
HeadBlock() *ethpb.BeaconBlock
HeadBlock() *ethpb.SignedBeaconBlock
HeadState(ctx context.Context) (*pb.BeaconState, error)
HeadValidatorsIndices(epoch uint64) ([]uint64, error)
HeadSeed(epoch uint64) ([32]byte, error)
Expand Down Expand Up @@ -122,11 +122,11 @@ func (s *Service) HeadRoot() []byte {
}

// HeadBlock returns the head block of the chain.
func (s *Service) HeadBlock() *ethpb.BeaconBlock {
func (s *Service) HeadBlock() *ethpb.SignedBeaconBlock {
s.headLock.RLock()
defer s.headLock.RUnlock()

return proto.Clone(s.headBlock).(*ethpb.BeaconBlock)
return proto.Clone(s.headBlock).(*ethpb.SignedBeaconBlock)
}

// HeadState returns the head state of the chain.
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/blockchain/chain_info_norace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestHeadSlot_DataRace(t *testing.T) {
go func() {
s.saveHead(
context.Background(),
&ethpb.BeaconBlock{Slot: 777},
&ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 777}},
[32]byte{},
)
}()
Expand All @@ -35,7 +35,7 @@ func TestHeadRoot_DataRace(t *testing.T) {
go func() {
s.saveHead(
context.Background(),
&ethpb.BeaconBlock{Slot: 777},
&ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 777}},
[32]byte{},
)
}()
Expand All @@ -52,7 +52,7 @@ func TestHeadBlock_DataRace(t *testing.T) {
go func() {
s.saveHead(
context.Background(),
&ethpb.BeaconBlock{Slot: 777},
&ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 777}},
[32]byte{},
)
}()
Expand All @@ -69,7 +69,7 @@ func TestHeadState_DataRace(t *testing.T) {
go func() {
s.saveHead(
context.Background(),
&ethpb.BeaconBlock{Slot: 777},
&ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 777}},
[32]byte{},
)
}()
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/chain_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestHeadRoot_CanRetrieve(t *testing.T) {
}

func TestHeadBlock_CanRetrieve(t *testing.T) {
b := &ethpb.BeaconBlock{Slot: 1}
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1}}
c := &Service{headBlock: b}
if !reflect.DeepEqual(b, c.HeadBlock()) {
t.Error("incorrect head block received")
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/forkchoice/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func BenchmarkForkChoiceTree1(b *testing.B) {

store := NewForkChoiceService(ctx, db)

roots, err := blockTree1(db)
roots, err := blockTree1(db, []byte{'g'})
if err != nil {
b.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/blockchain/forkchoice/lmd_ghost_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func TestGetHeadFromYaml(t *testing.T) {
// genesis block condition
if blk.ID == blk.Parent {
b := &ethpb.BeaconBlock{Slot: 0, ParentRoot: []byte{'g'}}
if err := db.SaveBlock(ctx, b); err != nil {
if err := db.SaveBlock(ctx, &ethpb.SignedBeaconBlock{Block: b}); err != nil {
t.Fatal(err)
}
root, err := ssz.SigningRoot(b)
root, err := ssz.HashTreeRoot(b)
if err != nil {
t.Fatal(err)
}
Expand All @@ -65,11 +65,11 @@ func TestGetHeadFromYaml(t *testing.T) {
if err != nil {
t.Fatal(err)
}
b := &ethpb.BeaconBlock{Slot: uint64(slot), ParentRoot: blksRoot[parentSlot]}
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: uint64(slot), ParentRoot: blksRoot[parentSlot]}}
if err := db.SaveBlock(ctx, b); err != nil {
t.Fatal(err)
}
root, err := ssz.SigningRoot(b)
root, err := ssz.HashTreeRoot(b.Block)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/blockchain/forkchoice/process_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ func (s *Store) verifyBeaconBlock(ctx context.Context, data *ethpb.AttestationDa
if err != nil {
return err
}
if b == nil {
if b == nil || b.Block == nil {
return fmt.Errorf("beacon block %#x does not exist", bytesutil.Trunc(data.BeaconBlockRoot))
}
if b.Slot > data.Slot {
return fmt.Errorf("could not process attestation for future block, %d > %d", b.Slot, data.Slot)
if b.Block.Slot > data.Slot {
return fmt.Errorf("could not process attestation for future block, %d > %d", b.Block.Slot, data.Slot)
}
return nil
}
Expand Down
22 changes: 11 additions & 11 deletions beacon-chain/blockchain/forkchoice/process_attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ func TestStore_OnAttestation(t *testing.T) {

store := NewForkChoiceService(ctx, db)

_, err := blockTree1(db)
_, err := blockTree1(db, []byte{'g'})
if err != nil {
t.Fatal(err)
}

BlkWithOutState := &ethpb.BeaconBlock{Slot: 0}
BlkWithOutState := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 0}}
if err := db.SaveBlock(ctx, BlkWithOutState); err != nil {
t.Fatal(err)
}
BlkWithOutStateRoot, _ := ssz.SigningRoot(BlkWithOutState)
BlkWithOutStateRoot, _ := ssz.HashTreeRoot(BlkWithOutState.Block)

BlkWithStateBadAtt := &ethpb.BeaconBlock{Slot: 1}
BlkWithStateBadAtt := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 1}}
if err := db.SaveBlock(ctx, BlkWithStateBadAtt); err != nil {
t.Fatal(err)
}
BlkWithStateBadAttRoot, _ := ssz.SigningRoot(BlkWithStateBadAtt)
BlkWithStateBadAttRoot, _ := ssz.HashTreeRoot(BlkWithStateBadAtt.Block)
if err := store.db.SaveState(ctx, &pb.BeaconState{}, BlkWithStateBadAttRoot); err != nil {
t.Fatal(err)
}

BlkWithValidState := &ethpb.BeaconBlock{Slot: 2}
BlkWithValidState := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 2}}
if err := db.SaveBlock(ctx, BlkWithValidState); err != nil {
t.Fatal(err)
}
BlkWithValidStateRoot, _ := ssz.SigningRoot(BlkWithValidState)
BlkWithValidStateRoot, _ := ssz.HashTreeRoot(BlkWithValidState.Block)
if err := store.db.SaveState(ctx, &pb.BeaconState{
Fork: &pb.Fork{
Epoch: 0,
Expand Down Expand Up @@ -342,9 +342,9 @@ func TestVerifyBeaconBlock_futureBlock(t *testing.T) {
defer testDB.TeardownDB(t, db)

s := NewForkChoiceService(ctx, db)
b := &ethpb.BeaconBlock{Slot: 2}
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 2}}
s.db.SaveBlock(ctx, b)
r, _ := ssz.SigningRoot(b)
r, _ := ssz.HashTreeRoot(b.Block)
d := &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: r[:]}

if err := s.verifyBeaconBlock(ctx, d); !strings.Contains(err.Error(), "could not process attestation for future block") {
Expand All @@ -358,9 +358,9 @@ func TestVerifyBeaconBlock_OK(t *testing.T) {
defer testDB.TeardownDB(t, db)

s := NewForkChoiceService(ctx, db)
b := &ethpb.BeaconBlock{Slot: 2}
b := &ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Slot: 2}}
s.db.SaveBlock(ctx, b)
r, _ := ssz.SigningRoot(b)
r, _ := ssz.HashTreeRoot(b.Block)
d := &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: r[:]}

if err := s.verifyBeaconBlock(ctx, d); err != nil {
Expand Down
47 changes: 34 additions & 13 deletions beacon-chain/blockchain/forkchoice/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,40 @@ import (
// # Update finalized checkpoint
// if state.finalized_checkpoint.epoch > store.finalized_checkpoint.epoch:
// store.finalized_checkpoint = state.finalized_checkpoint
func (s *Store) OnBlock(ctx context.Context, b *ethpb.BeaconBlock) error {
func (s *Store) OnBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) error {
ctx, span := trace.StartSpan(ctx, "forkchoice.onBlock")
defer span.End()

if signed == nil || signed.Block == nil {
return errors.New("nil block")
}

b := signed.Block

// Retrieve incoming block's pre state.
preState, err := s.getBlockPreState(ctx, b)
if err != nil {
return err
}
preStateValidatorCount := len(preState.Validators)

root, err := ssz.SigningRoot(b)
root, err := ssz.HashTreeRoot(b)
if err != nil {
return errors.Wrapf(err, "could not get signing root of block %d", b.Slot)
}
log.WithFields(logrus.Fields{
"slot": b.Slot,
"root": fmt.Sprintf("0x%s...", hex.EncodeToString(root[:])[:8]),
}).Info("Executing state transition on block")
postState, err := state.ExecuteStateTransition(ctx, preState, b)
postState, err := state.ExecuteStateTransition(ctx, preState, signed)
if err != nil {
return errors.Wrap(err, "could not execute state transition")
}
if err := s.updateBlockAttestationsVotes(ctx, b.Body.Attestations); err != nil {
return errors.Wrap(err, "could not update votes for attestations in block")
}

if err := s.db.SaveBlock(ctx, b); err != nil {
if err := s.db.SaveBlock(ctx, signed); err != nil {
return errors.Wrapf(err, "could not save block from slot %d", b.Slot)
}
if err := s.db.SaveState(ctx, postState, root); err != nil {
Expand Down Expand Up @@ -151,10 +157,16 @@ func (s *Store) OnBlock(ctx context.Context, b *ethpb.BeaconBlock) error {
// It runs state transition on the block and without any BLS verification. The BLS verification
// includes proposer signature, randao and attestation's aggregated signature. It also does not save
// attestations.
func (s *Store) OnBlockInitialSyncStateTransition(ctx context.Context, b *ethpb.BeaconBlock) error {
func (s *Store) OnBlockInitialSyncStateTransition(ctx context.Context, signed *ethpb.SignedBeaconBlock) error {
ctx, span := trace.StartSpan(ctx, "forkchoice.onBlock")
defer span.End()

if signed == nil || signed.Block == nil {
return errors.New("nil block")
}

b := signed.Block

s.initSyncStateLock.Lock()
defer s.initSyncStateLock.Unlock()

Expand All @@ -167,15 +179,15 @@ func (s *Store) OnBlockInitialSyncStateTransition(ctx context.Context, b *ethpb.

log.WithField("slot", b.Slot).Debug("Executing state transition on block")

postState, err := state.ExecuteStateTransitionNoVerify(ctx, preState, b)
postState, err := state.ExecuteStateTransitionNoVerify(ctx, preState, signed)
if err != nil {
return errors.Wrap(err, "could not execute state transition")
}

if err := s.db.SaveBlock(ctx, b); err != nil {
if err := s.db.SaveBlock(ctx, signed); err != nil {
return errors.Wrapf(err, "could not save block from slot %d", b.Slot)
}
root, err := ssz.SigningRoot(b)
root, err := ssz.HashTreeRoot(b)
if err != nil {
return errors.Wrapf(err, "could not get signing root of block %d", b.Slot)
}
Expand Down Expand Up @@ -349,10 +361,11 @@ func (s *Store) verifyBlkDescendant(ctx context.Context, root [32]byte, slot uin
ctx, span := trace.StartSpan(ctx, "forkchoice.verifyBlkDescendant")
defer span.End()

finalizedBlk, err := s.db.Block(ctx, bytesutil.ToBytes32(s.finalizedCheckpt.Root))
if err != nil || finalizedBlk == nil {
finalizedBlkSigned, err := s.db.Block(ctx, bytesutil.ToBytes32(s.finalizedCheckpt.Root))
if err != nil || finalizedBlkSigned == nil || finalizedBlkSigned.Block == nil {
return errors.Wrap(err, "could not get finalized block")
}
finalizedBlk := finalizedBlkSigned.Block

bFinalizedRoot, err := s.ancestor(ctx, root[:], finalizedBlk.Slot)
if err != nil {
Expand Down Expand Up @@ -481,17 +494,25 @@ func (s *Store) shouldUpdateCurrentJustified(ctx context.Context, newJustifiedCh
if helpers.SlotsSinceEpochStarts(s.currentSlot()) < params.BeaconConfig().SafeSlotsToUpdateJustified {
return true, nil
}
newJustifiedBlock, err := s.db.Block(ctx, bytesutil.ToBytes32(newJustifiedCheckpt.Root))
if err != nil || newJustifiedBlock == nil {
newJustifiedBlockSigned, err := s.db.Block(ctx, bytesutil.ToBytes32(newJustifiedCheckpt.Root))
if err != nil {
return false, err
}
if newJustifiedBlockSigned == nil || newJustifiedBlockSigned.Block == nil {
return false, errors.New("nil new justified block")
}
newJustifiedBlock := newJustifiedBlockSigned.Block
if newJustifiedBlock.Slot <= helpers.StartSlot(s.justifiedCheckpt.Epoch) {
return false, nil
}
justifiedBlock, err := s.db.Block(ctx, bytesutil.ToBytes32(s.justifiedCheckpt.Root))
justifiedBlockSigned, err := s.db.Block(ctx, bytesutil.ToBytes32(s.justifiedCheckpt.Root))
if err != nil {
return false, err
}
if justifiedBlockSigned == nil || justifiedBlockSigned.Block == nil {
return false, errors.New("nil justified block")
}
justifiedBlock := justifiedBlockSigned.Block
b, err := s.ancestor(ctx, newJustifiedCheckpt.Root, justifiedBlock.Slot)
if err != nil {
return false, err
Expand Down
Loading