mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-21 19:20:39 +00:00
[caplin] pkg refactor (#7507)
Co-authored-by: Giulio <giulio.rebuffo@gmail.com>
This commit is contained in:
parent
bc169179b0
commit
cda14447ad
@ -62,7 +62,6 @@ COPY --from=tools-builder /app/build/bin/mdbx_stat /usr/local/bin/mdbx_stat
|
||||
COPY --from=builder /app/build/bin/devnet /usr/local/bin/devnet
|
||||
COPY --from=builder /app/build/bin/downloader /usr/local/bin/downloader
|
||||
COPY --from=builder /app/build/bin/erigon /usr/local/bin/erigon
|
||||
COPY --from=builder /app/build/bin/erigon-cl /usr/local/bin/erigon-cl
|
||||
COPY --from=builder /app/build/bin/evm /usr/local/bin/evm
|
||||
COPY --from=builder /app/build/bin/hack /usr/local/bin/hack
|
||||
COPY --from=builder /app/build/bin/integration /usr/local/bin/integration
|
||||
|
1
Makefile
1
Makefile
@ -108,7 +108,6 @@ erigon: go-version erigon.cmd
|
||||
COMMANDS += devnet
|
||||
COMMANDS += erigon-el-mock
|
||||
COMMANDS += downloader
|
||||
COMMANDS += erigon-cl
|
||||
COMMANDS += hack
|
||||
COMMANDS += integration
|
||||
COMMANDS += observer
|
||||
|
@ -3,9 +3,9 @@ package initial_state
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
)
|
||||
|
||||
//go:embed mainnet.state.ssz
|
||||
|
@ -1,13 +1,13 @@
|
||||
package merkle_tree_test
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/state_encoding"
|
||||
"testing"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/state_encoding"
|
||||
)
|
||||
|
||||
func TestEmptyArraysRoot(t *testing.T) {
|
||||
|
@ -2,7 +2,7 @@ package cache
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/lru"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/lru"
|
||||
)
|
||||
|
||||
var attestationIndiciesCache *lru.Cache[*cltypes.AttestationData, []uint64]
|
@ -2,7 +2,7 @@ package cache
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/lru"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/lru"
|
||||
)
|
||||
|
||||
func init() {
|
@ -3,12 +3,12 @@ package core
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
)
|
||||
|
@ -3,6 +3,7 @@ package rawdb
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/length"
|
||||
@ -10,7 +11,6 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
)
|
||||
|
||||
func EncodeNumber(n uint64) []byte {
|
@ -1,11 +1,11 @@
|
||||
package rawdb_test
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/rawdb"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/kv/memdb"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/rawdb"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -2,6 +2,7 @@ package state
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/raw"
|
||||
|
||||
"github.com/Giulio2002/bls"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
@ -10,7 +11,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/raw"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
)
|
||||
|
@ -1,6 +1,8 @@
|
||||
package state_test
|
||||
|
||||
import (
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
shuffling2 "github.com/ledgerwatch/erigon/cl/phase1/core/state/shuffling"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
@ -8,12 +10,10 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/shuffling"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func getTestState(t *testing.T) *state.BeaconState {
|
||||
func getTestState(t *testing.T) *state2.BeaconState {
|
||||
numVals := 2048
|
||||
validators := make([]*cltypes.Validator, numVals)
|
||||
for i := 0; i < numVals; i++ {
|
||||
@ -22,7 +22,7 @@ func getTestState(t *testing.T) *state.BeaconState {
|
||||
v.SetActivationEpoch(0)
|
||||
v.SetExitEpoch(10000)
|
||||
}
|
||||
b := state.GetEmptyBeaconState()
|
||||
b := state2.GetEmptyBeaconState()
|
||||
b.SetValidators(validators)
|
||||
b.SetSlot(19)
|
||||
b.SetLatestBlockHeader(&cltypes.BeaconBlockHeader{Slot: 18})
|
||||
@ -36,11 +36,11 @@ func getTestState(t *testing.T) *state.BeaconState {
|
||||
|
||||
func TestGetBlockRoot(t *testing.T) {
|
||||
epoch := uint64(2)
|
||||
testState := state.GetEmptyBeaconState()
|
||||
testState := state2.GetEmptyBeaconState()
|
||||
root := common.HexToHash("ff")
|
||||
testState.SetSlot(100)
|
||||
testState.SetBlockRootAt(int(epoch*32), root)
|
||||
retrieved, err := state.GetBlockRoot(testState.BeaconState, epoch)
|
||||
retrieved, err := state2.GetBlockRoot(testState.BeaconState, epoch)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, retrieved, root)
|
||||
}
|
||||
@ -119,9 +119,9 @@ func TestComputeShuffledIndex(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
for i, val := range tc.startInds {
|
||||
state := state.New(&clparams.MainnetBeaconConfig)
|
||||
preInputs := shuffling.ComputeShuffledIndexPreInputs(state.BeaconConfig(), tc.seed)
|
||||
got, err := shuffling.ComputeShuffledIndex(state.BeaconConfig(), val, uint64(len(tc.startInds)), tc.seed, preInputs, utils.Keccak256)
|
||||
state := state2.New(&clparams.MainnetBeaconConfig)
|
||||
preInputs := shuffling2.ComputeShuffledIndexPreInputs(state.BeaconConfig(), tc.seed)
|
||||
got, err := shuffling2.ComputeShuffledIndex(state.BeaconConfig(), val, uint64(len(tc.startInds)), tc.seed, preInputs, utils.Keccak256)
|
||||
// Non-failure case.
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
@ -134,8 +134,8 @@ func TestComputeShuffledIndex(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func generateBeaconStateWithValidators(n int) *state.BeaconState {
|
||||
b := state.GetEmptyBeaconState()
|
||||
func generateBeaconStateWithValidators(n int) *state2.BeaconState {
|
||||
b := state2.GetEmptyBeaconState()
|
||||
for i := 0; i < n; i++ {
|
||||
v := &cltypes.Validator{}
|
||||
v.SetActivationEpoch(0)
|
||||
@ -151,7 +151,7 @@ func TestComputeProposerIndex(t *testing.T) {
|
||||
copy(seed[:], []byte("seed"))
|
||||
testCases := []struct {
|
||||
description string
|
||||
state *state.BeaconState
|
||||
state *state2.BeaconState
|
||||
indices []uint64
|
||||
seed [32]byte
|
||||
expected uint64
|
||||
@ -189,7 +189,7 @@ func TestComputeProposerIndex(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
got, err := shuffling.ComputeProposerIndex(tc.state.BeaconState, tc.indices, tc.seed)
|
||||
got, err := shuffling2.ComputeProposerIndex(tc.state.BeaconState, tc.indices, tc.seed)
|
||||
if tc.wantErr {
|
||||
if err == nil {
|
||||
t.Errorf("unexpected success, wanted error")
|
||||
@ -207,7 +207,7 @@ func TestComputeProposerIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSyncReward(t *testing.T) {
|
||||
s := state.GetEmptyBeaconState()
|
||||
s := state2.GetEmptyBeaconState()
|
||||
|
||||
v := &cltypes.Validator{}
|
||||
v.SetActivationEpoch(0)
|
||||
@ -234,11 +234,11 @@ func TestComputeCommittee(t *testing.T) {
|
||||
v.SetPublicKey(k)
|
||||
validators[i] = v
|
||||
}
|
||||
bState := state.GetEmptyBeaconState()
|
||||
bState := state2.GetEmptyBeaconState()
|
||||
bState.SetValidators(validators)
|
||||
bState.SetSlot(200)
|
||||
|
||||
epoch := state.Epoch(bState.BeaconState)
|
||||
epoch := state2.Epoch(bState.BeaconState)
|
||||
indices := bState.GetActiveValidatorsIndices(epoch)
|
||||
index := uint64(5)
|
||||
// Test shuffled indices are correct for index 5 committee
|
||||
@ -248,21 +248,21 @@ func TestComputeCommittee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAttestationParticipationFlagIndices(t *testing.T) {
|
||||
beaconState := state.GetEmptyBeaconState()
|
||||
beaconState := state2.GetEmptyBeaconState()
|
||||
//beaconState, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().MaxValidatorsPerCommittee)
|
||||
beaconState.SetSlot(1)
|
||||
cfg := clparams.MainnetBeaconConfig
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
inputState state.BeaconState
|
||||
inputState state2.BeaconState
|
||||
inputData *cltypes.AttestationData
|
||||
inputDelay uint64
|
||||
participationIndices []uint8
|
||||
}{
|
||||
{
|
||||
name: "none",
|
||||
inputState: func() state.BeaconState {
|
||||
inputState: func() state2.BeaconState {
|
||||
return *beaconState
|
||||
}(),
|
||||
inputData: &cltypes.AttestationData{
|
||||
@ -276,7 +276,7 @@ func TestAttestationParticipationFlagIndices(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "participated source",
|
||||
inputState: func() state.BeaconState {
|
||||
inputState: func() state2.BeaconState {
|
||||
return *beaconState
|
||||
}(),
|
||||
inputData: &cltypes.AttestationData{
|
||||
@ -290,7 +290,7 @@ func TestAttestationParticipationFlagIndices(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "participated source and target",
|
||||
inputState: func() state.BeaconState {
|
||||
inputState: func() state2.BeaconState {
|
||||
return *beaconState
|
||||
}(),
|
||||
inputData: &cltypes.AttestationData{
|
||||
@ -302,7 +302,7 @@ func TestAttestationParticipationFlagIndices(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "participated source and target and head",
|
||||
inputState: func() state.BeaconState {
|
||||
inputState: func() state2.BeaconState {
|
||||
return *beaconState
|
||||
}(),
|
||||
inputData: &cltypes.AttestationData{
|
@ -3,15 +3,15 @@ package state
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/lru"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/raw"
|
||||
shuffling2 "github.com/ledgerwatch/erigon/cl/phase1/core/state/shuffling"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/lru"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/raw"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/shuffling"
|
||||
)
|
||||
|
||||
type HashFunc func([]byte) ([32]byte, error)
|
||||
@ -61,7 +61,7 @@ func (b *BeaconState) _updateProposerIndex() (err error) {
|
||||
hash := sha256.New()
|
||||
// Input for the seed hash.
|
||||
randao := b.RandaoMixes()
|
||||
input := shuffling.GetSeed(b.BeaconConfig(), randao[:], epoch, b.BeaconConfig().DomainBeaconProposer)
|
||||
input := shuffling2.GetSeed(b.BeaconConfig(), randao[:], epoch, b.BeaconConfig().DomainBeaconProposer)
|
||||
slotByteArray := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(slotByteArray, b.Slot())
|
||||
|
||||
@ -78,7 +78,7 @@ func (b *BeaconState) _updateProposerIndex() (err error) {
|
||||
seedArray := [32]byte{}
|
||||
copy(seedArray[:], seed)
|
||||
b.proposerIndex = new(uint64)
|
||||
*b.proposerIndex, err = shuffling.ComputeProposerIndex(b.BeaconState, indices, seedArray)
|
||||
*b.proposerIndex, err = shuffling2.ComputeProposerIndex(b.BeaconState, indices, seedArray)
|
||||
return
|
||||
}
|
||||
|
@ -3,14 +3,14 @@ package state
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/cache"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/shuffling"
|
||||
"math"
|
||||
|
||||
"github.com/Giulio2002/bls"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/cache"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/shuffling"
|
||||
)
|
||||
|
||||
// these are view functions for the beacon state cache
|
@ -2,7 +2,7 @@ package state
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/raw"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/raw"
|
||||
)
|
||||
|
||||
func (b *BeaconState) CopyInto(bs *BeaconState) (err error) {
|
@ -1,7 +1,7 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/raw"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/raw"
|
||||
)
|
||||
|
||||
func IncreaseBalance(b *raw.BeaconState, index, delta uint64) error {
|
@ -1,11 +1,11 @@
|
||||
package state_test
|
||||
|
||||
import (
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@ -13,9 +13,9 @@ const (
|
||||
testExitEpoch = 53
|
||||
)
|
||||
|
||||
func getTestStateBalances(t *testing.T) *state.BeaconState {
|
||||
func getTestStateBalances(t *testing.T) *state2.BeaconState {
|
||||
numVals := uint64(2048)
|
||||
b := state.GetEmptyBeaconState()
|
||||
b := state2.GetEmptyBeaconState()
|
||||
for i := uint64(0); i < numVals; i++ {
|
||||
v := &cltypes.Validator{}
|
||||
v.SetExitEpoch(clparams.MainnetBeaconConfig.FarFutureEpoch)
|
||||
@ -24,7 +24,7 @@ func getTestStateBalances(t *testing.T) *state.BeaconState {
|
||||
return b
|
||||
}
|
||||
|
||||
func getTestStateValidators(t *testing.T, numVals int) *state.BeaconState {
|
||||
func getTestStateValidators(t *testing.T, numVals int) *state2.BeaconState {
|
||||
validators := make([]*cltypes.Validator, numVals)
|
||||
for i := 0; i < numVals; i++ {
|
||||
v := &cltypes.Validator{}
|
||||
@ -32,7 +32,7 @@ func getTestStateValidators(t *testing.T, numVals int) *state.BeaconState {
|
||||
v.SetExitEpoch(testExitEpoch)
|
||||
validators[i] = v
|
||||
}
|
||||
b := state.GetEmptyBeaconState()
|
||||
b := state2.GetEmptyBeaconState()
|
||||
b.SetSlot(testExitEpoch * clparams.MainnetBeaconConfig.SlotsPerEpoch)
|
||||
b.SetValidators(validators)
|
||||
return b
|
||||
@ -43,7 +43,7 @@ func TestIncreaseBalance(t *testing.T) {
|
||||
testInd := uint64(42)
|
||||
amount := uint64(100)
|
||||
beforeBalance, _ := s.ValidatorBalance(int(testInd))
|
||||
state.IncreaseBalance(s.BeaconState, testInd, amount)
|
||||
state2.IncreaseBalance(s.BeaconState, testInd, amount)
|
||||
afterBalance, _ := s.ValidatorBalance(int(testInd))
|
||||
require.Equal(t, afterBalance, beforeBalance+amount)
|
||||
}
|
||||
@ -78,7 +78,7 @@ func TestDecreaseBalance(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
s := getTestStateBalances(t)
|
||||
require.NoError(t, state.DecreaseBalance(s.BeaconState, testInd, tc.delta))
|
||||
require.NoError(t, state2.DecreaseBalance(s.BeaconState, testInd, tc.delta))
|
||||
afterBalance, _ := s.ValidatorBalance(int(testInd))
|
||||
require.Equal(t, afterBalance, tc.expectedBalance)
|
||||
})
|
||||
@ -156,7 +156,7 @@ func TestSlashValidator(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
state *state.BeaconState
|
||||
state *state2.BeaconState
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
@ -5,8 +5,8 @@ import (
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/state_encoding"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/state_encoding"
|
||||
)
|
||||
|
||||
const maxEth1Votes = 2048
|
@ -5,7 +5,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/state_encoding"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/state_encoding"
|
||||
)
|
||||
|
||||
func (b *BeaconState) SetVersion(version clparams.StateVersion) {
|
@ -2,6 +2,7 @@ package raw
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/state_encoding"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/common/length"
|
||||
"github.com/ledgerwatch/erigon-lib/types/clonable"
|
||||
@ -10,7 +11,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/state_encoding"
|
||||
)
|
||||
|
||||
// BlockRoot computes the block root for the state.
|
@ -1,9 +1,8 @@
|
||||
package state_test
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
)
|
||||
|
||||
// Curr: 4358340
|
@ -3,9 +3,9 @@ package shuffling
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/raw"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/raw"
|
||||
)
|
||||
|
||||
func ComputeProposerIndex(b *raw.BeaconState, indices []uint64, seed [32]byte) (uint64, error) {
|
@ -1,12 +1,12 @@
|
||||
package shuffling_test
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/shuffling"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/shuffling"
|
||||
eth2_shuffle "github.com/protolambda/eth2-shuffle"
|
||||
)
|
||||
|
@ -2,13 +2,13 @@ package state_test
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"testing"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -1,12 +1,11 @@
|
||||
package state_encoding_test
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/state_encoding"
|
||||
"testing"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/state_encoding"
|
||||
)
|
||||
|
||||
func TestSlashingsRoot(t *testing.T) {
|
@ -2,7 +2,7 @@ package state
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/raw"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/raw"
|
||||
)
|
||||
|
||||
func GetEmptyBeaconState() *BeaconState {
|
@ -1,12 +1,12 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/lru"
|
||||
"sort"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/lru"
|
||||
)
|
||||
|
||||
func copyLRU[K comparable, V any](dst *lru.Cache[K, V], src *lru.Cache[K, V]) *lru.Cache[K, V] {
|
@ -3,16 +3,16 @@ package transition
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/metrics/methelp"
|
||||
)
|
||||
|
||||
// processBlock takes a block and transitions the state to the next slot, using the provided execution payload if enabled.
|
||||
func processBlock(state *state.BeaconState, signedBlock *cltypes.SignedBeaconBlock, fullValidation bool) error {
|
||||
func processBlock(state *state2.BeaconState, signedBlock *cltypes.SignedBeaconBlock, fullValidation bool) error {
|
||||
block := signedBlock.Block
|
||||
version := state.Version()
|
||||
// Check the state version is correct.
|
||||
@ -94,7 +94,7 @@ func processBlock(state *state.BeaconState, signedBlock *cltypes.SignedBeaconBlo
|
||||
return nil
|
||||
}
|
||||
|
||||
func processOperations(state *state.BeaconState, blockBody *cltypes.BeaconBody, fullValidation bool) error {
|
||||
func processOperations(state *state2.BeaconState, blockBody *cltypes.BeaconBody, fullValidation bool) error {
|
||||
if len(blockBody.Deposits) != int(maximumDeposits(state)) {
|
||||
return errors.New("outstanding deposits do not match maximum deposits")
|
||||
}
|
||||
@ -156,7 +156,7 @@ func processOperations(state *state.BeaconState, blockBody *cltypes.BeaconBody,
|
||||
return nil
|
||||
}
|
||||
|
||||
func maximumDeposits(state *state.BeaconState) (maxDeposits uint64) {
|
||||
func maximumDeposits(state *state2.BeaconState) (maxDeposits uint64) {
|
||||
maxDeposits = state.Eth1Data().DepositCount - state.Eth1DepositIndex()
|
||||
if maxDeposits > state.BeaconConfig().MaxDeposits {
|
||||
maxDeposits = state.BeaconConfig().MaxDeposits
|
||||
@ -165,16 +165,16 @@ func maximumDeposits(state *state.BeaconState) (maxDeposits uint64) {
|
||||
}
|
||||
|
||||
// ProcessExecutionPayload sets the latest payload header accordinly.
|
||||
func ProcessExecutionPayload(s *state.BeaconState, payload *cltypes.Eth1Block) error {
|
||||
if state.IsMergeTransitionComplete(s.BeaconState) {
|
||||
func ProcessExecutionPayload(s *state2.BeaconState, payload *cltypes.Eth1Block) error {
|
||||
if state2.IsMergeTransitionComplete(s.BeaconState) {
|
||||
if payload.ParentHash != s.LatestExecutionPayloadHeader().BlockHash {
|
||||
return fmt.Errorf("ProcessExecutionPayload: invalid eth1 chain. mismatching parent")
|
||||
}
|
||||
}
|
||||
if payload.PrevRandao != s.GetRandaoMixes(state.Epoch(s.BeaconState)) {
|
||||
if payload.PrevRandao != s.GetRandaoMixes(state2.Epoch(s.BeaconState)) {
|
||||
return fmt.Errorf("ProcessExecutionPayload: randao mix mismatches with mix digest")
|
||||
}
|
||||
if payload.Time != state.ComputeTimestampAtSlot(s.BeaconState, s.Slot()) {
|
||||
if payload.Time != state2.ComputeTimestampAtSlot(s.BeaconState, s.Slot()) {
|
||||
return fmt.Errorf("ProcessExecutionPayload: invalid Eth1 timestamp")
|
||||
}
|
||||
payloadHeader, err := payload.PayloadHeader()
|
||||
@ -185,6 +185,6 @@ func ProcessExecutionPayload(s *state.BeaconState, payload *cltypes.Eth1Block) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func executionEnabled(s *state.BeaconState, payload *cltypes.Eth1Block) bool {
|
||||
return (!state.IsMergeTransitionComplete(s.BeaconState) && payload.BlockHash != libcommon.Hash{}) || state.IsMergeTransitionComplete(s.BeaconState)
|
||||
func executionEnabled(s *state2.BeaconState, payload *cltypes.Eth1Block) bool {
|
||||
return (!state2.IsMergeTransitionComplete(s.BeaconState) && payload.BlockHash != libcommon.Hash{}) || state2.IsMergeTransitionComplete(s.BeaconState)
|
||||
}
|
@ -3,14 +3,14 @@ package transition
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
)
|
||||
|
||||
// weighJustificationAndFinalization checks justification and finality of epochs and adds records to the state as needed.
|
||||
func weighJustificationAndFinalization(s *state.BeaconState, previousEpochTargetBalance, currentEpochTargetBalance uint64) error {
|
||||
func weighJustificationAndFinalization(s *state2.BeaconState, previousEpochTargetBalance, currentEpochTargetBalance uint64) error {
|
||||
totalActiveBalance := s.GetTotalActiveBalance()
|
||||
currentEpoch := state.Epoch(s.BeaconState)
|
||||
previousEpoch := state.PreviousEpoch(s.BeaconState)
|
||||
currentEpoch := state2.Epoch(s.BeaconState)
|
||||
previousEpoch := state2.PreviousEpoch(s.BeaconState)
|
||||
oldPreviousJustifiedCheckpoint := s.PreviousJustifiedCheckpoint()
|
||||
oldCurrentJustifiedCheckpoint := s.CurrentJustifiedCheckpoint()
|
||||
justificationBits := s.JustificationBits()
|
||||
@ -22,7 +22,7 @@ func weighJustificationAndFinalization(s *state.BeaconState, previousEpochTarget
|
||||
justificationBits[0] = false
|
||||
// Update justified checkpoint if super majority is reached on previous epoch
|
||||
if previousEpochTargetBalance*3 >= totalActiveBalance*2 {
|
||||
checkPointRoot, err := state.GetBlockRoot(s.BeaconState, previousEpoch)
|
||||
checkPointRoot, err := state2.GetBlockRoot(s.BeaconState, previousEpoch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -33,7 +33,7 @@ func weighJustificationAndFinalization(s *state.BeaconState, previousEpochTarget
|
||||
justificationBits[1] = true
|
||||
}
|
||||
if currentEpochTargetBalance*3 >= totalActiveBalance*2 {
|
||||
checkPointRoot, err := state.GetBlockRoot(s.BeaconState, currentEpoch)
|
||||
checkPointRoot, err := state2.GetBlockRoot(s.BeaconState, currentEpoch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -61,9 +61,9 @@ func weighJustificationAndFinalization(s *state.BeaconState, previousEpochTarget
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProcessJustificationBitsAndFinality(s *state.BeaconState) error {
|
||||
currentEpoch := state.Epoch(s.BeaconState)
|
||||
previousEpoch := state.PreviousEpoch(s.BeaconState)
|
||||
func ProcessJustificationBitsAndFinality(s *state2.BeaconState) error {
|
||||
currentEpoch := state2.Epoch(s.BeaconState)
|
||||
previousEpoch := state2.PreviousEpoch(s.BeaconState)
|
||||
beaconConfig := s.BeaconConfig()
|
||||
// Skip for first 2 epochs
|
||||
if currentEpoch <= beaconConfig.GenesisEpoch+1 {
|
@ -3,6 +3,7 @@ package transition
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
|
||||
"github.com/Giulio2002/bls"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
@ -11,11 +12,10 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
)
|
||||
|
||||
func ProcessProposerSlashing(s *state.BeaconState, propSlashing *cltypes.ProposerSlashing) error {
|
||||
func ProcessProposerSlashing(s *state2.BeaconState, propSlashing *cltypes.ProposerSlashing) error {
|
||||
h1 := propSlashing.Header1.Header
|
||||
h2 := propSlashing.Header2.Header
|
||||
|
||||
@ -43,12 +43,12 @@ func ProcessProposerSlashing(s *state.BeaconState, propSlashing *cltypes.Propose
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !proposer.IsSlashable(state.Epoch(s.BeaconState)) {
|
||||
if !proposer.IsSlashable(state2.Epoch(s.BeaconState)) {
|
||||
return fmt.Errorf("proposer is not slashable: %v", proposer)
|
||||
}
|
||||
|
||||
for _, signedHeader := range []*cltypes.SignedBeaconBlockHeader{propSlashing.Header1, propSlashing.Header2} {
|
||||
domain, err := s.GetDomain(s.BeaconConfig().DomainBeaconProposer, state.GetEpochAtSlot(s.BeaconConfig(), signedHeader.Header.Slot))
|
||||
domain, err := s.GetDomain(s.BeaconConfig().DomainBeaconProposer, state2.GetEpochAtSlot(s.BeaconConfig(), signedHeader.Header.Slot))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get domain: %v", err)
|
||||
}
|
||||
@ -71,7 +71,7 @@ func ProcessProposerSlashing(s *state.BeaconState, propSlashing *cltypes.Propose
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProcessAttesterSlashing(s *state.BeaconState, attSlashing *cltypes.AttesterSlashing) error {
|
||||
func ProcessAttesterSlashing(s *state2.BeaconState, attSlashing *cltypes.AttesterSlashing) error {
|
||||
att1 := attSlashing.Attestation_1
|
||||
att2 := attSlashing.Attestation_2
|
||||
|
||||
@ -79,7 +79,7 @@ func ProcessAttesterSlashing(s *state.BeaconState, attSlashing *cltypes.Attester
|
||||
return fmt.Errorf("attestation data not slashable: %+v; %+v", att1.Data, att2.Data)
|
||||
}
|
||||
|
||||
valid, err := state.IsValidIndexedAttestation(s.BeaconState, att1)
|
||||
valid, err := state2.IsValidIndexedAttestation(s.BeaconState, att1)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error calculating indexed attestation 1 validity: %v", err)
|
||||
}
|
||||
@ -87,7 +87,7 @@ func ProcessAttesterSlashing(s *state.BeaconState, attSlashing *cltypes.Attester
|
||||
return fmt.Errorf("invalid indexed attestation 1")
|
||||
}
|
||||
|
||||
valid, err = state.IsValidIndexedAttestation(s.BeaconState, att2)
|
||||
valid, err = state2.IsValidIndexedAttestation(s.BeaconState, att2)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error calculating indexed attestation 2 validity: %v", err)
|
||||
}
|
||||
@ -96,7 +96,7 @@ func ProcessAttesterSlashing(s *state.BeaconState, attSlashing *cltypes.Attester
|
||||
}
|
||||
|
||||
slashedAny := false
|
||||
currentEpoch := state.GetEpochAtSlot(s.BeaconConfig(), s.Slot())
|
||||
currentEpoch := state2.GetEpochAtSlot(s.BeaconConfig(), s.Slot())
|
||||
for _, ind := range utils.IntersectionOfSortedSets(att1.AttestingIndices, att2.AttestingIndices) {
|
||||
validator, err := s.ValidatorForValidatorIndex(int(ind))
|
||||
if err != nil {
|
||||
@ -117,7 +117,7 @@ func ProcessAttesterSlashing(s *state.BeaconState, attSlashing *cltypes.Attester
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProcessDeposit(s *state.BeaconState, deposit *cltypes.Deposit, fullValidation bool) error {
|
||||
func ProcessDeposit(s *state2.BeaconState, deposit *cltypes.Deposit, fullValidation bool) error {
|
||||
if deposit == nil {
|
||||
return nil
|
||||
}
|
||||
@ -163,7 +163,7 @@ func ProcessDeposit(s *state.BeaconState, deposit *cltypes.Deposit, fullValidati
|
||||
return nil
|
||||
}
|
||||
// Append validator
|
||||
s.AddValidator(state.ValidatorFromDeposit(s.BeaconConfig(), deposit), amount)
|
||||
s.AddValidator(state2.ValidatorFromDeposit(s.BeaconConfig(), deposit), amount)
|
||||
// Altair forward
|
||||
if s.Version() >= clparams.AltairVersion {
|
||||
s.AddCurrentEpochParticipationFlags(cltypes.ParticipationFlags(0))
|
||||
@ -173,14 +173,14 @@ func ProcessDeposit(s *state.BeaconState, deposit *cltypes.Deposit, fullValidati
|
||||
return nil
|
||||
}
|
||||
// Increase the balance if exists already
|
||||
return state.IncreaseBalance(s.BeaconState, validatorIndex, amount)
|
||||
return state2.IncreaseBalance(s.BeaconState, validatorIndex, amount)
|
||||
}
|
||||
|
||||
// ProcessVoluntaryExit takes a voluntary exit and applies state transition.
|
||||
func ProcessVoluntaryExit(s *state.BeaconState, signedVoluntaryExit *cltypes.SignedVoluntaryExit, fullValidation bool) error {
|
||||
func ProcessVoluntaryExit(s *state2.BeaconState, signedVoluntaryExit *cltypes.SignedVoluntaryExit, fullValidation bool) error {
|
||||
// Sanity checks so that we know it is good.
|
||||
voluntaryExit := signedVoluntaryExit.VolunaryExit
|
||||
currentEpoch := state.Epoch(s.BeaconState)
|
||||
currentEpoch := state2.Epoch(s.BeaconState)
|
||||
validator, err := s.ValidatorForValidatorIndex(int(voluntaryExit.ValidatorIndex))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -223,7 +223,7 @@ func ProcessVoluntaryExit(s *state.BeaconState, signedVoluntaryExit *cltypes.Sig
|
||||
|
||||
// ProcessWithdrawals processes withdrawals by decreasing the balance of each validator
|
||||
// and updating the next withdrawal index and validator index.
|
||||
func ProcessWithdrawals(s *state.BeaconState, withdrawals types.Withdrawals, fullValidation bool) error {
|
||||
func ProcessWithdrawals(s *state2.BeaconState, withdrawals types.Withdrawals, fullValidation bool) error {
|
||||
// Get the list of withdrawals, the expected withdrawals (if performing full validation),
|
||||
// and the beacon configuration.
|
||||
beaconConfig := s.BeaconConfig()
|
||||
@ -231,7 +231,7 @@ func ProcessWithdrawals(s *state.BeaconState, withdrawals types.Withdrawals, ful
|
||||
|
||||
// Check if full validation is required and verify expected withdrawals.
|
||||
if fullValidation {
|
||||
expectedWithdrawals := state.ExpectedWithdrawals(s.BeaconState)
|
||||
expectedWithdrawals := state2.ExpectedWithdrawals(s.BeaconState)
|
||||
if len(expectedWithdrawals) != len(withdrawals) {
|
||||
return fmt.Errorf("ProcessWithdrawals: expected %d withdrawals, but got %d", len(expectedWithdrawals), len(withdrawals))
|
||||
}
|
||||
@ -244,7 +244,7 @@ func ProcessWithdrawals(s *state.BeaconState, withdrawals types.Withdrawals, ful
|
||||
|
||||
// Decrease the balance of each validator for the corresponding withdrawal.
|
||||
for _, withdrawal := range withdrawals {
|
||||
if err := state.DecreaseBalance(s.BeaconState, withdrawal.Validator, withdrawal.Amount); err != nil {
|
||||
if err := state2.DecreaseBalance(s.BeaconState, withdrawal.Validator, withdrawal.Amount); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package transition
|
||||
|
||||
import (
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"testing"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
@ -8,7 +9,6 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
)
|
||||
|
||||
@ -122,7 +122,7 @@ func TestProcessProposerSlashing(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
state *state.BeaconState
|
||||
state *state2.BeaconState
|
||||
slashing *cltypes.ProposerSlashing
|
||||
wantErr bool
|
||||
}{
|
||||
@ -236,7 +236,7 @@ func TestProcessAttesterSlashing(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
state *state.BeaconState
|
||||
state *state2.BeaconState
|
||||
slashing *cltypes.AttesterSlashing
|
||||
wantErr bool
|
||||
}{
|
||||
@ -320,7 +320,7 @@ func TestProcessDeposit(t *testing.T) {
|
||||
WithdrawalCredentials: libcommon.HexToHash("00ec7ef7780c9d151597924036262dd28dc60e1228f4da6fecf9d402cb3f3594"),
|
||||
},
|
||||
}
|
||||
testState := state.GetEmptyBeaconState()
|
||||
testState := state2.GetEmptyBeaconState()
|
||||
v := &cltypes.Validator{}
|
||||
v.SetPublicKey([48]byte{1})
|
||||
v.SetWithdrawalCredentials([32]byte{1, 2, 3})
|
||||
@ -333,7 +333,7 @@ func TestProcessDeposit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessVoluntaryExits(t *testing.T) {
|
||||
state := state.GetEmptyBeaconState()
|
||||
state := state2.GetEmptyBeaconState()
|
||||
exit := &cltypes.SignedVoluntaryExit{
|
||||
VolunaryExit: &cltypes.VoluntaryExit{
|
||||
ValidatorIndex: 0,
|
@ -3,16 +3,16 @@ package transition
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/metrics/methelp"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
func ProcessAttestations(s *state.BeaconState, attestations []*cltypes.Attestation, fullValidation bool) error {
|
||||
func ProcessAttestations(s *state2.BeaconState, attestations []*cltypes.Attestation, fullValidation bool) error {
|
||||
var err error
|
||||
attestingIndiciesSet := make([][]uint64, len(attestations))
|
||||
h := methelp.NewHistTimer("beacon_process_attestations")
|
||||
@ -40,9 +40,9 @@ func ProcessAttestations(s *state.BeaconState, attestations []*cltypes.Attestati
|
||||
return nil
|
||||
}
|
||||
|
||||
func processAttestationPostAltair(s *state.BeaconState, attestation *cltypes.Attestation, baseRewardPerIncrement uint64) ([]uint64, error) {
|
||||
func processAttestationPostAltair(s *state2.BeaconState, attestation *cltypes.Attestation, baseRewardPerIncrement uint64) ([]uint64, error) {
|
||||
data := attestation.Data
|
||||
currentEpoch := state.Epoch(s.BeaconState)
|
||||
currentEpoch := state2.Epoch(s.BeaconState)
|
||||
stateSlot := s.Slot()
|
||||
beaconConfig := s.BeaconConfig()
|
||||
|
||||
@ -95,11 +95,11 @@ func processAttestationPostAltair(s *state.BeaconState, attestation *cltypes.Att
|
||||
c.PutSince()
|
||||
proposerRewardDenominator := (beaconConfig.WeightDenominator - beaconConfig.ProposerWeight) * beaconConfig.WeightDenominator / beaconConfig.ProposerWeight
|
||||
reward := proposerRewardNumerator / proposerRewardDenominator
|
||||
return attestingIndicies, state.IncreaseBalance(s.BeaconState, proposer, reward)
|
||||
return attestingIndicies, state2.IncreaseBalance(s.BeaconState, proposer, reward)
|
||||
}
|
||||
|
||||
// processAttestationsPhase0 implements the rules for phase0 processing.
|
||||
func processAttestationPhase0(s *state.BeaconState, attestation *cltypes.Attestation) ([]uint64, error) {
|
||||
func processAttestationPhase0(s *state2.BeaconState, attestation *cltypes.Attestation) ([]uint64, error) {
|
||||
data := attestation.Data
|
||||
committee, err := s.GetBeaconCommitee(data.Slot, data.Index)
|
||||
if err != nil {
|
||||
@ -121,7 +121,7 @@ func processAttestationPhase0(s *state.BeaconState, attestation *cltypes.Attesta
|
||||
InclusionDelay: s.Slot() - data.Slot,
|
||||
ProposerIndex: proposerIndex,
|
||||
}
|
||||
isCurrentAttestation := data.Target.Epoch == state.Epoch(s.BeaconState)
|
||||
isCurrentAttestation := data.Target.Epoch == state2.Epoch(s.BeaconState)
|
||||
// Depending of what slot we are on we put in either the current justified or previous justified.
|
||||
if isCurrentAttestation {
|
||||
if !data.Source.Equal(s.CurrentJustifiedCheckpoint()) {
|
||||
@ -139,7 +139,7 @@ func processAttestationPhase0(s *state.BeaconState, attestation *cltypes.Attesta
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
epochRoot, err := state.GetBlockRoot(s.BeaconState, attestation.Data.Target.Epoch)
|
||||
epochRoot, err := state2.GetBlockRoot(s.BeaconState, attestation.Data.Target.Epoch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -186,14 +186,14 @@ func processAttestationPhase0(s *state.BeaconState, attestation *cltypes.Attesta
|
||||
}
|
||||
|
||||
// ProcessAttestation takes an attestation and process it.
|
||||
func processAttestation(s *state.BeaconState, attestation *cltypes.Attestation, baseRewardPerIncrement uint64) ([]uint64, error) {
|
||||
func processAttestation(s *state2.BeaconState, attestation *cltypes.Attestation, baseRewardPerIncrement uint64) ([]uint64, error) {
|
||||
data := attestation.Data
|
||||
currentEpoch := state.Epoch(s.BeaconState)
|
||||
previousEpoch := state.PreviousEpoch(s.BeaconState)
|
||||
currentEpoch := state2.Epoch(s.BeaconState)
|
||||
previousEpoch := state2.PreviousEpoch(s.BeaconState)
|
||||
stateSlot := s.Slot()
|
||||
beaconConfig := s.BeaconConfig()
|
||||
// Prelimary checks.
|
||||
if (data.Target.Epoch != currentEpoch && data.Target.Epoch != previousEpoch) || data.Target.Epoch != state.GetEpochAtSlot(s.BeaconConfig(), data.Slot) {
|
||||
if (data.Target.Epoch != currentEpoch && data.Target.Epoch != previousEpoch) || data.Target.Epoch != state2.GetEpochAtSlot(s.BeaconConfig(), data.Slot) {
|
||||
return nil, errors.New("ProcessAttestation: attestation with invalid epoch")
|
||||
}
|
||||
if data.Slot+beaconConfig.MinAttestationInclusionDelay > stateSlot || stateSlot > data.Slot+beaconConfig.SlotsPerEpoch {
|
||||
@ -209,10 +209,10 @@ func processAttestation(s *state.BeaconState, attestation *cltypes.Attestation,
|
||||
return processAttestationPostAltair(s, attestation, baseRewardPerIncrement)
|
||||
}
|
||||
|
||||
func verifyAttestations(s *state.BeaconState, attestations []*cltypes.Attestation, attestingIndicies [][]uint64) (bool, error) {
|
||||
func verifyAttestations(s *state2.BeaconState, attestations []*cltypes.Attestation, attestingIndicies [][]uint64) (bool, error) {
|
||||
for i, attestation := range attestations {
|
||||
indexedAttestation := state.GetIndexedAttestation(attestation, attestingIndicies[i])
|
||||
success, err := state.IsValidIndexedAttestation(s.BeaconState, indexedAttestation)
|
||||
indexedAttestation := state2.GetIndexedAttestation(attestation, attestingIndicies[i])
|
||||
success, err := state2.IsValidIndexedAttestation(s.BeaconState, indexedAttestation)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
@ -3,12 +3,12 @@ package transition
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
|
||||
"github.com/Giulio2002/bls"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
)
|
||||
|
||||
// ProcessBlsToExecutionChange processes a BLSToExecutionChange message by updating a validator's withdrawal credentials.
|
@ -2,8 +2,8 @@ package transition
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
)
|
||||
|
||||
// ProcessEffectiveBalanceUpdates updates the effective balance of validators. Specs at: https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#effective-balances-updates
|
@ -3,7 +3,7 @@ package transition
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
)
|
||||
|
||||
// ProcessEpoch process epoch transition.
|
@ -2,12 +2,12 @@ package transition_test
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
transition2 "github.com/ledgerwatch/erigon/cl/phase1/core/transition"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/transition"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@ -90,64 +90,64 @@ var startingSlashingsResetState []byte
|
||||
|
||||
func TestProcessRewardsAndPenalties(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingRewardsPenaltyState, expectedRewardsPenaltyState, func(s *state.BeaconState) error {
|
||||
return transition.ProcessRewardsAndPenalties(s)
|
||||
return transition2.ProcessRewardsAndPenalties(s)
|
||||
})
|
||||
}
|
||||
|
||||
func TestProcessRegistryUpdates(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingRegistryUpdatesState, expectedRegistryUpdatesState, func(s *state.BeaconState) error {
|
||||
return transition.ProcessRegistryUpdates(s)
|
||||
return transition2.ProcessRegistryUpdates(s)
|
||||
})
|
||||
}
|
||||
|
||||
func TestProcessEffectiveBalances(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingEffectiveBalancesState, expectedEffectiveBalancesState, func(s *state.BeaconState) error {
|
||||
return transition.ProcessEffectiveBalanceUpdates(s)
|
||||
return transition2.ProcessEffectiveBalanceUpdates(s)
|
||||
})
|
||||
}
|
||||
|
||||
func TestProcessHistoricalRoots(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingHistoricalRootsState, expectedHistoricalRootsState, func(s *state.BeaconState) error {
|
||||
return transition.ProcessHistoricalRootsUpdate(s)
|
||||
return transition2.ProcessHistoricalRootsUpdate(s)
|
||||
})
|
||||
}
|
||||
|
||||
func TestProcessParticipationFlagUpdates(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingParticipationFlagState, expectedParticipationFlagState, func(s *state.BeaconState) error {
|
||||
transition.ProcessParticipationFlagUpdates(s)
|
||||
transition2.ProcessParticipationFlagUpdates(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func TestProcessSlashings(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingSlashingsState, expectedSlashingsState, func(s *state.BeaconState) error {
|
||||
return transition.ProcessSlashings(s)
|
||||
return transition2.ProcessSlashings(s)
|
||||
})
|
||||
}
|
||||
|
||||
func TestProcessJustificationAndFinality(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingJustificationAndFinalityState, expectedJustificationAndFinalityState, func(s *state.BeaconState) error {
|
||||
return transition.ProcessJustificationBitsAndFinality(s)
|
||||
return transition2.ProcessJustificationBitsAndFinality(s)
|
||||
})
|
||||
}
|
||||
|
||||
func TestEth1DataReset(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingEth1DataResetState, expectedEth1DataResetState, func(s *state.BeaconState) error {
|
||||
transition.ProcessEth1DataReset(s)
|
||||
transition2.ProcessEth1DataReset(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func TestRandaoMixesReset(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingRandaoMixesResetState, expectedRandaoMixesResetState, func(s *state.BeaconState) error {
|
||||
transition.ProcessRandaoMixesReset(s)
|
||||
transition2.ProcessRandaoMixesReset(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func TestSlashingsReset(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingSlashingsResetState, expectedSlashingsResetState, func(s *state.BeaconState) error {
|
||||
transition.ProcessSlashingsReset(s)
|
||||
transition2.ProcessSlashingsReset(s)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@ -160,6 +160,6 @@ var startingInactivityScoresState []byte
|
||||
|
||||
func TestInactivityScores(t *testing.T) {
|
||||
runEpochTransitionConsensusTest(t, startingInactivityScoresState, expectedInactivityScoresState, func(s *state.BeaconState) error {
|
||||
return transition.ProcessInactivityScores(s)
|
||||
return transition2.ProcessInactivityScores(s)
|
||||
})
|
||||
}
|
@ -1,28 +1,28 @@
|
||||
package transition
|
||||
|
||||
import (
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
)
|
||||
|
||||
// ProcessInactivityScores will updates the inactivity registry of each validator.
|
||||
func ProcessInactivityScores(s *state.BeaconState) error {
|
||||
if state.Epoch(s.BeaconState) == s.BeaconConfig().GenesisEpoch {
|
||||
func ProcessInactivityScores(s *state2.BeaconState) error {
|
||||
if state2.Epoch(s.BeaconState) == s.BeaconConfig().GenesisEpoch {
|
||||
return nil
|
||||
}
|
||||
previousEpoch := state.PreviousEpoch(s.BeaconState)
|
||||
for _, validatorIndex := range state.EligibleValidatorsIndicies(s.BeaconState) {
|
||||
previousEpoch := state2.PreviousEpoch(s.BeaconState)
|
||||
for _, validatorIndex := range state2.EligibleValidatorsIndicies(s.BeaconState) {
|
||||
// retrieve validator inactivity score index.
|
||||
score, err := s.ValidatorInactivityScore(int(validatorIndex))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if state.IsUnslashedParticipatingIndex(s.BeaconState, previousEpoch, validatorIndex, int(s.BeaconConfig().TimelyTargetFlagIndex)) {
|
||||
if state2.IsUnslashedParticipatingIndex(s.BeaconState, previousEpoch, validatorIndex, int(s.BeaconConfig().TimelyTargetFlagIndex)) {
|
||||
score -= utils.Min64(1, score)
|
||||
} else {
|
||||
score += s.BeaconConfig().InactivityScoreBias
|
||||
}
|
||||
if !state.InactivityLeaking(s.BeaconState) {
|
||||
if !state2.InactivityLeaking(s.BeaconState) {
|
||||
score -= utils.Min64(s.BeaconConfig().InactivityScoreRecoveryRate, score)
|
||||
}
|
||||
if err := s.SetValidatorInactivityScore(int(validatorIndex), score); err != nil {
|
@ -1,11 +1,11 @@
|
||||
package transition
|
||||
|
||||
import (
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"sort"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
)
|
||||
|
||||
// computeActivationExitEpoch is Implementation of compute_activation_exit_epoch. Defined in https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#compute_activation_exit_epoch.
|
||||
@ -14,15 +14,15 @@ func computeActivationExitEpoch(beaconConfig *clparams.BeaconChainConfig, epoch
|
||||
}
|
||||
|
||||
// ProcessRegistyUpdates updates every epoch the activation status of validators. Specs at: https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#registry-updates.
|
||||
func ProcessRegistryUpdates(s *state.BeaconState) error {
|
||||
func ProcessRegistryUpdates(s *state2.BeaconState) error {
|
||||
beaconConfig := s.BeaconConfig()
|
||||
currentEpoch := state.Epoch(s.BeaconState)
|
||||
currentEpoch := state2.Epoch(s.BeaconState)
|
||||
// start also initializing the activation queue.
|
||||
activationQueue := make([]uint64, 0)
|
||||
// Process activation eligibility and ejections.
|
||||
var err error
|
||||
s.ForEachValidator(func(validator *cltypes.Validator, validatorIndex, total int) bool {
|
||||
if state.IsValidatorEligibleForActivationQueue(s.BeaconState, validator) {
|
||||
if state2.IsValidatorEligibleForActivationQueue(s.BeaconState, validator) {
|
||||
s.SetActivationEligibilityEpochForValidatorAtIndex(validatorIndex, currentEpoch+1)
|
||||
}
|
||||
if validator.Active(currentEpoch) && validator.EffectiveBalance() <= beaconConfig.EjectionBalance {
|
||||
@ -31,7 +31,7 @@ func ProcessRegistryUpdates(s *state.BeaconState) error {
|
||||
}
|
||||
}
|
||||
// Insert in the activation queue in case.
|
||||
if state.IsValidatorEligibleForActivation(s.BeaconState, validator) {
|
||||
if state2.IsValidatorEligibleForActivation(s.BeaconState, validator) {
|
||||
activationQueue = append(activationQueue, uint64(validatorIndex))
|
||||
}
|
||||
return true
|
@ -3,16 +3,16 @@ package transition
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
)
|
||||
|
||||
func processRewardsAndPenaltiesPostAltair(s *state.BeaconState) (err error) {
|
||||
func processRewardsAndPenaltiesPostAltair(s *state2.BeaconState) (err error) {
|
||||
beaconConfig := s.BeaconConfig()
|
||||
weights := beaconConfig.ParticipationWeights()
|
||||
eligibleValidators := state.EligibleValidatorsIndicies(s.BeaconState)
|
||||
eligibleValidators := state2.EligibleValidatorsIndicies(s.BeaconState)
|
||||
// Initialize variables
|
||||
totalActiveBalance := s.GetTotalActiveBalance()
|
||||
previousEpoch := state.PreviousEpoch(s.BeaconState)
|
||||
previousEpoch := state2.PreviousEpoch(s.BeaconState)
|
||||
// Inactivity penalties denominator.
|
||||
inactivityPenaltyDenominator := beaconConfig.InactivityScoreBias * beaconConfig.GetPenaltyQuotient(s.Version())
|
||||
// Make buffer for flag indexes total balances.
|
||||
@ -20,7 +20,7 @@ func processRewardsAndPenaltiesPostAltair(s *state.BeaconState) (err error) {
|
||||
// Compute all total balances for each enable unslashed validator indicies with all flags on.
|
||||
s.ForEachValidator(func(validator *cltypes.Validator, validatorIndex, total int) bool {
|
||||
for i := range weights {
|
||||
if state.IsUnslashedParticipatingIndex(s.BeaconState, previousEpoch, uint64(validatorIndex), i) {
|
||||
if state2.IsUnslashedParticipatingIndex(s.BeaconState, previousEpoch, uint64(validatorIndex), i) {
|
||||
flagsTotalBalances[i] += validator.EffectiveBalance()
|
||||
}
|
||||
}
|
||||
@ -40,20 +40,20 @@ func processRewardsAndPenaltiesPostAltair(s *state.BeaconState) (err error) {
|
||||
return
|
||||
}
|
||||
for flagIdx := range weights {
|
||||
if state.IsUnslashedParticipatingIndex(s.BeaconState, previousEpoch, index, flagIdx) {
|
||||
if !state.InactivityLeaking(s.BeaconState) {
|
||||
if state2.IsUnslashedParticipatingIndex(s.BeaconState, previousEpoch, index, flagIdx) {
|
||||
if !state2.InactivityLeaking(s.BeaconState) {
|
||||
rewardNumerator := baseReward * rewardMultipliers[flagIdx]
|
||||
if err := state.IncreaseBalance(s.BeaconState, index, rewardNumerator/rewardDenominator); err != nil {
|
||||
if err := state2.IncreaseBalance(s.BeaconState, index, rewardNumerator/rewardDenominator); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else if flagIdx != int(beaconConfig.TimelyHeadFlagIndex) {
|
||||
if err := state.DecreaseBalance(s.BeaconState, index, baseReward*weights[flagIdx]/beaconConfig.WeightDenominator); err != nil {
|
||||
if err := state2.DecreaseBalance(s.BeaconState, index, baseReward*weights[flagIdx]/beaconConfig.WeightDenominator); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if !state.IsUnslashedParticipatingIndex(s.BeaconState, previousEpoch, index, int(beaconConfig.TimelyTargetFlagIndex)) {
|
||||
if !state2.IsUnslashedParticipatingIndex(s.BeaconState, previousEpoch, index, int(beaconConfig.TimelyTargetFlagIndex)) {
|
||||
inactivityScore, err := s.ValidatorInactivityScore(int(index))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -63,19 +63,19 @@ func processRewardsAndPenaltiesPostAltair(s *state.BeaconState) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
state.DecreaseBalance(s.BeaconState, index, (effectiveBalance*inactivityScore)/inactivityPenaltyDenominator)
|
||||
state2.DecreaseBalance(s.BeaconState, index, (effectiveBalance*inactivityScore)/inactivityPenaltyDenominator)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// processRewardsAndPenaltiesPhase0 process rewards and penalties for phase0 state.
|
||||
func processRewardsAndPenaltiesPhase0(s *state.BeaconState) (err error) {
|
||||
func processRewardsAndPenaltiesPhase0(s *state2.BeaconState) (err error) {
|
||||
beaconConfig := s.BeaconConfig()
|
||||
if state.Epoch(s.BeaconState) == beaconConfig.GenesisEpoch {
|
||||
if state2.Epoch(s.BeaconState) == beaconConfig.GenesisEpoch {
|
||||
return nil
|
||||
}
|
||||
eligibleValidators := state.EligibleValidatorsIndicies(s.BeaconState)
|
||||
eligibleValidators := state2.EligibleValidatorsIndicies(s.BeaconState)
|
||||
// Initialize variables
|
||||
rewardDenominator := s.GetTotalActiveBalance() / beaconConfig.EffectiveBalanceIncrement
|
||||
// Make buffer for flag indexes totTargetal balances.
|
||||
@ -113,47 +113,47 @@ func processRewardsAndPenaltiesPhase0(s *state.BeaconState) (err error) {
|
||||
// we can use a multiplier to account for all attesting
|
||||
attested, missed := currentValidator.DutiesAttested()
|
||||
// If we attested then we reward the validator.
|
||||
if state.InactivityLeaking(s.BeaconState) {
|
||||
if err := state.IncreaseBalance(s.BeaconState, index, baseReward*attested); err != nil {
|
||||
if state2.InactivityLeaking(s.BeaconState) {
|
||||
if err := state2.IncreaseBalance(s.BeaconState, index, baseReward*attested); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if !currentValidator.Slashed() && currentValidator.IsPreviousMatchingSourceAttester {
|
||||
rewardNumerator := baseReward * unslashedMatchingSourceBalanceIncrements
|
||||
if err := state.IncreaseBalance(s.BeaconState, index, rewardNumerator/rewardDenominator); err != nil {
|
||||
if err := state2.IncreaseBalance(s.BeaconState, index, rewardNumerator/rewardDenominator); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !currentValidator.Slashed() && currentValidator.IsPreviousMatchingTargetAttester {
|
||||
rewardNumerator := baseReward * unslashedMatchingTargetBalanceIncrements
|
||||
if err := state.IncreaseBalance(s.BeaconState, index, rewardNumerator/rewardDenominator); err != nil {
|
||||
if err := state2.IncreaseBalance(s.BeaconState, index, rewardNumerator/rewardDenominator); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !currentValidator.Slashed() && currentValidator.IsPreviousMatchingHeadAttester {
|
||||
rewardNumerator := baseReward * unslashedMatchingHeadBalanceIncrements
|
||||
if err := state.IncreaseBalance(s.BeaconState, index, rewardNumerator/rewardDenominator); err != nil {
|
||||
if err := state2.IncreaseBalance(s.BeaconState, index, rewardNumerator/rewardDenominator); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
// Process inactivity of the network as a whole finalities.
|
||||
if state.InactivityLeaking(s.BeaconState) {
|
||||
if state2.InactivityLeaking(s.BeaconState) {
|
||||
proposerReward := baseReward / beaconConfig.ProposerRewardQuotient
|
||||
// Neutralize rewards.
|
||||
if state.DecreaseBalance(s.BeaconState, index, beaconConfig.BaseRewardsPerEpoch*baseReward-proposerReward); err != nil {
|
||||
if state2.DecreaseBalance(s.BeaconState, index, beaconConfig.BaseRewardsPerEpoch*baseReward-proposerReward); err != nil {
|
||||
return err
|
||||
}
|
||||
if currentValidator.Slashed() || !currentValidator.IsPreviousMatchingTargetAttester {
|
||||
// Increase penalities linearly if network is leaking.
|
||||
if state.DecreaseBalance(s.BeaconState, index, currentValidator.EffectiveBalance()*state.FinalityDelay(s.BeaconState)/beaconConfig.InactivityPenaltyQuotient); err != nil {
|
||||
if state2.DecreaseBalance(s.BeaconState, index, currentValidator.EffectiveBalance()*state2.FinalityDelay(s.BeaconState)/beaconConfig.InactivityPenaltyQuotient); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For each missed duty we penalize the validator.
|
||||
if state.DecreaseBalance(s.BeaconState, index, baseReward*missed); err != nil {
|
||||
if state2.DecreaseBalance(s.BeaconState, index, baseReward*missed); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -172,11 +172,11 @@ func processRewardsAndPenaltiesPhase0(s *state.BeaconState) (err error) {
|
||||
}
|
||||
// Compute proposer reward.
|
||||
proposerReward := (baseReward / beaconConfig.ProposerRewardQuotient)
|
||||
if err = state.IncreaseBalance(s.BeaconState, attestation.ProposerIndex, proposerReward); err != nil {
|
||||
if err = state2.IncreaseBalance(s.BeaconState, attestation.ProposerIndex, proposerReward); err != nil {
|
||||
return false
|
||||
}
|
||||
maxAttesterReward := baseReward - proposerReward
|
||||
if err = state.IncreaseBalance(s.BeaconState, uint64(index), maxAttesterReward/attestation.InclusionDelay); err != nil {
|
||||
if err = state2.IncreaseBalance(s.BeaconState, uint64(index), maxAttesterReward/attestation.InclusionDelay); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@ -188,8 +188,8 @@ func processRewardsAndPenaltiesPhase0(s *state.BeaconState) (err error) {
|
||||
}
|
||||
|
||||
// ProcessRewardsAndPenalties applies rewards/penalties accumulated during previous epoch.
|
||||
func ProcessRewardsAndPenalties(s *state.BeaconState) error {
|
||||
if state.Epoch(s.BeaconState) == s.BeaconConfig().GenesisEpoch {
|
||||
func ProcessRewardsAndPenalties(s *state2.BeaconState) error {
|
||||
if state2.Epoch(s.BeaconState) == s.BeaconConfig().GenesisEpoch {
|
||||
return nil
|
||||
}
|
||||
if s.Version() == clparams.Phase0Version {
|
@ -3,17 +3,17 @@ package transition
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
)
|
||||
|
||||
func processSlashings(s *state.BeaconState, slashingMultiplier uint64) error {
|
||||
func processSlashings(s *state2.BeaconState, slashingMultiplier uint64) error {
|
||||
// Get the current epoch
|
||||
epoch := state.Epoch(s.BeaconState)
|
||||
epoch := state2.Epoch(s.BeaconState)
|
||||
// Get the total active balance
|
||||
totalBalance := s.GetTotalActiveBalance()
|
||||
// Calculate the total slashing amount
|
||||
// by summing all slashings and multiplying by the provided multiplier
|
||||
slashing := state.GetTotalSlashingAmount(s.BeaconState) * slashingMultiplier
|
||||
slashing := state2.GetTotalSlashingAmount(s.BeaconState) * slashingMultiplier
|
||||
// Adjust the total slashing amount to be no greater than the total active balance
|
||||
if totalBalance < slashing {
|
||||
slashing = totalBalance
|
||||
@ -32,7 +32,7 @@ func processSlashings(s *state.BeaconState, slashingMultiplier uint64) error {
|
||||
// Calculate the penalty by dividing the penalty numerator by the total balance and multiplying by the increment
|
||||
penalty := penaltyNumerator / totalBalance * increment
|
||||
// Decrease the validator's balance by the calculated penalty
|
||||
if err = state.DecreaseBalance(s.BeaconState, uint64(i), penalty); err != nil {
|
||||
if err = state2.DecreaseBalance(s.BeaconState, uint64(i), penalty); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@ -43,7 +43,7 @@ func processSlashings(s *state.BeaconState, slashingMultiplier uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProcessSlashings(state *state.BeaconState) error {
|
||||
func ProcessSlashings(state *state2.BeaconState) error {
|
||||
// Depending on the version of the state, use different multipliers
|
||||
switch state.Version() {
|
||||
case clparams.Phase0Version:
|
@ -2,23 +2,21 @@ package transition
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/state_encoding"
|
||||
"time"
|
||||
|
||||
"github.com/Giulio2002/bls"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/state_encoding"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
)
|
||||
|
||||
func TransitionState(s *state.BeaconState, block *cltypes.SignedBeaconBlock, fullValidation bool) error {
|
||||
func TransitionState(s *state2.BeaconState, block *cltypes.SignedBeaconBlock, fullValidation bool) error {
|
||||
currentBlock := block.Block
|
||||
if err := ProcessSlots(s, currentBlock.Slot); err != nil {
|
||||
return err
|
||||
@ -52,7 +50,7 @@ func TransitionState(s *state.BeaconState, block *cltypes.SignedBeaconBlock, ful
|
||||
}
|
||||
|
||||
// transitionSlot is called each time there is a new slot to process
|
||||
func transitionSlot(s *state.BeaconState) error {
|
||||
func transitionSlot(s *state2.BeaconState) error {
|
||||
slot := s.Slot()
|
||||
previousStateRoot := s.PreviousStateRoot()
|
||||
var err error
|
||||
@ -82,7 +80,7 @@ func transitionSlot(s *state.BeaconState) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProcessSlots(s *state.BeaconState, slot uint64) error {
|
||||
func ProcessSlots(s *state2.BeaconState, slot uint64) error {
|
||||
beaconConfig := s.BeaconConfig()
|
||||
sSlot := s.Slot()
|
||||
if slot <= sSlot {
|
||||
@ -100,7 +98,7 @@ func ProcessSlots(s *state.BeaconState, slot uint64) error {
|
||||
if err := ProcessEpoch(s); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debug("Processed new epoch successfully", "epoch", state.Epoch(s.BeaconState), "process_epoch_elpsed", time.Since(start))
|
||||
log.Debug("Processed new epoch successfully", "epoch", state2.Epoch(s.BeaconState), "process_epoch_elpsed", time.Since(start))
|
||||
}
|
||||
// TODO: add logic to process epoch updates.
|
||||
sSlot += 1
|
||||
@ -108,22 +106,22 @@ func ProcessSlots(s *state.BeaconState, slot uint64) error {
|
||||
if sSlot%beaconConfig.SlotsPerEpoch != 0 {
|
||||
continue
|
||||
}
|
||||
if state.Epoch(s.BeaconState) == beaconConfig.AltairForkEpoch {
|
||||
if state2.Epoch(s.BeaconState) == beaconConfig.AltairForkEpoch {
|
||||
if err := s.UpgradeToAltair(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if state.Epoch(s.BeaconState) == beaconConfig.BellatrixForkEpoch {
|
||||
if state2.Epoch(s.BeaconState) == beaconConfig.BellatrixForkEpoch {
|
||||
if err := s.UpgradeToBellatrix(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if state.Epoch(s.BeaconState) == beaconConfig.CapellaForkEpoch {
|
||||
if state2.Epoch(s.BeaconState) == beaconConfig.CapellaForkEpoch {
|
||||
if err := s.UpgradeToCapella(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if state.Epoch(s.BeaconState) == beaconConfig.DenebForkEpoch {
|
||||
if state2.Epoch(s.BeaconState) == beaconConfig.DenebForkEpoch {
|
||||
if err := s.UpgradeToDeneb(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -132,12 +130,12 @@ func ProcessSlots(s *state.BeaconState, slot uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func verifyBlockSignature(s *state.BeaconState, block *cltypes.SignedBeaconBlock) (bool, error) {
|
||||
func verifyBlockSignature(s *state2.BeaconState, block *cltypes.SignedBeaconBlock) (bool, error) {
|
||||
proposer, err := s.ValidatorForValidatorIndex(int(block.Block.ProposerIndex))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
domain, err := s.GetDomain(s.BeaconConfig().DomainBeaconProposer, state.Epoch(s.BeaconState))
|
||||
domain, err := s.GetDomain(s.BeaconConfig().DomainBeaconProposer, state2.Epoch(s.BeaconState))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -150,8 +148,8 @@ func verifyBlockSignature(s *state.BeaconState, block *cltypes.SignedBeaconBlock
|
||||
}
|
||||
|
||||
// ProcessHistoricalRootsUpdate updates the historical root data structure by computing a new historical root batch when it is time to do so.
|
||||
func ProcessHistoricalRootsUpdate(s *state.BeaconState) error {
|
||||
nextEpoch := state.Epoch(s.BeaconState) + 1
|
||||
func ProcessHistoricalRootsUpdate(s *state2.BeaconState) error {
|
||||
nextEpoch := state2.Epoch(s.BeaconState) + 1
|
||||
beaconConfig := s.BeaconConfig()
|
||||
blockRoots := s.BlockRoots()
|
||||
stateRoots := s.StateRoots()
|
@ -2,6 +2,7 @@ package transition
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"testing"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
@ -9,7 +10,6 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -26,22 +26,22 @@ var (
|
||||
blockHash44 = "3ff92b54cba8067044f6b6ca0a69c7a6344154de2a38742e7a89b1057877fffa"
|
||||
)
|
||||
|
||||
func getTestBeaconState() *state.BeaconState {
|
||||
return state.GetEmptyBeaconState()
|
||||
func getTestBeaconState() *state2.BeaconState {
|
||||
return state2.GetEmptyBeaconState()
|
||||
}
|
||||
|
||||
func getEmptyInvalidBeaconState() *state.BeaconState {
|
||||
b := state.GetEmptyBeaconState()
|
||||
func getEmptyInvalidBeaconState() *state2.BeaconState {
|
||||
b := state2.GetEmptyBeaconState()
|
||||
b.SetCurrentSyncCommittee(&cltypes.SyncCommittee{})
|
||||
return b // Invalid public key length
|
||||
}
|
||||
|
||||
func assertStateEq(t *testing.T, got *state.BeaconState, expected *state.BeaconState) {
|
||||
func assertStateEq(t *testing.T, got *state2.BeaconState, expected *state2.BeaconState) {
|
||||
assert.Equal(t, got.LatestExecutionPayloadHeader(), expected.LatestExecutionPayloadHeader())
|
||||
|
||||
}
|
||||
|
||||
func prepareNextBeaconState(t *testing.T, slots []uint64, stateHashs, blockHashs []string, nextState *state.BeaconState) *state.BeaconState {
|
||||
func prepareNextBeaconState(t *testing.T, slots []uint64, stateHashs, blockHashs []string, nextState *state2.BeaconState) *state2.BeaconState {
|
||||
// Set slot to initial index.
|
||||
for i, val := range slots {
|
||||
nextState.SetSlot(val)
|
||||
@ -71,8 +71,8 @@ func TestTransitionSlot(t *testing.T) {
|
||||
slot42.SetSlot(42)
|
||||
testCases := []struct {
|
||||
description string
|
||||
prevState *state.BeaconState
|
||||
expectedState *state.BeaconState
|
||||
prevState *state2.BeaconState
|
||||
expectedState *state2.BeaconState
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
@ -137,8 +137,8 @@ func TestProcessSlots(t *testing.T) {
|
||||
slot42.SetSlot(42)
|
||||
testCases := []struct {
|
||||
description string
|
||||
prevState *state.BeaconState
|
||||
expectedState *state.BeaconState
|
||||
prevState *state2.BeaconState
|
||||
expectedState *state2.BeaconState
|
||||
numSlots uint64
|
||||
startSlot uint64
|
||||
wantErr bool
|
@ -2,18 +2,18 @@ package transition
|
||||
|
||||
import (
|
||||
"errors"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
|
||||
"github.com/Giulio2002/bls"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
)
|
||||
|
||||
// processSyncAggregate applies all the logic in the spec function `process_sync_aggregate` except
|
||||
// verifying the BLS signatures. It returns the modified beacons state and the list of validators'
|
||||
// public keys that voted, for future signature verification.
|
||||
func processSyncAggregate(s *state.BeaconState, sync *cltypes.SyncAggregate) ([][]byte, error) {
|
||||
func processSyncAggregate(s *state2.BeaconState, sync *cltypes.SyncAggregate) ([][]byte, error) {
|
||||
currentSyncCommittee := s.CurrentSyncCommittee()
|
||||
|
||||
if currentSyncCommittee == nil {
|
||||
@ -47,12 +47,12 @@ func processSyncAggregate(s *state.BeaconState, sync *cltypes.SyncAggregate) ([]
|
||||
}
|
||||
if syncAggregateBits[i]&byte(bit) > 0 {
|
||||
votedKeys = append(votedKeys, currentSyncCommittee.PubKeys[currPubKeyIndex][:])
|
||||
if err := state.IncreaseBalance(s.BeaconState, vIdx, participantReward); err != nil {
|
||||
if err := state2.IncreaseBalance(s.BeaconState, vIdx, participantReward); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
earnedProposerReward += proposerReward
|
||||
} else {
|
||||
if err := state.DecreaseBalance(s.BeaconState, vIdx, participantReward); err != nil {
|
||||
if err := state2.DecreaseBalance(s.BeaconState, vIdx, participantReward); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@ -60,10 +60,10 @@ func processSyncAggregate(s *state.BeaconState, sync *cltypes.SyncAggregate) ([]
|
||||
}
|
||||
}
|
||||
|
||||
return votedKeys, state.IncreaseBalance(s.BeaconState, proposerIndex, earnedProposerReward)
|
||||
return votedKeys, state2.IncreaseBalance(s.BeaconState, proposerIndex, earnedProposerReward)
|
||||
}
|
||||
|
||||
func ProcessSyncAggregate(s *state.BeaconState, sync *cltypes.SyncAggregate, fullValidation bool) error {
|
||||
func ProcessSyncAggregate(s *state2.BeaconState, sync *cltypes.SyncAggregate, fullValidation bool) error {
|
||||
votedKeys, err := processSyncAggregate(s, sync)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -71,7 +71,7 @@ func ProcessSyncAggregate(s *state.BeaconState, sync *cltypes.SyncAggregate, ful
|
||||
if fullValidation {
|
||||
previousSlot := s.PreviousSlot()
|
||||
|
||||
domain, err := fork.Domain(s.Fork(), state.GetEpochAtSlot(s.BeaconConfig(), previousSlot), s.BeaconConfig().DomainSyncCommittee, s.GenesisValidatorsRoot())
|
||||
domain, err := fork.Domain(s.Fork(), state2.GetEpochAtSlot(s.BeaconConfig(), previousSlot), s.BeaconConfig().DomainSyncCommittee, s.GenesisValidatorsRoot())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package transition
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
)
|
||||
|
||||
// ProcessSyncCommitteeUpdate implements processing for the sync committee update. unfortunately there is no easy way to test it.
|
||||
func ProcessSyncCommitteeUpdate(s *state.BeaconState) error {
|
||||
if (state.Epoch(s.BeaconState)+1)%s.BeaconConfig().EpochsPerSyncCommitteePeriod != 0 {
|
||||
func ProcessSyncCommitteeUpdate(s *state2.BeaconState) error {
|
||||
if (state2.Epoch(s.BeaconState)+1)%s.BeaconConfig().EpochsPerSyncCommitteePeriod != 0 {
|
||||
return nil
|
||||
}
|
||||
// Set new current sync committee.
|
@ -2,12 +2,12 @@ package transition_test
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/transition"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/transition"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
@ -3,13 +3,13 @@ package transition
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
|
||||
"github.com/Giulio2002/bls"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
)
|
||||
|
||||
func computeSigningRootEpoch(epoch uint64, domain []byte) (libcommon.Hash, error) {
|
||||
@ -18,7 +18,7 @@ func computeSigningRootEpoch(epoch uint64, domain []byte) (libcommon.Hash, error
|
||||
return utils.Keccak256(b, domain), nil
|
||||
}
|
||||
|
||||
func ProcessBlockHeader(state *state.BeaconState, block *cltypes.BeaconBlock, fullValidation bool) error {
|
||||
func ProcessBlockHeader(state *state2.BeaconState, block *cltypes.BeaconBlock, fullValidation bool) error {
|
||||
if fullValidation {
|
||||
if block.Slot != state.Slot() {
|
||||
return fmt.Errorf("state slot: %d, not equal to block slot: %d", state.Slot(), block.Slot)
|
||||
@ -64,8 +64,8 @@ func ProcessBlockHeader(state *state.BeaconState, block *cltypes.BeaconBlock, fu
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProcessRandao(s *state.BeaconState, randao [96]byte, proposerIndex uint64, fullValidation bool) error {
|
||||
epoch := state.Epoch(s.BeaconState)
|
||||
func ProcessRandao(s *state2.BeaconState, randao [96]byte, proposerIndex uint64, fullValidation bool) error {
|
||||
epoch := state2.Epoch(s.BeaconState)
|
||||
proposer, err := s.ValidatorForValidatorIndex(int(proposerIndex))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -99,7 +99,7 @@ func ProcessRandao(s *state.BeaconState, randao [96]byte, proposerIndex uint64,
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProcessEth1Data(state *state.BeaconState, eth1Data *cltypes.Eth1Data) error {
|
||||
func ProcessEth1Data(state *state2.BeaconState, eth1Data *cltypes.Eth1Data) error {
|
||||
state.AddEth1DataVote(eth1Data)
|
||||
newVotes := state.Eth1DataVotes()
|
||||
|
@ -2,13 +2,13 @@ package transition
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"testing"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@ -20,7 +20,7 @@ var (
|
||||
emptyBlock = &cltypes.Eth1Block{}
|
||||
)
|
||||
|
||||
func getTestState(t *testing.T) *state.BeaconState {
|
||||
func getTestState(t *testing.T) *state2.BeaconState {
|
||||
numVals := 2048
|
||||
validators := make([]*cltypes.Validator, numVals)
|
||||
for i := 0; i < numVals; i++ {
|
||||
@ -29,7 +29,7 @@ func getTestState(t *testing.T) *state.BeaconState {
|
||||
v.SetExitEpoch(10000)
|
||||
validators[i] = v
|
||||
}
|
||||
b := state.GetEmptyBeaconState()
|
||||
b := state2.GetEmptyBeaconState()
|
||||
b.SetValidators(validators)
|
||||
b.SetSlot(19)
|
||||
b.SetLatestBlockHeader(&cltypes.BeaconBlockHeader{Slot: 18})
|
||||
@ -90,7 +90,7 @@ func TestProcessBlockHeader(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
state *state.BeaconState
|
||||
state *state2.BeaconState
|
||||
block *cltypes.BeaconBlock
|
||||
wantErr bool
|
||||
}{
|
||||
@ -179,7 +179,7 @@ func TestProcessRandao(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
state *state.BeaconState
|
||||
state *state2.BeaconState
|
||||
body *cltypes.BeaconBody
|
||||
wantErr bool
|
||||
}{
|
||||
@ -232,7 +232,7 @@ func TestProcessEth1Data(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unable to hash expected eth1data: %v", err)
|
||||
}
|
||||
successState := state.GetEmptyBeaconState()
|
||||
successState := state2.GetEmptyBeaconState()
|
||||
successState.SetEth1Data(Eth1DataB)
|
||||
|
||||
// Fill all votes.
|
||||
@ -243,12 +243,12 @@ func TestProcessEth1Data(t *testing.T) {
|
||||
Eth1Data: Eth1DataA,
|
||||
}
|
||||
|
||||
noUpdateState := state.GetEmptyBeaconState()
|
||||
noUpdateState := state2.GetEmptyBeaconState()
|
||||
noUpdateState.SetEth1Data(Eth1DataB)
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
state *state.BeaconState
|
||||
state *state2.BeaconState
|
||||
body *cltypes.BeaconBody
|
||||
expectedHash [32]byte
|
||||
}{
|
27
cl/phase1/core/transition/resets.go
Normal file
27
cl/phase1/core/transition/resets.go
Normal file
@ -0,0 +1,27 @@
|
||||
package transition
|
||||
|
||||
import (
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
)
|
||||
|
||||
func ProcessEth1DataReset(s *state2.BeaconState) {
|
||||
nextEpoch := state2.Epoch(s.BeaconState) + 1
|
||||
if nextEpoch%s.BeaconConfig().EpochsPerEth1VotingPeriod == 0 {
|
||||
s.ResetEth1DataVotes()
|
||||
}
|
||||
}
|
||||
|
||||
func ProcessSlashingsReset(s *state2.BeaconState) {
|
||||
s.SetSlashingSegmentAt(int(state2.Epoch(s.BeaconState)+1)%int(s.BeaconConfig().EpochsPerSlashingsVector), 0)
|
||||
|
||||
}
|
||||
|
||||
func ProcessRandaoMixesReset(s *state2.BeaconState) {
|
||||
currentEpoch := state2.Epoch(s.BeaconState)
|
||||
nextEpoch := state2.Epoch(s.BeaconState) + 1
|
||||
s.SetRandaoMixAt(int(nextEpoch%s.BeaconConfig().EpochsPerHistoricalVector), s.GetRandaoMixes(currentEpoch))
|
||||
}
|
||||
|
||||
func ProcessParticipationFlagUpdates(state *state2.BeaconState) {
|
||||
state.ResetEpochParticipation()
|
||||
}
|
@ -2,6 +2,7 @@ package forkchoice
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/shuffling"
|
||||
|
||||
"github.com/Giulio2002/bls"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
@ -10,7 +11,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state/shuffling"
|
||||
)
|
||||
|
||||
const randaoMixesLength = 65536
|
@ -2,6 +2,8 @@ package forkchoice_test
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice"
|
||||
"testing"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
@ -9,8 +11,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/forkchoice"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/transition"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/transition"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
@ -2,13 +2,13 @@ package fork_graph_test
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice/fork_graph"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/forkchoice/fork_graph"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -1,14 +1,14 @@
|
||||
package forkchoice
|
||||
|
||||
import (
|
||||
state2 "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/execution_client"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice/fork_graph"
|
||||
"sync"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru/v2"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/execution_client"
|
||||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/forkchoice/fork_graph"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -43,13 +43,13 @@ type LatestMessage struct {
|
||||
}
|
||||
|
||||
// NewForkChoiceStore initialize a new store from the given anchor state, either genesis or checkpoint sync state.
|
||||
func NewForkChoiceStore(anchorState *state.BeaconState, engine execution_client.ExecutionEngine, enabledPruning bool) (*ForkChoiceStore, error) {
|
||||
func NewForkChoiceStore(anchorState *state2.BeaconState, engine execution_client.ExecutionEngine, enabledPruning bool) (*ForkChoiceStore, error) {
|
||||
anchorRoot, err := anchorState.BlockRoot()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
anchorCheckpoint := &cltypes.Checkpoint{
|
||||
Epoch: state.Epoch(anchorState.BeaconState),
|
||||
Epoch: state2.Epoch(anchorState.BeaconState),
|
||||
Root: anchorRoot,
|
||||
}
|
||||
checkpointStates, err := lru.New[cltypes.Checkpoint, *checkpointState](allowedCachedStates)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user