Skip to content

Commit

Permalink
Use custom gas limit, if specified throughout charon
Browse files Browse the repository at this point in the history
  • Loading branch information
KaloyanTanev committed Jan 13, 2025
1 parent 3c81bec commit ee9b93a
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 105 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type Config struct {
ProcDirectory string
ConsensusProtocol string
Nickname string
TargetGasLimit uint

TestConfig TestConfig
}
Expand Down Expand Up @@ -490,7 +491,7 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,

dutyDB := dutydb.NewMemDB(deadlinerFunc("dutydb"))

vapi, err := validatorapi.NewComponent(eth2Cl, allPubSharesByKey, nodeIdx.ShareIdx, feeRecipientFunc, conf.BuilderAPI, seenPubkeys)
vapi, err := validatorapi.NewComponent(eth2Cl, allPubSharesByKey, nodeIdx.ShareIdx, feeRecipientFunc, conf.BuilderAPI, uint(cluster.GetTargetGasLimit()), seenPubkeys)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion app/peerinfo/peerinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (p *PeerInfo) sendOnce(ctx context.Context, now time.Time) {

name := p2p.PeerName(peerID)

p.nicknames[name] = resp.Nickname
p.nicknames[name] = resp.GetNickname()
log.Info(ctx, "Peer name to nickname mappings", z.Any("nicknames", p.nicknames))

// Validator git hash with regex.
Expand Down
4 changes: 2 additions & 2 deletions cluster/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ func NewDefinition(name string, numVals int, threshold int, feeRecipientAddresse
return Definition{}, errors.New("the version does not support partial deposits", z.Str("version", def.Version))
}

if targetGasLimit != 0 && !supportTargetGasLimit(def.Version) {
if def.TargetGasLimit != 0 && !supportTargetGasLimit(def.Version) {
return Definition{}, errors.New("the version does not support custom target gas limit", z.Str("version", def.Version))
}

if targetGasLimit == 0 && supportTargetGasLimit(def.Version) {
if def.TargetGasLimit == 0 && supportTargetGasLimit(def.Version) {
return Definition{}, errors.New("target gas limit should be set", z.Str("version", def.Version))
}

Expand Down
24 changes: 24 additions & 0 deletions cluster/manifest/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ import (
manifestpb "github.com/obolnetwork/charon/cluster/manifestpb/v1"
)

const (
v1_10 = "v1.10.0"
v1_9 = "v1.9.0"
v1_8 = "v1.8.0"
v1_7 = "v1.7.0"
v1_6 = "v1.6.0"
v1_5 = "v1.5.0"
v1_4 = "v1.4.0"
v1_3 = "v1.3.0"
v1_2 = "v1.2.0"
v1_1 = "v1.1.0"
v1_0 = "v1.0.0"
)

func isAnyVersion(version string, list ...string) bool {
for _, v := range list {
if version == v {
return true
}
}

return false
}

func TestDuplicateENRs(t *testing.T) {
seed := 0
random := rand.New(rand.NewSource(int64(seed)))
Expand Down
8 changes: 7 additions & 1 deletion cluster/manifest/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ func testLoadLegacy(t *testing.T, version string) {

var opts []func(*cluster.Definition)
opts = append(opts, cluster.WithVersion(version))
if version < "v1.5.0" {
if isAnyVersion(version, v1_0, v1_1, v1_2, v1_3, v1_4) {
opts = append(opts, cluster.WithLegacyVAddrs(testutil.RandomETHAddress(), testutil.RandomETHAddress()))
}

if isAnyVersion(version, v1_0, v1_1, v1_2, v1_3, v1_4, v1_5, v1_6, v1_7, v1_8, v1_9) {
opts = append(opts, func(d *cluster.Definition) { d.TargetGasLimit = 0 })
} else {
opts = append(opts, func(d *cluster.Definition) { d.TargetGasLimit = 36000000 })
}

seed := 0
random := rand.New(rand.NewSource(int64(seed)))
lock, _, _ := cluster.NewForT(t, rand.Intn(10), k, n, seed, random, opts...)
Expand Down
1 change: 1 addition & 0 deletions cluster/manifest/mutationlegacylock.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func transformLegacyLock(input *manifestpb.Cluster, signed *manifestpb.SignedMut
DkgAlgorithm: lock.DKGAlgorithm,
ForkVersion: lock.ForkVersion,
ConsensusProtocol: lock.ConsensusProtocol,
TargetGasLimit: uint32(lock.TargetGasLimit),
Validators: vals,
Operators: ops,
}, nil
Expand Down
115 changes: 63 additions & 52 deletions cluster/manifestpb/v1/manifest.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cluster/manifestpb/v1/manifest.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ message Cluster {
repeated Operator operators = 7; // Operators is the list of operators of the cluster.
repeated Validator validators = 8; // Validators is the list of validators of the cluster.
string consensus_protocol = 9; // ConsensusProtocol is the consensus protocol name preferred by the cluster, e.g. "abft".
uint32 target_gas_limit = 10; // TargetGasLimit is the custom target gas limit for transactions.
}

// Mutation mutates the cluster manifest.
Expand Down
15 changes: 10 additions & 5 deletions cmd/addvalidators.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func runAddValidatorsSolo(ctx context.Context, conf addValidatorsConfig) (err er
conf.WithdrawalAddrs = repeatAddr(conf.WithdrawalAddrs[0], conf.NumVals)
}

vals, secrets, shareSets, err := genNewVals(len(cluster.GetOperators()), int(cluster.GetThreshold()), cluster.GetForkVersion(), conf)
vals, secrets, shareSets, err := genNewVals(ctx, len(cluster.GetOperators()), int(cluster.GetThreshold()), cluster.GetForkVersion(), cluster.GetTargetGasLimit(), conf)
if err != nil {
return err
}
Expand Down Expand Up @@ -203,16 +203,21 @@ func runAddValidatorsSolo(ctx context.Context, conf addValidatorsConfig) (err er
}

// builderRegistration returns a builder registration object using the provided inputs.
func builderRegistration(secret tbls.PrivateKey, pubkey tbls.PublicKey, feeRecipientAddr string, forkVersion []byte) (*eth2v1.SignedValidatorRegistration, error) {
func builderRegistration(ctx context.Context, secret tbls.PrivateKey, pubkey tbls.PublicKey, feeRecipientAddr string, forkVersion []byte, targetGasLimit uint32) (*eth2v1.SignedValidatorRegistration, error) {
timestamp, err := eth2util.ForkVersionToGenesisTime(forkVersion)
if err != nil {
return nil, errors.Wrap(err, "invalid fork version")
}

if targetGasLimit == 0 {
log.Warn(ctx, "", errors.New("custom target gas limit not supported, setting to default", z.Uint("default_gas_limit", registration.DefaultGasLimit)))
targetGasLimit = registration.DefaultGasLimit
}

reg, err := registration.NewMessage(
eth2p0.BLSPubKey(pubkey),
feeRecipientAddr,
registration.DefaultGasLimit,
uint64(targetGasLimit),
timestamp,
)
if err != nil {
Expand Down Expand Up @@ -384,7 +389,7 @@ func validateConf(conf addValidatorsConfig) error {
}

// genNewVals returns a list of new validators, their corresponding private keys and threshold keyshares from the provided config.
func genNewVals(numOps, threshold int, forkVersion []byte, conf addValidatorsConfig) ([]*manifestpb.Validator, []tbls.PrivateKey, [][]tbls.PrivateKey, error) {
func genNewVals(ctx context.Context, numOps, threshold int, forkVersion []byte, targetGasLimit uint32, conf addValidatorsConfig) ([]*manifestpb.Validator, []tbls.PrivateKey, [][]tbls.PrivateKey, error) {
// Generate new validators
var (
vals []*manifestpb.Validator
Expand Down Expand Up @@ -439,7 +444,7 @@ func genNewVals(numOps, threshold int, forkVersion []byte, conf addValidatorsCon
}

// Generate builder registration
builderReg, err := builderRegistration(secret, pubkey, feeRecipientAddr, forkVersion)
builderReg, err := builderRegistration(ctx, secret, pubkey, feeRecipientAddr, forkVersion, targetGasLimit)
if err != nil {
return nil, nil, nil, err
}
Expand Down
Loading

0 comments on commit ee9b93a

Please sign in to comment.