|
|
|
@ -3,6 +3,7 @@ package params |
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"math/big" |
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
|
) |
|
|
|
@ -16,16 +17,27 @@ var ( |
|
|
|
|
StressnetChainID = big.NewInt(5) |
|
|
|
|
TestChainID = big.NewInt(99) // not a real network
|
|
|
|
|
AllProtocolChangesChainID = big.NewInt(100) // not a real network
|
|
|
|
|
|
|
|
|
|
// EthMainnetChainID to be reserved unique chain ID for eth compatible chains.
|
|
|
|
|
EthMainnetChainID = big.NewInt(1666600000) |
|
|
|
|
EthTestnetChainID = big.NewInt(1666700000) |
|
|
|
|
EthPangaeaChainID = big.NewInt(1666800000) |
|
|
|
|
EthPartnerChainID = big.NewInt(1666900000) |
|
|
|
|
EthStressnetChainID = big.NewInt(1661000000) |
|
|
|
|
EthTestChainID = big.NewInt(1661100000) // not a real network
|
|
|
|
|
EthAllProtocolChangesChainID = big.NewInt(1661200000) // not a real network
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// EpochTBD is a large, “not anytime soon” epoch. It used as a placeholder
|
|
|
|
|
// until the exact epoch is decided.
|
|
|
|
|
var EpochTBD = big.NewInt(10000000) |
|
|
|
|
var once sync.Once |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
// MainnetChainConfig is the chain parameters to run a node on the main network.
|
|
|
|
|
MainnetChainConfig = &ChainConfig{ |
|
|
|
|
ChainID: MainnetChainID, |
|
|
|
|
EthCompatibleChainID: EthMainnetChainID, |
|
|
|
|
CrossTxEpoch: big.NewInt(28), |
|
|
|
|
CrossLinkEpoch: big.NewInt(186), |
|
|
|
|
StakingEpoch: big.NewInt(186), |
|
|
|
@ -43,6 +55,7 @@ var ( |
|
|
|
|
// TestnetChainConfig contains the chain parameters to run a node on the harmony test network.
|
|
|
|
|
TestnetChainConfig = &ChainConfig{ |
|
|
|
|
ChainID: TestnetChainID, |
|
|
|
|
EthCompatibleChainID: EthTestnetChainID, |
|
|
|
|
CrossTxEpoch: big.NewInt(0), |
|
|
|
|
CrossLinkEpoch: big.NewInt(2), |
|
|
|
|
StakingEpoch: big.NewInt(2), |
|
|
|
@ -61,6 +74,7 @@ var ( |
|
|
|
|
// All features except for CrossLink are enabled at launch.
|
|
|
|
|
PangaeaChainConfig = &ChainConfig{ |
|
|
|
|
ChainID: PangaeaChainID, |
|
|
|
|
EthCompatibleChainID: EthPangaeaChainID, |
|
|
|
|
CrossTxEpoch: big.NewInt(0), |
|
|
|
|
CrossLinkEpoch: big.NewInt(2), |
|
|
|
|
StakingEpoch: big.NewInt(2), |
|
|
|
@ -79,6 +93,7 @@ var ( |
|
|
|
|
// All features except for CrossLink are enabled at launch.
|
|
|
|
|
PartnerChainConfig = &ChainConfig{ |
|
|
|
|
ChainID: PartnerChainID, |
|
|
|
|
EthCompatibleChainID: EthPartnerChainID, |
|
|
|
|
CrossTxEpoch: big.NewInt(0), |
|
|
|
|
CrossLinkEpoch: big.NewInt(2), |
|
|
|
|
StakingEpoch: big.NewInt(2), |
|
|
|
@ -97,6 +112,7 @@ var ( |
|
|
|
|
// All features except for CrossLink are enabled at launch.
|
|
|
|
|
StressnetChainConfig = &ChainConfig{ |
|
|
|
|
ChainID: StressnetChainID, |
|
|
|
|
EthCompatibleChainID: EthStressnetChainID, |
|
|
|
|
CrossTxEpoch: big.NewInt(0), |
|
|
|
|
CrossLinkEpoch: big.NewInt(2), |
|
|
|
|
StakingEpoch: big.NewInt(2), |
|
|
|
@ -114,6 +130,7 @@ var ( |
|
|
|
|
// LocalnetChainConfig contains the chain parameters to run for local development.
|
|
|
|
|
LocalnetChainConfig = &ChainConfig{ |
|
|
|
|
ChainID: TestnetChainID, |
|
|
|
|
EthCompatibleChainID: EthTestnetChainID, |
|
|
|
|
CrossTxEpoch: big.NewInt(0), |
|
|
|
|
CrossLinkEpoch: big.NewInt(2), |
|
|
|
|
StakingEpoch: big.NewInt(2), |
|
|
|
@ -133,6 +150,7 @@ var ( |
|
|
|
|
// adding flags to the config to also have to set these fields.
|
|
|
|
|
AllProtocolChanges = &ChainConfig{ |
|
|
|
|
AllProtocolChangesChainID, // ChainID
|
|
|
|
|
EthAllProtocolChangesChainID, // EthCompatibleChainID
|
|
|
|
|
big.NewInt(0), // CrossTxEpoch
|
|
|
|
|
big.NewInt(0), // CrossLinkEpoch
|
|
|
|
|
big.NewInt(0), // StakingEpoch
|
|
|
|
@ -152,6 +170,7 @@ var ( |
|
|
|
|
// adding flags to the config to also have to set these fields.
|
|
|
|
|
TestChainConfig = &ChainConfig{ |
|
|
|
|
TestChainID, // ChainID
|
|
|
|
|
EthTestChainID, // EthCompatibleChainID
|
|
|
|
|
big.NewInt(0), // CrossTxEpoch
|
|
|
|
|
big.NewInt(0), // CrossLinkEpoch
|
|
|
|
|
big.NewInt(0), // StakingEpoch
|
|
|
|
@ -191,6 +210,9 @@ type ChainConfig struct { |
|
|
|
|
// ChainId identifies the current chain and is used for replay protection
|
|
|
|
|
ChainID *big.Int `json:"chain-id"` |
|
|
|
|
|
|
|
|
|
// EthCompatibleChainID identifies the chain id used for ethereum compatible transactions
|
|
|
|
|
EthCompatibleChainID *big.Int `json:"eth-compatible-chain-id"` |
|
|
|
|
|
|
|
|
|
// CrossTxEpoch is the epoch where cross-shard transaction starts being
|
|
|
|
|
// processed.
|
|
|
|
|
CrossTxEpoch *big.Int `json:"cross-tx-epoch,omitempty"` |
|
|
|
@ -235,8 +257,9 @@ type ChainConfig struct { |
|
|
|
|
|
|
|
|
|
// String implements the fmt.Stringer interface.
|
|
|
|
|
func (c *ChainConfig) String() string { |
|
|
|
|
return fmt.Sprintf("{ChainID: %v EIP155: %v CrossTx: %v Staking: %v CrossLink: %v ReceiptLog: %v}", |
|
|
|
|
return fmt.Sprintf("{ChainID: %v EthCompatibleChainID: %v EIP155: %v CrossTx: %v Staking: %v CrossLink: %v ReceiptLog: %v}", |
|
|
|
|
c.ChainID, |
|
|
|
|
c.EthCompatibleChainID, |
|
|
|
|
c.EIP155Epoch, |
|
|
|
|
c.CrossTxEpoch, |
|
|
|
|
c.StakingEpoch, |
|
|
|
@ -320,6 +343,25 @@ func (c *ChainConfig) IsReceiptLog(epoch *big.Int) bool { |
|
|
|
|
return isForked(c.ReceiptLogEpoch, epoch) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// UpdateEthChainIDByShard update the ethChainID based on shard ID.
|
|
|
|
|
func UpdateEthChainIDByShard(shardID uint32) { |
|
|
|
|
once.Do(func() { |
|
|
|
|
MainnetChainConfig.EthCompatibleChainID.Add(MainnetChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID))) |
|
|
|
|
TestnetChainConfig.EthCompatibleChainID.Add(TestnetChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID))) |
|
|
|
|
PangaeaChainConfig.EthCompatibleChainID.Add(PangaeaChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID))) |
|
|
|
|
PartnerChainConfig.EthCompatibleChainID.Add(PartnerChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID))) |
|
|
|
|
StressnetChainConfig.EthCompatibleChainID.Add(StressnetChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID))) |
|
|
|
|
LocalnetChainConfig.EthCompatibleChainID.Add(LocalnetChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID))) |
|
|
|
|
AllProtocolChanges.EthCompatibleChainID.Add(AllProtocolChanges.EthCompatibleChainID, big.NewInt(int64(shardID))) |
|
|
|
|
TestChainConfig.EthCompatibleChainID.Add(TestChainConfig.EthCompatibleChainID, big.NewInt(int64(shardID))) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// IsEthCompatible returns whether the chainID is for ethereum compatible txn or not
|
|
|
|
|
func IsEthCompatible(chainID *big.Int) bool { |
|
|
|
|
return chainID.Cmp(EthMainnetChainID) >= 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice).
|
|
|
|
|
//
|
|
|
|
|
// The returned GasTable's fields shouldn't, under any circumstances, be changed.
|
|
|
|
@ -350,6 +392,7 @@ func isForked(s, epoch *big.Int) bool { |
|
|
|
|
// phases.
|
|
|
|
|
type Rules struct { |
|
|
|
|
ChainID *big.Int |
|
|
|
|
EthChainID *big.Int |
|
|
|
|
IsCrossLink, IsEIP155, IsS3, IsReceiptLog, IsIstanbul bool |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -359,8 +402,13 @@ func (c *ChainConfig) Rules(epoch *big.Int) Rules { |
|
|
|
|
if chainID == nil { |
|
|
|
|
chainID = new(big.Int) |
|
|
|
|
} |
|
|
|
|
ethChainID := c.EthCompatibleChainID |
|
|
|
|
if ethChainID == nil { |
|
|
|
|
ethChainID = new(big.Int) |
|
|
|
|
} |
|
|
|
|
return Rules{ |
|
|
|
|
ChainID: new(big.Int).Set(chainID), |
|
|
|
|
EthChainID: new(big.Int).Set(ethChainID), |
|
|
|
|
IsCrossLink: c.IsCrossLink(epoch), |
|
|
|
|
IsEIP155: c.IsEIP155(epoch), |
|
|
|
|
IsS3: c.IsS3(epoch), |
|
|
|
|