Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(withdrawals): Fixed withdrawal for EVM inflation per block #2158

Merged
merged 60 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
d9f823a
feat: evm inflation
calbera Nov 15, 2024
c0a78e4
nits
calbera Nov 15, 2024
0ad6329
more
calbera Nov 15, 2024
fb1177c
delete unneeded
calbera Nov 15, 2024
6c91765
gosec
calbera Nov 15, 2024
270b6ae
fix existing unit test
calbera Nov 15, 2024
ddb711e
bet
calbera Nov 15, 2024
d898aef
refactor sp tests package
calbera Nov 18, 2024
afea1e7
fix & rename file
calbera Nov 18, 2024
3c11427
transition withdrawals test
calbera Nov 18, 2024
ff487e9
bet
calbera Nov 18, 2024
220f499
edge case
calbera Nov 18, 2024
a2849f2
bet
calbera Nov 18, 2024
27f74ce
inflation per block as gwei
calbera Nov 18, 2024
a1cf677
e2e test
calbera Nov 18, 2024
fdb5163
bet
calbera Nov 18, 2024
6a3f282
bet
calbera Nov 18, 2024
6fd0c0a
remove unneeded checks
calbera Nov 19, 2024
c68fcab
nit
calbera Nov 19, 2024
5517eb9
reduce diff
calbera Nov 19, 2024
4f221e9
bet
calbera Nov 19, 2024
c498b53
Testnet variable
calbera Nov 19, 2024
45502d5
Merge branch 'main' of github.com:berachain/beacon-kit into evm-infla…
calbera Nov 19, 2024
b60f6cd
gen
calbera Nov 19, 2024
2e96a53
details of berachain values
calbera Nov 19, 2024
13631c4
nit
calbera Nov 19, 2024
9c77388
Merge branch 'main' of github.com:berachain/beacon-kit into evm-infla…
calbera Nov 20, 2024
a0f8650
Merge branch 'main' into evm-inflation
calbera Nov 25, 2024
b64cf6a
do not modify next withdrawal validator index if len == 0
calbera Nov 26, 2024
b018f78
nit
calbera Nov 26, 2024
380ac3d
explicitly ensure withdrawal 0 has no state update
calbera Nov 26, 2024
4ade066
use constants for inflation withdrawal
calbera Nov 26, 2024
c3fd4d3
enforce first is inflation wd
calbera Nov 26, 2024
d27d72e
bet
calbera Nov 26, 2024
115a48d
bet
calbera Nov 26, 2024
ed6c7ca
bit
calbera Nov 26, 2024
a84d097
special cases
calbera Nov 26, 2024
d7c6589
gen
calbera Nov 26, 2024
6382ef2
Update mod/state-transition/pkg/core/state_processor_staking.go
calbera Nov 26, 2024
56412ab
todo fix unit tests
calbera Nov 26, 2024
f9960d4
fix unit
calbera Nov 26, 2024
e3fd55e
gen
calbera Nov 26, 2024
22c86ab
gen
calbera Nov 26, 2024
d961091
Merge branch 'main' into evm-inflation
calbera Nov 27, 2024
5bac0a1
special casing
calbera Nov 27, 2024
3a85aa3
gen
calbera Nov 27, 2024
cbfc218
nit
calbera Nov 27, 2024
7f3e9fc
temp
calbera Nov 27, 2024
7cb3fb5
bet
calbera Nov 27, 2024
bb9ab6e
fix
calbera Nov 27, 2024
f00cb29
fix test
calbera Nov 27, 2024
97faad5
lint
calbera Nov 27, 2024
12996e5
remove unused
calbera Nov 27, 2024
484c575
Merge branch 'main' into evm-inflation
abi87 Nov 27, 2024
444a2fa
fork cleanup for withdrawals (#2187)
abi87 Nov 28, 2024
3136c14
devnet spec for e2e tests
calbera Nov 28, 2024
9099f2e
Merge branch 'evm-inflation' of github.com:berachain/beacon-kit into …
calbera Nov 28, 2024
2662284
cleanup testing
calbera Nov 28, 2024
24b9f21
naming cleaned
calbera Nov 28, 2024
afdf51d
tidy sync
calbera Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion mod/chain-spec/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ module github.com/berachain/beacon-kit/mod/chain-spec
go 1.23.0
calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved

require (
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240610210054-bfdc14c4013c
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240911165923-82f71ec86570
github.com/stretchr/testify v1.9.0
)

require (
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
calbera marked this conversation as resolved.
Show resolved Hide resolved
gopkg.in/yaml.v3 v3.0.1 // indirect
)
59 changes: 56 additions & 3 deletions mod/chain-spec/go.sum
Original file line number Diff line number Diff line change
@@ -1,20 +1,73 @@
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240610210054-bfdc14c4013c h1:rPoD2zVkIzuMC4R/XMuwx6eanJL8ccu37sLro+eIj3Y=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240610210054-bfdc14c4013c/go.mod h1:xgngH5/PYbyW+YDEmRhbBy3V333GXsNWF4DAkjYCmfs=
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240911165923-82f71ec86570 h1:w0Gkg31VQRFDv0EJjYgVtlpza7kSaJq7U28zxZjfZeE=
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240911165923-82f71ec86570/go.mod h1:Mrq1qol8vbkgZp2IMPFwngg75qE3k9IvT2MouBEhuus=
github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I=
github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/getsentry/sentry-go v0.28.1 h1:zzaSm/vHmGllRM6Tpx1492r0YDzauArdBfkJRtY6P5k=
github.com/getsentry/sentry-go v0.28.1/go.mod h1:1fQZ+7l7eeJ3wYi82q5Hg8GqAPgefRq+FP/QhafYVgg=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
46 changes: 43 additions & 3 deletions mod/chain-spec/pkg/chain/chain_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ type Spec[
// GetCometBFTConfigForSlot retrieves the CometBFT config for a specific
// slot.
GetCometBFTConfigForSlot(slot SlotT) CometBFTConfigT

// Berachain Values

// EVMInflationAddress returns the address on the EVM which will receive
// the inflation amount of native EVM balance through a withdrawal every
// block.
EVMInflationAddress() ExecutionAddressT

// EVMInflationPerBlock returns the amount of native EVM balance (in Gwei)
// to be minted to the EVMInflationAddress via a withdrawal every block.
EVMInflationPerBlock() uint64
calbera marked this conversation as resolved.
Show resolved Hide resolved
}

// chainSpec is a concrete implementation of the ChainSpec interface, holding
Expand All @@ -207,14 +218,27 @@ func NewChainSpec[
CometBFTConfigT any,
](data SpecData[
DomainTypeT, EpochT, ExecutionAddressT, SlotT, CometBFTConfigT,
]) Spec[
]) (Spec[
DomainTypeT, EpochT, ExecutionAddressT, SlotT, CometBFTConfigT,
] {
return &chainSpec[
], error) {
c := &chainSpec[
DomainTypeT, EpochT, ExecutionAddressT, SlotT, CometBFTConfigT,
]{
Data: data,
}
return c, c.validate()
}
calbera marked this conversation as resolved.
Show resolved Hide resolved

// validate ensures that the chain spec is valid, returning error if it is not.
func (c *chainSpec[
DomainTypeT, EpochT, ExecutionAddressT, SlotT, CometBFTConfigT,
]) validate() error {
if c.MaxWithdrawalsPerPayload() <= 1 {
return ErrZeroMaxWithdrawalsPerPayload
}
calbera marked this conversation as resolved.
Show resolved Hide resolved

// TODO: Add more validation rules here.
calbera marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good we have the scaffolding to do this rn.
Note: these checks may be fork dependent too

return nil
calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved
}

// MinDepositAmount returns the minimum deposit amount required.
Expand Down Expand Up @@ -476,3 +500,19 @@ func (c chainSpec[
]) GetCometBFTConfigForSlot(_ SlotT) CometBFTConfigT {
return c.Data.CometValues
}

// EVMInflationAddress returns the address on the EVM which will receive the
// inflation amount of native EVM balance through a withdrawal every block.
func (c chainSpec[
DomainTypeT, EpochT, ExecutionAddressT, SlotT, CometBFTConfigT,
]) EVMInflationAddress() ExecutionAddressT {
return c.Data.EVMInflationAddress
}

// EVMInflationPerBlock returns the amount of native EVM balance (in Gwei) to
// be minted to the EVMInflationAddress via a withdrawal every block.
func (c chainSpec[
DomainTypeT, EpochT, ExecutionAddressT, SlotT, CometBFTConfigT,
]) EVMInflationPerBlock() uint64 {
return c.Data.EVMInflationPerBlock
}
calbera marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 10 additions & 1 deletion mod/chain-spec/pkg/chain/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ type SpecData[
// KZGCommitmentInclusionProofDepth is the depth of the KZG inclusion proof.
KZGCommitmentInclusionProofDepth uint64 `mapstructure:"kzg-commitment-inclusion-proof-depth"`

// CometValues
// Comet Values
CometValues CometBFTConfigT `mapstructure:"comet-bft-config"`

// Berachain Values
//
// EVMInflationAddress is the address on the EVM which will receive the
// inflation amount of native EVM balance through a withdrawal every block.
EVMInflationAddress ExecutionAddressT `mapstructure:"evm-inflation-address"`
calbera marked this conversation as resolved.
Show resolved Hide resolved
// EVMInflationPerBlock is the amount of native EVM balance (in Gwei) to be
// minted to the EVMInflationAddress via a withdrawal every block.
EVMInflationPerBlock uint64 `mapstructure:"evm-inflation-per-block"`
calbera marked this conversation as resolved.
Show resolved Hide resolved
}
31 changes: 31 additions & 0 deletions mod/chain-spec/pkg/chain/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package chain

import "github.com/berachain/beacon-kit/mod/errors"

var (
// ErrZeroMaxWithdrawalsPerPayload is returned when the max withdrawals
// per payload is zero. Must allow at least one for the EVM inflation
// withdrawal, and at least one more for a validator withdrawal per block.
ErrZeroMaxWithdrawalsPerPayload = errors.New(
"max withdrawals per payload must be greater than 1")
calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved
)
calbera marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 4 additions & 1 deletion mod/chain-spec/pkg/chain/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ type (
cometBFTConfig struct{}
)

// TODO: Add setupValid, setupInvalid functions and use in each test.

calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved
// Create an instance of chainSpec with test data.
var spec = chain.NewChainSpec(
var spec, _ = chain.NewChainSpec(
calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved
chain.SpecData[
domainType, epoch, executionAddress, slot, cometBFTConfig,
]{
DenebPlusForkEpoch: 9,
ElectraForkEpoch: 10,
SlotsPerEpoch: 32,
MinEpochsForBlobsSidecarsRequest: 5,
MaxWithdrawalsPerPayload: 2,
calbera marked this conversation as resolved.
Show resolved Hide resolved
},
calbera marked this conversation as resolved.
Show resolved Hide resolved
)

Expand Down
4 changes: 2 additions & 2 deletions mod/config/pkg/spec/betnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (
)

// BetnetChainSpec is the ChainSpec for the localnet.
func BetnetChainSpec() chain.Spec[
func BetnetChainSpec() (chain.Spec[
common.DomainType,
math.Epoch,
common.ExecutionAddress,
math.Slot,
any,
] {
], error) {
testnetSpec := BaseSpec()
testnetSpec.DepositEth1ChainID = BetnetEth1ChainID
return chain.NewChainSpec(testnetSpec)
Expand Down
4 changes: 2 additions & 2 deletions mod/config/pkg/spec/boonet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (
)

// BoonetChainSpec is the ChainSpec for the localnet.
func BoonetChainSpec() chain.Spec[
func BoonetChainSpec() (chain.Spec[
common.DomainType,
math.Epoch,
common.ExecutionAddress,
math.Slot,
any,
] {
], error) {
testnetSpec := BaseSpec()
testnetSpec.DepositEth1ChainID = BoonetEth1ChainID
return chain.NewChainSpec(testnetSpec)
Expand Down
4 changes: 2 additions & 2 deletions mod/config/pkg/spec/devnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (
)

// DevnetChainSpec is the ChainSpec for the localnet.
func DevnetChainSpec() chain.Spec[
func DevnetChainSpec() (chain.Spec[
common.DomainType,
math.Epoch,
common.ExecutionAddress,
math.Slot,
any,
] {
], error) {
testnetSpec := BaseSpec()
testnetSpec.DepositEth1ChainID = DevnetEth1ChainID
return chain.NewChainSpec(testnetSpec)
Expand Down
22 changes: 14 additions & 8 deletions mod/config/pkg/spec/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import (
)

// TestnetChainSpec is the ChainSpec for the localnet.
func TestnetChainSpec() chain.Spec[
func TestnetChainSpec() (chain.Spec[
common.DomainType,
math.Epoch,
common.ExecutionAddress,
math.Slot,
any,
] {
], error) {
testnetSpec := BaseSpec()
testnetSpec.DepositEth1ChainID = TestnetEth1ChainID
return chain.NewChainSpec(testnetSpec)
Expand All @@ -59,11 +59,11 @@ func BaseSpec() chain.SpecData[
math.Slot,
any,
]{
// // Gwei value constants.
MinDepositAmount: uint64(1e9),
MaxEffectiveBalance: uint64(32e9),
EjectionBalance: uint64(16e9),
EffectiveBalanceIncrement: uint64(1e9),
// Gwei value constants.
MinDepositAmount: 1e9,
MaxEffectiveBalance: 32e9,
EjectionBalance: 16e9,
EffectiveBalanceIncrement: 1e9,
calbera marked this conversation as resolved.
Show resolved Hide resolved
// Time parameters constants.
SlotsPerEpoch: 32,
MinEpochsToInactivityPenalty: 4,
Expand Down Expand Up @@ -122,6 +122,12 @@ func BaseSpec() chain.SpecData[
FieldElementsPerBlob: 4096,
BytesPerBlob: 131072,
KZGCommitmentInclusionProofDepth: 17,
CometValues: cmtConsensusParams,
// Comet values.
CometValues: cmtConsensusParams,
// Berachain values.
EVMInflationAddress: common.NewExecutionAddressFromHex(
"0x6942069420694206942069420694206942069420",
),
EVMInflationPerBlock: 10e9,
calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved
}
}
6 changes: 4 additions & 2 deletions mod/da/pkg/store/pruner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,20 @@ func TestBuildPruneRangeFn(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cs := chain.NewChainSpec(
cs, err := chain.NewChainSpec(
chain.SpecData[
bytes.B4, math.U64, common.ExecutionAddress, math.U64, any,
]{
SlotsPerEpoch: tt.slotsPerEpoch,
MinEpochsForBlobsSidecarsRequest: tt.minEpochs,
MaxWithdrawalsPerPayload: 2,
},
)
require.NoError(t, err)
calbera marked this conversation as resolved.
Show resolved Hide resolved
pruneFn := store.BuildPruneRangeFn[MockBeaconBlock](
cs,
)
event := async.NewEvent[MockBeaconBlock](
event := async.NewEvent(
context.Background(),
async.EventID("mock"),
MockBeaconBlock{
Expand Down
21 changes: 11 additions & 10 deletions mod/node-core/pkg/components/chain_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ const (
)

// ProvideChainSpec provides the chain spec based on the environment variable.
func ProvideChainSpec() common.ChainSpec {
func ProvideChainSpec() (common.ChainSpec, error) {
// TODO: This is hood as fuck needs to be improved
// but for now we ball to get CI unblocked.
specType := os.Getenv(ChainSpecTypeEnvVar)
var chainSpec common.ChainSpec
switch specType {
var (
calbera marked this conversation as resolved.
Show resolved Hide resolved
chainSpec common.ChainSpec
err error
)
calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved
switch os.Getenv(ChainSpecTypeEnvVar) {
case DevnetChainSpecType:
chainSpec = spec.DevnetChainSpec()
chainSpec, err = spec.DevnetChainSpec()
case BetnetChainSpecType:
chainSpec = spec.BetnetChainSpec()
chainSpec, err = spec.BetnetChainSpec()
case BoonetChainSpecType:
chainSpec = spec.BoonetChainSpec()
chainSpec, err = spec.BoonetChainSpec()
default:
chainSpec = spec.TestnetChainSpec()
chainSpec, err = spec.TestnetChainSpec()
}
calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved

return chainSpec
return chainSpec, err
calbera marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading