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
7174ecf7
Commit
7174ecf7
authored
Jul 19, 2019
by
yukang
Committed by
vipwzw
Aug 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize some code
parent
db90235d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
20 deletions
+19
-20
parasync.go
plugin/consensus/para/parasync.go
+19
-20
No files found.
plugin/consensus/para/parasync.go
View file @
7174ecf7
...
@@ -17,15 +17,15 @@ import (
...
@@ -17,15 +17,15 @@ import (
)
)
//定义每一轮可执行状态
//
NextActionType
定义每一轮可执行状态
type
NextActionType
int8
type
NextActionType
int8
const
(
const
(
_
NextActionType
=
iota
_
NextActionType
=
iota
//回滚到前一区块
//
NextActionRollback
回滚到前一区块
NextActionRollback
NextActionRollback
//保持
//
NextActionKeep
保持
NextActionKeep
NextActionKeep
//增加一个新的区块
//
NextActionAdd
增加一个新的区块
NextActionAdd
NextActionAdd
)
)
...
@@ -108,24 +108,23 @@ func (client *client) getNextAction() (NextActionType,*types.Block,*pt.ParaLocal
...
@@ -108,24 +108,23 @@ func (client *client) getNextAction() (NextActionType,*types.Block,*pt.ParaLocal
if
common
.
ToHex
(
localBlock
.
MainHash
)
==
common
.
ToHex
(
lastBlock
.
MainHash
)
{
if
common
.
ToHex
(
localBlock
.
MainHash
)
==
common
.
ToHex
(
lastBlock
.
MainHash
)
{
//db中最新区块高度等于已执行最新区块高度并且hash相同,不做任何操作(已保持同步状态)
//db中最新区块高度等于已执行最新区块高度并且hash相同,不做任何操作(已保持同步状态)
return
NextActionKeep
,
nil
,
nil
,
lastLocalHeight
,
err
return
NextActionKeep
,
nil
,
nil
,
lastLocalHeight
,
err
}
else
{
//db中最新区块高度等于已执行最新区块高度并且hash不同,回滚
return
NextActionRollback
,
lastBlock
,
nil
,
lastLocalHeight
,
err
}
}
else
{
localBlock
,
err
:=
client
.
getLocalBlockByHeight
(
lastBlock
.
Height
+
1
)
if
err
!=
nil
{
//取db中后一高度区块发生错误,不做任何操作
return
NextActionKeep
,
nil
,
nil
,
lastLocalHeight
,
err
}
if
common
.
ToHex
(
localBlock
.
ParentMainHash
)
!=
common
.
ToHex
(
lastBlock
.
MainHash
)
{
//db中后一高度区块的父hash不等于已执行最新区块的hash,回滚
return
NextActionRollback
,
lastBlock
,
nil
,
lastLocalHeight
,
err
}
else
{
//db中后一高度区块的父hash等于已执行最新区块的hash,执行区块创建
return
NextActionAdd
,
lastBlock
,
localBlock
,
lastLocalHeight
,
err
}
}
//db中最新区块高度等于已执行最新区块高度并且hash不同,回滚
return
NextActionRollback
,
lastBlock
,
nil
,
lastLocalHeight
,
err
}
// lastLocalHeight > lastBlock.Height
localBlock
,
err
:=
client
.
getLocalBlockByHeight
(
lastBlock
.
Height
+
1
)
if
err
!=
nil
{
//取db中后一高度区块发生错误,不做任何操作
return
NextActionKeep
,
nil
,
nil
,
lastLocalHeight
,
err
}
if
common
.
ToHex
(
localBlock
.
ParentMainHash
)
!=
common
.
ToHex
(
lastBlock
.
MainHash
)
{
//db中后一高度区块的父hash不等于已执行最新区块的hash,回滚
return
NextActionRollback
,
lastBlock
,
nil
,
lastLocalHeight
,
err
}
}
//db中后一高度区块的父hash等于已执行最新区块的hash,执行区块创建
return
NextActionAdd
,
lastBlock
,
localBlock
,
lastLocalHeight
,
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