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
f6f7ee68
Commit
f6f7ee68
authored
Jul 11, 2019
by
mdj33
Committed by
vipwzw
Aug 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve
parent
b56786e6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
148 additions
and
1 deletion
+148
-1
para.go
plugin/consensus/para/para.go
+0
-0
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+1
-1
paracreate.go
plugin/consensus/para/paracreate.go
+0
-0
pararpc.go
plugin/consensus/para/pararpc.go
+147
-0
No files found.
plugin/consensus/para/para.go
View file @
f6f7ee68
This diff is collapsed.
Click to expand it.
plugin/consensus/para/paracommitmsg.go
View file @
f6f7ee68
...
@@ -559,7 +559,7 @@ out:
...
@@ -559,7 +559,7 @@ out:
continue
continue
}
}
_
,
block
,
err
:=
client
.
paraClient
.
getLastBlockInfo
()
block
,
err
:=
client
.
paraClient
.
getLastBlockInfo
()
if
err
!=
nil
{
if
err
!=
nil
{
continue
continue
}
}
...
...
plugin/consensus/para/para
download
.go
→
plugin/consensus/para/para
create
.go
View file @
f6f7ee68
This diff is collapsed.
Click to expand it.
plugin/consensus/para/pararpc.go
0 → 100644
View file @
f6f7ee68
// 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
(
"bytes"
"context"
"encoding/hex"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/types"
)
func
(
client
*
client
)
GetBlockedSeq
(
hash
[]
byte
)
(
int64
,
error
)
{
//from blockchain db
blockedSeq
,
err
:=
client
.
GetAPI
()
.
GetMainSequenceByHash
(
&
types
.
ReqHash
{
Hash
:
hash
})
if
err
!=
nil
{
return
-
2
,
err
}
return
blockedSeq
.
Data
,
nil
}
func
(
client
*
client
)
GetBlockByHeight
(
height
int64
)
(
*
types
.
Block
,
error
)
{
//from blockchain db
blockDetails
,
err
:=
client
.
GetAPI
()
.
GetBlocks
(
&
types
.
ReqBlocks
{
Start
:
height
,
End
:
height
})
if
err
!=
nil
{
plog
.
Error
(
"paracommitmsg get node status block count fail"
)
return
nil
,
err
}
if
1
!=
int64
(
len
(
blockDetails
.
Items
))
{
plog
.
Error
(
"paracommitmsg get node status block count fail"
)
return
nil
,
types
.
ErrInvalidParam
}
return
blockDetails
.
Items
[
0
]
.
Block
,
nil
}
// 获取当前平行链block对应主链seq,hash信息
// 对于云端主链节点,创世区块记录seq在不同主链节点上差异很大,通过记录的主链hash获取真实seq使用
func
(
client
*
client
)
getLastBlockMainInfo
()
(
int64
,
*
types
.
Block
,
error
)
{
lastBlock
,
err
:=
client
.
getLastBlockInfo
()
if
err
!=
nil
{
return
-
2
,
nil
,
err
}
//如果在云端节点获取不到对应MainHash,切换到switchLocalHashMatchedBlock 去循环查找
mainSeq
,
err
:=
client
.
GetSeqByHashOnMainChain
(
lastBlock
.
MainHash
)
if
err
!=
nil
{
return
0
,
lastBlock
,
nil
}
return
mainSeq
,
lastBlock
,
nil
}
func
(
client
*
client
)
getLastBlockInfo
()
(
*
types
.
Block
,
error
)
{
lastBlock
,
err
:=
client
.
RequestLastBlock
()
if
err
!=
nil
{
plog
.
Error
(
"Parachain RequestLastBlock fail"
,
"err"
,
err
)
return
nil
,
err
}
return
lastBlock
,
nil
}
func
(
client
*
client
)
GetForkHeightOnMainChain
(
key
string
)
(
int64
,
error
)
{
ret
,
err
:=
client
.
grpcClient
.
GetFork
(
context
.
Background
(),
&
types
.
ReqKey
{
Key
:
[]
byte
(
key
)})
if
err
!=
nil
{
plog
.
Error
(
"para get rpc ForkHeight fail"
,
"key"
,
key
,
"err"
,
err
.
Error
())
return
types
.
MaxHeight
,
err
}
return
ret
.
Data
,
nil
}
func
(
client
*
client
)
GetLastHeightOnMainChain
()
(
int64
,
error
)
{
header
,
err
:=
client
.
grpcClient
.
GetLastHeader
(
context
.
Background
(),
&
types
.
ReqNil
{})
if
err
!=
nil
{
plog
.
Error
(
"GetLastHeightOnMainChain"
,
"Error"
,
err
.
Error
())
return
-
1
,
err
}
return
header
.
Height
,
nil
}
func
(
client
*
client
)
GetLastSeqOnMainChain
()
(
int64
,
error
)
{
seq
,
err
:=
client
.
grpcClient
.
GetLastBlockSequence
(
context
.
Background
(),
&
types
.
ReqNil
{})
if
err
!=
nil
{
plog
.
Error
(
"GetLastSeqOnMainChain"
,
"Error"
,
err
.
Error
())
return
-
1
,
err
}
//the reflect checked in grpcHandle
return
seq
.
Data
,
nil
}
func
(
client
*
client
)
GetSeqByHeightOnMainChain
(
height
int64
)
(
int64
,
[]
byte
,
error
)
{
hash
,
err
:=
client
.
GetHashByHeightOnMainChain
(
height
)
if
err
!=
nil
{
return
-
1
,
nil
,
err
}
seq
,
err
:=
client
.
GetSeqByHashOnMainChain
(
hash
)
return
seq
,
hash
,
err
}
func
(
client
*
client
)
GetHashByHeightOnMainChain
(
height
int64
)
([]
byte
,
error
)
{
reply
,
err
:=
client
.
grpcClient
.
GetBlockHash
(
context
.
Background
(),
&
types
.
ReqInt
{
Height
:
height
})
if
err
!=
nil
{
plog
.
Error
(
"GetHashByHeightOnMainChain"
,
"Error"
,
err
.
Error
())
return
nil
,
err
}
return
reply
.
Hash
,
nil
}
func
(
client
*
client
)
GetSeqByHashOnMainChain
(
hash
[]
byte
)
(
int64
,
error
)
{
seq
,
err
:=
client
.
grpcClient
.
GetSequenceByHash
(
context
.
Background
(),
&
types
.
ReqHash
{
Hash
:
hash
})
if
err
!=
nil
{
plog
.
Error
(
"GetSeqByHashOnMainChain"
,
"Error"
,
err
.
Error
(),
"hash"
,
hex
.
EncodeToString
(
hash
))
return
-
1
,
err
}
//the reflect checked in grpcHandle
return
seq
.
Data
,
nil
}
func
(
client
*
client
)
GetBlockOnMainBySeq
(
seq
int64
)
(
*
types
.
BlockSeq
,
error
)
{
blockSeq
,
err
:=
client
.
grpcClient
.
GetBlockBySeq
(
context
.
Background
(),
&
types
.
Int64
{
Data
:
seq
})
if
err
!=
nil
{
plog
.
Error
(
"Not found block on main"
,
"seq"
,
seq
)
return
nil
,
err
}
hash
:=
blockSeq
.
Detail
.
Block
.
HashByForkHeight
(
mainBlockHashForkHeight
)
if
!
bytes
.
Equal
(
blockSeq
.
Seq
.
Hash
,
hash
)
{
plog
.
Error
(
"para compare ForkBlockHash fail"
,
"forkHeight"
,
mainBlockHashForkHeight
,
"seqHash"
,
hex
.
EncodeToString
(
blockSeq
.
Seq
.
Hash
),
"calcHash"
,
hex
.
EncodeToString
(
hash
))
return
nil
,
types
.
ErrBlockHashNoMatch
}
return
blockSeq
,
nil
}
func
(
client
*
client
)
GetBlockOnMainByHash
(
hash
[]
byte
)
(
*
types
.
Block
,
error
)
{
blocks
,
err
:=
client
.
grpcClient
.
GetBlockByHashes
(
context
.
Background
(),
&
types
.
ReqHashes
{
Hashes
:
[][]
byte
{
hash
}})
if
err
!=
nil
||
blocks
.
Items
[
0
]
==
nil
{
plog
.
Error
(
"GetBlockOnMainByHash Not found"
,
"blockhash"
,
common
.
ToHex
(
hash
))
return
nil
,
err
}
return
blocks
.
Items
[
0
]
.
Block
,
nil
}
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