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
493afe81
Commit
493afe81
authored
Jul 10, 2019
by
mdj33
Committed by
vipwzw
Aug 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
para download improve
parent
7fdd37ad
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
38 deletions
+54
-38
kv.go
plugin/consensus/para/kv.go
+20
-0
para.go
plugin/consensus/para/para.go
+26
-38
paradownload.go
plugin/consensus/para/paradownload.go
+0
-0
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+8
-0
No files found.
plugin/consensus/para/kv.go
0 → 100644
View file @
493afe81
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
para
import
(
"fmt"
)
func
calcTitleHeightKey
(
title
string
,
height
int64
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
"TH-%s-%d"
,
title
,
height
))
}
func
calcTitleLastHeightKey
(
title
string
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
"LH-%s"
,
title
))
}
plugin/consensus/para/para.go
View file @
493afe81
...
@@ -222,7 +222,7 @@ func (client *client) InitBlock() {
...
@@ -222,7 +222,7 @@ func (client *client) InitBlock() {
tx
:=
client
.
CreateGenesisTx
()
tx
:=
client
.
CreateGenesisTx
()
newblock
.
Txs
=
tx
newblock
.
Txs
=
tx
newblock
.
TxHash
=
merkle
.
CalcMerkleRoot
(
newblock
.
Txs
)
newblock
.
TxHash
=
merkle
.
CalcMerkleRoot
(
newblock
.
Txs
)
client
.
WriteBlock
(
zeroHash
[
:
],
newblock
,
startSeq
-
1
)
client
.
WriteBlock
(
zeroHash
[
:
],
newblock
,
startSeq
)
}
else
{
}
else
{
client
.
SetCurrentBlock
(
block
)
client
.
SetCurrentBlock
(
block
)
}
}
...
@@ -234,8 +234,8 @@ func (client *client) InitBlock() {
...
@@ -234,8 +234,8 @@ func (client *client) InitBlock() {
// GetStartSeq get startSeq in mainchain
// GetStartSeq get startSeq in mainchain
func
(
client
*
client
)
GetStartSeq
(
height
int64
)
(
int64
,
[]
byte
)
{
func
(
client
*
client
)
GetStartSeq
(
height
int64
)
(
int64
,
[]
byte
)
{
if
height
=
=
0
{
if
height
<
=
0
{
return
0
,
nil
panic
(
fmt
.
Sprintf
(
"startHeight(%d) should be more than 0 in mainchain"
,
height
))
}
}
lastHeight
,
err
:=
client
.
GetLastHeightOnMainChain
()
lastHeight
,
err
:=
client
.
GetLastHeightOnMainChain
()
...
@@ -262,7 +262,7 @@ func (client *client) GetStartSeq(height int64) (int64, []byte) {
...
@@ -262,7 +262,7 @@ func (client *client) GetStartSeq(height int64) (int64, []byte) {
hint
.
Stop
()
hint
.
Stop
()
plog
.
Info
(
fmt
.
Sprintf
(
"lastHeight more than %d blocks after startHeight"
,
minBlockNum
),
"lastHeight"
,
lastHeight
,
"startHeight"
,
height
)
plog
.
Info
(
fmt
.
Sprintf
(
"lastHeight more than %d blocks after startHeight"
,
minBlockNum
),
"lastHeight"
,
lastHeight
,
"startHeight"
,
height
)
seq
,
hash
,
err
:=
client
.
GetSeqByHeightOnMainChain
(
height
)
seq
,
hash
,
err
:=
client
.
GetSeqByHeightOnMainChain
(
height
-
1
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
...
@@ -320,43 +320,29 @@ func (client *client) GetBlockByHeight(height int64) (*types.Block, error) {
...
@@ -320,43 +320,29 @@ func (client *client) GetBlockByHeight(height int64) (*types.Block, error) {
return
blockDetails
.
Items
[
0
]
.
Block
,
nil
return
blockDetails
.
Items
[
0
]
.
Block
,
nil
}
}
// 获取上一个平行链对应主链seq,hash信息
// 获取当前平行链block对应主链seq,hash信息
// 对于平行链创世区块特殊场景:
// 对于云端主链节点,创世区块记录seq在不同主链节点上差异很大,通过记录的主链hash获取真实seq使用
// 1,创世区块seq从-1开始,也就是从主链0高度同步区块,主链seq从0开始,平行链对seq=0的区块校验时候做特殊处理,不校验parentHash
func
(
client
*
client
)
getLastBlockMainInfo
()
(
int64
,
*
types
.
Block
,
error
)
{
// 2,创世区块seq不是-1, 也就是从主链seq=n高度同步区块,此时创世区块记录了起始高度对应的主链hash,通过hash获取当前seq,然后创世区块需要倒退一个seq,lastSeq=n-1,
lastBlock
,
err
:=
client
.
getLastBlockInfo
()
// 因为对于云端主链节点,创世区块记录seq在不同主链节点上差异很大,通过记录的主链hash获取的真实seq-1来使用,主链hash使用对应区块的parenthash做校验目的
func
(
client
*
client
)
getLastBlockMainInfo
()
(
int64
,
[]
byte
,
error
)
{
lastSeq
,
lastBlock
,
err
:=
client
.
getLastBlockInfo
()
if
err
!=
nil
{
if
err
!=
nil
{
return
-
2
,
nil
,
err
return
-
2
,
nil
,
err
}
}
if
lastBlock
.
Height
==
0
&&
lastSeq
>
-
1
{
mainBlock
,
err
:=
client
.
GetBlockOnMainByHash
(
lastBlock
.
MainHash
)
if
err
!=
nil
{
return
-
2
,
nil
,
err
}
mainSeq
,
err
:=
client
.
GetSeqByHashOnMainChain
(
lastBlock
.
MainHash
)
mainSeq
,
err
:=
client
.
GetSeqByHashOnMainChain
(
lastBlock
.
MainHash
)
if
err
!=
nil
{
if
err
!=
nil
{
return
-
2
,
nil
,
err
return
client
.
reqChainMatchedBlock
(
0
)
}
}
return
mainSeq
-
1
,
mainBlock
.
ParentHash
,
nil
return
mainSeq
,
lastBlock
,
nil
}
return
lastSeq
,
lastBlock
.
MainHash
,
nil
}
}
func
(
client
*
client
)
getLastBlockInfo
()
(
int64
,
*
types
.
Block
,
error
)
{
func
(
client
*
client
)
getLastBlockInfo
()
(
*
types
.
Block
,
error
)
{
lastBlock
,
err
:=
client
.
RequestLastBlock
()
lastBlock
,
err
:=
client
.
RequestLastBlock
()
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"Parachain RequestLastBlock fail"
,
"err"
,
err
)
plog
.
Error
(
"Parachain RequestLastBlock fail"
,
"err"
,
err
)
return
-
2
,
nil
,
err
return
nil
,
err
}
blockedSeq
,
err
:=
client
.
GetBlockedSeq
(
lastBlock
.
Hash
())
if
err
!=
nil
{
plog
.
Error
(
"Parachain GetBlockedSeq fail"
,
"err"
,
err
)
return
-
2
,
nil
,
err
}
}
return
blockedSeq
,
lastBlock
,
nil
return
lastBlock
,
nil
}
}
func
(
client
*
client
)
GetForkHeightOnMainChain
(
key
string
)
(
int64
,
error
)
{
func
(
client
*
client
)
GetForkHeightOnMainChain
(
key
string
)
(
int64
,
error
)
{
...
@@ -409,7 +395,7 @@ func (client *client) GetHashByHeightOnMainChain(height int64) ([]byte, error) {
...
@@ -409,7 +395,7 @@ func (client *client) GetHashByHeightOnMainChain(height int64) ([]byte, error) {
func
(
client
*
client
)
GetSeqByHashOnMainChain
(
hash
[]
byte
)
(
int64
,
error
)
{
func
(
client
*
client
)
GetSeqByHashOnMainChain
(
hash
[]
byte
)
(
int64
,
error
)
{
seq
,
err
:=
client
.
grpcClient
.
GetSequenceByHash
(
context
.
Background
(),
&
types
.
ReqHash
{
Hash
:
hash
})
seq
,
err
:=
client
.
grpcClient
.
GetSequenceByHash
(
context
.
Background
(),
&
types
.
ReqHash
{
Hash
:
hash
})
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"GetSeqByHashOnMainChain"
,
"Error"
,
err
.
Error
())
plog
.
Error
(
"GetSeqByHashOnMainChain"
,
"Error"
,
err
.
Error
()
,
"hash"
,
hex
.
EncodeToString
(
hash
)
)
return
-
1
,
err
return
-
1
,
err
}
}
//the reflect checked in grpcHandle
//the reflect checked in grpcHandle
...
@@ -498,18 +484,18 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type
...
@@ -498,18 +484,18 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type
//genesis block scenario, new main node's blockHash as preMainHash, genesis sequence+1 as currSeq
//genesis block scenario, new main node's blockHash as preMainHash, genesis sequence+1 as currSeq
// for genesis seq=-1 scenario, mainHash not care, as the 0 seq instead of -1
// for genesis seq=-1 scenario, mainHash not care, as the 0 seq instead of -1
// not seq=-1 scenario, mainHash needed
// not seq=-1 scenario, mainHash needed
func
(
client
*
client
)
syncFromGenesisBlock
()
(
int64
,
[]
byte
,
error
)
{
func
(
client
*
client
)
syncFromGenesisBlock
()
(
int64
,
*
types
.
Block
,
error
)
{
lastSeq
,
last
MainHash
,
err
:=
client
.
getLastBlockMainInfo
()
lastSeq
,
last
Block
,
err
:=
client
.
getLastBlockMainInfo
()
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"Parachain getLastBlockInfo fail"
,
"err"
,
err
)
plog
.
Error
(
"Parachain getLastBlockInfo fail"
,
"err"
,
err
)
return
-
2
,
nil
,
err
return
-
2
,
nil
,
err
}
}
plog
.
Info
(
"syncFromGenesisBlock sync from height 0"
)
plog
.
Info
(
"syncFromGenesisBlock sync from height 0"
)
return
lastSeq
+
1
,
lastMainHash
,
nil
return
lastSeq
,
lastBlock
,
nil
}
}
// search base on para block but not last MainBlockHash, last MainBlockHash can not back tracing
// search base on para block but not last MainBlockHash, last MainBlockHash can not back tracing
func
(
client
*
client
)
switchHashMatchedBlock
(
currSeq
int64
)
(
int64
,
[]
byte
,
error
)
{
func
(
client
*
client
)
switchHashMatchedBlock
(
currSeq
int64
)
(
int64
,
*
types
.
Block
,
error
)
{
lastBlock
,
err
:=
client
.
RequestLastBlock
()
lastBlock
,
err
:=
client
.
RequestLastBlock
()
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"Parachain RequestLastBlock fail"
,
"err"
,
err
)
plog
.
Error
(
"Parachain RequestLastBlock fail"
,
"err"
,
err
)
...
@@ -559,7 +545,7 @@ func (client *client) switchHashMatchedBlock(currSeq int64) (int64, []byte, erro
...
@@ -559,7 +545,7 @@ func (client *client) switchHashMatchedBlock(currSeq int64) (int64, []byte, erro
plog
.
Info
(
"switchHashMatchedBlock succ"
,
"currHeight"
,
height
,
"initHeight"
,
lastBlock
.
Height
,
plog
.
Info
(
"switchHashMatchedBlock succ"
,
"currHeight"
,
height
,
"initHeight"
,
lastBlock
.
Height
,
"new currSeq"
,
mainSeq
+
1
,
"new preMainBlockHash"
,
hex
.
EncodeToString
(
block
.
MainHash
))
"new currSeq"
,
mainSeq
+
1
,
"new preMainBlockHash"
,
hex
.
EncodeToString
(
block
.
MainHash
))
return
mainSeq
+
1
,
block
.
MainHash
,
nil
return
mainSeq
,
block
,
nil
}
}
return
-
2
,
nil
,
paracross
.
ErrParaCurHashNotMatch
return
-
2
,
nil
,
paracross
.
ErrParaCurHashNotMatch
}
}
...
@@ -615,15 +601,17 @@ func (client *client) CreateBlock() {
...
@@ -615,15 +601,17 @@ func (client *client) CreateBlock() {
txs
,
blockOnMain
,
err
:=
client
.
RequestTx
(
currSeq
,
lastSeqMainHash
)
txs
,
blockOnMain
,
err
:=
client
.
RequestTx
(
currSeq
,
lastSeqMainHash
)
if
err
!=
nil
{
if
err
!=
nil
{
incSeqFlag
=
false
if
err
==
paracross
.
ErrParaCurHashNotMatch
{
if
err
==
paracross
.
ErrParaCurHashNotMatch
{
newSeq
,
newSeqMainHash
,
err
:=
client
.
switchHashMatchedBlock
(
currSeq
)
newSeq
,
newSeqMainHash
,
err
:=
client
.
switchHashMatchedBlock
(
currSeq
)
if
err
==
nil
{
if
err
==
nil
{
incSeqFlag
=
true
currSeq
=
newSeq
currSeq
=
newSeq
lastSeqMainHash
=
newSeqMainHash
lastSeqMainHash
=
newSeqMainHash
continue
continue
}
}
}
}
incSeqFlag
=
false
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
blockSec
))
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
blockSec
))
continue
continue
}
}
...
@@ -634,7 +622,7 @@ func (client *client) CreateBlock() {
...
@@ -634,7 +622,7 @@ func (client *client) CreateBlock() {
lastSeqMainHash
=
blockOnMain
.
Detail
.
Block
.
ParentHash
lastSeqMainHash
=
blockOnMain
.
Detail
.
Block
.
ParentHash
}
}
lastBlock
Seq
,
lastBlock
,
err
:=
client
.
getLastBlockInfo
()
lastBlock
,
err
:=
client
.
getLastBlockInfo
()
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"Parachain getLastBlockInfo fail"
,
"err"
,
err
)
plog
.
Error
(
"Parachain getLastBlockInfo fail"
,
"err"
,
err
)
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
...
@@ -642,7 +630,7 @@ func (client *client) CreateBlock() {
...
@@ -642,7 +630,7 @@ func (client *client) CreateBlock() {
}
}
plog
.
Info
(
"Parachain process block"
,
"lastSeq"
,
lastSeq
,
"curSeq"
,
currSeq
,
plog
.
Info
(
"Parachain process block"
,
"lastSeq"
,
lastSeq
,
"curSeq"
,
currSeq
,
"lastBlockHeight"
,
lastBlock
.
Height
,
"lastBlockSeq"
,
lastBlockSeq
,
"lastBlockHeight"
,
lastBlock
.
Height
,
"currSeqMainHeight"
,
lastSeqMainHeight
,
"currSeqMainHash"
,
common
.
ToHex
(
lastSeqMainHash
),
"currSeqMainHeight"
,
lastSeqMainHeight
,
"currSeqMainHash"
,
common
.
ToHex
(
lastSeqMainHash
),
"lastBlockMainHeight"
,
lastBlock
.
MainHeight
,
"lastBlockMainHash"
,
common
.
ToHex
(
lastBlock
.
MainHash
),
"seqTy"
,
blockOnMain
.
Seq
.
Type
)
"lastBlockMainHeight"
,
lastBlock
.
MainHeight
,
"lastBlockMainHash"
,
common
.
ToHex
(
lastBlock
.
MainHash
),
"seqTy"
,
blockOnMain
.
Seq
.
Type
)
...
...
plugin/consensus/para/paradownload.go
0 → 100644
View file @
493afe81
This diff is collapsed.
Click to expand it.
plugin/dapp/paracross/proto/paracross.proto
View file @
493afe81
...
@@ -301,6 +301,14 @@ message ParacrossAsset {
...
@@ -301,6 +301,14 @@ message ParacrossAsset {
bool
success
=
23
;
bool
success
=
23
;
}
}
message
ParaLocalDbBlock
{
int64
height
=
1
;
bytes
mainHash
=
2
;
int64
mainHeight
=
3
;
bytes
parentMainHash
=
4
;
int64
blockTime
=
5
;
repeated
Transaction
txs
=
6
;
}
service
paracross
{
service
paracross
{
...
...
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