Skip to content

Commit

Permalink
Add feature flag for rule change checks
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbertJordan committed Dec 20, 2024
1 parent afdec4a commit 753f687
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
4 changes: 4 additions & 0 deletions opera/legacy_serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func (u Upgrades) EncodeRLP(w io.Writer) error {
if u.Sonic {
bitmap.V |= sonicBit
}
if u.CheckRuleChanges {
bitmap.V |= checkRuleChangesBit
}
return rlp.Encode(w, &bitmap)
}

Expand All @@ -112,6 +115,7 @@ func (u *Upgrades) DecodeRLP(s *rlp.Stream) error {
u.London = (bitmap.V & londonBit) != 0
u.Llr = (bitmap.V & llrBit) != 0
u.Sonic = (bitmap.V & sonicBit) != 0
u.CheckRuleChanges = (bitmap.V & checkRuleChangesBit) != 0
return nil
}

Expand Down
6 changes: 4 additions & 2 deletions opera/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ func UpdateRules(src Rules, diff []byte) (Rules, error) {
changed.Name = src.Name

// check validity of the new rules
if err = changed.Validate(); err != nil {
return Rules{}, err
if changed.Upgrades.CheckRuleChanges {
if err = changed.Validate(); err != nil {
return Rules{}, err
}
}
return changed, nil
}
43 changes: 23 additions & 20 deletions opera/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import (
)

const (
MainNetworkID uint64 = 0xfa
TestNetworkID uint64 = 0xfa2
FakeNetworkID uint64 = 0xfa3
DefaultEventGas uint64 = 28000
berlinBit = 1 << 0
londonBit = 1 << 1
llrBit = 1 << 2
sonicBit = 1 << 3
MainNetworkID uint64 = 0xfa
TestNetworkID uint64 = 0xfa2
FakeNetworkID uint64 = 0xfa3
DefaultEventGas uint64 = 28000
berlinBit = 1 << 0
londonBit = 1 << 1
llrBit = 1 << 2
sonicBit = 1 << 3
checkRuleChangesBit = 1 << 4

MinimumMaxBlockGas = 1_000_000_000 // < must be large enough to allow internal transactions to seal blocks
MaximumMaxBlockGas = math.MaxInt64 // < should fit into 64-bit signed integers to avoid parsing errors in third-party libraries
Expand Down Expand Up @@ -214,6 +215,8 @@ type Upgrades struct {
London bool
Llr bool
Sonic bool

CheckRuleChanges bool // < enables safety checks for rule updates
}

type UpgradeHeight struct {
Expand Down Expand Up @@ -302,12 +305,7 @@ func MainNetRules() Rules {
MaxBlockGas: MinimumMaxBlockGas,
MaxEmptyBlockSkipPeriod: inter.Timestamp(1 * time.Minute),
},
Upgrades: Upgrades{
Berlin: true,
London: true,
Llr: false,
Sonic: true,
},
Upgrades: DefaultUpgrades(),
}
}

Expand All @@ -323,12 +321,7 @@ func FakeNetRules() Rules {
MaxBlockGas: MinimumMaxBlockGas,
MaxEmptyBlockSkipPeriod: inter.Timestamp(3 * time.Second),
},
Upgrades: Upgrades{
Berlin: true,
London: true,
Llr: false,
Sonic: true,
},
Upgrades: DefaultUpgrades(),
}
}

Expand All @@ -345,6 +338,16 @@ func DefaultEconomyRules() EconomyRules {
return rules
}

func DefaultUpgrades() Upgrades {
return Upgrades{
Berlin: true,
London: true,
Llr: false,
Sonic: true,
CheckRuleChanges: true,
}
}

// FakeEconomyRules returns fakenet economy
func FakeEconomyRules() EconomyRules {
return DefaultEconomyRules()
Expand Down
3 changes: 0 additions & 3 deletions opera/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ func validateDagRules(rules DagRules) error {
func validateEmitterRules(rules EmitterRules) error {

var issues []error
if rules.Interval < inter.Timestamp(100*time.Millisecond) {
issues = append(issues, errors.New("Emitter.Interval is too low"))
}
if rules.Interval > inter.Timestamp(10*time.Second) {
issues = append(issues, errors.New("Emitter.Interval is too high"))
}
Expand Down

0 comments on commit 753f687

Please sign in to comment.