Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
b08c65a3
Commit
b08c65a3
authored
Apr 30, 2019
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lint
parent
07cde0ca
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
193 additions
and
188 deletions
+193
-188
consensus_state.go
plugin/consensus/dpos/consensus_state.go
+38
-22
dpos.go
plugin/consensus/dpos/dpos.go
+4
-4
node.go
plugin/consensus/dpos/node.go
+1
-2
peer_set.go
plugin/consensus/dpos/peer_set.go
+1
-0
dpos_msg.proto
plugin/consensus/dpos/proto/dpos_msg.proto
+1
-1
secret_connection.go
plugin/consensus/dpos/secret_connection.go
+1
-1
state_machine.go
plugin/consensus/dpos/state_machine.go
+98
-96
state_machine_test.go
plugin/consensus/dpos/state_machine_test.go
+4
-7
dpos_msg.pb.go
plugin/consensus/dpos/types/dpos_msg.pb.go
+29
-29
genesis.go
plugin/consensus/dpos/types/genesis.go
+0
-0
msg.go
plugin/consensus/dpos/types/msg.go
+10
-10
priv_validator.go
plugin/consensus/dpos/types/priv_validator.go
+1
-3
signable.go
plugin/consensus/dpos/types/signable.go
+3
-4
validator_set.go
plugin/consensus/dpos/types/validator_set.go
+0
-0
validator_manager.go
plugin/consensus/dpos/validator_manager.go
+2
-9
No files found.
plugin/consensus/dpos/consensus_state.go
View file @
b08c65a3
...
...
@@ -27,7 +27,6 @@ const (
continueToVote
=
0
voteSuccess
=
1
voteFail
=
2
)
// Errors define
...
...
@@ -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)
}
// Get
State returns a copy of the chain state
.
// Get
ValidatorMgr returns a copy of the ValidatorMgr
.
func
(
cs
*
ConsensusState
)
GetValidatorMgr
()
ValidatorMgr
{
cs
.
mtx
.
Lock
()
defer
cs
.
mtx
.
Unlock
()
...
...
@@ -149,7 +148,7 @@ func (cs *ConsensusState) GetValidatorMgr() ValidatorMgr {
}
// GetValidators returns a copy of the current validators.
func
(
cs
*
ConsensusState
)
GetValidators
()
([]
*
ttypes
.
Validator
)
{
func
(
cs
*
ConsensusState
)
GetValidators
()
[]
*
ttypes
.
Validator
{
cs
.
mtx
.
Lock
()
defer
cs
.
mtx
.
Unlock
()
return
cs
.
validatorMgr
.
Validators
.
Copy
()
.
Validators
...
...
@@ -182,7 +181,7 @@ func (cs *ConsensusState) Start() {
go
cs
.
receiveRoutine
()
// schedule the first round!
cs
.
scheduleDPosTimeout
(
time
.
Second
*
3
,
InitStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Second
*
3
,
InitStateType
)
}
}
...
...
@@ -194,7 +193,7 @@ func (cs *ConsensusState) Stop() {
// Attempt to schedule a timeout (by sending timeoutInfo on the tickChan)
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
...
...
@@ -216,6 +215,7 @@ func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) {
func
(
cs
*
ConsensusState
)
updateToValMgr
(
valMgr
ValidatorMgr
)
{
cs
.
validatorMgr
=
valMgr
}
//-----------------------------------------
// the main go routines
...
...
@@ -297,22 +297,26 @@ func (cs *ConsensusState) IsProposer() bool {
return
false
}
func
(
cs
*
ConsensusState
)
SetState
(
state
DposState
){
// SetState method
func
(
cs
*
ConsensusState
)
SetState
(
state
DposState
)
{
cs
.
dposState
=
state
}
// SaveVote method
func
(
cs
*
ConsensusState
)
SaveVote
()
{
if
cs
.
lastVote
==
nil
{
cs
.
lastVote
=
cs
.
currentVote
}
else
if
cs
.
currentVote
!=
nil
&&
!
bytes
.
Equal
(
cs
.
currentVote
.
VoteI
d
,
cs
.
lastVote
.
VoteId
)
{
}
else
if
cs
.
currentVote
!=
nil
&&
!
bytes
.
Equal
(
cs
.
currentVote
.
VoteI
D
,
cs
.
lastVote
.
VoteID
)
{
cs
.
lastVote
=
cs
.
currentVote
}
}
func
(
cs
*
ConsensusState
)
SetCurrentVote
(
vote
*
dpostype
.
VoteItem
)
{
// SetCurrentVote method
func
(
cs
*
ConsensusState
)
SetCurrentVote
(
vote
*
dpostype
.
VoteItem
)
{
cs
.
currentVote
=
vote
}
// SaveMyVote method
func
(
cs
*
ConsensusState
)
SaveMyVote
()
{
if
cs
.
lastMyVote
==
nil
{
cs
.
lastMyVote
=
cs
.
myVote
...
...
@@ -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
}
// SaveNotify method
func
(
cs
*
ConsensusState
)
SaveNotify
()
{
if
cs
.
lastNotify
==
nil
{
cs
.
lastNotify
=
cs
.
notify
...
...
@@ -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
)
{
cs
.
lastNotify
=
cs
.
notify
}
...
...
@@ -341,15 +348,18 @@ func (cs *ConsensusState) SetNotify(notify * dpostype.DPosNotify){
cs
.
notify
=
notify
}
func
(
cs
*
ConsensusState
)
CacheNotify
(
notify
*
dpostype
.
DPosNotify
){
// CacheNotify method
func
(
cs
*
ConsensusState
)
CacheNotify
(
notify
*
dpostype
.
DPosNotify
)
{
cs
.
cachedNotify
=
notify
}
func
(
cs
*
ConsensusState
)
ClearCachedNotify
(){
// ClearCachedNotify method
func
(
cs
*
ConsensusState
)
ClearCachedNotify
()
{
cs
.
cachedNotify
=
nil
}
func
(
cs
*
ConsensusState
)
AddVotes
(
vote
*
dpostype
.
DPosVote
){
// AddVotes method
func
(
cs
*
ConsensusState
)
AddVotes
(
vote
*
dpostype
.
DPosVote
)
{
repeatFlag
:=
false
addrExistFlag
:=
false
index
:=
-
1
...
...
@@ -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
addrExistFlag
:=
false
index
:=
-
1
...
...
@@ -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
)
//总的票数还不够2/3,先不做决定
...
...
@@ -429,9 +441,9 @@ func (cs *ConsensusState) CheckVotes()(ty int, vote * dpostype.VoteItem){
return
continueToVote
,
nil
}
voteStat
:=
map
[
string
]
int
{}
voteStat
:=
map
[
string
]
int
{}
for
i
:=
0
;
i
<
len
(
cs
.
dposVotes
);
i
++
{
key
:=
string
(
cs
.
dposVotes
[
i
]
.
VoteItem
.
VoteI
d
)
key
:=
string
(
cs
.
dposVotes
[
i
]
.
VoteItem
.
VoteI
D
)
if
_
,
ok
:=
voteStat
[
key
];
ok
{
voteStat
[
key
]
++
}
else
{
...
...
@@ -452,11 +464,11 @@ func (cs *ConsensusState) CheckVotes()(ty int, vote * dpostype.VoteItem){
//如果一个节点的投票数已经过2/3,则返回最终票数超过2/3的选票
if
value
>=
major32
{
for
i
:=
0
;
i
<
len
(
cs
.
dposVotes
);
i
++
{
if
key
==
string
(
cs
.
dposVotes
[
i
]
.
VoteItem
.
VoteI
d
)
{
if
key
==
string
(
cs
.
dposVotes
[
i
]
.
VoteItem
.
VoteI
D
)
{
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多数,不能达成共识。
return
voteFail
,
nil
}
...
...
@@ -464,17 +476,20 @@ func (cs *ConsensusState) CheckVotes()(ty int, vote * dpostype.VoteItem){
return
continueToVote
,
nil
}
func
(
cs
*
ConsensusState
)
ClearVotes
(){
// ClearVotes method
func
(
cs
*
ConsensusState
)
ClearVotes
()
{
cs
.
dposVotes
=
nil
cs
.
currentVote
=
nil
cs
.
myVote
=
nil
}
// ClearCachedVotes method
func
(
cs
*
ConsensusState
)
ClearCachedVotes
()
{
cs
.
cachedVotes
=
nil
}
func
(
cs
*
ConsensusState
)
VerifyVote
(
vote
*
dpostype
.
DPosVote
)
bool
{
// VerifyVote method
func
(
cs
*
ConsensusState
)
VerifyVote
(
vote
*
dpostype
.
DPosVote
)
bool
{
// Check validator
index
,
val
:=
cs
.
validatorMgr
.
Validators
.
GetByAddress
(
vote
.
VoterNodeAddress
)
if
index
==
-
1
&&
val
==
nil
{
...
...
@@ -497,7 +512,8 @@ func (cs *ConsensusState)VerifyVote(vote * dpostype.DPosVote) bool{
return
true
}
func
(
cs
*
ConsensusState
)
VerifyNotify
(
notify
*
dpostype
.
DPosNotify
)
bool
{
// VerifyNotify method
func
(
cs
*
ConsensusState
)
VerifyNotify
(
notify
*
dpostype
.
DPosNotify
)
bool
{
// Check validator
index
,
val
:=
cs
.
validatorMgr
.
Validators
.
GetByAddress
(
notify
.
NotifyNodeAddress
)
if
index
==
-
1
&&
val
==
nil
{
...
...
plugin/consensus/dpos/dpos.go
View file @
b08c65a3
...
...
@@ -39,7 +39,6 @@ var (
dposCycle
=
int64
(
dposDelegateNum
*
dposBlockInterval
*
dposContinueBlockNum
)
dposPeriod
=
int64
(
dposBlockInterval
*
dposContinueBlockNum
)
zeroHash
[
32
]
byte
)
func
init
()
{
...
...
@@ -328,10 +327,9 @@ func (client *Client) CreateBlock() {
return
}
}
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
}
//check dup
...
...
@@ -368,11 +366,13 @@ func (client *Client) CheckTxDup(txs []*types.Transaction, height int64) (transa
return
types
.
CacheToTxs
(
cacheTxs
)
}
// SetBlockTime set current block time to generate new block
func
(
client
*
Client
)
SetBlockTime
(
blockTime
int64
)
{
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
{
index
,
_
:=
client
.
csState
.
validatorMgr
.
Validators
.
GetByAddress
(
client
.
privValidator
.
GetAddress
())
return
index
...
...
plugin/consensus/dpos/node.go
View file @
b08c65a3
...
...
@@ -42,7 +42,7 @@ const (
minReadBufferSize
=
1024
minWriteBufferSize
=
65536
)
)
// Parallel method
func
Parallel
(
tasks
...
func
())
{
...
...
@@ -301,7 +301,6 @@ func (node *Node) StartConsensusRoutine() {
}
}
// BroadcastRoutine receive to broadcast
func
(
node
*
Node
)
BroadcastRoutine
()
{
for
{
...
...
plugin/consensus/dpos/peer_set.go
View file @
b08c65a3
...
...
@@ -530,6 +530,7 @@ FOR_LOOP:
// Drain
}
}
// StackError struct
type
StackError
struct
{
Err
interface
{}
...
...
plugin/consensus/dpos/proto/dpos_msg.proto
View file @
b08c65a3
...
...
@@ -11,7 +11,7 @@ message VoteItem {
int64
periodStart
=
5
;
//新节点负责出块的起始时间
int64
periodStop
=
6
;
//新节点负责出块的终止时间
int64
height
=
7
;
//新节点负责出块的起始高度
bytes
voteI
d
=
8
;
//选票ID
bytes
voteI
D
=
8
;
//选票ID
}
//DPosVote Dpos共识的节点投票,为达成共识用。
...
...
plugin/consensus/dpos/secret_connection.go
View file @
b08c65a3
...
...
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// 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.
// Note we do not (yet) assume that a remote peer's pubkey
// is known ahead of time, and thus we are technically
...
...
plugin/consensus/dpos/state_machine.go
View file @
b08c65a3
...
...
@@ -10,22 +10,37 @@ import (
"github.com/outbrain/golib/math"
"time"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
dpostype
"github.com/33cn/plugin/plugin/consensus/dpos/types"
"github.com/33cn/chain33/common"
)
var
(
// InitStateType 为状态机的初始状态
InitStateType
=
1
// VotingStateType 为状态机的投票状态
VotingStateType
=
2
// VotedStateType 为状态机的已投票状态
VotedStateType
=
3
// WaitNotifyStateType 为状态机的等待通知状态
WaitNotifyStateType
=
4
StateTypeMapping
=
map
[
int
]
string
{
InitStateType
:
"InitState"
,
VotingStateType
:
"VotingState"
,
VotedStateType
:
"VotedState"
,
WaitNotifyStateType
:
"WaitNotifyState"
}
// StateTypeMapping 为状态的整型值和字符串值的对应关系
StateTypeMapping
=
map
[
int
]
string
{
InitStateType
:
"InitState"
,
VotingStateType
:
"VotingState"
,
VotedStateType
:
"VotedState"
,
WaitNotifyStateType
:
"WaitNotifyState"
}
)
// InitStateObj is the InitState obj
var
InitStateObj
=
&
InitState
{}
// VotingStateObj is the VotingState obj
var
VotingStateObj
=
&
VotingState
{}
// VotedStateObj is the VotedState obj
var
VotedStateObj
=
&
VotedState
{}
// WaitNotifyStateObj is the WaitNotifyState obj
var
WaitNotifyStateObj
=
&
WaitNofifyState
{}
// DPosTask 为计算当前时间所属周期的数据结构
type
DPosTask
struct
{
nodeI
d
int64
nodeI
D
int64
cycleStart
int64
cycleStop
int64
periodStart
int64
...
...
@@ -34,71 +49,69 @@ type DPosTask struct {
blockStop
int64
}
func
DecideTaskByTime
(
now
int64
)
(
task
DPosTask
){
task
.
nodeId
=
now
%
dposCycle
/
dposPeriod
// DecideTaskByTime 根据时间戳计算所属的周期,包括cycle周期,负责出块周期,当前出块周期
func
DecideTaskByTime
(
now
int64
)
(
task
DPosTask
)
{
task
.
nodeID
=
now
%
dposCycle
/
dposPeriod
task
.
cycleStart
=
now
-
now
%
dposCycle
task
.
cycleStart
=
now
-
now
%
dposCycle
task
.
cycleStop
=
task
.
cycleStart
+
dposCycle
-
1
task
.
periodStart
=
task
.
cycleStart
+
task
.
nodeI
d
*
dposBlockInterval
*
dposContinueBlockNum
task
.
periodStart
=
task
.
cycleStart
+
task
.
nodeI
D
*
dposBlockInterval
*
dposContinueBlockNum
task
.
periodStop
=
task
.
periodStart
+
dposPeriod
-
1
task
.
blockStart
=
task
.
periodStart
+
now
%
dposCycle
%
dposPeriod
/
dposBlockInterval
*
dposBlockInterval
task
.
blockStart
=
task
.
periodStart
+
now
%
dposCycle
%
dposPeriod
/
dposBlockInterval
*
dposBlockInterval
task
.
blockStop
=
task
.
blockStart
+
dposBlockInterval
-
1
return
task
}
// DposState is the base class of dpos state machine, it defines some interfaces.
type
DposState
interface
{
timeOut
(
cs
*
ConsensusState
)
sendVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
recvVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
sendVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
recvVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
sendNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
sendVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
recvVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
sendVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
recvVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
sendNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
}
// InitState is the initial state of dpos state machine
type
InitState
struct
{
}
func
(
init
*
InitState
)
timeOut
(
cs
*
ConsensusState
)
{
func
(
init
*
InitState
)
timeOut
(
cs
*
ConsensusState
)
{
//if available noes < 2/3, don't change the state to voting.
connections
:=
cs
.
client
.
node
.
peerSet
.
Size
()
validators
:=
cs
.
validatorMgr
.
Validators
.
Size
()
if
connections
==
0
||
connections
<
(
validators
*
2
/
3
-
1
)
{
if
connections
==
0
||
connections
<
(
validators
*
2
/
3
-
1
)
{
dposlog
.
Error
(
"InitState timeout but available nodes less than 2/3,waiting for more connections"
,
"connections"
,
connections
,
"validators"
,
validators
)
cs
.
ClearVotes
()
//设定超时时间,超时后再检查链接数量
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
}
else
{
//获得当前高度
height
:=
cs
.
client
.
GetCurrentHeight
()
now
:=
time
.
Now
()
.
Unix
()
if
cs
.
lastMyVote
!=
nil
&&
math
.
AbsInt64
(
now
-
cs
.
lastMyVote
.
VoteItem
.
PeriodStop
)
<=
1
{
if
cs
.
lastMyVote
!=
nil
&&
math
.
AbsInt64
(
now
-
cs
.
lastMyVote
.
VoteItem
.
PeriodStop
)
<=
1
{
now
+=
2
}
//计算当前时间,属于哪一个周期,应该哪一个节点出块,应该出块的高度
task
:=
DecideTaskByTime
(
now
)
addr
,
validator
:=
cs
.
validatorMgr
.
Validators
.
GetByIndex
(
int
(
task
.
nodeI
d
))
addr
,
validator
:=
cs
.
validatorMgr
.
Validators
.
GetByIndex
(
int
(
task
.
nodeI
D
))
if
addr
==
nil
&&
validator
==
nil
{
dposlog
.
Error
(
"Address and Validator is nil"
,
"node index"
,
task
.
nodeI
d
,
"now"
,
now
,
"cycle"
,
dposCycle
,
"period"
,
dposPeriod
)
dposlog
.
Error
(
"Address and Validator is nil"
,
"node index"
,
task
.
nodeI
D
,
"now"
,
now
,
"cycle"
,
dposCycle
,
"period"
,
dposPeriod
)
//cs.SetState(InitStateObj)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
return
}
//生成vote, 对于vote进行签名
voteItem
:=
&
dpostype
.
VoteItem
{
VotedNodeAddress
:
addr
,
VotedNodeIndex
:
int32
(
task
.
nodeId
),
VotedNodeIndex
:
int32
(
task
.
nodeID
),
CycleStart
:
task
.
cycleStart
,
CycleStop
:
task
.
cycleStop
,
PeriodStart
:
task
.
periodStart
,
...
...
@@ -109,14 +122,14 @@ func (init *InitState)timeOut(cs *ConsensusState) {
encode
,
err
:=
json
.
Marshal
(
voteItem
)
if
err
!=
nil
{
panic
(
"Marshal vote failed."
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
return
//cs.scheduleDPosTimeout(time.Duration(timeoutCheckConnections)*
time.Millisecond, InitStateType)
//
return
}
voteItem
.
VoteI
d
=
crypto
.
Ripemd160
(
encode
)
voteItem
.
VoteI
D
=
crypto
.
Ripemd160
(
encode
)
index
:=
-
1
for
i
:=
0
;
i
<
cs
.
validatorMgr
.
Validators
.
Size
();
i
++
{
for
i
:=
0
;
i
<
cs
.
validatorMgr
.
Validators
.
Size
();
i
++
{
if
bytes
.
Compare
(
cs
.
validatorMgr
.
Validators
.
Validators
[
i
]
.
Address
,
cs
.
privValidator
.
GetAddress
())
==
0
{
index
=
i
break
...
...
@@ -138,7 +151,7 @@ func (init *InitState)timeOut(cs *ConsensusState) {
if
err
:=
cs
.
privValidator
.
SignVote
(
cs
.
validatorMgr
.
ChainID
,
vote
);
err
!=
nil
{
dposlog
.
Error
(
"SignVote failed"
,
"vote"
,
vote
.
String
())
//cs.SetState(InitStateObj)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
return
}
...
...
@@ -152,7 +165,7 @@ func (init *InitState)timeOut(cs *ConsensusState) {
//通过node发送p2p消息到其他节点
cs
.
dposState
.
sendVote
(
cs
,
vote
.
DPosVote
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutVoting
)
*
time
.
Millisecond
,
VotingStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutVoting
)
*
time
.
Millisecond
,
VotingStateType
)
//处理之前缓存的投票信息
for
i
:=
0
;
i
<
len
(
cs
.
cachedVotes
);
i
++
{
cs
.
dposState
.
recvVote
(
cs
,
cs
.
cachedVotes
[
i
])
...
...
@@ -161,29 +174,29 @@ func (init *InitState)timeOut(cs *ConsensusState) {
}
}
func
(
init
*
InitState
)
sendVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
func
(
init
*
InitState
)
sendVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
dposlog
.
Info
(
"InitState does not support sendVote,so do nothing"
)
}
func
(
init
*
InitState
)
recvVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
func
(
init
*
InitState
)
recvVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
dposlog
.
Info
(
"InitState recvVote ,add it and will handle it later."
)
//cs.AddVotes(vote)
cs
.
CacheVotes
(
vote
)
}
func
(
init
*
InitState
)
sendVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
func
(
init
*
InitState
)
sendVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
dposlog
.
Info
(
"InitState don't support sendVoteReply,so do nothing"
)
}
func
(
init
*
InitState
)
recvVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
func
(
init
*
InitState
)
recvVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
dposlog
.
Info
(
"InitState recv Vote reply,ignore it."
)
}
func
(
init
*
InitState
)
sendNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
func
(
init
*
InitState
)
sendNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
dposlog
.
Info
(
"InitState does not support sendNotify,so do nothing"
)
}
func
(
init
*
InitState
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
func
(
init
*
InitState
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
dposlog
.
Info
(
"InitState recvNotify"
)
//zzh:需要增加对Notify的处理,可以考虑记录已经确认过的出快记录
...
...
@@ -192,10 +205,9 @@ func (init *InitState)recvNotify(cs *ConsensusState, notify * dpostype.DPosNotif
// VotingState is the voting state of dpos state machine until timeout or get an agreement by votes.
type
VotingState
struct
{
}
func
(
voting
*
VotingState
)
timeOut
(
cs
*
ConsensusState
)
{
func
(
voting
*
VotingState
)
timeOut
(
cs
*
ConsensusState
)
{
dposlog
.
Info
(
"VotingState timeout but don't get an agreement. change state to InitState"
)
//清理掉之前的选票记录,从初始状态重新开始
...
...
@@ -205,14 +217,14 @@ func (voting *VotingState)timeOut(cs *ConsensusState) {
dposlog
.
Info
(
"Change state because of timeOut."
,
"from"
,
"VotingState"
,
"to"
,
"InitState"
)
//由于连接多数情况下正常,快速触发InitState的超时处理
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
}
func
(
voting
*
VotingState
)
sendVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
func
(
voting
*
VotingState
)
sendVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
cs
.
broadcastChannel
<-
MsgInfo
{
TypeID
:
dpostype
.
VoteID
,
Msg
:
vote
,
PeerID
:
cs
.
ourID
,
PeerIP
:
""
}
}
func
(
voting
*
VotingState
)
recvVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
func
(
voting
*
VotingState
)
recvVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
dposlog
.
Info
(
"VotingState get a vote"
,
"VotedNodeIndex"
,
vote
.
VoteItem
.
VotedNodeIndex
,
"VotedNodeAddress"
,
common
.
ToHex
(
vote
.
VoteItem
.
VotedNodeAddress
),
"CycleStart"
,
vote
.
VoteItem
.
CycleStart
,
...
...
@@ -220,12 +232,12 @@ func (voting *VotingState)recvVote(cs *ConsensusState,vote * dpostype.DPosVote)
"PeriodStart"
,
vote
.
VoteItem
.
PeriodStart
,
"periodStop"
,
vote
.
VoteItem
.
PeriodStop
,
"Height"
,
vote
.
VoteItem
.
Height
,
"VoteId"
,
common
.
ToHex
(
vote
.
VoteItem
.
VoteId
),
"VoteID"
,
common
.
ToHex
(
vote
.
VoteItem
.
VoteID
),
"VoteTimestamp"
,
vote
.
VoteTimestamp
,
"VoterNodeIndex"
,
vote
.
VoterNodeIndex
,
"VoterNodeAddress"
,
common
.
ToHex
(
vote
.
VoterNodeAddress
),
"Signature"
,
common
.
ToHex
(
vote
.
Signature
),
"localNodeIndex"
,
cs
.
client
.
ValidatorIndex
(),
"now"
,
time
.
Now
()
.
Unix
())
"localNodeIndex"
,
cs
.
client
.
ValidatorIndex
(),
"now"
,
time
.
Now
()
.
Unix
())
if
!
cs
.
VerifyVote
(
vote
)
{
dposlog
.
Info
(
"VotingState verify vote failed"
)
...
...
@@ -246,7 +258,7 @@ func (voting *VotingState)recvVote(cs *ConsensusState,vote * dpostype.DPosVote)
cs
.
SetCurrentVote
(
voteItem
)
//1s后检查是否出块,是否需要重新投票
cs
.
scheduleDPosTimeout
(
time
.
Millisecond
*
500
,
VotedStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Millisecond
*
500
,
VotedStateType
)
}
else
if
result
==
continueToVote
{
dposlog
.
Info
(
"VotingState get a vote, but don't get an agreement,waiting for new votes..."
)
}
else
{
...
...
@@ -255,34 +267,33 @@ func (voting *VotingState)recvVote(cs *ConsensusState,vote * dpostype.DPosVote)
cs
.
ClearVotes
()
cs
.
SetState
(
InitStateObj
)
dposlog
.
Info
(
"Change state because of vote failed."
,
"from"
,
"VotingState"
,
"to"
,
"InitState"
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
}
}
func
(
voting
*
VotingState
)
sendVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
func
(
voting
*
VotingState
)
sendVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
dposlog
.
Info
(
"VotingState don't support sendVoteReply,so do nothing"
)
//cs.broadcastChannel <- MsgInfo{TypeID: dpostype.VoteReplyID, Msg: reply, PeerID: cs.ourID, PeerIP: ""}
}
func
(
voting
*
VotingState
)
recvVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
func
(
voting
*
VotingState
)
recvVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
dposlog
.
Info
(
"VotingState recv Vote reply"
)
voting
.
recvVote
(
cs
,
reply
.
Vote
)
}
func
(
voting
*
VotingState
)
sendNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
func
(
voting
*
VotingState
)
sendNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
dposlog
.
Info
(
"VotingState does not support sendNotify,so do nothing"
)
}
func
(
voting
*
VotingState
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
func
(
voting
*
VotingState
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
dposlog
.
Info
(
"VotingState does not support recvNotify,so do nothing"
)
}
// Vot
ingState is the voting state of dpos state machine until timeout or get an agreement by votes.
// Vot
edState is the voted state of dpos state machine after getting an agreement for a period
type
VotedState
struct
{
}
func
(
voted
*
VotedState
)
timeOut
(
cs
*
ConsensusState
)
{
func
(
voted
*
VotedState
)
timeOut
(
cs
*
ConsensusState
)
{
now
:=
time
.
Now
()
.
Unix
()
block
:=
cs
.
client
.
GetCurrentBlock
()
task
:=
DecideTaskByTime
(
now
)
...
...
@@ -330,9 +341,9 @@ func (voted *VotedState)timeOut(cs *ConsensusState) {
dposlog
.
Info
(
"Change state because of time."
,
"from"
,
"VotedState"
,
"to"
,
"InitState"
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
return
}
else
{
}
//如果区块未同步,则等待;如果区块已同步,则进行后续正常出块的判断和处理。
if
block
.
Height
+
1
<
cs
.
currentVote
.
Height
{
if
block
.
Height
+
1
<
cs
.
currentVote
.
Height
{
dposlog
.
Info
(
"VotedState timeOut but block is not sync,wait..."
,
"localHeight"
,
block
.
Height
,
"vote height"
,
cs
.
currentVote
.
Height
)
cs
.
scheduleDPosTimeout
(
time
.
Second
*
1
,
VotedStateType
)
return
...
...
@@ -342,35 +353,33 @@ func (voted *VotedState)timeOut(cs *ConsensusState) {
if
block
.
BlockTime
>=
task
.
blockStop
{
//已出块,或者时间落后了。
dposlog
.
Info
(
"VotedState timeOut but block already is generated."
,
"blocktime"
,
block
.
BlockTime
,
"blockStop"
,
task
.
blockStop
,
"now"
,
now
)
cs
.
scheduleDPosTimeout
(
time
.
Second
*
1
,
VotedStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Second
*
1
,
VotedStateType
)
return
}
else
if
block
.
BlockTime
<
task
.
blockStart
{
//本出块周期尚未出块,则进行出块
if
task
.
blockStop
-
now
<=
1
{
dposlog
.
Info
(
"Create new block."
,
"height"
,
block
.
Height
+
1
)
dposlog
.
Info
(
"Create new block."
,
"height"
,
block
.
Height
+
1
)
cs
.
client
.
SetBlockTime
(
task
.
blockStop
)
cs
.
client
.
CreateBlock
()
cs
.
scheduleDPosTimeout
(
time
.
Millisecond
*
500
,
VotedStateType
)
return
}
else
{
dposlog
.
Info
(
"Wait time to create block near blockStop."
,
"waittime"
,
task
.
blockStop
-
now
-
1
)
//cs.scheduleDPosTimeout(time.Second * time.Duration(task.blockStop - now - 1), VotedStateType
)
}
dposlog
.
Info
(
"Wait time to create block near blockStop."
)
cs
.
scheduleDPosTimeout
(
time
.
Millisecond
*
500
,
VotedStateType
)
return
}
}
else
{
//本周期已经出块
dposlog
.
Info
(
"Wait to next block cycle."
,
"waittime"
,
task
.
blockStop
-
now
+
1
)
//cs.scheduleDPosTimeout(time.Second * time.Duration(task.blockStop-now+1), VotedStateType)
cs
.
scheduleDPosTimeout
(
time
.
Millisecond
*
500
,
VotedStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Millisecond
*
500
,
VotedStateType
)
return
}
}
}
else
{
}
else
{
dposlog
.
Info
(
"This node is not current owner."
,
"current owner index"
,
cs
.
currentVote
.
VotedNodeIndex
,
"this node index"
,
cs
.
client
.
ValidatorIndex
())
//非当前出块节点,如果到了切换出块节点的时间,则进行状态切换,进行投票
...
...
@@ -381,36 +390,36 @@ func (voted *VotedState)timeOut(cs *ConsensusState) {
cs
.
ClearVotes
()
cs
.
SetState
(
WaitNotifyStateObj
)
dposlog
.
Info
(
"Change state because of time."
,
"from"
,
"VotedState"
,
"to"
,
"WaitNotifyState"
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutWaitNotify
)
*
time
.
Millisecond
,
WaitNotifyStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutWaitNotify
)
*
time
.
Millisecond
,
WaitNotifyStateType
)
if
cs
.
cachedNotify
!=
nil
{
cs
.
dposState
.
recvNotify
(
cs
,
cs
.
cachedNotify
)
}
return
}
else
{
}
//设置超时时间
dposlog
.
Info
(
"wait until change state."
,
"waittime"
,
cs
.
currentVote
.
PeriodStop
-
now
+
1
)
cs
.
scheduleDPosTimeout
(
time
.
Second
*
time
.
Duration
(
cs
.
currentVote
.
PeriodStop
-
now
+
1
),
VotedStateType
)
dposlog
.
Info
(
"wait until change state."
,
"waittime"
,
cs
.
currentVote
.
PeriodStop
-
now
+
1
)
cs
.
scheduleDPosTimeout
(
time
.
Second
*
time
.
Duration
(
cs
.
currentVote
.
PeriodStop
-
now
+
1
),
VotedStateType
)
return
}
}
}
func
(
voted
*
VotedState
)
sendVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
func
(
voted
*
VotedState
)
sendVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
dposlog
.
Info
(
"VotedState sendVoteReply"
)
cs
.
broadcastChannel
<-
MsgInfo
{
TypeID
:
dpostype
.
VoteReplyID
,
Msg
:
reply
,
PeerID
:
cs
.
ourID
,
PeerIP
:
""
}
}
func
(
voted
*
VotedState
)
recvVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
func
(
voted
*
VotedState
)
recvVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
dposlog
.
Info
(
"VotedState recv Vote reply"
,
"from index"
,
reply
.
Vote
.
VoterNodeIndex
,
"local index"
,
cs
.
privValidatorIndex
)
cs
.
AddVotes
(
reply
.
Vote
)
}
func
(
voted
*
VotedState
)
sendVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
func
(
voted
*
VotedState
)
sendVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
dposlog
.
Info
(
"VotedState does not support sendVote,so do nothing"
)
}
func
(
voted
*
VotedState
)
recvVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
func
(
voted
*
VotedState
)
recvVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
dposlog
.
Info
(
"VotedState recv Vote, will reply it"
,
"from index"
,
vote
.
VoterNodeIndex
,
"local index"
,
cs
.
privValidatorIndex
)
if
cs
.
currentVote
.
PeriodStart
>=
vote
.
VoteItem
.
PeriodStart
{
vote2
:=
*
cs
.
myVote
...
...
@@ -423,17 +432,18 @@ func (voted *VotedState)recvVote(cs *ConsensusState,vote * dpostype.DPosVote) {
}
}
func
(
voted
*
VotedState
)
sendNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
func
(
voted
*
VotedState
)
sendNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
cs
.
broadcastChannel
<-
MsgInfo
{
TypeID
:
dpostype
.
NotifyID
,
Msg
:
notify
,
PeerID
:
cs
.
ourID
,
PeerIP
:
""
}
}
func
(
voted
*
VotedState
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
func
(
voted
*
VotedState
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
dposlog
.
Info
(
"VotedState recvNotify"
)
if
bytes
.
Equal
(
cs
.
privValidator
.
GetAddress
(),
cs
.
currentVote
.
VotedNodeAddress
)
{
dposlog
.
Info
(
"ignore recvNotify because this node is the owner now."
)
return
}
else
{
}
cs
.
CacheNotify
(
notify
)
cs
.
SaveVote
()
cs
.
SaveMyVote
()
...
...
@@ -446,26 +456,24 @@ func (voted *VotedState)recvNotify(cs *ConsensusState, notify * dpostype.DPosNot
}
return
}
}
//
VotingState is the voting state of dpos state machine until timeout or get an agreement by votes
.
//
WaitNofifyState is the state of dpos state machine to wait notify
.
type
WaitNofifyState
struct
{
}
func
(
wait
*
WaitNofifyState
)
timeOut
(
cs
*
ConsensusState
)
{
func
(
wait
*
WaitNofifyState
)
timeOut
(
cs
*
ConsensusState
)
{
//cs.clearVotes()
cs
.
SetState
(
InitStateObj
)
dposlog
.
Info
(
"Change state because of time."
,
"from"
,
"WaitNofifyState"
,
"to"
,
"InitState"
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
cs
.
scheduleDPosTimeout
(
time
.
Duration
(
timeoutCheckConnections
)
*
time
.
Millisecond
,
InitStateType
)
}
func
(
wait
*
WaitNofifyState
)
sendVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
func
(
wait
*
WaitNofifyState
)
sendVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
dposlog
.
Info
(
"WaitNofifyState does not support sendVote,so do nothing"
)
}
func
(
wait
*
WaitNofifyState
)
recvVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
func
(
wait
*
WaitNofifyState
)
recvVote
(
cs
*
ConsensusState
,
vote
*
dpostype
.
DPosVote
)
{
dposlog
.
Info
(
"WaitNofifyState recvVote,store it."
)
//对于vote进行保存,在后续状态中进行处理。 保存的选票有先后,同一个节点发来的最新的选票被保存。
//if !cs.VerifyVote(vote) {
...
...
@@ -477,19 +485,19 @@ func (wait *WaitNofifyState)recvVote(cs *ConsensusState,vote * dpostype.DPosVote
cs
.
CacheVotes
(
vote
)
}
func
(
wait
*
WaitNofifyState
)
sendVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
func
(
wait
*
WaitNofifyState
)
sendVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
dposlog
.
Info
(
"WaitNofifyState does not support sendVoteReply,so do nothing"
)
}
func
(
wait
*
WaitNofifyState
)
recvVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
func
(
wait
*
WaitNofifyState
)
recvVoteReply
(
cs
*
ConsensusState
,
reply
*
dpostype
.
DPosVoteReply
)
{
dposlog
.
Info
(
"WaitNofifyState recv Vote reply,ignore it."
)
}
func
(
wait
*
WaitNofifyState
)
sendNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
func
(
wait
*
WaitNofifyState
)
sendNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
dposlog
.
Info
(
"WaitNofifyState does not support sendNotify,so do nothing"
)
}
func
(
wait
*
WaitNofifyState
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
func
(
wait
*
WaitNofifyState
)
recvNotify
(
cs
*
ConsensusState
,
notify
*
dpostype
.
DPosNotify
)
{
dposlog
.
Info
(
"WaitNofifyState recvNotify"
)
//记录Notify,校验区块,标记不可逆区块高度
if
!
cs
.
VerifyNotify
(
notify
)
{
...
...
@@ -498,10 +506,10 @@ func (wait *WaitNofifyState)recvNotify(cs *ConsensusState, notify * dpostype.DPo
}
block
:=
cs
.
client
.
GetCurrentBlock
()
if
(
block
.
Height
>
notify
.
HeightStop
)
{
if
block
.
Height
>
notify
.
HeightStop
{
dposlog
.
Info
(
"Local block height is advanced than notify, discard it."
,
"localheight"
,
block
.
Height
,
"notify"
,
notify
.
String
())
return
}
else
if
block
.
Height
==
notify
.
HeightStop
&&
bytes
.
Equal
(
block
.
Hash
(),
notify
.
HashStop
){
}
else
if
block
.
Height
==
notify
.
HeightStop
&&
bytes
.
Equal
(
block
.
Hash
(),
notify
.
HashStop
)
{
dposlog
.
Info
(
"Local block height is sync with notify"
,
"notify"
,
notify
.
String
())
}
else
{
dposlog
.
Info
(
"Local block height is not sync with notify"
,
"localheight"
,
cs
.
client
.
GetCurrentHeight
(),
"notify"
,
notify
.
String
())
...
...
@@ -512,7 +520,7 @@ func (wait *WaitNofifyState)recvNotify(cs *ConsensusState, notify * dpostype.DPo
for
!
catchupFlag
{
select
{
case
<-
hint
.
C
:
dposlog
.
Info
(
"Still catching up max height......"
,
"Height"
,
cs
.
client
.
GetCurrentHeight
(),
"notifyHeight"
,
notify
.
HeightStop
,
"cost"
,
time
.
Since
(
beg
))
dposlog
.
Info
(
"Still catching up max height......"
,
"Height"
,
cs
.
client
.
GetCurrentHeight
(),
"notifyHeight"
,
notify
.
HeightStop
,
"cost"
,
time
.
Since
(
beg
))
if
cs
.
client
.
IsCaughtUp
()
&&
cs
.
client
.
GetCurrentHeight
()
>=
notify
.
HeightStop
{
dposlog
.
Info
(
"This node has caught up max height"
,
"Height"
,
cs
.
client
.
GetCurrentHeight
(),
"isHashSame"
,
bytes
.
Equal
(
block
.
Hash
(),
notify
.
HashStop
))
break
OuterLoop
...
...
@@ -539,8 +547,3 @@ func (wait *WaitNofifyState)recvNotify(cs *ConsensusState, notify * dpostype.DPo
cs
.
dposState
.
timeOut
(
cs
)
//cs.scheduleDPosTimeout(time.Second * 1, InitStateType)
}
var
InitStateObj
=
&
InitState
{}
var
VotingStateObj
=
&
VotingState
{}
var
VotedStateObj
=
&
VotedState
{}
var
WaitNotifyStateObj
=
&
WaitNofifyState
{}
\ No newline at end of file
plugin/consensus/dpos/state_machine_test.go
View file @
b08c65a3
...
...
@@ -36,7 +36,7 @@ func setParams(delegateNum int64, blockInterval int64, continueBlockNum int64) {
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
"
,
now
,
task
.
cycleStart
,
...
...
@@ -45,10 +45,10 @@ func printTask(now int64, task *DPosTask){
task
.
periodStop
,
task
.
blockStart
,
task
.
blockStop
,
task
.
nodeI
d
)
task
.
nodeI
D
)
}
func
assertTask
(
task
*
DPosTask
,
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
true
,
task
.
nodeI
d
>=
0
&&
task
.
nodeId
<
dposDelegateNum
)
func
assertTask
(
task
*
DPosTask
,
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
true
,
task
.
nodeI
D
>=
0
&&
task
.
nodeID
<
dposDelegateNum
)
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) {
printTask
(
now
,
&
task
)
assertTask
(
&
task
,
t
)
setParams
(
2
,
1
,
6
)
now
=
time
.
Now
()
.
Unix
()
task
=
DecideTaskByTime
(
now
)
...
...
@@ -72,7 +71,6 @@ func TestDecideTaskByTime(t *testing.T) {
printTask
(
now
,
&
task
)
assertTask
(
&
task
,
t
)
setParams
(
21
,
2
,
12
)
now
=
time
.
Now
()
.
Unix
()
task
=
DecideTaskByTime
(
now
)
...
...
@@ -89,4 +87,3 @@ func TestDecideTaskByTime(t *testing.T) {
time
.
Sleep
(
time
.
Second
*
1
)
}
}
plugin/consensus/dpos/types/dpos_msg.pb.go
View file @
b08c65a3
...
...
@@ -38,7 +38,7 @@ type VoteItem struct {
PeriodStart
int64
`protobuf:"varint,5,opt,name=periodStart" json:"periodStart,omitempty"`
PeriodStop
int64
`protobuf:"varint,6,opt,name=periodStop" json:"periodStop,omitempty"`
Height
int64
`protobuf:"varint,7,opt,name=height" json:"height,omitempty"`
VoteI
d
[]
byte
`protobuf:"bytes,8,opt,name=voteId,proto3" json:"voteId
,omitempty"`
VoteI
D
[]
byte
`protobuf:"bytes,8,opt,name=voteID,proto3" json:"voteID
,omitempty"`
}
func
(
m
*
VoteItem
)
Reset
()
{
*
m
=
VoteItem
{}
}
...
...
@@ -95,9 +95,9 @@ func (m *VoteItem) GetHeight() int64 {
return
0
}
func
(
m
*
VoteItem
)
GetVoteI
d
()
[]
byte
{
func
(
m
*
VoteItem
)
GetVoteI
D
()
[]
byte
{
if
m
!=
nil
{
return
m
.
VoteI
d
return
m
.
VoteI
D
}
return
nil
}
...
...
@@ -242,30 +242,30 @@ func init() {
func
init
()
{
proto
.
RegisterFile
(
"dpos_msg.proto"
,
fileDescriptor0
)
}
var
fileDescriptor0
=
[]
byte
{
// 38
6
bytes of a gzipped FileDescriptorProto
0x1f
,
0x8b
,
0x08
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x02
,
0xff
,
0x74
,
0x93
,
0x
dd
,
0x6a
,
0xdb
,
0x3
0
,
0x14
,
0xc7
,
0x
71
,
0x1c
,
0x3b
,
0xde
,
0xc9
,
0xd7
,
0xa6
,
0x8b
,
0x61
,
0xc6
,
0x18
,
0xc6
,
0x1b
,
0x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
0x
47
,
0x8e
,
0x45
,
0xdb
,
0x71
,
0xdf
,
0x38
,
0x6e
,
0x73
,
0xed
,
0x50
,
0xe6
,
0xeb
,
0x6d
,
0xa2
,
0xde
,
0x
04
,
0x45
,
0x47
,
0xa3
,
0xd8
,
0x80
,
0xf0
,
0x16
,
0xc6
,
0xf5
,
0x40
,
0x31
,
0xe5
,
0x9b
,
0x3d
,
0x39
,
0x
85
,
0xbe
,
0x3e
,
0xa2
,
0x33
,
0x51
,
0xb3
,
0x06
,
0xc3
,
0xf0
,
0xa3
,
0x07
,
0xa0
,
0xd1
,
0x92
,
0xa9
,
0x
fc
,
0xf5
,
0xa7
,
0x3d
,
0x8d
,
0x05
,
0x0c
,
0xf5
,
0x5b
,
0x94
,
0x76
,
0xf1
,
0x2d
,
0xca
,
0xf1
,
0x5b
,
0x
84
,
0xfc
,
0x03
,
0x2f
,
0x4b
,
0x64
,
0x86
,
0xa9
,
0x8d
,
0x6d
,
0x36
,
0x35
,
0x89
,
0x60
,
0xba
,
0xc5
,
0x
ab
,
0x8c
,
0xbf
,
0xf2
,
0xdf
,
0xd0
,
0xc5
,
0x66
,
0xa5
,
0x51
,
0xe8
,
0xa0
,
0xc2
,
0x2e
,
0x26
,
0x57
,
0x
f0
,
0xc7
,
0xa0
,
0x5a
,
0xa2
,
0x8b
,
0x17
,
0x1f
,
0x07
,
0x87
,
0x16
,
0x07
,
0x1d
,
0x8b
,
0x2f
,
0x2e
,
0x
7e
,
0x36
,
0x37
,
0xdf
,
0x01
,
0x00
,
0x00
,
0xff
,
0xff
,
0x6e
,
0xf4
,
0x71
,
0xcb
,
0x48
,
0x03
,
0x00
,
0x00
,
}
plugin/consensus/dpos/types/genesis.go
View file @
b08c65a3
plugin/consensus/dpos/types/msg.go
View file @
b08c65a3
...
...
@@ -5,9 +5,9 @@
package
types
import
(
"time"
"reflect"
)
"time"
)
var
(
// MsgMap define
...
...
@@ -33,8 +33,7 @@ func InitMessageMap() {
}
}
//---------------------Canonical json-----------------------------------
// CanonicalJSONVote ...
// CanonicalJSONVoteItem ...
type
CanonicalJSONVoteItem
struct
{
VotedNodeIndex
int32
`json:"votedNodeIndex,omitempty"`
VotedNodeAddress
[]
byte
`json:"votedNodeAddress,omitempty"`
...
...
@@ -43,10 +42,10 @@ type CanonicalJSONVoteItem struct {
PeriodStart
int64
`json:"periodStart,omitempty"`
PeriodStop
int64
`json:"periodStop,omitempty"`
Height
int64
`json:"height,omitempty"`
VoteI
d
[]
byte
`json:"voteId
,omitempty"`
VoteI
D
[]
byte
`json:"voteID
,omitempty"`
}
// CanonicalJSONVote ...
type
CanonicalJSONVote
struct
{
VoteItem
*
CanonicalJSONVoteItem
`json:"vote,omitempty"`
VoteTimestamp
int64
`json:"voteTimestamp,omitempty"`
...
...
@@ -71,7 +70,7 @@ func CanonicalVote(vote *Vote) CanonicalJSONVote {
PeriodStart
:
vote
.
VoteItem
.
PeriodStart
,
PeriodStop
:
vote
.
VoteItem
.
PeriodStop
,
Height
:
vote
.
VoteItem
.
Height
,
VoteId
:
vote
.
VoteItem
.
VoteId
,
VoteID
:
vote
.
VoteItem
.
VoteID
,
},
VoteTimestamp
:
vote
.
VoteTimestamp
,
VoterNodeIndex
:
vote
.
VoterNodeIndex
,
...
...
@@ -79,6 +78,7 @@ func CanonicalVote(vote *Vote) CanonicalJSONVote {
}
}
// CanonicalJSONNotify ...
type
CanonicalJSONNotify
struct
{
VoteItem
*
CanonicalJSONVoteItem
`json:"vote,omitempty"`
...
...
@@ -86,13 +86,13 @@ type CanonicalJSONNotify struct {
NotifyTimestamp
int64
`json:"notifyTimestamp,omitempty"`
}
// CanonicalJSONOnce
Vote
...
// CanonicalJSONOnce
Notify
...
type
CanonicalJSONOnceNotify
struct
{
ChainID
string
`json:"chain_id"`
Notify
CanonicalJSONNotify
`json:"vote"`
}
// Canonical
Vote
...
// Canonical
Notify
...
func
CanonicalNotify
(
notify
*
Notify
)
CanonicalJSONNotify
{
return
CanonicalJSONNotify
{
VoteItem
:
&
CanonicalJSONVoteItem
{
...
...
@@ -103,7 +103,7 @@ func CanonicalNotify(notify *Notify) CanonicalJSONNotify {
PeriodStart
:
notify
.
Vote
.
PeriodStart
,
PeriodStop
:
notify
.
Vote
.
PeriodStop
,
Height
:
notify
.
Vote
.
Height
,
VoteI
d
:
notify
.
Vote
.
VoteId
,
VoteI
D
:
notify
.
Vote
.
VoteID
,
},
HeightStop
:
notify
.
HeightStop
,
NotifyTimestamp
:
notify
.
NotifyTimestamp
,
...
...
plugin/consensus/dpos/types/priv_validator.go
View file @
b08c65a3
...
...
@@ -290,7 +290,6 @@ func (pv *PrivValidatorImp) SignVote(chainID string, vote *Vote) error {
signBytes
:=
SignBytes
(
chainID
,
vote
)
signature
,
err
:=
pv
.
Sign
(
signBytes
)
if
err
!=
nil
{
return
errors
.
New
(
Fmt
(
"Error signing vote: %v"
,
err
))
...
...
@@ -299,7 +298,7 @@ func (pv *PrivValidatorImp) SignVote(chainID string, vote *Vote) error {
return
nil
}
// Sign
Vote signs a canonical representation of the vote
, along with the
// Sign
Notify signs a canonical representation of the notify
, along with the
// chainID. Implements PrivValidator.
func
(
pv
*
PrivValidatorImp
)
SignNotify
(
chainID
string
,
notify
*
Notify
)
error
{
pv
.
mtx
.
Lock
()
...
...
@@ -307,7 +306,6 @@ func (pv *PrivValidatorImp) SignNotify(chainID string, notify *Notify) error {
signBytes
:=
SignBytes
(
chainID
,
notify
)
signature
,
err
:=
pv
.
Sign
(
signBytes
)
if
err
!=
nil
{
return
errors
.
New
(
Fmt
(
"Error signing vote: %v"
,
err
))
...
...
plugin/consensus/dpos/types/signable.go
View file @
b08c65a3
...
...
@@ -91,7 +91,7 @@ func (vote *Vote) String() string {
vote
.
VoteItem
.
PeriodStart
,
vote
.
VoteItem
.
PeriodStop
,
vote
.
VoteItem
.
Height
,
Fingerprint
(
vote
.
VoteItem
.
VoteI
d
),
Fingerprint
(
vote
.
VoteItem
.
VoteI
D
),
CanonicalTime
(
time
.
Unix
(
0
,
vote
.
VoteTimestamp
)),
vote
.
VoterNodeIndex
,
Fingerprint
(
vote
.
VoterNodeAddress
),
...
...
@@ -133,8 +133,7 @@ func (vote *Vote) Hash() []byte {
return
crypto
.
Ripemd160
(
bytes
)
}
// Vote Represents a vote from validators for consensus.
// Notify Represents a notify from validators for consensus.
type
Notify
struct
{
*
DPosNotify
}
...
...
@@ -178,7 +177,7 @@ func (notify *Notify) String() string {
notify
.
Vote
.
PeriodStart
,
notify
.
Vote
.
PeriodStop
,
notify
.
Vote
.
Height
,
Fingerprint
(
notify
.
Vote
.
VoteI
d
),
Fingerprint
(
notify
.
Vote
.
VoteI
D
),
CanonicalTime
(
time
.
Unix
(
0
,
notify
.
NotifyTimestamp
)),
notify
.
HeightStop
,
notify
.
NotifyNodeIndex
,
...
...
plugin/consensus/dpos/types/validator_set.go
View file @
b08c65a3
plugin/consensus/dpos/validator_manager.go
View file @
b08c65a3
...
...
@@ -18,13 +18,7 @@ var (
r
*
rand
.
Rand
)
// State is a short description of the latest committed block of the Tendermint consensus.
// 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.
// ValidatorMgr ...
type
ValidatorMgr
struct
{
// Immutable
ChainID
string
...
...
@@ -75,8 +69,7 @@ func (s ValidatorMgr) GetValidators() (current *ttypes.ValidatorSet) {
return
s
.
Validators
}
// MakeGenesisState creates state from ttypes.GenesisDoc.
// MakeGenesisValidatorMgr creates validators from ttypes.GenesisDoc.
func
MakeGenesisValidatorMgr
(
genDoc
*
ttypes
.
GenesisDoc
)
(
ValidatorMgr
,
error
)
{
err
:=
genDoc
.
ValidateAndComplete
()
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment