Gas_Limit as string (#11264)

* setting gas limit as string in json and yaml

* adding more tests

* fixing unit test

* fixing string conversion
This commit is contained in:
james-prysm 2022-08-19 11:36:49 -05:00 committed by GitHub
parent 76f958710f
commit 5e2498be7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 140 additions and 34 deletions

View File

@ -3,6 +3,7 @@
package flags
import (
"fmt"
"path/filepath"
"runtime"
"time"
@ -346,10 +347,10 @@ var (
}
// BuilderGasLimitFlag defines the gas limit for the builder to use for constructing a payload.
BuilderGasLimitFlag = &cli.IntFlag{
BuilderGasLimitFlag = &cli.StringFlag{
Name: "suggested-gas-limit",
Usage: "Sets gas limit for the builder to use for constructing a payload for all the validators",
Value: int(params.BeaconConfig().DefaultBuilderGasLimit),
Value: fmt.Sprint(params.BeaconConfig().DefaultBuilderGasLimit),
}
)

View File

@ -1,6 +1,8 @@
package validator_service_config
import (
"strconv"
"github.com/ethereum/go-ethereum/common"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/config/params"
@ -25,10 +27,41 @@ type ProposerOptionPayload struct {
// GasLimit is a number set to help the network decide on the maximum gas in each block.
type BuilderConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
GasLimit uint64 `json:"gas_limit,omitempty" yaml:"gas_limit,omitempty"`
GasLimit Uint64 `json:"gas_limit,omitempty" yaml:"gas_limit,omitempty"`
Relays []string `json:"relays" yaml:"relays"`
}
type Uint64 uint64
func (u *Uint64) UnmarshalJSON(bs []byte) error {
str := string(bs) // Parse plain numbers directly.
if bs[0] == '"' && bs[len(bs)-1] == '"' {
// Unwrap the quotes from string numbers.
str = string(bs[1 : len(bs)-1])
}
x, err := strconv.ParseUint(str, 10, 64)
if err != nil {
return err
}
*u = Uint64(x)
return nil
}
func (u *Uint64) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
err := unmarshal(&str)
if err != nil {
return err
}
x, err := strconv.ParseUint(str, 10, 64)
if err != nil {
return err
}
*u = Uint64(x)
return nil
}
// ProposerSettings is a Prysm internal representation of the fee recipient config on the validator client.
// ProposerSettingsPayload maps to ProposerSettings on import through the CLI.
type ProposerSettings struct {

View File

@ -1066,7 +1066,7 @@ func (v *validator) buildSignedRegReqs(ctx context.Context, pubkeys [][fieldpara
feeRecipient = v.ProposerSettings.DefaultConfig.FeeRecipient // Use cli config for fee recipient.
config := v.ProposerSettings.DefaultConfig.BuilderConfig
if config != nil && config.Enabled {
gasLimit = config.GasLimit // Use cli config for gas limit.
gasLimit = uint64(config.GasLimit) // Use cli config for gas limit.
enabled = true
}
}
@ -1077,7 +1077,7 @@ func (v *validator) buildSignedRegReqs(ctx context.Context, pubkeys [][fieldpara
builderConfig := config.BuilderConfig
if builderConfig != nil {
if builderConfig.Enabled {
gasLimit = builderConfig.GasLimit // Use file config for gas limit.
gasLimit = uint64(builderConfig.GasLimit) // Use file config for gas limit.
enabled = true
} else {
enabled = false // Custom config can disable validator from register.

View File

@ -1514,7 +1514,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
GasLimit: 40000000,
},
}
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
@ -1523,7 +1523,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress(defaultFeeHex),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(35000000),
GasLimit: 35000000,
},
},
}
@ -1541,11 +1541,11 @@ func TestValidator_PushProposerSettings(t *testing.T) {
{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9").Bytes(),
GasLimit: uint64(40000000),
GasLimit: 40000000,
},
{
FeeRecipient: byteValueAddress,
GasLimit: uint64(35000000),
GasLimit: 35000000,
},
},
},
@ -1594,7 +1594,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
GasLimit: 40000000,
},
}
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
@ -1603,7 +1603,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress(defaultFeeHex),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: false,
GasLimit: uint64(35000000),
GasLimit: 35000000,
},
},
}
@ -1715,7 +1715,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress(defaultFeeHex),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
GasLimit: validatorserviceconfig.Uint64(params.BeaconConfig().DefaultBuilderGasLimit),
},
},
}
@ -1771,7 +1771,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress(defaultFeeHex),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
GasLimit: 40000000,
},
},
}
@ -1963,7 +1963,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
FeeRecipient: common.Address{},
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
GasLimit: 40000000,
},
}
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
@ -1972,7 +1972,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress(defaultFeeHex),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
GasLimit: 40000000,
},
},
}

View File

