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
2ba66c02
Commit
2ba66c02
authored
Mar 26, 2019
by
mdj33
Committed by
33cn
Mar 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ut
parent
4c276e65
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
42 deletions
+77
-42
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+46
-42
paratxrequest_test.go
plugin/consensus/para/paratxrequest_test.go
+31
-0
No files found.
plugin/consensus/para/paracommitmsg.go
View file @
2ba66c02
...
...
@@ -519,49 +519,10 @@ out:
continue
}
var
status
*
pt
.
ParacrossStatus
if
isParaSelfConsensusForked
(
block
.
MainHeight
)
{
//从本地查询共识高度
ret
,
err
:=
client
.
paraClient
.
GetAPI
()
.
QueryChain
(
&
types
.
ChainExecutor
{
Driver
:
"paracross"
,
FuncName
:
"GetTitle"
,
Param
:
types
.
Encode
(
&
types
.
ReqString
{
Data
:
types
.
GetTitle
()}),
})
if
err
!=
nil
{
plog
.
Error
(
"getConsensusHeight "
,
"err"
,
err
.
Error
())
continue
}
resp
,
ok
:=
ret
.
(
*
pt
.
ParacrossStatus
)
if
!
ok
{
plog
.
Error
(
"getConsensusHeight ParacrossStatus nok"
)
continue
}
status
=
resp
}
else
{
//获取主链共识高度
reply
,
err
:=
client
.
paraClient
.
grpcClient
.
QueryChain
(
context
.
Background
(),
&
types
.
ChainExecutor
{
Driver
:
"paracross"
,
FuncName
:
"GetTitleByHash"
,
Param
:
types
.
Encode
(
&
pt
.
ReqParacrossTitleHash
{
Title
:
types
.
GetTitle
(),
BlockHash
:
block
.
MainHash
}),
})
if
err
!=
nil
{
plog
.
Error
(
"getMainConsensusHeight"
,
"err"
,
err
.
Error
())
continue
}
if
!
reply
.
GetIsOk
()
{
plog
.
Info
(
"getMainConsensusHeight nok"
,
"error"
,
reply
.
GetMsg
())
continue
}
var
result
pt
.
ParacrossStatus
err
=
types
.
Decode
(
reply
.
Msg
,
&
result
)
if
err
!=
nil
{
plog
.
Error
(
"getMainConsensusHeight decode"
,
"err"
,
err
.
Error
())
continue
}
status
=
&
result
status
,
err
:=
client
.
getConsensusStatus
(
block
)
if
err
!=
nil
{
continue
}
consensusRst
<-
status
}
}
...
...
@@ -569,6 +530,49 @@ out:
client
.
paraClient
.
wg
.
Done
()
}
func
(
client
*
commitMsgClient
)
getConsensusStatus
(
block
*
types
.
Block
)
(
*
pt
.
ParacrossStatus
,
error
)
{
//获取主链共识高度
if
!
isParaSelfConsensusForked
(
block
.
MainHeight
)
{
reply
,
err
:=
client
.
paraClient
.
grpcClient
.
QueryChain
(
context
.
Background
(),
&
types
.
ChainExecutor
{
Driver
:
"paracross"
,
FuncName
:
"GetTitleByHash"
,
Param
:
types
.
Encode
(
&
pt
.
ReqParacrossTitleHash
{
Title
:
types
.
GetTitle
(),
BlockHash
:
block
.
MainHash
}),
})
if
err
!=
nil
{
plog
.
Error
(
"getMainConsensusHeight"
,
"err"
,
err
.
Error
())
return
nil
,
err
}
if
!
reply
.
GetIsOk
()
{
plog
.
Info
(
"getMainConsensusHeight nok"
,
"error"
,
reply
.
GetMsg
())
return
nil
,
err
}
var
result
pt
.
ParacrossStatus
err
=
types
.
Decode
(
reply
.
Msg
,
&
result
)
if
err
!=
nil
{
plog
.
Error
(
"getMainConsensusHeight decode"
,
"err"
,
err
.
Error
())
return
nil
,
err
}
return
&
result
,
nil
}
//从本地查询共识高度
ret
,
err
:=
client
.
paraClient
.
GetAPI
()
.
QueryChain
(
&
types
.
ChainExecutor
{
Driver
:
"paracross"
,
FuncName
:
"GetTitle"
,
Param
:
types
.
Encode
(
&
types
.
ReqString
{
Data
:
types
.
GetTitle
()}),
})
if
err
!=
nil
{
plog
.
Error
(
"getConsensusHeight "
,
"err"
,
err
.
Error
())
return
nil
,
err
}
resp
,
ok
:=
ret
.
(
*
pt
.
ParacrossStatus
)
if
!
ok
{
plog
.
Error
(
"getConsensusHeight ParacrossStatus nok"
)
return
nil
,
err
}
return
resp
,
nil
}
func
(
client
*
commitMsgClient
)
fetchPrivacyKey
(
ch
chan
crypto
.
PrivKey
)
{
defer
client
.
paraClient
.
wg
.
Done
()
if
client
.
paraClient
.
authAccount
==
""
{
...
...
plugin/consensus/para/paratxrequest_test.go
View file @
2ba66c02
...
...
@@ -246,3 +246,34 @@ func TestCalcCommitMsgTxs(t *testing.T) {
assert
.
NotNil
(
t
,
tx
)
}
func
TestGetConsensusStatus
(
t
*
testing
.
T
)
{
para
:=
new
(
client
)
para
.
GetAPI
()
grpcClient
:=
&
typesmocks
.
Chain33Client
{}
//grpcClient.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, errors.New("err")).Once()
para
.
grpcClient
=
grpcClient
commitCli
:=
new
(
commitMsgClient
)
commitCli
.
paraClient
=
para
block
:=
&
types
.
Block
{
Height
:
1
,
MainHeight
:
10
,
}
status
:=
&
pt
.
ParacrossStatus
{
Height
:
1
,
}
reply
:=
&
types
.
Reply
{
IsOk
:
true
,
Msg
:
types
.
Encode
(
status
),
}
grpcClient
.
On
(
"QueryChain"
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
reply
,
nil
)
.
Once
()
ret
,
err
:=
commitCli
.
getConsensusStatus
(
block
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
1
),
ret
.
Height
)
mainParaSelfConsensusForkHeight
=
1
}
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