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
b56786e6
Commit
b56786e6
authored
Jul 11, 2019
by
mdj33
Committed by
vipwzw
Aug 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add genesis
parent
b0d1ca85
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
15 deletions
+27
-15
para.go
plugin/consensus/para/para.go
+10
-2
paradownload.go
plugin/consensus/para/paradownload.go
+17
-13
No files found.
plugin/consensus/para/para.go
View file @
b56786e6
...
...
@@ -222,7 +222,15 @@ func (client *client) InitBlock() {
tx
:=
client
.
CreateGenesisTx
()
newblock
.
Txs
=
tx
newblock
.
TxHash
=
merkle
.
CalcMerkleRoot
(
newblock
.
Txs
)
client
.
WriteBlock
(
zeroHash
[
:
],
newblock
,
startSeq
)
err
:=
client
.
WriteBlock
(
zeroHash
[
:
],
newblock
,
startSeq
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"para chain create genesis block,err=%s"
,
err
.
Error
()))
}
err
=
client
.
createLocalGenesisBlock
(
newblock
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"para chain create local genesis block,err=%s"
,
err
.
Error
()))
}
}
else
{
client
.
SetCurrentBlock
(
block
)
}
...
...
@@ -329,7 +337,7 @@ func (client *client) getLastBlockMainInfo() (int64, *types.Block, error) {
}
mainSeq
,
err
:=
client
.
GetSeqByHashOnMainChain
(
lastBlock
.
MainHash
)
if
err
!=
nil
{
return
client
.
req
ChainMatchedBlock
(
0
)
return
client
.
req
MatchedBlockOnChain
(
0
)
}
return
mainSeq
,
lastBlock
,
nil
...
...
plugin/consensus/para/paradownload.go
View file @
b56786e6
...
...
@@ -55,15 +55,21 @@ func (client *client) createLocalBlock(lastBlock *paracross.ParaLocalDbBlock, tx
var
newblock
paracross
.
ParaLocalDbBlock
newblock
.
Height
=
lastBlock
.
Height
+
1
newblock
.
Txs
=
txs
newblock
.
BlockTime
=
mainBlock
.
Detail
.
Block
.
BlockTime
newblock
.
MainHash
=
mainBlock
.
Seq
.
Hash
newblock
.
MainHeight
=
mainBlock
.
Detail
.
Block
.
Height
newblock
.
ParentMainHash
=
mainBlock
.
Detail
.
Block
.
ParentHash
newblock
.
BlockTime
=
mainBlock
.
Detail
.
Block
.
BlockTime
newblock
.
Txs
=
txs
return
client
.
addLocalBlock
(
newblock
.
Height
,
&
newblock
)
}
func
(
client
*
client
)
createLocalGenesisBlock
(
genesis
*
types
.
Block
)
error
{
return
client
.
setLocalBlockByChainBlock
(
genesis
)
}
func
(
client
*
client
)
delLocalBlock
(
height
int64
)
error
{
set
:=
&
types
.
LocalDBSet
{}
key
:=
calcTitleHeightKey
(
types
.
GetTitle
(),
height
)
...
...
@@ -156,8 +162,7 @@ func (client *client) getLocalBlockByHeight(height int64) (*paracross.ParaLocalD
}
//TODO 是否考虑mainHash获取不到,回溯查找?
func
(
client
*
client
)
getLocalBlockInfoByHeight
(
height
int64
)
(
int64
,
[]
byte
,
error
)
{
func
(
client
*
client
)
getLocalBlockSeq
(
height
int64
)
(
int64
,
[]
byte
,
error
)
{
lastBlock
,
err
:=
client
.
getLocalBlockByHeight
(
height
)
if
err
!=
nil
{
return
-
2
,
nil
,
err
...
...
@@ -188,7 +193,7 @@ func (client *client) setLocalBlockByChainBlock(chainBlock *types.Block) error {
func
(
client
*
client
)
getLastLocalBlockInfo
()
(
int64
,
[]
byte
,
error
)
{
height
,
err
:=
client
.
getLastLocalHeight
()
if
err
==
nil
{
mainSeq
,
mainHash
,
err
:=
client
.
getLocalBlock
InfoByHeight
(
height
)
mainSeq
,
mainHash
,
err
:=
client
.
getLocalBlock
Seq
(
height
)
if
err
==
nil
{
return
mainSeq
,
mainHash
,
nil
}
...
...
@@ -216,7 +221,7 @@ func (client *client) getLastDbBlock() (*paracross.ParaLocalDbBlock, error) {
return
client
.
getLocalBlockByHeight
(
height
)
}
func
(
client
*
client
)
req
ChainMatchedBlock
(
startHeight
int64
)
(
int64
,
*
types
.
Block
,
error
)
{
func
(
client
*
client
)
req
MatchedBlockOnChain
(
startHeight
int64
)
(
int64
,
*
types
.
Block
,
error
)
{
lastBlock
,
err
:=
client
.
RequestLastBlock
()
if
err
!=
nil
{
plog
.
Error
(
"Parachain RequestLastBlock fail"
,
"err"
,
err
)
...
...
@@ -258,15 +263,15 @@ func (client *client) reqChainMatchedBlock(startHeight int64) (int64, *types.Blo
continue
}
plog
.
Info
(
"req
ChainMatchedBlock
succ"
,
"currHeight"
,
height
,
"initHeight"
,
lastBlock
.
Height
,
plog
.
Info
(
"req
MatchedBlockOnChain
succ"
,
"currHeight"
,
height
,
"initHeight"
,
lastBlock
.
Height
,
"new currSeq"
,
mainSeq
,
"new preMainBlockHash"
,
hex
.
EncodeToString
(
block
.
MainHash
))
return
mainSeq
,
block
,
nil
}
return
-
2
,
nil
,
paracross
.
ErrParaCurHashNotMatch
}
func
(
client
*
client
)
switch
ChainMatchedBlock
(
startHeight
int64
)
(
int64
,
[]
byte
,
error
)
{
mainSeq
,
chainBlock
,
err
:=
client
.
req
ChainMatchedBlock
(
startHeight
)
func
(
client
*
client
)
switch
MatchedBlockOnChain
(
startHeight
int64
)
(
int64
,
[]
byte
,
error
)
{
mainSeq
,
chainBlock
,
err
:=
client
.
req
MatchedBlockOnChain
(
startHeight
)
if
err
!=
nil
{
return
-
2
,
nil
,
err
}
...
...
@@ -282,8 +287,7 @@ func (client *client) switchLocalHashMatchedBlock(currSeq int64) (int64, []byte,
lastBlock
,
err
:=
client
.
getLastDbBlock
()
if
err
!=
nil
{
if
err
==
types
.
ErrNotFound
{
//TODO 或者通知执行层去切换
return
client
.
switchChainMatchedBlock
(
0
)
return
client
.
switchMatchedBlockOnChain
(
0
)
}
plog
.
Error
(
"Parachain RequestLastBlock fail"
,
"err"
,
err
)
return
-
2
,
nil
,
err
...
...
@@ -298,7 +302,7 @@ func (client *client) switchLocalHashMatchedBlock(currSeq int64) (int64, []byte,
if
err
!=
nil
{
return
-
2
,
nil
,
err
}
return
client
.
switch
ChainMatchedBlock
(
height
)
return
client
.
switch
MatchedBlockOnChain
(
height
)
}
return
-
2
,
nil
,
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