This commit is contained in:
powman 2023-10-29 22:40:54 -03:00
parent e7560963de
commit d2c6766611
24 changed files with 51 additions and 448 deletions

View file

@ -229,12 +229,8 @@ func ethFilter(args []string) (nodeFilter, error) {
switch args[0] {
case "mainnet":
filter = forkid.NewStaticFilter(params.MainnetChainConfig, params.MainnetGenesisHash)
case "PulseChain":
filter = forkid.NewStaticFilter(params.PulseChainConfig, params.MainnetGenesisHash)
case "WhaleChain":
filter = forkid.NewStaticFilter(params.WhaleChainConfig, params.MainnetGenesisHash)
case "PulseChainTestnetV4":
filter = forkid.NewStaticFilter(params.PulseChainTestnetV4Config, params.MainnetGenesisHash)
case "WhaleChainTestnetV4":
filter = forkid.NewStaticFilter(params.WhaleChainTestnetV4Config, params.MainnetGenesisHash)
case "goerli":

View file

@ -266,8 +266,6 @@ func main() {
func prepare(ctx *cli.Context) {
// If we're running a known preset, log it for convenience.
switch {
case ctx.IsSet(utils.PulseChainFlag.Name):
log.Info("Starting Geth on PulseChain mainnet...")
case ctx.IsSet(utils.WhaleChainFlag.Name):
log.Info("Starting Geth on WhaleChain mainnet...")
@ -278,9 +276,6 @@ func prepare(ctx *cli.Context) {
case ctx.IsSet(utils.SepoliaFlag.Name):
log.Info("Starting Geth on Sepolia testnet...")
case ctx.IsSet(utils.PulseChainTestnetV4Flag.Name):
log.Info("Starting Geth on PulseChain Testnet V4...")
case ctx.IsSet(utils.WhaleChainTestnetV4Flag.Name):
log.Info("Starting Geth on WhaleChain Testnet V4...")
@ -311,7 +306,7 @@ func prepare(ctx *cli.Context) {
if !ctx.IsSet(utils.SepoliaFlag.Name) &&
!ctx.IsSet(utils.GoerliFlag.Name) &&
!ctx.IsSet(utils.DeveloperFlag.Name) {
// Nope, we're really on mainnet or PulseChain. Bump that cache up!
// Nope, we're really on mainnet or WhaleChain. Bump that cache up!
log.Info("Bumping default cache on mainnet", "provided", ctx.Int(utils.CacheFlag.Name), "updated", 4096)
ctx.Set(utils.CacheFlag.Name, strconv.Itoa(4096))
}

View file

@ -945,13 +945,11 @@ var (
TestnetFlags = []cli.Flag{
GoerliFlag,
SepoliaFlag,
PulseChainTestnetV4Flag,
WhaleChainTestnetV4Flag,
}
// NetworkFlags is the flag group of all built-in supported networks.
NetworkFlags = append([]cli.Flag{
MainnetFlag,
PulseChainFlag,
WhaleChainFlag,
}, TestnetFlags...)
@ -1033,16 +1031,12 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
switch {
case ctx.IsSet(BootnodesFlag.Name):
urls = SplitAndTrim(ctx.String(BootnodesFlag.Name))
case ctx.Bool(PulseChainFlag.Name):
urls = params.PulseChainBootnodes
case ctx.Bool(WhaleChainFlag.Name):
urls = params.WhaleChainBootnodes
case ctx.Bool(SepoliaFlag.Name):
urls = params.SepoliaBootnodes
case ctx.Bool(GoerliFlag.Name):
urls = params.GoerliBootnodes
case ctx.Bool(PulseChainTestnetV4Flag.Name):
urls = params.PulseChainTestnetV4Bootnodes
case ctx.Bool(WhaleChainTestnetV4Flag.Name):
urls = params.WhaleChainTestnetV4Bootnodes
}
@ -1653,7 +1647,7 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
// SetEthConfig applies eth-related command line flags to the config.
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
// Avoid conflicting network flags
CheckExclusive(ctx, MainnetFlag, PulseChainFlag, WhaleChainFlag, DeveloperFlag, GoerliFlag, SepoliaFlag, PulseChainTestnetV4Flag, WhaleChainTestnetV4Flag)
CheckExclusive(ctx, MainnetFlag, WhaleChainFlag, DeveloperFlag, GoerliFlag, SepoliaFlag, WhaleChainTestnetV4Flag)
CheckExclusive(ctx, LightServeFlag, SyncModeFlag, "light")
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
if ctx.String(GCModeFlag.Name) == "archive" && ctx.Uint64(TxLookupLimitFlag.Name) != 0 {
@ -1783,12 +1777,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
cfg.Genesis = core.DefaultGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
case ctx.Bool(PulseChainFlag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 369
}
cfg.Genesis = core.DefaultPulseChainGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
case ctx.Bool(WhaleChainFlag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 370
@ -1807,12 +1795,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
cfg.Genesis = core.DefaultGoerliGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.GoerliGenesisHash)
case ctx.Bool(PulseChainTestnetV4Flag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 943
}
cfg.Genesis = core.DefaultPulseChainTestnetV4GenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
case ctx.Bool(WhaleChainTestnetV4Flag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 944
@ -2135,16 +2117,12 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis {
switch {
case ctx.Bool(MainnetFlag.Name):
genesis = core.DefaultGenesisBlock()
case ctx.Bool(PulseChainFlag.Name):
genesis = core.DefaultPulseChainGenesisBlock()
case ctx.Bool(WhaleChainFlag.Name):
genesis = core.DefaultWhaleChainGenesisBlock()
case ctx.Bool(SepoliaFlag.Name):
genesis = core.DefaultSepoliaGenesisBlock()
case ctx.Bool(GoerliFlag.Name):
genesis = core.DefaultGoerliGenesisBlock()
case ctx.Bool(PulseChainTestnetV4Flag.Name):
genesis = core.DefaultPulseChainTestnetV4GenesisBlock()
case ctx.Bool(WhaleChainTestnetV4Flag.Name):
genesis = core.DefaultWhaleChainTestnetV4GenesisBlock()
case ctx.Bool(DeveloperFlag.Name):

View file

@ -131,9 +131,9 @@ func (beacon *Beacon) splitHeaders(chain consensus.ChainHeaderReader, headers []
postHeaders []*types.Header
)
for i, header := range headers {
// PulseChain Special Case:
// WhaleChain Special Case:
// Partition based on header difficulty (IsPoSHeader) instead of TTD being reached
// so we can properly handle ETH Beacon blocks below the increased PulseChain TTD.
// so we can properly handle ETH Beacon blocks below the increased WhaleChain TTD.
if beacon.IsPoSHeader(header) {
preHeaders = headers[:i]
postHeaders = headers[i:]
@ -153,7 +153,7 @@ func (beacon *Beacon) splitHeaders(chain consensus.ChainHeaderReader, headers []
// 2. x * POS blocks
// 3. x * POW blocks => y * POS blocks
//
// Special Cases for PulseChain:
// Special Cases for WhaleChain:
// 4. x * POS blocks[eth] => POW fork block[pls]
// 5. x * POS blocks[eth] => POW fork block[pls] => y * POS blocks[pls]
func (beacon *Beacon) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) (chan<- struct{}, <-chan error) {
@ -166,16 +166,12 @@ func (beacon *Beacon) VerifyHeaders(chain consensus.ChainHeaderReader, headers [
return beacon.ethone.VerifyHeaders(chain, headers)
}
chainCfg := chain.Config()
primordialPulseIndex := 0
if chainCfg.PrimordialPulseAhead(postHeaders[0].Number) && !chainCfg.PrimordialPulseAhead(postHeaders[len(postHeaders)-1].Number) {
primordialPulseIndex = int(new(big.Int).Sub(chainCfg.PrimordialPulseBlock, postHeaders[0].Number).Uint64())
}
primordialWhaleIndex := 0
if chainCfg.PrimordialWhaleAhead(postHeaders[0].Number) && !chainCfg.PrimordialWhaleAhead(postHeaders[len(postHeaders)-1].Number) {
primordialWhaleIndex = int(new(big.Int).Sub(chainCfg.PrimordialWhaleBlock, postHeaders[0].Number).Uint64())
}
// Case 2
if len(preHeaders) == 0 && primordialPulseIndex == 0 && primordialWhaleIndex == 0 {
if len(preHeaders) == 0 && primordialWhaleIndex == 0 {
return beacon.verifyHeaders(chain, headers, nil)
}
// The transition point exists in the middle, separate the headers
@ -310,7 +306,7 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa
}
// Verify existence / non-existence of withdrawalsHash.
shanghai := chain.Config().IsShanghai(header.Number, header.Time)
if chain.Config().PrimordialPulseAhead(header.Number) {
if chain.Config().PrimordialWhaleAhead(header.Number) {
shanghai = params.MainnetChainConfig.IsShanghai(header.Number, header.Time)
}
if shanghai && header.WithdrawalsHash == nil {

View file

@ -40,7 +40,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/WhaleChain/go-ethereum/whale"
"github.com/ethereum/go-ethereum/pulse"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie"
@ -573,9 +573,9 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
// Finalize implements consensus.Engine. There is no post-transaction
// consensus rules in clique, do nothing here.
func (c *Clique) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
// Apply fork changes on PrimordialPulse block
if cfg := chain.Config(); cfg.IsPrimordialPulseBlock(header.Number) {
pulse.PrimordialPulseFork(state, cfg.Treasury, cfg.ChainID)
// Apply fork changes on PrimordialWhale block
if cfg := chain.Config(); cfg.IsPrimordialWhaleBlock(header.Number) {
whale.PrimordialWhaleFork(state, cfg.Treasury, cfg.ChainID)
}
// No block rewards in PoA, so the state remains as is

View file

@ -31,7 +31,7 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/pulse"
"github.com/WhaleChain/go-ethereum-whale/whale"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"golang.org/x/crypto/sha3"
@ -299,8 +299,6 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time uin
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
next := new(big.Int).Add(parent.Number, big1)
switch {
case config.IsPrimordialPulseBlock(next):
return params.PulseChainTTDOffset
case config.IsPrimordialWhaleBlock(next):
return params.WhaleChainTTDOffset
case config.IsGrayGlacier(next):
@ -495,9 +493,9 @@ func (ethash *Ethash) Prepare(chain consensus.ChainHeaderReader, header *types.H
// Finalize implements consensus.Engine, accumulating the block and uncle rewards.
func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
// Apply fork changes on PrimordialPulse block
if cfg := chain.Config(); cfg.IsPrimordialPulseBlock(header.Number) {
pulse.PrimordialPulseFork(state, cfg.Treasury, cfg.ChainID)
// Apply fork changes on PrimordialWhale block
if cfg := chain.Config(); cfg.IsPrimordialWhaleBlock(header.Number) {
whale.PrimordialWhaleFork(state, cfg.Treasury, cfg.ChainID)
}
// Accumulate any block and uncle rewards

View file

@ -108,7 +108,7 @@ func (f *ForkChoice) ReorgNeeded(current *types.Header, extern *types.Header) (b
currentPreserve, externPreserve = f.preserve(current), f.preserve(extern)
}
reorg = !currentPreserve && (externPreserve || f.rand.Float64() < 0.5)
} else if f.chain.Config().PrimordialPulseAhead(extern.Number) {
} else if f.chain.Config().PrimordialWhaleAhead(extern.Number) {
// Pre-fork ethereum mainnet pos blocks have a difficulty of 0.
// These blocks should be accepted onto the chain head.
reorg = true

View file

@ -345,8 +345,8 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen
// Assume mainnet chainId first
chainId := params.MainnetChainConfig.ChainID.Uint64()
// Note: The `genesis` argument will be one of:
// - nil: if running without the `init` command and without providing a network flag (--pulsechain, --ropsten, etc..)
// - defaulted: when a network flag is provided (--pulsechain, --ropsten, etc..), genesis will hold the defaults
// - nil: if running without the `init` command and without providing a network flag (--whalechain, --ropsten, etc..)
// - defaulted: when a network flag is provided (--whalechain, --ropsten, etc..), genesis will hold the defaults
// - custom: if running with the `init` command supplying a custom genesis.json file, genesis will hold the file contents
// Check whether the genesis block is already written.
if genesis != nil {
@ -374,9 +374,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen
// chain config as that would be AllProtocolChanges (applying any new fork
// on top of an existing private network genesis block). In that case, only
// apply the overrides.
// Added: support custom config for PrimordialPulse fork with mainnet genesis
// Added: support custom config for PrimordialWhale fork with mainnet genesis
// and non-standard chain id.
if genesis == nil && (storedcfg.PrimordialPulseBlock != nil ||
if genesis == nil && (storedcfg.PrimordialWhaleBlock != nil ||
stored != params.MainnetGenesisHash) {
newcfg = storedcfg
applyOverrides(newcfg)
@ -437,12 +437,8 @@ func (g *Genesis) configOrDefault(ghash common.Hash, chainId uint64) *params.Cha
return g.Config
case ghash == params.MainnetGenesisHash:
switch chainId {
case params.PulseChainConfig.ChainID.Uint64():
return params.PulseChainConfig
case params.WhaleChainConfig.ChainID.Uint64():
return params.WhaleChainConfig
case params.PulseChainTestnetV4Config.ChainID.Uint64():
return params.PulseChainTestnetV4Config
case params.WhaleChainTestnetV4Config.ChainID.Uint64():
return params.WhaleChainTestnetV4Config
default:
@ -569,18 +565,6 @@ func DefaultGenesisBlock() *Genesis {
}
}
// DefaultPulseChainGenesisBlock returns the PulseChain mainnet genesis block.
func DefaultPulseChainGenesisBlock() *Genesis {
return &Genesis{
Config: params.PulseChainConfig,
Nonce: 66,
ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
GasLimit: 5000,
Difficulty: big.NewInt(17179869184),
Alloc: decodePrealloc(mainnetAllocData),
}
}
// DefaultWhaleChainGenesisBlock returns the WhaleChain mainnet genesis block.
func DefaultWhaleChainGenesisBlock() *Genesis {
return &Genesis{
@ -618,18 +602,6 @@ func DefaultSepoliaGenesisBlock() *Genesis {
}
}
// DefaultPulseChainTestnetV4GenesisBlock returns the PulseChain Testnet V4 genesis block.
func DefaultPulseChainTestnetV4GenesisBlock() *Genesis {
return &Genesis{
Config: params.PulseChainTestnetV4Config,
Nonce: 66,
ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
GasLimit: 5000,
Difficulty: big.NewInt(17179869184),
Alloc: decodePrealloc(mainnetAllocData),
}
}
// DefaultWhaleChainTestnetV4GenesisBlock returns the WhaleChain Testnet V4 genesis block.
func DefaultWhaleChainTestnetV4GenesisBlock() *Genesis {
return &Genesis{

View file

@ -93,7 +93,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
// Fail if Shanghai not enabled and len(withdrawals) is non-zero.
withdrawals := block.Withdrawals()
shanghai := p.config.IsShanghai(blockNumber, block.Time())
if p.config.PrimordialPulseAhead(blockNumber) {
if p.config.PrimordialWhaleAhead(blockNumber) {
shanghai = params.MainnetChainConfig.IsShanghai(blockNumber, block.Time())
}
if len(withdrawals) > 0 && !shanghai {

View file

@ -41,7 +41,7 @@ func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, blockTime uint
var signer Signer
chainID := config.ChainID
if config.PrimordialPulseAhead(blockNumber) {
if config.PrimordialWhaleAhead(blockNumber) {
// Use ethereum mainnet chainid for pre-fork transactions
chainID = big.NewInt(1)
}

View file

@ -126,7 +126,7 @@ type EVM struct {
// only ever be used *once*.
func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig *params.ChainConfig, config Config) *EVM {
flexChainConfig := chainConfig
if chainConfig.PrimordialPulseAhead(blockCtx.BlockNumber) {
if chainConfig.PrimordialWhaleAhead(blockCtx.BlockNumber) {
// Create a shallow of chainConfig struct and set to ethereum mainnet
chainCfgCpy := *chainConfig
chainCfgCpy.ChainID = big.NewInt(1)

2
go.mod
View file

@ -1,4 +1,4 @@
module github.com/ethereum/go-ethereum
module github.com/WhaleChain/go-ethereum-whale
go 1.19

View file

@ -28,14 +28,6 @@ var MainnetBootnodes = []string{
"enode://4aeb4ab6c14b23e2c4cfdce879c04b0748a20d8e9b59e25ded2a08143e265c6c25936e74cbc8e641e3312ca288673d91f2f93f8e277de3cfa444ecdaaf982052@157.90.35.166:30303", // bootnode-hetzner-fsn
}
// PulseChainBootnodes are the enode URLs of the P2P bootstrap nodes running on
// the main PulseChain network.
var PulseChainBootnodes = []string{
"enode://ba55e4342cdf8b4d45a0da26ed0575f96c8422400930bfde0ec7b241dd60d55651eb6a7010c2275ea63475dd77dbf431ae24b7b0f12453bc5120007e815b85f1@18.216.186.49:30303", // bootnode-aws-us-east-2-001
"enode://c4c8889c0d4bdc2cff9502e8dba81ab855772767ef023088dfd6d393328c1b3931304672d5fc722cd11b6141ecf0868f86d823748edd1bebd129b4c541509a27@18.188.89.119:30303", // bootnode-aws-us-east-2-002
"enode://345b8ef4dad4013b994ff664ec3a6b3f0438221794c4946b756bcae7fd0a1eb373a15035d3f032c039b5e3a69884b01774a3ca19c91081058cd05fcd02f93450@18.216.221.152:30303", // bootnode-aws-us-east-2-003
}
// WhaleChainBootnodes are the enode URLs of the P2P bootstrap nodes running on
// the main WhaleChain network.
var WhaleChainBootnodes = []string{
@ -44,14 +36,6 @@ var WhaleChainBootnodes = []string{
"enode://345b8ef4dad4013b994ff664ec3a6b3f0438221794c4946b756bcae7fd0a1eb373a15035d3f032c039b5e3a69884b01774a3ca19c91081058cd05fcd02f93450@18.216.221.152:30303", // bootnode-aws-us-east-2-003
}
// PulseChainTestnetV4Bootnodes are the enode URLs of the P2P bootstrap nodes running on
// the PulseChain Testnet V4 network.
var PulseChainTestnetV4Bootnodes = []string{
"enode://499f821836b8fec272c0664e79b95e8ec50b4320d201e02ac83c5bf63bcff33869c411e8290b1774d74ed01b7a53e838e3689cfe46992243094886a0980a9c60@3.142.166.203:30303", // bootnode-aws-us-east-2-001
"enode://133f45485d3b5221d10e5ed288bf1da827d5adbe454a9a9ae3cd4ae15d14b65d0b6d937b0a1a0ba3b9b2ebbf50c40e379573293f1ff51b553e997d843faa2c4b@18.118.188.165:30303", // bootnode-aws-us-east-2-002
"enode://ef4bf6197515e2aa3290f5bf5e43e2b99022254fcbd540507d325d2de40e9c6fd87581d88e9affe97bc7c099946a84ca66de0c7752a1ab616c7b51ef1f10b2fb@3.138.107.144:30303", // bootnode-aws-us-east-2-003
}
// WhaleChainTestnetV4Bootnodes are the enode URLs of the P2P bootstrap nodes running on
// the WhaleChain Testnet V4 network.
var WhaleChainTestnetV4Bootnodes = []string{
@ -114,11 +98,6 @@ func KnownDNSNetwork(genesis common.Hash, networkId uint64, protocol string) str
var dnsPrefix = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@"
var tld = ".ethdisco.net"
if networkId == PulseChainConfig.ChainID.Uint64() || networkId == PulseChainTestnetV4Config.ChainID.Uint64() {
tld = ".pulsedisco.net"
dnsPrefix = "enrtree://APFXO36RU3TWV7XFGWI2TYF5IDA3WM2GPTRL3TCZINWHZX4R6TAOK@"
}
if networkId == WhaleChainConfig.ChainID.Uint64() || networkId == WhaleChainTestnetV4Config.ChainID.Uint64() {
tld = ".whaledisco.net"
dnsPrefix = "enrtree://APFXO36RU3TWV7XFGWI2TYF5IDA3WM2GPTRL3TCZINWHZX4R6TAOK@"
@ -127,8 +106,6 @@ func KnownDNSNetwork(genesis common.Hash, networkId uint64, protocol string) str
switch genesis {
case MainnetGenesisHash:
switch networkId {
case PulseChainTestnetV4Config.ChainID.Uint64():
net = "testnet-v4"
case WhaleChainTestnetV4Config.ChainID.Uint64():
net = "testnet-v4"
default:

View file

@ -305,9 +305,9 @@ type ChainConfig struct {
Clique *CliqueConfig `json:"clique,omitempty"`
IsDevMode bool `json:"isDev,omitempty"`
// PulseChain modifications
PrimordialPulseBlock *big.Int `json:"primordialPulseBlock,omitempty"` // PrimordialPulseBlock switch block (nil = no fork, 0 = already activated)
Treasury *Treasury `json:"treasury,omitempty"` // An optional treasury which will receive allocations during the PrimordialPulseBlock
// WhaleChain modifications
PrimordialWhaleBlock *big.Int `json:"primordialWhaleBlock,omitempty"` // PrimordialWhaleBlock switch block (nil = no fork, 0 = already activated)
Treasury *Treasury `json:"treasury,omitempty"` // An optional treasury which will receive allocations during the PrimordialWhaleBlock
}
// EthashConfig is the consensus engine configs for proof-of-work based sealing.
@ -387,8 +387,8 @@ func (c *ChainConfig) Description() string {
if c.GrayGlacierBlock != nil {
banner += fmt.Sprintf(" - Gray Glacier: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/gray-glacier.md)\n", c.GrayGlacierBlock)
}
if c.PrimordialPulseBlock != nil {
banner += fmt.Sprintf(" - Primordial Pulse: #%-8v (https://gitlab.com/pulsechaincom/go-pulse)\n", c.PrimordialPulseBlock)
if c.PrimordialWhaleBlock != nil {
banner += fmt.Sprintf(" - Primordial Whale: #%-8v (https://github.com/WhaleChain/go-ethereum)\n", c.PrimordialWhaleBlock)
}
banner += "\n"
@ -524,15 +524,15 @@ func (c *ChainConfig) IsVerkle(num *big.Int, time uint64) bool {
return c.IsLondon(num) && isTimestampForked(c.VerkleTime, time)
}
// IsPrimordialPulseBlock returns whether or not the given block is the primordial pulse block.
func (c *ChainConfig) IsPrimordialPulseBlock(num *big.Int) bool {
// Returns whether or not the given block is the PrimordialPulseBlock.
return c.PrimordialPulseBlock != nil && c.PrimordialPulseBlock.Cmp(num) == 0
// IsPrimordialWhaleBlock returns whether or not the given block is the primordial whale block.
func (c *ChainConfig) IsPrimordialWhaleBlock(num *big.Int) bool {
// Returns whether or not the given block is the PrimordialWhaleBlock.
return c.PrimordialWhaleBlock != nil && c.PrimordialWhaleBlock.Cmp(num) == 0
}
// Returns true if there is a PrimordialPulse block in the future.
func (c *ChainConfig) PrimordialPulseAhead(num *big.Int) bool {
return c.PrimordialPulseBlock != nil && c.PrimordialPulseBlock.Cmp(num) > 0
// Returns true if there is a PrimordialWhale block in the future.
func (c *ChainConfig) PrimordialWhaleAhead(num *big.Int) bool {
return c.PrimordialWhaleBlock != nil && c.PrimordialWhaleBlock.Cmp(num) > 0
}
// CheckCompatible checks whether scheduled fork transitions have been imported
@ -647,8 +647,8 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
if isForkBlockIncompatible(c.EIP158Block, newcfg.EIP158Block, headNumber) {
return newBlockCompatError("EIP158 fork block", c.EIP158Block, newcfg.EIP158Block)
}
// allow mismatching ChainID if there is a PrimordialPulse block ahead
if c.IsEIP158(headNumber) && !configBlockEqual(c.ChainID, newcfg.ChainID) && !newcfg.PrimordialPulseAhead(headNumber) {
// allow mismatching ChainID if there is a PrimordialWhale block ahead
if c.IsEIP158(headNumber) && !configBlockEqual(c.ChainID, newcfg.ChainID) && !newcfg.PrimordialWhaleAhead(headNumber) {
return newBlockCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block)
}
if isForkBlockIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, headNumber) {
@ -685,8 +685,8 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
if isForkBlockIncompatible(c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock, headNumber) {
return newBlockCompatError("Merge netsplit fork block", c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock)
}
// allow mismatching Shanghai time if we're on the PrimordialPulse block or if there is a PrimordialPulse block ahead
if isForkTimestampIncompatible(c.ShanghaiTime, newcfg.ShanghaiTime, headTimestamp) && !newcfg.IsPrimordialPulseBlock(headNumber) && !newcfg.PrimordialPulseAhead(headNumber) {
// allow mismatching Shanghai time if we're on the PrimordialWhale block or if there is a PrimordialWhale block ahead
if isForkTimestampIncompatible(c.ShanghaiTime, newcfg.ShanghaiTime, headTimestamp) && !newcfg.IsPrimordialWhaleBlock(headNumber) && !newcfg.PrimordialWhaleAhead(headNumber) {
return newTimestampCompatError("Shanghai fork timestamp", c.ShanghaiTime, newcfg.ShanghaiTime)
}
if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, headTimestamp) {
@ -698,8 +698,8 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, headTimestamp) {
return newTimestampCompatError("Verkle fork timestamp", c.VerkleTime, newcfg.VerkleTime)
}
if isForkBlockIncompatible(c.PrimordialPulseBlock, newcfg.PrimordialPulseBlock, headNumber) {
return newBlockCompatError("PrimordialPulse fork block", c.PrimordialPulseBlock, newcfg.PrimordialPulseBlock)
if isForkBlockIncompatible(c.PrimordialWhaleBlock, newcfg.PrimordialWhaleBlock, headNumber) {
return newBlockCompatError("PrimordialWhale fork block", c.PrimordialWhaleBlock, newcfg.PrimordialWhaleBlock)
}
return nil
}
@ -856,7 +856,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
chainID = new(big.Int)
}
isShanghai := c.IsShanghai(num, timestamp)
if c.PrimordialPulseAhead(num) {
if c.PrimordialWhaleAhead(num) {
isShanghai = MainnetChainConfig.IsShanghai(num, timestamp)
}
return Rules{

View file

@ -1,82 +0,0 @@
package params
import (
"math/big"
"github.com/ethereum/go-ethereum/common/math"
)
// Optional treasury for launching PulseChain testnets
type Treasury struct {
Addr string `json:"addr"`
Balance *math.HexOrDecimal256 `json:"balance"`
}
// A trivially small amount of work to add to the Ethereum Mainnet TTD
// to allow for un-merging and merging with the PulseChain beacon chain
var PulseChainTTDOffset = big.NewInt(131_072)
// This value is defined as LAST_ACTUAL_MAINNET_TTD + PulseChainTTDOffset
// where LAST_ACTUAL_MAINNET_TTD = 58_750_003_716_598_352_816_469
var PulseChainTerminalTotalDifficulty, _ = new(big.Int).SetString("58_750_003_716_598_352_947_541", 0)
var (
PulseChainConfig = &ChainConfig{
ChainID: big.NewInt(369),
HomesteadBlock: big.NewInt(1_150_000),
DAOForkBlock: big.NewInt(1_920_000),
DAOForkSupport: true,
EIP150Block: big.NewInt(2_463_000),
EIP155Block: big.NewInt(2_675_000),
EIP158Block: big.NewInt(2_675_000),
ByzantiumBlock: big.NewInt(4_370_000),
ConstantinopleBlock: big.NewInt(7_280_000),
PetersburgBlock: big.NewInt(7_280_000),
IstanbulBlock: big.NewInt(9_069_000),
MuirGlacierBlock: big.NewInt(9_200_000),
BerlinBlock: big.NewInt(12_244_000),
LondonBlock: big.NewInt(12_965_000),
ArrowGlacierBlock: big.NewInt(13_773_000),
GrayGlacierBlock: big.NewInt(15_050_000),
TerminalTotalDifficulty: PulseChainTerminalTotalDifficulty,
TerminalTotalDifficultyPassed: true,
Ethash: new(EthashConfig),
PrimordialPulseBlock: big.NewInt(17_233_000),
ShanghaiTime: newUint64(1683786515),
}
PulseChainTestnetV4Config = &ChainConfig{
ChainID: big.NewInt(943),
HomesteadBlock: big.NewInt(1_150_000),
DAOForkBlock: big.NewInt(1_920_000),
DAOForkSupport: true,
EIP150Block: big.NewInt(2_463_000),
EIP155Block: big.NewInt(2_675_000),
EIP158Block: big.NewInt(2_675_000),
ByzantiumBlock: big.NewInt(4_370_000),
ConstantinopleBlock: big.NewInt(7_280_000),
PetersburgBlock: big.NewInt(7_280_000),
IstanbulBlock: big.NewInt(9_069_000),
MuirGlacierBlock: big.NewInt(9_200_000),
BerlinBlock: big.NewInt(12_244_000),
LondonBlock: big.NewInt(12_965_000),
ArrowGlacierBlock: big.NewInt(13_773_000),
GrayGlacierBlock: big.NewInt(15_050_000),
TerminalTotalDifficulty: PulseChainTerminalTotalDifficulty,
TerminalTotalDifficultyPassed: true,
Ethash: new(EthashConfig),
PrimordialPulseBlock: big.NewInt(16_492_700),
Treasury: testnetTreasury(),
ShanghaiTime: newUint64(1682700369),
}
)
func testnetTreasury() *Treasury {
var pulseChainTestnetTreasuryBalance math.HexOrDecimal256
pulseChainTestnetTreasuryBalance.UnmarshalText([]byte("0x314DC6448D9338C15B0A00000000"))
return &Treasury{
Addr: "0xA592ED65885bcbCeb30442F4902a0D1Cf3AcB8fC",
Balance: &pulseChainTestnetTreasuryBalance,
}
}

View file

@ -24,7 +24,7 @@ const (
VersionMajor = 3 // Major version component of the current release
VersionMinor = 0 // Minor version component of the current release
VersionPatch = 1 // Patch version component of the current release
VariantMeta = "pulse" // Variant metadata to append to the version string
VariantMeta = "whale" // Variant metadata to append to the version string
VersionMeta = "stable" // Version metadata to append to the version string
)

View file

@ -6,17 +6,17 @@ import (
"github.com/ethereum/go-ethereum/common/math"
)
// Optional treasury for launching PulseChain testnets
// Optional treasury for launching WhaleChain testnets
type Treasury struct {
Addr string `json:"addr"`
Balance *math.HexOrDecimal256 `json:"balance"`
}
// A trivially small amount of work to add to the Ethereum Mainnet TTD
// to allow for un-merging and merging with the PulseChain beacon chain
// to allow for un-merging and merging with the WhaleChain beacon chain
var WhaleChainTTDOffset = big.NewInt(131_072)
// This value is defined as LAST_ACTUAL_MAINNET_TTD + PulseChainTTDOffset
// This value is defined as LAST_ACTUAL_MAINNET_TTD + WhaleChainTTDOffset
// where LAST_ACTUAL_MAINNET_TTD = 58_750_003_716_598_352_816_469
var WhaleChainTerminalTotalDifficulty, _ = new(big.Int).SetString("58_750_003_716_598_352_947_541", 0)
@ -38,10 +38,10 @@ var (
LondonBlock: big.NewInt(12_965_000),
ArrowGlacierBlock: big.NewInt(13_773_000),
GrayGlacierBlock: big.NewInt(15_050_000),
TerminalTotalDifficulty: PulseChainTerminalTotalDifficulty,
TerminalTotalDifficulty: WhaleChainTerminalTotalDifficulty,
TerminalTotalDifficultyPassed: true,
Ethash: new(EthashConfig),
PrimordialPulseBlock: big.NewInt(17_233_000),
PrimordialWhaleBlock: big.NewInt(17_233_000),
ShanghaiTime: newUint64(1683786515),
}
@ -62,10 +62,10 @@ var (
LondonBlock: big.NewInt(12_965_000),
ArrowGlacierBlock: big.NewInt(13_773_000),
GrayGlacierBlock: big.NewInt(15_050_000),
TerminalTotalDifficulty: PulseChainTerminalTotalDifficulty,
TerminalTotalDifficulty: WhaleChainTerminalTotalDifficulty,
TerminalTotalDifficultyPassed: true,
Ethash: new(EthashConfig),
PrimordialPulseBlock: big.NewInt(16_492_700),
PrimordialWhaleBlock: big.NewInt(16_492_700),
Treasury: testnetTreasury(),
ShanghaiTime: newUint64(1682700369),
}

File diff suppressed because one or more lines are too long

View file

@ -1,43 +0,0 @@
package pulse
import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/trie"
)
func TestReplaceDepositContract(t *testing.T) {
// Init
db := rawdb.NewMemoryDatabase()
state, _ := state.New(common.Hash{}, state.NewDatabaseWithConfig(db, &trie.Config{Preimages: true}), nil)
// Exec
replaceDepositContract(state)
// Verify
balance := state.GetBalance(pulseDepositContractAddr)
if balance.Cmp(common.Big0) != 0 {
t.Errorf("Found unexpected deposit contract balance: %d", balance)
}
actualCode := state.GetCode(pulseDepositContractAddr)
for i, b := range actualCode {
if b != depositContractBytes[i] {
t.Errorf("Invalid deposit contract code at index %d", i)
}
}
// Verify Storage
for i, store := range depositContractStorage {
actualStorage := state.GetState(pulseDepositContractAddr, common.HexToHash(store[0]))
expectedStorage := common.HexToHash(store[1])
if actualStorage != expectedStorage {
t.Errorf("Invalid storage entry %d, actual: %d, expected: %d", i, actualStorage, expectedStorage)
} else {
t.Log("Valid Storage entry")
}
}
}

View file

@ -1,15 +0,0 @@
// Package pulse implements the PulseChain fork
package pulse
import (
"math/big"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/params"
)
// Apply PrimordialPulse fork changes
func PrimordialPulseFork(state *state.StateDB, treasury *params.Treasury, chainID *big.Int) {
applySacrificeCredits(state, treasury, chainID)
replaceDepositContract(state)
}

View file

@ -1,49 +0,0 @@
package pulse
import (
_ "embed"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)
// see https://gitlab.com/pulsechaincom/compressed-allocations/-/tags/Mainnet
//
//go:embed sacrifice_credits_mainnet.bin
var mainnetRawCredits []byte
// see https://gitlab.com/pulsechaincom/compressed-allocations/-/tags/Testnet-V4
//
//go:embed sacrifice_credits_testnet_v4.bin
var testnetV4RawCredits []byte
// Applies the sacrifice credits for the PrimordialPulse fork.
func applySacrificeCredits(state *state.StateDB, treasury *params.Treasury, chainID *big.Int) {
rawCredits := mainnetRawCredits
if chainID.Cmp(params.PulseChainTestnetV4Config.ChainID) == 0 {
rawCredits = testnetV4RawCredits
}
if treasury != nil {
log.Info("Applying PrimordialPulse treasury allocation 💸")
state.AddBalance(common.HexToAddress(treasury.Addr), (*big.Int)(treasury.Balance))
}
log.Info("Applying PrimordialPulse sacrifice credits 💸")
for ptr := 0; ptr < len(rawCredits); {
byteCount := int(rawCredits[ptr])
ptr++
record := rawCredits[ptr : ptr+byteCount]
ptr += byteCount
addr := common.BytesToAddress(record[:20])
credit := new(big.Int).SetBytes(record[20:])
state.AddBalance(addr, credit)
}
log.Info("Finished applying PrimordialPulse sacrifice credits 🤑")
}

Binary file not shown.

View file

@ -1,48 +0,0 @@
package pulse
import (
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
)
func TestApplySacrificeCredits(t *testing.T) {
// Init
var pulseChainTestnetTreasuryBalance math.HexOrDecimal256
pulseChainTestnetTreasuryBalance.UnmarshalText([]byte("0xC9F2C9CD04674EDEA40000000"))
db := rawdb.NewMemoryDatabase()
state, _ := state.New(common.Hash{}, state.NewDatabaseWithConfig(db, &trie.Config{Preimages: true}), nil)
treasury := &params.Treasury{
Addr: "0xceB59257450820132aB274ED61C49E5FD96E8868",
Balance: &pulseChainTestnetTreasuryBalance,
}
// Exec
applySacrificeCredits(state, treasury, params.PulseChainConfig.ChainID)
// Verify
actual := state.GetBalance(common.HexToAddress(treasury.Addr))
expected := (*big.Int)(treasury.Balance)
if actual.Cmp(expected) != 0 {
t.Errorf("Invalid treasury balance, actual: %d, expected: %d", actual, expected)
} else {
t.Log("Treasury allocating successful")
}
// from the credits.csv file in compressed-allocations
actual = state.GetBalance(common.HexToAddress("0x000000005dCEE11e13fb536Fa40d65450F53c5a8"))
expected, _ = new(big.Int).SetString("64000000000000000000", 10)
if actual.Cmp(expected) != 0 {
t.Errorf("Invalid sacrifice credit balance, actual: %d, expected: %d", actual, expected)
} else {
t.Log("Sacrifice allocation successful")
}
}