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
8fd20a22
Commit
8fd20a22
authored
Sep 18, 2019
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
d6a85a25
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
45 additions
and
38 deletions
+45
-38
consensus_state.go
plugin/consensus/dpos/consensus_state.go
+7
-6
dpos.go
plugin/consensus/dpos/dpos.go
+15
-2
dpos_test.go
plugin/consensus/dpos/dpos_test.go
+11
-18
genesis.json
plugin/consensus/dpos/genesis.json
+0
-2
node.go
plugin/consensus/dpos/node.go
+2
-2
node_test.go
plugin/consensus/dpos/node_test.go
+0
-0
priv_validator.json
plugin/consensus/dpos/priv_validator.json
+0
-2
ticker_test.go
plugin/consensus/dpos/ticker_test.go
+3
-1
genesis_test.go
plugin/consensus/dpos/types/genesis_test.go
+4
-4
priv_validator.go
plugin/consensus/dpos/types/priv_validator.go
+3
-1
No files found.
plugin/consensus/dpos/consensus_state.go
View file @
8fd20a22
...
@@ -185,11 +185,11 @@ func (cs *ConsensusState) SetPrivValidator(priv ttypes.PrivValidator, index int)
...
@@ -185,11 +185,11 @@ func (cs *ConsensusState) SetPrivValidator(priv ttypes.PrivValidator, index int)
}
}
// SetTimeoutTicker sets the local timer. It may be useful to overwrite for testing.
// SetTimeoutTicker sets the local timer. It may be useful to overwrite for testing.
func
(
cs
*
ConsensusState
)
SetTimeoutTicker
(
timeoutTicker
TimeoutTicker
)
{
//
func (cs *ConsensusState) SetTimeoutTicker(timeoutTicker TimeoutTicker) {
cs
.
mtx
.
Lock
()
//
cs.mtx.Lock()
defer
cs
.
mtx
.
Unlock
()
//
defer cs.mtx.Unlock()
cs
.
timeoutTicker
=
timeoutTicker
//
cs.timeoutTicker = timeoutTicker
}
//
}
// Start It start first time starts the timeout receive routines.
// Start It start first time starts the timeout receive routines.
func
(
cs
*
ConsensusState
)
Start
()
{
func
(
cs
*
ConsensusState
)
Start
()
{
...
@@ -219,6 +219,7 @@ func (cs *ConsensusState) scheduleDPosTimeout(duration time.Duration, stateType
...
@@ -219,6 +219,7 @@ func (cs *ConsensusState) scheduleDPosTimeout(duration time.Duration, 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
/*
func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) {
func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) {
select {
select {
case cs.internalMsgQueue <- mi:
case cs.internalMsgQueue <- mi:
...
@@ -231,7 +232,7 @@ func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) {
...
@@ -231,7 +232,7 @@ func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) {
go func() { cs.internalMsgQueue <- mi }()
go func() { cs.internalMsgQueue <- mi }()
}
}
}
}
*/
// Updates ConsensusState and increments height to match that of state.
// Updates ConsensusState and increments height to match that of state.
// The round becomes 0 and cs.Step becomes ttypes.RoundStepNewHeight.
// The round becomes 0 and cs.Step becomes ttypes.RoundStepNewHeight.
func
(
cs
*
ConsensusState
)
updateToValMgr
(
valMgr
ValidatorMgr
)
{
func
(
cs
*
ConsensusState
)
updateToValMgr
(
valMgr
ValidatorMgr
)
{
...
...
plugin/consensus/dpos/dpos.go
View file @
8fd20a22
...
@@ -76,6 +76,7 @@ type Client struct {
...
@@ -76,6 +76,7 @@ type Client struct {
stopC
chan
struct
{}
stopC
chan
struct
{}
isDelegator
bool
isDelegator
bool
blockTime
int64
blockTime
int64
testFlag
bool
}
}
type
subConfig
struct
{
type
subConfig
struct
{
...
@@ -230,6 +231,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
...
@@ -230,6 +231,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
crypto
:
cr
,
crypto
:
cr
,
stopC
:
make
(
chan
struct
{},
1
),
stopC
:
make
(
chan
struct
{},
1
),
isDelegator
:
false
,
isDelegator
:
false
,
testFlag
:
false
,
}
}
c
.
SetChild
(
client
)
c
.
SetChild
(
client
)
...
@@ -366,7 +368,7 @@ OuterLoop:
...
@@ -366,7 +368,7 @@ OuterLoop:
csState
.
SetPrivValidator
(
client
.
privValidator
,
client
.
ValidatorIndex
())
csState
.
SetPrivValidator
(
client
.
privValidator
,
client
.
ValidatorIndex
())
// Create & add listener
// Create & add listener
protocol
,
listeningAddress
:=
"tcp"
,
"0.0.0.0:"
+
dposPort
protocol
,
listeningAddress
:=
"tcp"
,
"0.0.0.0:"
+
dposPort
node
:=
NewNode
(
validatorNodes
,
protocol
,
listeningAddress
,
client
.
privKey
,
valMgr
.
ChainID
,
dposVersion
,
csState
)
node
:=
NewNode
(
validatorNodes
,
protocol
,
listeningAddress
,
client
.
privKey
,
valMgr
.
ChainID
,
dposVersion
,
csState
)
client
.
node
=
node
client
.
node
=
node
...
@@ -376,7 +378,7 @@ OuterLoop:
...
@@ -376,7 +378,7 @@ OuterLoop:
client
.
InitBlock
()
client
.
InitBlock
()
time
.
Sleep
(
time
.
Second
*
2
)
time
.
Sleep
(
time
.
Second
*
2
)
client
.
csState
.
Init
()
client
.
csState
.
Init
()
node
.
Start
()
node
.
Start
(
client
.
testFlag
)
}
}
//go client.MonitorCandidators()
//go client.MonitorCandidators()
...
@@ -763,3 +765,13 @@ func printCandidators(cands []*dty.Candidator) string {
...
@@ -763,3 +765,13 @@ func printCandidators(cands []*dty.Candidator) string {
func
(
client
*
Client
)
GetConsensusState
()
*
ConsensusState
{
func
(
client
*
Client
)
GetConsensusState
()
*
ConsensusState
{
return
client
.
csState
return
client
.
csState
}
}
// SetTestFlag set the test flag
func
(
client
*
Client
)
SetTestFlag
()
{
client
.
testFlag
=
true
}
// GetNode return the pointer to Node
func
(
client
*
Client
)
GetNode
()
*
Node
{
return
client
.
node
}
\ No newline at end of file
plugin/consensus/dpos/dpos_test.go
View file @
8fd20a22
...
@@ -69,7 +69,7 @@ func init() {
...
@@ -69,7 +69,7 @@ func init() {
pubkey
,
_
=
hex
.
DecodeString
(
strPubkey
)
pubkey
,
_
=
hex
.
DecodeString
(
strPubkey
)
}
}
func
TestDposPerf
(
t
*
testing
.
T
)
{
func
TestDposPerf
(
t
*
testing
.
T
)
{
DposPerf
()
//
DposPerf()
fmt
.
Println
(
"=======start clear test data!======="
)
fmt
.
Println
(
"=======start clear test data!======="
)
clearTestData
()
clearTestData
()
}
}
...
@@ -83,9 +83,10 @@ func DposPerf() {
...
@@ -83,9 +83,10 @@ func DposPerf() {
defer
q
.
Close
()
defer
q
.
Close
()
defer
cs
.
Close
()
defer
cs
.
Close
()
defer
p2p
.
Close
()
defer
p2p
.
Close
()
err
:=
createConn
()
var
err
error
conn
,
c
,
err
=
createConn
(
"127.0.0.1:8802"
)
for
err
!=
nil
{
for
err
!=
nil
{
err
=
createConn
(
)
conn
,
c
,
err
=
createConn
(
"127.0.0.1:8802"
)
}
}
time
.
Sleep
(
10
*
time
.
Second
)
time
.
Sleep
(
10
*
time
.
Second
)
for
i
:=
0
;
i
<
loopCount
;
i
++
{
for
i
:=
0
;
i
<
loopCount
;
i
++
{
...
@@ -149,15 +150,7 @@ func DposPerf() {
...
@@ -149,15 +150,7 @@ func DposPerf() {
dposClient
.
csState
.
SendCBTx
(
info
)
dposClient
.
csState
.
SendCBTx
(
info
)
sendCBTx
(
dposClient
.
csState
,
info
)
sendCBTx
(
dposClient
.
csState
,
info
)
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
/*
info2 := dposClient.csState.GetCBInfoByCircle(task.Cycle)
if info2 != nil && info2.StopHeight == info.StopHeight {
fmt.Println("GetCBInfoByCircle ok")
} else {
fmt.Println("GetCBInfoByCircle failed")
}
time.Sleep(1 * time.Second)
*/
for
{
for
{
now
=
time
.
Now
()
.
Unix
()
now
=
time
.
Now
()
.
Unix
()
task
=
DecideTaskByTime
(
now
)
task
=
DecideTaskByTime
(
now
)
...
@@ -282,18 +275,18 @@ func initEnvDpos() (queue.Queue, *blockchain.BlockChain, queue.Module, queue.Mod
...
@@ -282,18 +275,18 @@ func initEnvDpos() (queue.Queue, *blockchain.BlockChain, queue.Module, queue.Mod
return
q
,
chain
,
s
,
mem
,
exec
,
cs
,
network
return
q
,
chain
,
s
,
mem
,
exec
,
cs
,
network
}
}
func
createConn
(
)
error
{
func
createConn
(
url
string
)
(
*
grpc
.
ClientConn
,
types
.
Chain33Client
,
error
)
{
var
err
error
var
err
error
url
:=
"127.0.0.1:8802"
//
url := "127.0.0.1:8802"
fmt
.
Println
(
"grpc url:"
,
url
)
fmt
.
Println
(
"grpc url:"
,
url
)
conn
,
err
=
grpc
.
Dial
(
url
,
grpc
.
WithInsecure
())
conn
1
,
err
:
=
grpc
.
Dial
(
url
,
grpc
.
WithInsecure
())
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
err
return
conn1
,
nil
,
err
}
}
c
=
types
.
NewChain33Client
(
conn
)
c
1
:
=
types
.
NewChain33Client
(
conn
)
//r = rand.New(rand.NewSource(types.Now().UnixNano()))
//r = rand.New(rand.NewSource(types.Now().UnixNano()))
return
nil
return
conn1
,
c1
,
nil
}
}
func
generateKey
(
i
,
valI
int
)
string
{
func
generateKey
(
i
,
valI
int
)
string
{
...
...
plugin/consensus/dpos/genesis.json
deleted
100644 → 0
View file @
d6a85a25
{
"genesis_time"
:
"2018-08-16T15:38:56.951569432+08:00"
,
"chain_id"
:
"chain33-Z2cgFj"
,
"validators"
:[{
"pub_key"
:{
"type"
:
"secp256k1"
,
"data"
:
"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"
},
"name"
:
""
},{
"pub_key"
:{
"type"
:
"secp256k1"
,
"data"
:
"027848E7FA630B759DB406940B5506B666A344B1060794BBF314EB459D40881BB3"
},
"name"
:
""
},{
"pub_key"
:{
"type"
:
"secp256k1"
,
"data"
:
"03F4AB6659E61E8512C9A24AC385CC1AC4D52B87D10ADBDF060086EA82BE62CDDE"
},
"name"
:
""
}],
"app_hash"
:
null
}
\ No newline at end of file
plugin/consensus/dpos/node.go
View file @
8fd20a22
...
@@ -169,7 +169,7 @@ func NewNode(seeds []string, protocol string, lAddr string, privKey crypto.PrivK
...
@@ -169,7 +169,7 @@ func NewNode(seeds []string, protocol string, lAddr string, privKey crypto.PrivK
}
}
// Start node
// Start node
func
(
node
*
Node
)
Start
()
{
func
(
node
*
Node
)
Start
(
testFlag
bool
)
{
if
atomic
.
CompareAndSwapUint32
(
&
node
.
started
,
0
,
1
)
{
if
atomic
.
CompareAndSwapUint32
(
&
node
.
started
,
0
,
1
)
{
// Create listener
// Create listener
var
listener
net
.
Listener
var
listener
net
.
Listener
...
@@ -197,7 +197,7 @@ func (node *Node) Start() {
...
@@ -197,7 +197,7 @@ func (node *Node) Start() {
addr
:=
node
.
seeds
[
i
]
addr
:=
node
.
seeds
[
i
]
ip
,
_
:=
splitHostPort
(
addr
)
ip
,
_
:=
splitHostPort
(
addr
)
_
,
ok
:=
node
.
localIPs
[
ip
]
_
,
ok
:=
node
.
localIPs
[
ip
]
if
ok
{
if
ok
&&
!
testFlag
{
dposlog
.
Info
(
"find our ip "
,
"ourip"
,
ip
)
dposlog
.
Info
(
"find our ip "
,
"ourip"
,
ip
)
node
.
IP
=
ip
node
.
IP
=
ip
return
return
...
...
plugin/consensus/dpos/node_test.go
0 → 100644
View file @
8fd20a22
This diff is collapsed.
Click to expand it.
plugin/consensus/dpos/priv_validator.json
deleted
100644 → 0
View file @
d6a85a25
{
"address"
:
"2B226E6603E52C94715BA4E92080EEF236292E33"
,
"pub_key"
:{
"type"
:
"secp256k1"
,
"data"
:
"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"
},
"last_height"
:
1679
,
"last_round"
:
0
,
"last_step"
:
3
,
"last_signature"
:{
"type"
:
"secp256k1"
,
"data"
:
"37892A916D6E487ADF90F9E88FE37024597677B6C6FED47444AD582F74144B3D6E4B364EAF16AF03A4E42827B6D3C86415D734A5A6CCA92E114B23EB9265AF09"
},
"last_signbytes"
:
"7B22636861696E5F6964223A22636861696E33332D5A326367466A222C22766F7465223A7B22626C6F636B5F6964223A7B2268617368223A224F6A657975396B2B4149426A6E4859456739584765356A7A462B673D222C227061727473223A7B2268617368223A6E756C6C2C22746F74616C223A307D7D2C22686569676874223A313637392C22726F756E64223A302C2274696D657374616D70223A22323031382D30382D33315430373A35313A34332E3935395A222C2274797065223A327D7D"
,
"priv_key"
:{
"type"
:
"secp256k1"
,
"data"
:
"5A6A14DA6F5A42835E529D75D87CC8904544F59EEE5387A37D87EEAD194D7EB2"
}}
\ No newline at end of file
plugin/consensus/dpos/ticker_test.go
View file @
8fd20a22
package
dpos
package
dpos
import
(
import
(
"fmt"
"testing"
"testing"
"time"
"time"
...
@@ -15,6 +16,7 @@ func TestTicker(t *testing.T) {
...
@@ -15,6 +16,7 @@ func TestTicker(t *testing.T) {
Duration
:
time
.
Second
*
time
.
Duration
(
2
),
Duration
:
time
.
Second
*
time
.
Duration
(
2
),
State
:
InitStateType
,
State
:
InitStateType
,
}
}
fmt
.
Println
(
"timeoutInfo:"
,
ti
.
String
())
now
:=
time
.
Now
()
.
Unix
()
now
:=
time
.
Now
()
.
Unix
()
ticker
.
ScheduleTimeout
(
ti
)
ticker
.
ScheduleTimeout
(
ti
)
...
@@ -23,5 +25,5 @@ func TestTicker(t *testing.T) {
...
@@ -23,5 +25,5 @@ func TestTicker(t *testing.T) {
ticker
.
Stop
()
ticker
.
Stop
()
assert
.
True
(
t
,
end
-
now
>=
2
)
assert
.
True
(
t
,
end
-
now
>=
2
)
fmt
.
Println
(
"TestTicker ok"
)
}
}
plugin/consensus/dpos/types/genesis_test.go
View file @
8fd20a22
...
@@ -11,9 +11,9 @@ import (
...
@@ -11,9 +11,9 @@ import (
)
)
const
(
const
(
errGenesisFile
=
`{"genesis_time:"2018-08-16T15:38:56.951569432+08:00","chain_id":"chain33-Z2cgF
j
","validators":[{"pub_key":{"type":"secp256k1","data":"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"},"name":""},{"pub_key":{"type":"secp256k1","data":"027848E7FA630B759DB406940B5506B666A344B1060794BBF314EB459D40881BB3"},"name":""},{"pub_key":{"type":"secp256k1","data":"03F4AB6659E61E8512C9A24AC385CC1AC4D52B87D10ADBDF060086EA82BE62CDDE"},"name":""}],"app_hash":null}`
errGenesisFile
=
`{"genesis_time:"2018-08-16T15:38:56.951569432+08:00","chain_id":"chain33-Z2cgF
X
","validators":[{"pub_key":{"type":"secp256k1","data":"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"},"name":""},{"pub_key":{"type":"secp256k1","data":"027848E7FA630B759DB406940B5506B666A344B1060794BBF314EB459D40881BB3"},"name":""},{"pub_key":{"type":"secp256k1","data":"03F4AB6659E61E8512C9A24AC385CC1AC4D52B87D10ADBDF060086EA82BE62CDDE"},"name":""}],"app_hash":null}`
genesisFile
=
`{"genesis_time":"2018-08-16T15:38:56.951569432+08:00","chain_id":"chain33-Z2cgF
j
","validators":[{"pub_key":{"type":"secp256k1","data":"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"},"name":""},{"pub_key":{"type":"secp256k1","data":"027848E7FA630B759DB406940B5506B666A344B1060794BBF314EB459D40881BB3"},"name":""},{"pub_key":{"type":"secp256k1","data":"03F4AB6659E61E8512C9A24AC385CC1AC4D52B87D10ADBDF060086EA82BE62CDDE"},"name":""}],"app_hash":null}`
genesisFile
=
`{"genesis_time":"2018-08-16T15:38:56.951569432+08:00","chain_id":"chain33-Z2cgF
X
","validators":[{"pub_key":{"type":"secp256k1","data":"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"},"name":""},{"pub_key":{"type":"secp256k1","data":"027848E7FA630B759DB406940B5506B666A344B1060794BBF314EB459D40881BB3"},"name":""},{"pub_key":{"type":"secp256k1","data":"03F4AB6659E61E8512C9A24AC385CC1AC4D52B87D10ADBDF060086EA82BE62CDDE"},"name":""}],"app_hash":null}`
)
)
func
init
()
{
func
init
()
{
...
@@ -40,7 +40,7 @@ func TestGenesisDocFromJSON(t *testing.T) {
...
@@ -40,7 +40,7 @@ func TestGenesisDocFromJSON(t *testing.T) {
genDoc
,
err
:=
GenesisDocFromJSON
([]
byte
(
genesisFile
))
genDoc
,
err
:=
GenesisDocFromJSON
([]
byte
(
genesisFile
))
require
.
NotNil
(
t
,
genDoc
)
require
.
NotNil
(
t
,
genDoc
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
True
(
t
,
genDoc
.
ChainID
==
"chain33-Z2cgF
j
"
)
assert
.
True
(
t
,
genDoc
.
ChainID
==
"chain33-Z2cgF
X
"
)
assert
.
True
(
t
,
genDoc
.
AppHash
==
nil
)
assert
.
True
(
t
,
genDoc
.
AppHash
==
nil
)
assert
.
True
(
t
,
len
(
genDoc
.
Validators
)
==
3
)
assert
.
True
(
t
,
len
(
genDoc
.
Validators
)
==
3
)
...
@@ -53,7 +53,7 @@ func TestSaveAs(t *testing.T) {
...
@@ -53,7 +53,7 @@ func TestSaveAs(t *testing.T) {
genDoc
,
err
:=
GenesisDocFromJSON
([]
byte
(
genesisFile
))
genDoc
,
err
:=
GenesisDocFromJSON
([]
byte
(
genesisFile
))
require
.
NotNil
(
t
,
genDoc
)
require
.
NotNil
(
t
,
genDoc
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
assert
.
True
(
t
,
genDoc
.
ChainID
==
"chain33-Z2cgF
j
"
)
assert
.
True
(
t
,
genDoc
.
ChainID
==
"chain33-Z2cgF
X
"
)
assert
.
True
(
t
,
genDoc
.
AppHash
==
nil
)
assert
.
True
(
t
,
genDoc
.
AppHash
==
nil
)
assert
.
True
(
t
,
len
(
genDoc
.
Validators
)
==
3
)
assert
.
True
(
t
,
len
(
genDoc
.
Validators
)
==
3
)
...
...
plugin/consensus/dpos/types/priv_validator.go
View file @
8fd20a22
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"encoding/hex"
"encoding/hex"
"encoding/json"
"encoding/json"
"errors"
"errors"
"github.com/33cn/chain33/common/address"
"io/ioutil"
"io/ioutil"
"os"
"os"
"sync"
"sync"
...
@@ -136,7 +137,8 @@ func GenPrivValidatorImp(filePath string) *PrivValidatorImp {
...
@@ -136,7 +137,8 @@ func GenPrivValidatorImp(filePath string) *PrivValidatorImp {
panic
(
Fmt
(
"GenPrivValidatorImp: GenKey failed:%v"
,
err
))
panic
(
Fmt
(
"GenPrivValidatorImp: GenKey failed:%v"
,
err
))
}
}
return
&
PrivValidatorImp
{
return
&
PrivValidatorImp
{
Address
:
GenAddressByPubKey
(
privKey
.
PubKey
()),
//Address: GenAddressByPubKey(privKey.PubKey()),
Address
:
address
.
PubKeyToAddress
(
privKey
.
PubKey
()
.
Bytes
())
.
Hash160
[
:
],
PubKey
:
privKey
.
PubKey
(),
PubKey
:
privKey
.
PubKey
(),
PrivKey
:
privKey
,
PrivKey
:
privKey
,
Signer
:
NewDefaultSigner
(
privKey
),
Signer
:
NewDefaultSigner
(
privKey
),
...
...
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