diff --git a/cmd/opera/launcher/config.go b/cmd/opera/launcher/config.go index 693b6a749..388dca428 100644 --- a/cmd/opera/launcher/config.go +++ b/cmd/opera/launcher/config.go @@ -367,8 +367,11 @@ func mayMakeAllConfigs(ctx *cli.Context) (*config, error) { if ctx.GlobalIsSet(FakeNetFlag.Name) { _, num, _ := parseFakeGen(ctx.GlobalString(FakeNetFlag.Name)) cfg.Emitter = emitter.FakeConfig(num) + setBootnodes(ctx, []string{}, &cfg.Node) } else { - setBootnodes(ctx, Bootnodes, &cfg.Node) + // "asDefault" means set network defaults + cfg.Node.P2P.BootstrapNodes = asDefault + cfg.Node.P2P.BootstrapNodesV5 = asDefault } // Load config file (medium priority) diff --git a/cmd/opera/launcher/launcher.go b/cmd/opera/launcher/launcher.go index be648105b..79f54fb16 100644 --- a/cmd/opera/launcher/launcher.go +++ b/cmd/opera/launcher/launcher.go @@ -281,8 +281,6 @@ func makeNode(ctx *cli.Context, cfg *config, genesisStore *genesisstore.Store) ( errlock.SetDefaultDatadir(cfg.Node.DataDir) errlock.Check() - stack := makeConfigNode(ctx, &cfg.Node) - chaindataDir := path.Join(cfg.Node.DataDir, "chaindata") if err := os.MkdirAll(chaindataDir, 0700); err != nil { utils.Fatalf("Failed to create chaindata directory: %v", err) @@ -298,6 +296,24 @@ func makeNode(ctx *cli.Context, cfg *config, genesisStore *genesisstore.Store) ( } metrics.SetDataDir(cfg.Node.DataDir) + // substitute default bootnodes if requested + networkName := "" + if gdb.HasBlockEpochState() { + networkName = gdb.GetRules().Name + } + if len(networkName) == 0 && genesisStore != nil { + networkName = genesisStore.Header().NetworkName + } + if len(cfg.Node.P2P.BootstrapNodes) == len(asDefault) && cfg.Node.P2P.BootstrapNodes[0] == asDefault[0] { + bootnodes := Bootnodes[networkName] + if bootnodes == nil { + bootnodes = []string{} + } + setBootnodes(ctx, bootnodes, &cfg.Node) + } + + stack := makeConfigNode(ctx, &cfg.Node) + valKeystore := valkeystore.NewDefaultFileKeystore(path.Join(getValKeystoreDir(cfg.Node), "validator")) valPubkey := cfg.Emitter.Validator.PubKey if key := getFakeValidatorKey(ctx); key != nil && cfg.Emitter.Validator.ID != 0 { diff --git a/cmd/opera/launcher/params.go b/cmd/opera/launcher/params.go index 2703b0a28..261276d8b 100644 --- a/cmd/opera/launcher/params.go +++ b/cmd/opera/launcher/params.go @@ -2,6 +2,7 @@ package launcher import ( "github.com/Fantom-foundation/lachesis-base/hash" + "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/params" "github.com/Fantom-foundation/go-opera/opera" @@ -10,17 +11,24 @@ import ( ) var ( - Bootnodes = []string{ - "enode://03c70d4597d731ef182678b7664f2a4a3add07056f23d4e01aba86f066080d18fa13abbd2e13e9d4ea762a2715a983b5ac6151162d05ee0434f1847da1a626e9@34.242.220.16:5050", - "enode://01c64d1a9dd8a65c56f2d4e373795eb6efd27b714b2b5999363a42a0edc39d7417a431416ceb5c67b1a170983af109e8a15d0c2d44a2ac41ecfb5c23c1a1a48a@3.35.200.210:5050", - "enode://7044c88daa5df059e2f7a2667471a8149a5cf66e68643dcb86f399d48c4ff6475b73ee91486ea830d225f7f78a2fdf955208673da51c6852230c3a90a3701c06@3.1.103.70:5050", - "enode://594d26c2338566daca9391d73f1b1821bb0b454e6f3d48715116bf42f320924d569534c143b640feec8a8eaa137a0b822426fb62b52a90162270ea5868bdc37c@18.138.254.181:5050", - "enode://339e331912e5239a9e13eb82b47be58ea4d3946e91caa2992103a8d4f0226c1e86f9134822d5b238f25c9cbdd473f806caa8e4f8ef1748a6c66395f4bf0dd569@54.66.206.151:5050", - "enode://563b30428f48357f31c9d4906ca2f3d3815d663b151302c1ba9d58f3428265b554398c6fabf4b806a49525670cd9e031257c805375b9fdbcc015f60a7943e427@3.213.142.230:7946", - "enode://8b53fe4410cde82d98d28697d56ccb793f9a67b1f8807c523eadafe96339d6e56bc82c0e702757ac5010972e966761b1abecb4935d9a86a9feed47e3e9ba27a6@3.227.34.226:7946", - "enode://1703640d1239434dcaf010541cafeeb3c4c707be9098954c50aa705f6e97e2d0273671df13f6e447563e7d3a7c7ffc88de48318d8a3cc2cc59d196516054f17e@52.72.222.228:7946", + Bootnodes = map[string][]string{ + "main": { + "enode://03c70d4597d731ef182678b7664f2a4a3add07056f23d4e01aba86f066080d18fa13abbd2e13e9d4ea762a2715a983b5ac6151162d05ee0434f1847da1a626e9@34.242.220.16:5050", + "enode://01c64d1a9dd8a65c56f2d4e373795eb6efd27b714b2b5999363a42a0edc39d7417a431416ceb5c67b1a170983af109e8a15d0c2d44a2ac41ecfb5c23c1a1a48a@3.35.200.210:5050", + "enode://7044c88daa5df059e2f7a2667471a8149a5cf66e68643dcb86f399d48c4ff6475b73ee91486ea830d225f7f78a2fdf955208673da51c6852230c3a90a3701c06@3.1.103.70:5050", + "enode://594d26c2338566daca9391d73f1b1821bb0b454e6f3d48715116bf42f320924d569534c143b640feec8a8eaa137a0b822426fb62b52a90162270ea5868bdc37c@18.138.254.181:5050", + "enode://339e331912e5239a9e13eb82b47be58ea4d3946e91caa2992103a8d4f0226c1e86f9134822d5b238f25c9cbdd473f806caa8e4f8ef1748a6c66395f4bf0dd569@54.66.206.151:5050", + }, + "test": { + "enode://563b30428f48357f31c9d4906ca2f3d3815d663b151302c1ba9d58f3428265b554398c6fabf4b806a49525670cd9e031257c805375b9fdbcc015f60a7943e427@3.213.142.230:7946", + "enode://8b53fe4410cde82d98d28697d56ccb793f9a67b1f8807c523eadafe96339d6e56bc82c0e702757ac5010972e966761b1abecb4935d9a86a9feed47e3e9ba27a6@3.227.34.226:7946", + "enode://1703640d1239434dcaf010541cafeeb3c4c707be9098954c50aa705f6e97e2d0273671df13f6e447563e7d3a7c7ffc88de48318d8a3cc2cc59d196516054f17e@52.72.222.228:7946", + }, } + // asDefault is slice with one empty element which indicates that network default bootnodes should be substituted + asDefault = []*enode.Node{{}} + mainnetHeader = genesis.Header{ GenesisID: hash.HexToHash("0x4a53c5445584b3bfc20dbfb2ec18ae20037c716f3ba2d9e1da768a9deca17cb4"), NetworkID: opera.MainNetworkID, diff --git a/gossip/store_decided_state.go b/gossip/store_decided_state.go index 50903a9f3..787092d77 100644 --- a/gossip/store_decided_state.go +++ b/gossip/store_decided_state.go @@ -69,6 +69,11 @@ func (s *Store) HasHistoryBlockEpochState(epoch idx.Epoch) bool { return has } +func (s *Store) HasBlockEpochState() bool { + has, _ := s.table.BlockEpochState.Has([]byte(sKey)) + return has +} + // SetBlockEpochState stores the latest block and epoch state in memory func (s *Store) SetBlockEpochState(bs iblockproc.BlockState, es iblockproc.EpochState) { bs, es = bs.Copy(), es.Copy()