Skip to content

Commit

Permalink
caplin: Fix config type (#13609)
Browse files Browse the repository at this point in the history
Fixes an issue where the `/eth/v1/config/spec` was returning an
incorrect output.

```bash
curl -s 0.0.0.0:5052/eth/v1/config/spec | jq '.data | with_entries(select(.key | test("REQUEST_TYPE$")))'
{
  "DEPOSIT_REQUEST_TYPE": "0x00",
  "WITHDRAWAL_REQUEST_TYPE": "0x01",
  "CONSOLIDATION_REQUEST_TYPE": "0x02"
}
```
  • Loading branch information
shohamc1 authored Jan 30, 2025
1 parent 3746a57 commit 5fd0aba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
19 changes: 13 additions & 6 deletions cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"gopkg.in/yaml.v2"

"github.com/c2h5oh/datasize"

"github.com/erigontech/erigon-lib/chain/networkname"
libcommon "github.com/erigontech/erigon-lib/common"

Expand Down Expand Up @@ -357,6 +358,12 @@ func (b ConfigByte) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"0x%x\"", b)), nil
}

type RequestTypePrefix byte

func (b RequestTypePrefix) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"0x%02x\"", b)), nil
}

type ConfigForkVersion uint32

func (v ConfigForkVersion) MarshalJSON() ([]byte, error) {
Expand Down Expand Up @@ -578,12 +585,12 @@ type BeaconChainConfig struct {
PendingConsolidationsLimit uint64 `yaml:"PENDING_CONSOLIDATIONS_LIMIT" spec:"true" json:"PENDING_CONSOLIDATIONS_LIMIT,string"` // PendingConsolidationsLimit defines the maximum number of pending consolidations.
MaxBlobsPerBlockElectra uint64 `yaml:"MAX_BLOBS_PER_BLOCK_ELECTRA" spec:"true" json:"MAX_BLOBS_PER_BLOCK_ELECTRA,string"` // MaxBlobsPerBlockElectra defines the maximum number of blobs per block for Electra.
// Constants for the Electra fork.
UnsetDepositRequestsStartIndex uint64 `yaml:"UNSET_DEPOSIT_REQUESTS_START_INDEX" spec:"true" json:"UNSET_DEPOSIT_REQUESTS_START_INDEX,string"` // UnsetDepositRequestsStartIndex defines the start index for unset deposit requests.
FullExitRequestAmount uint64 `yaml:"FULL_EXIT_REQUEST_AMOUNT" spec:"true" json:"FULL_EXIT_REQUEST_AMOUNT,string"` // FullExitRequestAmount defines the amount for a full exit request.
CompoundingWithdrawalPrefix byte `yaml:"COMPOUNDING_WITHDRAWAL_PREFIX" spec:"true" json:"COMPOUNDING_WITHDRAWAL_PREFIX"` // CompoundingWithdrawalPrefix is the prefix for compounding withdrawals.
DepositRequestType byte `yaml:"DEPOSIT_REQUEST_TYPE" spec:"true" json:"DEPOSIT_REQUEST_TYPE"` // DepositRequestType is the type for deposit requests.
WithdrawalRequestType byte `yaml:"WITHDRAWAL_REQUEST_TYPE" spec:"true" json:"WITHDRAWAL_REQUEST_TYPE"` // WithdrawalRequestType is the type for withdrawal requests.
ConsolidationRequestType byte `yaml:"CONSOLIDATION_REQUEST_TYPE" spec:"true" json:"CONSOLIDATION_REQUEST_TYPE"` // ConsolidationRequestType is the type for consolidation requests.
UnsetDepositRequestsStartIndex uint64 `yaml:"UNSET_DEPOSIT_REQUESTS_START_INDEX" spec:"true" json:"UNSET_DEPOSIT_REQUESTS_START_INDEX,string"` // UnsetDepositRequestsStartIndex defines the start index for unset deposit requests.
FullExitRequestAmount uint64 `yaml:"FULL_EXIT_REQUEST_AMOUNT" spec:"true" json:"FULL_EXIT_REQUEST_AMOUNT,string"` // FullExitRequestAmount defines the amount for a full exit request.
CompoundingWithdrawalPrefix RequestTypePrefix `yaml:"COMPOUNDING_WITHDRAWAL_PREFIX" spec:"true" json:"COMPOUNDING_WITHDRAWAL_PREFIX"` // CompoundingWithdrawalPrefix is the prefix for compounding withdrawals.
DepositRequestType RequestTypePrefix `yaml:"DEPOSIT_REQUEST_TYPE" spec:"true" json:"DEPOSIT_REQUEST_TYPE"` // DepositRequestType is the type for deposit requests.
WithdrawalRequestType RequestTypePrefix `yaml:"WITHDRAWAL_REQUEST_TYPE" spec:"true" json:"WITHDRAWAL_REQUEST_TYPE"` // WithdrawalRequestType is the type for withdrawal requests.
ConsolidationRequestType RequestTypePrefix `yaml:"CONSOLIDATION_REQUEST_TYPE" spec:"true" json:"CONSOLIDATION_REQUEST_TYPE"` // ConsolidationRequestType is the type for consolidation requests.
}

func (b *BeaconChainConfig) RoundSlotToEpoch(slot uint64) uint64 {
Expand Down
6 changes: 3 additions & 3 deletions cl/cltypes/beacon_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,9 @@ func (b *BeaconBody) GetExecutionRequestsList() []hexutility.Bytes {
typ byte
requests ssz.EncodableSSZ
}{
{b.beaconCfg.DepositRequestType, r.Deposits},
{b.beaconCfg.WithdrawalRequestType, r.Withdrawals},
{b.beaconCfg.ConsolidationRequestType, r.Consolidations},
{byte(b.beaconCfg.DepositRequestType), r.Deposits},
{byte(b.beaconCfg.WithdrawalRequestType), r.Withdrawals},
{byte(b.beaconCfg.ConsolidationRequestType), r.Consolidations},
} {
ssz, err := r.requests.EncodeSSZ([]byte{})
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cl/phase1/core/state/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sort"

"github.com/Giulio2002/bls"

"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon/cl/abstract"
"github.com/erigontech/erigon/cl/clparams"
Expand Down Expand Up @@ -77,7 +78,7 @@ func HasEth1WithdrawalCredential(validator solid.Validator, conf *clparams.Beaco

func HasCompoundingWithdrawalCredential(validator solid.Validator, conf *clparams.BeaconChainConfig) bool {
withdrawalCredentials := validator.WithdrawalCredentials()
return withdrawalCredentials[0] == conf.CompoundingWithdrawalPrefix
return withdrawalCredentials[0] == byte(conf.CompoundingWithdrawalPrefix)
}

func HasExecutionWithdrawalCredential(validator solid.Validator, conf *clparams.BeaconChainConfig) bool {
Expand Down
2 changes: 1 addition & 1 deletion cl/transition/impl/eth2/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ func switchToCompoundingValidator(s abstract.BeaconState, vindex uint64) error {
wc := validator.WithdrawalCredentials()
newWc := common.Hash{}
copy(newWc[:], wc[:])
newWc[0] = s.BeaconConfig().CompoundingWithdrawalPrefix
newWc[0] = byte(s.BeaconConfig().CompoundingWithdrawalPrefix)
validator.SetWithdrawalCredentials(newWc)
s.SetValidatorAtIndex(int(vindex), validator) // update the state
return state.QueueExcessActiveBalance(s, vindex, &validator)
Expand Down

0 comments on commit 5fd0aba

Please sign in to comment.