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

lint

parent 07cde0ca
...@@ -27,7 +27,6 @@ const ( ...@@ -27,7 +27,6 @@ const (
continueToVote = 0 continueToVote = 0
voteSuccess = 1 voteSuccess = 1
voteFail = 2 voteFail = 2
) )
// Errors define // Errors define
...@@ -141,7 +140,7 @@ func (cs *ConsensusState) String() string { ...@@ -141,7 +140,7 @@ func (cs *ConsensusState) String() string {
return fmt.Sprintf("ConsensusState") //(H:%v R:%v S:%v", cs.Height, cs.Round, cs.Step) return fmt.Sprintf("ConsensusState") //(H:%v R:%v S:%v", cs.Height, cs.Round, cs.Step)
} }
// GetState returns a copy of the chain state. // GetValidatorMgr returns a copy of the ValidatorMgr.
func (cs *ConsensusState) GetValidatorMgr() ValidatorMgr { func (cs *ConsensusState) GetValidatorMgr() ValidatorMgr {
cs.mtx.Lock() cs.mtx.Lock()
defer cs.mtx.Unlock() defer cs.mtx.Unlock()
...@@ -149,7 +148,7 @@ func (cs *ConsensusState) GetValidatorMgr() ValidatorMgr { ...@@ -149,7 +148,7 @@ func (cs *ConsensusState) GetValidatorMgr() ValidatorMgr {
} }
// GetValidators returns a copy of the current validators. // GetValidators returns a copy of the current validators.
func (cs *ConsensusState) GetValidators() ([]*ttypes.Validator) { func (cs *ConsensusState) GetValidators() []*ttypes.Validator {
cs.mtx.Lock() cs.mtx.Lock()
defer cs.mtx.Unlock() defer cs.mtx.Unlock()
return cs.validatorMgr.Validators.Copy().Validators return cs.validatorMgr.Validators.Copy().Validators
...@@ -182,7 +181,7 @@ func (cs *ConsensusState) Start() { ...@@ -182,7 +181,7 @@ func (cs *ConsensusState) Start() {
go cs.receiveRoutine() go cs.receiveRoutine()
// schedule the first round! // schedule the first round!
cs.scheduleDPosTimeout(time.Second * 3, InitStateType) cs.scheduleDPosTimeout(time.Second*3, InitStateType)
} }
} }
...@@ -194,7 +193,7 @@ func (cs *ConsensusState) Stop() { ...@@ -194,7 +193,7 @@ func (cs *ConsensusState) Stop() {
// Attempt to schedule a timeout (by sending timeoutInfo on the tickChan) // Attempt to schedule a timeout (by sending timeoutInfo on the tickChan)
func (cs *ConsensusState) scheduleDPosTimeout(duration time.Duration, stateType int) { func (cs *ConsensusState) scheduleDPosTimeout(duration time.Duration, stateType int) {
cs.timeoutTicker.ScheduleTimeout(timeoutInfo{Duration:duration, State: stateType}) cs.timeoutTicker.ScheduleTimeout(timeoutInfo{Duration: duration, State: stateType})
} }
// send a msg into the receiveRoutine regarding our own proposal, block part, or vote // send a msg into the receiveRoutine regarding our own proposal, block part, or vote
...@@ -216,6 +215,7 @@ func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) { ...@@ -216,6 +215,7 @@ func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) {
func (cs *ConsensusState) updateToValMgr(valMgr ValidatorMgr) { func (cs *ConsensusState) updateToValMgr(valMgr ValidatorMgr) {
cs.validatorMgr = valMgr cs.validatorMgr = valMgr
} }
//----------------------------------------- //-----------------------------------------
// the main go routines // the main go routines
...@@ -297,22 +297,26 @@ func (cs *ConsensusState) IsProposer() bool { ...@@ -297,22 +297,26 @@ func (cs *ConsensusState) IsProposer() bool {
return false return false
} }
func (cs *ConsensusState) SetState(state DposState){ // SetState method
func (cs *ConsensusState) SetState(state DposState) {
cs.dposState = state cs.dposState = state
} }
// SaveVote method
func (cs *ConsensusState) SaveVote() { func (cs *ConsensusState) SaveVote() {
if cs.lastVote == nil { if cs.lastVote == nil {
cs.lastVote = cs.currentVote cs.lastVote = cs.currentVote
} else if cs.currentVote != nil && !bytes.Equal(cs.currentVote.VoteId, cs.lastVote.VoteId) { } else if cs.currentVote != nil && !bytes.Equal(cs.currentVote.VoteID, cs.lastVote.VoteID) {
cs.lastVote = cs.currentVote cs.lastVote = cs.currentVote
} }
} }
func (cs *ConsensusState) SetCurrentVote(vote * dpostype.VoteItem) { // SetCurrentVote method
func (cs *ConsensusState) SetCurrentVote(vote *dpostype.VoteItem) {
cs.currentVote = vote cs.currentVote = vote
} }
// SaveMyVote method
func (cs *ConsensusState) SaveMyVote() { func (cs *ConsensusState) SaveMyVote() {
if cs.lastMyVote == nil { if cs.lastMyVote == nil {
cs.lastMyVote = cs.myVote cs.lastMyVote = cs.myVote
...@@ -321,10 +325,12 @@ func (cs *ConsensusState) SaveMyVote() { ...@@ -321,10 +325,12 @@ func (cs *ConsensusState) SaveMyVote() {
} }
} }
func (cs *ConsensusState) SetMyVote(vote * dpostype.DPosVote){ // SetMyVote method
func (cs *ConsensusState) SetMyVote(vote *dpostype.DPosVote) {
cs.myVote = vote cs.myVote = vote
} }
// SaveNotify method
func (cs *ConsensusState) SaveNotify() { func (cs *ConsensusState) SaveNotify() {
if cs.lastNotify == nil { if cs.lastNotify == nil {
cs.lastNotify = cs.notify cs.lastNotify = cs.notify
...@@ -333,7 +339,8 @@ func (cs *ConsensusState) SaveNotify() { ...@@ -333,7 +339,8 @@ func (cs *ConsensusState) SaveNotify() {
} }
} }
func (cs *ConsensusState) SetNotify(notify * dpostype.DPosNotify){ // SetNotify method
func (cs *ConsensusState) SetNotify(notify *dpostype.DPosNotify) {
if cs.notify != nil && !bytes.Equal(cs.lastNotify.Signature, notify.Signature) { if cs.notify != nil && !bytes.Equal(cs.lastNotify.Signature, notify.Signature) {
cs.lastNotify = cs.notify cs.lastNotify = cs.notify
} }
...@@ -341,15 +348,18 @@ func (cs *ConsensusState) SetNotify(notify * dpostype.DPosNotify){ ...@@ -341,15 +348,18 @@ func (cs *ConsensusState) SetNotify(notify * dpostype.DPosNotify){
cs.notify = notify cs.notify = notify
} }
func (cs *ConsensusState) CacheNotify(notify * dpostype.DPosNotify){ // CacheNotify method
func (cs *ConsensusState) CacheNotify(notify *dpostype.DPosNotify) {
cs.cachedNotify = notify cs.cachedNotify = notify
} }
func (cs *ConsensusState) ClearCachedNotify(){ // ClearCachedNotify method
func (cs *ConsensusState) ClearCachedNotify() {
cs.cachedNotify = nil cs.cachedNotify = nil
} }
func (cs *ConsensusState) AddVotes(vote * dpostype.DPosVote){ // AddVotes method
func (cs *ConsensusState) AddVotes(vote *dpostype.DPosVote) {
repeatFlag := false repeatFlag := false
addrExistFlag := false addrExistFlag := false
index := -1 index := -1
...@@ -384,7 +394,8 @@ func (cs *ConsensusState) AddVotes(vote * dpostype.DPosVote){ ...@@ -384,7 +394,8 @@ func (cs *ConsensusState) AddVotes(vote * dpostype.DPosVote){
} }
} }
func (cs *ConsensusState) CacheVotes(vote * dpostype.DPosVote){ // CacheVotes method
func (cs *ConsensusState) CacheVotes(vote *dpostype.DPosVote) {
repeatFlag := false repeatFlag := false
addrExistFlag := false addrExistFlag := false
index := -1 index := -1
...@@ -421,7 +432,8 @@ func (cs *ConsensusState) CacheVotes(vote * dpostype.DPosVote){ ...@@ -421,7 +432,8 @@ func (cs *ConsensusState) CacheVotes(vote * dpostype.DPosVote){
} }
} }
func (cs *ConsensusState) CheckVotes()(ty int, vote * dpostype.VoteItem){ // CheckVotes method
func (cs *ConsensusState) CheckVotes() (ty int, vote *dpostype.VoteItem) {
major32 := int(dposDelegateNum * 2 / 3) major32 := int(dposDelegateNum * 2 / 3)
//总的票数还不够2/3,先不做决定 //总的票数还不够2/3,先不做决定
...@@ -429,9 +441,9 @@ func (cs *ConsensusState) CheckVotes()(ty int, vote * dpostype.VoteItem){ ...@@ -429,9 +441,9 @@ func (cs *ConsensusState) CheckVotes()(ty int, vote * dpostype.VoteItem){
return continueToVote, nil return continueToVote, nil
} }
voteStat := map[string] int {} voteStat := map[string]int{}
for i := 0; i < len(cs.dposVotes); i++ { for i := 0; i < len(cs.dposVotes); i++ {
key := string(cs.dposVotes[i].VoteItem.VoteId) key := string(cs.dposVotes[i].VoteItem.VoteID)
if _, ok := voteStat[key]; ok { if _, ok := voteStat[key]; ok {
voteStat[key]++ voteStat[key]++
} else { } else {
...@@ -452,11 +464,11 @@ func (cs *ConsensusState) CheckVotes()(ty int, vote * dpostype.VoteItem){ ...@@ -452,11 +464,11 @@ func (cs *ConsensusState) CheckVotes()(ty int, vote * dpostype.VoteItem){
//如果一个节点的投票数已经过2/3,则返回最终票数超过2/3的选票 //如果一个节点的投票数已经过2/3,则返回最终票数超过2/3的选票
if value >= major32 { if value >= major32 {
for i := 0; i < len(cs.dposVotes); i++ { for i := 0; i < len(cs.dposVotes); i++ {
if key == string(cs.dposVotes[i].VoteItem.VoteId) { if key == string(cs.dposVotes[i].VoteItem.VoteID) {
return voteSuccess, cs.dposVotes[i].VoteItem return voteSuccess, cs.dposVotes[i].VoteItem
} }
} }
} else if (value + (int(dposDelegateNum) - len(cs.dposVotes))) < major32{ } else if (value + (int(dposDelegateNum) - len(cs.dposVotes))) < major32 {
//得票最多的节点,即使后续所有票都选它,也不满足2/3多数,不能达成共识。 //得票最多的节点,即使后续所有票都选它,也不满足2/3多数,不能达成共识。
return voteFail, nil return voteFail, nil
} }
...@@ -464,17 +476,20 @@ func (cs *ConsensusState) CheckVotes()(ty int, vote * dpostype.VoteItem){ ...@@ -464,17 +476,20 @@ func (cs *ConsensusState) CheckVotes()(ty int, vote * dpostype.VoteItem){
return continueToVote, nil return continueToVote, nil
} }
func (cs *ConsensusState) ClearVotes(){ // ClearVotes method
func (cs *ConsensusState) ClearVotes() {
cs.dposVotes = nil cs.dposVotes = nil
cs.currentVote = nil cs.currentVote = nil
cs.myVote = nil cs.myVote = nil
} }
// ClearCachedVotes method
func (cs *ConsensusState) ClearCachedVotes() { func (cs *ConsensusState) ClearCachedVotes() {
cs.cachedVotes = nil cs.cachedVotes = nil
} }
func (cs *ConsensusState)VerifyVote(vote * dpostype.DPosVote) bool{ // VerifyVote method
func (cs *ConsensusState) VerifyVote(vote *dpostype.DPosVote) bool {
// Check validator // Check validator
index, val := cs.validatorMgr.Validators.GetByAddress(vote.VoterNodeAddress) index, val := cs.validatorMgr.Validators.GetByAddress(vote.VoterNodeAddress)
if index == -1 && val == nil { if index == -1 && val == nil {
...@@ -497,7 +512,8 @@ func (cs *ConsensusState)VerifyVote(vote * dpostype.DPosVote) bool{ ...@@ -497,7 +512,8 @@ func (cs *ConsensusState)VerifyVote(vote * dpostype.DPosVote) bool{
return true return true
} }
func (cs *ConsensusState)VerifyNotify(notify * dpostype.DPosNotify) bool{ // VerifyNotify method
func (cs *ConsensusState) VerifyNotify(notify *dpostype.DPosNotify) bool {
// Check validator // Check validator
index, val := cs.validatorMgr.Validators.GetByAddress(notify.NotifyNodeAddress) index, val := cs.validatorMgr.Validators.GetByAddress(notify.NotifyNodeAddress)
if index == -1 && val == nil { if index == -1 && val == nil {
......
...@@ -39,7 +39,6 @@ var ( ...@@ -39,7 +39,6 @@ var (
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() {
...@@ -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,11 +366,13 @@ func (client *Client) CheckTxDup(txs []*types.Transaction, height int64) (transa ...@@ -368,11 +366,13 @@ func (client *Client) CheckTxDup(txs []*types.Transaction, height int64) (transa
return types.CacheToTxs(cacheTxs) return types.CacheToTxs(cacheTxs)
} }
// SetBlockTime set current block time to generate new block
func (client *Client) SetBlockTime(blockTime int64) { 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
......
...@@ -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 {
......
...@@ -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.
...@@ -36,7 +36,7 @@ func setParams(delegateNum int64, blockInterval int64, continueBlockNum int64) { ...@@ -36,7 +36,7 @@ func setParams(delegateNum int64, blockInterval int64, continueBlockNum int64) {
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, 0x3d,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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,
} }
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
package types package types
import ( import (
"time"
"reflect" "reflect"
) "time"
)
var ( var (
// MsgMap define // MsgMap define
...@@ -33,8 +33,7 @@ func InitMessageMap() { ...@@ -33,8 +33,7 @@ func InitMessageMap() {
} }
} }
//---------------------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,10 +42,10 @@ type CanonicalJSONVoteItem struct { ...@@ -43,10 +42,10 @@ 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"`
...@@ -71,7 +70,7 @@ func CanonicalVote(vote *Vote) CanonicalJSONVote { ...@@ -71,7 +70,7 @@ func CanonicalVote(vote *Vote) CanonicalJSONVote {
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,
...@@ -79,6 +78,7 @@ func CanonicalVote(vote *Vote) CanonicalJSONVote { ...@@ -79,6 +78,7 @@ func CanonicalVote(vote *Vote) CanonicalJSONVote {
} }
} }
// CanonicalJSONNotify ...
type CanonicalJSONNotify struct { type CanonicalJSONNotify struct {
VoteItem *CanonicalJSONVoteItem `json:"vote,omitempty"` VoteItem *CanonicalJSONVoteItem `json:"vote,omitempty"`
...@@ -86,13 +86,13 @@ type CanonicalJSONNotify struct { ...@@ -86,13 +86,13 @@ type CanonicalJSONNotify struct {
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{
...@@ -103,7 +103,7 @@ func CanonicalNotify(notify *Notify) CanonicalJSONNotify { ...@@ -103,7 +103,7 @@ func CanonicalNotify(notify *Notify) CanonicalJSONNotify {
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,
......
...@@ -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))
......
...@@ -91,7 +91,7 @@ func (vote *Vote) String() string { ...@@ -91,7 +91,7 @@ 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),
...@@ -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,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
...@@ -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 {
......
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