Skip to content

Commit 4c8c5e2

Browse files
karalabefjl
authored andcommitted
cmd, ethstats, les, mobile, params: native netstats (bnb-chain#3336)
1 parent d1a95c6 commit 4c8c5e2

8 files changed

Lines changed: 533 additions & 46 deletions

File tree

‎cmd/geth/consolecmd_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"testing"
2929
"time"
3030

31-
"github.com/ethereum/go-ethereum/cmd/utils"
31+
"github.com/ethereum/go-ethereum/params"
3232
"github.com/ethereum/go-ethereum/rpc"
3333
)
3434

@@ -46,7 +46,7 @@ func TestConsoleWelcome(t *testing.T) {
4646
// Gather all the infos the welcome message needs to contain
4747
geth.setTemplateFunc("goos", func() string { return runtime.GOOS })
4848
geth.setTemplateFunc("gover", runtime.Version)
49-
geth.setTemplateFunc("gethver", func() string { return utils.Version })
49+
geth.setTemplateFunc("gethver", func() string { return params.Version })
5050
geth.setTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
5151
geth.setTemplateFunc("apis", func() []string {
5252
apis := append(strings.Split(rpc.DefaultIPCApis, ","), rpc.MetadataApi)
@@ -132,7 +132,7 @@ func testAttachWelcome(t *testing.T, geth *testgeth, endpoint string) {
132132
// Gather all the infos the welcome message needs to contain
133133
attach.setTemplateFunc("goos", func() string { return runtime.GOOS })
134134
attach.setTemplateFunc("gover", runtime.Version)
135-
attach.setTemplateFunc("gethver", func() string { return utils.Version })
135+
attach.setTemplateFunc("gethver", func() string { return params.Version })
136136
attach.setTemplateFunc("etherbase", func() string { return geth.Etherbase })
137137
attach.setTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
138138
attach.setTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") })

‎cmd/geth/main.go‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import (
4040
"github.com/ethereum/go-ethereum/logger/glog"
4141
"github.com/ethereum/go-ethereum/metrics"
4242
"github.com/ethereum/go-ethereum/node"
43+
"github.com/ethereum/go-ethereum/params"
44+
"github.com/ethereum/go-ethereum/rlp"
4345
"gopkg.in/urfave/cli.v1"
4446
)
4547

@@ -173,6 +175,7 @@ participating.
173175
utils.VMEnableJitFlag,
174176
utils.NetworkIdFlag,
175177
utils.RPCCORSDomainFlag,
178+
utils.EthStatsURLFlag,
176179
utils.MetricsEnabledFlag,
177180
utils.FakePoWFlag,
178181
utils.SolcPathFlag,
@@ -254,31 +257,49 @@ func initGenesis(ctx *cli.Context) error {
254257
}
255258

256259
func makeFullNode(ctx *cli.Context) *node.Node {
260+
// Create the default extradata and construct the base node
261+
var clientInfo = struct {
262+
Version uint
263+
Name string
264+
GoVersion string
265+
Os string
266+
}{uint(params.VersionMajor<<16 | params.VersionMinor<<8 | params.VersionPatch), clientIdentifier, runtime.Version(), runtime.GOOS}
267+
extra, err := rlp.EncodeToBytes(clientInfo)
268+
if err != nil {
269+
glog.V(logger.Warn).Infoln("error setting canonical miner information:", err)
270+
}
271+
if uint64(len(extra)) > params.MaximumExtraDataSize.Uint64() {
272+
glog.V(logger.Warn).Infoln("error setting canonical miner information: extra exceeds", params.MaximumExtraDataSize)
273+
glog.V(logger.Debug).Infof("extra: %x\n", extra)
274+
extra = nil
275+
}
257276
stack := utils.MakeNode(ctx, clientIdentifier, gitCommit)
258-
utils.RegisterEthService(ctx, stack, utils.MakeDefaultExtraData(clientIdentifier))
277+
utils.RegisterEthService(ctx, stack, extra)
259278

260279
// Whisper must be explicitly enabled, but is auto-enabled in --dev mode.
261280
shhEnabled := ctx.GlobalBool(utils.WhisperEnabledFlag.Name)
262281
shhAutoEnabled := !ctx.GlobalIsSet(utils.WhisperEnabledFlag.Name) && ctx.GlobalIsSet(utils.DevModeFlag.Name)
263282
if shhEnabled || shhAutoEnabled {
264283
utils.RegisterShhService(stack)
265284
}
266-
285+
// Add the Ethereum Stats daemon if requested
286+
if url := ctx.GlobalString(utils.EthStatsURLFlag.Name); url != "" {
287+
utils.RegisterEthStatsService(stack, url)
288+
}
267289
// Add the release oracle service so it boots along with node.
268290
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
269291
config := release.Config{
270292
Oracle: relOracle,
271-
Major: uint32(utils.VersionMajor),
272-
Minor: uint32(utils.VersionMinor),
273-
Patch: uint32(utils.VersionPatch),
293+
Major: uint32(params.VersionMajor),
294+
Minor: uint32(params.VersionMinor),
295+
Patch: uint32(params.VersionPatch),
274296
}
275297
commit, _ := hex.DecodeString(gitCommit)
276298
copy(config.Commit[:], commit)
277299
return release.NewReleaseService(ctx, config)
278300
}); err != nil {
279301
utils.Fatalf("Failed to register the Geth release oracle service: %v", err)
280302
}
281-
282303
return stack
283304
}
284305

@@ -342,7 +363,7 @@ func makedag(ctx *cli.Context) error {
342363

343364
func version(ctx *cli.Context) error {
344365
fmt.Println(strings.Title(clientIdentifier))
345-
fmt.Println("Version:", utils.Version)
366+
fmt.Println("Version:", params.Version)
346367
if gitCommit != "" {
347368
fmt.Println("Git Commit:", gitCommit)
348369
}

‎cmd/geth/usage.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ var AppHelpFlagGroups = []flagGroup{
161161
{
162162
Name: "LOGGING AND DEBUGGING",
163163
Flags: append([]cli.Flag{
164+
utils.EthStatsURLFlag,
164165
utils.MetricsEnabledFlag,
165166
utils.FakePoWFlag,
166167
}, debug.Flags...),

‎cmd/utils/flags.go‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
1616

17+
// Package utils contains internal helper functions for go-ethereum commands.
1718
package utils
1819

1920
import (
@@ -36,6 +37,7 @@ import (
3637
"github.com/ethereum/go-ethereum/crypto"
3738
"github.com/ethereum/go-ethereum/eth"
3839
"github.com/ethereum/go-ethereum/ethdb"
40+
"github.com/ethereum/go-ethereum/ethstats"
3941
"github.com/ethereum/go-ethereum/event"
4042
"github.com/ethereum/go-ethereum/les"
4143
"github.com/ethereum/go-ethereum/logger"
@@ -86,7 +88,7 @@ func NewApp(gitCommit, usage string) *cli.App {
8688
app.Author = ""
8789
//app.Authors = nil
8890
app.Email = ""
89-
app.Version = Version
91+
app.Version = params.Version
9092
if gitCommit != "" {
9193
app.Version += "-" + gitCommit[:8]
9294
}
@@ -242,8 +244,11 @@ var (
242244
Name: "jitvm",
243245
Usage: "Enable the JIT VM",
244246
}
245-
246-
// logging and debug settings
247+
// Logging and debug settings
248+
EthStatsURLFlag = cli.StringFlag{
249+
Name: "ethstats",
250+
Usage: "Reporting URL of a ethstats service (nodename:secret@host:port)",
251+
}
247252
MetricsEnabledFlag = cli.BoolFlag{
248253
Name: metrics.MetricsEnabledFlag,
249254
Usage: "Enable metrics collection and reporting",
@@ -660,7 +665,7 @@ func MakePasswordList(ctx *cli.Context) []string {
660665

661666
// MakeNode configures a node with no services from command line flags.
662667
func MakeNode(ctx *cli.Context, name, gitCommit string) *node.Node {
663-
vsn := Version
668+
vsn := params.Version
664669
if gitCommit != "" {
665670
vsn += "-" + gitCommit[:8]
666671
}
@@ -801,13 +806,30 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
801806
}
802807
}
803808

804-
// RegisterShhService configures whisper and adds it to the given node.
809+
// RegisterShhService configures Whisper and adds it to the given node.
805810
func RegisterShhService(stack *node.Node) {
806811
if err := stack.Register(func(*node.ServiceContext) (node.Service, error) { return whisper.New(), nil }); err != nil {
807812
Fatalf("Failed to register the Whisper service: %v", err)
808813
}
809814
}
810815

816+
// RegisterEthStatsService configures the Ethereum Stats daemon and adds it to
817+
// th egiven node.
818+
func RegisterEthStatsService(stack *node.Node, url string) {
819+
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
820+
// Retrieve both eth and les services
821+
var ethServ *eth.Ethereum
822+
ctx.Service(&ethServ)
823+
824+
var lesServ *les.LightEthereum
825+
ctx.Service(&lesServ)
826+
827+
return ethstats.New(url, ethServ, lesServ)
828+
}); err != nil {
829+
Fatalf("Failed to register the Ethereum Stats service: %v", err)
830+
}
831+
}
832+
811833
// SetupNetwork configures the system for either the main net or some test network.
812834
func SetupNetwork(ctx *cli.Context) {
813835
switch {

0 commit comments

Comments
 (0)