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 @@ -179,6 +179,11 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
cfg.Eth.ECBP1100NoDisable = &enable
}
}
if ctx.IsSet(utils.OverrideECBP1100DeactivateFlag.Name) {
if n := ctx.Uint64(utils.OverrideECBP1100DeactivateFlag.Name); n != math.MaxUint64 {
cfg.Eth.OverrideECBP1100Deactivate = new(big.Int).SetUint64(n)
}
}
if ctx.IsSet(utils.OverrideShanghai.Name) {
v := ctx.Uint64(utils.OverrideShanghai.Name)
cfg.Eth.OverrideShanghai = &v
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.OverrideECBP1100DeactivateFlag,
configFileFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags)

Expand Down
17 changes: 12 additions & 5 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,13 +1064,19 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Value: "",
}
ECBP1100Flag = &cli.Uint64Flag{
Name: "ecbp1100",
Usage: "Configure ECBP-1100 (MESS) block activation number",
Value: math.MaxUint64,
Name: "ecbp1100", // should have been override.ecbp1100, but maintained now for backwards compatibility
Usage: "Manually specify the ECBP-1100 (MESS) block activation number, overriding the bundled setting",
Category: flags.EthCategory,
}
OverrideECBP1100DeactivateFlag = &cli.Uint64Flag{
Name: "override.ecbp1100.deactivate",
Usage: "Manually specify the ECBP-1100 (MESS) deactivation block number, overriding the bundled setting",
Category: flags.EthCategory,
}
ECBP1100NoDisableFlag = &cli.BoolFlag{
Name: "ecbp1100.nodisable",
Usage: "Short-circuit ECBP-1100 (MESS) disable mechanisms; (yields a permanent-once-activated state, deactivating auto-shutoff mechanisms)",
Name: "ecbp1100.nodisable",
Usage: "Short-circuit ECBP-1100 (MESS) disable mechanisms; (yields a permanent-once-activated state, deactivating auto-shutoff mechanisms)",
Category: flags.DeprecatedCategory,
}

MetricsEnableInfluxDBV2Flag = &cli.BoolFlag{
Expand Down Expand Up @@ -2081,6 +2087,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.EthDiscoveryURLs = SplitAndTrim(urls)
}
}

// Override any default configs for hard coded networks.

// Override genesis configuration if a --<chain> flag.
Expand Down
24 changes: 23 additions & 1 deletion core/blockchain_af.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,31 @@ var errReorgFinality = errors.New("finality-enforced invalid new chain")
// n = 1 : ON
// n != 1 : OFF
func (bc *BlockChain) ArtificialFinalityNoDisable(n int32) {
log.Warn("Deactivating ECBP1100 (MESS) disablers", "always on", true)
log.Warn("Deactivating ECBP1100 (MESS) safety mechanisms", "always on", true)
bc.artificialFinalityNoDisable = new(int32)
atomic.StoreInt32(bc.artificialFinalityNoDisable, n)

if n == 1 {
deactivateTransition := bc.chainConfig.GetECBP1100DeactivateTransition()
if deactivateTransition != nil && big.NewInt(int64(*deactivateTransition)).Cmp(big.NewInt(0)) > 0 {
// Log the activation block as well as the deactivation block.
// Context is nice to have for the user.
var logActivationBlock uint64
logActivationBlockRaw := bc.chainConfig.GetECBP1100Transition()
if logActivationBlockRaw == nil {
// panic("impossible")
logActivationBlock = *deactivateTransition
} else {
logActivationBlock = *logActivationBlockRaw
}

log.Warn(`Deactivate-ECBP1100 (MESS) block activation number is set together with '--ecbp1100.nodisable'.
The --ecbp1100.nodisable feature prevents the toggling of ECBP1100 (MESS) artificial finality with its safety mechanisms of low peer count and stale head.
ECBP1100 (MESS) is scheduled for network-wide deactivation, rendering the --ecbp1100.nodisable feature anachronistic.
`, "ECBP1100 activation block", logActivationBlock,
"ECBP1100 deactivation block", *deactivateTransition)
}
}
}

// EnableArtificialFinality enables and disable artificial finality features for the blockchain.
Expand Down
17 changes: 11 additions & 6 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package eth
import (
"errors"
"fmt"
"math"
"math/big"
"runtime"
"sync"
Expand Down Expand Up @@ -231,13 +230,19 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}
eth.bloomIndexer.Start(eth.blockchain)
// Handle artificial finality config override cases.
if config.ECBP1100 != nil {
if n := config.ECBP1100.Uint64(); n != math.MaxUint64 {
if err := eth.blockchain.Config().SetECBP1100Transition(&n); err != nil {
return nil, err
}
if n := config.ECBP1100; n != nil {
v := n.Uint64()
if err := eth.blockchain.Config().SetECBP1100Transition(&v); err != nil {
return nil, err
}
}
if n := config.OverrideECBP1100Deactivate; n != nil {
v := n.Uint64()
if err := eth.blockchain.Config().SetECBP1100DeactivateTransition(&v); 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.
OverrideECBP1100Deactivate *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
ECBP1100DeactivateFBlock: big.NewInt(19_250_000), // ETA 31 Jan 2023 (== Spiral hard fork)
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
ECBP1100DeactivateFBlock *big.Int `json:"ecbp1100DeactivateFBlockFBlock,omitempty"` // Deactivate ECBP1100:MESS artificial finality

// 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) GetECBP1100DeactivateTransition() *uint64 {
return bigNewU64(c.ECBP1100DeactivateFBlock)
}

func (c *CoreGethChainConfig) SetECBP1100DeactivateTransition(n *uint64) error {
c.ECBP1100DeactivateFBlock = setBig(c.ECBP1100DeactivateFBlock, 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") {
deactivateTransition := c.GetECBP1100DeactivateTransition()
if deactivateTransition != nil {
return big.NewInt(int64(*deactivateTransition)).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_ECBP1100Deactivate(t *testing.T) {
var _testConfig = &CoreGethChainConfig{}
*_testConfig = *testConfig

activate := uint64(100)
deactivate := uint64(200)
_testConfig.SetECBP1100Transition(&activate)
_testConfig.SetECBP1100DeactivateTransition(&deactivate)

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

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

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

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

n = uint64(210)
bigN = new(big.Int).SetUint64(n)
if _testConfig.IsEnabled(_testConfig.GetECBP1100Transition, bigN) {
t.Errorf("ECBP1100 should be deactivated 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
GetECBP1100DeactivateTransition() *uint64
SetECBP1100DeactivateTransition(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) GetECBP1100DeactivateTransition() *uint64 {
return g.Config.GetECBP1100DeactivateTransition()
}

func (g *Genesis) SetECBP1100DeactivateTransition(n *uint64) error {
return g.Config.SetECBP1100DeactivateTransition(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
ecbp1100DeactivateTransition *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) GetECBP1100DeactivateTransition() *uint64 {
return bigNewU64(c.ecbp1100DeactivateTransition)
}

func (c *ChainConfig) SetECBP1100DeactivateTransition(n *uint64) error {
c.ecbp1100DeactivateTransition = setBig(c.ecbp1100DeactivateTransition, 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") {
deactivateTransition := c.GetECBP1100DeactivateTransition()
if deactivateTransition != nil {
return big.NewInt(int64(*deactivateTransition)).Cmp(n) > 0 && big.NewInt(int64(*f)).Cmp(n) <= 0
}
}
return big.NewInt(int64(*f)).Cmp(n) <= 0
}

Expand Down
Loading