@ -13,6 +13,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strconv"
"strings"
"sync"
"syscall"
@ -498,9 +499,17 @@ func proposerSettings(cliCtx *cli.Context) (*validatorServiceConfig.ProposerSett
suggestedFee := cliCtx.String(flags.SuggestedFeeRecipientFlag.Name)
var vr *validatorServiceConfig.BuilderConfig
if cliCtx.Bool(flags.EnableBuilderFlag.Name) {
sgl := cliCtx.String(flags.BuilderGasLimitFlag.Name)
vr = &validatorServiceConfig.BuilderConfig{
Enabled: true,
GasLimit: reviewGasLimit(uint64(cliCtx.Int(flags.BuilderGasLimitFlag.Name))),
GasLimit: validatorServiceConfig.Uint64(params.BeaconConfig().DefaultBuilderGasLimit),
}
if sgl != "" {
gl, err := strconv.ParseUint(sgl, 10, 64)
if err != nil {
return nil, errors.New("Gas Limit is not a uint64")
}
vr.GasLimit = reviewGasLimit(validatorServiceConfig.Uint64(gl))
}
}
fileConfig = &validatorServiceConfig.ProposerSettingsPayload{
@ -595,10 +604,10 @@ func warnNonChecksummedAddress(feeRecipient string) error {
return nil
}
func reviewGasLimit(gasLimit uint64) uint64 {
func reviewGasLimit(gasLimit validatorServiceConfig.Uint64) validatorServiceConfig.Uint64 {
// sets gas limit to default if not defined or set to 0
if gasLimit == 0 {
return params.BeaconConfig().DefaultBuilderGasLimit
return validatorServiceConfig.Uint64(params.BeaconConfig().DefaultBuilderGasLimit)
}
//TODO(10810): add in warning for ranges
return gasLimit

View File

@ -211,6 +211,7 @@ func TestProposerSettings(t *testing.T) {
dir string
url string
defaultfee string
defaultgas string
}
type args struct {
@ -271,14 +272,14 @@ func TestProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress("0x50155530FCE8a85ec7055A5F8b2bE214B3DaeFd3"),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
GasLimit: validatorserviceconfig.Uint64(params.BeaconConfig().DefaultBuilderGasLimit),
},
},
bytesutil.ToBytes48(key2): {
FeeRecipient: common.HexToAddress("0x60155530FCE8a85ec7055A5F8b2bE214B3DaeFd4"),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
GasLimit: validatorserviceconfig.Uint64(35000000),
},
},
},
@ -286,7 +287,7 @@ func TestProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress("0x6e35733c5af9B61374A128e6F85f553aF09ff89A"),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
GasLimit: validatorserviceconfig.Uint64(40000000),
},
},
}
@ -336,7 +337,7 @@ func TestProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress("0x50155530FCE8a85ec7055A5F8b2bE214B3DaeFd3"),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
GasLimit: 40000000,
},
},
},
@ -344,7 +345,7 @@ func TestProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress("0x6e35733c5af9B61374A128e6F85f553aF09ff89A"),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: false,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
GasLimit: validatorserviceconfig.Uint64(params.BeaconConfig().DefaultBuilderGasLimit),
},
},
}
@ -386,7 +387,32 @@ func TestProposerSettings(t *testing.T) {
FeeRecipient: common.HexToAddress("0x6e35733c5af9B61374A128e6F85f553aF09ff89A"),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
GasLimit: validatorserviceconfig.Uint64(params.BeaconConfig().DefaultBuilderGasLimit),
},
},
}
},
wantErr: "",
validatorRegistrationEnabled: true,
},
{
name: "Happy Path Suggested Fee , validator registration enabled and default gas",
args: args{
proposerSettingsFlagValues: &proposerSettingsFlag{
dir: "",
url: "",
defaultfee: "0x6e35733c5af9B61374A128e6F85f553aF09ff89A",
defaultgas: "50000000",
},
},
want: func() *validatorserviceconfig.ProposerSettings {
return &validatorserviceconfig.ProposerSettings{
ProposeConfig: nil,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress("0x6e35733c5af9B61374A128e6F85f553aF09ff89A"),
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: 50000000,
},
},
}
@ -487,6 +513,20 @@ func TestProposerSettings(t *testing.T) {
},
wantErr: "cannot specify both",
},
{
name: "Bad Gas value in JSON",
args: args{
proposerSettingsFlagValues: &proposerSettingsFlag{
dir: "./testdata/bad-gas-value-proposer-settings.json",
url: "",
defaultfee: "",
},
},
want: func() *validatorserviceconfig.ProposerSettings {
return nil
},
wantErr: "failed to unmarshal yaml file",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@ -514,6 +554,10 @@ func TestProposerSettings(t *testing.T) {
set.String(flags.SuggestedFeeRecipientFlag.Name, tt.args.proposerSettingsFlagValues.defaultfee, "")
require.NoError(t, set.Set(flags.SuggestedFeeRecipientFlag.Name, tt.args.proposerSettingsFlagValues.defaultfee))
}
if tt.args.proposerSettingsFlagValues.defaultgas != "" {
set.String(flags.BuilderGasLimitFlag.Name, tt.args.proposerSettingsFlagValues.defaultgas, "")
require.NoError(t, set.Set(flags.BuilderGasLimitFlag.Name, tt.args.proposerSettingsFlagValues.defaultgas))
}
if tt.validatorRegistrationEnabled {
set.Bool(flags.EnableBuilderFlag.Name, true, "")
}

View File

@ -0,0 +1,19 @@
{
"proposer_config": {
"0xa057816155ad77931185101128655c0191bd0214c201ca48ed887f6c4c6adf334070efcd75140eada5ac83a92506dd7a": {
"fee_recipient": "0x50155530FCE8a85ec7055A5F8b2bE214B3DaeFd3",
"builder": {
"enabled": true,
"gas_limit": "asdfsffsdf"
}
}
},
"default_config": {
"fee_recipient": "0x6e35733c5af9B61374A128e6F85f553aF09ff89A",
"builder": {
"enabled": true,
"gas_limit": 40000000
}
}
}

View File

@ -4,14 +4,14 @@
"fee_recipient": "0x50155530FCE8a85ec7055A5F8b2bE214B3DaeFd3",
"builder": {
"enabled": true,
"gas_limit": 30000000
"gas_limit": "30000000"
}
},
"0xb057816155ad77931185101128655c0191bd0214c201ca48ed887f6c4c6adf334070efcd75140eada5ac83a92506dd7b": {
"fee_recipient": "0x60155530FCE8a85ec7055A5F8b2bE214B3DaeFd4",
"builder": {
"enabled": true,
"gas_limit": 30000000
"gas_limit": 35000000
}
}
},
@ -19,7 +19,7 @@
"fee_recipient": "0x6e35733c5af9B61374A128e6F85f553aF09ff89A",
"builder": {
"enabled": true,
"gas_limit": 30000000
"gas_limit": 40000000
}
}
}

