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
Registry
Registry
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
1bdb1f42
Commit
1bdb1f42
authored
Jul 27, 2019
by
mdj33
Committed by
vipwzw
Aug 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ut
parent
c169bc80
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
49 deletions
+71
-49
para.go
plugin/consensus/para/para.go
+2
-5
para_test.go
plugin/consensus/para/para_test.go
+15
-11
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+8
-6
paracreate.go
plugin/consensus/para/paracreate.go
+5
-1
paratxrequest_test.go
plugin/consensus/para/paratxrequest_test.go
+41
-26
No files found.
plugin/consensus/para/para.go
View file @
1bdb1f42
...
@@ -162,11 +162,8 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
...
@@ -162,11 +162,8 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
quitCreate
:
make
(
chan
struct
{}),
quitCreate
:
make
(
chan
struct
{}),
}
}
waitBlocks
:=
int32
(
3
)
//
最小是2
waitBlocks
:=
int32
(
3
)
//
缺省是3
if
subcfg
.
WaitBlocks4CommitMsg
>
0
{
if
subcfg
.
WaitBlocks4CommitMsg
>
0
{
if
subcfg
.
WaitBlocks4CommitMsg
<
waitBlocks
{
panic
(
"config WaitBlocks4CommitMsg should not less 2"
)
}
waitBlocks
=
subcfg
.
WaitBlocks4CommitMsg
waitBlocks
=
subcfg
.
WaitBlocks4CommitMsg
}
}
...
@@ -181,7 +178,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
...
@@ -181,7 +178,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
waitConsensStopTimes
:
waitConsensTimes
,
waitConsensStopTimes
:
waitConsensTimes
,
commitCh
:
make
(
chan
int64
,
1
),
commitCh
:
make
(
chan
int64
,
1
),
resetCh
:
make
(
chan
int64
,
1
),
resetCh
:
make
(
chan
int64
,
1
),
verifyCh
:
make
(
chan
bool
,
1
),
verifyCh
:
make
(
chan
[]
byte
,
1
),
consensHeight
:
-
2
,
consensHeight
:
-
2
,
sendingHeight
:
-
1
,
sendingHeight
:
-
1
,
quit
:
make
(
chan
struct
{}),
quit
:
make
(
chan
struct
{}),
...
...
plugin/consensus/para/para_test.go
View file @
1bdb1f42
...
@@ -212,27 +212,31 @@ func initBlock() {
...
@@ -212,27 +212,31 @@ func initBlock() {
println
(
"initblock"
)
println
(
"initblock"
)
}
}
func
TestGetLastBlockInfo
(
t
*
testing
.
T
)
{
func
getMockLastBlock
(
para
*
client
,
returnBlock
*
types
.
Block
)
{
para
:=
new
(
client
)
baseCli
:=
drivers
.
NewBaseClient
(
&
types
.
Consensus
{
Name
:
"name"
})
baseCli
:=
drivers
.
NewBaseClient
(
&
types
.
Consensus
{
Name
:
"name"
})
para
.
BaseClient
=
baseCli
para
.
BaseClient
=
baseCli
grpcClient
:=
&
typesmocks
.
Chain33Client
{}
qClient
:=
&
qmocks
.
Client
{}
qClient
:=
&
qmocks
.
Client
{}
para
.
InitClient
(
qClient
,
initBlock
)
para
.
InitClient
(
qClient
,
initBlock
)
api
:=
&
apimocks
.
QueueProtocolAPI
{}
msg
:=
queue
.
NewMessage
(
0
,
""
,
1
,
returnBlock
)
para
.
SetAPI
(
api
)
qClient
.
On
(
"NewMessage"
,
"blockchain"
,
int64
(
types
.
EventGetLastBlock
),
mock
.
Anything
)
.
Return
(
msg
)
qClient
.
On
(
"Send"
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
nil
)
qClient
.
On
(
"Wait"
,
mock
.
Anything
)
.
Return
(
msg
,
nil
)
}
func
TestGetLastBlockInfo
(
t
*
testing
.
T
)
{
para
:=
new
(
client
)
grpcClient
:=
&
typesmocks
.
Chain33Client
{}
para
.
grpcClient
=
grpcClient
para
.
grpcClient
=
grpcClient
block
:=
&
types
.
Block
{
Height
:
0
}
block
:=
&
types
.
Block
{
Height
:
0
}
msg
:=
queue
.
NewMessage
(
0
,
""
,
1
,
block
)
getMockLastBlock
(
para
,
block
)
qClient
.
On
(
"NewMessage"
,
mock
.
Anything
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
msg
)
api
:=
&
apimocks
.
QueueProtocolAPI
{}
qClient
.
On
(
"Send"
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
nil
)
para
.
SetAPI
(
api
)
qClient
.
On
(
"Wait"
,
mock
.
Anything
)
.
Return
(
msg
,
nil
)
grpcClient
.
On
(
"GetSequenceByHash"
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
&
types
.
Int64
{
Data
:
int64
(
10
)},
nil
)
grpcClient
.
On
(
"GetSequenceByHash"
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
&
types
.
Int64
{
Data
:
int64
(
10
)},
nil
)
...
...
plugin/consensus/para/paracommitmsg.go
View file @
1bdb1f42
...
@@ -13,6 +13,8 @@ import (
...
@@ -13,6 +13,8 @@ import (
"sync/atomic"
"sync/atomic"
"unsafe"
"unsafe"
"bytes"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
...
@@ -32,7 +34,7 @@ type commitMsgClient struct {
...
@@ -32,7 +34,7 @@ type commitMsgClient struct {
waitConsensStopTimes
uint32
//共识高度低于完成高度, reset高度重发等待的次数
waitConsensStopTimes
uint32
//共识高度低于完成高度, reset高度重发等待的次数
commitCh
chan
int64
commitCh
chan
int64
resetCh
chan
int64
resetCh
chan
int64
verifyCh
chan
bool
verifyCh
chan
[]
byte
sendMsgCh
chan
*
types
.
Transaction
sendMsgCh
chan
*
types
.
Transaction
minerSwitch
int32
minerSwitch
int32
currentTx
unsafe
.
Pointer
currentTx
unsafe
.
Pointer
...
@@ -112,8 +114,8 @@ func (client *commitMsgClient) resetNotify() {
...
@@ -112,8 +114,8 @@ func (client *commitMsgClient) resetNotify() {
client
.
resetCh
<-
1
client
.
resetCh
<-
1
}
}
func
(
client
*
commitMsgClient
)
verifyNotify
(
verif
ied
bool
)
{
func
(
client
*
commitMsgClient
)
verifyNotify
(
verif
yTx
[]
byte
)
{
client
.
verifyCh
<-
verif
ied
client
.
verifyCh
<-
verif
yTx
}
}
func
(
client
*
commitMsgClient
)
resetSendEnv
()
{
func
(
client
*
commitMsgClient
)
resetSendEnv
()
{
...
@@ -169,13 +171,13 @@ func (client *commitMsgClient) procSendTx() {
...
@@ -169,13 +171,13 @@ func (client *commitMsgClient) procSendTx() {
}
}
func
(
client
*
commitMsgClient
)
procVerifyTx
(
verif
ied
bool
)
{
func
(
client
*
commitMsgClient
)
procVerifyTx
(
verif
yTx
[]
byte
)
{
curTx
:=
client
.
getCurrentTx
()
curTx
:=
client
.
getCurrentTx
()
if
curTx
==
nil
{
if
curTx
==
nil
{
return
return
}
}
if
verified
{
if
bytes
.
Equal
(
curTx
.
Hash
(),
verifyTx
)
{
client
.
clearCurrentTx
()
client
.
clearCurrentTx
()
client
.
procSendTx
()
client
.
procSendTx
()
return
return
...
@@ -190,6 +192,7 @@ func (client *commitMsgClient) procVerifyTx(verified bool) {
...
@@ -190,6 +192,7 @@ func (client *commitMsgClient) procVerifyTx(verified bool) {
}
}
//如果共识高度一直没有追上发送高度,且当前发送高度已经上链,说明共识一直没达成,安全起见,超过停止次数后,重发
func
(
client
*
commitMsgClient
)
checkConsensusStop
(
consensStopTimes
uint32
)
uint32
{
func
(
client
*
commitMsgClient
)
checkConsensusStop
(
consensStopTimes
uint32
)
uint32
{
consensHeight
:=
client
.
getConsensusHeight
()
consensHeight
:=
client
.
getConsensusHeight
()
if
client
.
sendingHeight
>
consensHeight
&&
!
client
.
isSendingCommitMsg
()
{
if
client
.
sendingHeight
>
consensHeight
&&
!
client
.
isSendingCommitMsg
()
{
...
@@ -649,7 +652,6 @@ func (client *commitMsgClient) getSelfConsensusStatus() (*pt.ParacrossStatus, er
...
@@ -649,7 +652,6 @@ func (client *commitMsgClient) getSelfConsensusStatus() (*pt.ParacrossStatus, er
if
resp
.
Height
>
-
1
{
if
resp
.
Height
>
-
1
{
var
statusMainHeight
int64
var
statusMainHeight
int64
if
pt
.
IsParaForkHeight
(
resp
.
MainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
if
pt
.
IsParaForkHeight
(
resp
.
MainHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
plog
.
Error
(
"getSelfConsensusStatus ForkLoopCheckCommitTxDone reach"
)
statusMainHeight
=
resp
.
MainHeight
statusMainHeight
=
resp
.
MainHeight
}
else
{
}
else
{
block
,
err
:=
client
.
paraClient
.
GetBlockByHeight
(
resp
.
Height
)
block
,
err
:=
client
.
paraClient
.
GetBlockByHeight
(
resp
.
Height
)
...
...
plugin/consensus/para/paracreate.go
View file @
1bdb1f42
...
@@ -64,7 +64,11 @@ func (client *client) checkCommitTxSuccess(txs []*pt.TxDetail) {
...
@@ -64,7 +64,11 @@ func (client *client) checkCommitTxSuccess(txs []*pt.TxDetail) {
return
return
}
}
client
.
commitMsgClient
.
verifyNotify
(
txMap
[
string
(
curTx
.
Hash
())])
if
txMap
[
string
(
curTx
.
Hash
())]
{
client
.
commitMsgClient
.
verifyNotify
(
curTx
.
Hash
())
}
else
{
client
.
commitMsgClient
.
verifyNotify
(
nil
)
}
}
}
...
...
plugin/consensus/para/paratxrequest_test.go
View file @
1bdb1f42
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"github.com/33cn/chain33/common/log"
"github.com/33cn/chain33/common/log"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/mock"
apimocks
"github.com/33cn/chain33/client/mocks"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
typesmocks
"github.com/33cn/chain33/types/mocks"
typesmocks
"github.com/33cn/chain33/types/mocks"
...
@@ -69,32 +70,46 @@ func TestCalcCommitMsgTxs(t *testing.T) {
...
@@ -69,32 +70,46 @@ func TestCalcCommitMsgTxs(t *testing.T) {
}
}
//func TestGetConsensusStatus(t *testing.T) {
func
TestGetConsensusStatus
(
t
*
testing
.
T
)
{
// para := new(client)
mainFork
:=
mainParaSelfConsensusForkHeight
// grpcClient := &typesmocks.Chain33Client{}
mainParaSelfConsensusForkHeight
=
1
// //grpcClient.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, errors.New("err")).Once()
para
:=
new
(
client
)
// para.grpcClient = grpcClient
grpcClient
:=
&
typesmocks
.
Chain33Client
{}
// commitCli := new(commitMsgClient)
//grpcClient.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, errors.New("err")).Once()
// commitCli.paraClient = para
para
.
grpcClient
=
grpcClient
//
commitCli
:=
new
(
commitMsgClient
)
// block := &types.Block{
commitCli
.
paraClient
=
para
// Height: 1,
// MainHeight: 10,
block
:=
&
types
.
Block
{
// }
Height
:
1
,
//
MainHeight
:
10
,
// status := &pt.ParacrossStatus{
}
// Height: 1,
getMockLastBlock
(
para
,
block
)
// }
// reply := &types.Reply{
api
:=
&
apimocks
.
QueueProtocolAPI
{}
// IsOk: true,
para
.
SetAPI
(
api
)
// Msg: types.Encode(status),
// }
status
:=
&
pt
.
ParacrossStatus
{
// grpcClient.On("QueryChain", mock.Anything, mock.Anything).Return(reply, nil).Once()
Height
:
1
,
// ret, err := commitCli.getSelfConsensusStatus()
}
//
// assert.Nil(t, err)
//msgx := &types.Message{types.Encode(status)}
// assert.Equal(t, int64(1), ret.Height)
//msg := types.Encode(status)
//}
//reply := &types.Reply{
// IsOk: true,
// Msg: types.Encode(status),
//}
api
.
On
(
"QueryChain"
,
mock
.
Anything
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
status
,
nil
)
.
Once
()
detail
:=
&
types
.
BlockDetail
{
Block
:
block
}
details
:=
&
types
.
BlockDetails
{
Items
:
[]
*
types
.
BlockDetail
{
detail
}}
api
.
On
(
"GetBlocks"
,
mock
.
Anything
)
.
Return
(
details
,
nil
)
.
Once
()
ret
,
err
:=
commitCli
.
getSelfConsensusStatus
()
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
1
),
ret
.
Height
)
mainParaSelfConsensusForkHeight
=
mainFork
}
func
TestSendCommitMsg
(
t
*
testing
.
T
)
{
func
TestSendCommitMsg
(
t
*
testing
.
T
)
{
para
:=
new
(
client
)
para
:=
new
(
client
)
...
...
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