Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/config"
"math/big"
"os"
"reflect"
Expand Down Expand Up @@ -111,22 +112,11 @@ func defaultNodeConfig() node.Config {
return cfg
}

// makeConfigNode loads geth configuration and creates a blank node instance.
func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
// Load defaults.
cfg := gethConfig{
Eth: ethconfig.Defaults,
Node: defaultNodeConfig(),
Metrics: metrics.DefaultConfig,
func readGenesisConfig(ctx *cli.Context) *core.Genesis {
// for scoville just return already stored genesis config
if ctx.GlobalBool(utils.ChilizTestnetFlag.Name) {
return config.ScovilleGenesisConfig
}

// Load config file.
if file := ctx.GlobalString(configFileFlag.Name); file != "" {
if err := loadConfig(file, &cfg); err != nil {
utils.Fatalf("%v", err)
}
}

// Make sure we have a valid genesis JSON
genesisPath := ctx.GlobalString(utils.GenesisFlag.Name)
if len(genesisPath) == 0 {
Expand All @@ -138,12 +128,30 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
}
//goland:noinspection GoUnhandledErrorResult
defer file.Close()

genesis := new(core.Genesis)
if err := json.NewDecoder(file).Decode(genesis); err != nil {
utils.Fatalf("invalid genesis file: %v", err)
}
cfg.Eth.Genesis = genesis
return genesis
}

// makeConfigNode loads geth configuration and creates a blank node instance.
func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
// Load defaults.
cfg := gethConfig{
Eth: ethconfig.Defaults,
Node: defaultNodeConfig(),
Metrics: metrics.DefaultConfig,
}

// Load config file.
if file := ctx.GlobalString(configFileFlag.Name); file != "" {
if err := loadConfig(file, &cfg); err != nil {
utils.Fatalf("%v", err)
}
}

cfg.Eth.Genesis = readGenesisConfig(ctx)

// Apply flags.
utils.SetNodeConfig(ctx, &cfg.Node)
Expand All @@ -163,7 +171,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
if err != nil {
utils.Fatalf("Failed to open database: %v", err)
}
_, hash, err := core.SetupGenesisBlock(chaindb, genesis)
_, hash, err := core.SetupGenesisBlock(chaindb, cfg.Eth.Genesis)
if err != nil {
utils.Fatalf("Failed to write genesis block: %v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var (
// flags that configure the node
nodeFlags = []cli.Flag{
utils.GenesisFlag,
utils.ChilizTestnetFlag,
utils.ChilizMainnetFlag,
utils.IdentityFlag,
utils.UnlockedAccountFlag,
utils.PasswordFileFlag,
Expand Down
9 changes: 3 additions & 6 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ var (
GenesisFlag = cli.StringFlag{
Name: "genesis",
Usage: "Path to genesis JSON file",
Value: "./genesis/devnet.json",
}

// General settings
Expand Down Expand Up @@ -201,8 +200,8 @@ var (
Usage: "Chiliz network: pre-configured proof-of-work test network",
}
ChilizTestnetFlag = cli.BoolFlag{
Name: "chiliztestnet",
Usage: "Chiliz network: pre-configured proof-of-work test network",
Name: "scoville",
Usage: "Chiliz testnet network",
}
DeveloperFlag = cli.BoolFlag{
Name: "dev",
Expand Down Expand Up @@ -939,7 +938,7 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
case ctx.GlobalBool(ChilizMainnetFlag.Name):
urls = params.ChilizMainnetBootnodes
case ctx.GlobalBool(ChilizTestnetFlag.Name):
urls = params.ChilizTestnetBootnodes
urls = params.ChilizScovilleBootnodes
case cfg.BootstrapNodes != nil:
return // already set, don't apply defaults.
}
Expand Down Expand Up @@ -1776,12 +1775,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 88888
}
cfg.Genesis = core.DefaultChilizMainnetGenesisBlock()
case ctx.GlobalBool(ChilizTestnetFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 88880
}
cfg.Genesis = core.DefaultChilizTestnetGenesisBlock()
case ctx.GlobalBool(DeveloperFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1337
Expand Down
139 changes: 139 additions & 0 deletions config/embedded/scoville.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions config/embeded.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package config

import (
_ "embed"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/core"
)

func mustParseGenesisConfigFromJson(rawJson []byte) *core.Genesis {
genesis := new(core.Genesis)
if err := json.Unmarshal(rawJson, genesis); err != nil {
panic(fmt.Sprintf("invalid genesis file: %v", err))
}
return genesis
}

//go:embed embedded/scoville.json
var scovilleRawGenesisConfig []byte

var ScovilleGenesisConfig = mustParseGenesisConfigFromJson(scovilleRawGenesisConfig)
9 changes: 7 additions & 2 deletions core/vm/chiliz.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ func applyChilizInvocationEvmHook(evm *EVM, addr common.Address, gas uint64) (le
return gas, nil
}

func applyChilizDeploymentEvmHook(evm *EVM, addr common.Address, gas uint64) (leftOverGas uint64, err error) {
func applyChilizDeploymentEvmHook(evm *EVM, caller ContractRef, addr common.Address, gas uint64) (leftOverGas uint64, err error) {
if systemcontract.IsSystemContract(addr) {
return gas, nil
}
input, err := systemcontract.EvmHooksAbi.Pack("registerDeployedContract", evm.TxContext.Origin, addr)
var input []byte
if evm.chainRules.HasDeployOrigin {
input, err = systemcontract.EvmHooksAbi.Pack("registerDeployedContract", evm.TxContext.Origin, addr)
} else {
input, err = systemcontract.EvmHooksAbi.Pack("registerDeployedContract", caller.Address(), addr)
}
if err != nil {
return gas, ErrNotAllowed
}
Expand Down
2 changes: 1 addition & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,

// Make sure it's allowed to deploy smart contracts
var err error
gas, err = applyChilizDeploymentEvmHook(evm, address, gas)
gas, err = applyChilizDeploymentEvmHook(evm, caller, address, gas)
if err != nil {
return nil, common.Address{}, gas, err
}
Expand Down
9 changes: 7 additions & 2 deletions params/bootnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,14 @@ var YoloV3Bootnodes = []string{
"enode://9e1096aa59862a6f164994cb5cb16f5124d6c992cdbf4535ff7dea43ea1512afe5448dca9df1b7ab0726129603f1a3336b631e4d7a1a44c94daddd03241587f9@3.9.20.133:30303",
}

var ChilizMainnetBootnodes = []string{}
var ChilizScovilleBootnodes = []string{
"enode://3e400492243ac18b838fa782d7bcfa08f57f307d130988de2aae63174b5b05aeba29786b82d70b2b3f556c62923b08012ead1eae4a9e17416a9273f788774577@15.237.22.149:30303",
"enode://c80406f22398f9657684cc9d87994cb25857197f6fa26451ae1068d72899eae1a259b4dba2f5310d920b2112de5bed8bccb9f22ea51518c5a1a239b3ce489934@15.236.167.157:30303",
"enode://770d890858aa0cfeb8c64052830f8f3ad87e2b2c52105b9a418565e1e98dc61ecaf58b5742c1b31d76277215eea906c078e532b61c36c4606badbe77c92bbe1f@13.38.166.107:30303",
"enode://1e3593214f7c080e5687594dff5b49a1a7744bf6dca0491ea2e12436ba903d647403f0cecf7fd8305a5be3d999b439b4323fd22f05c64c23401ee60c23528f53@13.36.115.227:30303",
}

var ChilizTestnetBootnodes = []string{}
var ChilizMainnetBootnodes = []string{}

var V5Bootnodes = []string{
// Teku team's bootnode
Expand Down
90 changes: 22 additions & 68 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var (
RialtoGenesisHash = common.HexToHash("0xaabe549bfa85c84f7aee9da7010b97453ad686f2c2d8ce00503d1a00c72cad54")
YoloV3GenesisHash = common.HexToHash("0xf1f2876e8500c77afcc03228757b39477eceffccf645b734967fe3c7e16967b7")

ChilizMainnetGenesisHash = common.HexToHash("0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b")
ChilizTestnetGenesisHash = common.HexToHash("0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b")
ChilizScovilleGenesisHash = common.HexToHash("0xa148378fbfd7562cd43c8622d20ad056b735fdc0f968f56d0033294c33ededf2")
ChilizMainnetGenesisHash = common.HexToHash("")
)

// TrustedCheckpoints associates each known checkpoint with the genesis hash of
Expand Down Expand Up @@ -329,48 +329,6 @@ var (
},
}

ChilizMainnetChainConfig = &ChainConfig{
ChainID: big.NewInt(88888),
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
RamanujanBlock: big.NewInt(0),
NielsBlock: big.NewInt(0),
MirrorSyncBlock: big.NewInt(0),
BrunoBlock: big.NewInt(0),
Parlia: &ParliaConfig{
Period: 3,
Epoch: 200,
},
}

ChilizTestnetChainConfig = &ChainConfig{
ChainID: big.NewInt(88880),
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
RamanujanBlock: big.NewInt(0),
NielsBlock: big.NewInt(0),
MirrorSyncBlock: big.NewInt(0),
BrunoBlock: big.NewInt(0),
Parlia: &ParliaConfig{
Period: 3,
Epoch: 200,
},
}

// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Ethash consensus.
//
Expand Down Expand Up @@ -532,8 +490,9 @@ type ChainConfig struct {
MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated)
BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin)

RuntimeUpgradeBlock *big.Int `json:"RuntimeUpgradeBlock,omitempty"`
DeployerProxyBlock *big.Int `json:"DeployerProxyBlock,omitempty"`
// Chiliz V2 forks
RuntimeUpgradeBlock *big.Int `json:"runtimeUpgradeBlock,omitempty"`
DeployOriginBlock *big.Int `json:"deployOriginBlock,omitempty"`

YoloV3Block *big.Int `json:"yoloV3Block,omitempty"` // YOLO v3: Gas repricings TODO @holiman add EIP references
EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated) RamanujanBlock *big.Int `json:"ramanujanBlock,omitempty" toml:",omitempty"` // ramanujanBlock switch block (nil = no fork, 0 = already activated)
Expand Down Expand Up @@ -723,14 +682,6 @@ func (c *ChainConfig) IsEWASM(num *big.Int) bool {
return isForked(c.EWASMBlock, num)
}

func (c *ChainConfig) HasRuntimeUpgrade(num *big.Int) bool {
return isForked(c.RuntimeUpgradeBlock, num)
}

func (c *ChainConfig) HasDeployerProxy(num *big.Int) bool {
return isForked(c.DeployerProxyBlock, num)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration.
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
Expand Down Expand Up @@ -911,7 +862,9 @@ type Rules struct {
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsCatalyst bool
HasRuntimeUpgrade, HasDeployerProxy bool
// features
HasRuntimeUpgrade bool
HasDeployOrigin bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -921,18 +874,19 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
chainID = new(big.Int)
}
return Rules{
ChainID: new(big.Int).Set(chainID),
IsHomestead: c.IsHomestead(num),
IsEIP150: c.IsEIP150(num),
IsEIP155: c.IsEIP155(num),
IsEIP158: c.IsEIP158(num),
IsByzantium: c.IsByzantium(num),
IsConstantinople: c.IsConstantinople(num),
IsPetersburg: c.IsPetersburg(num),
IsIstanbul: c.IsIstanbul(num),
IsBerlin: c.IsBerlin(num),
IsCatalyst: c.IsCatalyst(num),
HasRuntimeUpgrade: c.HasRuntimeUpgrade(num),
HasDeployerProxy: c.HasDeployerProxy(num),
ChainID: new(big.Int).Set(chainID),
IsHomestead: c.IsHomestead(num),
IsEIP150: c.IsEIP150(num),
IsEIP155: c.IsEIP155(num),
IsEIP158: c.IsEIP158(num),
IsByzantium: c.IsByzantium(num),
IsConstantinople: c.IsConstantinople(num),
IsPetersburg: c.IsPetersburg(num),
IsIstanbul: c.IsIstanbul(num),
IsBerlin: c.IsBerlin(num),
IsCatalyst: c.IsCatalyst(num),
// features
HasRuntimeUpgrade: isForked(c.RuntimeUpgradeBlock, num),
HasDeployOrigin: isForked(c.DeployOriginBlock, num),
}
}