View File

@ -9,4 +9,4 @@ default_config:
fee_recipient: '0x6e35733c5af9B61374A128e6F85f553aF09ff89A'
builder:
enabled: false
gas_limit: 30000000
gas_limit: '30000000'

View File

@ -406,11 +406,11 @@ func (s *Server) GetGasLimit(_ context.Context, req *ethpbservice.PubkeyRequest)
proposerOption, found := s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)]
if found {
if proposerOption.BuilderConfig != nil {
resp.Data.GasLimit = proposerOption.BuilderConfig.GasLimit
resp.Data.GasLimit = uint64(proposerOption.BuilderConfig.GasLimit)
return resp, nil
}
} else if s.validatorService.ProposerSettings.DefaultConfig != nil && s.validatorService.ProposerSettings.DefaultConfig.BuilderConfig != nil {
resp.Data.GasLimit = s.validatorService.ProposerSettings.DefaultConfig.BuilderConfig.GasLimit
resp.Data.GasLimit = uint64(s.validatorService.ProposerSettings.DefaultConfig.BuilderConfig.GasLimit)
return resp, nil
}
}
@ -437,10 +437,10 @@ func (s *Server) SetGasLimit(ctx context.Context, req *ethpbservice.SetGasLimitR
// "DefaultConfig.BuilderConfig".
bo := *s.validatorService.ProposerSettings.DefaultConfig.BuilderConfig
pBuilderConfig = &bo
pBuilderConfig.GasLimit = req.GasLimit
pBuilderConfig.GasLimit = validatorServiceConfig.Uint64(req.GasLimit)
} else {
// No default BuildConfig to copy from, just create one and set "GasLimit", but keep "Enabled" to "false".
pBuilderConfig = &validatorServiceConfig.BuilderConfig{Enabled: false, GasLimit: req.GasLimit}
pBuilderConfig = &validatorServiceConfig.BuilderConfig{Enabled: false, GasLimit: validatorServiceConfig.Uint64(req.GasLimit)}
}
pOption := validatorServiceConfig.DefaultProposerOption()
@ -463,7 +463,7 @@ func (s *Server) SetGasLimit(ctx context.Context, req *ethpbservice.SetGasLimitR
if proposerOption.BuilderConfig == nil {
proposerOption.BuilderConfig = pBuilderConfig
} else {
proposerOption.BuilderConfig.GasLimit = req.GasLimit
proposerOption.BuilderConfig.GasLimit = validatorServiceConfig.Uint64(req.GasLimit)
}
} else {
s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)] = &pOption

View File

@ -1007,7 +1007,7 @@ func TestServer_SetGasLimit(t *testing.T) {
_, err = s.SetGasLimit(ctx, &ethpbservice.SetGasLimitRequest{Pubkey: tt.pubkey, GasLimit: tt.newGasLimit})
require.NoError(t, err)
for _, w := range tt.w {
assert.Equal(t, w.gaslimit, s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(w.pubkey)].BuilderConfig.GasLimit)
assert.Equal(t, w.gaslimit, uint64(s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(w.pubkey)].BuilderConfig.GasLimit))
}
})
}