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
017bcf9e
Commit
017bcf9e
authored
Aug 05, 2019
by
mdj33
Committed by
vipwzw
Aug 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit review
parent
2e57d4c1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
84 additions
and
84 deletions
+84
-84
para.go
plugin/consensus/para/para.go
+49
-52
para_test.go
plugin/consensus/para/para_test.go
+4
-1
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+8
-9
paracreate.go
plugin/consensus/para/paracreate.go
+13
-9
pararpc.go
plugin/consensus/para/pararpc.go
+2
-2
parasync.go
plugin/consensus/para/parasync.go
+1
-1
paratxrequest_test.go
plugin/consensus/para/paratxrequest_test.go
+7
-10
No files found.
plugin/consensus/para/para.go
View file @
017bcf9e
...
@@ -32,26 +32,25 @@ const (
...
@@ -32,26 +32,25 @@ const (
delAct
int64
=
2
//reference blockstore.go, del para block action
delAct
int64
=
2
//reference blockstore.go, del para block action
minBlockNum
=
100
//min block number startHeight before lastHeight in mainchain
minBlockNum
=
100
//min block number startHeight before lastHeight in mainchain
)
var
(
genesisBlockTime
int64
=
1514533390
plog
=
log
.
New
(
"module"
,
"para"
)
grpcSite
=
"localhost:8802"
genesisBlockTime
int64
=
1514533390
startHeight
int64
//parachain sync from startHeight in mainchain
blockSec
int64
=
5
//write block interval, second
emptyBlockInterval
int64
=
4
//write empty block every interval blocks in mainchain
zeroHash
[
32
]
byte
//current miner tx take any privatekey for unify all nodes sign purpose, and para chain is free
//current miner tx take any privatekey for unify all nodes sign purpose, and para chain is free
minerPrivateKey
=
"6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
minerPrivateKey
=
"6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
searchHashMatchDepth
int32
=
100
defaultGenesisAmount
int64
=
1e8
mainBlockHashForkHeight
int64
=
209186
//calc block hash fork height in main chain
poolMainBlockSec
int64
=
5
defaultEmptyBlockInterval
int64
=
4
//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
mainParaSelfConsensusForkHeight
int64
=
types
.
MaxHeight
//para chain self consensus height switch, must >= ForkParacrossCommitTx of main
mainForkParacrossCommitTx
int64
=
types
.
MaxHeight
//support paracross commit tx fork height in main chain: ForkParacrossCommitTx
mainForkParacrossCommitTx
int64
=
types
.
MaxHeight
//support paracross commit tx fork height in main chain: ForkParacrossCommitTx
fetchFilterParaTxsEnable
bool
batchFetchBlockCount
int64
=
128
batchFetchBlockCount
int64
=
128
)
)
var
(
plog
=
log
.
New
(
"module"
,
"para"
)
zeroHash
[
32
]
byte
)
func
init
()
{
func
init
()
{
drivers
.
Reg
(
"para"
,
New
)
drivers
.
Reg
(
"para"
,
New
)
drivers
.
QueryData
.
Register
(
"para"
,
&
client
{})
drivers
.
QueryData
.
Register
(
"para"
,
&
client
{})
...
@@ -99,41 +98,36 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
...
@@ -99,41 +98,36 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
types
.
MustDecode
(
sub
,
&
subcfg
)
types
.
MustDecode
(
sub
,
&
subcfg
)
}
}
if
subcfg
.
GenesisAmount
<=
0
{
if
subcfg
.
GenesisAmount
<=
0
{
subcfg
.
GenesisAmount
=
1e8
subcfg
.
GenesisAmount
=
defaultGenesisAmount
}
if
subcfg
.
ParaRemoteGrpcClient
!=
""
{
grpcSite
=
subcfg
.
ParaRemoteGrpcClient
}
}
if
subcfg
.
StartHeight
>
0
{
startHeight
=
subcfg
.
StartHeight
if
subcfg
.
WriteBlockSeconds
<=
0
{
}
subcfg
.
WriteBlockSeconds
=
poolMainBlockSec
if
subcfg
.
WriteBlockSeconds
>
0
{
blockSec
=
subcfg
.
WriteBlockSeconds
}
}
if
subcfg
.
EmptyBlockInterval
>
0
{
if
subcfg
.
EmptyBlockInterval
<=
0
{
emptyBlockInterval
=
subcfg
.
EmptyBlockInterval
subcfg
.
EmptyBlockInterval
=
default
EmptyBlockInterval
}
}
if
subcfg
.
SearchHashMatchedBlockDepth
>
0
{
if
subcfg
.
SearchHashMatchedBlockDepth
<=
0
{
s
earchHashMatchDepth
=
subcfg
.
SearchHas
hMatchedBlockDepth
s
ubcfg
.
SearchHashMatchedBlockDepth
=
defaultSearc
hMatchedBlockDepth
}
}
if
subcfg
.
MainBlockHashForkHeight
>
0
{
if
subcfg
.
MainBlockHashForkHeight
<=
0
{
mainBlockHashForkHeight
=
subcfg
.
MainBlockHashForkHeight
subcfg
.
MainBlockHashForkHeight
=
default
MainBlockHashForkHeight
}
}
if
subcfg
.
MainParaSelfConsensusForkHeight
>
0
{
if
subcfg
.
MainParaSelfConsensusForkHeight
<=
0
{
mainParaSelfConsensusForkHeight
=
subcfg
.
M
ainParaSelfConsensusForkHeight
subcfg
.
MainParaSelfConsensusForkHeight
=
m
ainParaSelfConsensusForkHeight
}
}
if
subcfg
.
MainForkParacrossCommitTx
>
0
{
if
subcfg
.
MainForkParacrossCommitTx
<=
0
{
mainForkParacrossCommitTx
=
subcfg
.
M
ainForkParacrossCommitTx
subcfg
.
MainForkParacrossCommitTx
=
m
ainForkParacrossCommitTx
}
}
if
subcfg
.
FetchFilterParaTxsEnable
>
0
{
if
subcfg
.
FetchFilterParaTxsEnable
>
0
{
fetchFilterParaTxsEnable
=
true
fetchFilterParaTxsEnable
=
true
}
}
if
subcfg
.
BatchFetchBlockCount
>
0
{
if
subcfg
.
BatchFetchBlockCount
<=
0
{
batchFetchBlockCount
=
subcfg
.
B
atchFetchBlockCount
subcfg
.
BatchFetchBlockCount
=
b
atchFetchBlockCount
}
}
pk
,
err
:=
hex
.
DecodeString
(
minerPrivateKey
)
pk
,
err
:=
hex
.
DecodeString
(
minerPrivateKey
)
...
@@ -163,26 +157,25 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
...
@@ -163,26 +157,25 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
quitCreate
:
make
(
chan
struct
{}),
quitCreate
:
make
(
chan
struct
{}),
}
}
waitBlocks
:=
int32
(
3
)
//缺省是3
if
subcfg
.
WaitBlocks4CommitMsg
>
0
{
waitBlocks
=
subcfg
.
WaitBlocks4CommitMsg
}
waitConsensTimes
:=
uint32
(
30
)
//30*10s = 5min
if
subcfg
.
WaitConsensStopTimes
>
0
{
waitConsensTimes
=
subcfg
.
WaitConsensStopTimes
}
para
.
commitMsgClient
=
&
commitMsgClient
{
para
.
commitMsgClient
=
&
commitMsgClient
{
paraClient
:
para
,
paraClient
:
para
,
waitMainBlocks
:
waitBlocks
,
waitMainBlocks
:
waitBlocks
4CommitMsg
,
waitConsensStopTimes
:
waitConsensTimes
,
waitConsensStopTimes
:
waitConsens
Stop
Times
,
consensHeight
:
-
2
,
consensHeight
:
-
2
,
sendingHeight
:
-
1
,
sendingHeight
:
-
1
,
consensStartHeight
:
-
1
,
consensStartHeight
:
-
1
,
resetCh
:
make
(
chan
interface
{},
1
),
resetCh
:
make
(
chan
interface
{},
1
),
quit
:
make
(
chan
struct
{}),
quit
:
make
(
chan
struct
{}),
}
}
if
subcfg
.
WaitBlocks4CommitMsg
>
0
{
para
.
commitMsgClient
.
waitMainBlocks
=
subcfg
.
WaitBlocks4CommitMsg
}
if
subcfg
.
WaitConsensStopTimes
>
0
{
para
.
commitMsgClient
.
waitConsensStopTimes
=
subcfg
.
WaitConsensStopTimes
}
// 设置平行链共识起始高度,在共识高度为-1也就是从未共识过的环境中允许从设置的非0起始高度开始共识
//note:只有在主链LoopCheckCommitTxDoneForkHeight之后才支持设置ParaConsensStartHeight
//note:只有在主链LoopCheckCommitTxDoneForkHeight之后才支持设置ParaConsensStartHeight
if
subcfg
.
ParaConsensStartHeight
>
0
{
if
subcfg
.
ParaConsensStartHeight
>
0
{
para
.
commitMsgClient
.
consensStartHeight
=
subcfg
.
ParaConsensStartHeight
-
1
para
.
commitMsgClient
.
consensStartHeight
=
subcfg
.
ParaConsensStartHeight
-
1
...
@@ -247,18 +240,18 @@ func (client *client) InitBlock() {
...
@@ -247,18 +240,18 @@ func (client *client) InitBlock() {
}
}
if
block
==
nil
{
if
block
==
nil
{
if
s
tartHeight
<=
0
{
if
client
.
subCfg
.
S
tartHeight
<=
0
{
panic
(
fmt
.
Sprintf
(
"startHeight(%d) should be more than 0 in mainchain"
,
s
tartHeight
))
panic
(
fmt
.
Sprintf
(
"startHeight(%d) should be more than 0 in mainchain"
,
client
.
subCfg
.
S
tartHeight
))
}
}
//平行链创世区块对应主链hash为startHeight-1的那个block的hash
//平行链创世区块对应主链hash为startHeight-1的那个block的hash
mainHash
:=
client
.
GetStartMainHash
(
s
tartHeight
-
1
)
mainHash
:=
client
.
GetStartMainHash
(
client
.
subCfg
.
S
tartHeight
-
1
)
// 创世区块
// 创世区块
newblock
:=
&
types
.
Block
{}
newblock
:=
&
types
.
Block
{}
newblock
.
Height
=
0
newblock
.
Height
=
0
newblock
.
BlockTime
=
genesisBlockTime
newblock
.
BlockTime
=
genesisBlockTime
newblock
.
ParentHash
=
zeroHash
[
:
]
newblock
.
ParentHash
=
zeroHash
[
:
]
newblock
.
MainHash
=
mainHash
newblock
.
MainHash
=
mainHash
newblock
.
MainHeight
=
s
tartHeight
-
1
newblock
.
MainHeight
=
client
.
subCfg
.
S
tartHeight
-
1
tx
:=
client
.
CreateGenesisTx
()
tx
:=
client
.
CreateGenesisTx
()
newblock
.
Txs
=
tx
newblock
.
Txs
=
tx
newblock
.
TxHash
=
merkle
.
CalcMerkleRoot
(
newblock
.
Txs
)
newblock
.
TxHash
=
merkle
.
CalcMerkleRoot
(
newblock
.
Txs
)
...
@@ -275,8 +268,8 @@ func (client *client) InitBlock() {
...
@@ -275,8 +268,8 @@ func (client *client) InitBlock() {
client
.
SetCurrentBlock
(
block
)
client
.
SetCurrentBlock
(
block
)
}
}
plog
.
Debug
(
"para consensus init parameter"
,
"mainBlockHashForkHeight"
,
m
ainBlockHashForkHeight
)
plog
.
Debug
(
"para consensus init parameter"
,
"mainBlockHashForkHeight"
,
client
.
subCfg
.
M
ainBlockHashForkHeight
)
plog
.
Debug
(
"para consensus init parameter"
,
"mainParaSelfConsensusForkHeight"
,
m
ainParaSelfConsensusForkHeight
)
plog
.
Debug
(
"para consensus init parameter"
,
"mainParaSelfConsensusForkHeight"
,
client
.
subCfg
.
M
ainParaSelfConsensusForkHeight
)
}
}
...
@@ -291,7 +284,7 @@ func (client *client) GetStartMainHash(height int64) []byte {
...
@@ -291,7 +284,7 @@ func (client *client) GetStartMainHash(height int64) []byte {
}
}
if
height
>
0
{
if
height
>
0
{
hint
:=
time
.
NewTicker
(
5
*
time
.
Second
)
hint
:=
time
.
NewTicker
(
time
.
Second
*
time
.
Duration
(
client
.
subCfg
.
WriteBlockSeconds
)
)
for
lastHeight
<
height
+
minBlockNum
{
for
lastHeight
<
height
+
minBlockNum
{
select
{
select
{
case
<-
hint
.
C
:
case
<-
hint
.
C
:
...
@@ -329,6 +322,10 @@ func (client *client) CreateGenesisTx() (ret []*types.Transaction) {
...
@@ -329,6 +322,10 @@ func (client *client) CreateGenesisTx() (ret []*types.Transaction) {
return
return
}
}
func
(
client
*
client
)
isParaSelfConsensusForked
(
height
int64
)
bool
{
return
height
>
client
.
subCfg
.
MainParaSelfConsensusForkHeight
}
func
(
client
*
client
)
ProcEvent
(
msg
*
queue
.
Message
)
bool
{
func
(
client
*
client
)
ProcEvent
(
msg
*
queue
.
Message
)
bool
{
return
false
return
false
}
}
...
...
plugin/consensus/para/para_test.go
View file @
017bcf9e
...
@@ -190,7 +190,6 @@ func TestAddMinerTx(t *testing.T) {
...
@@ -190,7 +190,6 @@ func TestAddMinerTx(t *testing.T) {
priKey
,
err
:=
secp
.
PrivKeyFromBytes
(
pk
)
priKey
,
err
:=
secp
.
PrivKeyFromBytes
(
pk
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
mainForkParacrossCommitTx
=
1
block
:=
&
types
.
Block
{}
block
:=
&
types
.
Block
{}
_
,
filterTxs
,
_
:=
createTestTxs
(
t
)
_
,
filterTxs
,
_
:=
createTestTxs
(
t
)
...
@@ -200,7 +199,11 @@ func TestAddMinerTx(t *testing.T) {
...
@@ -200,7 +199,11 @@ func TestAddMinerTx(t *testing.T) {
MainHash
:
[]
byte
(
"mainhash"
),
MainHash
:
[]
byte
(
"mainhash"
),
Txs
:
filterTxs
}
Txs
:
filterTxs
}
para
:=
new
(
client
)
para
:=
new
(
client
)
para
.
subCfg
=
new
(
subConfig
)
para
.
privateKey
=
priKey
para
.
privateKey
=
priKey
para
.
commitMsgClient
=
new
(
commitMsgClient
)
para
.
commitMsgClient
.
paraClient
=
para
para
.
blockSyncClient
=
new
(
BlockSyncClient
)
para
.
blockSyncClient
=
new
(
BlockSyncClient
)
para
.
blockSyncClient
.
paraClient
=
para
para
.
blockSyncClient
.
paraClient
=
para
para
.
blockSyncClient
.
addMinerTx
(
nil
,
block
,
localBlock
)
para
.
blockSyncClient
.
addMinerTx
(
nil
,
block
,
localBlock
)
...
...
plugin/consensus/para/paracommitmsg.go
View file @
017bcf9e
...
@@ -25,9 +25,12 @@ import (
...
@@ -25,9 +25,12 @@ import (
"github.com/pkg/errors"
"github.com/pkg/errors"
)
)
var
(
const
(
consensusInterval
=
10
//about 1 new block interval
consensusInterval
=
10
//about 1 new block interval
minerInterval
=
10
//5s的主块间隔后分叉概率增加,10s可以消除一些分叉回退
minerInterval
=
10
//5s的主块间隔后分叉概率增加,10s可以消除一些分叉回退
waitBlocks4CommitMsg
int32
=
3
waitConsensStopTimes
uint32
=
30
//30*10s = 5min
)
)
type
commitMsgClient
struct
{
type
commitMsgClient
struct
{
...
@@ -393,7 +396,7 @@ func (client *commitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNod
...
@@ -393,7 +396,7 @@ func (client *commitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNod
var
rawTxs
types
.
Transactions
var
rawTxs
types
.
Transactions
for
_
,
status
:=
range
notifications
{
for
_
,
status
:=
range
notifications
{
execName
:=
pt
.
ParaX
execName
:=
pt
.
ParaX
if
isParaSelfConsensusForked
(
status
.
MainBlockHeight
)
{
if
client
.
paraClient
.
isParaSelfConsensusForked
(
status
.
MainBlockHeight
)
{
execName
=
paracross
.
GetExecName
()
execName
=
paracross
.
GetExecName
()
}
}
tx
,
err
:=
paracross
.
CreateRawCommitTx4MainChain
(
status
,
execName
,
feeRate
)
tx
,
err
:=
paracross
.
CreateRawCommitTx4MainChain
(
status
,
execName
,
feeRate
)
...
@@ -413,7 +416,7 @@ func (client *commitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNod
...
@@ -413,7 +416,7 @@ func (client *commitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNod
func
(
client
*
commitMsgClient
)
singleCalcTx
(
status
*
pt
.
ParacrossNodeStatus
,
feeRate
int64
)
(
*
types
.
Transaction
,
error
)
{
func
(
client
*
commitMsgClient
)
singleCalcTx
(
status
*
pt
.
ParacrossNodeStatus
,
feeRate
int64
)
(
*
types
.
Transaction
,
error
)
{
execName
:=
pt
.
ParaX
execName
:=
pt
.
ParaX
if
isParaSelfConsensusForked
(
status
.
MainBlockHeight
)
{
if
client
.
paraClient
.
isParaSelfConsensusForked
(
status
.
MainBlockHeight
)
{
execName
=
paracross
.
GetExecName
()
execName
=
paracross
.
GetExecName
()
}
}
tx
,
err
:=
paracross
.
CreateRawCommitTx4MainChain
(
status
,
execName
,
feeRate
)
tx
,
err
:=
paracross
.
CreateRawCommitTx4MainChain
(
status
,
execName
,
feeRate
)
...
@@ -498,10 +501,6 @@ out:
...
@@ -498,10 +501,6 @@ out:
client
.
paraClient
.
wg
.
Done
()
client
.
paraClient
.
wg
.
Done
()
}
}
func
isParaSelfConsensusForked
(
height
int64
)
bool
{
return
height
>
mainParaSelfConsensusForkHeight
}
//当前未考虑获取key非常多失败的场景, 如果获取height非常多,block模块会比较大,但是使用完了就释放了
//当前未考虑获取key非常多失败的场景, 如果获取height非常多,block模块会比较大,但是使用完了就释放了
//如果有必要也可以考虑每次最多取20个一个txgroup,发送共识部分循环获取发送也没问题
//如果有必要也可以考虑每次最多取20个一个txgroup,发送共识部分循环获取发送也没问题
func
(
client
*
commitMsgClient
)
getNodeStatus
(
start
,
end
int64
)
([]
*
pt
.
ParacrossNodeStatus
,
error
)
{
func
(
client
*
commitMsgClient
)
getNodeStatus
(
start
,
end
int64
)
([]
*
pt
.
ParacrossNodeStatus
,
error
)
{
...
@@ -705,7 +704,7 @@ func (client *commitMsgClient) getSelfConsensusStatus() (*pt.ParacrossStatus, er
...
@@ -705,7 +704,7 @@ func (client *commitMsgClient) getSelfConsensusStatus() (*pt.ParacrossStatus, er
return
nil
,
err
return
nil
,
err
}
}
if
isParaSelfConsensusForked
(
block
.
MainHeight
)
{
if
client
.
paraClient
.
isParaSelfConsensusForked
(
block
.
MainHeight
)
{
//从本地查询共识高度
//从本地查询共识高度
ret
,
err
:=
client
.
paraClient
.
GetAPI
()
.
QueryChain
(
&
types
.
ChainExecutor
{
ret
,
err
:=
client
.
paraClient
.
GetAPI
()
.
QueryChain
(
&
types
.
ChainExecutor
{
Driver
:
"paracross"
,
Driver
:
"paracross"
,
...
@@ -736,7 +735,7 @@ func (client *commitMsgClient) getSelfConsensusStatus() (*pt.ParacrossStatus, er
...
@@ -736,7 +735,7 @@ func (client *commitMsgClient) getSelfConsensusStatus() (*pt.ParacrossStatus, er
}
}
//本地共识高度对应主链高度一定要高于自共识高度,为了适配平行链共识高度不连续场景
//本地共识高度对应主链高度一定要高于自共识高度,为了适配平行链共识高度不连续场景
if
isParaSelfConsensusForked
(
statusMainHeight
)
{
if
client
.
paraClient
.
isParaSelfConsensusForked
(
statusMainHeight
)
{
return
resp
,
nil
return
resp
,
nil
}
}
}
}
...
...
plugin/consensus/para/paracreate.go
View file @
017bcf9e
...
@@ -19,6 +19,10 @@ import (
...
@@ -19,6 +19,10 @@ import (
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
)
)
var
(
fetchFilterParaTxsEnable
bool
)
func
(
client
*
client
)
addLocalBlock
(
height
int64
,
block
*
pt
.
ParaLocalDbBlock
)
error
{
func
(
client
*
client
)
addLocalBlock
(
height
int64
,
block
*
pt
.
ParaLocalDbBlock
)
error
{
set
:=
&
types
.
LocalDBSet
{}
set
:=
&
types
.
LocalDBSet
{}
...
@@ -89,7 +93,7 @@ func (client *client) getLastLocalHeight() (int64, error) {
...
@@ -89,7 +93,7 @@ func (client *client) getLastLocalHeight() (int64, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
-
1
,
err
return
-
1
,
err
}
}
if
value
[
0
]
==
nil
{
if
len
(
value
)
==
0
{
return
-
1
,
types
.
ErrNotFound
return
-
1
,
types
.
ErrNotFound
}
}
...
@@ -110,7 +114,7 @@ func (client *client) getLocalBlockByHeight(height int64) (*pt.ParaLocalDbBlock,
...
@@ -110,7 +114,7 @@ func (client *client) getLocalBlockByHeight(height int64) (*pt.ParaLocalDbBlock,
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
value
[
0
]
==
nil
{
if
len
(
value
)
==
0
{
return
nil
,
types
.
ErrNotFound
return
nil
,
types
.
ErrNotFound
}
}
...
@@ -212,7 +216,7 @@ func (client *client) getMatchedBlockOnChain(startHeight int64) (int64, *types.B
...
@@ -212,7 +216,7 @@ func (client *client) getMatchedBlockOnChain(startHeight int64) (int64, *types.B
startHeight
=
lastBlock
.
Height
startHeight
=
lastBlock
.
Height
}
}
depth
:=
searchHashMatch
Depth
depth
:=
client
.
subCfg
.
SearchHashMatchedBlock
Depth
for
height
:=
startHeight
;
height
>
0
&&
depth
>
0
;
height
--
{
for
height
:=
startHeight
;
height
>
0
&&
depth
>
0
;
height
--
{
block
,
err
:=
client
.
GetBlockByHeight
(
height
)
block
,
err
:=
client
.
GetBlockByHeight
(
height
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -227,7 +231,7 @@ func (client *client) getMatchedBlockOnChain(startHeight int64) (int64, *types.B
...
@@ -227,7 +231,7 @@ func (client *client) getMatchedBlockOnChain(startHeight int64) (int64, *types.B
if
depth
==
0
{
if
depth
==
0
{
plog
.
Error
(
"switchHashMatchedBlock depth overflow"
,
"last info:mainHeight"
,
block
.
MainHeight
,
plog
.
Error
(
"switchHashMatchedBlock depth overflow"
,
"last info:mainHeight"
,
block
.
MainHeight
,
"mainHash"
,
hex
.
EncodeToString
(
block
.
MainHash
),
"search startHeight"
,
lastBlock
.
Height
,
"curHeight"
,
height
,
"mainHash"
,
hex
.
EncodeToString
(
block
.
MainHash
),
"search startHeight"
,
lastBlock
.
Height
,
"curHeight"
,
height
,
"search depth"
,
searchHashMatch
Depth
)
"search depth"
,
client
.
subCfg
.
SearchHashMatchedBlock
Depth
)
panic
(
"search HashMatchedBlock overflow, re-setting search depth and restart to try"
)
panic
(
"search HashMatchedBlock overflow, re-setting search depth and restart to try"
)
}
}
if
height
==
1
{
if
height
==
1
{
...
@@ -307,13 +311,13 @@ func (client *client) getBatchSeqCount(currSeq int64) (int64, error) {
...
@@ -307,13 +311,13 @@ func (client *client) getBatchSeqCount(currSeq int64) (int64, error) {
}
}
if
lastSeq
>
currSeq
{
if
lastSeq
>
currSeq
{
if
lastSeq
-
currSeq
>
e
mptyBlockInterval
{
if
lastSeq
-
currSeq
>
client
.
subCfg
.
E
mptyBlockInterval
{
atomic
.
StoreInt32
(
&
client
.
caughtUp
,
0
)
atomic
.
StoreInt32
(
&
client
.
caughtUp
,
0
)
}
else
{
}
else
{
atomic
.
StoreInt32
(
&
client
.
caughtUp
,
1
)
atomic
.
StoreInt32
(
&
client
.
caughtUp
,
1
)
}
}
if
fetchFilterParaTxsEnable
&&
lastSeq
-
currSeq
>
b
atchFetchBlockCount
{
if
fetchFilterParaTxsEnable
&&
lastSeq
-
currSeq
>
client
.
subCfg
.
B
atchFetchBlockCount
{
return
b
atchFetchBlockCount
,
nil
return
client
.
subCfg
.
B
atchFetchBlockCount
,
nil
}
}
return
0
,
nil
return
0
,
nil
}
}
...
@@ -437,7 +441,7 @@ func (client *client) procLocalBlock(mainBlock *types.ParaTxDetail) (bool, error
...
@@ -437,7 +441,7 @@ func (client *client) procLocalBlock(mainBlock *types.ParaTxDetail) (bool, error
}
else
if
mainBlock
.
Type
==
addAct
{
}
else
if
mainBlock
.
Type
==
addAct
{
if
len
(
txs
)
==
0
{
if
len
(
txs
)
==
0
{
if
lastSeqMainHeight
-
lastBlock
.
MainHeight
<
e
mptyBlockInterval
{
if
lastSeqMainHeight
-
lastBlock
.
MainHeight
<
client
.
subCfg
.
E
mptyBlockInterval
{
return
false
,
nil
return
false
,
nil
}
}
plog
.
Info
(
"Create empty block"
)
plog
.
Info
(
"Create empty block"
)
...
@@ -487,7 +491,7 @@ out:
...
@@ -487,7 +491,7 @@ out:
if
err
==
nil
{
if
err
==
nil
{
continue
continue
}
}
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
blockSec
))
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
client
.
subCfg
.
WriteBlockSeconds
))
continue
continue
}
}
...
...
plugin/consensus/para/pararpc.go
View file @
017bcf9e
...
@@ -139,9 +139,9 @@ func (client *client) GetBlockOnMainBySeq(seq int64) (*types.BlockSeq, error) {
...
@@ -139,9 +139,9 @@ func (client *client) GetBlockOnMainBySeq(seq int64) (*types.BlockSeq, error) {
return
nil
,
err
return
nil
,
err
}
}
hash
:=
blockSeq
.
Detail
.
Block
.
HashByForkHeight
(
m
ainBlockHashForkHeight
)
hash
:=
blockSeq
.
Detail
.
Block
.
HashByForkHeight
(
client
.
subCfg
.
M
ainBlockHashForkHeight
)
if
!
bytes
.
Equal
(
blockSeq
.
Seq
.
Hash
,
hash
)
{
if
!
bytes
.
Equal
(
blockSeq
.
Seq
.
Hash
,
hash
)
{
plog
.
Error
(
"para compare ForkBlockHash fail"
,
"forkHeight"
,
m
ainBlockHashForkHeight
,
plog
.
Error
(
"para compare ForkBlockHash fail"
,
"forkHeight"
,
client
.
subCfg
.
M
ainBlockHashForkHeight
,
"seqHash"
,
hex
.
EncodeToString
(
blockSeq
.
Seq
.
Hash
),
"calcHash"
,
hex
.
EncodeToString
(
hash
))
"seqHash"
,
hex
.
EncodeToString
(
blockSeq
.
Seq
.
Hash
),
"calcHash"
,
hex
.
EncodeToString
(
hash
))
return
nil
,
types
.
ErrBlockHashNoMatch
return
nil
,
types
.
ErrBlockHashNoMatch
}
}
...
...
plugin/consensus/para/parasync.go
View file @
017bcf9e
...
@@ -355,7 +355,7 @@ func (client *BlockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc
...
@@ -355,7 +355,7 @@ func (client *BlockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc
tx
,
err
:=
pt
.
CreateRawMinerTx
(
&
pt
.
ParacrossMinerAction
{
tx
,
err
:=
pt
.
CreateRawMinerTx
(
&
pt
.
ParacrossMinerAction
{
Status
:
status
,
Status
:
status
,
IsSelfConsensus
:
isParaSelfConsensusForked
(
status
.
MainBlockHeight
),
IsSelfConsensus
:
client
.
paraClient
.
isParaSelfConsensusForked
(
status
.
MainBlockHeight
),
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
plugin/consensus/para/paratxrequest_test.go
View file @
017bcf9e
...
@@ -40,10 +40,15 @@ func getPrivKey(t *testing.T) crypto.PrivKey {
...
@@ -40,10 +40,15 @@ func getPrivKey(t *testing.T) crypto.PrivKey {
}
}
func
TestCalcCommitMsgTxs
(
t
*
testing
.
T
)
{
func
TestCalcCommitMsgTxs
(
t
*
testing
.
T
)
{
para
:=
new
(
client
)
para
.
subCfg
=
new
(
subConfig
)
priKey
:=
getPrivKey
(
t
)
priKey
:=
getPrivKey
(
t
)
client
:=
commitMsgClient
{
client
:=
&
commitMsgClient
{
privateKey
:
priKey
,
privateKey
:
priKey
,
paraClient
:
para
,
}
}
para
.
commitMsgClient
=
client
nt1
:=
&
pt
.
ParacrossNodeStatus
{
nt1
:=
&
pt
.
ParacrossNodeStatus
{
Height
:
1
,
Height
:
1
,
Title
:
"user.p.para"
,
Title
:
"user.p.para"
,
...
@@ -71,9 +76,8 @@ func TestCalcCommitMsgTxs(t *testing.T) {
...
@@ -71,9 +76,8 @@ func TestCalcCommitMsgTxs(t *testing.T) {
}
}
func
TestGetConsensusStatus
(
t
*
testing
.
T
)
{
func
TestGetConsensusStatus
(
t
*
testing
.
T
)
{
mainFork
:=
mainParaSelfConsensusForkHeight
mainParaSelfConsensusForkHeight
=
1
para
:=
new
(
client
)
para
:=
new
(
client
)
para
.
subCfg
=
new
(
subConfig
)
grpcClient
:=
&
typesmocks
.
Chain33Client
{}
grpcClient
:=
&
typesmocks
.
Chain33Client
{}
//grpcClient.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, errors.New("err")).Once()
//grpcClient.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, errors.New("err")).Once()
para
.
grpcClient
=
grpcClient
para
.
grpcClient
=
grpcClient
...
@@ -93,12 +97,6 @@ func TestGetConsensusStatus(t *testing.T) {
...
@@ -93,12 +97,6 @@ func TestGetConsensusStatus(t *testing.T) {
Height
:
1
,
Height
:
1
,
}
}
//msgx := &types.Message{types.Encode(status)}
//msg := types.Encode(status)
//reply := &types.Reply{
// IsOk: true,
// Msg: types.Encode(status),
//}
api
.
On
(
"QueryChain"
,
mock
.
Anything
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
status
,
nil
)
.
Once
()
api
.
On
(
"QueryChain"
,
mock
.
Anything
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
status
,
nil
)
.
Once
()
detail
:=
&
types
.
BlockDetail
{
Block
:
block
}
detail
:=
&
types
.
BlockDetail
{
Block
:
block
}
details
:=
&
types
.
BlockDetails
{
Items
:
[]
*
types
.
BlockDetail
{
detail
}}
details
:=
&
types
.
BlockDetails
{
Items
:
[]
*
types
.
BlockDetail
{
detail
}}
...
@@ -108,7 +106,6 @@ func TestGetConsensusStatus(t *testing.T) {
...
@@ -108,7 +106,6 @@ func TestGetConsensusStatus(t *testing.T) {
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
1
),
ret
.
Height
)
assert
.
Equal
(
t
,
int64
(
1
),
ret
.
Height
)
mainParaSelfConsensusForkHeight
=
mainFork
}
}
func
TestSendCommitMsg
(
t
*
testing
.
T
)
{
func
TestSendCommitMsg
(
t
*
testing
.
T
)
{
...
...
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