Merge pull request #1511 from tendermint/bucky/rpc-fixes
Various RPC fixes
This commit is contained in:
commit
1188dfe7ee
|
@ -207,6 +207,30 @@ func (hvs *HeightVoteSet) StringIndented(indent string) string {
|
|||
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.
|
||||
// NOTE: if there are too many peers, or too much peer churn,
|
||||
// this can cause memory issues.
|
||||
|
|
|
@ -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)
|
||||
}
|
22
node/node.go
22
node/node.go
|
@ -382,16 +382,6 @@ func (n *Node) OnStart() error {
|
|||
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
|
||||
protocol, address := cmn.ProtocolAndAddress(n.config.P2P.ListenAddress)
|
||||
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
|
||||
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()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -3,6 +3,8 @@ package p2p
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -10,6 +12,7 @@ const (
|
|||
maxNumChannels = 16 // plenty of room for upgrades, for now
|
||||
)
|
||||
|
||||
// Max size of the NodeInfo struct
|
||||
func MaxNodeInfoSize() int {
|
||||
return maxNodeInfoSize
|
||||
}
|
||||
|
@ -21,10 +24,11 @@ type NodeInfo struct {
|
|||
ID ID `json:"id"` // authenticated identifier
|
||||
ListenAddr string `json:"listen_addr"` // accepting incoming
|
||||
|
||||
// Check compatibility
|
||||
// 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 []byte `json:"channels"` // channels this node knows about
|
||||
Channels cmn.HexBytes `json:"channels"` // channels this node knows about
|
||||
|
||||
// Sanitize
|
||||
Moniker string `json:"moniker"` // arbitrary moniker
|
||||
|
|
|
@ -79,6 +79,11 @@ func Status() (*ctypes.ResultStatus, error) {
|
|||
|
||||
latestBlockTime := time.Unix(0, latestBlockTimeNano)
|
||||
|
||||
var votingPower int64
|
||||
if val := validatorAtHeight(latestHeight); val != nil {
|
||||
votingPower = val.VotingPower
|
||||
}
|
||||
|
||||
result := &ctypes.ResultStatus{
|
||||
NodeInfo: p2pSwitch.NodeInfo(),
|
||||
SyncInfo: ctypes.SyncInfo{
|
||||
|
@ -88,12 +93,11 @@ func Status() (*ctypes.ResultStatus, error) {
|
|||
LatestBlockTime: latestBlockTime,
|
||||
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
|
||||
|
|
|
@ -63,6 +63,7 @@ type SyncInfo struct {
|
|||
}
|
||||
|
||||
type ValidatorInfo struct {
|
||||
Address cmn.HexBytes `json:"address"`
|
||||
PubKey crypto.PubKey `json:"pub_key"`
|
||||
VotingPower int64 `json:"voting_power"`
|
||||
}
|
||||
|
|
|
@ -264,3 +264,20 @@ func (ps *PartSet) StringShort() string {
|
|||
defer ps.mtx.Unlock()
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -56,9 +56,9 @@ type VoteSet struct {
|
|||
height int64
|
||||
round int
|
||||
type_ byte
|
||||
valSet *ValidatorSet
|
||||
|
||||
mtx sync.Mutex
|
||||
valSet *ValidatorSet
|
||||
votesBitArray *cmn.BitArray
|
||||
votes []*Vote // Primary votes to share
|
||||
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 {
|
||||
voteSet.mtx.Lock()
|
||||
defer voteSet.mtx.Unlock()
|
||||
return voteSet.sum == voteSet.valSet.TotalVotingPower()
|
||||
}
|
||||
|
||||
|
@ -424,6 +426,8 @@ func (voteSet *VoteSet) String() string {
|
|||
}
|
||||
|
||||
func (voteSet *VoteSet) StringIndented(indent string) string {
|
||||
voteSet.mtx.Lock()
|
||||
defer voteSet.mtx.Unlock()
|
||||
voteStrings := make([]string, len(voteSet.votes))
|
||||
for i, vote := range voteSet.votes {
|
||||
if vote == nil {
|
||||
|
@ -445,6 +449,28 @@ func (voteSet *VoteSet) StringIndented(indent string) string {
|
|||
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 {
|
||||
if voteSet == nil {
|
||||
return "nil-VoteSet"
|
||||
|
|
Loading…
Reference in New Issue