Browse Source

Merge pull request #1511 from tendermint/bucky/rpc-fixes

Various RPC fixes
pull/1514/head
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
1188dfe7ee
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 110 additions and 22 deletions
  1. +24
    -0
      consensus/types/height_vote_set.go
  2. +12
    -0
      consensus/types/wire.go
  3. +11
    -11
      node/node.go
  4. +8
    -4
      p2p/node_info.go
  5. +10
    -6
      rpc/core/status.go
  6. +1
    -0
      rpc/core/types/responses.go
  7. +17
    -0
      types/part_set.go
  8. +27
    -1
      types/vote_set.go

+ 24
- 0
consensus/types/height_vote_set.go View File

@ -207,6 +207,30 @@ func (hvs *HeightVoteSet) StringIndented(indent string) string {
indent) indent)
} }
type roundVoteBitArrays struct {
Round int `json:"round"`
Prevotes *cmn.BitArray `json:"prevotes"`
Precommits *cmn.BitArray `json:"precommits"`
}
func (hvs *HeightVoteSet) MarshalJSON() ([]byte, error) {
hvs.mtx.Lock()
defer hvs.mtx.Unlock()
totalRounds := hvs.round + 1
roundsVotes := make([]roundVoteBitArrays, totalRounds)
// rounds 0 ~ hvs.round inclusive
for round := 0; round < totalRounds; round++ {
roundsVotes[round] = roundVoteBitArrays{
Round: round,
Prevotes: hvs.roundVoteSets[round].Prevotes.BitArray(),
Precommits: hvs.roundVoteSets[round].Precommits.BitArray(),
}
}
// TODO: all other peer catchup rounds
return cdc.MarshalJSON(roundsVotes)
}
// If a peer claims that it has 2/3 majority for given blockKey, call this. // If a peer claims that it has 2/3 majority for given blockKey, call this.
// NOTE: if there are too many peers, or too much peer churn, // NOTE: if there are too many peers, or too much peer churn,
// this can cause memory issues. // this can cause memory issues.


+ 12
- 0
consensus/types/wire.go View File

@ -0,0 +1,12 @@
package types
import (
"github.com/tendermint/go-amino"
"github.com/tendermint/go-crypto"
)
var cdc = amino.NewCodec()
func init() {
crypto.RegisterAmino(cdc)
}

+ 11
- 11
node/node.go View File

