Electra: BeaconState implementation (#13919)

* Electra: Beacon State

* Electra: Beacon state fixes from PR 13919

* Add missing tests - part 1

* Split eip_7251_root.go into different files and reuse/share code with historical state summaries root. It's identical!

* Add missing tests - part 2

* deposit receipts start index getters and setters (#13947)

* adding in getters and setters for deposit receipts start index

* adding tests

* gaz

* Add missing tests - part 3 of 3

Update the electra withdrawal example with a ssz state containing pending partial withdrawals

* add tests for beacon-chain/state/state-native/getters_balance_deposits.go

* Add electra field to testing/util/block.go execution payload

* godoc commentary on public methods

* Fix failing test

* Add balances index out of bounds check and relevant tests.

* Revert switch case electra

* Instead of copying spectest data into testdata, use the spectest dependency

* Deepsource fixes

* Address @rkapka PR feedback

* s/MaxPendingPartialsPerWithdrawalSweep/MaxPendingPartialsPerWithdrawalsSweep/

* Use multivalue slice compatible accessors for validator and balance in ActiveBalanceAtIndex

* More @rkapka feedback. What a great reviewer!

* More tests for branching logic in ExitEpochAndUpdateChurn

* fix build

---------

Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
This commit is contained in:
Preston Van Loon
2024-05-06 13:04:33 -05:00
committed by GitHub
parent 26355768a0
commit 9b2934f1f6
78 changed files with 3100 additions and 838 deletions

View File

@@ -5,7 +5,10 @@ go_library(
srcs = ["math_helper.go"],
importpath = "github.com/prysmaticlabs/prysm/v5/math",
visibility = ["//visibility:public"],
deps = ["@com_github_thomaso_mirodin_intmath//u64:go_default_library"],
deps = [
"@com_github_prysmaticlabs_fastssz//:go_default_library",
"@com_github_thomaso_mirodin_intmath//u64:go_default_library",
],
)
go_test(

View File

@@ -3,11 +3,13 @@ package math
import (
"errors"
"fmt"
stdmath "math"
"math/big"
"math/bits"
"sync"
fssz "github.com/prysmaticlabs/fastssz"
"github.com/thomaso-mirodin/intmath/u64"
)
@@ -216,9 +218,53 @@ func AddInt(i ...int) (int, error) {
// Wei is the smallest unit of Ether, represented as a pointer to a bigInt.
type Wei *big.Int
var _ fssz.HashRoot = (Gwei)(0)
var _ fssz.Marshaler = (*Gwei)(nil)
var _ fssz.Unmarshaler = (*Gwei)(nil)
// Gwei is a denomination of 1e9 Wei represented as an uint64.
type Gwei uint64
// HashTreeRoot --
func (g Gwei) HashTreeRoot() ([32]byte, error) {
return fssz.HashWithDefaultHasher(g)
}
// HashTreeRootWith --
func (g Gwei) HashTreeRootWith(hh *fssz.Hasher) error {
hh.PutUint64(uint64(g))
return nil
}
// UnmarshalSSZ --
func (g *Gwei) UnmarshalSSZ(buf []byte) error {
if len(buf) != g.SizeSSZ() {
return fmt.Errorf("expected buffer of length %d received %d", g.SizeSSZ(), len(buf))
}
*g = Gwei(fssz.UnmarshallUint64(buf))
return nil
}
// MarshalSSZTo --
func (g *Gwei) MarshalSSZTo(dst []byte) ([]byte, error) {
marshalled, err := g.MarshalSSZ()
if err != nil {
return nil, err
}
return append(dst, marshalled...), nil
}
// MarshalSSZ --
func (g *Gwei) MarshalSSZ() ([]byte, error) {
marshalled := fssz.MarshalUint64([]byte{}, uint64(*g))
return marshalled, nil
}
// SizeSSZ --
func (g *Gwei) SizeSSZ() int {
return 8
}
// WeiToGwei converts big int wei to uint64 gwei.
// The input `v` is copied before being modified.
func WeiToGwei(v Wei) Gwei {