From 5c6dc6d7f4b7f84c4ea21b03bd5cbfe73a604419 Mon Sep 17 00:00:00 2001 From: Qi Zhou Date: Thu, 3 Mar 2022 19:53:47 -0800 Subject: [PATCH] add galileo config add codegen for header --- cmd/utils/flags.go | 19 +++++++++++++- core/genesis.go | 4 ++- core/types/gen_header_rlp.go | 49 +++++++++++++++++++++++++++++++++++- params/bootnodes.go | 3 +++ params/config.go | 29 ++++++++++++++++++--- 5 files changed, 97 insertions(+), 7 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 34f2a9d0d2ff..58dc945e9136 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -165,6 +165,10 @@ var ( Name: "web3q_testnet", Usage: "Web3Q network: pre-configured proof-of-authority test network", } + Web3QGalileoFlag = cli.BoolFlag{ + Name: "web3q_galileo", + Usage: "Web3Q network: pre-configured proof-of-authority BFT test network", + } Web3QMainnetFlag = cli.BoolFlag{ Name: "web3q_mainnet", Usage: "Web3Q mainnet", @@ -822,6 +826,9 @@ func MakeDataDir(ctx *cli.Context) string { if ctx.GlobalBool(Web3QTestnetFlag.Name) { return filepath.Join(path, "web3q_testnet") } + if ctx.GlobalBool(Web3QGalileoFlag.Name) { + return filepath.Join(path, "web3q_galileo") + } if ctx.GlobalBool(Web3QMainnetFlag.Name) { return filepath.Join(path, "web3q_mainnet") } @@ -881,6 +888,8 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) { urls = params.GoerliBootnodes case ctx.GlobalBool(Web3QTestnetFlag.Name): urls = params.Web3QTestnetBootnodes + case ctx.GlobalBool(Web3QGalileoFlag.Name): + urls = params.Web3QGalileoBootnodes case ctx.GlobalBool(Web3QMainnetFlag.Name): urls = params.Web3QMainnetBootnodes case cfg.BootstrapNodes != nil: @@ -1306,6 +1315,8 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) { cfg.DataDir = filepath.Join(node.DefaultDataDir(), "sepolia") case ctx.GlobalBool(Web3QTestnetFlag.Name) && cfg.DataDir == node.DefaultDataDir(): cfg.DataDir = filepath.Join(node.DefaultDataDir(), "web3q_testnet") + case ctx.GlobalBool(Web3QGalileoFlag.Name) && cfg.DataDir == node.DefaultDataDir(): + cfg.DataDir = filepath.Join(node.DefaultDataDir(), "web3q_galileo") case ctx.GlobalBool(Web3QMainnetFlag.Name) && cfg.DataDir == node.DefaultDataDir(): cfg.DataDir = filepath.Join(node.DefaultDataDir(), "web3q_mainnet") } @@ -1493,7 +1504,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, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag, SepoliaFlag, Web3QTestnetFlag, Web3QMainnetFlag) + CheckExclusive(ctx, MainnetFlag, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag, SepoliaFlag, Web3QTestnetFlag, Web3QGalileoFlag, Web3QMainnetFlag) CheckExclusive(ctx, LightServeFlag, SyncModeFlag, "light") CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer if ctx.GlobalString(GCModeFlag.Name) == "archive" && ctx.GlobalUint64(TxLookupLimitFlag.Name) != 0 { @@ -1661,6 +1672,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { } cfg.Genesis = core.DefaultWeb3QTestnetGenesisBlock() SetDNSDiscoveryDefaults(cfg, cfg.Genesis.ToBlock(nil).Hash()) + case ctx.GlobalBool(Web3QGalileoFlag.Name): + if !ctx.GlobalIsSet(NetworkIdFlag.Name) { + cfg.NetworkId = 3334 + } + cfg.Genesis = core.DefaultWeb3QGalileoGenesisBlock() + SetDNSDiscoveryDefaults(cfg, cfg.Genesis.ToBlock(nil).Hash()) case ctx.GlobalBool(Web3QMainnetFlag.Name): if !ctx.GlobalIsSet(NetworkIdFlag.Name) { cfg.NetworkId = 333 diff --git a/core/genesis.go b/core/genesis.go index 0658e7c55c1f..64ec74d583e8 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -442,7 +442,7 @@ func DefaultWeb3QTestnetGenesisBlock() *Genesis { // DefaultWeb3QGalileoGenesisBlock returns the Web3Q test network genesis block. func DefaultWeb3QGalileoGenesisBlock() *Genesis { return &Genesis{ - Config: params.Web3QTestnetChainConfig, + Config: params.Web3QGalileoChainConfig, Nonce: 0, ExtraData: hexutil.MustDecode("0x57656c636f6d6520746f20746865206272617665206e657720776f726c6421"), GasLimit: 30000000, @@ -451,6 +451,8 @@ func DefaultWeb3QGalileoGenesisBlock() *Genesis { Alloc: map[common.Address]GenesisAccount{ common.HexToAddress("0x0E961a6A6235eFDB9a0F0BC753E395211B77cc28"): {Balance: new(big.Int).Mul(big.NewInt(1000000000000000000), big.NewInt(1000000000))}, // 1e9 Ether }, + NextValidators: []common.Address{common.HexToAddress("0xC7B6Ad1038b5a79c12B066d6E3e8972f3EceaDe7")}, + NextValidatorPowers: []uint64{1}, } } diff --git a/core/types/gen_header_rlp.go b/core/types/gen_header_rlp.go index e1a687331853..2bac26e720b5 100644 --- a/core/types/gen_header_rlp.go +++ b/core/types/gen_header_rlp.go @@ -5,6 +5,7 @@ package types +import "github.com/ethereum/go-ethereum/common" import "github.com/ethereum/go-ethereum/rlp" import "io" @@ -41,7 +42,12 @@ func (obj *Header) EncodeRLP(_w io.Writer) error { w.WriteBytes(obj.MixDigest[:]) w.WriteBytes(obj.Nonce[:]) _tmp1 := obj.BaseFee != nil - if _tmp1 { + _tmp2 := obj.TimeMs != 0 + _tmp3 := len(obj.NextValidators) > 0 + _tmp4 := len(obj.NextValidatorPowers) > 0 + _tmp5 := obj.LastCommitHash != (common.Hash{}) + _tmp6 := obj.Commit != nil + if _tmp1 || _tmp2 || _tmp3 || _tmp4 || _tmp5 || _tmp6 { if obj.BaseFee == nil { w.Write(rlp.EmptyString) } else { @@ -51,6 +57,47 @@ func (obj *Header) EncodeRLP(_w io.Writer) error { w.WriteBigInt(obj.BaseFee) } } + if _tmp2 || _tmp3 || _tmp4 || _tmp5 || _tmp6 { + w.WriteUint64(obj.TimeMs) + } + if _tmp3 || _tmp4 || _tmp5 || _tmp6 { + _tmp7 := w.List() + for _, _tmp8 := range obj.NextValidators { + w.WriteBytes(_tmp8[:]) + } + w.ListEnd(_tmp7) + } + if _tmp4 || _tmp5 || _tmp6 { + _tmp9 := w.List() + for _, _tmp10 := range obj.NextValidatorPowers { + w.WriteUint64(_tmp10) + } + w.ListEnd(_tmp9) + } + if _tmp5 || _tmp6 { + w.WriteBytes(obj.LastCommitHash[:]) + } + if _tmp6 { + if obj.Commit == nil { + w.Write([]byte{0xC0}) + } else { + _tmp11 := w.List() + w.WriteUint64(obj.Commit.Height) + w.WriteUint64(uint64(obj.Commit.Round)) + w.WriteBytes(obj.Commit.BlockID[:]) + _tmp12 := w.List() + for _, _tmp13 := range obj.Commit.Signatures { + _tmp14 := w.List() + w.WriteUint64(uint64(_tmp13.BlockIDFlag)) + w.WriteBytes(_tmp13.ValidatorAddress[:]) + w.WriteUint64(_tmp13.TimestampMs) + w.WriteBytes(_tmp13.Signature) + w.ListEnd(_tmp14) + } + w.ListEnd(_tmp12) + w.ListEnd(_tmp11) + } + } w.ListEnd(_tmp0) return w.Flush() } diff --git a/params/bootnodes.go b/params/bootnodes.go index 897b5a462aca..d61e460eb8a1 100644 --- a/params/bootnodes.go +++ b/params/bootnodes.go @@ -81,6 +81,9 @@ var Web3QTestnetBootnodes = []string{ "enode://0b1f72bd2cdf8af6b42e1f1b24b1e927afd393de4a43f69f5bc402e2754d06bc140c3c3baac12f94aaf0aa4513f2b216c768c5d1a66f0b3b6c923575f0db64b1@128.199.102.174:30303", } +// TODO: to update +var Web3QGalileoBootnodes = []string{} + var Web3QMainnetBootnodes = []string{ "enode://0c2e9b39c4f8655d6cdd3dd3a57bee4fb1c20a3c844507b36bd806d7219048e3df6b7bc3dcc0a1830b59c7d25f983572c11a8ab8469e21a8d937f4ba84d98288@143.244.163.228:30303", "enode://50206144578410407a682aef0353f6efc9372efaf8c0077b3e37b9d87a7d548531da4df8e7682da976e446f9a71af96e7ab0b279c876d17b48da9b351633a373@128.199.163.220:30303", diff --git a/params/config.go b/params/config.go index f3a0e4990d47..7a818a2c907f 100644 --- a/params/config.go +++ b/params/config.go @@ -20,6 +20,7 @@ import ( "encoding/binary" "fmt" "math/big" + "time" "github.com/ethereum/go-ethereum/common" "golang.org/x/crypto/sha3" @@ -278,7 +279,7 @@ var ( // Web3QGalileoChainConfig contains the chain parameters to run a node on the Web3Q test network. Web3QGalileoChainConfig = &ChainConfig{ - ChainID: big.NewInt(3333), + ChainID: big.NewInt(3334), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, DAOForkSupport: true, @@ -293,9 +294,28 @@ var ( BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), ArrowGlacierBlock: nil, - Clique: &CliqueConfig{ - Period: 6, - Epoch: 100800, // one week + Tendermint: &TendermintConfig{ + Epoch: 100800, // expect 6s block interval = one week + P2pPort: 33333, + ProposerRepetition: 8, + P2pBootstrap: "/ip4/127.0.0.1/udp/33333/quic/p2p/12D3KooWRqZRJf6gYeLgeUnNCnKeRb29KiEVQcvRWk2tet9Q3Hmy", + NodeKeyPath: "/Users/qizhou/.ssh/node_galileo.key", + ValKeyPath: "/Users/qizhou/.ssh/val_galileo.key", + consensusConfig: ConsensusConfig{ + // WalPath: filepath.Join(defaultDataDir, "cs.wal", "wal"), + TimeoutPropose: 3000 * time.Millisecond, + TimeoutProposeDelta: 500 * time.Millisecond, + TimeoutPrevote: 1000 * time.Millisecond, + TimeoutPrevoteDelta: 500 * time.Millisecond, + TimeoutPrecommit: 1000 * time.Millisecond, + TimeoutPrecommitDelta: 500 * time.Millisecond, + TimeoutCommit: 5000 * time.Millisecond, + SkipTimeoutCommit: false, + PeerGossipSleepDuration: 100 * time.Millisecond, + PeerQueryMaj23SleepDuration: 2000 * time.Millisecond, + DoubleSignCheckHeight: uint64(0), + ConsensusSyncRequestDuration: 500 * time.Millisecond, + }, }, } @@ -451,6 +471,7 @@ type TendermintConfig struct { P2pBootstrap string NodeName string ProposerRepetition uint64 + consensusConfig ConsensusConfig } // String implements the stringer interface, returning the consensus engine details.