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
b35f406b
Commit
b35f406b
authored
Jul 01, 2019
by
mdj33
Committed by
vipwzw
Jul 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove float calculate
parent
cedd7c81
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
9 deletions
+26
-9
para.go
plugin/consensus/para/para.go
+8
-0
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+12
-5
action.go
plugin/dapp/paracross/executor/action.go
+6
-4
No files found.
plugin/consensus/para/para.go
View file @
b35f406b
...
...
@@ -83,6 +83,7 @@ type subConfig struct {
MainBlockHashForkHeight
int64
`json:"mainBlockHashForkHeight,omitempty"`
MainParaSelfConsensusForkHeight
int64
`json:"mainParaSelfConsensusForkHeight,omitempty"`
MainForkParacrossCommitTx
int64
`json:"mainForkParacrossCommitTx,omitempty"`
WaitConsensStopTimes
uint32
`json:"waitConsensStopTimes,omitempty"`
}
// New function to init paracross env
...
...
@@ -155,9 +156,16 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
}
waitBlocks
=
subcfg
.
WaitBlocks4CommitMsg
}
waitConsensTimes
:=
uint32
(
30
)
//30*10s = 5min
if
subcfg
.
WaitConsensStopTimes
>
0
{
waitConsensTimes
=
subcfg
.
WaitConsensStopTimes
}
para
.
commitMsgClient
=
&
commitMsgClient
{
paraClient
:
para
,
waitMainBlocks
:
waitBlocks
,
waitConsensStopTimes
:
waitConsensTimes
,
commitMsgNotify
:
make
(
chan
int64
,
1
),
delMsgNotify
:
make
(
chan
int64
,
1
),
mainBlockAdd
:
make
(
chan
*
types
.
BlockDetail
,
1
),
...
...
plugin/consensus/para/paracommitmsg.go
View file @
b35f406b
...
...
@@ -27,6 +27,7 @@ var (
type
commitMsgClient
struct
{
paraClient
*
client
waitMainBlocks
int32
//等待平行链共识消息在主链上链并成功的块数,超出会重发共识消息,最小是2
waitConsensStopTimes
uint32
//共识高度低于完成高度, reset高度重发等待的次数
commitMsgNotify
chan
int64
delMsgNotify
chan
int64
mainBlockAdd
chan
*
types
.
BlockDetail
...
...
@@ -47,12 +48,12 @@ func (client *commitMsgClient) handler() {
var
isRollback
bool
var
notification
[]
int64
//记录每次系统重启后 min and current height
var
finishHeight
int64
=
-
1
var
consensHeight
int64
=
-
1
var
sendingHeight
int64
//当前发送的最大高度
var
sendingMsgs
[]
*
pt
.
ParacrossNodeStatus
var
readTick
<-
chan
time
.
Time
var
ticker
*
time
.
Ticker
var
lastAuthAccountIn
bool
var
consensStopTimes
uint32
client
.
paraClient
.
wg
.
Add
(
1
)
consensusCh
:=
make
(
chan
*
commitConsensRsp
,
1
)
...
...
@@ -163,7 +164,7 @@ out:
//获取正在共识的高度,同步有两层意思,一个是主链跟其他节点完成了同步,另一个是当前平行链节点的高度追赶上了共识高度
//一般来说高度增长从小到大: notifiy[0] -- selfConsensusHeight(mainHeight) -- finishHeight -- sendingHeight -- notify[1]
case
rsp
:=
<-
consensusCh
:
consensHeight
=
rsp
.
status
.
Height
consensHeight
:
=
rsp
.
status
.
Height
plog
.
Info
(
"para consensus rcv"
,
"notify"
,
notification
,
"sending"
,
len
(
sendingMsgs
),
"consensHeight"
,
rsp
.
status
.
Height
,
"finishHeight"
,
finishHeight
,
"authIn"
,
rsp
.
authAccountIn
,
"sync"
,
isSync
,
"miner"
,
readTick
!=
nil
)
plog
.
Debug
(
"para consensus rcv"
,
"consensBlockHash"
,
common
.
ToHex
(
rsp
.
status
.
BlockHash
))
...
...
@@ -186,15 +187,23 @@ out:
// 共识高度追赶上完成高度之后再发,不然继续发浪费手续费
if
finishHeight
>
consensHeight
{
if
consensStopTimes
<
client
.
waitConsensStopTimes
{
isSync
=
false
consensStopTimes
++
continue
}
//reset finishHeight to consensHeight and resent
finishHeight
=
consensHeight
}
//未共识过的小于当前共识高度的区块,可以不参与共识, 如果是新节点,一直等到同步的区块达到了共识高度,才设置同步参与共识
//在某些特殊场景下,比如平行链连接的主链节点分叉后又恢复,主链的共识高度低于分叉高度时候,主链上形成共识空洞,需要从共识高度重新发送而不是分叉高度
//共识高度和分叉高度不一致其中一个原因是共识交易组里面某个高度分叉了,分叉的主链节点执行成功,而其他主链节点执行失败,共识高度停留在交易组最小高度-1
//而分叉高度是交易组里面的某个高度
if
finishHeight
<
consensHeight
{
if
finishHeight
<
=
consensHeight
{
finishHeight
=
consensHeight
consensStopTimes
=
0
}
//系统每次重启都有检查一次共识,如果共识高度落后于系统起来后完成的第一个高度或最小高度,说明可能有共识空洞,需要重发
...
...
@@ -222,8 +231,6 @@ out:
readTick
=
ticker
.
C
plog
.
Info
(
"para consensus start mining"
)
//钱包开启后,从共识高度重新开始发送,在需要重发共识时候,不需要重启设备
finishHeight
=
consensHeight
}
case
<-
client
.
quit
:
...
...
plugin/dapp/paracross/executor/action.go
View file @
b35f406b
...
...
@@ -118,8 +118,9 @@ func checkCommitInfo(commit *pt.ParacrossCommitAction) error {
return
nil
}
//区块链中不能使用float类型
func
isCommitDone
(
nodes
map
[
string
]
struct
{},
mostSame
int
)
bool
{
return
float32
(
mostSame
)
>
float32
(
len
(
nodes
))
*
float32
(
2
)
/
float32
(
3
)
return
3
*
mostSame
>
2
*
len
(
nodes
)
}
func
makeCommitReceipt
(
addr
string
,
commit
*
pt
.
ParacrossCommitAction
,
prev
,
current
*
pt
.
ParacrossHeightStatus
)
*
types
.
Receipt
{
...
...
@@ -273,6 +274,7 @@ func getDappForkHeight(forkKey string) int64 {
}
else
{
forkHeight
=
types
.
GetDappFork
(
pt
.
ParaX
,
forkKey
)
// CI特殊处理,主链是local,fork都是0,平行链有些配置项需要设置为非0,不然获取到的高度为MaxHeight
if
types
.
IsLocal
()
{
switch
forkKey
{
case
pt
.
ForkCommitTx
:
...
...
@@ -696,7 +698,7 @@ func (a *action) commitTxDoneByStat(stat *pt.ParacrossHeightStatus, titleStatus
//平行链自共识无缝切换条件:1,平行链没有共识过,2:commit高度是大于自共识分叉高度且上一次共识的主链高度小于自共识分叉高度,保证只运行一次,
// 这样在主链没有共识空洞前提下,平行链允许有条件的共识跳跃
func
(
a
*
action
)
isParaSelfConsensSwitch
(
sta
t
*
pt
.
ParacrossHeightStatus
,
titleStatus
*
pt
.
ParacrossStatus
)
(
bool
,
error
)
{
func
(
a
*
action
)
isParaSelfConsensSwitch
(
commi
t
*
pt
.
ParacrossHeightStatus
,
titleStatus
*
pt
.
ParacrossStatus
)
(
bool
,
error
)
{
if
!
types
.
IsPara
()
{
return
false
,
nil
}
...
...
@@ -708,7 +710,7 @@ func (a *action) isParaSelfConsensSwitch(stat *pt.ParacrossHeightStatus, titleSt
selfConsensForkHeight
:=
getDappForkHeight
(
pt
.
ParaSelfConsensForkHeight
)
lastStatusMainHeight
:=
int64
(
-
1
)
if
titleStatus
.
Height
>
-
1
{
s
,
err
:=
getTitleHeight
(
a
.
db
,
calcTitleHeightKey
(
sta
t
.
Title
,
titleStatus
.
Height
))
s
,
err
:=
getTitleHeight
(
a
.
db
,
calcTitleHeightKey
(
commi
t
.
Title
,
titleStatus
.
Height
))
if
err
!=
nil
{
clog
.
Error
(
"paracross.Commit isParaSelfConsensSwitch getTitleHeight failed"
,
"err"
,
err
.
Error
())
return
false
,
err
...
...
@@ -716,7 +718,7 @@ func (a *action) isParaSelfConsensSwitch(stat *pt.ParacrossHeightStatus, titleSt
lastStatusMainHeight
=
s
.
MainHeight
}
return
sta
t
.
MainHeight
>
selfConsensForkHeight
&&
lastStatusMainHeight
<
selfConsensForkHeight
,
nil
return
commi
t
.
MainHeight
>
selfConsensForkHeight
&&
lastStatusMainHeight
<
selfConsensForkHeight
,
nil
}
...
...
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