Commit b08c65a3 authored by 张振华's avatar 张振华

lint

parent 07cde0ca
This diff is collapsed.
...@@ -22,24 +22,23 @@ import ( ...@@ -22,24 +22,23 @@ import (
const tendermintVersion = "0.1.0" const tendermintVersion = "0.1.0"
var ( var (
dposlog = log15.New("module", "dpos") dposlog = log15.New("module", "dpos")
genesis string genesis string
genesisBlockTime int64 genesisBlockTime int64
timeoutCheckConnections int32 = 1000 timeoutCheckConnections int32 = 1000
timeoutVoting int32 = 3000 timeoutVoting int32 = 3000
timeoutWaitNotify int32 = 2000 timeoutWaitNotify int32 = 2000
createEmptyBlocks = false createEmptyBlocks = false
createEmptyBlocksInterval int32 // second createEmptyBlocksInterval int32 // second
validatorNodes = []string{"127.0.0.1:46656"} validatorNodes = []string{"127.0.0.1:46656"}
isValidator = false isValidator = false
dposDelegateNum int64 = 3 //委托节点个数,从配置读取,以后可以根据投票结果来定 dposDelegateNum int64 = 3 //委托节点个数,从配置读取,以后可以根据投票结果来定
dposBlockInterval int64 = 3 //出块间隔,当前按3s dposBlockInterval int64 = 3 //出块间隔,当前按3s
dposContinueBlockNum int64 = 6 //一个委托节点当选后,一次性持续出块数量 dposContinueBlockNum int64 = 6 //一个委托节点当选后,一次性持续出块数量
dposCycle = int64(dposDelegateNum * dposBlockInterval * dposContinueBlockNum) dposCycle = int64(dposDelegateNum * dposBlockInterval * dposContinueBlockNum)
dposPeriod = int64(dposBlockInterval * dposContinueBlockNum) dposPeriod = int64(dposBlockInterval * dposContinueBlockNum)
zeroHash [32]byte zeroHash [32]byte
) )
func init() { func init() {
...@@ -221,7 +220,7 @@ OuterLoop: ...@@ -221,7 +220,7 @@ OuterLoop:
for !DebugCatchup { for !DebugCatchup {
select { select {
case <-hint.C: case <-hint.C:
dposlog.Info("Still catching up max height......", "cost", time.Since(beg)) dposlog.Info("Still catching up max height......", "cost", time.Since(beg))
default: default:
if client.IsCaughtUp() { if client.IsCaughtUp() {
dposlog.Info("This node has caught up max height") dposlog.Info("This node has caught up max height")
...@@ -328,10 +327,9 @@ func (client *Client) CreateBlock() { ...@@ -328,10 +327,9 @@ func (client *Client) CreateBlock() {
return return
} }
} else { } else {
dposlog.Info("Ignore to create new Block for no tx in mempool", "Height", block.Height + 1) dposlog.Info("Ignore to create new Block for no tx in mempool", "Height", block.Height+1)
} }
return return
} }
//check dup //check dup
...@@ -368,15 +366,17 @@ func (client *Client) CheckTxDup(txs []*types.Transaction, height int64) (transa ...@@ -368,15 +366,17 @@ func (client *Client) CheckTxDup(txs []*types.Transaction, height int64) (transa
return types.CacheToTxs(cacheTxs) return types.CacheToTxs(cacheTxs)
} }
func (client *Client) SetBlockTime(blockTime int64) { // SetBlockTime set current block time to generate new block
func (client *Client) SetBlockTime(blockTime int64) {
client.blockTime = blockTime client.blockTime = blockTime
} }
func (client *Client) ValidatorIndex() int{ // ValidatorIndex get the index of local this validator if it's
func (client *Client) ValidatorIndex() int {
if client.isDelegator { if client.isDelegator {
index, _ := client.csState.validatorMgr.Validators.GetByAddress(client.privValidator.GetAddress()) index, _ := client.csState.validatorMgr.Validators.GetByAddress(client.privValidator.GetAddress())
return index return index
} }
return -1 return -1
} }
\ No newline at end of file
...@@ -42,7 +42,7 @@ const ( ...@@ -42,7 +42,7 @@ const (
minReadBufferSize = 1024 minReadBufferSize = 1024
minWriteBufferSize = 65536 minWriteBufferSize = 65536
) )
// Parallel method // Parallel method
func Parallel(tasks ...func()) { func Parallel(tasks ...func()) {
...@@ -301,7 +301,6 @@ func (node *Node) StartConsensusRoutine() { ...@@ -301,7 +301,6 @@ func (node *Node) StartConsensusRoutine() {
} }
} }
// BroadcastRoutine receive to broadcast // BroadcastRoutine receive to broadcast
func (node *Node) BroadcastRoutine() { func (node *Node) BroadcastRoutine() {
for { for {
......
...@@ -85,7 +85,7 @@ type peerConn struct { ...@@ -85,7 +85,7 @@ type peerConn struct {
onPeerError func(Peer, interface{}) onPeerError func(Peer, interface{})
myState *ConsensusState myState *ConsensusState
} }
// PeerSet struct // PeerSet struct
...@@ -530,6 +530,7 @@ FOR_LOOP: ...@@ -530,6 +530,7 @@ FOR_LOOP:
// Drain // Drain
} }
} }
// StackError struct // StackError struct
type StackError struct { type StackError struct {
Err interface{} Err interface{}
......
...@@ -11,7 +11,7 @@ message VoteItem { ...@@ -11,7 +11,7 @@ message VoteItem {
int64 periodStart = 5; //新节点负责出块的起始时间 int64 periodStart = 5; //新节点负责出块的起始时间
int64 periodStop = 6; //新节点负责出块的终止时间 int64 periodStop = 6; //新节点负责出块的终止时间
int64 height = 7; //新节点负责出块的起始高度 int64 height = 7; //新节点负责出块的起始高度
bytes voteId = 8; //选票ID bytes voteID = 8; //选票ID
} }
//DPosVote Dpos共识的节点投票,为达成共识用。 //DPosVote Dpos共识的节点投票,为达成共识用。
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Package tendermint Uses nacl's secret_box to encrypt a net.Conn. // Package dpos Uses nacl's secret_box to encrypt a net.Conn.
// It is (meant to be) an implementation of the STS protocol. // It is (meant to be) an implementation of the STS protocol.
// Note we do not (yet) assume that a remote peer's pubkey // Note we do not (yet) assume that a remote peer's pubkey
// is known ahead of time, and thus we are technically // is known ahead of time, and thus we are technically
......
This diff is collapsed.
...@@ -29,14 +29,14 @@ func init() { ...@@ -29,14 +29,14 @@ func init() {
setParams(3, 3, 6) setParams(3, 3, 6)
} }
func setParams(delegateNum int64, blockInterval int64, continueBlockNum int64) { func setParams(delegateNum int64, blockInterval int64, continueBlockNum int64) {
dposDelegateNum = delegateNum //委托节点个数,从配置读取,以后可以根据投票结果来定 dposDelegateNum = delegateNum //委托节点个数,从配置读取,以后可以根据投票结果来定
dposBlockInterval = blockInterval //出块间隔,当前按3s dposBlockInterval = blockInterval //出块间隔,当前按3s
dposContinueBlockNum = continueBlockNum //一个委托节点当选后,一次性持续出块数量 dposContinueBlockNum = continueBlockNum //一个委托节点当选后,一次性持续出块数量
dposCycle = int64(dposDelegateNum * dposBlockInterval * dposContinueBlockNum) dposCycle = int64(dposDelegateNum * dposBlockInterval * dposContinueBlockNum)
dposPeriod = int64(dposBlockInterval * dposContinueBlockNum) dposPeriod = int64(dposBlockInterval * dposContinueBlockNum)
} }
func printTask(now int64, task *DPosTask){ func printTask(now int64, task *DPosTask) {
fmt.Printf("now:%v|cycleStart:%v|cycleStop:%v|periodStart:%v|periodStop:%v|blockStart:%v|blockStop:%v|nodeId:%v\n", fmt.Printf("now:%v|cycleStart:%v|cycleStop:%v|periodStart:%v|periodStop:%v|blockStart:%v|blockStop:%v|nodeId:%v\n",
now, now,
task.cycleStart, task.cycleStart,
...@@ -45,10 +45,10 @@ func printTask(now int64, task *DPosTask){ ...@@ -45,10 +45,10 @@ func printTask(now int64, task *DPosTask){
task.periodStop, task.periodStop,
task.blockStart, task.blockStart,
task.blockStop, task.blockStop,
task.nodeId) task.nodeID)
} }
func assertTask(task *DPosTask, t*testing.T){ func assertTask(task *DPosTask, t *testing.T) {
assert.Equal(t, true, task.nodeId >= 0 && task.nodeId < dposDelegateNum) assert.Equal(t, true, task.nodeID >= 0 && task.nodeID < dposDelegateNum)
assert.Equal(t, true, task.cycleStart <= task.periodStart && task.periodStart <= task.blockStart && task.blockStop <= task.periodStop && task.periodStop <= task.cycleStop) assert.Equal(t, true, task.cycleStart <= task.periodStart && task.periodStart <= task.blockStart && task.blockStop <= task.periodStop && task.periodStop <= task.cycleStop)
} }
...@@ -59,7 +59,6 @@ func TestDecideTaskByTime(t *testing.T) { ...@@ -59,7 +59,6 @@ func TestDecideTaskByTime(t *testing.T) {
printTask(now, &task) printTask(now, &task)
assertTask(&task, t) assertTask(&task, t)
setParams(2, 1, 6) setParams(2, 1, 6)
now = time.Now().Unix() now = time.Now().Unix()
task = DecideTaskByTime(now) task = DecideTaskByTime(now)
...@@ -72,7 +71,6 @@ func TestDecideTaskByTime(t *testing.T) { ...@@ -72,7 +71,6 @@ func TestDecideTaskByTime(t *testing.T) {
printTask(now, &task) printTask(now, &task)
assertTask(&task, t) assertTask(&task, t)
setParams(21, 2, 12) setParams(21, 2, 12)
now = time.Now().Unix() now = time.Now().Unix()
task = DecideTaskByTime(now) task = DecideTaskByTime(now)
...@@ -89,4 +87,3 @@ func TestDecideTaskByTime(t *testing.T) { ...@@ -89,4 +87,3 @@ func TestDecideTaskByTime(t *testing.T) {
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
} }
} }
...@@ -38,7 +38,7 @@ type VoteItem struct { ...@@ -38,7 +38,7 @@ type VoteItem struct {
PeriodStart int64 `protobuf:"varint,5,opt,name=periodStart" json:"periodStart,omitempty"` PeriodStart int64 `protobuf:"varint,5,opt,name=periodStart" json:"periodStart,omitempty"`
PeriodStop int64 `protobuf:"varint,6,opt,name=periodStop" json:"periodStop,omitempty"` PeriodStop int64 `protobuf:"varint,6,opt,name=periodStop" json:"periodStop,omitempty"`
Height int64 `protobuf:"varint,7,opt,name=height" json:"height,omitempty"` Height int64 `protobuf:"varint,7,opt,name=height" json:"height,omitempty"`
VoteId []byte `protobuf:"bytes,8,opt,name=voteId,proto3" json:"voteId,omitempty"` VoteID []byte `protobuf:"bytes,8,opt,name=voteID,proto3" json:"voteID,omitempty"`
} }
func (m *VoteItem) Reset() { *m = VoteItem{} } func (m *VoteItem) Reset() { *m = VoteItem{} }
...@@ -95,9 +95,9 @@ func (m *VoteItem) GetHeight() int64 { ...@@ -95,9 +95,9 @@ func (m *VoteItem) GetHeight() int64 {
return 0 return 0
} }
func (m *VoteItem) GetVoteId() []byte { func (m *VoteItem) GetVoteID() []byte {
if m != nil { if m != nil {
return m.VoteId return m.VoteID
} }
return nil return nil
} }
...@@ -242,30 +242,30 @@ func init() { ...@@ -242,30 +242,30 @@ func init() {
func init() { proto.RegisterFile("dpos_msg.proto", fileDescriptor0) } func init() { proto.RegisterFile("dpos_msg.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{ var fileDescriptor0 = []byte{
// 386 bytes of a gzipped FileDescriptorProto // 385 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xdd, 0x6a, 0xdb, 0x30, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xcd, 0x4a, 0xeb, 0x40,
0x14, 0xc7, 0x71, 0x1c, 0x3b, 0xde, 0xc9, 0xd7, 0xa6, 0x8b, 0x61, 0xc6, 0x18, 0xc6, 0x1b, 0xc3, 0x14, 0xc7, 0x49, 0xd3, 0xa4, 0xb9, 0xa7, 0x5f, 0xf7, 0xce, 0xe2, 0x12, 0x2e, 0x17, 0x09, 0x51,
0x6c, 0x25, 0x17, 0x6d, 0x5f, 0xa0, 0xd0, 0x9b, 0xdc, 0x84, 0xe2, 0x96, 0xde, 0x16, 0x37, 0x52, 0x24, 0xa8, 0x74, 0xa1, 0xbe, 0x80, 0xd0, 0x4d, 0x37, 0x45, 0xa2, 0xb8, 0x95, 0xd8, 0x8c, 0x4d,
0x63, 0x43, 0x1c, 0x09, 0x49, 0x0d, 0xcd, 0x43, 0xb4, 0xaf, 0xd6, 0x57, 0x2a, 0x3a, 0xfe, 0x90, 0xa0, 0xe9, 0x0c, 0x33, 0x63, 0xb1, 0x0f, 0xa1, 0xaf, 0xe6, 0x2b, 0xc9, 0x9c, 0x7c, 0x4c, 0x9a,
0xe3, 0xd0, 0xbb, 0x9c, 0xdf, 0x5f, 0x1f, 0xe7, 0xfc, 0x14, 0xc3, 0x8c, 0x0a, 0xae, 0x1e, 0x4a, 0xe2, 0xae, 0xe7, 0xf7, 0x9f, 0x8f, 0x73, 0x7e, 0xd3, 0xc0, 0x24, 0xe5, 0x4c, 0x3e, 0x17, 0x72,
0xb5, 0x59, 0x08, 0xc9, 0x35, 0x27, 0x9e, 0x3e, 0x08, 0xa6, 0xe2, 0xb7, 0x01, 0x04, 0xf7, 0x5c, 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x8b, 0x17, 0x1f, 0x07, 0x87, 0x16, 0x07, 0x1d, 0x8b, 0x2f, 0x2e,
0x8f, 0x9f, 0xcd, 0xc5, 0x47, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc3, 0x26, 0x39, 0x79, 0x48, 0x03, 0x7e, 0x36, 0x37, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x6e, 0xf4, 0x71, 0xcb, 0x48, 0x03, 0x00,
0x00, 0x00, 0x00,
} }
...@@ -23,11 +23,11 @@ type GenesisValidator struct { ...@@ -23,11 +23,11 @@ type GenesisValidator struct {
// GenesisDoc defines the initial conditions for a tendermint blockchain, in particular its validator set. // GenesisDoc defines the initial conditions for a tendermint blockchain, in particular its validator set.
type GenesisDoc struct { type GenesisDoc struct {
GenesisTime time.Time `json:"genesis_time"` GenesisTime time.Time `json:"genesis_time"`
ChainID string `json:"chain_id"` ChainID string `json:"chain_id"`
Validators []GenesisValidator `json:"validators"` Validators []GenesisValidator `json:"validators"`
AppHash []byte `json:"app_hash"` AppHash []byte `json:"app_hash"`
AppOptions interface{} `json:"app_options,omitempty"` AppOptions interface{} `json:"app_options,omitempty"`
} }
// SaveAs is a utility method for saving GenensisDoc as a JSON file. // SaveAs is a utility method for saving GenensisDoc as a JSON file.
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
package types package types
import ( import (
"time"
"reflect" "reflect"
) "time"
)
var ( var (
// MsgMap define // MsgMap define
...@@ -16,9 +16,9 @@ var ( ...@@ -16,9 +16,9 @@ var (
// step and message id define // step and message id define
const ( const (
VoteID = byte(0x06) VoteID = byte(0x06)
VoteReplyID = byte(0x07) VoteReplyID = byte(0x07)
NotifyID = byte(0x08) NotifyID = byte(0x08)
PacketTypePing = byte(0xff) PacketTypePing = byte(0xff)
PacketTypePong = byte(0xfe) PacketTypePong = byte(0xfe)
...@@ -27,14 +27,13 @@ const ( ...@@ -27,14 +27,13 @@ const (
// InitMessageMap ... // InitMessageMap ...
func InitMessageMap() { func InitMessageMap() {
MsgMap = map[byte]reflect.Type{ MsgMap = map[byte]reflect.Type{
VoteID: reflect.TypeOf(DPosVote{}), VoteID: reflect.TypeOf(DPosVote{}),
VoteReplyID: reflect.TypeOf(DPosVoteReply{}), VoteReplyID: reflect.TypeOf(DPosVoteReply{}),
NotifyID: reflect.TypeOf(DPosNotify{}), NotifyID: reflect.TypeOf(DPosNotify{}),
} }
} }
//---------------------Canonical json----------------------------------- // CanonicalJSONVoteItem ...
// CanonicalJSONVote ...
type CanonicalJSONVoteItem struct { type CanonicalJSONVoteItem struct {
VotedNodeIndex int32 `json:"votedNodeIndex,omitempty"` VotedNodeIndex int32 `json:"votedNodeIndex,omitempty"`
VotedNodeAddress []byte `json:"votedNodeAddress,omitempty"` VotedNodeAddress []byte `json:"votedNodeAddress,omitempty"`
...@@ -43,15 +42,15 @@ type CanonicalJSONVoteItem struct { ...@@ -43,15 +42,15 @@ type CanonicalJSONVoteItem struct {
PeriodStart int64 `json:"periodStart,omitempty"` PeriodStart int64 `json:"periodStart,omitempty"`
PeriodStop int64 `json:"periodStop,omitempty"` PeriodStop int64 `json:"periodStop,omitempty"`
Height int64 `json:"height,omitempty"` Height int64 `json:"height,omitempty"`
VoteId []byte `json:"voteId,omitempty"` VoteID []byte `json:"voteID,omitempty"`
} }
// CanonicalJSONVote ...
type CanonicalJSONVote struct { type CanonicalJSONVote struct {
VoteItem *CanonicalJSONVoteItem `json:"vote,omitempty"` VoteItem *CanonicalJSONVoteItem `json:"vote,omitempty"`
VoteTimestamp int64 `json:"voteTimestamp,omitempty"` VoteTimestamp int64 `json:"voteTimestamp,omitempty"`
VoterNodeIndex int32 `json:"voterNodeIndex,omitempty"` VoterNodeIndex int32 `json:"voterNodeIndex,omitempty"`
VoterNodeAddress []byte `json:"voterNodeAddress,omitempty"` VoterNodeAddress []byte `json:"voterNodeAddress,omitempty"`
} }
// CanonicalJSONOnceVote ... // CanonicalJSONOnceVote ...
...@@ -63,49 +62,50 @@ type CanonicalJSONOnceVote struct { ...@@ -63,49 +62,50 @@ type CanonicalJSONOnceVote struct {
// CanonicalVote ... // CanonicalVote ...
func CanonicalVote(vote *Vote) CanonicalJSONVote { func CanonicalVote(vote *Vote) CanonicalJSONVote {
return CanonicalJSONVote{ return CanonicalJSONVote{
VoteItem: &CanonicalJSONVoteItem{ VoteItem: &CanonicalJSONVoteItem{
VotedNodeIndex: vote.VoteItem.VotedNodeIndex, VotedNodeIndex: vote.VoteItem.VotedNodeIndex,
VotedNodeAddress: vote.VoteItem.VotedNodeAddress, VotedNodeAddress: vote.VoteItem.VotedNodeAddress,
CycleStart: vote.VoteItem.CycleStart, CycleStart: vote.VoteItem.CycleStart,
CycleStop: vote.VoteItem.CycleStop, CycleStop: vote.VoteItem.CycleStop,
PeriodStart: vote.VoteItem.PeriodStart, PeriodStart: vote.VoteItem.PeriodStart,
PeriodStop: vote.VoteItem.PeriodStop, PeriodStop: vote.VoteItem.PeriodStop,
Height: vote.VoteItem.Height, Height: vote.VoteItem.Height,
VoteId: vote.VoteItem.VoteId, VoteID: vote.VoteItem.VoteID,
}, },
VoteTimestamp: vote.VoteTimestamp, VoteTimestamp: vote.VoteTimestamp,
VoterNodeIndex: vote.VoterNodeIndex, VoterNodeIndex: vote.VoterNodeIndex,
VoterNodeAddress: vote.VoterNodeAddress, VoterNodeAddress: vote.VoterNodeAddress,
} }
} }
// CanonicalJSONNotify ...
type CanonicalJSONNotify struct { type CanonicalJSONNotify struct {
VoteItem *CanonicalJSONVoteItem `json:"vote,omitempty"` VoteItem *CanonicalJSONVoteItem `json:"vote,omitempty"`
HeightStop int64 `json:"heightStop,omitempty"` HeightStop int64 `json:"heightStop,omitempty"`
NotifyTimestamp int64 `json:"notifyTimestamp,omitempty"` NotifyTimestamp int64 `json:"notifyTimestamp,omitempty"`
} }
// CanonicalJSONOnceVote ... // CanonicalJSONOnceNotify ...
type CanonicalJSONOnceNotify struct { type CanonicalJSONOnceNotify struct {
ChainID string `json:"chain_id"` ChainID string `json:"chain_id"`
Notify CanonicalJSONNotify `json:"vote"` Notify CanonicalJSONNotify `json:"vote"`
} }
// CanonicalVote ... // CanonicalNotify ...
func CanonicalNotify(notify *Notify) CanonicalJSONNotify { func CanonicalNotify(notify *Notify) CanonicalJSONNotify {
return CanonicalJSONNotify{ return CanonicalJSONNotify{
VoteItem: &CanonicalJSONVoteItem{ VoteItem: &CanonicalJSONVoteItem{
VotedNodeIndex: notify.Vote.VotedNodeIndex, VotedNodeIndex: notify.Vote.VotedNodeIndex,
VotedNodeAddress: notify.Vote.VotedNodeAddress, VotedNodeAddress: notify.Vote.VotedNodeAddress,
CycleStart: notify.Vote.CycleStart, CycleStart: notify.Vote.CycleStart,
CycleStop: notify.Vote.CycleStop, CycleStop: notify.Vote.CycleStop,
PeriodStart: notify.Vote.PeriodStart, PeriodStart: notify.Vote.PeriodStart,
PeriodStop: notify.Vote.PeriodStop, PeriodStop: notify.Vote.PeriodStop,
Height: notify.Vote.Height, Height: notify.Vote.Height,
VoteId: notify.Vote.VoteId, VoteID: notify.Vote.VoteID,
}, },
HeightStop: notify.HeightStop, HeightStop: notify.HeightStop,
NotifyTimestamp: notify.NotifyTimestamp, NotifyTimestamp: notify.NotifyTimestamp,
} }
} }
......
...@@ -195,7 +195,7 @@ func LoadPrivValidatorFSWithSigner(filePath string, signerFunc func(PrivValidato ...@@ -195,7 +195,7 @@ func LoadPrivValidatorFSWithSigner(filePath string, signerFunc func(PrivValidato
Exit(Fmt("Error PrivValidator DecodeString failed:%v\n", err)) Exit(Fmt("Error PrivValidator DecodeString failed:%v\n", err))
} }
privValImp := &PrivValidatorImp{ privValImp := &PrivValidatorImp{
Address: addr, Address: addr,
} }
tmp, err := hex.DecodeString(privVal.PrivKey.Data) tmp, err := hex.DecodeString(privVal.PrivKey.Data)
if err != nil { if err != nil {
...@@ -290,7 +290,6 @@ func (pv *PrivValidatorImp) SignVote(chainID string, vote *Vote) error { ...@@ -290,7 +290,6 @@ func (pv *PrivValidatorImp) SignVote(chainID string, vote *Vote) error {
signBytes := SignBytes(chainID, vote) signBytes := SignBytes(chainID, vote)
signature, err := pv.Sign(signBytes) signature, err := pv.Sign(signBytes)
if err != nil { if err != nil {
return errors.New(Fmt("Error signing vote: %v", err)) return errors.New(Fmt("Error signing vote: %v", err))
...@@ -299,7 +298,7 @@ func (pv *PrivValidatorImp) SignVote(chainID string, vote *Vote) error { ...@@ -299,7 +298,7 @@ func (pv *PrivValidatorImp) SignVote(chainID string, vote *Vote) error {
return nil return nil
} }
// SignVote signs a canonical representation of the vote, along with the // SignNotify signs a canonical representation of the notify, along with the
// chainID. Implements PrivValidator. // chainID. Implements PrivValidator.
func (pv *PrivValidatorImp) SignNotify(chainID string, notify *Notify) error { func (pv *PrivValidatorImp) SignNotify(chainID string, notify *Notify) error {
pv.mtx.Lock() pv.mtx.Lock()
...@@ -307,7 +306,6 @@ func (pv *PrivValidatorImp) SignNotify(chainID string, notify *Notify) error { ...@@ -307,7 +306,6 @@ func (pv *PrivValidatorImp) SignNotify(chainID string, notify *Notify) error {
signBytes := SignBytes(chainID, notify) signBytes := SignBytes(chainID, notify)
signature, err := pv.Sign(signBytes) signature, err := pv.Sign(signBytes)
if err != nil { if err != nil {
return errors.New(Fmt("Error signing vote: %v", err)) return errors.New(Fmt("Error signing vote: %v", err))
......
...@@ -21,12 +21,12 @@ var ( ...@@ -21,12 +21,12 @@ var (
ErrNotifyInvalidValidatorIndex = errors.New("Invalid validator index for notify") ErrNotifyInvalidValidatorIndex = errors.New("Invalid validator index for notify")
ErrNotifyInvalidSignature = errors.New("Invalid notify signature") ErrNotifyInvalidSignature = errors.New("Invalid notify signature")
ErrVoteInvalidValidatorIndex = errors.New("Invalid validator index for vote") ErrVoteInvalidValidatorIndex = errors.New("Invalid validator index for vote")
ErrVoteInvalidValidatorAddress = errors.New("Invalid validator address for vote") ErrVoteInvalidValidatorAddress = errors.New("Invalid validator address for vote")
ErrVoteInvalidSignature = errors.New("Invalid vote signature") ErrVoteInvalidSignature = errors.New("Invalid vote signature")
ErrVoteNil = errors.New("Nil vote") ErrVoteNil = errors.New("Nil vote")
votelog = log15.New("module", "tendermint-vote") votelog = log15.New("module", "tendermint-vote")
ConsensusCrypto crypto.Crypto ConsensusCrypto crypto.Crypto
) )
...@@ -91,12 +91,12 @@ func (vote *Vote) String() string { ...@@ -91,12 +91,12 @@ func (vote *Vote) String() string {
vote.VoteItem.PeriodStart, vote.VoteItem.PeriodStart,
vote.VoteItem.PeriodStop, vote.VoteItem.PeriodStop,
vote.VoteItem.Height, vote.VoteItem.Height,
Fingerprint(vote.VoteItem.VoteId), Fingerprint(vote.VoteItem.VoteID),
CanonicalTime(time.Unix(0, vote.VoteTimestamp)), CanonicalTime(time.Unix(0, vote.VoteTimestamp)),
vote.VoterNodeIndex, vote.VoterNodeIndex,
Fingerprint(vote.VoterNodeAddress), Fingerprint(vote.VoterNodeAddress),
Fingerprint(vote.Signature), Fingerprint(vote.Signature),
) )
} }
// Verify ... // Verify ...
...@@ -133,8 +133,7 @@ func (vote *Vote) Hash() []byte { ...@@ -133,8 +133,7 @@ func (vote *Vote) Hash() []byte {
return crypto.Ripemd160(bytes) return crypto.Ripemd160(bytes)
} }
// Notify Represents a notify from validators for consensus.
// Vote Represents a vote from validators for consensus.
type Notify struct { type Notify struct {
*DPosNotify *DPosNotify
} }
...@@ -178,7 +177,7 @@ func (notify *Notify) String() string { ...@@ -178,7 +177,7 @@ func (notify *Notify) String() string {
notify.Vote.PeriodStart, notify.Vote.PeriodStart,
notify.Vote.PeriodStop, notify.Vote.PeriodStop,
notify.Vote.Height, notify.Vote.Height,
Fingerprint(notify.Vote.VoteId), Fingerprint(notify.Vote.VoteID),
CanonicalTime(time.Unix(0, notify.NotifyTimestamp)), CanonicalTime(time.Unix(0, notify.NotifyTimestamp)),
notify.HeightStop, notify.HeightStop,
notify.NotifyNodeIndex, notify.NotifyNodeIndex,
......
...@@ -18,15 +18,15 @@ var validatorsetlog = log15.New("module", "dpos-val") ...@@ -18,15 +18,15 @@ var validatorsetlog = log15.New("module", "dpos-val")
// Validator ... // Validator ...
type Validator struct { type Validator struct {
Address []byte `json:"address"` Address []byte `json:"address"`
PubKey []byte `json:"pub_key"` PubKey []byte `json:"pub_key"`
} }
// NewValidator ... // NewValidator ...
func NewValidator(pubKey crypto.PubKey) *Validator { func NewValidator(pubKey crypto.PubKey) *Validator {
return &Validator{ return &Validator{
Address: GenAddressByPubKey(pubKey), Address: GenAddressByPubKey(pubKey),
PubKey: pubKey.Bytes(), PubKey: pubKey.Bytes(),
} }
} }
...@@ -91,7 +91,7 @@ func (valSet *ValidatorSet) Copy() *ValidatorSet { ...@@ -91,7 +91,7 @@ func (valSet *ValidatorSet) Copy() *ValidatorSet {
validators[i] = val.Copy() validators[i] = val.Copy()
} }
return &ValidatorSet{ return &ValidatorSet{
Validators: validators, Validators: validators,
} }
} }
......
...@@ -18,13 +18,7 @@ var ( ...@@ -18,13 +18,7 @@ var (
r *rand.Rand r *rand.Rand
) )
// State is a short description of the latest committed block of the Tendermint consensus. // ValidatorMgr ...
// It keeps all information necessary to validate new blocks,
// including the last validator set and the consensus params.
// All fields are exposed so the struct can be easily serialized,
// but none of them should be mutated directly.
// Instead, use state.Copy() or state.NextState(...).
// NOTE: not goroutine-safe.
type ValidatorMgr struct { type ValidatorMgr struct {
// Immutable // Immutable
ChainID string ChainID string
...@@ -33,7 +27,7 @@ type ValidatorMgr struct { ...@@ -33,7 +27,7 @@ type ValidatorMgr struct {
// so we can query for historical validator sets. // so we can query for historical validator sets.
// Note that if s.LastBlockHeight causes a valset change, // Note that if s.LastBlockHeight causes a valset change,
// we set s.LastHeightValidatorsChanged = s.LastBlockHeight + 1 // we set s.LastHeightValidatorsChanged = s.LastBlockHeight + 1
Validators *ttypes.ValidatorSet Validators *ttypes.ValidatorSet
// The latest AppHash we've received from calling abci.Commit() // The latest AppHash we've received from calling abci.Commit()
AppHash []byte AppHash []byte
...@@ -44,7 +38,7 @@ func (s ValidatorMgr) Copy() ValidatorMgr { ...@@ -44,7 +38,7 @@ func (s ValidatorMgr) Copy() ValidatorMgr {
return ValidatorMgr{ return ValidatorMgr{
ChainID: s.ChainID, ChainID: s.ChainID,
Validators: s.Validators.Copy(), Validators: s.Validators.Copy(),
AppHash: s.AppHash, AppHash: s.AppHash,
} }
...@@ -75,8 +69,7 @@ func (s ValidatorMgr) GetValidators() (current *ttypes.ValidatorSet) { ...@@ -75,8 +69,7 @@ func (s ValidatorMgr) GetValidators() (current *ttypes.ValidatorSet) {
return s.Validators return s.Validators
} }
// MakeGenesisValidatorMgr creates validators from ttypes.GenesisDoc.
// MakeGenesisState creates state from ttypes.GenesisDoc.
func MakeGenesisValidatorMgr(genDoc *ttypes.GenesisDoc) (ValidatorMgr, error) { func MakeGenesisValidatorMgr(genDoc *ttypes.GenesisDoc) (ValidatorMgr, error) {
err := genDoc.ValidateAndComplete() err := genDoc.ValidateAndComplete()
if err != nil { if err != nil {
...@@ -93,14 +86,14 @@ func MakeGenesisValidatorMgr(genDoc *ttypes.GenesisDoc) (ValidatorMgr, error) { ...@@ -93,14 +86,14 @@ func MakeGenesisValidatorMgr(genDoc *ttypes.GenesisDoc) (ValidatorMgr, error) {
// Make validator // Make validator
validators[i] = &ttypes.Validator{ validators[i] = &ttypes.Validator{
Address: ttypes.GenAddressByPubKey(pubKey), Address: ttypes.GenAddressByPubKey(pubKey),
PubKey: pubKey.Bytes(), PubKey: pubKey.Bytes(),
} }
} }
return ValidatorMgr{ return ValidatorMgr{
ChainID: genDoc.ChainID, ChainID: genDoc.ChainID,
Validators: ttypes.NewValidatorSet(validators), Validators: ttypes.NewValidatorSet(validators),
AppHash: genDoc.AppHash, AppHash: genDoc.AppHash,
}, nil }, nil
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment