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
9bceceab
Commit
9bceceab
authored
Oct 18, 2019
by
caopingcp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code cleanup
parent
88a82e81
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
38 additions
and
42 deletions
+38
-42
consensus_state.go
plugin/consensus/tendermint/consensus_state.go
+1
-6
node.go
plugin/consensus/tendermint/node.go
+0
-6
peer_set.go
plugin/consensus/tendermint/peer_set.go
+0
-9
secret_connection.go
plugin/consensus/tendermint/secret_connection.go
+1
-5
tendermint.go
plugin/consensus/tendermint/tendermint.go
+19
-7
tendermint_test.go
plugin/consensus/tendermint/tendermint_test.go
+15
-3
block.go
plugin/consensus/tendermint/types/block.go
+0
-2
height_vote_set.go
plugin/consensus/tendermint/types/height_vote_set.go
+2
-3
signable.go
plugin/consensus/tendermint/types/signable.go
+0
-1
No files found.
plugin/consensus/tendermint/consensus_state.go
View file @
9bceceab
...
@@ -137,11 +137,6 @@ func (cs *ConsensusState) IsRunning() bool {
...
@@ -137,11 +137,6 @@ func (cs *ConsensusState) IsRunning() bool {
}
}
//----------------------------------------
//----------------------------------------
// String returns a string.
func
(
cs
*
ConsensusState
)
String
()
string
{
// better not to access shared variables
return
fmt
.
Sprintf
(
"ConsensusState"
)
//(H:%v R:%v S:%v", cs.Height, cs.Round, cs.Step)
}
// GetState returns a copy of the chain state.
// GetState returns a copy of the chain state.
func
(
cs
*
ConsensusState
)
GetState
()
State
{
func
(
cs
*
ConsensusState
)
GetState
()
State
{
...
@@ -443,7 +438,7 @@ func (cs *ConsensusState) handleMsg(mi MsgInfo) {
...
@@ -443,7 +438,7 @@ func (cs *ConsensusState) handleMsg(mi MsgInfo) {
}
}
func
(
cs
*
ConsensusState
)
handleTimeout
(
ti
timeoutInfo
,
rs
ttypes
.
RoundState
)
{
func
(
cs
*
ConsensusState
)
handleTimeout
(
ti
timeoutInfo
,
rs
ttypes
.
RoundState
)
{
tendermintlog
.
Debug
(
"Received tock"
,
"timeout"
,
ti
.
Duration
,
"height"
,
ti
.
Height
,
"round"
,
ti
.
Round
,
"step"
,
ti
.
Step
)
tendermintlog
.
Debug
(
"Received tock"
,
"timeout"
,
ti
.
String
()
)
// timeouts must be for current height, round, step
// timeouts must be for current height, round, step
if
ti
.
Height
!=
rs
.
Height
||
ti
.
Round
<
rs
.
Round
||
(
ti
.
Round
==
rs
.
Round
&&
ti
.
Step
<
rs
.
Step
)
{
if
ti
.
Height
!=
rs
.
Height
||
ti
.
Round
<
rs
.
Round
||
(
ti
.
Round
==
rs
.
Round
&&
ti
.
Step
<
rs
.
Step
)
{
...
...
plugin/consensus/tendermint/node.go
View file @
9bceceab
...
@@ -414,11 +414,6 @@ func (node *Node) addPeer(pc *peerConn) error {
...
@@ -414,11 +414,6 @@ func (node *Node) addPeer(pc *peerConn) error {
return
fmt
.
Errorf
(
"get remote ip failed:%v"
,
rErr
)
return
fmt
.
Errorf
(
"get remote ip failed:%v"
,
rErr
)
}
}
// Filter peer against ID white list
//if err := node.FilterConnByID(peerID); err != nil {
//return err
//}
// Check version, chain id
// Check version, chain id
if
err
:=
node
.
CompatibleWith
(
peerNodeInfo
);
err
!=
nil
{
if
err
:=
node
.
CompatibleWith
(
peerNodeInfo
);
err
!=
nil
{
return
err
return
err
...
@@ -440,7 +435,6 @@ func (node *Node) addPeer(pc *peerConn) error {
...
@@ -440,7 +435,6 @@ func (node *Node) addPeer(pc *peerConn) error {
if
err
:=
node
.
peerSet
.
Add
(
pc
);
err
!=
nil
{
if
err
:=
node
.
peerSet
.
Add
(
pc
);
err
!=
nil
{
return
err
return
err
}
}
//node.metrics.Peers.Add(float64(1))
tendermintlog
.
Info
(
"Added peer"
,
"peer"
,
pc
.
ip
)
tendermintlog
.
Info
(
"Added peer"
,
"peer"
,
pc
.
ip
)
return
nil
return
nil
...
...
plugin/consensus/tendermint/peer_set.go
View file @
9bceceab
...
@@ -698,12 +698,6 @@ OUTER_LOOP:
...
@@ -698,12 +698,6 @@ OUTER_LOOP:
// If the peer is on a previous height, help catch up.
// If the peer is on a previous height, help catch up.
if
(
0
<
prs
.
Height
)
&&
(
prs
.
Height
<
rs
.
Height
)
{
if
(
0
<
prs
.
Height
)
&&
(
prs
.
Height
<
rs
.
Height
)
{
//if prs.Height+1 == rs.Height && prs.Round == rs.LastCommit.Round() && prs.Step == ttypes.RoundStepCommit && prs.ProposalBlock {
// tendermintlog.Debug("Peer is waiting for finalizeCommit finish", "peerip", pc.ip.String(),
// "state", fmt.Sprintf("%v/%v/%v", prs.Height, prs.Round, prs.Step))
// time.Sleep(10 * pc.myState.PeerGossipSleep())
// continue OUTER_LOOP
//}
if
prs
.
ProposalBlockHash
==
nil
||
prs
.
ProposalBlock
{
if
prs
.
ProposalBlockHash
==
nil
||
prs
.
ProposalBlock
{
time
.
Sleep
(
pc
.
myState
.
PeerGossipSleep
())
time
.
Sleep
(
pc
.
myState
.
PeerGossipSleep
())
continue
OUTER_LOOP
continue
OUTER_LOOP
...
@@ -803,9 +797,6 @@ OUTER_LOOP:
...
@@ -803,9 +797,6 @@ OUTER_LOOP:
rs
:=
pc
.
myState
.
GetRoundState
()
rs
:=
pc
.
myState
.
GetRoundState
()
prs
:=
pc
.
state
prs
:=
pc
.
state
//tendermintlog.Debug("gossipVotesRoutine", "rs(H/R/S)", fmt.Sprintf("%v/%v/%v", rs.Height, rs.Round, rs.Step.String()),
// "prs(H/R/S)", fmt.Sprintf("%v/%v/%v", prs.Height, prs.Round, prs.Step.String()),
// "precommits", rs.Votes.Precommits(prs.Round).BitArray().String(), "peerip", pc.ip.String())
switch
sleeping
{
switch
sleeping
{
case
1
:
// First sleep
case
1
:
// First sleep
...
...
plugin/consensus/tendermint/secret_connection.go
View file @
9bceceab
...
@@ -133,7 +133,6 @@ func (sc *SecretConnection) Write(data []byte) (n int, err error) {
...
@@ -133,7 +133,6 @@ func (sc *SecretConnection) Write(data []byte) (n int, err error) {
// encrypt the frame
// encrypt the frame
var
sealedFrame
=
make
([]
byte
,
sealedFrameSize
)
var
sealedFrame
=
make
([]
byte
,
sealedFrameSize
)
secretbox
.
Seal
(
sealedFrame
[
:
0
],
frame
,
sc
.
sendNonce
,
sc
.
shrSecret
)
secretbox
.
Seal
(
sealedFrame
[
:
0
],
frame
,
sc
.
sendNonce
,
sc
.
shrSecret
)
// fmt.Printf("secretbox.Seal(sealed:%X,sendNonce:%X,shrSecret:%X\n", sealedFrame, sc.sendNonce, sc.shrSecret)
incr2Nonce
(
sc
.
sendNonce
)
incr2Nonce
(
sc
.
sendNonce
)
// end encryption
// end encryption
...
@@ -162,7 +161,6 @@ func (sc *SecretConnection) Read(data []byte) (n int, err error) {
...
@@ -162,7 +161,6 @@ func (sc *SecretConnection) Read(data []byte) (n int, err error) {
// decrypt the frame
// decrypt the frame
var
frame
=
make
([]
byte
,
totalFrameSize
)
var
frame
=
make
([]
byte
,
totalFrameSize
)
// fmt.Printf("secretbox.Open(sealed:%X,recvNonce:%X,shrSecret:%X\n", sealedFrame, sc.recvNonce, sc.shrSecret)
_
,
ok
:=
secretbox
.
Open
(
frame
[
:
0
],
sealedFrame
,
sc
.
recvNonce
,
sc
.
shrSecret
)
_
,
ok
:=
secretbox
.
Open
(
frame
[
:
0
],
sealedFrame
,
sc
.
recvNonce
,
sc
.
shrSecret
)
if
!
ok
{
if
!
ok
{
return
n
,
errors
.
New
(
"Failed to decrypt SecretConnection"
)
return
n
,
errors
.
New
(
"Failed to decrypt SecretConnection"
)
...
@@ -298,9 +296,7 @@ func shareAuthSignature(sc io.ReadWriter, pubKey crypto.PubKey, signature crypto
...
@@ -298,9 +296,7 @@ func shareAuthSignature(sc io.ReadWriter, pubKey crypto.PubKey, signature crypto
if
err2
!=
nil
{
if
err2
!=
nil
{
return
return
}
}
//n := int(0) // not used.
//recvMsg = wire.ReadBinary(authSigMessage{}, bytes.NewBuffer(readBuffer), authSigMsgSize, &n, &err2).(authSigMessage)
//secret.Info("shareAuthSignature", "readBuffer", readBuffer)
recvMsg
.
Key
,
err2
=
types
.
ConsensusCrypto
.
PubKeyFromBytes
(
readBuffer
[
:
32
])
recvMsg
.
Key
,
err2
=
types
.
ConsensusCrypto
.
PubKeyFromBytes
(
readBuffer
[
:
32
])
if
err2
!=
nil
{
if
err2
!=
nil
{
return
return
...
...
plugin/consensus/tendermint/tendermint.go
View file @
9bceceab
...
@@ -407,17 +407,30 @@ func (client *Client) CreateBlock() {
...
@@ -407,17 +407,30 @@ func (client *Client) CreateBlock() {
if
issleep
{
if
issleep
{
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
}
}
if
!
client
.
CheckTxsAvailable
()
{
height
,
err
:=
client
.
getLastHeight
()
if
err
!=
nil
{
issleep
=
true
continue
}
if
!
client
.
CheckTxsAvailable
(
height
)
{
issleep
=
true
issleep
=
true
continue
continue
}
}
issleep
=
false
issleep
=
false
client
.
txsAvailable
<-
client
.
GetCurrentHeight
()
+
1
client
.
txsAvailable
<-
height
+
1
time
.
Sleep
(
time
.
Duration
(
timeoutTxAvail
)
*
time
.
Millisecond
)
time
.
Sleep
(
time
.
Duration
(
timeoutTxAvail
)
*
time
.
Millisecond
)
}
}
}
}
func
(
client
*
Client
)
getLastHeight
()
(
int64
,
error
)
{
lastBlock
,
err
:=
client
.
RequestLastBlock
()
if
err
!=
nil
{
return
-
1
,
err
}
return
lastBlock
.
Height
,
nil
}
// TxsAvailable check available channel
// TxsAvailable check available channel
func
(
client
*
Client
)
TxsAvailable
()
<-
chan
int64
{
func
(
client
*
Client
)
TxsAvailable
()
<-
chan
int64
{
return
client
.
txsAvailable
return
client
.
txsAvailable
...
@@ -429,9 +442,9 @@ func (client *Client) StopC() <-chan struct{} {
...
@@ -429,9 +442,9 @@ func (client *Client) StopC() <-chan struct{} {
}
}
// CheckTxsAvailable check whether some new transactions arriving
// CheckTxsAvailable check whether some new transactions arriving
func
(
client
*
Client
)
CheckTxsAvailable
()
bool
{
func
(
client
*
Client
)
CheckTxsAvailable
(
height
int64
)
bool
{
txs
:=
client
.
RequestTx
(
10
,
nil
)
txs
:=
client
.
RequestTx
(
10
,
nil
)
txs
=
client
.
CheckTxDup
(
txs
,
client
.
GetCurrentHeight
()
)
txs
=
client
.
CheckTxDup
(
txs
,
height
)
return
len
(
txs
)
!=
0
return
len
(
txs
)
!=
0
}
}
...
@@ -495,10 +508,9 @@ func (client *Client) CommitBlock(block *types.Block) error {
...
@@ -495,10 +508,9 @@ func (client *Client) CommitBlock(block *types.Block) error {
// WaitBlock by height
// WaitBlock by height
func
(
client
*
Client
)
WaitBlock
(
height
int64
)
bool
{
func
(
client
*
Client
)
WaitBlock
(
height
int64
)
bool
{
retry
:=
0
retry
:=
0
var
newHeight
int64
for
{
for
{
newHeight
=
client
.
GetCurren
tHeight
()
newHeight
,
err
:=
client
.
getLas
tHeight
()
if
newHeight
>=
height
{
if
err
==
nil
&&
newHeight
>=
height
{
return
true
return
true
}
}
retry
++
retry
++
...
...
plugin/consensus/tendermint/tendermint_test.go
View file @
9bceceab
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"errors"
"errors"
"flag"
"flag"
"fmt"
"fmt"
"github.com/stretchr/testify/assert"
"math/rand"
"math/rand"
"os"
"os"
"testing"
"testing"
...
@@ -52,12 +53,12 @@ func init() {
...
@@ -52,12 +53,12 @@ func init() {
log
.
SetLogLevel
(
"info"
)
log
.
SetLogLevel
(
"info"
)
}
}
func
TestTendermintPerf
(
t
*
testing
.
T
)
{
func
TestTendermintPerf
(
t
*
testing
.
T
)
{
TendermintPerf
()
TendermintPerf
(
t
)
fmt
.
Println
(
"=======start clear test data!======="
)
fmt
.
Println
(
"=======start clear test data!======="
)
clearTestData
()
clearTestData
()
}
}
func
TendermintPerf
()
{
func
TendermintPerf
(
t
*
testing
.
T
)
{
q
,
chain
,
s
,
mem
,
exec
,
cs
,
p2p
:=
initEnvTendermint
()
q
,
chain
,
s
,
mem
,
exec
,
cs
,
p2p
:=
initEnvTendermint
()
defer
chain
.
Close
()
defer
chain
.
Close
()
defer
mem
.
Close
()
defer
mem
.
Close
()
...
@@ -75,6 +76,7 @@ func TendermintPerf() {
...
@@ -75,6 +76,7 @@ func TendermintPerf() {
NormPut
()
NormPut
()
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
}
}
CheckState
(
t
,
cs
.
(
*
Client
))
AddNode
()
AddNode
()
for
i
:=
0
;
i
<
loopCount
*
3
;
i
++
{
for
i
:=
0
;
i
<
loopCount
*
3
;
i
++
{
NormPut
()
NormPut
()
...
@@ -196,7 +198,7 @@ func AddNode() {
...
@@ -196,7 +198,7 @@ func AddNode() {
action
:=
&
ty
.
ValNodeAction
{
Value
:
nput
,
Ty
:
ty
.
ValNodeActionUpdate
}
action
:=
&
ty
.
ValNodeAction
{
Value
:
nput
,
Ty
:
ty
.
ValNodeActionUpdate
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"valnode"
),
Payload
:
types
.
Encode
(
action
),
Fee
:
fee
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"valnode"
),
Payload
:
types
.
Encode
(
action
),
Fee
:
fee
}
tx
.
To
=
address
.
ExecAddress
(
"valnode"
)
tx
.
To
=
address
.
ExecAddress
(
"valnode"
)
tx
.
Nonce
=
r
.
Int63
()
tx
.
Nonce
=
r
andom
.
Int63
()
tx
.
Sign
(
types
.
SECP256K1
,
getprivkey
(
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
))
tx
.
Sign
(
types
.
SECP256K1
,
getprivkey
(
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
))
reply
,
err
:=
c
.
SendTransaction
(
context
.
Background
(),
tx
)
reply
,
err
:=
c
.
SendTransaction
(
context
.
Background
(),
tx
)
...
@@ -209,3 +211,13 @@ func AddNode() {
...
@@ -209,3 +211,13 @@ func AddNode() {
return
return
}
}
}
}
func
CheckState
(
t
*
testing
.
T
,
client
*
Client
)
{
msg1
,
err
:=
client
.
Query_IsHealthy
(
&
types
.
ReqNil
{})
assert
.
Nil
(
t
,
err
)
flag
:=
msg1
.
(
*
ty
.
IsHealthy
)
.
IsHealthy
assert
.
Equal
(
t
,
true
,
flag
)
_
,
err
=
client
.
Query_NodeInfo
(
&
types
.
ReqNil
{})
assert
.
Nil
(
t
,
err
)
}
plugin/consensus/tendermint/types/block.go
View file @
9bceceab
...
@@ -163,10 +163,8 @@ func (b *TendermintBlock) StringIndented(indent string) string {
...
@@ -163,10 +163,8 @@ func (b *TendermintBlock) StringIndented(indent string) string {
return
Fmt
(
`Block{
return
Fmt
(
`Block{
%s %v
%s %v
%s %v
%s %v
%s %v
%s}#%v`
,
%s}#%v`
,
indent
,
header
.
StringIndented
(
indent
+
" "
),
indent
,
header
.
StringIndented
(
indent
+
" "
),
// indent, b.Evidence.StringIndented(indent+" "),
indent
,
lastCommit
.
StringIndented
(
indent
+
" "
),
indent
,
lastCommit
.
StringIndented
(
indent
+
" "
),
indent
,
b
.
Hash
())
indent
,
b
.
Hash
())
}
}
...
...
plugin/consensus/tendermint/types/height_vote_set.go
View file @
9bceceab
...
@@ -100,9 +100,8 @@ func (hvs *HeightVoteSet) SetRound(round int) {
...
@@ -100,9 +100,8 @@ func (hvs *HeightVoteSet) SetRound(round int) {
func
(
hvs
*
HeightVoteSet
)
addRound
(
round
int
)
{
func
(
hvs
*
HeightVoteSet
)
addRound
(
round
int
)
{
if
_
,
ok
:=
hvs
.
roundVoteSets
[
round
];
ok
{
if
_
,
ok
:=
hvs
.
roundVoteSets
[
round
];
ok
{
panic
(
Fmt
(
"Panicked on a Sanity Check: %v"
,
"addRound() for an existing round"
)
)
panic
(
"addRound() for an existing round"
)
}
}
// log.Debug("addRound(round)", "round", round)
prevotes
:=
NewVoteSet
(
hvs
.
chainID
,
hvs
.
height
,
round
,
VoteTypePrevote
,
hvs
.
valSet
)
prevotes
:=
NewVoteSet
(
hvs
.
chainID
,
hvs
.
height
,
round
,
VoteTypePrevote
,
hvs
.
valSet
)
precommits
:=
NewVoteSet
(
hvs
.
chainID
,
hvs
.
height
,
round
,
VoteTypePrecommit
,
hvs
.
valSet
)
precommits
:=
NewVoteSet
(
hvs
.
chainID
,
hvs
.
height
,
round
,
VoteTypePrecommit
,
hvs
.
valSet
)
hvs
.
roundVoteSets
[
round
]
=
RoundVoteSet
{
hvs
.
roundVoteSets
[
round
]
=
RoundVoteSet
{
...
@@ -179,7 +178,7 @@ func (hvs *HeightVoteSet) getVoteSet(round int, voteType byte) *VoteSet {
...
@@ -179,7 +178,7 @@ func (hvs *HeightVoteSet) getVoteSet(round int, voteType byte) *VoteSet {
case
VoteTypePrecommit
:
case
VoteTypePrecommit
:
return
rvs
.
Precommits
return
rvs
.
Precommits
default
:
default
:
panic
(
Fmt
(
"
Panicked on a Sanity Check: %v"
,
Fmt
(
"Unexpected vote type %X"
,
voteType
)
))
panic
(
Fmt
(
"
Unexpected vote type %X"
,
voteType
))
}
}
}
}
...
...
plugin/consensus/tendermint/types/signable.go
View file @
9bceceab
...
@@ -213,7 +213,6 @@ func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error {
...
@@ -213,7 +213,6 @@ func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error {
// Hash ...
// Hash ...
func
(
vote
*
Vote
)
Hash
()
[]
byte
{
func
(
vote
*
Vote
)
Hash
()
[]
byte
{
if
vote
==
nil
{
if
vote
==
nil
{
//votelog.Error("vote hash is nil")
return
nil
return
nil
}
}
bytes
,
err
:=
json
.
Marshal
(
vote
)
bytes
,
err
:=
json
.
Marshal
(
vote
)
...
...
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