@ -382,16 +382,6 @@ func (n *Node) OnStart() error {
return err return err
} }
// Run the RPC server first
// so we can eg. receive txs for the first block
if n.config.RPC.ListenAddress != "" {
listeners, err := n.startRPC()
if err != nil {
return err
}
n.rpcListeners = listeners
}
// Create & add listener // Create & add listener
protocol, address := cmn.ProtocolAndAddress(n.config.P2P.ListenAddress) protocol, address := cmn.ProtocolAndAddress(n.config.P2P.ListenAddress)
l := p2p.NewDefaultListener(protocol, address, n.config.P2P.SkipUPNP, n.Logger.With("module", "p2p")) l := p2p.NewDefaultListener(protocol, address, n.config.P2P.SkipUPNP, n.Logger.With("module", "p2p"))
@ -412,7 +402,17 @@ func (n *Node) OnStart() error {
// Add ourselves to addrbook to prevent dialing ourselves // Add ourselves to addrbook to prevent dialing ourselves
n.addrBook.AddOurAddress(nodeInfo.NetAddress()) n.addrBook.AddOurAddress(nodeInfo.NetAddress())
// Start the switch
// Start the RPC server before the P2P server
// so we can eg. receive txs for the first block
if n.config.RPC.ListenAddress != "" {
listeners, err := n.startRPC()
if err != nil {
return err
}
n.rpcListeners = listeners
}
// Start the switch (the P2P server).
err = n.sw.Start() err = n.sw.Start()
if err != nil { if err != nil {
return err return err


+ 8
- 4
p2p/node_info.go View File

@ -3,6 +3,8 @@ package p2p
import ( import (
"fmt" "fmt"
"strings" "strings"
cmn "github.com/tendermint/tmlibs/common"
) )
const ( const (
@ -10,6 +12,7 @@ const (
maxNumChannels = 16 // plenty of room for upgrades, for now maxNumChannels = 16 // plenty of room for upgrades, for now
) )
// Max size of the NodeInfo struct
func MaxNodeInfoSize() int { func MaxNodeInfoSize() int {
return maxNodeInfoSize return maxNodeInfoSize
} }
@ -21,10 +24,11 @@ type NodeInfo struct {
ID ID `json:"id"` // authenticated identifier ID ID `json:"id"` // authenticated identifier
ListenAddr string `json:"listen_addr"` // accepting incoming ListenAddr string `json:"listen_addr"` // accepting incoming
// Check compatibility
Network string `json:"network"` // network/chain ID
Version string `json:"version"` // major.minor.revision
Channels []byte `json:"channels"` // channels this node knows about
// Check compatibility.
// Channels are HexBytes so easier to read as JSON
Network string `json:"network"` // network/chain ID
Version string `json:"version"` // major.minor.revision
Channels cmn.HexBytes `json:"channels"` // channels this node knows about
// Sanitize // Sanitize
Moniker string `json:"moniker"` // arbitrary moniker Moniker string `json:"moniker"` // arbitrary moniker


+ 10
- 6
rpc/core/status.go View File

@ -79,6 +79,11 @@ func Status() (*ctypes.ResultStatus, error) {
latestBlockTime := time.Unix(0, latestBlockTimeNano) latestBlockTime := time.Unix(0, latestBlockTimeNano)
var votingPower int64
if val := validatorAtHeight(latestHeight); val != nil {
votingPower = val.VotingPower
}
result := &ctypes.ResultStatus{ result := &ctypes.ResultStatus{
NodeInfo: p2pSwitch.NodeInfo(), NodeInfo: p2pSwitch.NodeInfo(),
SyncInfo: ctypes.SyncInfo{ SyncInfo: ctypes.SyncInfo{
@ -88,12 +93,11 @@ func Status() (*ctypes.ResultStatus, error) {
LatestBlockTime: latestBlockTime, LatestBlockTime: latestBlockTime,
Syncing: consensusReactor.FastSync(), Syncing: consensusReactor.FastSync(),
}, },
ValidatorInfo: ctypes.ValidatorInfo{PubKey: pubKey},
}
// add ValidatorStatus if node is a validator
if val := validatorAtHeight(latestHeight); val != nil {
result.ValidatorInfo.VotingPower = val.VotingPower
ValidatorInfo: ctypes.ValidatorInfo{
Address: pubKey.Address(),
PubKey: pubKey,
VotingPower: votingPower,
},
} }
return result, nil return result, nil


+ 1
- 0
rpc/core/types/responses.go View File

@ -63,6 +63,7 @@ type SyncInfo struct {
} }
type ValidatorInfo struct { type ValidatorInfo struct {
Address cmn.HexBytes `json:"address"`
PubKey crypto.PubKey `json:"pub_key"` PubKey crypto.PubKey `json:"pub_key"`
VotingPower int64 `json:"voting_power"` VotingPower int64 `json:"voting_power"`
} }


+ 17
- 0
types/part_set.go View File

@ -264,3 +264,20 @@ func (ps *PartSet) StringShort() string {
defer ps.mtx.Unlock() defer ps.mtx.Unlock()
return fmt.Sprintf("(%v of %v)", ps.Count(), ps.Total()) return fmt.Sprintf("(%v of %v)", ps.Count(), ps.Total())
} }
func (ps *PartSet) MarshalJSON() ([]byte, error) {
if ps == nil {
return []byte("{}"), nil
}
ps.mtx.Lock()
defer ps.mtx.Unlock()
return cdc.MarshalJSON(struct {
CountTotal string `json:"count/total"`
PartsBitArray *cmn.BitArray `json:"parts_bit_array"`
}{
fmt.Sprintf("%d/%d", ps.Count(), ps.Total()),
ps.partsBitArray,
})
}

+ 27
- 1
types/vote_set.go View File

@ -56,9 +56,9 @@ type VoteSet struct {
height int64 height int64
round int round int
type_ byte type_ byte
valSet *ValidatorSet
mtx sync.Mutex mtx sync.Mutex
valSet *ValidatorSet
votesBitArray *cmn.BitArray votesBitArray *cmn.BitArray
votes []*Vote // Primary votes to share votes []*Vote // Primary votes to share
sum int64 // Sum of voting power for seen votes, discounting conflicts sum int64 // Sum of voting power for seen votes, discounting conflicts
@ -399,6 +399,8 @@ func (voteSet *VoteSet) HasTwoThirdsAny() bool {
} }
func (voteSet *VoteSet) HasAll() bool { func (voteSet *VoteSet) HasAll() bool {
voteSet.mtx.Lock()
defer voteSet.mtx.Unlock()
return voteSet.sum == voteSet.valSet.TotalVotingPower() return voteSet.sum == voteSet.valSet.TotalVotingPower()
} }
@ -424,6 +426,8 @@ func (voteSet *VoteSet) String() string {
} }
func (voteSet *VoteSet) StringIndented(indent string) string { func (voteSet *VoteSet) StringIndented(indent string) string {
voteSet.mtx.Lock()
defer voteSet.mtx.Unlock()
voteStrings := make([]string, len(voteSet.votes)) voteStrings := make([]string, len(voteSet.votes))
for i, vote := range voteSet.votes { for i, vote := range voteSet.votes {
if vote == nil { if vote == nil {
@ -445,6 +449,28 @@ func (voteSet *VoteSet) StringIndented(indent string) string {
indent) indent)
} }
// Marshal the VoteSet to JSON. Same as String(), just in JSON,
// and without the height/round/type_ (since its already included in the votes).
func (voteSet *VoteSet) MarshalJSON() ([]byte, error) {
voteSet.mtx.Lock()
defer voteSet.mtx.Unlock()
voteStrings := make([]string, len(voteSet.votes))
for i, vote := range voteSet.votes {
if vote == nil {
voteStrings[i] = "nil-Vote"
} else {
voteStrings[i] = vote.String()
}
}
return cdc.MarshalJSON(struct {
Votes []string `json:"votes"`
VotesBitArray *cmn.BitArray `json:"votes_bit_array"`
PeerMaj23s map[P2PID]BlockID `json:"peer_maj_23s"`
}{
voteStrings, voteSet.votesBitArray, voteSet.peerMaj23s,
})
}
func (voteSet *VoteSet) StringShort() string { func (voteSet *VoteSet) StringShort() string {
if voteSet == nil { if voteSet == nil {
return "nil-VoteSet" return "nil-VoteSet"


Loading…
Cancel
Save