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

Disable MESS #592

Merged
merged 9 commits into from
Dec 6, 2023
5 changes: 5 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
cfg.Eth.ECBP1100 = new(big.Int).SetUint64(n)
}
}
if ctx.IsSet(utils.ECBP1100DisableFlag.Name) {
if n := ctx.Uint64(utils.ECBP1100DisableFlag.Name); n != math.MaxUint64 {
cfg.Eth.ECBP1100Disable = new(big.Int).SetUint64(n)
}
}
if ctx.IsSet(utils.ECBP1100NoDisableFlag.Name) {
if enable := ctx.Bool(utils.ECBP1100NoDisableFlag.Name); enable {
cfg.Eth.ECBP1100NoDisable = &enable
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ var (
utils.MinerNotifyFullFlag,
utils.ECBP1100Flag,
utils.ECBP1100NoDisableFlag,
utils.ECBP1100DisableFlag,
configFileFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags)

Expand Down
7 changes: 7 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,11 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Usage: "Configure ECBP-1100 (MESS) block activation number",
Value: math.MaxUint64,
}
ECBP1100DisableFlag = &cli.Uint64Flag{
Name: "ecbp1100.disable",
Usage: "Disable ECBP-1100 (MESS) block activation number",
Value: math.MaxUint64,
}
ECBP1100NoDisableFlag = &cli.BoolFlag{
Name: "ecbp1100.nodisable",
Usage: "Short-circuit ECBP-1100 (MESS) disable mechanisms; (yields a permanent-once-activated state, deactivating auto-shutoff mechanisms)",
Expand Down Expand Up @@ -2081,6 +2086,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.EthDiscoveryURLs = SplitAndTrim(urls)
}
}
CheckExclusive(ctx, ECBP1100DisableFlag, ECBP1100NoDisableFlag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meowsbits this is probably better to be removed (I added it).

A node operator might indeed want the nodisable functionality, so if he still wants to enable ECBP-1100 he has to do --ecbp1100.disable=69420123 --ecbp1100.nodisable.

The thing is that with the above check, this is not allowed.


// Override any default configs for hard coded networks.

// Override genesis configuration if a --<chain> flag.
Expand Down
7 changes: 7 additions & 0 deletions core/blockchain_af.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func (bc *BlockChain) ArtificialFinalityNoDisable(n int32) {
log.Warn("Deactivating ECBP1100 (MESS) disablers", "always on", true)
bc.artificialFinalityNoDisable = new(int32)
atomic.StoreInt32(bc.artificialFinalityNoDisable, n)

if n == 1 {
disabledTransition := bc.chainConfig.GetECBP1100DisableTransition()
if disabledTransition != nil && big.NewInt(int64(*disabledTransition)).Cmp(big.NewInt(0)) > 0 {
log.Warn("Disable ECBP1100 (MESS) block activation number is set together with '--ecbp1100.nodisable'. ECBP1100 will not be disabled.", "disable transition block", *disabledTransition)
}
}
}

// EnableArtificialFinality enables and disable artificial finality features for the blockchain.
Expand Down
8 changes: 8 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}
}
}
if config.ECBP1100Disable != nil {
if n := config.ECBP1100Disable.Uint64(); n != math.MaxUint64 {
if err := eth.blockchain.Config().SetECBP1100DisableTransition(&n); err != nil {
return nil, err
}
}
}

