Skip to content

Commit

Permalink
Merge pull request #1830 from dedis/bcadmin_debug_wss
Browse files Browse the repository at this point in the history
adds wss to bcadmin debug
  • Loading branch information
Jeff R. Allen committed May 2, 2019
2 parents 9614ad9 + cf707ed commit 89654a2
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 80 deletions.
12 changes: 5 additions & 7 deletions byzcoin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"go.dedis.ch/cothority/v3/darc"
"go.dedis.ch/cothority/v3/darc/expression"
"go.dedis.ch/cothority/v3/skipchain"
"go.dedis.ch/kyber/v3"
"go.dedis.ch/kyber/v3/sign/schnorr"
"go.dedis.ch/onet/v3"
"go.dedis.ch/onet/v3/log"
Expand Down Expand Up @@ -364,26 +363,25 @@ func (c *Client) DownloadState(byzcoinID skipchain.SkipBlockID, nonce uint64, le
log.Error("Couldn't download from", c.Roster.List[index], ":", err)
index++
}
return nil, errors.New("Error while downloading state from nodes")
return nil, errors.New("error while downloading state from nodes")
}

// Debug can be used to dump things from a byzcoin service. If byzcoinID is nil, it will return all
// existing byzcoin instances. If byzcoinID is given, it will return all instances for that ID.
func Debug(addr network.Address, byzcoinID *skipchain.SkipBlockID) (reply *DebugResponse, err error) {
si := &network.ServerIdentity{Address: addr}
func Debug(url string, byzcoinID *skipchain.SkipBlockID) (reply *DebugResponse, err error) {
reply = &DebugResponse{}
request := &DebugRequest{}
if byzcoinID != nil {
request.ByzCoinID = *byzcoinID
}
si := &network.ServerIdentity{URL: url}
err = onet.NewClient(cothority.Suite, ServiceName).SendProtobuf(si, request, reply)
return
}

// DebugRemove deletes an existing byzcoin-instance from the conode.
func DebugRemove(addr network.Address, priv kyber.Scalar, byzcoinID skipchain.SkipBlockID) error {
si := &network.ServerIdentity{Address: addr}
sig, err := schnorr.Sign(cothority.Suite, priv, byzcoinID)
func DebugRemove(si *network.ServerIdentity, byzcoinID skipchain.SkipBlockID) error {
sig, err := schnorr.Sign(cothority.Suite, si.GetPrivate(), byzcoinID)
if err != nil {
return err
}
Expand Down
153 changes: 83 additions & 70 deletions byzcoin/bcadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"strings"
"time"

"github.com/BurntSushi/toml"
"github.com/qantik/qrgo"
"go.dedis.ch/cothority/v3"
"go.dedis.ch/cothority/v3/byzcoin"
Expand All @@ -27,8 +26,6 @@ import (
"go.dedis.ch/cothority/v3/darc"
"go.dedis.ch/cothority/v3/darc/expression"
"go.dedis.ch/cothority/v3/skipchain"
"go.dedis.ch/kyber/v3/suites"
"go.dedis.ch/kyber/v3/util/encoding"
"go.dedis.ch/kyber/v3/util/random"
"go.dedis.ch/onet/v3"
"go.dedis.ch/onet/v3/app"
Expand Down Expand Up @@ -111,10 +108,16 @@ var cmds = cli.Commands{
Aliases: []string{"d"},
Subcommands: cli.Commands{
{
Name: "list",
Usage: "Lists all byzcoin instances",
Action: debugList,
ArgsUsage: "ip:port",
Name: "list",
Usage: "Lists all byzcoin instances",
Action: debugList,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "verbose, v",
Usage: "print more information of the instances",
},
},
ArgsUsage: "(ip:port | group.toml)",
},
{
Name: "dump",
Expand Down Expand Up @@ -675,27 +678,21 @@ func getBcKeyPub(c *cli.Context) (cfg lib.Config, cl *byzcoin.Client, signer *da
err = errors.New("no TOML file provided")
return
}
grf, err := os.Open(fn)
f, err := os.Open(fn)
if err != nil {
err = fmt.Errorf("couldn't open %v: %v", fn, err.Error())
return
}
defer func() {
err := grf.Close()
if err != nil {
log.Error(err)
}
}()
gr, err := app.ReadGroupDescToml(grf)
defer f.Close()
group, err := app.ReadGroupDescToml(f)
if err != nil {
err = fmt.Errorf("couldn't load %v: %v", fn, err.Error())
err = fmt.Errorf("couldn't open %v: %v", fn, err.Error())
return
}
if len(gr.Roster.List) != 1 {
if len(group.Roster.List) != 1 {
err = errors.New("the TOML file should have exactly one entry")
return
}
pub = gr.Roster.List[0]
pub = group.Roster.List[0]

return
}
Expand Down Expand Up @@ -1067,42 +1064,77 @@ func darcShow(c *cli.Context) error {

func debugList(c *cli.Context) error {
if c.NArg() < 1 {
return errors.New("please give ip:port as argument")
return errors.New("please give (ip:port | group.toml) as argument")
}

resp, err := byzcoin.Debug(network.NewAddress(network.TLS, c.Args().First()), nil)
if err != nil {
return err
}
sort.SliceStable(resp.Byzcoins, func(i, j int) bool {
var iData byzcoin.DataHeader
var jData byzcoin.DataHeader
err := protobuf.Decode(resp.Byzcoins[i].Genesis.Data, &iData)
var urls []string
if f, err := os.Open(c.Args().First()); err == nil {
defer f.Close()
group, err := app.ReadGroupDescToml(f)
if err != nil {
return false
return err
}
err = protobuf.Decode(resp.Byzcoins[j].Genesis.Data, &jData)
if err != nil {
return false
for _, si := range group.Roster.List {
if si.URL != "" {
urls = append(urls, si.URL)
} else {
p, err := strconv.Atoi(si.Address.Port())
if err != nil {
return err
}
urls = append(urls, fmt.Sprintf("http://%s:%d", si.Address.Host(), p+1))
}
}
return iData.Timestamp > jData.Timestamp
})
for _, rb := range resp.Byzcoins {
log.Infof("ByzCoinID %x has", rb.ByzCoinID)
headerGenesis := byzcoin.DataHeader{}
headerLatest := byzcoin.DataHeader{}
err := protobuf.Decode(rb.Genesis.Data, &headerGenesis)
} else {
urls = []string{c.Args().First()}
}

for _, url := range urls {
log.Info("Contacting ", url)
resp, err := byzcoin.Debug(url, nil)
if err != nil {
return err
log.Error(err)
continue
}
err = protobuf.Decode(rb.Latest.Data, &headerLatest)
if err != nil {
return err
sort.SliceStable(resp.Byzcoins, func(i, j int) bool {
var iData byzcoin.DataHeader
var jData byzcoin.DataHeader
err := protobuf.Decode(resp.Byzcoins[i].Genesis.Data, &iData)
if err != nil {
return false
}
err = protobuf.Decode(resp.Byzcoins[j].Genesis.Data, &jData)
if err != nil {
return false
}
return iData.Timestamp > jData.Timestamp
})
for _, rb := range resp.Byzcoins {
log.Infof("ByzCoinID %x has", rb.ByzCoinID)
headerGenesis := byzcoin.DataHeader{}
headerLatest := byzcoin.DataHeader{}
err := protobuf.Decode(rb.Genesis.Data, &headerGenesis)
if err != nil {
log.Error(err)
continue
}
err = protobuf.Decode(rb.Latest.Data, &headerLatest)
if err != nil {
log.Error(err)
continue
}
log.Infof("\tBlocks: %d\n\tFrom %s to %s\tBlock hash: %x",
rb.Latest.Index,
time.Unix(headerGenesis.Timestamp/1e9, 0),
time.Unix(headerLatest.Timestamp/1e9, 0),
rb.Latest.Hash[:])
if c.Bool("verbose") {
log.Infof("\tGenesis block header: %+v\n\tLatest block header: %+v",
rb.Genesis.SkipBlockFix,
rb.Latest.SkipBlockFix)
}
log.Info()
}
log.Infof("\tBlocks: %d\n\tFrom %s to %s\n",
rb.Latest.Index,
time.Unix(headerGenesis.Timestamp/1e9, 0),
time.Unix(headerLatest.Timestamp/1e9, 0))
}
return nil
}
Expand All @@ -1118,7 +1150,7 @@ func debugDump(c *cli.Context) error {
return err
}
bcid := skipchain.SkipBlockID(bcidBuf)
resp, err := byzcoin.Debug(network.NewAddress(network.TLS, c.Args().First()), &bcid)
resp, err := byzcoin.Debug(c.Args().First(), &bcid)
if err != nil {
log.Error(err)
return err
Expand Down Expand Up @@ -1151,40 +1183,21 @@ func debugRemove(c *cli.Context) error {
return errors.New("please give the following arguments: private.toml byzcoin-id")
}

hc := &app.CothorityConfig{}
_, err := toml.DecodeFile(c.Args().First(), hc)
ccfg, err := app.LoadCothority(c.Args().First())
if err != nil {
return err
}

// Backwards compatibility with configs before we included the suite name
if hc.Suite == "" {
hc.Suite = "Ed25519"
}
suite, err := suites.Find(hc.Suite)
si, err := ccfg.GetServerIdentity()
if err != nil {
return err
}

// Try to decode the Hex values
private, err := encoding.StringHexToScalar(suite, hc.Private)
if err != nil {
return fmt.Errorf("parsing private key: %v", err)
}
point, err := encoding.StringHexToPoint(suite, hc.Public)
if err != nil {
return fmt.Errorf("parsing public key: %v", err)
}
si := network.NewServerIdentity(point, hc.Address)
si.SetPrivate(private)
si.Description = hc.Description
bcidBuf, err := hex.DecodeString(c.Args().Get(1))
if err != nil {
log.Error(err)
return err
}
bcid := skipchain.SkipBlockID(bcidBuf)
err = byzcoin.DebugRemove(si.Address, si.GetPrivate(), bcid)
err = byzcoin.DebugRemove(si, bcid)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions byzcoin/wallet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ func transfer(c *cli.Context) error {
{
InstanceID: iid,
Invoke: &byzcoin.Invoke{
Command: "transfer",
ContractID: contracts.ContractCoinID,
Command: "transfer",
Args: byzcoin.Arguments{
{
Name: "coins",
Expand All @@ -245,7 +246,7 @@ func transfer(c *cli.Context) error {
},
},
}
ctx.SignWith(signer)
ctx.FillSignersAndSignWith(signer)

log.Info("Sending transaction of", amount, "coins to address", c.Args().Get(1))
wait := 0
Expand Down Expand Up @@ -290,6 +291,7 @@ type siJSON struct {
ID string
Address string
Description string
URL string
}

type rosterJSON struct {
Expand Down Expand Up @@ -359,6 +361,7 @@ func loadConfig() (cfg config, cl *byzcoin.Client, err error) {
}
si := network.NewServerIdentity(pub, network.Address(siJ.Address))
si.Description = siJ.Description
si.URL = siJ.URL
var id []byte
id, err = hex.DecodeString(siJ.ID)
if err != nil {
Expand Down Expand Up @@ -416,6 +419,7 @@ func (cfg config) save() error {
ID: fmt.Sprintf("%x", si.ID[:]),
Address: string(si.Address),
Description: si.Description,
URL: si.URL,
})
}
d := cfg.BCConfig.AdminDarc
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/satori/go.uuid v1.2.0
github.com/stretchr/testify v1.3.0
go.dedis.ch/kyber/v3 v3.0.3
go.dedis.ch/onet/v3 v3.0.7
go.dedis.ch/onet/v3 v3.0.8
go.dedis.ch/protobuf v1.0.6
go.etcd.io/bbolt v1.3.2
golang.org/x/oauth2 v0.0.0-20190115181402-5dab4167f31c
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ go.dedis.ch/onet/v3 v3.0.6 h1:WWuBvNBW2Y/2UcmiszjCSwGva/Q16g1zUe+w8GC9GWI=
go.dedis.ch/onet/v3 v3.0.6/go.mod h1:0wrof0zfyD+Qfw9Pfhu9jW+bTbwwWBzC1hMuV/c8v2w=
go.dedis.ch/onet/v3 v3.0.7 h1:fyufYfqFE6YIi+jeAMb4F+eTCwCs6B8yiRLvDvDw/w4=
go.dedis.ch/onet/v3 v3.0.7/go.mod h1:0wrof0zfyD+Qfw9Pfhu9jW+bTbwwWBzC1hMuV/c8v2w=
go.dedis.ch/onet/v3 v3.0.8 h1:awxEfzpWh3JYiht8CeHx5T9G01xxujjinP/C5VYmkIM=
go.dedis.ch/onet/v3 v3.0.8/go.mod h1:0wrof0zfyD+Qfw9Pfhu9jW+bTbwwWBzC1hMuV/c8v2w=
go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo=
go.dedis.ch/protobuf v1.0.6 h1:E61p2XjYbYrTf3WeXE8M8Ui5WA3hX/NgbHHi5D0FLxI=
go.dedis.ch/protobuf v1.0.6/go.mod h1:YHYXW6dQ9p2iJ3f+2fxKnOpjGx0MvL4cwpg1RVNXaV8=
Expand Down

0 comments on commit 89654a2

Please sign in to comment.