Skip to content

Commit

Permalink
Merge pull request #2500 from oasislabs/ptrus/feature/signature-count…
Browse files Browse the repository at this point in the history
…-tool

per entity signature count tool
  • Loading branch information
ptrus authored Dec 26, 2019
2 parents 87d942d + b8cc045 commit 609047e
Show file tree
Hide file tree
Showing 10 changed files with 425 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .changelog/2500.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Entity block signatures count tool.

The tool uses node consensus and registry API endpoints and computes the per
entity block signature counts.
4 changes: 2 additions & 2 deletions go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all: build

# Build.
# List of Go binaries to build.
go-binaries := oasis-node oasis-test-runner oasis-net-runner
go-binaries := oasis-node oasis-test-runner oasis-net-runner extra/stats
# List of test helpers to build.
test-helpers := urkel
# List of test vectors to generate.
Expand All @@ -22,7 +22,7 @@ generate:

$(go-binaries):
@$(ECHO) "$(MAGENTA)*** Building $@...$(OFF)"
@$(GO) build $(GOFLAGS) $(GO_EXTRA_FLAGS) -o ./$@/$@ ./$@
@$(GO) build $(GOFLAGS) $(GO_EXTRA_FLAGS) -o ./$@/$(notdir $@) ./$@

oasis-node:

Expand Down
3 changes: 2 additions & 1 deletion go/consensus/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"

beacon "github.com/oasislabs/oasis-core/go/beacon/api"
"github.com/oasislabs/oasis-core/go/common/cbor"
"github.com/oasislabs/oasis-core/go/common/crypto/signature"
"github.com/oasislabs/oasis-core/go/common/errors"
"github.com/oasislabs/oasis-core/go/common/node"
Expand Down Expand Up @@ -73,7 +74,7 @@ type Block struct {
// Height contains the block height.
Height int64 `json:"height"`
// Meta contains the consensus backend specific block metadata.
Meta interface{} `json:"meta"`
Meta cbor.RawMessage `json:"meta"`
}

// Backend is an interface that a consensus backend must provide.
Expand Down
12 changes: 8 additions & 4 deletions go/consensus/tendermint/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
tmp2p "github.com/tendermint/tendermint/p2p"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/oasislabs/oasis-core/go/common/cbor"
"github.com/oasislabs/oasis-core/go/common/crypto/signature"
"github.com/oasislabs/oasis-core/go/common/node"
consensus "github.com/oasislabs/oasis-core/go/consensus/api"
Expand Down Expand Up @@ -140,11 +141,14 @@ type BlockMeta struct {

// NewBlock creates a new consensus.Block from a Tendermint block.
func NewBlock(blk *tmtypes.Block) *consensus.Block {
meta := BlockMeta{
Header: &blk.Header,
LastCommit: blk.LastCommit,
}
rawMeta := cbor.Marshal(meta)

return &consensus.Block{
Height: blk.Header.Height,
Meta: BlockMeta{
Header: &blk.Header,
LastCommit: blk.LastCommit,
},
Meta: rawMeta,
}
}
4 changes: 4 additions & 0 deletions go/extra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Extra

This directory contains packages depending on (but not directly part of)
oasis-core.
1 change: 1 addition & 0 deletions go/extra/stats/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stats
19 changes: 19 additions & 0 deletions go/extra/stats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Stats

Queries a node for network stats. Currently implemented per entity block
signature counts.

## Usage

```
stats/stats entity-signatures \
--address unix:<node_dir>/internal.sock \
--start-block 0 \
--end-block 100 \
--top-n 100
|Rank |Entity ID |Nodes |Signatures|
------------------------------------------------------------------------------------------
|1 |ef9ccfc825d5f0087e56937c697b46520f29f81e21d8a289218a4ebaef00509c| 6| 100|
|2 |4ea5328f943ef6f66daaed74cb0e99c3b1c45f76307b425003dbc7cb3638ed35| 1| 80|
...
53 changes: 53 additions & 0 deletions go/extra/stats/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Package cmd implements stats cmd tool.
package cmd

import (
"fmt"

"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/oasislabs/oasis-core/go/common/logging"
"github.com/oasislabs/oasis-core/go/common/version"
"github.com/oasislabs/oasis-core/go/oasis-node/cmd/common"
)

const cfgLogLevel = "log.level"

var (
rootCmd = &cobra.Command{
Use: "stats",
Short: "Oasis stats",
Version: version.SoftwareVersion,
}

rootFlags = flag.NewFlagSet("", flag.ContinueOnError)
)

// RootCommand returns the root (top level) cobra.Command.
func RootCommand() *cobra.Command {
return rootCmd
}

// Execute spawns the main entry point after handling the command line arguments.
func Execute() {
var logLevel logging.Level
if err := logLevel.Set(viper.GetString(cfgLogLevel)); err != nil {
common.EarlyLogAndExit(fmt.Errorf("root: failed to set log level: %w", err))
}

if err := rootCmd.Execute(); err != nil {
common.EarlyLogAndExit(err)
}
}

func init() {
logLevel := logging.LevelInfo
rootFlags.Var(&logLevel, cfgLogLevel, "log level")
_ = viper.BindPFlags(rootFlags)
rootCmd.PersistentFlags().AddFlagSet(rootFlags)

// Register all of the sub-commands.
RegisterStatsCmd(rootCmd)
}
Loading

0 comments on commit 609047e

Please sign in to comment.