Altair: new protos/state object (#8907)

* Altair: new protos/state

* Undo changes in proto/migration/migration.go

* Change proto/beacon/p2p/v1/generated.ssz.go to 0644

* Update proto/beacon/p2p/v1/types.proto

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* PR Feedback: rename SyncCommitteeSigningData to SyncAggregatorSelectionData

* 644

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Preston Van Loon
2021-06-01 22:07:13 -05:00
committed by GitHub
parent 8a6e2a33a2
commit ef20f2da7e
4 changed files with 1656 additions and 147 deletions

View File

@@ -43,7 +43,10 @@ ssz_gen_marshal(
"HistoricalBatch",
"Status",
"BeaconState",
"BeaconStateAltair",
"SigningData",
"SyncCommittee",
"SyncAggregatorSelectionData",
],
)

View File

@@ -1117,6 +1117,779 @@ func (b *BeaconState) HashTreeRootWith(hh *ssz.Hasher) (err error) {
return
}
// MarshalSSZ ssz marshals the BeaconStateAltair object
func (b *BeaconStateAltair) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(b)
}
// MarshalSSZTo ssz marshals the BeaconStateAltair object to a target array
func (b *BeaconStateAltair) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
offset := int(2736629)
// Field (0) 'GenesisTime'
dst = ssz.MarshalUint64(dst, b.GenesisTime)
// Field (1) 'GenesisValidatorsRoot'
if len(b.GenesisValidatorsRoot) != 32 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, b.GenesisValidatorsRoot...)
// Field (2) 'Slot'
dst = ssz.MarshalUint64(dst, uint64(b.Slot))
// Field (3) 'Fork'
if b.Fork == nil {
b.Fork = new(Fork)
}
if dst, err = b.Fork.MarshalSSZTo(dst); err != nil {
return
}
// Field (4) 'LatestBlockHeader'
if b.LatestBlockHeader == nil {
b.LatestBlockHeader = new(v1alpha1.BeaconBlockHeader)
}
if dst, err = b.LatestBlockHeader.MarshalSSZTo(dst); err != nil {
return
}
// Field (5) 'BlockRoots'
if len(b.BlockRoots) != 8192 {
err = ssz.ErrVectorLength
return
}
for ii := 0; ii < 8192; ii++ {
if len(b.BlockRoots[ii]) != 32 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, b.BlockRoots[ii]...)
}
// Field (6) 'StateRoots'
if len(b.StateRoots) != 8192 {
err = ssz.ErrVectorLength
return
}
for ii := 0; ii < 8192; ii++ {
if len(b.StateRoots[ii]) != 32 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, b.StateRoots[ii]...)
}
// Offset (7) 'HistoricalRoots'
dst = ssz.WriteOffset(dst, offset)
offset += len(b.HistoricalRoots) * 32
// Field (8) 'Eth1Data'
if b.Eth1Data == nil {
b.Eth1Data = new(v1alpha1.Eth1Data)
}
if dst, err = b.Eth1Data.MarshalSSZTo(dst); err != nil {
return
}
// Offset (9) 'Eth1DataVotes'
dst = ssz.WriteOffset(dst, offset)
offset += len(b.Eth1DataVotes) * 72
// Field (10) 'Eth1DepositIndex'
dst = ssz.MarshalUint64(dst, b.Eth1DepositIndex)
// Offset (11) 'Validators'
dst = ssz.WriteOffset(dst, offset)
offset += len(b.Validators) * 121
// Offset (12) 'Balances'
dst = ssz.WriteOffset(dst, offset)
offset += len(b.Balances) * 8
// Field (13) 'RandaoMixes'
if len(b.RandaoMixes) != 65536 {
err = ssz.ErrVectorLength
return
}
for ii := 0; ii < 65536; ii++ {
if len(b.RandaoMixes[ii]) != 32 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, b.RandaoMixes[ii]...)
}
// Field (14) 'Slashings'
if len(b.Slashings) != 8192 {
err = ssz.ErrVectorLength
return
}
for ii := 0; ii < 8192; ii++ {
dst = ssz.MarshalUint64(dst, b.Slashings[ii])
}
// Offset (15) 'PreviousEpochParticipation'
dst = ssz.WriteOffset(dst, offset)
offset += len(b.PreviousEpochParticipation)
// Offset (16) 'CurrentEpochParticipation'
dst = ssz.WriteOffset(dst, offset)
offset += len(b.CurrentEpochParticipation)
// Field (17) 'JustificationBits'
if len(b.JustificationBits) != 1 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, b.JustificationBits...)
// Field (18) 'PreviousJustifiedCheckpoint'
if b.PreviousJustifiedCheckpoint == nil {
b.PreviousJustifiedCheckpoint = new(v1alpha1.Checkpoint)
}
if dst, err = b.PreviousJustifiedCheckpoint.MarshalSSZTo(dst); err != nil {
return
}
// Field (19) 'CurrentJustifiedCheckpoint'
if b.CurrentJustifiedCheckpoint == nil {
b.CurrentJustifiedCheckpoint = new(v1alpha1.Checkpoint)
}
if dst, err = b.CurrentJustifiedCheckpoint.MarshalSSZTo(dst); err != nil {
return
}
// Field (20) 'FinalizedCheckpoint'
if b.FinalizedCheckpoint == nil {
b.FinalizedCheckpoint = new(v1alpha1.Checkpoint)
}
if dst, err = b.FinalizedCheckpoint.MarshalSSZTo(dst); err != nil {
return
}
// Offset (21) 'InactivityScores'
dst = ssz.WriteOffset(dst, offset)
offset += len(b.InactivityScores) * 8
// Field (22) 'CurrentSyncCommittee'
if b.CurrentSyncCommittee == nil {
b.CurrentSyncCommittee = new(SyncCommittee)
}
if dst, err = b.CurrentSyncCommittee.MarshalSSZTo(dst); err != nil {
return
}
// Field (23) 'NextSyncCommittee'
if b.NextSyncCommittee == nil {
b.NextSyncCommittee = new(SyncCommittee)
}
if dst, err = b.NextSyncCommittee.MarshalSSZTo(dst); err != nil {
return
}
// Field (7) 'HistoricalRoots'
if len(b.HistoricalRoots) > 16777216 {
err = ssz.ErrListTooBig
return
}
for ii := 0; ii < len(b.HistoricalRoots); ii++ {
if len(b.HistoricalRoots[ii]) != 32 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, b.HistoricalRoots[ii]...)
}
// Field (9) 'Eth1DataVotes'
if len(b.Eth1DataVotes) > 2048 {
err = ssz.ErrListTooBig
return
}
for ii := 0; ii < len(b.Eth1DataVotes); ii++ {
if dst, err = b.Eth1DataVotes[ii].MarshalSSZTo(dst); err != nil {
return
}
}
// Field (11) 'Validators'
if len(b.Validators) > 1099511627776 {
err = ssz.ErrListTooBig
return
}
for ii := 0; ii < len(b.Validators); ii++ {
if dst, err = b.Validators[ii].MarshalSSZTo(dst); err != nil {
return
}
}
// Field (12) 'Balances'
if len(b.Balances) > 1099511627776 {
err = ssz.ErrListTooBig
return
}
for ii := 0; ii < len(b.Balances); ii++ {
dst = ssz.MarshalUint64(dst, b.Balances[ii])
}
// Field (15) 'PreviousEpochParticipation'
if len(b.PreviousEpochParticipation) > 1099511627776 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, b.PreviousEpochParticipation...)
// Field (16) 'CurrentEpochParticipation'
if len(b.CurrentEpochParticipation) > 1099511627776 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, b.CurrentEpochParticipation...)
// Field (21) 'InactivityScores'
if len(b.InactivityScores) > 1099511627776 {
err = ssz.ErrListTooBig
return
}
for ii := 0; ii < len(b.InactivityScores); ii++ {
dst = ssz.MarshalUint64(dst, b.InactivityScores[ii])
}
return
}
// UnmarshalSSZ ssz unmarshals the BeaconStateAltair object
func (b *BeaconStateAltair) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size < 2736629 {
return ssz.ErrSize
}
tail := buf
var o7, o9, o11, o12, o15, o16, o21 uint64
// Field (0) 'GenesisTime'
b.GenesisTime = ssz.UnmarshallUint64(buf[0:8])
// Field (1) 'GenesisValidatorsRoot'
if cap(b.GenesisValidatorsRoot) == 0 {
b.GenesisValidatorsRoot = make([]byte, 0, len(buf[8:40]))
}
b.GenesisValidatorsRoot = append(b.GenesisValidatorsRoot, buf[8:40]...)
// Field (2) 'Slot'
b.Slot = github_com_prysmaticlabs_eth2_types.Slot(ssz.UnmarshallUint64(buf[40:48]))
// Field (3) 'Fork'
if b.Fork == nil {
b.Fork = new(Fork)
}
if err = b.Fork.UnmarshalSSZ(buf[48:64]); err != nil {
return err
}
// Field (4) 'LatestBlockHeader'
if b.LatestBlockHeader == nil {
b.LatestBlockHeader = new(v1alpha1.BeaconBlockHeader)
}
if err = b.LatestBlockHeader.UnmarshalSSZ(buf[64:176]); err != nil {
return err
}
// Field (5) 'BlockRoots'
b.BlockRoots = make([][]byte, 8192)
for ii := 0; ii < 8192; ii++ {
if cap(b.BlockRoots[ii]) == 0 {
b.BlockRoots[ii] = make([]byte, 0, len(buf[176:262320][ii*32:(ii+1)*32]))
}
b.BlockRoots[ii] = append(b.BlockRoots[ii], buf[176:262320][ii*32:(ii+1)*32]...)
}
// Field (6) 'StateRoots'
b.StateRoots = make([][]byte, 8192)
for ii := 0; ii < 8192; ii++ {
if cap(b.StateRoots[ii]) == 0 {
b.StateRoots[ii] = make([]byte, 0, len(buf[262320:524464][ii*32:(ii+1)*32]))
}
b.StateRoots[ii] = append(b.StateRoots[ii], buf[262320:524464][ii*32:(ii+1)*32]...)
}
// Offset (7) 'HistoricalRoots'
if o7 = ssz.ReadOffset(buf[524464:524468]); o7 > size {
return ssz.ErrOffset
}
// Field (8) 'Eth1Data'
if b.Eth1Data == nil {
b.Eth1Data = new(v1alpha1.Eth1Data)
}
if err = b.Eth1Data.UnmarshalSSZ(buf[524468:524540]); err != nil {
return err
}
// Offset (9) 'Eth1DataVotes'
if o9 = ssz.ReadOffset(buf[524540:524544]); o9 > size || o7 > o9 {
return ssz.ErrOffset
}
// Field (10) 'Eth1DepositIndex'
b.Eth1DepositIndex = ssz.UnmarshallUint64(buf[524544:524552])
// Offset (11) 'Validators'
if o11 = ssz.ReadOffset(buf[524552:524556]); o11 > size || o9 > o11 {
return ssz.ErrOffset
}
// Offset (12) 'Balances'
if o12 = ssz.ReadOffset(buf[524556:524560]); o12 > size || o11 > o12 {
return ssz.ErrOffset
}
// Field (13) 'RandaoMixes'
b.RandaoMixes = make([][]byte, 65536)
for ii := 0; ii < 65536; ii++ {
if cap(b.RandaoMixes[ii]) == 0 {
b.RandaoMixes[ii] = make([]byte, 0, len(buf[524560:2621712][ii*32:(ii+1)*32]))
}
b.RandaoMixes[ii] = append(b.RandaoMixes[ii], buf[524560:2621712][ii*32:(ii+1)*32]...)
}
// Field (14) 'Slashings'
b.Slashings = ssz.ExtendUint64(b.Slashings, 8192)
for ii := 0; ii < 8192; ii++ {
b.Slashings[ii] = ssz.UnmarshallUint64(buf[2621712:2687248][ii*8 : (ii+1)*8])
}
// Offset (15) 'PreviousEpochParticipation'
if o15 = ssz.ReadOffset(buf[2687248:2687252]); o15 > size || o12 > o15 {
return ssz.ErrOffset
}
// Offset (16) 'CurrentEpochParticipation'
if o16 = ssz.ReadOffset(buf[2687252:2687256]); o16 > size || o15 > o16 {
return ssz.ErrOffset
}
// Field (17) 'JustificationBits'
if cap(b.JustificationBits) == 0 {
b.JustificationBits = make([]byte, 0, len(buf[2687256:2687257]))
}
b.JustificationBits = append(b.JustificationBits, buf[2687256:2687257]...)
// Field (18) 'PreviousJustifiedCheckpoint'
if b.PreviousJustifiedCheckpoint == nil {
b.PreviousJustifiedCheckpoint = new(v1alpha1.Checkpoint)
}
if err = b.PreviousJustifiedCheckpoint.UnmarshalSSZ(buf[2687257:2687297]); err != nil {
return err
}
// Field (19) 'CurrentJustifiedCheckpoint'
if b.CurrentJustifiedCheckpoint == nil {
b.CurrentJustifiedCheckpoint = new(v1alpha1.Checkpoint)
}
if err = b.CurrentJustifiedCheckpoint.UnmarshalSSZ(buf[2687297:2687337]); err != nil {
return err
}
// Field (20) 'FinalizedCheckpoint'
if b.FinalizedCheckpoint == nil {
b.FinalizedCheckpoint = new(v1alpha1.Checkpoint)
}
if err = b.FinalizedCheckpoint.UnmarshalSSZ(buf[2687337:2687377]); err != nil {
return err
}
// Offset (21) 'InactivityScores'
if o21 = ssz.ReadOffset(buf[2687377:2687381]); o21 > size || o16 > o21 {
return ssz.ErrOffset
}
// Field (22) 'CurrentSyncCommittee'
if b.CurrentSyncCommittee == nil {
b.CurrentSyncCommittee = new(SyncCommittee)
}
if err = b.CurrentSyncCommittee.UnmarshalSSZ(buf[2687381:2712005]); err != nil {
return err
}
// Field (23) 'NextSyncCommittee'
if b.NextSyncCommittee == nil {
b.NextSyncCommittee = new(SyncCommittee)
}
if err = b.NextSyncCommittee.UnmarshalSSZ(buf[2712005:2736629]); err != nil {
return err
}
// Field (7) 'HistoricalRoots'
{
buf = tail[o7:o9]
num, err := ssz.DivideInt2(len(buf), 32, 16777216)
if err != nil {
return err
}
b.HistoricalRoots = make([][]byte, num)
for ii := 0; ii < num; ii++ {
if cap(b.HistoricalRoots[ii]) == 0 {
b.HistoricalRoots[ii] = make([]byte, 0, len(buf[ii*32:(ii+1)*32]))
}
b.HistoricalRoots[ii] = append(b.HistoricalRoots[ii], buf[ii*32:(ii+1)*32]...)
}
}
// Field (9) 'Eth1DataVotes'
{
buf = tail[o9:o11]
num, err := ssz.DivideInt2(len(buf), 72, 2048)
if err != nil {
return err
}
b.Eth1DataVotes = make([]*v1alpha1.Eth1Data, num)
for ii := 0; ii < num; ii++ {
if b.Eth1DataVotes[ii] == nil {
b.Eth1DataVotes[ii] = new(v1alpha1.Eth1Data)
}
if err = b.Eth1DataVotes[ii].UnmarshalSSZ(buf[ii*72 : (ii+1)*72]); err != nil {
return err
}
}
}
// Field (11) 'Validators'
{
buf = tail[o11:o12]
num, err := ssz.DivideInt2(len(buf), 121, 1099511627776)
if err != nil {
return err
}
b.Validators = make([]*v1alpha1.Validator, num)
for ii := 0; ii < num; ii++ {
if b.Validators[ii] == nil {
b.Validators[ii] = new(v1alpha1.Validator)
}
if err = b.Validators[ii].UnmarshalSSZ(buf[ii*121 : (ii+1)*121]); err != nil {
return err
}
}
}
// Field (12) 'Balances'
{
buf = tail[o12:o15]
num, err := ssz.DivideInt2(len(buf), 8, 1099511627776)
if err != nil {
return err
}
b.Balances = ssz.ExtendUint64(b.Balances, num)
for ii := 0; ii < num; ii++ {
b.Balances[ii] = ssz.UnmarshallUint64(buf[ii*8 : (ii+1)*8])
}
}
// Field (15) 'PreviousEpochParticipation'
{
buf = tail[o15:o16]
if len(buf) > 1099511627776 {
return ssz.ErrBytesLength
}
if cap(b.PreviousEpochParticipation) == 0 {
b.PreviousEpochParticipation = make([]byte, 0, len(buf))
}
b.PreviousEpochParticipation = append(b.PreviousEpochParticipation, buf...)
}
// Field (16) 'CurrentEpochParticipation'
{
buf = tail[o16:o21]
if len(buf) > 1099511627776 {
return ssz.ErrBytesLength
}
if cap(b.CurrentEpochParticipation) == 0 {
b.CurrentEpochParticipation = make([]byte, 0, len(buf))
}
b.CurrentEpochParticipation = append(b.CurrentEpochParticipation, buf...)
}
// Field (21) 'InactivityScores'
{
buf = tail[o21:]
num, err := ssz.DivideInt2(len(buf), 8, 1099511627776)
if err != nil {
return err
}
b.InactivityScores = ssz.ExtendUint64(b.InactivityScores, num)
for ii := 0; ii < num; ii++ {
b.InactivityScores[ii] = ssz.UnmarshallUint64(buf[ii*8 : (ii+1)*8])
}
}
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the BeaconStateAltair object
func (b *BeaconStateAltair) SizeSSZ() (size int) {
size = 2736629
// Field (7) 'HistoricalRoots'
size += len(b.HistoricalRoots) * 32
// Field (9) 'Eth1DataVotes'
size += len(b.Eth1DataVotes) * 72
// Field (11) 'Validators'
size += len(b.Validators) * 121
// Field (12) 'Balances'
size += len(b.Balances) * 8
// Field (15) 'PreviousEpochParticipation'
size += len(b.PreviousEpochParticipation)
// Field (16) 'CurrentEpochParticipation'
size += len(b.CurrentEpochParticipation)
// Field (21) 'InactivityScores'
size += len(b.InactivityScores) * 8
return
}
// HashTreeRoot ssz hashes the BeaconStateAltair object
func (b *BeaconStateAltair) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(b)
}
// HashTreeRootWith ssz hashes the BeaconStateAltair object with a hasher
func (b *BeaconStateAltair) HashTreeRootWith(hh *ssz.Hasher) (err error) {
indx := hh.Index()
// Field (0) 'GenesisTime'
hh.PutUint64(b.GenesisTime)
// Field (1) 'GenesisValidatorsRoot'
if len(b.GenesisValidatorsRoot) != 32 {
err = ssz.ErrBytesLength
return
}
hh.PutBytes(b.GenesisValidatorsRoot)
// Field (2) 'Slot'
hh.PutUint64(uint64(b.Slot))
// Field (3) 'Fork'
if err = b.Fork.HashTreeRootWith(hh); err != nil {
return
}
// Field (4) 'LatestBlockHeader'
if err = b.LatestBlockHeader.HashTreeRootWith(hh); err != nil {
return
}
// Field (5) 'BlockRoots'
{
if len(b.BlockRoots) != 8192 {
err = ssz.ErrVectorLength
return
}
subIndx := hh.Index()
for _, i := range b.BlockRoots {
if len(i) != 32 {
err = ssz.ErrBytesLength
return
}
hh.Append(i)
}
hh.Merkleize(subIndx)
}
// Field (6) 'StateRoots'
{
if len(b.StateRoots) != 8192 {
err = ssz.ErrVectorLength
return
}
subIndx := hh.Index()
for _, i := range b.StateRoots {
if len(i) != 32 {
err = ssz.ErrBytesLength
return
}
hh.Append(i)
}
hh.Merkleize(subIndx)
}
// Field (7) 'HistoricalRoots'
{
if len(b.HistoricalRoots) > 16777216 {
err = ssz.ErrListTooBig
return
}
subIndx := hh.Index()
for _, i := range b.HistoricalRoots {
if len(i) != 32 {
err = ssz.ErrBytesLength
return
}
hh.Append(i)
}
numItems := uint64(len(b.HistoricalRoots))
hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(16777216, numItems, 32))
}
// Field (8) 'Eth1Data'
if err = b.Eth1Data.HashTreeRootWith(hh); err != nil {
return
}
// Field (9) 'Eth1DataVotes'
{
subIndx := hh.Index()
num := uint64(len(b.Eth1DataVotes))
if num > 2048 {
err = ssz.ErrIncorrectListSize
return
}
for i := uint64(0); i < num; i++ {
if err = b.Eth1DataVotes[i].HashTreeRootWith(hh); err != nil {
return
}
}
hh.MerkleizeWithMixin(subIndx, num, 2048)
}
// Field (10) 'Eth1DepositIndex'
hh.PutUint64(b.Eth1DepositIndex)
// Field (11) 'Validators'
{
subIndx := hh.Index()
num := uint64(len(b.Validators))
if num > 1099511627776 {
err = ssz.ErrIncorrectListSize
return
}
for i := uint64(0); i < num; i++ {
if err = b.Validators[i].HashTreeRootWith(hh); err != nil {
return
}
}
hh.MerkleizeWithMixin(subIndx, num, 1099511627776)
}
// Field (12) 'Balances'
{
if len(b.Balances) > 1099511627776 {
err = ssz.ErrListTooBig
return
}
subIndx := hh.Index()
for _, i := range b.Balances {
hh.AppendUint64(i)
}
hh.FillUpTo32()
numItems := uint64(len(b.Balances))
hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(1099511627776, numItems, 8))
}
// Field (13) 'RandaoMixes'
{
if len(b.RandaoMixes) != 65536 {
err = ssz.ErrVectorLength
return
}
subIndx := hh.Index()
for _, i := range b.RandaoMixes {
if len(i) != 32 {
err = ssz.ErrBytesLength
return
}
hh.Append(i)
}
hh.Merkleize(subIndx)
}
// Field (14) 'Slashings'
{
if len(b.Slashings) != 8192 {
err = ssz.ErrVectorLength
return
}
subIndx := hh.Index()
for _, i := range b.Slashings {
hh.AppendUint64(i)
}
hh.Merkleize(subIndx)
}
// Field (15) 'PreviousEpochParticipation'
if len(b.PreviousEpochParticipation) > 1099511627776 {
err = ssz.ErrBytesLength
return
}
hh.PutBytes(b.PreviousEpochParticipation)
// Field (16) 'CurrentEpochParticipation'
if len(b.CurrentEpochParticipation) > 1099511627776 {
err = ssz.ErrBytesLength
return
}
hh.PutBytes(b.CurrentEpochParticipation)
// Field (17) 'JustificationBits'
if len(b.JustificationBits) != 1 {
err = ssz.ErrBytesLength
return
}
hh.PutBytes(b.JustificationBits)
// Field (18) 'PreviousJustifiedCheckpoint'
if err = b.PreviousJustifiedCheckpoint.HashTreeRootWith(hh); err != nil {
return
}
// Field (19) 'CurrentJustifiedCheckpoint'
if err = b.CurrentJustifiedCheckpoint.HashTreeRootWith(hh); err != nil {
return
}
// Field (20) 'FinalizedCheckpoint'
if err = b.FinalizedCheckpoint.HashTreeRootWith(hh); err != nil {
return
}
// Field (21) 'InactivityScores'
{
if len(b.InactivityScores) > 1099511627776 {
err = ssz.ErrListTooBig
return
}
subIndx := hh.Index()
for _, i := range b.InactivityScores {
hh.AppendUint64(i)
}
hh.FillUpTo32()
numItems := uint64(len(b.InactivityScores))
hh.MerkleizeWithMixin(subIndx, numItems, ssz.CalculateLimit(1099511627776, numItems, 8))
}
// Field (22) 'CurrentSyncCommittee'
if err = b.CurrentSyncCommittee.HashTreeRootWith(hh); err != nil {
return
}
// Field (23) 'NextSyncCommittee'
if err = b.NextSyncCommittee.HashTreeRootWith(hh); err != nil {
return
}
hh.Merkleize(indx)
return
}
// MarshalSSZ ssz marshals the Fork object
func (f *Fork) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(f)
@@ -1709,3 +2482,164 @@ func (d *DepositMessage) HashTreeRootWith(hh *ssz.Hasher) (err error) {
hh.Merkleize(indx)
return
}
// MarshalSSZ ssz marshals the SyncCommittee object
func (s *SyncCommittee) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(s)
}
// MarshalSSZTo ssz marshals the SyncCommittee object to a target array
func (s *SyncCommittee) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
// Field (0) 'Pubkeys'
if len(s.Pubkeys) != 512 {
err = ssz.ErrVectorLength
return
}
for ii := 0; ii < 512; ii++ {
if len(s.Pubkeys[ii]) != 48 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, s.Pubkeys[ii]...)
}
// Field (1) 'AggregatePubkey'
if len(s.AggregatePubkey) != 48 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, s.AggregatePubkey...)
return
}
// UnmarshalSSZ ssz unmarshals the SyncCommittee object
func (s *SyncCommittee) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size != 24624 {
return ssz.ErrSize
}
// Field (0) 'Pubkeys'
s.Pubkeys = make([][]byte, 512)
for ii := 0; ii < 512; ii++ {
if cap(s.Pubkeys[ii]) == 0 {
s.Pubkeys[ii] = make([]byte, 0, len(buf[0:24576][ii*48:(ii+1)*48]))
}
s.Pubkeys[ii] = append(s.Pubkeys[ii], buf[0:24576][ii*48:(ii+1)*48]...)
}
// Field (1) 'AggregatePubkey'
if cap(s.AggregatePubkey) == 0 {
s.AggregatePubkey = make([]byte, 0, len(buf[24576:24624]))
}
s.AggregatePubkey = append(s.AggregatePubkey, buf[24576:24624]...)
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the SyncCommittee object
func (s *SyncCommittee) SizeSSZ() (size int) {
size = 24624
return
}
// HashTreeRoot ssz hashes the SyncCommittee object
func (s *SyncCommittee) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(s)
}
// HashTreeRootWith ssz hashes the SyncCommittee object with a hasher
func (s *SyncCommittee) HashTreeRootWith(hh *ssz.Hasher) (err error) {
indx := hh.Index()
// Field (0) 'Pubkeys'
{
if len(s.Pubkeys) != 512 {
err = ssz.ErrVectorLength
return
}
subIndx := hh.Index()
for _, i := range s.Pubkeys {
if len(i) != 48 {
err = ssz.ErrBytesLength
return
}
hh.Append(i)
}
hh.Merkleize(subIndx)
}
// Field (1) 'AggregatePubkey'
if len(s.AggregatePubkey) != 48 {
err = ssz.ErrBytesLength
return
}
hh.PutBytes(s.AggregatePubkey)
hh.Merkleize(indx)
return
}
// MarshalSSZ ssz marshals the SyncAggregatorSelectionData object
func (s *SyncAggregatorSelectionData) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(s)
}
// MarshalSSZTo ssz marshals the SyncAggregatorSelectionData object to a target array
func (s *SyncAggregatorSelectionData) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
// Field (0) 'Slot'
dst = ssz.MarshalUint64(dst, s.Slot)
// Field (1) 'SubcommitteeIndex'
dst = ssz.MarshalUint64(dst, s.SubcommitteeIndex)
return
}
// UnmarshalSSZ ssz unmarshals the SyncAggregatorSelectionData object
func (s *SyncAggregatorSelectionData) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size != 16 {
return ssz.ErrSize
}
// Field (0) 'Slot'
s.Slot = ssz.UnmarshallUint64(buf[0:8])
// Field (1) 'SubcommitteeIndex'
s.SubcommitteeIndex = ssz.UnmarshallUint64(buf[8:16])
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the SyncAggregatorSelectionData object
func (s *SyncAggregatorSelectionData) SizeSSZ() (size int) {
size = 16
return
}
// HashTreeRoot ssz hashes the SyncAggregatorSelectionData object
func (s *SyncAggregatorSelectionData) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(s)
}
// HashTreeRootWith ssz hashes the SyncAggregatorSelectionData object with a hasher
func (s *SyncAggregatorSelectionData) HashTreeRootWith(hh *ssz.Hasher) (err error) {
indx := hh.Index()
// Field (0) 'Slot'
hh.PutUint64(s.Slot)
// Field (1) 'SubcommitteeIndex'
hh.PutUint64(s.SubcommitteeIndex)
hh.Merkleize(indx)
return
}

