Skip to content

Commit

Permalink
Merge branch 'main' of github.com:berachain/beacon-kit into bs-recover
Browse files Browse the repository at this point in the history
  • Loading branch information
calbera committed Aug 20, 2024
2 parents 15c3f9b + 410b352 commit 03272da
Show file tree
Hide file tree
Showing 156 changed files with 2,685 additions and 2,411 deletions.
9 changes: 4 additions & 5 deletions beacond/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ replace (
cosmossdk.io/api => cosmossdk.io/api v0.7.3-0.20240806152830-8fb47b368cd4
cosmossdk.io/core => cosmossdk.io/core v0.12.1-0.20240806152830-8fb47b368cd4
cosmossdk.io/core/testing => cosmossdk.io/core/testing v0.0.0-20240806152830-8fb47b368cd4
cosmossdk.io/x/auth => cosmossdk.io/x/auth v0.0.0-20240806152830-8fb47b368cd4
cosmossdk.io/x/consensus => cosmossdk.io/x/consensus v0.0.0-20240806152830-8fb47b368cd4

github.com/cometbft/cometbft => github.com/cometbft/cometbft v1.0.0-rc1.0.20240805134408-314422469051
github.com/cosmos/cosmos-sdk => github.com/berachain/cosmos-sdk v0.46.0-beta2.0.20240808182639-7bdbf06a94f2
github.com/ferranbt/fastssz => github.com/itsdevbear/fastssz v0.0.0-20240731164358-a354a31813e6
Expand Down Expand Up @@ -37,7 +36,7 @@ require (
cosmossdk.io/core v0.12.1-0.20240806152830-8fb47b368cd4 // indirect
cosmossdk.io/depinject v1.0.0 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.4.0 // indirect
cosmossdk.io/log v1.4.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/schema v0.1.1 // indirect
cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect
Expand Down Expand Up @@ -101,7 +100,7 @@ require (
github.com/cosmos/crypto v0.1.2 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.5.0 // indirect
github.com/cosmos/gogoproto v1.7.0 // indirect
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
Expand Down Expand Up @@ -247,7 +246,7 @@ require (
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions beacond/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050=
cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8=
cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/log v1.4.0 h1:Ttt9d6fQ0GlktwhcysOeNiIjixW7l0rYBocmoXOb11k=
cosmossdk.io/log v1.4.0/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/schema v0.1.1 h1:I0M6pgI7R10nq+/HCQfbO6BsGBZA8sQy+duR1Y3aKcA=
Expand Down Expand Up @@ -208,8 +208,8 @@ github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4x
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ4GUkT+tbFI=
github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU=
github.com/cosmos/gogoproto v1.5.0 h1:SDVwzEqZDDBoslaeZg+dGE55hdzHfgUA40pEanMh52o=
github.com/cosmos/gogoproto v1.5.0/go.mod h1:iUM31aofn3ymidYG6bUR5ZFrk+Om8p5s754eMUcyp8I=
github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro=
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179 h1:wmwDn7V3RodN9auB3FooSQxs46nHVE3u0mb87TJkZFE=
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179/go.mod h1:GiM43q0pB+uG53mLxLDzimxM9l/5N9UuSY3/D0huuVw=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
Expand Down Expand Up @@ -821,8 +821,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
Expand Down
4 changes: 0 additions & 4 deletions build/scripts/testing.mk
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,6 @@ test-unit-fuzz: ## run fuzz tests
go test ./mod/payload/pkg/cache/... -fuzz=FuzzPayloadIDCacheConcurrency -fuzztime=${SHORT_FUZZ_TIME}
go test -fuzz=FuzzHashTreeRoot ./mod/primitives/pkg/merkle -fuzztime=${MEDIUM_FUZZ_TIME}





test-e2e: ## run e2e tests
@$(MAKE) build-docker VERSION=kurtosis-local test-e2e-no-build

Expand Down
2 changes: 1 addition & 1 deletion build/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ require (
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions build/tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,8 @@ golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
6 changes: 3 additions & 3 deletions examples/berad/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
cosmossdk.io/api v0.7.5 // indirect
cosmossdk.io/depinject v1.0.0 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.4.0 // indirect
cosmossdk.io/log v1.4.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect
cosmossdk.io/x/tx v0.13.4-0.20240623110059-dec2d5583e39 // indirect
Expand All @@ -36,7 +36,7 @@ require (
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-db v1.0.2 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/gogoproto v1.5.0 // indirect
github.com/cosmos/gogoproto v1.7.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/dgraph-io/badger/v4 v4.2.0 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
Expand Down Expand Up @@ -147,7 +147,7 @@ require (
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions examples/berad/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050=
cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8=
cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/log v1.4.0 h1:Ttt9d6fQ0GlktwhcysOeNiIjixW7l0rYBocmoXOb11k=
cosmossdk.io/log v1.4.0/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/schema v0.1.1 h1:I0M6pgI7R10nq+/HCQfbO6BsGBZA8sQy+duR1Y3aKcA=
Expand Down Expand Up @@ -130,8 +130,8 @@ github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ4GUkT+tbFI=
github.com/cosmos/gogoproto v1.5.0 h1:SDVwzEqZDDBoslaeZg+dGE55hdzHfgUA40pEanMh52o=
github.com/cosmos/gogoproto v1.5.0/go.mod h1:iUM31aofn3ymidYG6bUR5ZFrk+Om8p5s754eMUcyp8I=
github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro=
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179 h1:wmwDn7V3RodN9auB3FooSQxs46nHVE3u0mb87TJkZFE=
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179/go.mod h1:GiM43q0pB+uG53mLxLDzimxM9l/5N9UuSY3/D0huuVw=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
Expand Down Expand Up @@ -595,8 +595,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
Expand Down
35 changes: 1 addition & 34 deletions examples/berad/pkg/consensus-types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ type BeaconState[
// Withdrawals
NextWithdrawalIndex uint64
NextWithdrawalValidatorIndex math.ValidatorIndex

// Slashing
Slashings []uint64
TotalSlashing math.Gwei
}

/* -------------------------------------------------------------------------- */
Expand All @@ -78,7 +74,7 @@ type BeaconState[
func (st *BeaconState[
_, _, _, _, _, _, _, _, _,
]) SizeSSZ(fixed bool) uint32 {
var size uint32 = 300
var size uint32 = 276

if fixed {
return size
Expand All @@ -91,7 +87,6 @@ func (st *BeaconState[
size += ssz.SizeSliceOfStaticObjects(st.Validators)
size += ssz.SizeSliceOfUint64s(st.Balances)
size += ssz.SizeSliceOfStaticBytes(st.RandaoMixes)
size += ssz.SizeSliceOfUint64s(st.Slashings)

return size
}
Expand Down Expand Up @@ -123,18 +118,13 @@ func (st *BeaconState[
ssz.DefineUint64(codec, &st.NextWithdrawalIndex)
ssz.DefineUint64(codec, &st.NextWithdrawalValidatorIndex)

// // Slashing
ssz.DefineSliceOfUint64sOffset(codec, &st.Slashings, 1099511627776)
ssz.DefineUint64(codec, (*uint64)(&st.TotalSlashing))

// Dynamic content
ssz.DefineSliceOfStaticBytesContent(codec, &st.BlockRoots, 8192)
ssz.DefineSliceOfStaticBytesContent(codec, &st.StateRoots, 8192)
ssz.DefineDynamicObjectContent(codec, &st.LatestExecutionPayloadHeader)
ssz.DefineSliceOfStaticObjectsContent(codec, &st.Validators, 1099511627776)
ssz.DefineSliceOfUint64sContent(codec, &st.Balances, 1099511627776)
ssz.DefineSliceOfStaticBytesContent(codec, &st.RandaoMixes, 65536)
ssz.DefineSliceOfUint64sContent(codec, &st.Slashings, 1099511627776)
}

// MarshalSSZ marshals the BeaconState into SSZ format.
Expand Down Expand Up @@ -291,29 +281,6 @@ func (st *BeaconState[
// Field (12) 'NextWithdrawalValidatorIndex'
hh.PutUint64(uint64(st.NextWithdrawalValidatorIndex))

// Field (14) 'Slashings'
if size := len(st.Slashings); size > 1099511627776 {
return fastssz.ErrListTooBigFn(
"BeaconState.Slashings",
size,
1099511627776,
)
}
subIndx = hh.Index()
for _, i := range st.Slashings {
hh.AppendUint64(i)
}
hh.FillUpTo32()
numItems = uint64(len(st.Slashings))
hh.MerkleizeWithMixin(
subIndx,
numItems,
fastssz.CalculateLimit(1099511627776, numItems, 8),
)

// Field (15) 'TotalSlashing'
hh.PutUint64(uint64(st.TotalSlashing))

hh.Merkleize(indx)
return nil
}
Expand Down
4 changes: 0 additions & 4 deletions examples/berad/pkg/state-transition/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ type ReadOnlyBeaconState[
GetNextWithdrawalIndex() (uint64, error)
GetNextWithdrawalValidatorIndex() (math.ValidatorIndex, error)
GetSlot() (math.Slot, error)
GetSlashingAtIndex(uint64) (math.Gwei, error)
GetTotalActiveBalances(uint64) (math.Gwei, error)
GetTotalSlashing() (math.Gwei, error)
GetTotalValidators() (uint64, error)
GetValidators() (ValidatorsT, error)
GetValidatorsByEffectiveBalance() ([]ValidatorT, error)
Expand Down Expand Up @@ -116,9 +114,7 @@ type WriteOnlyBeaconState[
SetNextWithdrawalIndex(uint64) error
SetNextWithdrawalValidatorIndex(math.ValidatorIndex) error
SetSlot(math.Slot) error
SetTotalSlashing(math.Gwei) error
UpdateBlockRootAtIndex(uint64, common.Root) error
UpdateSlashingAtIndex(uint64, math.Gwei) error
}

// WriteOnlyStateRoots defines a struct which only has write access to state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// processSyncCommitteeUpdates processes the sync committee updates.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, ValidatorT, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _,
]) processSyncCommitteeUpdates(
st BeaconStateT,
) (transition.ValidatorUpdates, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
//nolint:gocognit // its ok
func (sp *StateProcessor[
_, BeaconBlockBodyT, BeaconBlockHeaderT, BeaconStateT, _, DepositT,
_, ExecutionPayloadHeaderT, ForkT, _, _, ValidatorT, _, _, _, _,
_, ExecutionPayloadHeaderT, ForkT, _, _, _, _, _, _, _,
]) InitializePreminedBeaconStateFromEth1(
st BeaconStateT,
deposits []DepositT,
Expand Down Expand Up @@ -125,10 +125,6 @@ func (sp *StateProcessor[
return nil, err
}

if err = st.SetTotalSlashing(0); err != nil {
return nil, err
}

var updates transition.ValidatorUpdates
updates, err = sp.processSyncCommitteeUpdates(st)
if err != nil {
Expand Down
84 changes: 11 additions & 73 deletions examples/berad/pkg/state-transition/state_processor_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,17 @@

package transition

import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

// processSlashingsReset as defined in the Ethereum 2.0 specification.
// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#slashings-balances-updates
//
//nolint:lll
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _,
]) processSlashingsReset(
st BeaconStateT,
_ BeaconStateT,
) error {
// Get the current epoch.
slot, err := st.GetSlot()
if err != nil {
return err
}

index := (sp.cs.SlotToEpoch(slot.Unwrap()) + 1) % sp.cs.EpochsPerSlashingsVector()
return st.UpdateSlashingAtIndex(index, 0)
// TODO: implement this
return nil
}

// processProposerSlashing as defined in the Ethereum 2.0 specification.
Expand Down Expand Up @@ -79,50 +69,9 @@ func (sp *StateProcessor[
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _,
]) processSlashings(
st BeaconStateT,
_ BeaconStateT,
) error {
totalBalance, err := st.GetTotalActiveBalances(sp.cs.SlotsPerEpoch())
if err != nil {
return err
}

totalSlashings, err := st.GetTotalSlashing()
if err != nil {
return err
}

adjustedTotalSlashingBalance := min(
totalSlashings.Unwrap()*sp.cs.ProportionalSlashingMultiplier(),
totalBalance.Unwrap(),
)

vals, err := st.GetValidators()
if err != nil {
return err
}

// Get the current slot.
slot, err := st.GetSlot()
if err != nil {
return err
}

//nolint:mnd // this is in the spec
slashableEpoch := (sp.cs.SlotToEpoch(slot.Unwrap()) + sp.cs.EpochsPerSlashingsVector()) / 2

// Iterate through the validators and slash if needed.
for _, val := range vals {
if val.IsSlashed() &&
(slashableEpoch == val.GetWithdrawableEpoch().Unwrap()) {
if err = sp.processSlash(
st, val,
adjustedTotalSlashingBalance,
totalBalance.Unwrap(),
); err != nil {
return err
}
}
}
// TODO: implement this
return nil
}

Expand All @@ -132,22 +81,11 @@ func (sp *StateProcessor[
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, ValidatorT, _, _, _, _,
]) processSlash(
st BeaconStateT,
val ValidatorT,
adjustedTotalSlashingBalance uint64,
totalBalance uint64,
_ BeaconStateT,
_ ValidatorT,
_ uint64,
_ uint64,
) error {
// Calculate the penalty.
increment := sp.cs.EffectiveBalanceIncrement()
balDivIncrement := val.GetEffectiveBalance().Unwrap() / increment
penaltyNumerator := balDivIncrement * adjustedTotalSlashingBalance
penalty := penaltyNumerator / totalBalance * increment

// Get the val index and decrease the balance of the validator.
idx, err := st.ValidatorIndexByPubkey(val.GetPubkey())
if err != nil {
return err
}

return st.DecreaseBalance(idx, math.Gwei(penalty))
// TODO: implement this
return nil
}
Loading

0 comments on commit 03272da

Please sign in to comment.