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
63d2b2cb
Commit
63d2b2cb
authored
Nov 07, 2019
by
mdj33
Committed by
vipwzw
Nov 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add stage cmd
parent
6d6bf32e
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
134 additions
and
97 deletions
+134
-97
chain33.para.toml
chain33.para.toml
+1
-5
para.go
plugin/consensus/para/para.go
+20
-20
parasync.go
plugin/consensus/para/parasync.go
+7
-2
testcase.sh
plugin/dapp/paracross/cmd/build/testcase.sh
+0
-4
paracross.go
plugin/dapp/paracross/commands/paracross.go
+1
-1
action.go
plugin/dapp/paracross/executor/action.go
+7
-13
query.go
plugin/dapp/paracross/executor/query.go
+2
-2
stage.go
plugin/dapp/paracross/executor/stage.go
+45
-22
stagelocaldb.go
plugin/dapp/paracross/executor/stagelocaldb.go
+35
-16
stagetable.go
plugin/dapp/paracross/executor/stagetable.go
+1
-1
superaccount.go
plugin/dapp/paracross/executor/superaccount.go
+1
-1
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+10
-10
errors.go
plugin/dapp/paracross/types/errors.go
+2
-0
paracross.go
plugin/dapp/paracross/types/paracross.go
+2
-0
No files found.
chain33.para.toml
View file @
63d2b2cb
...
@@ -108,15 +108,11 @@ mainBlockHashForkHeight=209186
...
@@ -108,15 +108,11 @@ mainBlockHashForkHeight=209186
mainForkParacrossCommitTx
=
2270000
mainForkParacrossCommitTx
=
2270000
#主链开启循环检查共识交易done的fork高度,需要和主链保持严格一致,不可修改,4320000是bityuan主链对应高度, ycc或其他按实际修改
#主链开启循环检查共识交易done的fork高度,需要和主链保持严格一致,不可修改,4320000是bityuan主链对应高度, ycc或其他按实际修改
mainLoopCheckCommitTxDoneForkHeight
=
4320000
mainLoopCheckCommitTxDoneForkHeight
=
4320000
#精简commitMsg,删除多余的hash参数,缺省mainLoopCheckCommitTxDoneForkHeight一致,一些特殊的链如game需定制
rmCommitMsgHashParamMainHeight
=
4320000
#paraSelfConsInitDisable=false
#主链每隔几个没有相关平行链交易的区块,平行链上打包空区块,缺省从平行链blockHeight=0开始,依次增长,空块间隔不能为0
#主链每隔几个没有相关平行链交易的区块,平行链上打包空区块,缺省从平行链blockHeight=0开始,依次增长,空块间隔不能为0
[[consensus.sub.para.emptyBlockInterval]]
[[consensus.sub.para.emptyBlockInterval]]
blockHeight
=
0
blockHeight
=
0
interval
=
50
interval
=
50
#平行链自共识开启对应的主链高度,必须大于等于MainForkParacrossCommitTx=2270000, -1 不开启,可以多个高度开启和关闭
#selfConsensEnablePreContract=["0-9848"]
[store]
[store]
...
...
plugin/consensus/para/para.go
View file @
63d2b2cb
...
@@ -72,26 +72,26 @@ type emptyBlockInterval struct {
...
@@ -72,26 +72,26 @@ type emptyBlockInterval struct {
}
}
type
subConfig
struct
{
type
subConfig
struct
{
WriteBlockSeconds
int64
`json:"writeBlockSeconds,omitempty"`
WriteBlockSeconds
int64
`json:"writeBlockSeconds,omitempty"`
ParaRemoteGrpcClient
string
`json:"paraRemoteGrpcClient,omitempty"`
ParaRemoteGrpcClient
string
`json:"paraRemoteGrpcClient,omitempty"`
StartHeight
int64
`json:"startHeight,omitempty"`
StartHeight
int64
`json:"startHeight,omitempty"`
GenesisStartHeightSame
bool
`json:"genesisStartHeightSame,omitempty"`
GenesisStartHeightSame
bool
`json:"genesisStartHeightSame,omitempty"`
EmptyBlockInterval
[]
*
emptyBlockInterval
`json:"emptyBlockInterval,omitempty"`
EmptyBlockInterval
[]
*
emptyBlockInterval
`json:"emptyBlockInterval,omitempty"`
AuthAccount
string
`json:"authAccount,omitempty"`
AuthAccount
string
`json:"authAccount,omitempty"`
WaitBlocks4CommitMsg
int32
`json:"waitBlocks4CommitMsg,omitempty"`
WaitBlocks4CommitMsg
int32
`json:"waitBlocks4CommitMsg,omitempty"`
GenesisAmount
int64
`json:"genesisAmount,omitempty"`
GenesisAmount
int64
`json:"genesisAmount,omitempty"`
MainBlockHashForkHeight
int64
`json:"mainBlockHashForkHeight,omitempty"`
MainBlockHashForkHeight
int64
`json:"mainBlockHashForkHeight,omitempty"`
WaitConsensStopTimes
uint32
`json:"waitConsensStopTimes,omitempty"`
WaitConsensStopTimes
uint32
`json:"waitConsensStopTimes,omitempty"`
MaxCacheCount
int64
`json:"maxCacheCount,omitempty"`
MaxCacheCount
int64
`json:"maxCacheCount,omitempty"`
MaxSyncErrCount
int32
`json:"maxSyncErrCount,omitempty"`
MaxSyncErrCount
int32
`json:"maxSyncErrCount,omitempty"`
FetchFilterParaTxsClose
bool
`json:"fetchFilterParaTxsClose,omitempty"`
FetchFilterParaTxsClose
bool
`json:"fetchFilterParaTxsClose,omitempty"`
BatchFetchBlockCount
int64
`json:"batchFetchBlockCount,omitempty"`
BatchFetchBlockCount
int64
`json:"batchFetchBlockCount,omitempty"`
ParaConsensStartHeight
int64
`json:"paraConsensStartHeight,omitempty"`
ParaConsensStartHeight
int64
`json:"paraConsensStartHeight,omitempty"`
MultiDownloadOpen
bool
`json:"multiDownloadOpen,omitempty"`
MultiDownloadOpen
bool
`json:"multiDownloadOpen,omitempty"`
MultiDownInvNumPerJob
int64
`json:"multiDownInvNumPerJob,omitempty"`
MultiDownInvNumPerJob
int64
`json:"multiDownInvNumPerJob,omitempty"`
MultiDownJobBuffNum
uint32
`json:"multiDownJobBuffNum,omitempty"`
MultiDownJobBuffNum
uint32
`json:"multiDownJobBuffNum,omitempty"`
MultiDownServerRspTime
uint32
`json:"multiDownServerRspTime,omitempty"`
MultiDownServerRspTime
uint32
`json:"multiDownServerRspTime,omitempty"`
RmCommit
MsgHashParamMainHeight
int64
`json:"rmCommitMsgHash
ParamMainHeight,omitempty"`
RmCommit
ParamMainHeight
int64
`json:"rmCommit
ParamMainHeight,omitempty"`
}
}
// New function to init paracross env
// New function to init paracross env
...
...
plugin/consensus/para/parasync.go
View file @
63d2b2cb
...
@@ -365,12 +365,17 @@ func (client *blockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc
...
@@ -365,12 +365,17 @@ func (client *blockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc
MainBlockHash
:
localBlock
.
MainHash
,
MainBlockHash
:
localBlock
.
MainHash
,
MainBlockHeight
:
localBlock
.
MainHeight
,
MainBlockHeight
:
localBlock
.
MainHeight
,
}
}
if
status
.
MainBlockHeight
<
client
.
paraClient
.
subCfg
.
RmCommitMsgHashParamMainHeight
{
maxHeight
:=
pt
.
GetDappForkHeight
(
cfg
,
pt
.
ForkLoopCheckCommitTxDone
)
if
maxHeight
<
client
.
paraClient
.
subCfg
.
RmCommitParamMainHeight
{
maxHeight
=
client
.
paraClient
.
subCfg
.
RmCommitParamMainHeight
}
if
status
.
MainBlockHeight
<
maxHeight
{
status
.
PreBlockHash
=
block
.
ParentHash
status
.
PreBlockHash
=
block
.
ParentHash
status
.
PreStateHash
=
preStateHash
status
.
PreStateHash
=
preStateHash
}
}
//selfConsensEnablePreContract 是ForkParaSelfConsStages之前对是否开启共识的设置,fork之后采用合约控制,两个高度不能重叠
tx
,
err
:=
pt
.
CreateRawMinerTx
(
cfg
,
&
pt
.
ParacrossMinerAction
{
tx
,
err
:=
pt
.
CreateRawMinerTx
(
cfg
,
&
pt
.
ParacrossMinerAction
{
Status
:
status
,
Status
:
status
,
IsSelfConsensus
:
client
.
paraClient
.
commitMsgClient
.
isSelfConsEnable
(
status
.
Height
),
IsSelfConsensus
:
client
.
paraClient
.
commitMsgClient
.
isSelfConsEnable
(
status
.
Height
),
...
...
plugin/dapp/paracross/cmd/build/testcase.sh
View file @
63d2b2cb
...
@@ -40,13 +40,9 @@ function para_set_toml() {
...
@@ -40,13 +40,9 @@ function para_set_toml() {
sed
-i
$xsedfix
's/^mainForkParacrossCommitTx=.*/mainForkParacrossCommitTx=10/g'
"
${
1
}
"
sed
-i
$xsedfix
's/^mainForkParacrossCommitTx=.*/mainForkParacrossCommitTx=10/g'
"
${
1
}
"
sed
-i
$xsedfix
's/^mainLoopCheckCommitTxDoneForkHeight=.*/mainLoopCheckCommitTxDoneForkHeight='''
$MainLoopCheckForkHeight
'''/g'
"
${
1
}
"
sed
-i
$xsedfix
's/^mainLoopCheckCommitTxDoneForkHeight=.*/mainLoopCheckCommitTxDoneForkHeight='''
$MainLoopCheckForkHeight
'''/g'
"
${
1
}
"
sed
-i
$xsedfix
's/^rmCommitMsgHashParamMainHeight=.*/rmCommitMsgHashParamMainHeight='''
$MainLoopCheckForkHeight
'''/g'
"
${
1
}
"
sed
-i
$xsedfix
's/^mainBlockHashForkHeight=.*/mainBlockHashForkHeight=1/g'
"
${
1
}
"
sed
-i
$xsedfix
's/^mainBlockHashForkHeight=.*/mainBlockHashForkHeight=1/g'
"
${
1
}
"
#sed -i $xsedfix '/\[\[consensus.sub.para.selfConsensusEnable\]\]/{n;n;s/enable=false/enable=true/}' "${1}"
sed
-i
$xsedfix
'/\[\[consensus.sub.para.selfConsensusEnable\]\]/!b;n;n;cenable=true'
"
${
1
}
"
# rpc
# rpc
sed
-i
$xsedfix
's/^jrpcBindAddr=.*/jrpcBindAddr="0.0.0.0:8901"/g'
"
${
1
}
"
sed
-i
$xsedfix
's/^jrpcBindAddr=.*/jrpcBindAddr="0.0.0.0:8901"/g'
"
${
1
}
"
sed
-i
$xsedfix
's/^grpcBindAddr=.*/grpcBindAddr="0.0.0.0:8902"/g'
"
${
1
}
"
sed
-i
$xsedfix
's/^grpcBindAddr=.*/grpcBindAddr="0.0.0.0:8902"/g'
"
${
1
}
"
...
...
plugin/dapp/paracross/commands/paracross.go
View file @
63d2b2cb
...
@@ -1059,7 +1059,7 @@ func showSelfStages(cmd *cobra.Command, args []string) {
...
@@ -1059,7 +1059,7 @@ func showSelfStages(cmd *cobra.Command, args []string) {
height
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"height"
)
height
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"height"
)
index
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"index"
)
index
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"index"
)
params
:=
&
pt
.
ReqQuerySelfStages
{
params
:=
pt
.
ReqQuerySelfStages
{
Status
:
status
,
Status
:
status
,
Id
:
id
,
Id
:
id
,
Count
:
count
,
Count
:
count
,
...
...
plugin/dapp/paracross/executor/action.go
View file @
63d2b2cb
...
@@ -320,15 +320,14 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
...
@@ -320,15 +320,14 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
cfg
:=
a
.
api
.
GetConfig
()
cfg
:=
a
.
api
.
GetConfig
()
var
stage
*
pt
.
SelfConsensStage
var
stage
*
pt
.
SelfConsensStage
if
types
.
IsPara
()
&&
types
.
IsDappFork
(
a
.
height
,
pt
.
ParaX
,
pt
.
ForkParaSelfConsStages
)
{
if
types
.
IsPara
()
&&
types
.
IsDappFork
(
a
.
height
,
pt
.
ParaX
,
pt
.
ForkParaSelfConsStages
)
{
_
,
stages
,
err
:=
getSelfConsensStages
(
a
.
db
)
stages
,
err
:=
getSelfConsensStages
(
a
.
db
)
if
err
!=
nil
{
if
err
!=
nil
{
return
&
types
.
Receipt
{},
nil
return
nil
,
err
}
}
stage
=
getSelfConsOneStage
(
a
.
height
,
stages
)
stage
=
getSelfConsOneStage
(
a
.
height
,
stages
)
clog
.
Info
(
"paracross.commit"
,
"height"
,
a
.
height
,
"stageHeight"
,
stage
.
BlockHeight
,
"enable"
,
stage
.
Enable
)
if
stage
.
Enable
==
pt
.
ParaConfigNo
{
if
stage
.
Enable
==
pt
.
ParaConfigNo
{
return
&
types
.
Receipt
{},
nil
return
nil
,
pt
.
ErrConsensClosed
}
}
}
}
...
@@ -950,17 +949,12 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
...
@@ -950,17 +949,12 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
minerReceipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
nil
,
Logs
:
logs
}
minerReceipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
nil
,
Logs
:
logs
}
isSelfConsensOn
:=
miner
.
IsSelfConsensus
isSelfConsensOn
:=
miner
.
IsSelfConsensus
if
types
.
IsDappFork
(
a
.
height
,
pt
.
ParaX
,
pt
.
ForkParaSelfConsStages
)
{
if
types
.
IsDappFork
(
a
.
height
,
pt
.
ParaX
,
pt
.
ForkParaSelfConsStages
)
{
_
,
stages
,
err
:=
getSelfConsensStages
(
a
.
db
)
var
err
error
if
err
!=
nil
&&
errors
.
Cause
(
err
)
!=
pt
.
ErrKeyNotExist
{
isSelfConsensOn
,
err
=
isSelfConsOn
(
a
.
db
,
miner
.
Status
.
Height
)
if
err
!=
nil
{
clog
.
Error
(
"paracross miner getConsensus "
,
"height"
,
miner
.
Status
.
Height
,
"err"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
if
stages
!=
nil
{
stage
:=
getSelfConsOneStage
(
miner
.
Status
.
Height
,
stages
)
isSelfConsensOn
=
stage
.
Enable
==
pt
.
ParaConfigYes
}
else
{
isSelfConsensOn
=
false
}
}
}
//自共识后才挖矿
//自共识后才挖矿
...
...
plugin/dapp/paracross/executor/query.go
View file @
63d2b2cb
...
@@ -411,7 +411,7 @@ func (p *Paracross) paracrossGetAssetTxResult(hash []byte) (types.Message, error
...
@@ -411,7 +411,7 @@ func (p *Paracross) paracrossGetAssetTxResult(hash []byte) (types.Message, error
//Query_GetSelfConsStages get self consensus stages configed
//Query_GetSelfConsStages get self consensus stages configed
func
(
p
*
Paracross
)
Query_GetSelfConsStages
(
in
*
types
.
ReqNil
)
(
types
.
Message
,
error
)
{
func
(
p
*
Paracross
)
Query_GetSelfConsStages
(
in
*
types
.
ReqNil
)
(
types
.
Message
,
error
)
{
_
,
stages
,
err
:=
getSelfConsensStages
(
p
.
GetStateDB
())
stages
,
err
:=
getSelfConsensStages
(
p
.
GetStateDB
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Cause
(
err
)
return
nil
,
errors
.
Cause
(
err
)
}
}
...
@@ -421,7 +421,7 @@ func (p *Paracross) Query_GetSelfConsStages(in *types.ReqNil) (types.Message, er
...
@@ -421,7 +421,7 @@ func (p *Paracross) Query_GetSelfConsStages(in *types.ReqNil) (types.Message, er
//Query_GetSelfConsOneStage get self consensus one stage
//Query_GetSelfConsOneStage get self consensus one stage
func
(
p
*
Paracross
)
Query_GetSelfConsOneStage
(
in
*
types
.
Int64
)
(
types
.
Message
,
error
)
{
func
(
p
*
Paracross
)
Query_GetSelfConsOneStage
(
in
*
types
.
Int64
)
(
types
.
Message
,
error
)
{
_
,
stages
,
err
:=
getSelfConsensStages
(
p
.
GetStateDB
())
stages
,
err
:=
getSelfConsensStages
(
p
.
GetStateDB
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Cause
(
err
)
return
nil
,
errors
.
Cause
(
err
)
}
}
...
...
plugin/dapp/paracross/executor/stage.go
View file @
63d2b2cb
...
@@ -84,43 +84,53 @@ func makeStageGroupReceipt(prev, current *pt.SelfConsensStages) *types.Receipt {
...
@@ -84,43 +84,53 @@ func makeStageGroupReceipt(prev, current *pt.SelfConsensStages) *types.Receipt {
}
}
}
}
func
getSelfConsensStages
(
db
dbm
.
KV
)
(
map
[
int64
]
uint32
,
*
pt
.
SelfConsensStages
,
error
)
{
func
getSelfConsensStages
(
db
dbm
.
KV
)
(
*
pt
.
SelfConsensStages
,
error
)
{
key
:=
calcParaSelfConsStagesKey
()
key
:=
calcParaSelfConsStagesKey
()
item
,
err
:=
db
.
Get
(
key
)
item
,
err
:=
db
.
Get
(
key
)
if
err
!=
nil
{
if
err
!=
nil
{
if
isNotFound
(
err
)
{
if
isNotFound
(
err
)
{
err
=
pt
.
ErrKeyNotExist
err
=
pt
.
ErrKeyNotExist
}
}
return
nil
,
nil
,
errors
.
Wrapf
(
err
,
"getSelfConsensStages key:%s"
,
string
(
key
))
return
nil
,
errors
.
Wrapf
(
err
,
"getSelfConsensStages key:%s"
,
string
(
key
))
}
}
var
config
pt
.
SelfConsensStages
var
config
pt
.
SelfConsensStages
err
=
types
.
Decode
(
item
,
&
config
)
err
=
types
.
Decode
(
item
,
&
config
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
Wrap
(
err
,
"getSelfConsensStages decode config"
)
return
nil
,
errors
.
Wrap
(
err
,
"getSelfConsensStages decode config"
)
}
}
return
&
config
,
nil
}
func
getSelfConsStagesMap
(
stages
[]
*
pt
.
SelfConsensStage
)
map
[
int64
]
uint32
{
stagesMap
:=
make
(
map
[
int64
]
uint32
)
stagesMap
:=
make
(
map
[
int64
]
uint32
)
for
_
,
v
:=
range
config
.
Item
s
{
for
_
,
v
:=
range
stage
s
{
stagesMap
[
v
.
BlockHeight
]
=
v
.
Enable
stagesMap
[
v
.
BlockHeight
]
=
v
.
Enable
}
}
return
stagesMap
}
return
stagesMap
,
&
config
,
nil
func
sortStages
(
stages
*
pt
.
SelfConsensStages
,
new
*
pt
.
SelfConsensStage
)
{
stages
.
Items
=
append
(
stages
.
Items
,
new
)
sort
.
Slice
(
stages
.
Items
,
func
(
i
,
j
int
)
bool
{
return
stages
.
Items
[
i
]
.
BlockHeight
<
stages
.
Items
[
j
]
.
BlockHeight
})
}
}
func
updateStages
(
db
dbm
.
KV
,
stage
*
pt
.
SelfConsensStage
)
(
*
types
.
Receipt
,
error
)
{
func
updateStages
(
db
dbm
.
KV
,
stage
*
pt
.
SelfConsensStage
)
(
*
types
.
Receipt
,
error
)
{
_
,
stages
,
err
:=
getSelfConsensStages
(
db
)
stages
,
err
:=
getSelfConsensStages
(
db
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
oldStages
:=
*
stages
var
old
pt
.
SelfConsensStages
stages
.
Items
=
append
(
stages
.
Items
,
stage
)
err
=
deepCopy
(
&
old
,
stages
)
sort
.
Slice
(
stages
.
Items
,
func
(
i
,
j
int
)
bool
{
return
stages
.
Items
[
i
]
.
BlockHeight
<
stages
.
Items
[
j
]
.
BlockHeight
})
if
err
!=
nil
{
clog
.
Error
(
"updateStages deep copy fail"
,
"copy"
,
old
,
"stat"
,
stages
)
return
makeStageGroupReceipt
(
&
oldStages
,
stages
),
nil
return
nil
,
err
}
sortStages
(
stages
,
stage
)
return
makeStageGroupReceipt
(
&
old
,
stages
),
nil
}
}
func
selfConsensInitStage
(
db
dbm
.
KV
)
*
types
.
Receipt
{
func
selfConsensInitStage
()
*
types
.
Receipt
{
close
:=
types
.
IsEnable
(
"consensus.sub.para.paraSelfConsInitDisable"
)
close
:=
types
.
IsEnable
(
"consensus.sub.para.paraSelfConsInitDisable"
)
stage
:=
&
pt
.
SelfConsensStage
{
BlockHeight
:
0
,
Enable
:
pt
.
ParaConfigYes
}
stage
:=
&
pt
.
SelfConsensStage
{
BlockHeight
:
0
,
Enable
:
pt
.
ParaConfigYes
}
if
close
{
if
close
{
...
@@ -136,23 +146,36 @@ func getSelfConsOneStage(height int64, stages *pt.SelfConsensStages) *pt.SelfCon
...
@@ -136,23 +146,36 @@ func getSelfConsOneStage(height int64, stages *pt.SelfConsensStages) *pt.SelfCon
return
stages
.
Items
[
i
]
return
stages
.
Items
[
i
]
}
}
}
}
clog
.
Error
(
"getSelfConsOneStage height not hit"
,
"height"
,
height
)
return
&
pt
.
SelfConsensStage
{
Enable
:
pt
.
ParaConfigNo
}
return
&
pt
.
SelfConsensStage
{
Enable
:
pt
.
ParaConfigNo
}
}
}
func
isSelfConsOn
(
db
dbm
.
KV
,
height
int64
)
(
bool
,
error
)
{
stages
,
err
:=
getSelfConsensStages
(
db
)
if
err
!=
nil
&&
errors
.
Cause
(
err
)
!=
pt
.
ErrKeyNotExist
{
return
false
,
err
}
if
stages
!=
nil
{
stage
:=
getSelfConsOneStage
(
height
,
stages
)
return
stage
.
Enable
==
pt
.
ParaConfigYes
,
nil
}
return
false
,
nil
}
func
(
a
*
action
)
checkValidStage
(
config
*
pt
.
SelfConsensStage
)
error
{
func
(
a
*
action
)
checkValidStage
(
config
*
pt
.
SelfConsensStage
)
error
{
//1. 设置高度必须大于当前区块高度
//1. 设置高度必须大于当前区块高度
if
config
.
BlockHeight
<=
a
.
height
{
if
config
.
BlockHeight
<=
a
.
height
{
return
errors
.
Wrapf
(
pt
.
ErrHeightHasPast
,
"checkValidStage config height:%d less than block height:%d"
,
config
.
BlockHeight
,
a
.
height
)
return
errors
.
Wrapf
(
pt
.
ErrHeightHasPast
,
"checkValidStage config height:%d less than block height:%d"
,
config
.
BlockHeight
,
a
.
height
)
}
}
//2. 如果已经设置到stages中,简单起见,就不能更改了,应该也不会有很大影响
//2. 如果已经设置到stages中,简单起见,就不能更改了,应该也不会有很大影响
stages
,
_
,
err
:=
getSelfConsensStages
(
a
.
db
)
stages
,
err
:=
getSelfConsensStages
(
a
.
db
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"checkValidStage get stages"
)
return
errors
.
Wrapf
(
err
,
"checkValidStage get stages"
)
}
}
if
_
,
exist
:=
stages
[
config
.
BlockHeight
];
exist
{
stageMap
:=
getSelfConsStagesMap
(
stages
.
Items
)
if
_
,
exist
:=
stageMap
[
config
.
BlockHeight
];
exist
{
return
errors
.
Wrapf
(
err
,
"checkValidStage config height:%d existed"
,
config
.
BlockHeight
)
return
errors
.
Wrapf
(
err
,
"checkValidStage config height:%d existed"
,
config
.
BlockHeight
)
}
}
...
@@ -189,7 +212,7 @@ func (a *action) stageCancel(config *pt.ConfigCancelInfo) (*types.Receipt, error
...
@@ -189,7 +212,7 @@ func (a *action) stageCancel(config *pt.ConfigCancelInfo) (*types.Receipt, error
return
nil
,
errors
.
Wrapf
(
types
.
ErrNotAllow
,
"stage id create by:%s,not by:%s"
,
stat
.
FromAddr
,
a
.
fromaddr
)
return
nil
,
errors
.
Wrapf
(
types
.
ErrNotAllow
,
"stage id create by:%s,not by:%s"
,
stat
.
FromAddr
,
a
.
fromaddr
)
}
}
if
stat
.
Status
!=
pt
.
ParaApplyJoining
{
if
stat
.
Status
!=
pt
.
ParaApplyJoining
&&
stat
.
Status
!=
pt
.
ParaApplyVoting
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeOpStatusWrong
,
"stage config id:%s,status:%d"
,
config
.
Id
,
stat
.
Status
)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeOpStatusWrong
,
"stage config id:%s,status:%d"
,
config
.
Id
,
stat
.
Status
)
}
}
...
@@ -216,10 +239,10 @@ func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
...
@@ -216,10 +239,10 @@ func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
stat
,
err
:=
getStageID
(
a
.
db
,
config
.
Id
)
stat
,
err
:=
getStageID
(
a
.
db
,
config
.
Id
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
Wrapf
(
err
,
"stageVote getStageID:%s"
,
config
.
Id
)
}
}
if
stat
.
Status
!=
pt
.
ParaApplyJoining
{
if
stat
.
Status
!=
pt
.
ParaApplyJoining
&&
stat
.
Status
!=
pt
.
ParaApplyVoting
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeOpStatusWrong
,
"config id:%s,status:%d"
,
config
.
Id
,
stat
.
Status
)
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeOpStatusWrong
,
"config id:%s,status:%d"
,
config
.
Id
,
stat
.
Status
)
}
}
//stage blockHeight 也不能小于当前vote tx height,不然没有意义
//stage blockHeight 也不能小于当前vote tx height,不然没有意义
...
@@ -234,7 +257,7 @@ func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
...
@@ -234,7 +257,7 @@ func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
clog
.
Error
(
"selfConsensVote deep copy fail"
,
"copy"
,
copyStat
,
"stat"
,
stat
)
clog
.
Error
(
"selfConsensVote deep copy fail"
,
"copy"
,
copyStat
,
"stat"
,
stat
)
return
nil
,
err
return
nil
,
err
}
}
stat
.
Status
=
pt
.
ParaApplyVoting
if
stat
.
Votes
==
nil
{
if
stat
.
Votes
==
nil
{
stat
.
Votes
=
&
pt
.
ParaNodeVoteDetail
{}
stat
.
Votes
=
&
pt
.
ParaNodeVoteDetail
{}
}
}
...
@@ -253,13 +276,13 @@ func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
...
@@ -253,13 +276,13 @@ func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
if
!
isCommitDone
(
nodes
,
most
)
{
if
!
isCommitDone
(
nodes
,
most
)
{
return
makeStageConfigReceipt
(
&
copyStat
,
stat
),
nil
return
makeStageConfigReceipt
(
&
copyStat
,
stat
),
nil
}
}
clog
.
Info
(
"paracross.
nod
eVote ----pass"
,
"most"
,
most
,
"pass"
,
vote
)
clog
.
Info
(
"paracross.
stag
eVote ----pass"
,
"most"
,
most
,
"pass"
,
vote
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
if
vote
==
pt
.
ParaVoteYes
{
if
vote
==
pt
.
ParaVoteYes
{
r
,
err
:=
updateStages
(
a
.
db
,
stat
.
Stage
)
r
,
err
:=
updateStages
(
a
.
db
,
stat
.
Stage
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
Wrapf
(
err
,
"stageVote updateStages"
)
}
}
receipt
=
mergeReceipt
(
receipt
,
r
)
receipt
=
mergeReceipt
(
receipt
,
r
)
}
}
...
@@ -279,7 +302,7 @@ func (a *action) SelfStageConfig(config *pt.ParaStageConfig) (*types.Receipt, er
...
@@ -279,7 +302,7 @@ func (a *action) SelfStageConfig(config *pt.ParaStageConfig) (*types.Receipt, er
if
config
.
OpTy
==
pt
.
ParaOpNewApply
{
if
config
.
OpTy
==
pt
.
ParaOpNewApply
{
return
a
.
stageApply
(
config
.
GetStage
())
return
a
.
stageApply
(
config
.
GetStage
())
}
else
if
config
.
OpTy
==
pt
.
ParaOp
Quit
{
}
else
if
config
.
OpTy
==
pt
.
ParaOp
Cancel
{
return
a
.
stageCancel
(
config
.
GetCancel
())
return
a
.
stageCancel
(
config
.
GetCancel
())
}
else
if
config
.
OpTy
==
pt
.
ParaOpVote
{
}
else
if
config
.
OpTy
==
pt
.
ParaOpVote
{
...
...
plugin/dapp/paracross/executor/stagelocaldb.go
View file @
63d2b2cb
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
package
executor
package
executor
import
(
import
(
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
...
@@ -22,7 +23,7 @@ func (e *Paracross) execAutoLocalStage(tx *types.Transaction, receiptData *types
...
@@ -22,7 +23,7 @@ func (e *Paracross) execAutoLocalStage(tx *types.Transaction, receiptData *types
func
(
e
*
Paracross
)
execLocalStage
(
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
e
*
Paracross
)
execLocalStage
(
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
table
:=
NewStageTable
(
e
.
GetLocalDB
())
table
:=
NewStageTable
(
e
.
GetLocalDB
())
txIndex
:=
dapp
.
HeightIndexStr
(
e
.
GetHeight
(),
int64
(
index
))
for
_
,
log
:=
range
receiptData
.
Logs
{
for
_
,
log
:=
range
receiptData
.
Logs
{
switch
log
.
Ty
{
switch
log
.
Ty
{
case
pt
.
TyLogParaSelfConsStageConfig
:
case
pt
.
TyLogParaSelfConsStageConfig
:
...
@@ -32,13 +33,18 @@ func (e *Paracross) execLocalStage(receiptData *types.ReceiptData, index int) (*
...
@@ -32,13 +33,18 @@ func (e *Paracross) execLocalStage(receiptData *types.ReceiptData, index int) (*
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
r
:=
&
pt
.
LocalSelfConsStageInfo
{
if
receipt
.
Current
.
Status
==
pt
.
ParaApplyJoining
{
Stage
:
receipt
.
Current
,
txIndex
:=
dapp
.
HeightIndexStr
(
e
.
GetHeight
(),
int64
(
index
))
TxIndex
:
txIndex
,
r
:=
&
pt
.
LocalSelfConsStageInfo
{
}
Stage
:
receipt
.
Current
,
err
=
table
.
Replace
(
r
)
TxIndex
:
txIndex
,
if
err
!=
nil
{
}
return
nil
,
err
err
=
table
.
Add
(
r
)
if
err
!=
nil
{
return
nil
,
err
}
}
else
{
update
(
table
,
receipt
.
GetCurrent
())
}
}
}
}
default
:
default
:
...
@@ -64,6 +70,22 @@ func (e *Paracross) execAutoDelLocal(tx *types.Transaction, receiptData *types.R
...
@@ -64,6 +70,22 @@ func (e *Paracross) execAutoDelLocal(tx *types.Transaction, receiptData *types.R
return
dbSet
,
nil
return
dbSet
,
nil
}
}
func
update
(
ldb
*
table
.
Table
,
stage
*
pt
.
SelfConsensStageInfo
)
error
{
xs
,
err
:=
ldb
.
ListIndex
(
"id"
,
[]
byte
(
stage
.
Id
),
nil
,
1
,
0
)
if
err
!=
nil
||
len
(
xs
)
!=
1
{
clog
.
Error
(
"SelfStages update query List failed"
,
"key"
,
stage
.
Id
,
"err"
,
err
,
"len"
,
len
(
xs
))
return
nil
}
u
,
ok
:=
xs
[
0
]
.
Data
.
(
*
pt
.
LocalSelfConsStageInfo
)
if
!
ok
{
clog
.
Error
(
"SelfStages update decode failed"
,
"data"
,
xs
[
0
]
.
Data
)
return
nil
}
u
.
Stage
=
stage
return
ldb
.
Update
([]
byte
(
u
.
TxIndex
),
u
)
}
func
(
e
*
Paracross
)
listSelfStages
(
req
*
pt
.
ReqQuerySelfStages
)
(
types
.
Message
,
error
)
{
func
(
e
*
Paracross
)
listSelfStages
(
req
*
pt
.
ReqQuerySelfStages
)
(
types
.
Message
,
error
)
{
if
req
==
nil
{
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
...
@@ -80,33 +102,30 @@ func (e *Paracross) listSelfStages(req *pt.ReqQuerySelfStages) (types.Message, e
...
@@ -80,33 +102,30 @@ func (e *Paracross) listSelfStages(req *pt.ReqQuerySelfStages) (types.Message, e
}
else
if
req
.
Id
!=
""
{
}
else
if
req
.
Id
!=
""
{
indexName
=
"id"
indexName
=
"id"
}
}
cur
:=
&
StageRow
{
cur
:=
&
StageRow
{
LocalSelfConsStageInfo
:
&
pt
.
LocalSelfConsStageInfo
{},
LocalSelfConsStageInfo
:
&
pt
.
LocalSelfConsStageInfo
{
Stage
:
&
pt
.
SelfConsensStageInfo
{}
},
}
}
cur
.
Stage
.
Status
=
req
.
Status
cur
.
Stage
.
Status
=
req
.
Status
cur
.
Stage
.
Id
=
req
.
Id
cur
.
Stage
.
Id
=
calcParaSelfConsensStageIDKey
(
req
.
Id
)
prefix
,
err
:=
cur
.
Get
(
indexName
)
prefix
,
err
:=
cur
.
Get
(
indexName
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"Get"
,
"indexName"
,
indexName
,
"err"
,
err
)
clog
.
Error
(
"
listSelfStages
Get"
,
"indexName"
,
indexName
,
"err"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
rows
,
err
:=
query
.
ListIndex
(
indexName
,
prefix
,
primary
,
req
.
Count
,
req
.
Direction
)
rows
,
err
:=
query
.
ListIndex
(
indexName
,
prefix
,
primary
,
req
.
Count
,
req
.
Direction
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"
query List failed"
,
"indexName"
,
indexName
,
"prefix"
,
"prefix"
,
"key"
,
string
(
primary
),
"err"
,
err
)
clog
.
Error
(
"
listSelfStages query failed"
,
"indexName"
,
indexName
,
"prefix"
,
prefix
,
"key"
,
string
(
primary
),
"err"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
if
len
(
rows
)
==
0
{
if
len
(
rows
)
==
0
{
return
nil
,
types
.
ErrNotFound
return
nil
,
types
.
ErrNotFound
}
}
var
rep
pt
.
ReplyQuerySelfStages
var
rep
pt
.
ReplyQuerySelfStages
for
_
,
row
:=
range
rows
{
for
_
,
row
:=
range
rows
{
r
,
ok
:=
row
.
Data
.
(
*
pt
.
LocalSelfConsStageInfo
)
r
,
ok
:=
row
.
Data
.
(
*
pt
.
LocalSelfConsStageInfo
)
if
!
ok
{
if
!
ok
{
clog
.
Error
(
"list
ProposalProject
"
,
"err"
,
"bad row type"
)
clog
.
Error
(
"list
SelfStages
"
,
"err"
,
"bad row type"
)
return
nil
,
types
.
ErrDecode
return
nil
,
types
.
ErrDecode
}
}
ok
,
txID
,
_
:=
getRealTxHashID
(
r
.
Stage
.
Id
)
ok
,
txID
,
_
:=
getRealTxHashID
(
r
.
Stage
.
Id
)
...
...
plugin/dapp/paracross/executor/stagetable.go
View file @
63d2b2cb
...
@@ -39,7 +39,7 @@ type StageRow struct {
...
@@ -39,7 +39,7 @@ type StageRow struct {
//NewStageRow 新建一个meta 结构
//NewStageRow 新建一个meta 结构
func
NewStageRow
()
*
StageRow
{
func
NewStageRow
()
*
StageRow
{
return
&
StageRow
{
LocalSelfConsStageInfo
:
nil
}
return
&
StageRow
{
LocalSelfConsStageInfo
:
&
pt
.
LocalSelfConsStageInfo
{}
}
}
}
//CreateRow 新建数据行(注意index 数据一定也要保存到数据中,不能就保存heightindex)
//CreateRow 新建数据行(注意index 数据一定也要保存到数据中,不能就保存heightindex)
...
...
plugin/dapp/paracross/executor/superaccount.go
View file @
63d2b2cb
...
@@ -930,7 +930,7 @@ func (a *action) nodeGroupApproveApply(config *pt.ParaNodeGroupConfig, apply *pt
...
@@ -930,7 +930,7 @@ func (a *action) nodeGroupApproveApply(config *pt.ParaNodeGroupConfig, apply *pt
if
types
.
IsPara
()
&&
types
.
IsDappFork
(
a
.
height
,
pt
.
ParaX
,
pt
.
ForkParaSelfConsStages
)
{
if
types
.
IsPara
()
&&
types
.
IsDappFork
(
a
.
height
,
pt
.
ParaX
,
pt
.
ForkParaSelfConsStages
)
{
//不允许主链成功平行链失败导致不一致的情况,这里如果失败则手工设置init stage
//不允许主链成功平行链失败导致不一致的情况,这里如果失败则手工设置init stage
r
=
selfConsensInitStage
(
a
.
db
)
r
=
selfConsensInitStage
()
receipt
.
KV
=
append
(
receipt
.
KV
,
r
.
KV
...
)
receipt
.
KV
=
append
(
receipt
.
KV
,
r
.
KV
...
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
r
.
Logs
...
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
r
.
Logs
...
)
}
}
...
...
plugin/dapp/paracross/proto/paracross.proto
View file @
63d2b2cb
...
@@ -219,9 +219,9 @@ message LocalSelfConsStageInfo {
...
@@ -219,9 +219,9 @@ message LocalSelfConsStageInfo {
message
ConfigVoteInfo
{
message
ConfigVoteInfo
{
string
id
=
1
;
string
id
=
1
;
// 投票值 1:ok 2:nok
// 投票值 1:ok 2:nok
uint32
value
=
2
;
uint32
value
=
2
;
}
}
message
ConfigCancelInfo
{
message
ConfigCancelInfo
{
...
@@ -230,9 +230,9 @@ message ConfigCancelInfo {
...
@@ -230,9 +230,9 @@ message ConfigCancelInfo {
//广义配置类型
//广义配置类型
message
ParaStageConfig
{
message
ParaStageConfig
{
string
title
=
1
;
string
title
=
1
;
// 配置类型
// 配置类型
uint32
opTy
=
2
;
uint32
opTy
=
2
;
oneof
op
{
oneof
op
{
SelfConsensStage
stage
=
10
;
SelfConsensStage
stage
=
10
;
ConfigVoteInfo
vote
=
11
;
ConfigVoteInfo
vote
=
11
;
...
@@ -247,12 +247,12 @@ message ReceiptSelfConsStageConfig {
...
@@ -247,12 +247,12 @@ message ReceiptSelfConsStageConfig {
}
}
message
ReceiptSelfConsStageVoteDone
{
message
ReceiptSelfConsStageVoteDone
{
string
id
=
1
;
string
id
=
1
;
SelfConsensStage
stage
=
2
;
SelfConsensStage
stage
=
2
;
int32
totalNodes
=
3
;
int32
totalNodes
=
3
;
int32
totalVote
=
4
;
int32
totalVote
=
4
;
int32
mostVote
=
5
;
int32
mostVote
=
5
;
string
voteRst
=
6
;
string
voteRst
=
6
;
}
}
message
ReceiptSelfConsStagesUpdate
{
message
ReceiptSelfConsStagesUpdate
{
...
...
plugin/dapp/paracross/types/errors.go
View file @
63d2b2cb
...
@@ -55,4 +55,6 @@ var (
...
@@ -55,4 +55,6 @@ var (
ErrHeightHasPast
=
errors
.
New
(
"ErrHeightHasPast"
)
ErrHeightHasPast
=
errors
.
New
(
"ErrHeightHasPast"
)
// ErrKeyNotExist config key not exist
// ErrKeyNotExist config key not exist
ErrKeyNotExist
=
errors
.
New
(
"ErrKeyNotExist"
)
ErrKeyNotExist
=
errors
.
New
(
"ErrKeyNotExist"
)
// ErrConsensClosed consensus closed
ErrConsensClosed
=
errors
.
New
(
"ErrConsensClosed"
)
)
)
plugin/dapp/paracross/types/paracross.go
View file @
63d2b2cb
...
@@ -128,6 +128,8 @@ const (
...
@@ -128,6 +128,8 @@ const (
ParaApplyClosed
ParaApplyClosed
// ParaApplyCanceled to cancel apply of joining or quiting
// ParaApplyCanceled to cancel apply of joining or quiting
ParaApplyCanceled
ParaApplyCanceled
// ParaApplyVoting record voting status
ParaApplyVoting
)
)
//针对addr本身的生命周期,addr维护了申请id和quit id,方便查询如coinfrozen等额外信息
//针对addr本身的生命周期,addr维护了申请id和quit id,方便查询如coinfrozen等额外信息
...
...
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