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

Create New Beacon State Data Structure #4602

Merged
merged 32 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d4cd5af
begin state service
rauljordan Jan 20, 2020
845a409
begin on the state trie idea
rauljordan Jan 20, 2020
8eae092
created beacon state structure
rauljordan Jan 20, 2020
33d7693
add in the full clone getter
rauljordan Jan 20, 2020
eb5b91f
return by value instead
rauljordan Jan 20, 2020
45980b8
add all setters
rauljordan Jan 20, 2020
5fa1e0a
new state setters are being completed
rauljordan Jan 20, 2020
7a994c5
arrays roots exposed
rauljordan Jan 20, 2020
aeff2e4
close to finishing all these headerssss
rauljordan Jan 21, 2020
a9f4e2a
functionality complete
rauljordan Jan 21, 2020
a8b6fe9
added in proto benchmark test
rauljordan Jan 21, 2020
babd076
test for compatibility
rauljordan Jan 21, 2020
cff2276
add test for compat
rauljordan Jan 21, 2020
5cf40d9
comments fixed
rauljordan Jan 21, 2020
1f62238
Merge branch 'master' into state-service
rauljordan Jan 21, 2020
b7c681f
add clone
nisdas Jan 21, 2020
60bf43a
add clone
nisdas Jan 21, 2020
aafed8f
remove underlying copies
nisdas Jan 21, 2020
86bd353
make it immutable
nisdas Jan 21, 2020
d03429a
integrate it into chainservice
nisdas Jan 21, 2020
0af8955
revert
rauljordan Jan 21, 2020
17a7cfc
wrap up comments for package
rauljordan Jan 21, 2020
372af74
address all comments and godocs
rauljordan Jan 21, 2020
37fdc89
address all comments
rauljordan Jan 21, 2020
9f8c528
Merge branch 'master' into state-service
rauljordan Jan 21, 2020
e23672c
clone the pending attestation properly
rauljordan Jan 21, 2020
0856c04
Merge branch 'state-service' of github.com:prysmaticlabs/prysm into s…
rauljordan Jan 21, 2020
dabe5fb
properly clone remaining items
rauljordan Jan 21, 2020
ae24d8d
tests pass fixed bug
rauljordan Jan 21, 2020
dd68b33
prevent nil pointer exceptions
rauljordan Jan 21, 2020
354ed4e
fixed up some bugs in the clone comparisons
rauljordan Jan 21, 2020
6c9eb01
Merge refs/heads/master into state-service
prylabs-bulldozer[bot] Jan 21, 2020
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
37 changes: 37 additions & 0 deletions beacon-chain/state/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"getters.go",
"setters.go",
"types.go",
],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/state",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/stateutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_protolambda_zssz//merkle:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = ["types_test.go"],
embed = [":go_default_library"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//shared/interop:go_default_library",
"//shared/params:go_default_library",
"//shared/stateutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
],
)
179 changes: 179 additions & 0 deletions beacon-chain/state/getters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package state

