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
f7fdf9e0
Commit
f7fdf9e0
authored
Sep 18, 2019
by
张振华
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dpos-v2' of
https://github.com/zzh33cn/plugin
into dpos-v2
parents
5b4e5c30
93752812
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
38 deletions
+34
-38
dpos.go
plugin/consensus/dpos/dpos.go
+3
-4
node.go
plugin/consensus/dpos/node.go
+1
-1
node_test.go
plugin/consensus/dpos/node_test.go
+27
-31
priv_validator.go
plugin/consensus/dpos/types/priv_validator.go
+3
-2
No files found.
plugin/consensus/dpos/dpos.go
View file @
f7fdf9e0
...
@@ -368,7 +368,7 @@ OuterLoop:
...
@@ -368,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
...
@@ -772,6 +772,6 @@ func (client *Client) SetTestFlag() {
...
@@ -772,6 +772,6 @@ func (client *Client) SetTestFlag() {
}
}
// GetNode return the pointer to Node
// GetNode return the pointer to Node
func
(
client
*
Client
)
GetNode
()
*
Node
{
func
(
client
*
Client
)
GetNode
()
*
Node
{
return
client
.
node
return
client
.
node
}
}
\ No newline at end of file
plugin/consensus/dpos/node.go
View file @
f7fdf9e0
...
@@ -197,7 +197,7 @@ func (node *Node) Start(testFlag bool) {
...
@@ -197,7 +197,7 @@ func (node *Node) Start(testFlag bool) {
addr
:=
node
.
seeds
[
i
]
addr
:=
node
.
seeds
[
i
]
ip
,
_
:=
splitHostPort
(
addr
)
ip
,
_
:=
splitHostPort
(
addr
)
_
,
ok
:=
node
.
localIPs
[
ip
]
_
,
ok
:=
node
.
localIPs
[
ip
]
if
ok
&&
!
testFlag
{
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
View file @
f7fdf9e0
...
@@ -5,6 +5,12 @@ import (
...
@@ -5,6 +5,12 @@ import (
"encoding/json"
"encoding/json"
"flag"
"flag"
"fmt"
"fmt"
"io/ioutil"
"os"
"sync"
"testing"
"time"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/executor"
"github.com/33cn/chain33/executor"
"github.com/33cn/chain33/p2p"
"github.com/33cn/chain33/p2p"
...
@@ -13,11 +19,6 @@ import (
...
@@ -13,11 +19,6 @@ import (
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"sync"
"testing"
"time"
"github.com/33cn/chain33/blockchain"
"github.com/33cn/chain33/blockchain"
"github.com/33cn/chain33/mempool"
"github.com/33cn/chain33/mempool"
...
@@ -28,11 +29,11 @@ import (
...
@@ -28,11 +29,11 @@ import (
var
(
var
(
secureConnCrypto
crypto
.
Crypto
secureConnCrypto
crypto
.
Crypto
securePriv
crypto
.
PrivKey
securePriv
crypto
.
PrivKey
sum
=
0
sum
=
0
mutx
sync
.
Mutex
mutx
sync
.
Mutex
privKey
=
"B3DC4C0725884EBB7264B92F1D8D37584A64ADE1799D997EC64B4FE3973E08DE220ACBE680DF2473A0CB48987A00FCC1812F106A7390BE6B8E2D31122C992A19"
privKey
=
"B3DC4C0725884EBB7264B92F1D8D37584A64ADE1799D997EC64B4FE3973E08DE220ACBE680DF2473A0CB48987A00FCC1812F106A7390BE6B8E2D31122C992A19"
expectAddress
=
"02A13174B92727C4902DB099E51A3339F48BD45E"
expectAddress
=
"02A13174B92727C4902DB099E51A3339F48BD45E"
//localGenesis = `{"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}`
//localGenesis = `{"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}`
...
@@ -190,7 +191,7 @@ cryptoPath="authdir/crypto"
...
@@ -190,7 +191,7 @@ cryptoPath="authdir/crypto"
# 带证书签名类型,支持"auth_ecdsa", "auth_sm2"
# 带证书签名类型,支持"auth_ecdsa", "auth_sm2"
signType="auth_ecdsa"
signType="auth_ecdsa"
`
`
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
config2
=
`Title="local"
config2
=
`Title="local"
[log]
[log]
...
@@ -365,6 +366,7 @@ cryptoPath="authdir/crypto"
...
@@ -365,6 +366,7 @@ cryptoPath="authdir/crypto"
signType="auth_ecdsa"
signType="auth_ecdsa"
`
`
)
)
func
init
()
{
func
init
()
{
cr2
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
ED25519
))
cr2
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
ED25519
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -398,23 +400,22 @@ func Init() {
...
@@ -398,23 +400,22 @@ func Init() {
ioutil
.
WriteFile
(
"chain33.test2.toml"
,
[]
byte
(
config2
),
0664
)
ioutil
.
WriteFile
(
"chain33.test2.toml"
,
[]
byte
(
config2
),
0664
)
}
}
func
TestParallel
(
t
*
testing
.
T
)
{
func
TestParallel
(
t
*
testing
.
T
)
{
Parallel
(
func
()
{
Parallel
(
func
()
{
mutx
.
Lock
()
mutx
.
Lock
()
sum
+=
1
sum
+=
1
mutx
.
Unlock
()
mutx
.
Unlock
()
},
},
func
()
{
func
()
{
mutx
.
Lock
()
mutx
.
Lock
()
sum
+=
2
sum
+=
2
mutx
.
Unlock
()
mutx
.
Unlock
()
},
},
func
()
{
func
()
{
mutx
.
Lock
()
mutx
.
Lock
()
sum
+=
3
sum
+=
3
mutx
.
Unlock
()
mutx
.
Unlock
()
},
},
)
)
fmt
.
Println
(
"TestParallel ok"
)
fmt
.
Println
(
"TestParallel ok"
)
...
@@ -454,7 +455,7 @@ func TestNode(t *testing.T) {
...
@@ -454,7 +455,7 @@ func TestNode(t *testing.T) {
fmt
.
Println
(
"=======start TestNode!======="
)
fmt
.
Println
(
"=======start TestNode!======="
)
Init
()
Init
()
q1
,
chain1
,
s1
,
mem1
,
exec1
,
cs1
,
p2p1
:=
initEnvDpos1
(
"chain33.test1.toml"
)
q1
,
chain1
,
s1
,
mem1
,
exec1
,
cs1
,
p2p1
:=
initEnvDpos1
(
"chain33.test1.toml"
)
q2
,
chain2
,
s2
,
mem2
,
exec2
,
cs2
,
p2p2
:=
initEnvDpos2
(
"chain33.test2.toml"
)
q2
,
chain2
,
s2
,
mem2
,
exec2
,
cs2
,
p2p2
:=
initEnvDpos2
(
"chain33.test2.toml"
)
defer
clearTestData1
()
defer
clearTestData1
()
defer
chain1
.
Close
()
defer
chain1
.
Close
()
...
@@ -491,8 +492,8 @@ func TestNode(t *testing.T) {
...
@@ -491,8 +492,8 @@ func TestNode(t *testing.T) {
fmt
.
Println
(
"node1 version:"
,
cs1
.
(
*
Client
)
.
GetNode
()
.
Version
)
fmt
.
Println
(
"node1 version:"
,
cs1
.
(
*
Client
)
.
GetNode
()
.
Version
)
nodeinfo
:=
NodeInfo
{
nodeinfo
:=
NodeInfo
{
ID
:
cs1
.
(
*
Client
)
.
GetNode
()
.
ID
,
ID
:
cs1
.
(
*
Client
)
.
GetNode
()
.
ID
,
IP
:
cs1
.
(
*
Client
)
.
GetNode
()
.
IP
,
IP
:
cs1
.
(
*
Client
)
.
GetNode
()
.
IP
,
Network
:
cs1
.
(
*
Client
)
.
GetNode
()
.
Network
,
Network
:
cs1
.
(
*
Client
)
.
GetNode
()
.
Network
,
Version
:
cs1
.
(
*
Client
)
.
GetNode
()
.
Version
,
Version
:
cs1
.
(
*
Client
)
.
GetNode
()
.
Version
,
}
}
...
@@ -500,7 +501,6 @@ func TestNode(t *testing.T) {
...
@@ -500,7 +501,6 @@ func TestNode(t *testing.T) {
require
.
Nil
(
t
,
cs1
.
(
*
Client
)
.
GetNode
()
.
CompatibleWith
(
nodeinfo
))
require
.
Nil
(
t
,
cs1
.
(
*
Client
)
.
GetNode
()
.
CompatibleWith
(
nodeinfo
))
fmt
.
Println
(
"TestNodeCompatibleWith ok"
)
fmt
.
Println
(
"TestNodeCompatibleWith ok"
)
//time.Sleep(2 * time.Second)
//time.Sleep(2 * time.Second)
fmt
.
Println
(
q1
.
Name
())
fmt
.
Println
(
q1
.
Name
())
...
@@ -532,7 +532,6 @@ func TestNode(t *testing.T) {
...
@@ -532,7 +532,6 @@ func TestNode(t *testing.T) {
fmt
.
Println
(
"======= cs1 is not running======="
)
fmt
.
Println
(
"======= cs1 is not running======="
)
}
}
//cs2.(*Client).StopC()
//cs2.(*Client).StopC()
if
cs2
.
(
*
Client
)
.
GetNode
()
.
IsRunning
()
{
if
cs2
.
(
*
Client
)
.
GetNode
()
.
IsRunning
()
{
fmt
.
Println
(
"=======cs2 is running======="
)
fmt
.
Println
(
"=======cs2 is running======="
)
...
@@ -568,7 +567,6 @@ func clearTestData1() {
...
@@ -568,7 +567,6 @@ func clearTestData1() {
fmt
.
Println
(
"test data clear successfully!"
)
fmt
.
Println
(
"test data clear successfully!"
)
}
}
func
initEnvDpos1
(
configName
string
)
(
queue
.
Queue
,
*
blockchain
.
BlockChain
,
queue
.
Module
,
queue
.
Module
,
*
executor
.
Executor
,
queue
.
Module
,
queue
.
Module
)
{
func
initEnvDpos1
(
configName
string
)
(
queue
.
Queue
,
*
blockchain
.
BlockChain
,
queue
.
Module
,
queue
.
Module
,
*
executor
.
Executor
,
queue
.
Module
,
queue
.
Module
)
{
var
q
=
queue
.
New
(
"channel"
)
var
q
=
queue
.
New
(
"channel"
)
flag
.
Parse
()
flag
.
Parse
()
...
@@ -625,7 +623,6 @@ func initEnvDpos2(configName string) (queue.Queue, *blockchain.BlockChain, queue
...
@@ -625,7 +623,6 @@ func initEnvDpos2(configName string) (queue.Queue, *blockchain.BlockChain, queue
cs
.
(
*
Client
)
.
SetTestFlag
()
cs
.
(
*
Client
)
.
SetTestFlag
()
cs
.
SetQueueClient
(
q
.
Client
())
cs
.
SetQueueClient
(
q
.
Client
())
mem
:=
mempool
.
New
(
cfg
.
Mempool
,
nil
)
mem
:=
mempool
.
New
(
cfg
.
Mempool
,
nil
)
mem
.
SetQueueClient
(
q
.
Client
())
mem
.
SetQueueClient
(
q
.
Client
())
network
:=
p2p
.
New
(
cfg
.
P2P
)
network
:=
p2p
.
New
(
cfg
.
P2P
)
...
@@ -638,4 +635,3 @@ func initEnvDpos2(configName string) (queue.Queue, *blockchain.BlockChain, queue
...
@@ -638,4 +635,3 @@ func initEnvDpos2(configName string) (queue.Queue, *blockchain.BlockChain, queue
return
q
,
chain
,
s
,
mem
,
exec
,
cs
,
network
return
q
,
chain
,
s
,
mem
,
exec
,
cs
,
network
}
}
plugin/consensus/dpos/types/priv_validator.go
View file @
f7fdf9e0
...
@@ -10,11 +10,12 @@ import (
...
@@ -10,11 +10,12 @@ 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"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto"
vrf
"github.com/33cn/chain33/common/vrf/secp256k1"
vrf
"github.com/33cn/chain33/common/vrf/secp256k1"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
...
@@ -138,7 +139,7 @@ func GenPrivValidatorImp(filePath string) *PrivValidatorImp {
...
@@ -138,7 +139,7 @@ func GenPrivValidatorImp(filePath string) *PrivValidatorImp {
}
}
return
&
PrivValidatorImp
{
return
&
PrivValidatorImp
{
//Address: GenAddressByPubKey(privKey.PubKey()),
//Address: GenAddressByPubKey(privKey.PubKey()),
Address
:
address
.
PubKeyToAddress
(
privKey
.
PubKey
()
.
Bytes
())
.
Hash160
[
:
],
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