Skip to content

core/blockchain_mess.go — Version Comparison

v1.16.8 v1.17.3
Branch etc/v1.16.8-full-node etc/v1.17.3-full-node
Delta +261 -0 +270 -0

Diff between branches

diff --git a/core/blockchain_mess.go b/core/blockchain_mess.go
index 37fd245be..58c49dab2 100644
--- a/core/blockchain_mess.go
+++ b/core/blockchain_mess.go
@@ -21,7 +21,6 @@ import (
    "fmt"
    "math"
    "math/big"
-   "sync/atomic"
    "time"

    "github.com/ethereum/go-ethereum/common"
@@ -51,30 +50,27 @@ var (
    messHeight = new(big.Int).Mul(new(big.Int).Mul(messCurveFunctionDenominator, messAmpl), big2)
 )

-// messEnabledStatus holds the current MESS activation status (atomic).
-// 0 = disabled, 1 = enabled
-var messEnabledStatus atomic.Int32
-
-// EnableMESS enables or disables MESS artificial finality for the blockchain.
+// EnableMESS enables or disables MESS artificial finality for this blockchain.
 // This is controlled dynamically by the sync process based on network conditions.
-// The method is idempotent.
+// The state is per-BlockChain (bc.messEnabled), so separate chains/tests in the same
+// process don't affect each other. The method is idempotent.
 func (bc *BlockChain) EnableMESS(enable bool, reason string) {
    var statusLog string
    if enable {
        statusLog = "enabled"
-       messEnabledStatus.Store(1)
+       bc.messEnabled.Store(1)
    } else {
        statusLog = "disabled"
-       messEnabledStatus.Store(0)
+       bc.messEnabled.Store(0)
    }
    log.Info("MESS artificial finality "+statusLog, "reason", reason)
 }

-// IsMESSEnabled returns the current MESS activation status.
+// IsMESSEnabled returns the current MESS activation status for this blockchain.
 // This status is independent of chain config activation - it reflects
 // the dynamic runtime state controlled by the sync process.
 func (bc *BlockChain) IsMESSEnabled() bool {
-   return messEnabledStatus.Load() == 1
+   return bc.messEnabled.Load() == 1
 }

 // ecbp1100 implements the "MESS" artificial finality mechanism.
@@ -253,9 +249,22 @@ func NewForkChoiceWithMESS(bc *BlockChain, preserve func(header *types.Header) b
        }
        commonAncestor, err := bc.findCommonAncestor(current, extern)
        if err != nil || commonAncestor == nil {
-           return nil
+           // Fail closed: MESS is an artificial-finality guard, so a reorg we cannot
+           // verify (no common ancestor, or a missing header) must be rejected, not
+           // silently allowed. core-geth propagates this error in the equivalent path
+           // (core/forkchoice.go); allowing the reorg here would bypass MESS exactly
+           // in the anomalous case where it should act.
+           if err == nil {
+               err = errors.New("no common ancestor")
+           }
+           log.Warn("MESS: rejecting unverifiable reorg", "current", current.Number, "proposed", extern.Number, "err", err)
+           return fmt.Errorf("MESS: cannot verify reorg: %w", err)
+       }
+       if err := ecbp1100(commonAncestor, current, extern, bc.GetTd); err != nil {
+           log.Warn("MESS: reorg disallowed", "common", commonAncestor.Number, "current", current.Number, "proposed", extern.Number, "err", err)
+           return err
        }
-       return ecbp1100(commonAncestor, current, extern, bc.GetTd)
+       return nil
    }
    return f
 }
← Back to Version Comparison