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

Refactor Core/Types Package to Align With Spec #1021

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
904a7cc
begin major refactor starting with attestations
rauljordan Nov 24, 2018
450f986
db package full refactor
rauljordan Nov 24, 2018
98712bc
simulator full refactor done
rauljordan Nov 24, 2018
255d8a9
initial sync passes
rauljordan Nov 24, 2018
10ef557
all rpc tests passing
rauljordan Nov 24, 2018
853e891
almost done with blockchain refactor
rauljordan Nov 24, 2018
72e0bb9
need to add block validity conditions, then make blockchain tests pas…
rauljordan Nov 25, 2018
762b9a1
cleaned up validity conditions file in core
rauljordan Nov 25, 2018
65834d4
update proto
rauljordan Nov 25, 2018
f061029
yay it buildssssss
rauljordan Nov 25, 2018
ce63cfa
fix test
rauljordan Nov 25, 2018
304b715
tests pass
rauljordan Nov 25, 2018
8d17827
shuffle stream fixed
rauljordan Nov 25, 2018
0329de8
merge master
rauljordan Nov 25, 2018
0112f42
fix lint
rauljordan Nov 25, 2018
bccd4b1
readd most blockchain tests
rauljordan Nov 26, 2018
868bfec
added rest of the blockchain tests
rauljordan Nov 26, 2018
a70d822
Merge branch 'master' into single-state-refactor
rauljordan Nov 26, 2018
8dba7e5
readd pubkey
rauljordan Nov 26, 2018
7881e30
Merge branch 'single-state-refactor' of github.com:rauljordan/prysm i…
rauljordan Nov 26, 2018
55d03aa
validity conditions tests
rauljordan Nov 26, 2018
feaa34b
Merge branch 'master' into single-state-refactor
rauljordan Nov 26, 2018
1d283c0
added block tests
rauljordan Nov 26, 2018
5e8e6ca
block test
rauljordan Nov 26, 2018
e1ce8bf
Merge branch 'single-state-refactor' of github.com:rauljordan/prysm i…
rauljordan Nov 26, 2018
326f151
Merge branch 'master' into single-state-refactor
rauljordan Nov 28, 2018
1293d55
Merge branch 'master' into single-state-refactor
rauljordan Nov 28, 2018
d3d790e
gazelle add
rauljordan Nov 28, 2018
4356e62
Merge branch 'single-state-refactor' of github.com:rauljordan/prysm i…
rauljordan Nov 28, 2018
4d99331
Merge branch 'master' into single-state-refactor
rauljordan Nov 28, 2018
981a1ca
Merge branch 'master' into single-state-refactor
rauljordan Nov 28, 2018
d668940
define proto types according to spec
rauljordan Nov 28, 2018
0b1d113
fix dependency in dbcleanup
rauljordan Nov 28, 2018
275ffdb
Merge branch 'single-state-refactor' into type-fixes
rauljordan Nov 28, 2018
04bf3f0
Merge branch 'master' into single-state-refactor
rauljordan Nov 28, 2018
218f738
Merge branch 'single-state-refactor' into type-fixes
rauljordan Nov 28, 2018
643a740
types tests passing
rauljordan Nov 28, 2018
27e3e27
added more setters
rauljordan Nov 28, 2018
7d3dade
added getters for justification
rauljordan Nov 28, 2018
5884249
defined attestation record type instead with the ability to create pr…
rauljordan Nov 29, 2018
44f87e6
fix types tests and building
rauljordan Nov 29, 2018
948bd7d
add processed att proto
rauljordan Nov 29, 2018
b091e08
fix att types
rauljordan Nov 29, 2018
e99fb3f
fixes done
rauljordan Nov 29, 2018
7ed8f84
fix some review comments
rauljordan Nov 29, 2018
c4d9185
merge confs fixed
rauljordan Dec 1, 2018
f096df3
gazelle
rauljordan Dec 1, 2018
aaed96e
fixed errors
rauljordan Dec 1, 2018
27fce5d
fix att
rauljordan Dec 1, 2018
6cdf372
fix test
rauljordan Dec 1, 2018
d5aa222
core/types passing
rauljordan Dec 1, 2018
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
2 changes: 0 additions & 2 deletions beacon-chain/core/types/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ go_library(
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
],
Expand All @@ -33,7 +32,6 @@ go_test(
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//shared/params:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
],
)
9 changes: 1 addition & 8 deletions beacon-chain/core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"fmt"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/prysmaticlabs/prysm/beacon-chain/utils"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
Expand All @@ -30,7 +29,6 @@ func NewBlock(data *pb.BeaconBlock) *Block {
data: &pb.BeaconBlock{
AncestorHashes: ancestorHashes,
RandaoReveal: []byte{0},
PowChainRef: []byte{0},
StateRoot: []byte{0},
Specials: []*pb.SpecialRecord{},
},
Expand Down Expand Up @@ -102,11 +100,6 @@ func (b *Block) Attestations() []*pb.AggregatedAttestation {
return b.data.Attestations
}

// PowChainRef returns a keccak256 hash corresponding to a PoW chain block.
func (b *Block) PowChainRef() common.Hash {
return common.BytesToHash(b.data.PowChainRef)
}

// RandaoReveal returns the blake2b randao hash.
func (b *Block) RandaoReveal() [32]byte {
var h [32]byte
Expand Down
5 changes: 0 additions & 5 deletions beacon-chain/core/types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"reflect"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/golang/protobuf/ptypes"
"github.com/prysmaticlabs/prysm/shared/params"
)
Expand Down Expand Up @@ -43,10 +42,6 @@ func TestGenesisBlock(t *testing.T) {
t.Error("genesis block missing RandaoReveal field")
}

if b1.PowChainRef() != common.BytesToHash([]byte{}) {
t.Error("genesis block missing PowChainRef field")
}

if b1.StateRoot() != stateHash {
t.Error("genesis block StateRoot isn't initialized correctly")
}
Expand Down
112 changes: 68 additions & 44 deletions beacon-chain/core/types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/proto"
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/hashutil"
Expand Down Expand Up @@ -55,19 +55,19 @@ func NewGenesisBeaconState(genesisValidators []*pb.ValidatorRecord) (*BeaconStat
return &BeaconState{
data: &pb.BeaconState{
LastStateRecalculationSlot: 0,
JustifiedStreak: 0,
LastJustifiedSlot: 0,
LastFinalizedSlot: 0,
ValidatorSetChangeSlot: 0,
ForkSlotNumber: 0,
Crosslinks: crosslinks,
Validators: genesisValidators,
ShardAndCommitteesForSlots: shardAndCommitteesForSlots,
PreForkVersion: uint64(params.BeaconConfig().InitialForkVersion),
PostForkVersion: uint64(params.BeaconConfig().InitialForkVersion),
PendingAttestations: []*pb.AggregatedAttestation{},
RecentBlockHashes: recentBlockHashes,
RandaoMix: make([]byte, 0, 32),
ForkData: &pb.ForkData{
PreForkVersion: uint64(params.BeaconConfig().InitialForkVersion),
PostForkVersion: uint64(params.BeaconConfig().InitialForkVersion),
ForkSlotNumber: 0,
},
PendingAttestations: []*pb.ProcessedAttestation{},
RecentBlockHashes: recentBlockHashes,
RandaoMix: make([]byte, 0, 32),
},
}, nil
}
Expand All @@ -85,13 +85,12 @@ func (b *BeaconState) CopyState() *BeaconState {
validators := make([]*pb.ValidatorRecord, len(b.Validators()))
for index, validator := range b.Validators() {
validators[index] = &pb.ValidatorRecord{
Pubkey: validator.GetPubkey(),
WithdrawalShard: validator.GetWithdrawalShard(),
WithdrawalAddress: validator.GetWithdrawalAddress(),
RandaoCommitment: validator.GetRandaoCommitment(),
Balance: validator.GetBalance(),
Status: validator.GetStatus(),
ExitSlot: validator.GetExitSlot(),
Pubkey: validator.GetPubkey(),
WithdrawalCredentials: validator.GetWithdrawalCredentials(),
RandaoCommitment: validator.GetRandaoCommitment(),
Balance: validator.GetBalance(),
Status: validator.GetStatus(),
LastStatusChangeSlot: validator.GetLastStatusChangeSlot(),
}
}

Expand All @@ -111,17 +110,18 @@ func (b *BeaconState) CopyState() *BeaconState {

newState := BeaconState{&pb.BeaconState{
LastStateRecalculationSlot: b.LastStateRecalculationSlot(),
JustifiedStreak: b.JustifiedStreak(),
LastJustifiedSlot: b.LastJustifiedSlot(),
LastFinalizedSlot: b.LastFinalizedSlot(),
ValidatorSetChangeSlot: b.ValidatorSetChangeSlot(),
Crosslinks: crosslinks,
Validators: validators,
ShardAndCommitteesForSlots: shardAndCommitteesForSlots,
DepositsPenalizedInPeriod: b.DepositsPenalizedInPeriod(),
PreForkVersion: b.data.PreForkVersion,
PostForkVersion: b.data.PostForkVersion,
ForkSlotNumber: b.data.ForkSlotNumber,
PendingAttestations: b.PendingAttestations(),
ForkData: &pb.ForkData{
PreForkVersion: b.data.ForkData.PreForkVersion,
PostForkVersion: b.data.ForkData.PostForkVersion,
ForkSlotNumber: b.data.ForkData.ForkSlotNumber,
},
}}

return &newState
Expand Down Expand Up @@ -199,6 +199,23 @@ func (b *BeaconState) Validators() []*pb.ValidatorRecord {
return b.data.Validators
}

// JustifiedSlotBitfield returns the bitfield of justified slots corresponding to
// this beacon block.
func (b *BeaconState) JustifiedSlotBitfield() []byte {
return b.data.JustifiedSlotBitfield
}

// JustificationSource returns the beacon block's justification source.
func (b *BeaconState) JustificationSource() uint64 {
return b.data.JustificationSource
}

// PrevCycleJustificationSource returns the previous cycle's justification source
// for this block.
func (b *BeaconState) PrevCycleJustificationSource() uint64 {
return b.data.PrevCycleJustificationSource
}

// LastStateRecalculationSlot returns when the last time crystallized state recalculated.
func (b *BeaconState) LastStateRecalculationSlot() uint64 {
return b.data.LastStateRecalculationSlot
Expand All @@ -209,34 +226,24 @@ func (b *BeaconState) LastFinalizedSlot() uint64 {
return b.data.LastFinalizedSlot
}

// LastJustifiedSlot return the last justified slot of the beacon chain.
func (b *BeaconState) LastJustifiedSlot() uint64 {
return b.data.LastJustifiedSlot
}

// JustifiedStreak returns number of consecutive justified slots ending at head.
func (b *BeaconState) JustifiedStreak() uint64 {
return b.data.JustifiedStreak
}

// DepositsPenalizedInPeriod returns total deposits penalized in the given withdrawal period.
func (b *BeaconState) DepositsPenalizedInPeriod() []uint64 {
return b.data.DepositsPenalizedInPeriod
}

// ForkSlotNumber returns the slot of last fork.
func (b *BeaconState) ForkSlotNumber() uint64 {
return b.data.ForkSlotNumber
return b.data.ForkData.ForkSlotNumber
}

// PreForkVersion returns the last pre fork version.
func (b *BeaconState) PreForkVersion() uint64 {
return b.data.PreForkVersion
return b.data.ForkData.PreForkVersion
}

// PostForkVersion returns the last post fork version.
func (b *BeaconState) PostForkVersion() uint64 {
return b.data.PostForkVersion
return b.data.ForkData.PostForkVersion
}

// RecentBlockHashes returns the most recent 2*EPOCH_LENGTH block hashes.
Expand All @@ -249,7 +256,7 @@ func (b *BeaconState) RecentBlockHashes() [][32]byte {
}

// PendingAttestations returns attestations that have not yet been processed.
func (b *BeaconState) PendingAttestations() []*pb.AggregatedAttestation {
func (b *BeaconState) PendingAttestations() []*pb.ProcessedAttestation {
return b.data.PendingAttestations
}

Expand Down Expand Up @@ -277,6 +284,14 @@ func (b *BeaconState) PenalizedETH(period uint64) uint64 {
return totalPenalty
}

<<<<<<< HEAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have merge conflict here

// ClearAttestations removes attestations older than last state recalc slot.
func (b *BeaconState) ClearAttestations(lastStateRecalc uint64) {
existing := b.data.PendingAttestations
update := make([]*pb.ProcessedAttestation, 0, len(existing))
for _, a := range existing {
if a.SignedData.Slot >= lastStateRecalc {
=======
// SignedParentHashes returns all the parent hashes stored in active state up to last cycle length.
func (b *BeaconState) SignedParentHashes(block *Block, attestation *pb.AggregatedAttestation) ([][32]byte, error) {
recentBlockHashes := b.RecentBlockHashes()
Expand Down Expand Up @@ -307,6 +322,7 @@ func (b *BeaconState) ClearAttestations(lastStateRecalc uint64) {
update := make([]*pb.AggregatedAttestation, 0, len(existing))
for _, a := range existing {
if a.GetSlot() >= lastStateRecalc {
>>>>>>> master
update = append(update, a)
}
}
Expand Down Expand Up @@ -357,28 +373,37 @@ func (b *BeaconState) SetDepositsPenalizedInPeriod(penalizedDeposits []uint64) {
b.data.DepositsPenalizedInPeriod = penalizedDeposits
}

// SetLastJustifiedSlot updates the inner proto's last justified slot.
func (b *BeaconState) SetLastJustifiedSlot(justifiedSlot uint64) {
b.data.LastJustifiedSlot = justifiedSlot
// SetJustificationSource updates the inner proto's justification source.
func (b *BeaconState) SetJustificationSource(justificationSource uint64) {
b.data.JustificationSource = justificationSource
}

// SetPrevCycleJustificationSource updates the inner proto's previous cycle justification source.
func (b *BeaconState) SetPrevCycleJustificationSource(justificationSource uint64) {
b.data.PrevCycleJustificationSource = justificationSource
}

// SetJustifiedSlotBitfield updates the inner proto's justified slot bitfield.
func (b *BeaconState) SetJustifiedSlotBitfield(bitfield []byte) {
b.data.JustifiedSlotBitfield = bitfield
}

// SetLastFinalizedSlot updates the inner proto's last finalized slot.
func (b *BeaconState) SetLastFinalizedSlot(finalizedSlot uint64) {
b.data.LastFinalizedSlot = finalizedSlot
}

// SetJustifiedStreak updates the inner proto's justified streak.
func (b *BeaconState) SetJustifiedStreak(justifiedSlot uint64) {
b.data.JustifiedStreak = justifiedSlot
}

// SetLastStateRecalculationSlot updates the inner proto's last state recalc slot.
func (b *BeaconState) SetLastStateRecalculationSlot(slot uint64) {
b.data.LastStateRecalculationSlot = slot
}

// SetPendingAttestations updates the inner proto's pending attestations.
<<<<<<< HEAD
func (b *BeaconState) SetPendingAttestations(pendingAttestations []*pb.ProcessedAttestation) {
=======
func (b *BeaconState) SetPendingAttestations(pendingAttestations []*pb.AggregatedAttestation) {
>>>>>>> master
b.data.PendingAttestations = pendingAttestations
}

Expand Down Expand Up @@ -412,6 +437,5 @@ func getPenaltyForPeriod(penalties []uint64, period uint64) uint64 {
if numPeriods < period+1 {
return 0
}

return penalties[period]
}
4 changes: 2 additions & 2 deletions beacon-chain/core/validators/committees.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func AttesterIndices(
) ([]uint32, error) {
shardCommitteesArray := shardCommittees.ArrayShardAndCommittee
for _, shardCommittee := range shardCommitteesArray {
if attestation.Shard == shardCommittee.Shard {
if attestation.SignedData.Shard == shardCommittee.Shard {
return shardCommittee.Committee, nil
}
}

return nil, fmt.Errorf("unable to find committee for shard %d", attestation.Shard)
return nil, fmt.Errorf("unable to find committee for shard %d", attestation.SignedData.Shard)
}

// splitBySlotShard splits the validator list into evenly sized committees and assigns each
Expand Down
Loading