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(berad): Bera minting every block with withdrawal to BGT contract #2129

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions examples/berad/pkg/chain-spec/berachain.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type BeraChainSpec struct {
]
// BGTContractAddress is the address of the BGT contract.
BGTContractAddress [20]byte `mapstructure:"bgt-contract-address"`
// MaxBeraMintAmount is the amount of BERA minted per block to the BGT
// contract.
MaxBeraMintAmount uint64 `mapstructure:"max-bera-mint-amount"`
abi87 marked this conversation as resolved.
Show resolved Hide resolved
// MaxCommitteeSize is the maximum size of the committee.
MaxCommitteeSize uint64 `mapstructure:"max-committee-size"`
}
19 changes: 16 additions & 3 deletions examples/berad/pkg/state-transition/state_processor_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (sp *StateProcessor[
_ BeaconStateT,
_ BeaconBlockBodyT,
) error {
// TODO: implement
// TODO: implement by calling ExpectedWithdrawals and then applying them.
calbera marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

Expand All @@ -190,7 +190,20 @@ func (sp *StateProcessor[
// ExpectedWithdrawals retrieves the expected withdrawals.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _,
_, _, _, _, _, _, _, WithdrawalsT, _,
_, _, _, _, _, _, WithdrawalT, WithdrawalsT, _,
]) ExpectedWithdrawals(st BeaconStateT) (WithdrawalsT, error) {
return st.GetWithdrawals()
withdrawals, err := st.GetWithdrawals()
if err != nil {
return nil, err
}
calbera marked this conversation as resolved.
Show resolved Hide resolved

var bgtWithdrawal WithdrawalT
bgtWithdrawal = bgtWithdrawal.New(
math.U64(len(withdrawals)),
math.ValidatorIndex(0), // TODO: replace with validator set cap.
sp.cs.BGTContractAddress,
math.U64(sp.cs.MaxBeraMintAmount),
)
calbera marked this conversation as resolved.
Show resolved Hide resolved

return append(withdrawals, bgtWithdrawal), nil
}
22 changes: 22 additions & 0 deletions mod/chain-spec/pkg/chain/chain_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ type Spec[
// slashing penalties.
ProportionalSlashingMultiplier() uint64

// BGTContractAddress is the address of the BGT contract.
BGTContractAddress() [20]byte

// MaxBeraMintAmount is the amount of BERA minted per block to the BGT
// contract.
MaxBeraMintAmount() uint64
calbera marked this conversation as resolved.
Show resolved Hide resolved

// Capella Values

// MaxWithdrawalsPerPayload returns the maximum number of withdrawals per
Expand Down Expand Up @@ -416,6 +423,21 @@ func (c chainSpec[
return c.Data.ProportionalSlashingMultiplier
}

// BGTContractAddress is the address of the BGT contract.
func (c chainSpec[
DomainTypeT, EpochT, ExecutionAddressT, SlotT, CometBFTConfigT,
]) BGTContractAddress() [20]byte {
return c.Data.BGTContractAddress
}

// MaxBeraMintAmount is the amount of BERA minted per block to the BGT
// contract.
func (c chainSpec[
DomainTypeT, EpochT, ExecutionAddressT, SlotT, CometBFTConfigT,
]) MaxBeraMintAmount() uint64 {
return c.Data.MaxBeraMintAmount
}

// MaxWithdrawalsPerPayload returns the maximum number of withdrawals per
// payload.
func (c chainSpec[
Expand Down
6 changes: 6 additions & 0 deletions mod/chain-spec/pkg/chain/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ type SpecData[
// base penalty.
ProportionalSlashingMultiplier uint64 `mapstructure:"proportional-slashing-multiplier"`

// BGTContractAddress is the address of the BGT contract.
BGTContractAddress [20]byte `mapstructure:"bgt-contract-address"`
// MaxBeraMintAmount is the amount of BERA minted per block to the BGT
// contract.
MaxBeraMintAmount uint64 `mapstructure:"max-bera-mint-amount"`
calbera marked this conversation as resolved.
Show resolved Hide resolved

// Capella Values
//
// MaxWithdrawalsPerPayload indicates the maximum number of withdrawal
Expand Down
17 changes: 17 additions & 0 deletions mod/state-transition/pkg/core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,23 @@ func (s *StateDB[
return nil, err
}

// Note by prepending the withdrawals for bera minting here we
// explicitly request for these (automatic) withdrawals to be
// included in a block. This feels future-proof if we ever change
// the amount, but may be considered wasteful as well.
var mintWithdrawal WithdrawalT
withdrawals = append(withdrawals, mintWithdrawal.New(
calbera marked this conversation as resolved.
Show resolved Hide resolved
math.U64(withdrawalIndex),

// QUESTION: if we use withdrawals, what do we use here?
// Proposer index? 0 (which is a valid index)? MaxU64??
0,

s.cs.BGTContractAddress(),
math.Gwei(s.cs.MaxBeraMintAmount()),
))
withdrawalIndex++

calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved
validatorIndex, err := s.GetNextWithdrawalValidatorIndex()
if err != nil {
return nil, err
Expand Down
Loading