Browse Source

add longestchain and notarized to lightinfod

master
Denio 5 years ago
parent
commit
0978322f62
  1. 4
      cmd/server/main.go
  2. 14
      common/common.go
  3. 4
      frontend/service.go
  4. 14
      walletrpc/service.pb.go
  5. 4
      walletrpc/service.proto

4
cmd/server/main.go

@ -168,14 +168,14 @@ func main() {
}
// Get the sapling activation height from the RPC
saplingHeight, blockHeight, chainName, branchID, difficulty, err := common.GetSaplingInfo(rpcClient)
saplingHeight, blockHeight, chainName, branchID, difficulty, longestchain, notarized, err := common.GetSaplingInfo(rpcClient)
if err != nil {
log.WithFields(logrus.Fields{
"error": err,
}).Warn("Unable to get sapling activation height")
}
log.Info("Got sapling height ", saplingHeight, " chain ", chainName, " branchID ", branchID," difficulty ", difficulty,)
log.Info("Got sapling height ", saplingHeight, " chain ", chainName, " branchID ", branchID," difficulty ", difficulty,longestchain, " longestchain ",notarized," notarized ")
// Initialize the cache
cache := common.NewBlockCache(opts.cacheSize)

14
common/common.go

@ -15,7 +15,7 @@ import (
"github.com/sirupsen/logrus"
)
func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int, error) {
func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int,int,int, error) {
result, rpcErr := rpcClient.RawRequest("getblockchaininfo", make([]json.RawMessage, 0))
var err error
@ -27,15 +27,15 @@ func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int,
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
//Check to see if we are requesting a height the hushd doesn't have yet
if err == nil && errCode == -8 {
return -1, -1, "", "",-1, nil
return -1, -1, "", "",-1,-1,-1, nil
}
return -1, -1, "", "",-1, errors.Wrap(rpcErr, "error requesting block")
return -1, -1, "", "",-1,-1,-1, errors.Wrap(rpcErr, "error requesting block")
}
var f interface{}
err = json.Unmarshal(result, &f)
if err != nil {
return -1, -1, "", "",-1, errors.Wrap(err, "error reading JSON response")
return -1, -1, "", "",-1,-1,-1, errors.Wrap(err, "error reading JSON response")
}
chainName := f.(map[string]interface{})["chain"].(string)
@ -45,12 +45,14 @@ func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int,
saplingHeight := saplingJSON.(map[string]interface{})["activationheight"].(float64)
blockHeight := f.(map[string]interface{})["headers"].(float64)
difficulty := f.(map[string]interface{})["difficulty"].(float64)
difficulty := f.(map[string]interface{})["difficulty"].(float64)
longestchain := f.(map[string]interface{})["longestchain"].(float64)
notarized := f.(map[string]interface{})["notarized"].(float64)
consensus := f.(map[string]interface{})["consensus"]
branchID := consensus.(map[string]interface{})["nextblock"].(string)
return int(saplingHeight), int(blockHeight), chainName, branchID, int(difficulty), nil
return int(saplingHeight), int(blockHeight), chainName, branchID, int(difficulty), int(longestchain), int(notarized), nil
}
func getBlockFromRPC(rpcClient *rpcclient.Client, height int) (*walletrpc.CompactBlock, error) {

4
frontend/service.go

@ -229,7 +229,7 @@ func (s *SqlStreamer) GetTransaction(ctx context.Context, txf *walletrpc.TxFilte
// GetLightdInfo gets the LightWalletD (this server) info
func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (*walletrpc.LightdInfo, error) {
saplingHeight, blockHeight, chainName, consensusBranchId, difficulty, err := common.GetSaplingInfo(s.client)
saplingHeight, blockHeight, chainName, consensusBranchId, difficulty, longestchain, notarized, err := common.GetSaplingInfo(s.client)
if err != nil {
s.log.WithFields(logrus.Fields{
@ -249,6 +249,8 @@ func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (*
ConsensusBranchId: consensusBranchId,
BlockHeight: uint64(blockHeight),
Difficulty: uint64(difficulty),
Longestchain: uint64(longestchain),
Notarized: uint64(notarized),
}, nil
}

14
walletrpc/service.pb.go

@ -348,6 +348,8 @@ type LightdInfo struct {
ConsensusBranchId string `protobuf:"bytes,6,opt,name=consensusBranchId,proto3" json:"consensusBranchId,omitempty"`
BlockHeight uint64 `protobuf:"varint,7,opt,name=blockHeight,proto3" json:"blockHeight,omitempty"`
Difficulty uint64 `protobuf:"varint,8,opt,name=difficulty,proto3" json:"difficulty,omitempty"`
Longestchain uint64 `protobuf:"varint,9,opt,name=longestchain,proto3" json:"longestchain,omitempty"`
Notarized uint64 `protobuf:"varint,10,opt,name=notarized,proto3" json:"notarized,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -425,6 +427,18 @@ func (m *LightdInfo) Getdifficulty() uint64 {
}
return 0
}
func (m *LightdInfo) Getlongestchain() uint64 {
if m != nil {
return m.Longestchain
}
return 0
}
func (m *LightdInfo) Getnotarized() uint64 {
if m != nil {
return m.Notarized
}
return 0
}
func (m *LightdInfo) GetBlockHeight() uint64 {
if m != nil {

4
walletrpc/service.proto

@ -52,7 +52,9 @@ message LightdInfo {
uint64 saplingActivationHeight = 5;
string consensusBranchId = 6; // This should really be u32 or []byte, but string for readability
uint64 blockHeight = 7;
string difficulty = 8;
uint64 difficulty = 8;
uint64 longestchain = 9;
uint64 notarized = 10;
}
message TransparentAddress {

Loading…
Cancel
Save