if config.ECBP1100NoDisable != nil {
if *config.ECBP1100NoDisable {
eth.blockchain.ArtificialFinalityNoDisable(1)
Expand Down
2 changes: 2 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ type Config struct {

// Manual configuration field for ECBP1100 activation number. Used for modifying genesis config via CLI flag.
ECBP1100 *big.Int
// Manual configuration field for ECBP1100's disablement block number. Used for modifying genesis config via CLI flag.
ECBP1100Disable *big.Int

// ECBP1100NoDisable overrides
// When this value is *true, ECBP100 will not (ever) be disabled; when *false, it will never be enabled.
Expand Down
7 changes: 7 additions & 0 deletions eth/ethconfig/gen_config.go

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

5 changes: 3 additions & 2 deletions params/config_classic.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ var (
EIP2028FBlock: big.NewInt(10_500_839),
EIP2200FBlock: big.NewInt(10_500_839), // RePetersburg (=~ re-1283)

ECBP1100FBlock: big.NewInt(11_380_000), // ETA 09 Oct 2020
ECIP1099FBlock: big.NewInt(11_700_000), // Etchash (DAG size limit)
ECBP1100FBlock: big.NewInt(11_380_000), // ETA 09 Oct 2020
ECBP1100DisableFBlock: big.NewInt(69_420_123),
meowsbits marked this conversation as resolved.
Show resolved Hide resolved
ECIP1099FBlock: big.NewInt(11_700_000), // Etchash (DAG size limit)

// Berlin eq, aka Magneto
EIP2565FBlock: big.NewInt(13_189_133),
Expand Down
5 changes: 3 additions & 2 deletions params/types/coregeth/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ type CoreGethChainConfig struct {
ECIP1017EraRounds *big.Int `json:"ecip1017EraRounds,omitempty"` // ECIP1017 era rounds
ECIP1080FBlock *big.Int `json:"ecip1080FBlock,omitempty"`

ECIP1099FBlock *big.Int `json:"ecip1099FBlock,omitempty"` // ECIP1099 etchash HF block
ECBP1100FBlock *big.Int `json:"ecbp1100FBlock,omitempty"` // ECBP1100:MESS artificial finality
ECIP1099FBlock *big.Int `json:"ecip1099FBlock,omitempty"` // ECIP1099 etchash HF block
ECBP1100FBlock *big.Int `json:"ecbp1100FBlock,omitempty"` // ECBP1100:MESS artificial finality
ECBP1100DisableFBlock *big.Int `json:"ecbp1100DisableFBlock,omitempty"` // Disable ECBP1100:MESS artificial finality
meowsbits marked this conversation as resolved.
Show resolved Hide resolved

// EIP-2315: Simple Subroutines
// https://eips.ethereum.org/EIPS/eip-2315
Expand Down
19 changes: 19 additions & 0 deletions params/types/coregeth/chain_config_configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ package coregeth

import (
"math/big"
"reflect"
"runtime"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
Expand Down Expand Up @@ -424,6 +427,15 @@ func (c *CoreGethChainConfig) SetECBP1100Transition(n *uint64) error {
return nil
}

func (c *CoreGethChainConfig) GetECBP1100DisableTransition() *uint64 {
return bigNewU64(c.ECBP1100DisableFBlock)
}

func (c *CoreGethChainConfig) SetECBP1100DisableTransition(n *uint64) error {
c.ECBP1100DisableFBlock = setBig(c.ECBP1100DisableFBlock, n)
return nil
}

func (c *CoreGethChainConfig) GetEIP2315Transition() *uint64 {
return bigNewU64(c.EIP2315FBlock)
}
Expand Down Expand Up @@ -669,6 +681,13 @@ func (c *CoreGethChainConfig) IsEnabled(fn func() *uint64, n *big.Int) bool {
if f == nil || n == nil {
return false
}
fnName := runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice hack in order to check if both are enabled, either way it will not stay for too long.

p.s.: I hope I don't read back this comment in 1-2 years and the code is still here :)

if strings.Contains(fnName, "ECBP1100Transition") {
disabledTransition := c.GetECBP1100DisableTransition()
if disabledTransition != nil {
return big.NewInt(int64(*disabledTransition)).Cmp(n) > 0 && big.NewInt(int64(*f)).Cmp(n) <= 0
}
}
return big.NewInt(int64(*f)).Cmp(n) <= 0
}

Expand Down
40 changes: 40 additions & 0 deletions params/types/coregeth/chain_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,43 @@ func TestCoreGethChainConfig_String(t *testing.T) {
t.Skip("(noop) development use only")
t.Log(testConfig.String())
}

func TestCoreGethChainConfig_ECBP1100Disable(t *testing.T) {
var _testConfig = &CoreGethChainConfig{}
*_testConfig = *testConfig

enable := uint64(100)
disable := uint64(200)
_testConfig.SetECBP1100Transition(&enable)
_testConfig.SetECBP1100DisableTransition(&disable)

n := uint64(10)
bigN := new(big.Int).SetUint64(n)
if _testConfig.IsEnabled(_testConfig.GetECBP1100Transition, bigN) {
t.Errorf("ECBP1100 should be not yet be enabled at block %d", n)
}

n = uint64(100)
bigN = new(big.Int).SetUint64(n)
if !_testConfig.IsEnabled(_testConfig.GetECBP1100Transition, bigN) {
t.Errorf("ECBP1100 should be enabled at block %d", n)
}

n = uint64(110)
bigN = new(big.Int).SetUint64(n)
if !_testConfig.IsEnabled(_testConfig.GetECBP1100Transition, bigN) {
t.Errorf("ECBP1100 should be enabled at block %d", n)
}

n = uint64(200)
bigN = new(big.Int).SetUint64(n)
if _testConfig.IsEnabled(_testConfig.GetECBP1100Transition, bigN) {
t.Errorf("ECBP1100 should be disabled at block %d", n)
}

n = uint64(210)
bigN = new(big.Int).SetUint64(n)
if _testConfig.IsEnabled(_testConfig.GetECBP1100Transition, bigN) {
t.Errorf("ECBP1100 should be disabled at block %d", n)
}
}
3 changes: 3 additions & 0 deletions params/types/ctypes/configurator_iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ type ProtocolSpecifier interface {

GetECBP1100Transition() *uint64
SetECBP1100Transition(n *uint64) error
GetECBP1100DisableTransition() *uint64
SetECBP1100DisableTransition(n *uint64) error

GetEIP2315Transition() *uint64
SetEIP2315Transition(n *uint64) error

Expand Down
8 changes: 8 additions & 0 deletions params/types/genesisT/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,14 @@ func (g *Genesis) SetECBP1100Transition(n *uint64) error {
return g.Config.SetECBP1100Transition(n)
}

func (g *Genesis) GetECBP1100DisableTransition() *uint64 {
return g.Config.GetECBP1100DisableTransition()
}

func (g *Genesis) SetECBP1100DisableTransition(n *uint64) error {
return g.Config.SetECBP1100DisableTransition(n)
}

func (g *Genesis) IsEnabled(fn func() *uint64, n *big.Int) bool {
return g.Config.IsEnabled(fn, n)
}
Expand Down
3 changes: 2 additions & 1 deletion params/types/goethereum/goethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ type ChainConfig struct {
ECIP1080Transition *big.Int `json:"-"`

// Cache types for use with testing, but will not show up in config API.
ecbp1100Transition *big.Int
ecbp1100Transition *big.Int
ecbp1100DisableTransition *big.Int

Lyra2NonceTransitionBlock *big.Int `json:"lyra2NonceTransitionBlock,omitempty"`
}
Expand Down
19 changes: 19 additions & 0 deletions params/types/goethereum/goethereum_configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package goethereum

import (
"math/big"
"reflect"
"runtime"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params/types/ctypes"
Expand Down Expand Up @@ -449,6 +452,15 @@ func (c *ChainConfig) SetECBP1100Transition(n *uint64) error {
return nil
}

func (c *ChainConfig) GetECBP1100DisableTransition() *uint64 {
return bigNewU64(c.ecbp1100DisableTransition)
}

func (c *ChainConfig) SetECBP1100DisableTransition(n *uint64) error {
c.ecbp1100DisableTransition = setBig(c.ecbp1100DisableTransition, n)
return nil
}

// GetEIP2315Transition implements EIP2537.
// This logic is written but not configured for any Ethereum-supported networks, yet.
func (c *ChainConfig) GetEIP2315Transition() *uint64 {
Expand Down Expand Up @@ -691,6 +703,13 @@ func (c *ChainConfig) IsEnabled(fn func() *uint64, n *big.Int) bool {
if f == nil || n == nil {
return false
}
fnName := runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
if strings.Contains(fnName, "ECBP1100Transition") {
disabledTransition := c.GetECBP1100DisableTransition()
if disabledTransition != nil {
return big.NewInt(int64(*disabledTransition)).Cmp(n) > 0 && big.NewInt(int64(*f)).Cmp(n) <= 0
}
}
return big.NewInt(int64(*f)).Cmp(n) <= 0
}

Expand Down
Loading