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
e9bd0511
Commit
e9bd0511
authored
Aug 29, 2019
by
mdj33
Committed by
vipwzw
Aug 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
multi-version
parent
36fdfd31
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
140 additions
and
45 deletions
+140
-45
chain33.para.toml
chain33.para.toml
+7
-2
para.go
plugin/consensus/para/para.go
+53
-31
para_test.go
plugin/consensus/para/para_test.go
+61
-0
paracreate.go
plugin/consensus/para/paracreate.go
+17
-9
paramultidownload.go
plugin/consensus/para/paramultidownload.go
+1
-2
type.go
plugin/dapp/paracross/types/type.go
+1
-1
No files found.
chain33.para.toml
View file @
e9bd0511
...
...
@@ -101,8 +101,7 @@ ParaRemoteGrpcClient="localhost:8802"
startHeight
=
345850
#打包时间间隔,单位秒
writeBlockSeconds
=
2
#主链每隔几个没有相关交易的区块,平行链上打包空区块
emptyBlockInterval
=
50
#验证账户,验证节点需要配置自己的账户,并且钱包导入对应种子,非验证节点留空
authAccount
=
""
#云端主链节点切换后,平行链适配新主链节点block,回溯查找和自己记录的相同blockhash的深度
...
...
@@ -117,6 +116,12 @@ MainParaSelfConsensusForkHeight=-1
MainLoopCheckCommitTxDoneForkHeight
=
-1
#主链过滤平行链tx
FetchFilterParaTxsEnable
=
-1
#主链每隔几个没有相关平行链交易的区块,平行链上打包空区块,缺省从平行链blockHeight=0开始,依次增长,空块间隔不能为0
[[consensus.sub.para.emptyBlockInterval]]
blockHeight
=
0
intervel
=
50
[store]
name
=
"kvmvccmavl"
...
...
plugin/consensus/para/para.go
View file @
e9bd0511
...
...
@@ -36,7 +36,7 @@ const (
minerPrivateKey
=
"6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
defaultGenesisAmount
int64
=
1e8
poolMainBlockSec
int64
=
5
defaultEmptyBlockInterval
int64
=
4
//write empty block every interval blocks in mainchain
defaultEmptyBlockInterval
int64
=
50
//write empty block every interval blocks in mainchain
defaultSearchMatchedBlockDepth
int32
=
10000
defaultMainBlockHashForkHeight
int64
=
209186
//calc block hash fork height in main chain
mainParaSelfConsensusForkHeight
int64
=
types
.
MaxHeight
//para chain self consensus height switch, must >= ForkParacrossCommitTx of main
...
...
@@ -69,28 +69,33 @@ type client struct {
quitCreate
chan
struct
{}
}
type
emptyBlockInterval
struct
{
BlockHeight
int64
`json:"blockHeight,omitempty"`
Interval
int64
`json:"interval,omitempty"`
}
type
subConfig
struct
{
WriteBlockSeconds
int64
`json:"writeBlockSeconds,omitempty"`
ParaRemoteGrpcClient
string
`json:"paraRemoteGrpcClient,omitempty"`
StartHeight
int64
`json:"startHeight,omitempty"`
EmptyBlockInterval
int64
`json:"emptyBlockInterval,omitempty"`
AuthAccount
string
`json:"authAccount,omitempty"`
WaitBlocks4CommitMsg
int32
`json:"waitBlocks4CommitMsg,omitempty"`
SearchHashMatchedBlockDepth
int32
`json:"searchHashMatchedBlockDepth,omitempty"`
GenesisAmount
int64
`json:"genesisAmount,omitempty"`
MainBlockHashForkHeight
int64
`json:"mainBlockHashForkHeight,omitempty"`
MainParaSelfConsensusForkHeight
int64
`json:"mainParaSelfConsensusForkHeight,omitempty"`
MainForkParacrossCommitTx
int64
`json:"mainForkParacrossCommitTx,omitempty"`
WaitConsensStopTimes
uint32
`json:"waitConsensStopTimes,omitempty"`
MaxCacheCount
int64
`json:"maxCacheCount,omitempty"`
MaxSyncErrCount
int32
`json:"maxSyncErrCount,omitempty"`
FetchFilterParaTxsEnable
uint32
`json:"fetchFilterParaTxsEnable,omitempty"`
BatchFetchBlockCount
int64
`json:"batchFetchBlockCount,omitempty"`
ParaConsensStartHeight
int64
`json:"paraConsensStartHeight,omitempty"`
MultiDownloadOpen
int32
`json:"multiDownloadOpen,omitempty"`
MultiDownInvNumPerJob
int64
`json:"multiDownInvNumPerJob,omitempty"`
MultiDownJobBuffNum
uint32
`json:"multiDownJobBuffNum,omitempty"`
MultiDownServerRspTime
uint32
`json:"multiDownServerRspTime,omitempty"`
WriteBlockSeconds
int64
`json:"writeBlockSeconds,omitempty"`
ParaRemoteGrpcClient
string
`json:"paraRemoteGrpcClient,omitempty"`
StartHeight
int64
`json:"startHeight,omitempty"`
EmptyBlockInterval
[]
*
emptyBlockInterval
`json:"emptyBlockInterval,omitempty"`
AuthAccount
string
`json:"authAccount,omitempty"`
WaitBlocks4CommitMsg
int32
`json:"waitBlocks4CommitMsg,omitempty"`
SearchHashMatchedBlockDepth
int32
`json:"searchHashMatchedBlockDepth,omitempty"`
GenesisAmount
int64
`json:"genesisAmount,omitempty"`
MainBlockHashForkHeight
int64
`json:"mainBlockHashForkHeight,omitempty"`
MainParaSelfConsensusForkHeight
int64
`json:"mainParaSelfConsensusForkHeight,omitempty"`
MainForkParacrossCommitTx
int64
`json:"mainForkParacrossCommitTx,omitempty"`
WaitConsensStopTimes
uint32
`json:"waitConsensStopTimes,omitempty"`
MaxCacheCount
int64
`json:"maxCacheCount,omitempty"`
MaxSyncErrCount
int32
`json:"maxSyncErrCount,omitempty"`
FetchFilterParaTxsEnable
bool
`json:"fetchFilterParaTxsEnable,omitempty"`
BatchFetchBlockCount
int64
`json:"batchFetchBlockCount,omitempty"`
ParaConsensStartHeight
int64
`json:"paraConsensStartHeight,omitempty"`
MultiDownloadOpen
bool
`json:"multiDownloadOpen,omitempty"`
MultiDownInvNumPerJob
int64
`json:"multiDownInvNumPerJob,omitempty"`
MultiDownJobBuffNum
uint32
`json:"multiDownJobBuffNum,omitempty"`
MultiDownServerRspTime
uint32
`json:"multiDownServerRspTime,omitempty"`
}
// New function to init paracross env
...
...
@@ -107,9 +112,15 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
if
subcfg
.
WriteBlockSeconds
<=
0
{
subcfg
.
WriteBlockSeconds
=
poolMainBlockSec
}
if
subcfg
.
EmptyBlockInterval
<=
0
{
subcfg
.
EmptyBlockInterval
=
defaultEmptyBlockInterval
if
len
(
subcfg
.
EmptyBlockInterval
)
==
0
{
interval
:=
&
emptyBlockInterval
{
Interval
:
defaultEmptyBlockInterval
}
subcfg
.
EmptyBlockInterval
=
append
(
subcfg
.
EmptyBlockInterval
,
interval
)
}
err
:=
checkEmptyBlockInterval
(
subcfg
.
EmptyBlockInterval
)
if
err
!=
nil
{
panic
(
"para EmptyBlockInterval config not correct"
)
}
if
subcfg
.
SearchHashMatchedBlockDepth
<=
0
{
subcfg
.
SearchHashMatchedBlockDepth
=
defaultSearchMatchedBlockDepth
}
...
...
@@ -125,10 +136,6 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
subcfg
.
MainForkParacrossCommitTx
=
mainForkParacrossCommitTx
}
if
subcfg
.
FetchFilterParaTxsEnable
>
0
{
fetchFilterParaTxsEnable
=
true
}
if
subcfg
.
BatchFetchBlockCount
<=
0
{
subcfg
.
BatchFetchBlockCount
=
types
.
MaxBlockCountPerTime
}
...
...
@@ -213,9 +220,6 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
if
subcfg
.
MultiDownJobBuffNum
>
0
{
para
.
multiDldCli
.
jobBufferNum
=
subcfg
.
MultiDownJobBuffNum
}
if
subcfg
.
MultiDownloadOpen
>
0
{
para
.
multiDldCli
.
multiDldOpen
=
true
}
if
subcfg
.
MultiDownServerRspTime
>
0
{
para
.
multiDldCli
.
serverTimeout
=
subcfg
.
MultiDownServerRspTime
...
...
@@ -225,6 +229,24 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
return
para
}
func
checkEmptyBlockInterval
(
in
[]
*
emptyBlockInterval
)
error
{
for
i
:=
0
;
i
<
len
(
in
);
i
++
{
if
i
==
0
&&
in
[
i
]
.
BlockHeight
!=
0
{
plog
.
Error
(
"EmptyBlockInterval,first blockHeight should be 0"
,
"height"
,
in
[
i
]
.
BlockHeight
)
return
types
.
ErrInvalidParam
}
if
i
>
0
&&
in
[
i
]
.
BlockHeight
<=
in
[
i
-
1
]
.
BlockHeight
{
plog
.
Error
(
"EmptyBlockInterval,blockHeight should be sequence"
,
"preHeight"
,
in
[
i
-
1
]
.
BlockHeight
,
"laterHeight"
,
in
[
i
]
.
BlockHeight
)
return
types
.
ErrInvalidParam
}
if
in
[
i
]
.
Interval
<=
0
{
plog
.
Error
(
"EmptyBlockInterval,interval should big than 0"
,
"height"
,
in
[
i
]
.
BlockHeight
)
return
types
.
ErrInvalidParam
}
}
return
nil
}
//para 不检查任何的交易
func
(
client
*
client
)
CheckBlock
(
parent
*
types
.
Block
,
current
*
types
.
BlockDetail
)
error
{
err
:=
checkMinerTx
(
current
)
...
...
plugin/consensus/para/para_test.go
View file @
e9bd0511
...
...
@@ -219,3 +219,64 @@ func TestGetLastBlockInfo(t *testing.T) {
assert
.
Equal
(
t
,
int64
(
10
),
mainSeq
)
assert
.
Equal
(
t
,
lastBlock
.
Height
,
block
.
Height
)
}
func
TestGetEmptyInterval
(
t
*
testing
.
T
)
{
int1
:=
&
emptyBlockInterval
{
BlockHeight
:
0
,
Interval
:
1
}
int2
:=
&
emptyBlockInterval
{
BlockHeight
:
10
,
Interval
:
10
}
int3
:=
&
emptyBlockInterval
{
BlockHeight
:
15
,
Interval
:
15
}
ints
:=
[]
*
emptyBlockInterval
{
int1
,
int2
,
int3
}
para
:=
new
(
client
)
para
.
subCfg
=
&
subConfig
{
EmptyBlockInterval
:
ints
}
lastBlock
:=
&
pt
.
ParaLocalDbBlock
{
Height
:
1
}
ret
:=
para
.
getEmptyInterval
(
lastBlock
)
assert
.
Equal
(
t
,
int1
.
Interval
,
ret
)
lastBlock
=
&
pt
.
ParaLocalDbBlock
{
Height
:
10
}
ret
=
para
.
getEmptyInterval
(
lastBlock
)
assert
.
Equal
(
t
,
int2
.
Interval
,
ret
)
lastBlock
=
&
pt
.
ParaLocalDbBlock
{
Height
:
11
}
ret
=
para
.
getEmptyInterval
(
lastBlock
)
assert
.
Equal
(
t
,
int2
.
Interval
,
ret
)
lastBlock
=
&
pt
.
ParaLocalDbBlock
{
Height
:
16
}
ret
=
para
.
getEmptyInterval
(
lastBlock
)
assert
.
Equal
(
t
,
int3
.
Interval
,
ret
)
}
func
TestCheckEmptyInterval
(
t
*
testing
.
T
)
{
int1
:=
&
emptyBlockInterval
{
BlockHeight
:
0
,
Interval
:
1
}
int2
:=
&
emptyBlockInterval
{
BlockHeight
:
10
,
Interval
:
10
}
int3
:=
&
emptyBlockInterval
{
BlockHeight
:
15
,
Interval
:
15
}
int1
.
BlockHeight
=
5
ints
:=
[]
*
emptyBlockInterval
{
int1
,
int2
,
int3
}
err
:=
checkEmptyBlockInterval
(
ints
)
assert
.
Equal
(
t
,
types
.
ErrInvalidParam
,
err
)
int1
.
BlockHeight
=
0
int3
.
BlockHeight
=
5
ints
=
[]
*
emptyBlockInterval
{
int1
,
int2
,
int3
}
err
=
checkEmptyBlockInterval
(
ints
)
assert
.
Equal
(
t
,
types
.
ErrInvalidParam
,
err
)
int3
.
BlockHeight
=
10
ints
=
[]
*
emptyBlockInterval
{
int1
,
int2
,
int3
}
err
=
checkEmptyBlockInterval
(
ints
)
assert
.
Equal
(
t
,
types
.
ErrInvalidParam
,
err
)
int3
.
BlockHeight
=
15
int2
.
Interval
=
0
ints
=
[]
*
emptyBlockInterval
{
int1
,
int2
,
int3
}
err
=
checkEmptyBlockInterval
(
ints
)
assert
.
Equal
(
t
,
types
.
ErrInvalidParam
,
err
)
int2
.
Interval
=
2
ints
=
[]
*
emptyBlockInterval
{
int1
,
int2
,
int3
}
err
=
checkEmptyBlockInterval
(
ints
)
assert
.
Equal
(
t
,
nil
,
err
)
}
plugin/consensus/para/paracreate.go
View file @
e9bd0511
...
...
@@ -13,16 +13,14 @@ import (
"sync/atomic"
"fmt"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/types"
paraexec
"github.com/33cn/plugin/plugin/dapp/paracross/executor"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
)
var
(
fetchFilterParaTxsEnable
bool
)
func
(
client
*
client
)
addLocalBlock
(
height
int64
,
block
*
pt
.
ParaLocalDbBlock
)
error
{
set
:=
&
types
.
LocalDBSet
{}
...
...
@@ -316,12 +314,12 @@ func (client *client) getBatchSeqCount(currSeq int64) (int64, error) {
}
if
lastSeq
>
currSeq
{
if
lastSeq
-
currSeq
>
client
.
subCfg
.
EmptyBlockInterval
{
if
lastSeq
-
currSeq
>
client
.
subCfg
.
EmptyBlockInterval
[
0
]
.
Interval
{
atomic
.
StoreInt32
(
&
client
.
caughtUp
,
0
)
}
else
{
atomic
.
StoreInt32
(
&
client
.
caughtUp
,
1
)
}
if
f
etchFilterParaTxsEnable
&&
lastSeq
-
currSeq
>
client
.
subCfg
.
BatchFetchBlockCount
{
if
client
.
subCfg
.
F
etchFilterParaTxsEnable
&&
lastSeq
-
currSeq
>
client
.
subCfg
.
BatchFetchBlockCount
{
return
client
.
subCfg
.
BatchFetchBlockCount
-
1
,
nil
}
return
0
,
nil
...
...
@@ -435,7 +433,7 @@ func (client *client) requestFilterParaTxs(currSeq int64, count int64, preMainBl
}
func
(
client
*
client
)
RequestTx
(
currSeq
int64
,
count
int64
,
preMainBlockHash
[]
byte
)
(
*
types
.
ParaTxDetails
,
error
)
{
if
f
etchFilterParaTxsEnable
{
if
client
.
subCfg
.
F
etchFilterParaTxsEnable
{
return
client
.
requestFilterParaTxs
(
currSeq
,
count
,
preMainBlockHash
)
}
...
...
@@ -452,6 +450,15 @@ func (client *client) processHashNotMatchError(currSeq int64, lastSeqMainHash []
return
currSeq
,
lastSeqMainHash
,
err
}
func
(
client
*
client
)
getEmptyInterval
(
lastBlock
*
pt
.
ParaLocalDbBlock
)
int64
{
for
i
:=
len
(
client
.
subCfg
.
EmptyBlockInterval
)
-
1
;
i
>=
0
;
i
--
{
if
lastBlock
.
Height
>=
client
.
subCfg
.
EmptyBlockInterval
[
i
]
.
BlockHeight
{
return
client
.
subCfg
.
EmptyBlockInterval
[
i
]
.
Interval
}
}
panic
(
fmt
.
Sprintf
(
"emptyBlockInterval not set for height=%d"
,
lastBlock
.
Height
))
}
func
(
client
*
client
)
procLocalBlock
(
mainBlock
*
types
.
ParaTxDetail
)
(
bool
,
error
)
{
lastSeqMainHeight
:=
mainBlock
.
Header
.
Height
...
...
@@ -460,12 +467,13 @@ func (client *client) procLocalBlock(mainBlock *types.ParaTxDetail) (bool, error
plog
.
Error
(
"Parachain getLastLocalBlock"
,
"err"
,
err
)
return
false
,
err
}
emptyInterval
:=
client
.
getEmptyInterval
(
lastBlock
)
txs
:=
paraexec
.
FilterTxsForPara
(
mainBlock
)
plog
.
Info
(
"Parachain process block"
,
"lastBlockHeight"
,
lastBlock
.
Height
,
"lastBlockMainHeight"
,
lastBlock
.
MainHeight
,
"lastBlockMainHash"
,
common
.
ToHex
(
lastBlock
.
MainHash
),
"currMainHeight"
,
lastSeqMainHeight
,
"curMainHash"
,
common
.
ToHex
(
mainBlock
.
Header
.
Hash
),
"seqTy"
,
mainBlock
.
Type
)
"curMainHash"
,
common
.
ToHex
(
mainBlock
.
Header
.
Hash
),
"
emptyIntval"
,
emptyInterval
,
"
seqTy"
,
mainBlock
.
Type
)
if
mainBlock
.
Type
==
types
.
DelBlock
{
if
len
(
txs
)
==
0
{
...
...
@@ -479,7 +487,7 @@ func (client *client) procLocalBlock(mainBlock *types.ParaTxDetail) (bool, error
}
//AddAct
if
len
(
txs
)
==
0
{
if
lastSeqMainHeight
-
lastBlock
.
MainHeight
<
client
.
subCfg
.
EmptyBlock
Interval
{
if
lastSeqMainHeight
-
lastBlock
.
MainHeight
<
empty
Interval
{
return
false
,
nil
}
plog
.
Info
(
"Create empty block"
,
"newHeight"
,
lastBlock
.
Height
+
1
)
...
...
plugin/consensus/para/paramultidownload.go
View file @
e9bd0511
...
...
@@ -64,7 +64,6 @@ type multiDldClient struct {
serverTimeout
uint32
conns
[]
*
connectCli
connsCheckDone
bool
multiDldOpen
bool
wg
sync
.
WaitGroup
mtx
sync
.
Mutex
}
...
...
@@ -157,7 +156,7 @@ func (m *multiDldClient) getConns(inv *inventory) error {
}
func
(
m
*
multiDldClient
)
tryMultiServerDownload
()
{
if
!
m
.
multiDl
dOpen
{
if
!
m
.
paraClient
.
subCfg
.
MultiDownloa
dOpen
{
return
}
...
...
plugin/dapp/paracross/types/type.go
View file @
e9bd0511
...
...
@@ -35,7 +35,7 @@ func init() {
types
.
RegisterDappFork
(
ParaX
,
"Enable"
,
0
)
types
.
RegisterDappFork
(
ParaX
,
"ForkParacrossWithdrawFromParachain"
,
1298600
)
types
.
RegisterDappFork
(
ParaX
,
ForkCommitTx
,
1850000
)
types
.
RegisterDappFork
(
ParaX
,
ForkLoopCheckCommitTxDone
,
types
.
MaxHeight
)
types
.
RegisterDappFork
(
ParaX
,
ForkLoopCheckCommitTxDone
,
3230000
)
}
// GetExecName get para exec name
...
...
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