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
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
203 additions
and
201 deletions
+203
-201
consensus_state.go
plugin/consensus/dpos/consensus_state.go
+65
-49
dpos.go
plugin/consensus/dpos/dpos.go
+24
-25
node.go
plugin/consensus/dpos/node.go
+1
-2
peer_set.go
plugin/consensus/dpos/peer_set.go
+2
-1
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
+0
-0
state_machine_test.go
plugin/consensus/dpos/state_machine_test.go
+7
-10
dpos_msg.pb.go
plugin/consensus/dpos/types/dpos_msg.pb.go
+29
-29
genesis.go
plugin/consensus/dpos/types/genesis.go
+5
-5
msg.go
plugin/consensus/dpos/types/msg.go
+43
-43
priv_validator.go
plugin/consensus/dpos/types/priv_validator.go
+2
-4
signable.go
plugin/consensus/dpos/types/signable.go
+9
-10
validator_set.go
plugin/consensus/dpos/types/validator_set.go
+5
-5
validator_manager.go
plugin/consensus/dpos/validator_manager.go
+9
-16
No files found.
plugin/consensus/dpos/consensus_state.go
View file @
b08c65a3
This diff is collapsed.
Click to expand it.
plugin/consensus/dpos/dpos.go
View file @
b08c65a3
...
...
@@ -22,24 +22,23 @@ import (
const
tendermintVersion
=
"0.1.0"
var
(
dposlog
=
log15
.
New
(
"module"
,
"dpos"
)
genesis
string
genesisBlockTime
int64
timeoutCheckConnections
int32
=
1000
timeoutVoting
int32
=
3000
timeoutWaitNotify
int32
=
2000
createEmptyBlocks
=
false
createEmptyBlocksInterval
int32
// second
validatorNodes
=
[]
string
{
"127.0.0.1:46656"
}
isValidator
=
false
dposDelegateNum
int64
=
3
//委托节点个数,从配置读取,以后可以根据投票结果来定
dposBlockInterval
int64
=
3
//出块间隔,当前按3s
dposContinueBlockNum
int64
=
6
//一个委托节点当选后,一次性持续出块数量
dposCycle
=
int64
(
dposDelegateNum
*
dposBlockInterval
*
dposContinueBlockNum
)
dposPeriod
=
int64
(
dposBlockInterval
*
dposContinueBlockNum
)
zeroHash
[
32
]
byte
dposlog
=
log15
.
New
(
"module"
,
"dpos"
)
genesis
string
genesisBlockTime
int64
timeoutCheckConnections
int32
=
1000
timeoutVoting
int32
=
3000
timeoutWaitNotify
int32
=
2000
createEmptyBlocks
=
false
createEmptyBlocksInterval
int32
// second
validatorNodes
=
[]
string
{
"127.0.0.1:46656"
}
isValidator
=
false
dposDelegateNum
int64
=
3
//委托节点个数,从配置读取,以后可以根据投票结果来定
dposBlockInterval
int64
=
3
//出块间隔,当前按3s
dposContinueBlockNum
int64
=
6
//一个委托节点当选后,一次性持续出块数量
dposCycle
=
int64
(
dposDelegateNum
*
dposBlockInterval
*
dposContinueBlockNum
)
dposPeriod
=
int64
(
dposBlockInterval
*
dposContinueBlockNum
)
zeroHash
[
32
]
byte
)
func
init
()
{
...
...
@@ -221,7 +220,7 @@ OuterLoop:
for
!
DebugCatchup
{
select
{
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
:
if
client
.
IsCaughtUp
()
{
dposlog
.
Info
(
"This node has caught up max height"
)
...
...
@@ -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,15 +366,17 @@ func (client *Client) CheckTxDup(txs []*types.Transaction, height int64) (transa
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
}
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
}
return
-
1
}
\ No newline at end of file
}
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
...
...
@@ -85,7 +85,7 @@ type peerConn struct {
onPeerError
func
(
Peer
,
interface
{})
myState
*
ConsensusState
myState
*
ConsensusState
}
// PeerSet struct
...
...
@@ -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
This diff is collapsed.
Click to expand it.
plugin/consensus/dpos/state_machine_test.go
View file @
b08c65a3
...
...
@@ -29,14 +29,14 @@ func init() {
setParams
(
3
,
3
,
6
)
}
func
setParams
(
delegateNum
int64
,
blockInterval
int64
,
continueBlockNum
int64
)
{
dposDelegateNum
=
delegateNum
//委托节点个数,从配置读取,以后可以根据投票结果来定
dposBlockInterval
=
blockInterval
//出块间隔,当前按3s
dposContinueBlockNum
=
continueBlockNum
//一个委托节点当选后,一次性持续出块数量
dposDelegateNum
=
delegateNum
//委托节点个数,从配置读取,以后可以根据投票结果来定
dposBlockInterval
=
blockInterval
//出块间隔,当前按3s
dposContinueBlockNum
=
continueBlockNum
//一个委托节点当选后,一次性持续出块数量
dposCycle
=
int64
(
dposDelegateNum
*
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
"
,
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
,
0xc3
,
0x
6c
,
0x25
,
0x17
,
0x6d
,
0x5f
,
0xa0
,
0xd0
,
0x9b
,
0xdc
,
0x84
,
0xe2
,
0x96
,
0xde
,
0x16
,
0x37
,
0x52
,
0x
63
,
0x43
,
0x1c
,
0x09
,
0x49
,
0x0d
,
0xcd
,
0x43
,
0xb4
,
0xaf
,
0xd6
,
0x57
,
0x2a
,
0x3a
,
0xfe
,
0x90
,
0xe
3
,
0xd0
,
0xbb
,
0x9c
,
0xdf
,
0x5f
,
0x1f
,
0xe7
,
0xfc
,
0x14
,
0xc3
,
0x8c
,
0x0a
,
0xae
,
0x1e
,
0x4a
,
0x
b5
,
0x59
,
0x08
,
0xc9
,
0x35
,
0x27
,
0x9e
,
0x3e
,
0x08
,
0xa6
,
0xe2
,
0xb7
,
0x01
,
0x04
,
0xf7
,
0x5c
,
0x
b3
,
0xa5
,
0x66
,
0x25
,
0xf9
,
0x0b
,
0xb3
,
0x3d
,
0xd7
,
0x8c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
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
...
...
@@ -23,11 +23,11 @@ type GenesisValidator struct {
// GenesisDoc defines the initial conditions for a tendermint blockchain, in particular its validator set.
type
GenesisDoc
struct
{
GenesisTime
time
.
Time
`json:"genesis_time"`
ChainID
string
`json:"chain_id"`
Validators
[]
GenesisValidator
`json:"validators"`
AppHash
[]
byte
`json:"app_hash"`
AppOptions
interface
{}
`json:"app_options,omitempty"`
GenesisTime
time
.
Time
`json:"genesis_time"`
ChainID
string
`json:"chain_id"`
Validators
[]
GenesisValidator
`json:"validators"`
AppHash
[]
byte
`json:"app_hash"`
AppOptions
interface
{}
`json:"app_options,omitempty"`
}
// SaveAs is a utility method for saving GenensisDoc as a JSON file.
...
...
plugin/consensus/dpos/types/msg.go
View file @
b08c65a3
...
...
@@ -5,9 +5,9 @@
package
types
import
(
"time"
"reflect"
)
"time"
)
var
(
// MsgMap define
...
...
@@ -16,9 +16,9 @@ var (
// step and message id define
const
(
VoteID
=
byte
(
0x06
)
VoteReplyID
=
byte
(
0x07
)
NotifyID
=
byte
(
0x08
)
VoteID
=
byte
(
0x06
)
VoteReplyID
=
byte
(
0x07
)
NotifyID
=
byte
(
0x08
)
PacketTypePing
=
byte
(
0xff
)
PacketTypePong
=
byte
(
0xfe
)
...
...
@@ -27,14 +27,13 @@ const (
// InitMessageMap ...
func
InitMessageMap
()
{
MsgMap
=
map
[
byte
]
reflect
.
Type
{
VoteID
:
reflect
.
TypeOf
(
DPosVote
{}),
VoteReplyID
:
reflect
.
TypeOf
(
DPosVoteReply
{}),
NotifyID
:
reflect
.
TypeOf
(
DPosNotify
{}),
VoteID
:
reflect
.
TypeOf
(
DPosVote
{}),
VoteReplyID
:
reflect
.
TypeOf
(
DPosVoteReply
{}),
NotifyID
:
reflect
.
TypeOf
(
DPosNotify
{}),
}
}
//---------------------Canonical json-----------------------------------
// CanonicalJSONVote ...
// CanonicalJSONVoteItem ...
type
CanonicalJSONVoteItem
struct
{
VotedNodeIndex
int32
`json:"votedNodeIndex,omitempty"`
VotedNodeAddress
[]
byte
`json:"votedNodeAddress,omitempty"`
...
...
@@ -43,15 +42,15 @@ 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"`
VoterNodeIndex
int32
`json:"voterNodeIndex,omitempty"`
VoterNodeAddress
[]
byte
`json:"voterNodeAddress,omitempty"`
VoteTimestamp
int64
`json:"voteTimestamp,omitempty"`
VoterNodeIndex
int32
`json:"voterNodeIndex,omitempty"`
VoterNodeAddress
[]
byte
`json:"voterNodeAddress,omitempty"`
}
// CanonicalJSONOnceVote ...
...
...
@@ -63,49 +62,50 @@ type CanonicalJSONOnceVote struct {
// CanonicalVote ...
func
CanonicalVote
(
vote
*
Vote
)
CanonicalJSONVote
{
return
CanonicalJSONVote
{
VoteItem
:
&
CanonicalJSONVoteItem
{
VotedNodeIndex
:
vote
.
VoteItem
.
VotedNodeIndex
,
VotedNodeAddress
:
vote
.
VoteItem
.
VotedNodeAddress
,
CycleStart
:
vote
.
VoteItem
.
CycleStart
,
CycleStop
:
vote
.
VoteItem
.
CycleStop
,
PeriodStart
:
vote
.
VoteItem
.
PeriodStart
,
PeriodStop
:
vote
.
VoteItem
.
PeriodStop
,
Height
:
vote
.
VoteItem
.
Height
,
VoteId
:
vote
.
VoteItem
.
VoteId
,
},
VoteTimestamp
:
vote
.
VoteTimestamp
,
VoterNodeIndex
:
vote
.
VoterNodeIndex
,
VoteItem
:
&
CanonicalJSONVoteItem
{
VotedNodeIndex
:
vote
.
VoteItem
.
VotedNodeIndex
,
VotedNodeAddress
:
vote
.
VoteItem
.
VotedNodeAddress
,
CycleStart
:
vote
.
VoteItem
.
CycleStart
,
CycleStop
:
vote
.
VoteItem
.
CycleStop
,
PeriodStart
:
vote
.
VoteItem
.
PeriodStart
,
PeriodStop
:
vote
.
VoteItem
.
PeriodStop
,
Height
:
vote
.
VoteItem
.
Height
,
VoteID
:
vote
.
VoteItem
.
VoteID
,
},
VoteTimestamp
:
vote
.
VoteTimestamp
,
VoterNodeIndex
:
vote
.
VoterNodeIndex
,
VoterNodeAddress
:
vote
.
VoterNodeAddress
,
}
}
// CanonicalJSONNotify ...
type
CanonicalJSONNotify
struct
{
VoteItem
*
CanonicalJSONVoteItem
`json:"vote,omitempty"`
VoteItem
*
CanonicalJSONVoteItem
`json:"vote,omitempty"`
HeightStop
int64
`json:"heightStop,omitempty"`
NotifyTimestamp
int64
`json:"notifyTimestamp,omitempty"`
HeightStop
int64
`json:"heightStop,omitempty"`
NotifyTimestamp
int64
`json:"notifyTimestamp,omitempty"`
}
// CanonicalJSONOnce
Vote
...
// CanonicalJSONOnce
Notify
...
type
CanonicalJSONOnceNotify
struct
{
ChainID
string
`json:"chain_id"`
Notify
CanonicalJSONNotify
`json:"vote"`
ChainID
string
`json:"chain_id"`
Notify
CanonicalJSONNotify
`json:"vote"`
}
// Canonical
Vote
...
// Canonical
Notify
...
func
CanonicalNotify
(
notify
*
Notify
)
CanonicalJSONNotify
{
return
CanonicalJSONNotify
{
VoteItem
:
&
CanonicalJSONVoteItem
{
VotedNodeIndex
:
notify
.
Vote
.
VotedNodeIndex
,
VoteItem
:
&
CanonicalJSONVoteItem
{
VotedNodeIndex
:
notify
.
Vote
.
VotedNodeIndex
,
VotedNodeAddress
:
notify
.
Vote
.
VotedNodeAddress
,
CycleStart
:
notify
.
Vote
.
CycleStart
,
CycleStop
:
notify
.
Vote
.
CycleStop
,
PeriodStart
:
notify
.
Vote
.
PeriodStart
,
PeriodStop
:
notify
.
Vote
.
PeriodStop
,
Height
:
notify
.
Vote
.
Height
,
VoteI
d
:
notify
.
Vote
.
VoteId
,
CycleStart
:
notify
.
Vote
.
CycleStart
,
CycleStop
:
notify
.
Vote
.
CycleStop
,
PeriodStart
:
notify
.
Vote
.
PeriodStart
,
PeriodStop
:
notify
.
Vote
.
PeriodStop
,
Height
:
notify
.
Vote
.
Height
,
VoteI
D
:
notify
.
Vote
.
VoteID
,
},
HeightStop
:
notify
.
HeightStop
,
HeightStop
:
notify
.
HeightStop
,
NotifyTimestamp
:
notify
.
NotifyTimestamp
,
}
}
...
...
plugin/consensus/dpos/types/priv_validator.go
View file @
b08c65a3
...
...
@@ -195,7 +195,7 @@ func LoadPrivValidatorFSWithSigner(filePath string, signerFunc func(PrivValidato
Exit
(
Fmt
(
"Error PrivValidator DecodeString failed:%v
\n
"
,
err
))
}
privValImp
:=
&
PrivValidatorImp
{
Address
:
addr
,
Address
:
addr
,
}
tmp
,
err
:=
hex
.
DecodeString
(
privVal
.
PrivKey
.
Data
)
if
err
!=
nil
{
...
...
@@ -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
...
...
@@ -21,12 +21,12 @@ var (
ErrNotifyInvalidValidatorIndex
=
errors
.
New
(
"Invalid validator index for notify"
)
ErrNotifyInvalidSignature
=
errors
.
New
(
"Invalid notify signature"
)
ErrVoteInvalidValidatorIndex
=
errors
.
New
(
"Invalid validator index for vote"
)
ErrVoteInvalidValidatorAddress
=
errors
.
New
(
"Invalid validator address for vote"
)
ErrVoteInvalidSignature
=
errors
.
New
(
"Invalid vote signature"
)
ErrVoteNil
=
errors
.
New
(
"Nil vote"
)
ErrVoteInvalidValidatorIndex
=
errors
.
New
(
"Invalid validator index for vote"
)
ErrVoteInvalidValidatorAddress
=
errors
.
New
(
"Invalid validator address for vote"
)
ErrVoteInvalidSignature
=
errors
.
New
(
"Invalid vote signature"
)
ErrVoteNil
=
errors
.
New
(
"Nil vote"
)
votelog
=
log15
.
New
(
"module"
,
"tendermint-vote"
)
votelog
=
log15
.
New
(
"module"
,
"tendermint-vote"
)
ConsensusCrypto
crypto
.
Crypto
)
...
...
@@ -91,12 +91,12 @@ 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
),
Fingerprint
(
vote
.
Signature
),
)
)
}
// Verify ...
...
...
@@ -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
...
...
@@ -18,15 +18,15 @@ var validatorsetlog = log15.New("module", "dpos-val")
// Validator ...
type
Validator
struct
{
Address
[]
byte
`json:"address"`
PubKey
[]
byte
`json:"pub_key"`
Address
[]
byte
`json:"address"`
PubKey
[]
byte
`json:"pub_key"`
}
// NewValidator ...
func
NewValidator
(
pubKey
crypto
.
PubKey
)
*
Validator
{
return
&
Validator
{
Address
:
GenAddressByPubKey
(
pubKey
),
PubKey
:
pubKey
.
Bytes
(),
Address
:
GenAddressByPubKey
(
pubKey
),
PubKey
:
pubKey
.
Bytes
(),
}
}
...
...
@@ -91,7 +91,7 @@ func (valSet *ValidatorSet) Copy() *ValidatorSet {
validators
[
i
]
=
val
.
Copy
()
}
return
&
ValidatorSet
{
Validators
:
validators
,
Validators
:
validators
,
}
}
...
...
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
...
...
@@ -33,7 +27,7 @@ type ValidatorMgr struct {
// so we can query for historical validator sets.
// Note that if s.LastBlockHeight causes a valset change,
// we set s.LastHeightValidatorsChanged = s.LastBlockHeight + 1
Validators
*
ttypes
.
ValidatorSet
Validators
*
ttypes
.
ValidatorSet
// The latest AppHash we've received from calling abci.Commit()
AppHash
[]
byte
...
...
@@ -44,7 +38,7 @@ func (s ValidatorMgr) Copy() ValidatorMgr {
return
ValidatorMgr
{
ChainID
:
s
.
ChainID
,
Validators
:
s
.
Validators
.
Copy
(),
Validators
:
s
.
Validators
.
Copy
(),
AppHash
:
s
.
AppHash
,
}
...
...
@@ -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
{
...
...
@@ -93,14 +86,14 @@ func MakeGenesisValidatorMgr(genDoc *ttypes.GenesisDoc) (ValidatorMgr, error) {
// Make validator
validators
[
i
]
=
&
ttypes
.
Validator
{
Address
:
ttypes
.
GenAddressByPubKey
(
pubKey
),
PubKey
:
pubKey
.
Bytes
(),
Address
:
ttypes
.
GenAddressByPubKey
(
pubKey
),
PubKey
:
pubKey
.
Bytes
(),
}
}
return
ValidatorMgr
{
ChainID
:
genDoc
.
ChainID
,
Validators
:
ttypes
.
NewValidatorSet
(
validators
),
AppHash
:
genDoc
.
AppHash
,
ChainID
:
genDoc
.
ChainID
,
Validators
:
ttypes
.
NewValidatorSet
(
validators
),
AppHash
:
genDoc
.
AppHash
,
},
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