github.com/dominant-strategies/go-quai@v0.28.2/params/config.go (about)

     1  // Cojyright 2016 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package params
    18  
    19  import (
    20  	"fmt"
    21  	"math/big"
    22  
    23  	"github.com/dominant-strategies/go-quai/common"
    24  )
    25  
    26  // Genesis hashes to enforce below configs on.
    27  var (
    28  	// Progpow GenesisHashes
    29  	ProgpowColosseumGenesisHash  = common.HexToHash("0xcdaaf48cc057d97a14acbe76ce5a6e1ab377049059c74416cdfb0c6fd5d0b058")
    30  	ProgpowGardenGenesisHash     = common.HexToHash("0x7823e58617576af80cc557595380b55c2d565b294e3b6438fc11c4410e48da5e")
    31  	ProgpowOrchardGenesisHash    = common.HexToHash("0x4042b03aa7c4d6a58d4e6238b2da5c03dda97a0c7e7a7b1d237917a23ca4b0d6")
    32  	ProgpowLocalGenesisHash      = common.HexToHash("0x53a10194f6b385aa037fe1911b52a56d4d0ac8f95f3e98ac4f546269429c288d")
    33  	ProgpowLighthouseGenesisHash = common.HexToHash("0x888542dc6e379e29db4c86934b05cfd4a376e1c19261db3f44d6e4e9f6ce0495")
    34  
    35  	// Blake3GenesisHashes
    36  	Blake3PowColosseumGenesisHash  = common.HexToHash("0x40057f44be0809f939c7d70893d101abc74af1f1c535e406ec9909cfa2c20cbe")
    37  	Blake3PowGardenGenesisHash     = common.HexToHash("0x0a942bb7fa04b80d658a64d0ca49c62199503a796abc169f05a1863421a22098")
    38  	Blake3PowOrchardGenesisHash    = common.HexToHash("0x1f3743c323ec7a9a6a8150a33de81723abb70fa10ad49c35e365e48488430b56")
    39  	Blake3PowLocalGenesisHash      = common.HexToHash("0x31ac78ff6abcd99ad1fd8cd1b8ef54cfb28bdc72f7a38311e67a9e34fc2adb45")
    40  	Blake3PowLighthouseGenesisHash = common.HexToHash("0xaadedd7ed5a68a8885b54079e8193ae5be8f9b9bf4799ea9f1612bca835f33da")
    41  )
    42  
    43  var (
    44  	// ColosseumChainConfig is the chain parameters to run a node on the Colosseum network.
    45  	ProgpowColosseumChainConfig = &ChainConfig{
    46  		ChainID:     big.NewInt(9000),
    47  		Progpow:     new(ProgpowConfig),
    48  		GenesisHash: ProgpowColosseumGenesisHash,
    49  	}
    50  
    51  	Blake3PowColosseumChainConfig = &ChainConfig{
    52  		ChainID:     big.NewInt(9000),
    53  		Blake3Pow:   new(Blake3powConfig),
    54  		GenesisHash: Blake3PowColosseumGenesisHash,
    55  	}
    56  
    57  	// GardenChainConfig contains the chain parameters to run a node on the Garden test network.
    58  	ProgpowGardenChainConfig = &ChainConfig{
    59  		ChainID:     big.NewInt(12000),
    60  		Progpow:     new(ProgpowConfig),
    61  		GenesisHash: ProgpowGardenGenesisHash,
    62  	}
    63  
    64  	Blake3PowGardenChainConfig = &ChainConfig{
    65  		ChainID:     big.NewInt(12000),
    66  		Blake3Pow:   new(Blake3powConfig),
    67  		GenesisHash: Blake3PowGardenGenesisHash,
    68  	}
    69  
    70  	// OrchardChainConfig contains the chain parameters to run a node on the Orchard test network.
    71  	ProgpowOrchardChainConfig = &ChainConfig{
    72  		ChainID:     big.NewInt(15000),
    73  		Progpow:     new(ProgpowConfig),
    74  		GenesisHash: ProgpowOrchardGenesisHash,
    75  	}
    76  
    77  	Blake3PowOrchardChainConfig = &ChainConfig{
    78  		ChainID:     big.NewInt(15000),
    79  		Blake3Pow:   new(Blake3powConfig),
    80  		GenesisHash: Blake3PowOrchardGenesisHash,
    81  	}
    82  
    83  	// LighthouseChainConfig contains the chain parameters to run a node on the Lighthouse test network.
    84  	ProgpowLighthouseChainConfig = &ChainConfig{
    85  		ChainID:     big.NewInt(17000),
    86  		Blake3Pow:   new(Blake3powConfig),
    87  		Progpow:     new(ProgpowConfig),
    88  		GenesisHash: ProgpowLighthouseGenesisHash,
    89  	}
    90  
    91  	Blake3PowLighthouseChainConfig = &ChainConfig{
    92  		ChainID:     big.NewInt(17000),
    93  		Blake3Pow:   new(Blake3powConfig),
    94  		GenesisHash: Blake3PowLighthouseGenesisHash,
    95  	}
    96  
    97  	// LocalChainConfig contains the chain parameters to run a node on the Local test network.
    98  	ProgpowLocalChainConfig = &ChainConfig{
    99  		ChainID:     big.NewInt(1337),
   100  		Progpow:     new(ProgpowConfig),
   101  		GenesisHash: ProgpowLocalGenesisHash,
   102  	}
   103  
   104  	Blake3PowLocalChainConfig = &ChainConfig{
   105  		ChainID:     big.NewInt(1337),
   106  		Blake3Pow:   new(Blake3powConfig),
   107  		GenesisHash: Blake3PowLocalGenesisHash,
   108  	}
   109  
   110  	// AllProgpowProtocolChanges contains every protocol change introduced
   111  	// and accepted by the Quai core developers into the Progpow consensus.
   112  	//
   113  	// This configuration is intentionally not using keyed fields to force anyone
   114  	// adding flags to the config to also have to set these fields.
   115  	AllProgpowProtocolChanges = &ChainConfig{big.NewInt(1337), "progpow", new(Blake3powConfig), new(ProgpowConfig), common.Hash{}, common.NodeLocation}
   116  
   117  	TestChainConfig = &ChainConfig{big.NewInt(1), "progpow", new(Blake3powConfig), new(ProgpowConfig), common.Hash{}, common.NodeLocation}
   118  	TestRules       = TestChainConfig.Rules(new(big.Int))
   119  )
   120  
   121  // ChainConfig is the core config which determines the blockchain settings.
   122  //
   123  // ChainConfig is stored in the database on a per block basis. This means
   124  // that any network, identified by its genesis block, can have its own
   125  // set of configuration options.
   126  type ChainConfig struct {
   127  	ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection
   128  	// Various consensus engines
   129  	ConsensusEngine string
   130  	Blake3Pow       *Blake3powConfig `json:"blake3pow,omitempty"`
   131  	Progpow         *ProgpowConfig   `json:"progpow,omitempty"`
   132  	GenesisHash     common.Hash
   133  	Location        common.Location
   134  }
   135  
   136  // SetLocation sets the location on the chain config
   137  func (cfg *ChainConfig) SetLocation(location common.Location) {
   138  	cfg.Location = location
   139  }
   140  
   141  // Blake3powConfig is the consensus engine configs for proof-of-work based sealing.
   142  type Blake3powConfig struct{}
   143  
   144  // String implements the stringer interface, returning the consensus engine details.
   145  func (c *Blake3powConfig) String() string {
   146  	return "blake3pow"
   147  }
   148  
   149  // ProgpowConfig is the consensus engine configs for proof-of-work based sealing.
   150  type ProgpowConfig struct{}
   151  
   152  // String implements the stringer interface, returning the consensus engine details.
   153  func (c *ProgpowConfig) String() string {
   154  	return "progpow"
   155  }
   156  
   157  // String implements the fmt.Stringer interface.
   158  func (c *ChainConfig) String() string {
   159  	var engine interface{}
   160  	switch {
   161  	case c.Blake3Pow != nil:
   162  		engine = c.Blake3Pow
   163  	case c.Progpow != nil:
   164  		engine = c.Progpow
   165  	default:
   166  		engine = "unknown"
   167  	}
   168  	return fmt.Sprintf("{ChainID: %v, Engine: %v, Location: %v}",
   169  		c.ChainID,
   170  		engine,
   171  		c.Location,
   172  	)
   173  }
   174  
   175  func configNumEqual(x, y *big.Int) bool {
   176  	if x == nil {
   177  		return y == nil
   178  	}
   179  	if y == nil {
   180  		return x == nil
   181  	}
   182  	return x.Cmp(y) == 0
   183  }
   184  
   185  // ConfigCompatError is raised if the locally-stored blockchain is initialised with a
   186  // ChainConfig that would alter the past.
   187  type ConfigCompatError struct {
   188  	What string
   189  	// block numbers of the stored and new configurations
   190  	StoredConfig, NewConfig *big.Int
   191  	// the block number to which the local chain must be rewound to correct the error
   192  	RewindTo uint64
   193  }
   194  
   195  func newCompatError(what string, storedblock, newblock *big.Int) *ConfigCompatError {
   196  	var rew *big.Int
   197  	switch {
   198  	case storedblock == nil:
   199  		rew = newblock
   200  	case newblock == nil || storedblock.Cmp(newblock) < 0:
   201  		rew = storedblock
   202  	default:
   203  		rew = newblock
   204  	}
   205  	err := &ConfigCompatError{what, storedblock, newblock, 0}
   206  	if rew != nil && rew.Sign() > 0 {
   207  		err.RewindTo = rew.Uint64() - 1
   208  	}
   209  	return err
   210  }
   211  
   212  func (err *ConfigCompatError) Error() string {
   213  	return fmt.Sprintf("mismatching %s in database (have %d, want %d, rewindto %d)", err.What, err.StoredConfig, err.NewConfig, err.RewindTo)
   214  }
   215  
   216  // Rules wraps ChainConfig and is merely syntactic sugar or can be used for functions
   217  // that do not have or require information about the block.
   218  //
   219  // Rules is a one time interface meaning that it shouldn't be used in between transition
   220  // phases.
   221  type Rules struct {
   222  	ChainID *big.Int
   223  }
   224  
   225  // Rules ensures c's ChainID is not nil.
   226  func (c *ChainConfig) Rules(num *big.Int) Rules {
   227  	chainID := c.ChainID
   228  	if chainID == nil {
   229  		chainID = new(big.Int)
   230  	}
   231  	return Rules{
   232  		ChainID: new(big.Int).Set(chainID),
   233  	}
   234  }