From 4401581ef18851166b4acd6c53f90c078bba3634 Mon Sep 17 00:00:00 2001
From: Arpit Agarwal <93arpit@gmail.com>
Date: Tue, 7 Apr 2020 10:56:29 +0530
Subject: [PATCH] dev: Provide Heimdall URL as flag instead of in genesis (#46)
---
cmd/bor/config.go | 3 +++
cmd/bor/main.go | 5 +++++
cmd/bor/usage.go | 4 ++++
cmd/puppeth/wizard_genesis.go | 1 -
cmd/utils/flags.go | 8 +++++++-
consensus/bor/bor.go | 3 ++-
consensus/bor/bor_test/genesis.json | 3 +--
eth/backend.go | 12 ++++++++----
eth/config.go | 3 +++
params/config.go | 1 -
10 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/cmd/bor/config.go b/cmd/bor/config.go
index b525cedb0..4929d826e 100644
--- a/cmd/bor/config.go
+++ b/cmd/bor/config.go
@@ -29,6 +29,7 @@ import (
"github.com/maticnetwork/bor/cmd/utils"
"github.com/maticnetwork/bor/dashboard"
"github.com/maticnetwork/bor/eth"
+ "github.com/maticnetwork/bor/log"
"github.com/maticnetwork/bor/node"
"github.com/maticnetwork/bor/params"
whisper "github.com/maticnetwork/bor/whisper/whisperv6"
@@ -150,6 +151,8 @@ func enableWhisper(ctx *cli.Context) bool {
func makeFullNode(ctx *cli.Context) *node.Node {
stack, cfg := makeConfigNode(ctx)
+ cfg.Eth.HeimdallURL = ctx.String(utils.HeimdallURLFlag.Name)
+ log.Info("Connecting to heimdall service on...", "heimdallURL", cfg.Eth.HeimdallURL)
utils.RegisterEthService(stack, &cfg.Eth)
if ctx.GlobalBool(utils.DashboardEnabledFlag.Name) {
diff --git a/cmd/bor/main.go b/cmd/bor/main.go
index d187f40d7..d5ba1b9f6 100644
--- a/cmd/bor/main.go
+++ b/cmd/bor/main.go
@@ -190,6 +190,10 @@ var (
utils.MetricsInfluxDBPasswordFlag,
utils.MetricsInfluxDBTagsFlag,
}
+
+ borFlags = []cli.Flag{
+ utils.HeimdallURLFlag,
+ }
)
func init() {
@@ -233,6 +237,7 @@ func init() {
app.Flags = append(app.Flags, debug.Flags...)
app.Flags = append(app.Flags, whisperFlags...)
app.Flags = append(app.Flags, metricsFlags...)
+ app.Flags = append(app.Flags, borFlags...)
app.Before = func(ctx *cli.Context) error {
logdir := ""
diff --git a/cmd/bor/usage.go b/cmd/bor/usage.go
index 6d3260e70..fe680d31c 100644
--- a/cmd/bor/usage.go
+++ b/cmd/bor/usage.go
@@ -246,6 +246,10 @@ var AppHelpFlagGroups = []flagGroup{
Name: "METRICS AND STATS",
Flags: metricsFlags,
},
+ {
+ Name: "BOR",
+ Flags: borFlags,
+ },
{
Name: "WHISPER (EXPERIMENTAL)",
Flags: whisperFlags,
diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go
index 439143586..695005f09 100644
--- a/cmd/puppeth/wizard_genesis.go
+++ b/cmd/puppeth/wizard_genesis.go
@@ -113,7 +113,6 @@ func (w *wizard) makeGenesis() {
Sprint: 60,
ValidatorContract: "0x0000000000000000000000000000000000001000",
StateReceiverContract: "0x0000000000000000000000000000000000001001",
- Heimdall: "http://localhost:1317",
}
// We also need the initial list of signers
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 94f79edc6..fa0aa9bf1 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -741,6 +741,13 @@ var (
Usage: "External EVM configuration (default = built-in interpreter)",
Value: "",
}
+
+ // Bor Specific flags
+ HeimdallURLFlag = cli.StringFlag{
+ Name: "heimdall",
+ Usage: "URL of Heimdall service",
+ Value: "http://localhost:1317",
+ }
)
// MakeDataDir retrieves the currently requested data directory, terminating
@@ -1161,7 +1168,6 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
setNodeUserIdent(ctx, cfg)
setDataDir(ctx, cfg)
setSmartCard(ctx, cfg)
-
if ctx.GlobalIsSet(ExternalSignerFlag.Name) {
cfg.ExternalSigner = ctx.GlobalString(ExternalSignerFlag.Name)
}
diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go
index bd55a745e..a59fecd2e 100644
--- a/consensus/bor/bor.go
+++ b/consensus/bor/bor.go
@@ -257,6 +257,7 @@ func New(
chainConfig *params.ChainConfig,
db ethdb.Database,
ethAPI *ethapi.PublicBlockChainAPI,
+ heimdallURL string,
) *Bor {
// get bor config
borConfig := chainConfig.Bor
@@ -271,7 +272,7 @@ func New(
signatures, _ := lru.NewARC(inmemorySignatures)
vABI, _ := abi.JSON(strings.NewReader(validatorsetABI))
sABI, _ := abi.JSON(strings.NewReader(stateReceiverABI))
- heimdallClient, _ := NewHeimdallClient(chainConfig.Bor.Heimdall)
+ heimdallClient, _ := NewHeimdallClient(heimdallURL)
c := &Bor{
chainConfig: chainConfig,
diff --git a/consensus/bor/bor_test/genesis.json b/consensus/bor/bor_test/genesis.json
index 737cb600d..32b9cd5b2 100644
--- a/consensus/bor/bor_test/genesis.json
+++ b/consensus/bor/bor_test/genesis.json
@@ -13,8 +13,7 @@
"producerDelay": 4,
"sprint": 1,
"validatorContract": "0x0000000000000000000000000000000000001000",
- "stateReceiverContract": "0x0000000000000000000000000000000000001001",
- "heimdall": "http://localhost:1317"
+ "stateReceiverContract": "0x0000000000000000000000000000000000001001"
}
},
"nonce": "0x0",
diff --git a/eth/backend.go b/eth/backend.go
index edb253111..271103c99 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -165,7 +165,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
}
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
ethAPI := ethapi.NewPublicBlockChainAPI(eth.APIBackend)
- eth.engine = CreateConsensusEngine(ctx, chainConfig, &config.Ethash, config.Miner.Notify, config.Miner.Noverify, chainDb, ethAPI)
+ eth.engine = CreateConsensusEngine(ctx, chainConfig, config, chainDb, ethAPI)
bcVersion := rawdb.ReadDatabaseVersion(chainDb)
var dbVer = "<nil>"
@@ -252,8 +252,12 @@ func makeExtraData(extra []byte) []byte {
return extra
}
-// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
-func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database, ee *ethapi.PublicBlockChainAPI) consensus.Engine {
+// func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database, ee *ethapi.PublicBlockChainAPI) consensus.Engine {
+func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainConfig, ethConfig *Config, db ethdb.Database, ee *ethapi.PublicBlockChainAPI) consensus.Engine {
+ config := ðConfig.Ethash
+ notify := ethConfig.Miner.Notify
+ noverify := ethConfig.Miner.Noverify
+
// If proof-of-authority is requested, set it up
if chainConfig.Clique != nil {
return clique.New(chainConfig.Clique, db)
@@ -261,7 +265,7 @@ func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainCo
// If Matic Bor is requested, set it up
if chainConfig.Bor != nil {
- return bor.New(chainConfig, db, ee)
+ return bor.New(chainConfig, db, ee, ethConfig.HeimdallURL)
}
// Otherwise assume proof-of-work
diff --git a/eth/config.go b/eth/config.go
index f201b7cc9..60bf9d359 100644
--- a/eth/config.go
+++ b/eth/config.go
@@ -154,4 +154,7 @@ type Config struct {
// CheckpointOracle is the configuration for checkpoint oracle.
CheckpointOracle *params.CheckpointOracleConfig
+
+ // URL to connect to Heimdall node
+ HeimdallURL string
}
diff --git a/params/config.go b/params/config.go
index 0573a7628..e56336fe2 100644
--- a/params/config.go
+++ b/params/config.go
@@ -321,7 +321,6 @@ type BorConfig struct {
Sprint uint64 `json:"sprint"` // Epoch length to proposer
ValidatorContract string `json:"validatorContract"` // Validator set contract
StateReceiverContract string `json:"stateReceiverContract"` // State receiver contract
- Heimdall string `json:"heimdall"` // heimdall light client url
}
// String implements the stringer interface, returning the consensus engine details.
--
GitLab