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
2d38ee7d
Commit
2d38ee7d
authored
Nov 12, 2019
by
mdj33
Committed by
vipwzw
Nov 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code improve
parent
340b0718
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
26 deletions
+86
-26
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+44
-26
paracommitmsg_test.go
plugin/consensus/para/paracommitmsg_test.go
+42
-0
No files found.
plugin/consensus/para/paracommitmsg.go
View file @
2d38ee7d
...
@@ -148,7 +148,7 @@ func (client *commitMsgClient) resetSend() {
...
@@ -148,7 +148,7 @@ func (client *commitMsgClient) resetSend() {
//自共识后直接从本地获取最新共识高度,没有自共识,获取主链的共识高度
//自共识后直接从本地获取最新共识高度,没有自共识,获取主链的共识高度
func
(
client
*
commitMsgClient
)
getConsensusHeight
()
int64
{
func
(
client
*
commitMsgClient
)
getConsensusHeight
()
int64
{
status
,
err
:=
client
.
getSelfConsensus
Status
()
status
,
err
:=
client
.
getSelfConsensus
()
if
err
!=
nil
{
if
err
!=
nil
{
return
atomic
.
LoadInt64
(
&
client
.
consensHeight
)
return
atomic
.
LoadInt64
(
&
client
.
consensHeight
)
}
}
...
@@ -729,14 +729,12 @@ func (client *commitMsgClient) GetProperFeeRate() error {
...
@@ -729,14 +729,12 @@ func (client *commitMsgClient) GetProperFeeRate() error {
return
nil
return
nil
}
}
func
(
client
*
commitMsgClient
)
getSelfConsensusStatus
()
(
*
pt
.
ParacrossStatus
,
error
)
{
//在自共识阶段获取共识高度
func
(
client
*
commitMsgClient
)
getSelfConsensus
()
(
*
pt
.
ParacrossStatus
,
error
)
{
block
,
err
:=
client
.
paraClient
.
getLastBlockInfo
()
block
,
err
:=
client
.
paraClient
.
getLastBlockInfo
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
cfg
:=
client
.
paraClient
.
GetAPI
()
.
GetConfig
()
//从本地查询共识高度
ret
,
err
:=
client
.
paraClient
.
GetAPI
()
.
QueryChain
(
&
types
.
ChainExecutor
{
ret
,
err
:=
client
.
paraClient
.
GetAPI
()
.
QueryChain
(
&
types
.
ChainExecutor
{
Driver
:
"paracross"
,
Driver
:
"paracross"
,
FuncName
:
"GetSelfConsOneStage"
,
FuncName
:
"GetSelfConsOneStage"
,
...
@@ -752,19 +750,8 @@ func (client *commitMsgClient) getSelfConsensusStatus() (*pt.ParacrossStatus, er
...
@@ -752,19 +750,8 @@ func (client *commitMsgClient) getSelfConsensusStatus() (*pt.ParacrossStatus, er
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
if
stage
.
Enable
==
pt
.
ParaConfigYes
{
if
stage
.
Enable
==
pt
.
ParaConfigYes
{
//从本地查询共识高度
resp
,
err
:=
client
.
getSelfConsensusStatus
()
ret
,
err
:=
client
.
paraClient
.
GetAPI
()
.
QueryChain
(
&
types
.
ChainExecutor
{
Driver
:
"paracross"
,
FuncName
:
"GetTitle"
,
Param
:
types
.
Encode
(
&
types
.
ReqString
{
Data
:
cfg
.
GetTitle
()}),
})
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"getSelfConsensusStatus "
,
"err"
,
err
.
Error
())
return
nil
,
err
}
resp
,
ok
:=
ret
.
(
*
pt
.
ParacrossStatus
)
if
!
ok
{
plog
.
Error
(
"getSelfConsensusStatus ParacrossStatus nok"
)
return
nil
,
err
return
nil
,
err
}
}
//开启自共识后也要等到自共识真正切换之后再使用,如果本地区块已经过了自共识高度,但自共识的高度还没达成,就会导致共识机制出错
//开启自共识后也要等到自共识真正切换之后再使用,如果本地区块已经过了自共识高度,但自共识的高度还没达成,就会导致共识机制出错
...
@@ -775,6 +762,27 @@ func (client *commitMsgClient) getSelfConsensusStatus() (*pt.ParacrossStatus, er
...
@@ -775,6 +762,27 @@ func (client *commitMsgClient) getSelfConsensusStatus() (*pt.ParacrossStatus, er
return
nil
,
types
.
ErrNotFound
return
nil
,
types
.
ErrNotFound
}
}
//从本地查询共识高度
func
(
client
*
commitMsgClient
)
getSelfConsensusStatus
()
(
*
pt
.
ParacrossStatus
,
error
)
{
cfg
:=
client
.
paraClient
.
GetAPI
()
.
GetConfig
()
ret
,
err
:=
client
.
paraClient
.
GetAPI
()
.
QueryChain
(
&
types
.
ChainExecutor
{
Driver
:
"paracross"
,
FuncName
:
"GetTitle"
,
Param
:
types
.
Encode
(
&
types
.
ReqString
{
Data
:
cfg
.
GetTitle
()}),
})
if
err
!=
nil
{
plog
.
Error
(
"getSelfConsensusStatus "
,
"err"
,
err
)
return
nil
,
err
}
resp
,
ok
:=
ret
.
(
*
pt
.
ParacrossStatus
)
if
!
ok
{
plog
.
Error
(
"getSelfConsensusStatus ParacrossStatus nok"
)
return
nil
,
types
.
ErrNotFound
}
return
resp
,
nil
}
//通过grpc获取主链状态可能耗时,放在定时器里面处理
//通过grpc获取主链状态可能耗时,放在定时器里面处理
func
(
client
*
commitMsgClient
)
getMainConsensusStatus
()
(
*
pt
.
ParacrossStatus
,
error
)
{
func
(
client
*
commitMsgClient
)
getMainConsensusStatus
()
(
*
pt
.
ParacrossStatus
,
error
)
{
block
,
err
:=
client
.
paraClient
.
getLastBlockInfo
()
block
,
err
:=
client
.
paraClient
.
getLastBlockInfo
()
...
@@ -794,7 +802,7 @@ func (client *commitMsgClient) getMainConsensusStatus() (*pt.ParacrossStatus, er
...
@@ -794,7 +802,7 @@ func (client *commitMsgClient) getMainConsensusStatus() (*pt.ParacrossStatus, er
}
}
if
!
reply
.
GetIsOk
()
{
if
!
reply
.
GetIsOk
()
{
plog
.
Info
(
"getMainConsensusStatus nok"
,
"error"
,
reply
.
GetMsg
())
plog
.
Info
(
"getMainConsensusStatus nok"
,
"error"
,
reply
.
GetMsg
())
return
nil
,
err
return
nil
,
types
.
ErrNotFound
}
}
var
result
pt
.
ParacrossStatus
var
result
pt
.
ParacrossStatus
err
=
types
.
Decode
(
reply
.
Msg
,
&
result
)
err
=
types
.
Decode
(
reply
.
Msg
,
&
result
)
...
@@ -899,25 +907,35 @@ func (client *commitMsgClient) fetchPriKey() error {
...
@@ -899,25 +907,35 @@ func (client *commitMsgClient) fetchPriKey() error {
return
nil
return
nil
}
}
func
(
client
*
commitMsgClient
)
setSelfConsEnable
()
error
{
func
parseSelfConsEnableStr
(
selfEnables
[]
string
)
([]
*
paraSelfConsEnable
,
error
)
{
var
err
error
var
err
error
cfg
:=
client
.
paraClient
.
GetAPI
()
.
GetConfig
()
var
list
[]
*
paraSelfConsEnable
selfEnables
:=
types
.
Conf
(
cfg
,
"config.consensus.sub.para"
)
.
GStrList
(
"selfConsensEnablePreContract"
)
for
_
,
v
:=
range
selfEnables
{
for
_
,
v
:=
range
selfEnables
{
hs
:=
strings
.
Split
(
v
,
"-"
)
hs
:=
strings
.
Split
(
v
,
"-"
)
enable
:=
&
paraSelfConsEnable
{}
enable
:=
&
paraSelfConsEnable
{}
enable
.
startHeight
,
err
=
strconv
.
ParseInt
(
hs
[
0
],
0
,
64
)
enable
.
startHeight
,
err
=
strconv
.
ParseInt
(
hs
[
0
],
0
,
64
)
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"para setSelfConsEnable"
,
"v0"
,
hs
[
0
])
plog
.
Error
(
"para setSelfConsEnable"
,
"v0"
,
hs
[
0
]
,
"err"
,
err
)
return
err
return
nil
,
err
}
}
enable
.
endHeight
,
err
=
strconv
.
ParseInt
(
hs
[
1
],
0
,
64
)
enable
.
endHeight
,
err
=
strconv
.
ParseInt
(
hs
[
1
],
0
,
64
)
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"para setSelfConsEnable"
,
"v1"
,
hs
[
1
])
plog
.
Error
(
"para setSelfConsEnable"
,
"v1"
,
hs
[
1
]
,
"err"
,
err
)
return
err
return
nil
,
err
}
}
client
.
selfConsEnableList
=
append
(
client
.
selfConsEnableList
,
enable
)
list
=
append
(
list
,
enable
)
}
return
list
,
nil
}
func
(
client
*
commitMsgClient
)
setSelfConsEnable
()
error
{
cfg
:=
client
.
paraClient
.
GetAPI
()
.
GetConfig
()
selfEnables
:=
types
.
Conf
(
cfg
,
"config.consensus.sub.para"
)
.
GStrList
(
"selfConsensEnablePreContract"
)
list
,
err
:=
parseSelfConsEnableStr
(
selfEnables
)
if
err
!=
nil
{
return
err
}
}
client
.
selfConsEnableList
=
append
(
client
.
selfConsEnableList
,
list
...
)
return
nil
return
nil
}
}
...
...
plugin/consensus/para/paracommitmsg_test.go
View file @
2d38ee7d
...
@@ -7,7 +7,11 @@ package para
...
@@ -7,7 +7,11 @@ package para
import
(
import
(
"testing"
"testing"
"github.com/33cn/chain33/queue"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/chain33/system"
drivers
"github.com/33cn/chain33/system/consensus"
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
)
)
...
@@ -29,3 +33,41 @@ func TestIsSelfConsEnable(t *testing.T) {
...
@@ -29,3 +33,41 @@ func TestIsSelfConsEnable(t *testing.T) {
enable
=
commitCli
.
isSelfConsEnable
(
30
)
enable
=
commitCli
.
isSelfConsEnable
(
30
)
assert
.
Equal
(
t
,
true
,
enable
)
assert
.
Equal
(
t
,
true
,
enable
)
}
}
func
TestParseSelfConsEnableStr
(
t
*
testing
.
T
)
{
t1
:=
[]
string
{
"1-100"
,
"200-300"
}
e1
:=
&
paraSelfConsEnable
{
startHeight
:
1
,
endHeight
:
100
}
e2
:=
&
paraSelfConsEnable
{
startHeight
:
200
,
endHeight
:
300
}
ep1
:=
[]
*
paraSelfConsEnable
{
e1
,
e2
}
t2
:=
[]
string
{
"1-100"
,
"200-"
}
l1
,
err
:=
parseSelfConsEnableStr
(
t1
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
ep1
,
l1
)
l2
,
err
:=
parseSelfConsEnableStr
(
t2
)
assert
.
NotNil
(
t
,
err
)
assert
.
Nil
(
t
,
l2
)
}
func
TestSetSelfConsEnable
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
testnode
.
DefaultConfig
)
q
:=
queue
.
New
(
"channel"
)
q
.
SetConfig
(
cfg
)
para
:=
new
(
client
)
para
.
subCfg
=
new
(
subConfig
)
baseCli
:=
drivers
.
NewBaseClient
(
&
types
.
Consensus
{
Name
:
"name"
})
para
.
BaseClient
=
baseCli
para
.
InitClient
(
q
.
Client
(),
initTestSyncBlock
)
para
.
commitMsgClient
=
&
commitMsgClient
{
paraClient
:
para
,
}
err
:=
para
.
commitMsgClient
.
setSelfConsEnable
()
assert
.
Nil
(
t
,
err
)
e1
:=
&
paraSelfConsEnable
{
startHeight
:
0
,
endHeight
:
1000
}
ep1
:=
[]
*
paraSelfConsEnable
{
e1
}
assert
.
Equal
(
t
,
ep1
,
para
.
commitMsgClient
.
selfConsEnableList
)
}
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