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
e30ad65c
Commit
e30ad65c
authored
Jul 08, 2019
by
mdj33
Committed by
vipwzw
Jul 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve
parent
369b8945
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
32 deletions
+63
-32
action.go
plugin/dapp/paracross/executor/action.go
+46
-27
db.go
plugin/dapp/paracross/executor/db.go
+16
-2
exec_local.go
plugin/dapp/paracross/executor/exec_local.go
+1
-3
No files found.
plugin/dapp/paracross/executor/action.go
View file @
e30ad65c
...
@@ -102,28 +102,24 @@ func checkCommitInfo(commit *pt.ParacrossCommitAction) error {
...
@@ -102,28 +102,24 @@ func checkCommitInfo(commit *pt.ParacrossCommitAction) error {
clog
.
Debug
(
"paracross.Commit check input"
,
"height"
,
commit
.
Status
.
Height
,
"mainHeight"
,
commit
.
Status
.
MainBlockHeight
,
clog
.
Debug
(
"paracross.Commit check input"
,
"height"
,
commit
.
Status
.
Height
,
"mainHeight"
,
commit
.
Status
.
MainBlockHeight
,
"mainHash"
,
hex
.
EncodeToString
(
commit
.
Status
.
MainBlockHash
),
"blockHash"
,
hex
.
EncodeToString
(
commit
.
Status
.
BlockHash
))
"mainHash"
,
hex
.
EncodeToString
(
commit
.
Status
.
MainBlockHash
),
"blockHash"
,
hex
.
EncodeToString
(
commit
.
Status
.
BlockHash
))
if
!
pt
.
IsParaForkHeight
(
commit
.
Status
.
MainBlockHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
if
commit
.
Status
.
Height
==
0
{
if
commit
.
Status
.
Height
==
0
{
if
len
(
commit
.
Status
.
Title
)
==
0
||
len
(
commit
.
Status
.
BlockHash
)
==
0
{
if
len
(
commit
.
Status
.
Title
)
==
0
||
len
(
commit
.
Status
.
BlockHash
)
==
0
{
return
types
.
ErrInvalidParam
}
return
nil
}
if
len
(
commit
.
Status
.
MainBlockHash
)
==
0
||
len
(
commit
.
Status
.
Title
)
==
0
||
commit
.
Status
.
Height
<
0
||
len
(
commit
.
Status
.
PreBlockHash
)
==
0
||
len
(
commit
.
Status
.
BlockHash
)
==
0
||
len
(
commit
.
Status
.
StateHash
)
==
0
||
len
(
commit
.
Status
.
PreStateHash
)
==
0
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
return
nil
return
nil
}
}
if
commit
.
Status
.
Height
==
0
{
if
!
pt
.
IsParaForkHeight
(
commit
.
Status
.
MainBlockHeight
,
pt
.
ForkLoopCheckCommitTxDone
)
{
if
len
(
commit
.
Status
.
Title
)
==
0
||
len
(
commit
.
Status
.
BlockHash
)
==
0
{
if
len
(
commit
.
Status
.
MainBlockHash
)
==
0
||
len
(
commit
.
Status
.
Title
)
==
0
||
commit
.
Status
.
Height
<
0
||
len
(
commit
.
Status
.
PreBlockHash
)
==
0
||
len
(
commit
.
Status
.
BlockHash
)
==
0
||
len
(
commit
.
Status
.
StateHash
)
==
0
||
len
(
commit
.
Status
.
PreStateHash
)
==
0
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
return
nil
return
nil
}
}
if
len
(
commit
.
Status
.
MainBlockHash
)
==
0
||
commit
.
Status
.
Height
<
0
||
len
(
commit
.
Status
.
BlockHash
)
==
0
{
if
len
(
commit
.
Status
.
MainBlockHash
)
==
0
||
len
(
commit
.
Status
.
BlockHash
)
==
0
||
commit
.
Status
.
MainBlockHeight
<
0
||
commit
.
Status
.
Height
<
0
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
...
@@ -356,21 +352,30 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
...
@@ -356,21 +352,30 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
// 主链 (1)Bn1 (3) rollback-Bn1 (4) commit-done in Bn2
// 主链 (1)Bn1 (3) rollback-Bn1 (4) commit-done in Bn2
// 平行链 (2)commit (5) 将得到一个错误的块
// 平行链 (2)commit (5) 将得到一个错误的块
// 所以有必要做这个检测
// 所以有必要做这个检测
commitHeight
:=
commit
.
Status
.
MainBlockHeight
var
dbMainHash
[]
byte
commitHash
:=
commit
.
Status
.
MainBlockHash
if
!
types
.
IsPara
(){
if
types
.
IsPara
()
{
blockHash
,
err
:=
getBlockHash
(
a
.
api
,
commit
.
Status
.
MainBlockHeight
)
commitHeight
=
commit
.
Status
.
Height
if
err
!=
nil
{
commitHash
=
commit
.
Status
.
BlockHash
clog
.
Error
(
"paracross.Commit getBlockHash"
,
"err"
,
err
,
}
"commit tx height"
,
commit
.
Status
.
MainBlockHeight
,
"from"
,
a
.
fromaddr
)
blockHash
,
err
:=
getBlockHash
(
a
.
api
,
commitHeight
)
return
nil
,
err
if
err
!=
nil
{
}
clog
.
Error
(
"paracross.Commit getBlockHash"
,
"err"
,
err
,
dbMainHash
=
blockHash
.
Hash
"commit tx height"
,
commitHeight
,
"isMain"
,
!
types
.
IsPara
(),
"from"
,
a
.
fromaddr
)
return
nil
,
err
}
else
{
block
,
err
:=
getBlockInfo
(
a
.
api
,
commit
.
Status
.
Height
)
if
err
!=
nil
{
clog
.
Error
(
"paracross.Commit getBlockInfo"
,
"err"
,
err
,
"height"
,
commit
.
Status
.
Height
,
"from"
,
a
.
fromaddr
)
return
nil
,
err
}
dbMainHash
=
block
.
MainHash
}
}
if
!
bytes
.
Equal
(
blockHash
.
Hash
,
commitHash
)
&&
commit
.
Status
.
Height
>
0
{
clog
.
Error
(
"paracross.Commit blockHash not match"
,
"isMain"
,
!
types
.
IsPara
(),
"db"
,
hex
.
EncodeToString
(
blockHash
.
Hash
),
//对于主链,校验的是主链高度对应的blockhash是否和commit的一致
"commit tx"
,
hex
.
EncodeToString
(
commitHash
),
"commitHeight"
,
commit
.
Status
.
Height
,
//对于平行链, 校验的是commit信息的平行链height block对应的mainHash是否和本地相同高度对应的mainHash一致, 在主链hash一致的时候看平行链共识blockhash是否一致
if
!
bytes
.
Equal
(
dbMainHash
,
commit
.
Status
.
MainBlockHash
)
&&
commit
.
Status
.
Height
>
0
{
clog
.
Error
(
"paracross.Commit blockHash not match"
,
"isMain"
,
!
types
.
IsPara
(),
"db"
,
hex
.
EncodeToString
(
dbMainHash
),
"commit"
,
hex
.
EncodeToString
(
commit
.
Status
.
MainBlockHash
),
"commitHeight"
,
commit
.
Status
.
Height
,
"commitMainHeight"
,
commit
.
Status
.
MainBlockHeight
,
"from"
,
a
.
fromaddr
)
"commitMainHeight"
,
commit
.
Status
.
MainBlockHeight
,
"from"
,
a
.
fromaddr
)
return
nil
,
types
.
ErrBlockHashNoMatch
return
nil
,
types
.
ErrBlockHashNoMatch
}
}
...
@@ -519,6 +524,20 @@ func (a *action) commitTxDoneStep2(nodeStatus *pt.ParacrossNodeStatus, stat *pt.
...
@@ -519,6 +524,20 @@ func (a *action) commitTxDoneStep2(nodeStatus *pt.ParacrossNodeStatus, stat *pt.
//parallel chain not need to process cross commit tx here
//parallel chain not need to process cross commit tx here
if
types
.
IsPara
()
{
if
types
.
IsPara
()
{
//平行链自共识校验
selfBlockHash
,
err
:=
getBlockHash
(
a
.
api
,
nodeStatus
.
Height
)
if
err
!=
nil
{
clog
.
Error
(
"paracross.CommitDone getBlockHash"
,
"err"
,
err
,
"commit tx height"
,
nodeStatus
.
Height
,
"tx"
,
hex
.
EncodeToString
(
a
.
txhash
))
return
nil
,
err
}
//说明本节点blockhash和共识hash不一致,需要停止本节点执行
if
!
bytes
.
Equal
(
selfBlockHash
.
Hash
,
nodeStatus
.
BlockHash
){
clog
.
Error
(
"paracross.CommitDone mosthash not match"
,
"height"
,
nodeStatus
.
Height
,
"blockHash"
,
hex
.
EncodeToString
(
selfBlockHash
.
Hash
),
"mosthash"
,
hex
.
EncodeToString
(
nodeStatus
.
BlockHash
))
return
nil
,
pt
.
ErrParaCurHashNotMatch
}
//平行连进行奖励分配
//平行连进行奖励分配
rewardReceipt
,
err
:=
a
.
reward
(
nodeStatus
,
stat
)
rewardReceipt
,
err
:=
a
.
reward
(
nodeStatus
,
stat
)
//错误会导致和主链处理的共识结果不一致
//错误会导致和主链处理的共识结果不一致
...
...
plugin/dapp/paracross/executor/db.go
View file @
e30ad65c
...
@@ -20,7 +20,7 @@ func getTitle(db dbm.KV, key []byte) (*pt.ParacrossStatus, error) {
...
@@ -20,7 +20,7 @@ func getTitle(db dbm.KV, key []byte) (*pt.ParacrossStatus, error) {
return
nil
,
err
return
nil
,
err
}
}
// 平行链如果是从其他链上移过来的, 需要增加配置, 对应title的平行链的起始高度
// 平行链如果是从其他链上移过来的, 需要增加配置, 对应title的平行链的起始高度
clog
.
Info
(
"first time load title"
,
"key"
,
string
(
key
))
clog
.
Debug
(
"first time load title"
,
"key"
,
string
(
key
))
return
&
pt
.
ParacrossStatus
{
Height
:
-
1
},
nil
return
&
pt
.
ParacrossStatus
{
Height
:
-
1
},
nil
}
}
...
@@ -39,7 +39,7 @@ func getTitleHeight(db dbm.KV, key []byte) (*pt.ParacrossHeightStatus, error) {
...
@@ -39,7 +39,7 @@ func getTitleHeight(db dbm.KV, key []byte) (*pt.ParacrossHeightStatus, error) {
if
err
!=
nil
{
if
err
!=
nil
{
// 对应高度第一次提交commit
// 对应高度第一次提交commit
if
isNotFound
(
err
)
{
if
isNotFound
(
err
)
{
clog
.
Info
(
"paracross.Commit first commit"
,
"key"
,
string
(
key
))
clog
.
Debug
(
"paracross.Commit first commit"
,
"key"
,
string
(
key
))
}
}
return
nil
,
err
return
nil
,
err
}
}
...
@@ -83,6 +83,20 @@ func getBlockHash(api client.QueueProtocolAPI, height int64) (*types.ReplyHash,
...
@@ -83,6 +83,20 @@ func getBlockHash(api client.QueueProtocolAPI, height int64) (*types.ReplyHash,
return
hash
,
nil
return
hash
,
nil
}
}
func
getBlockInfo
(
api
client
.
QueueProtocolAPI
,
height
int64
)
(
*
types
.
Block
,
error
)
{
blockDetails
,
err
:=
api
.
GetBlocks
(
&
types
.
ReqBlocks
{
Start
:
height
,
End
:
height
})
if
err
!=
nil
{
clog
.
Error
(
"paracross.Commit getBlockInfo"
,
"height"
,
height
,
"err"
,
err
.
Error
())
return
nil
,
err
}
if
1
!=
int64
(
len
(
blockDetails
.
Items
))
{
clog
.
Error
(
"paracross.Commit getBlockInfo count"
)
return
nil
,
types
.
ErrInvalidParam
}
return
blockDetails
.
Items
[
0
]
.
Block
,
nil
}
func
isNotFound
(
err
error
)
bool
{
func
isNotFound
(
err
error
)
bool
{
if
err
!=
nil
&&
(
err
==
dbm
.
ErrNotFoundInDb
||
err
==
types
.
ErrNotFound
)
{
if
err
!=
nil
&&
(
err
==
dbm
.
ErrNotFoundInDb
||
err
==
types
.
ErrNotFound
)
{
return
true
return
true
...
...
plugin/dapp/paracross/executor/exec_local.go
View file @
e30ad65c
...
@@ -248,10 +248,8 @@ func (e *Paracross) ExecLocal_Miner(payload *pt.ParacrossMinerAction, tx *types.
...
@@ -248,10 +248,8 @@ func (e *Paracross) ExecLocal_Miner(payload *pt.ParacrossMinerAction, tx *types.
var
set
types
.
LocalDBSet
var
set
types
.
LocalDBSet
txs
:=
e
.
GetTxs
()
txs
:=
e
.
GetTxs
()
forkHeight
:=
pt
.
GetDappForkHeight
(
pt
.
ForkCommitTx
)
//removed the 0 vote tx
//removed the 0 vote tx
if
p
ayload
.
Status
.
MainBlockHeight
>=
forkHeight
{
if
p
t
.
IsParaForkHeight
(
payload
.
Status
.
MainBlockHeight
,
pt
.
ForkCommitTx
)
{
err
:=
setMinerTxResultFork
(
payload
.
Status
,
txs
[
1
:
],
e
.
GetReceipt
()[
1
:
])
err
:=
setMinerTxResultFork
(
payload
.
Status
,
txs
[
1
:
],
e
.
GetReceipt
()[
1
:
])
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
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