File diff suppressed because it is too large Load Diff

View File

@@ -46,6 +46,53 @@ message BeaconState {
ethereum.eth.v1alpha1.Checkpoint finalized_checkpoint = 8004;
}
// The beacon state for Altair hard fork 1.
// Reference: https://github.com/ethereum/eth2.0-specs/blob/dev/specs/altair/beacon-chain.md#beaconstate
message BeaconStateAltair {
// Versioning [1001-2000]
uint64 genesis_time = 1001;
bytes genesis_validators_root = 1002 [(ethereum.eth.ext.ssz_size) = "32"];
uint64 slot = 1003 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.Slot"];
Fork fork = 1004;
// History [2001-3000]
ethereum.eth.v1alpha1.BeaconBlockHeader latest_block_header = 2001;
repeated bytes block_roots = 2002 [(ethereum.eth.ext.ssz_size) = "block_roots.size"];
repeated bytes state_roots = 2003 [(ethereum.eth.ext.ssz_size) = "state_roots.size"];
repeated bytes historical_roots = 2004 [(ethereum.eth.ext.ssz_size) = "?,32", (ethereum.eth.ext.ssz_max) = "16777216"];
// Eth1 [3001-4000]
ethereum.eth.v1alpha1.Eth1Data eth1_data = 3001;
repeated ethereum.eth.v1alpha1.Eth1Data eth1_data_votes = 3002 [(ethereum.eth.ext.ssz_max) = "eth1_data_votes.size"];
uint64 eth1_deposit_index = 3003;
// Registry [4001-5000]
repeated ethereum.eth.v1alpha1.Validator validators = 4001 [(ethereum.eth.ext.ssz_max) = "1099511627776"];
repeated uint64 balances = 4002 [(ethereum.eth.ext.ssz_max) = "1099511627776"];
// Randomness [5001-6000]
repeated bytes randao_mixes = 5001 [(ethereum.eth.ext.ssz_size) = "randao_mixes.size"];
// Slashings [6001-7000]
repeated uint64 slashings = 6001 [(ethereum.eth.ext.ssz_size) = "slashings.size"];
// Participation [7001-8000]
bytes previous_epoch_participation = 7001 [(ethereum.eth.ext.ssz_max) = "1099511627776"]; // [New in Altair, replaced previous_epoch_attestations]
bytes current_epoch_participation = 7002 [(ethereum.eth.ext.ssz_max) = "1099511627776"]; // [New in Altair, replaced current_epoch_attestations]
// Finality [8001-9000]
// Spec type [4]Bitvector which means this would be a fixed size of 4 bits.
bytes justification_bits = 8001 [(ethereum.eth.ext.ssz_size) = "1", (ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/go-bitfield.Bitvector4"];
ethereum.eth.v1alpha1.Checkpoint previous_justified_checkpoint = 8002;
ethereum.eth.v1alpha1.Checkpoint current_justified_checkpoint = 8003;
ethereum.eth.v1alpha1.Checkpoint finalized_checkpoint = 8004;
// New Altair fields [9001-10000]
repeated uint64 inactivity_scores = 9001 [(ethereum.eth.ext.ssz_max) = "1099511627776"]; // [New in Altair]
SyncCommittee current_sync_committee = 9002; // [New in Altair]
SyncCommittee next_sync_committee = 9003; // [New in Altair]
}
message Fork {
bytes previous_version = 1 [(ethereum.eth.ext.ssz_size) = "4"];
bytes current_version = 2 [(ethereum.eth.ext.ssz_size) = "4"];
@@ -116,4 +163,18 @@ message DepositMessage {
// Deposit amount in gwei.
uint64 amount = 3;
}
}
// SyncCommittee serves as committees to facilitate light client syncing to beacon chain.
message SyncCommittee {
repeated bytes pubkeys = 1 [(ethereum.eth.ext.ssz_size) = "512,48"];
bytes aggregate_pubkey = 2 [(ethereum.eth.ext.ssz_size) = "48"];
}
// SyncAggregatorSelectionData is used to sign over and then check whether the aggregator is selected within a subcommittee.
message SyncAggregatorSelectionData {
// Slot of this signing data.
uint64 slot = 1;
// Subcommittee index of this signing data.
uint64 subcommittee_index = 2;
}