Skip to content

Use cchain config from coreth instead of hardcoded #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 34 additions & 1 deletion local/default/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,39 @@
"delegationFee": 62500
}
],
"cChainGenesis": "{\"config\":{\"chainId\":43112,\"homesteadBlock\":0,\"daoForkBlock\":0,\"daoForkSupport\":true,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0,\"apricotPhase1BlockTimestamp\":0,\"apricotPhase2BlockTimestamp\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x5f5e100\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC\":{\"balance\":\"0x295BE96E64066972000000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}",
"cChainGenesis": {
"config": {
"chainId": 43112,
"homesteadBlock": 0,
"daoForkBlock": 0,
"daoForkSupport": true,
"eip150Block": 0,
"eip150Hash": "0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"apricotPhase1BlockTimestamp": 0,
"apricotPhase2BlockTimestamp": 0
},
"nonce": "0x0",
"timestamp": "0x0",
"extraData": "0x00",
"gasLimit": "0x5f5e100",
"difficulty": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC": {
"balance": "0x295BE96E64066972000000"
}
},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"message": "{{ fun_quote }}"
}
27 changes: 25 additions & 2 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ava-labs/avalanchego/utils/ips"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/wrappers"
coreth_params "github.com/ava-labs/coreth/params"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -158,6 +159,28 @@ func init() {
}
}
}

// set the cchain genesis directly from coreth
// the whole of `cChainGenesis` should be set as a string, not a json object...
corethCChainGenesis := coreth_params.AvalancheLocalChainConfig
// but the part in coreth is only the "config" part.
// In order to set it easily, first we get the cChainGenesis item
cChainGenesis := genesisMap["cChainGenesis"]
// convert it to a map
cChainGenesisMap, ok := cChainGenesis.(map[string]interface{})
if !ok {
panic("expected field 'cChainGenesis' of genesisMap to be a map[string]interface{}, but it failed")
}
// set the `config` key to the actual coreth object
cChainGenesisMap["config"] = corethCChainGenesis
// and then marshal everything into a string
genesisBytes, err := json.Marshal(cChainGenesisMap)
if err != nil {
panic(err)
}
// this way the whole of `cChainGenesis` is a properly escaped string
genesisMap["cChainGenesis"] = string(genesisBytes)
// now we can marshal the *whole* thing into bytes
updatedGenesis, err := json.Marshal(genesisMap)
if err != nil {
panic(err)
Expand Down Expand Up @@ -910,8 +933,8 @@ func (ln *localNetwork) buildFlags(

// avoid given these again, as apiPort/p2pPort can be dynamic even if given in nodeConfig
portFlags := map[string]struct{}{
config.HTTPPortKey: struct{}{},
config.StakingPortKey: struct{}{},
config.HTTPPortKey: {},
config.StakingPortKey: {},
}

// Add flags given in node config.
Expand Down
10 changes: 9 additions & 1 deletion network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,27 @@ import (
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/utils/units"
coreth_params "github.com/ava-labs/coreth/params"
)

var cChainConfig map[string]interface{}

const (
validatorStake = units.MegaAvax
defaultCChainConfigStr = "{\"config\":{\"chainId\":43112,\"homesteadBlock\":0,\"daoForkBlock\":0,\"daoForkSupport\":true,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0,\"apricotPhase1BlockTimestamp\":0,\"apricotPhase2BlockTimestamp\":0,\"apricotPhase3BlockTimestamp\":0,\"apricotPhase4BlockTimestamp\":0,\"apricotPhase5BlockTimestamp\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x5f5e100\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}"
defaultCChainConfigStr = `{"config":{"chainId":43112,"homesteadBlock":0,"daoForkBlock":0,"daoForkSupport":true,"eip150Block":0,"eip150Hash":"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0","eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"constantinopleBlock":0,"petersburgBlock":0,"istanbulBlock":0,"muirGlacierBlock":0,"apricotPhase1BlockTimestamp":0,"apricotPhase2BlockTimestamp":0,"apricotPhase3BlockTimestamp":0,"apricotPhase4BlockTimestamp":0,"apricotPhase5BlockTimestamp":0},"nonce":"0x0","timestamp":"0x0","extraData":"0x00","gasLimit":"0x5f5e100","difficulty":"0x0","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","coinbase":"0x0000000000000000000000000000000000000000","number":"0x0","gasUsed":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}`
)

func init() {
if err := json.Unmarshal([]byte(defaultCChainConfigStr), &cChainConfig); err != nil {
panic(err)
}
corethCChainGenesis := coreth_params.AvalancheLocalChainConfig
cChainGenesisJSON, err := json.Marshal(corethCChainGenesis)
if err != nil {
panic(err)
}
cChainGenesisStr := string(cChainGenesisJSON)
cChainConfig["config"] = cChainGenesisStr
}

// AddrAndBalance holds both an address and its balance
Expand Down