import (
"github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)

// Clone --
func (b *BeaconState) Clone() *pbp2p.BeaconState {
return proto.Clone(b.state).(*pbp2p.BeaconState)
}

// GenesisTime --
func (b *BeaconState) GenesisTime() uint64 {
return b.state.GenesisTime
}

// Slot --
func (b *BeaconState) Slot() uint64 {
return b.state.Slot
}

// Fork --
func (b *BeaconState) Fork() *pbp2p.Fork {
return &pbp2p.Fork{
PreviousVersion: b.state.Fork.PreviousVersion,
CurrentVersion: b.state.Fork.CurrentVersion,
Epoch: b.state.Fork.Epoch,
}
}

// LatestBlockHeader --
func (b *BeaconState) LatestBlockHeader() *ethpb.BeaconBlockHeader {
return &ethpb.BeaconBlockHeader{
Slot: b.state.LatestBlockHeader.Slot,
ParentRoot: b.state.LatestBlockHeader.ParentRoot,
rauljordan marked this conversation as resolved.
Show resolved Hide resolved
StateRoot: b.state.LatestBlockHeader.StateRoot,
BodyRoot: b.state.LatestBlockHeader.BodyRoot,
}
}

// BlockRoots --
func (b *BeaconState) BlockRoots() [][]byte {
res := make([][]byte, len(b.state.BlockRoots))
copy(res, b.state.BlockRoots)
return res
}

// StateRoots --
func (b *BeaconState) StateRoots() [][]byte {
res := make([][]byte, len(b.state.StateRoots))
copy(res, b.state.StateRoots)
return res
}

// HistoricalRoots --
func (b *BeaconState) HistoricalRoots() [][]byte {
res := make([][]byte, len(b.state.HistoricalRoots))
copy(res, b.state.HistoricalRoots)
return res
}

// Eth1Data --
func (b *BeaconState) Eth1Data() *ethpb.Eth1Data {
return &ethpb.Eth1Data{
DepositRoot: b.state.Eth1Data.DepositRoot,
DepositCount: b.state.Eth1Data.DepositCount,
BlockHash: b.state.Eth1Data.BlockHash,
}
}

// Eth1DataVotes --
func (b *BeaconState) Eth1DataVotes() []*ethpb.Eth1Data {
res := make([]*ethpb.Eth1Data, len(b.state.Eth1DataVotes))
for i := 0; i < len(res); i++ {
res[i] = &ethpb.Eth1Data{
DepositRoot: b.state.Eth1DataVotes[i].DepositRoot,
DepositCount: b.state.Eth1DataVotes[i].DepositCount,
BlockHash: b.state.Eth1DataVotes[i].BlockHash,
}
}
return res
}

// Eth1DepositIndex --
func (b *BeaconState) Eth1DepositIndex() uint64 {
return b.state.Eth1DepositIndex
}

// Validators --
func (b *BeaconState) Validators() []*ethpb.Validator {
res := make([]*ethpb.Validator, len(b.state.Validators))
for i := 0; i < len(res); i++ {
val := b.state.Validators[i]
res[i] = &ethpb.Validator{
PublicKey: val.PublicKey,
WithdrawalCredentials: val.WithdrawalCredentials,
EffectiveBalance: val.EffectiveBalance,
Slashed: val.Slashed,
ActivationEligibilityEpoch: val.ActivationEligibilityEpoch,
ActivationEpoch: val.ActivationEpoch,
ExitEpoch: val.ExitEpoch,
WithdrawableEpoch: val.WithdrawableEpoch,
}
}
return res
}

// Balances --
func (b *BeaconState) Balances() []uint64 {
res := make([]uint64, len(b.state.Balances))
copy(res, b.state.Balances)
return res
}

// RandaoMixes --
func (b *BeaconState) RandaoMixes() [][]byte {
res := make([][]byte, len(b.state.RandaoMixes))
copy(res, b.state.RandaoMixes)
return res
}

// Slashings --
func (b *BeaconState) Slashings() []uint64 {
res := make([]uint64, len(b.state.Slashings))
copy(res, b.state.Slashings)
return res
}

// PreviousEpochAttestations --
func (b *BeaconState) PreviousEpochAttestations() []*pbp2p.PendingAttestation {
res := make([]*pbp2p.PendingAttestation, len(b.state.PreviousEpochAttestations))
for i := 0; i < len(res); i++ {
res[i] = proto.Clone(b.state.PreviousEpochAttestations[i]).(*pbp2p.PendingAttestation)
rauljordan marked this conversation as resolved.
Show resolved Hide resolved
}
return res
}

// CurrentEpochAttestations --
func (b *BeaconState) CurrentEpochAttestations() []*pbp2p.PendingAttestation {
res := make([]*pbp2p.PendingAttestation, len(b.state.CurrentEpochAttestations))
for i := 0; i < len(res); i++ {
res[i] = proto.Clone(b.state.CurrentEpochAttestations[i]).(*pbp2p.PendingAttestation)
}
return res
}

// JustificationBits --
func (b *BeaconState) JustificationBits() bitfield.Bitvector4 {
res := bitfield.Bitvector4{}
copy(res, b.state.JustificationBits)
return res
}

// PreviousJustifiedCheckpoint --
func (b *BeaconState) PreviousJustifiedCheckpoint() *ethpb.Checkpoint {
return &ethpb.Checkpoint{
Epoch: b.state.PreviousJustifiedCheckpoint.Epoch,
Root: b.state.PreviousJustifiedCheckpoint.Root,
}
}

// CurrentJustifiedCheckpoint --
func (b *BeaconState) CurrentJustifiedCheckpoint() *ethpb.Checkpoint {
return &ethpb.Checkpoint{
Epoch: b.state.CurrentJustifiedCheckpoint.Epoch,
Root: b.state.CurrentJustifiedCheckpoint.Root,
}
}

// FinalizedCheckpoint --
func (b *BeaconState) FinalizedCheckpoint() *ethpb.Checkpoint {
return &ethpb.Checkpoint{
Epoch: b.state.FinalizedCheckpoint.Epoch,
Root: b.state.FinalizedCheckpoint.Root,
}
}
Loading