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
ce619cf7
Commit
ce619cf7
authored
Jul 19, 2019
by
mdj33
Committed by
vipwzw
Aug 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support batch fetch tx
parent
7174ecf7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
314 additions
and
50 deletions
+314
-50
para.go
plugin/consensus/para/para.go
+12
-0
paracreate.go
plugin/consensus/para/paracreate.go
+185
-50
pararpc.go
plugin/consensus/para/pararpc.go
+10
-0
filtertxs.go
plugin/dapp/paracross/executor/filtertxs.go
+83
-0
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+24
-0
No files found.
plugin/consensus/para/para.go
View file @
ce619cf7
...
@@ -49,6 +49,8 @@ var (
...
@@ -49,6 +49,8 @@ var (
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
localCacheCount
int64
=
1000
// local cache block max count
localCacheCount
int64
=
1000
// local cache block max count
batchFetchSeqEnable
bool
batchFetchSeqNum
int64
=
128
)
)
func
init
()
{
func
init
()
{
...
@@ -86,6 +88,8 @@ type subConfig struct {
...
@@ -86,6 +88,8 @@ type subConfig struct {
MainForkParacrossCommitTx
int64
`json:"mainForkParacrossCommitTx,omitempty"`
MainForkParacrossCommitTx
int64
`json:"mainForkParacrossCommitTx,omitempty"`
WaitConsensStopTimes
uint32
`json:"waitConsensStopTimes,omitempty"`
WaitConsensStopTimes
uint32
`json:"waitConsensStopTimes,omitempty"`
LocalCacheCount
int64
`json:"localCacheCount,omitempty"`
LocalCacheCount
int64
`json:"localCacheCount,omitempty"`
BatchFetchSeqEnable
uint32
`json:"batchFetchSeqEnable,omitempty"`
BatchFetchSeqNum
int64
`json:"batchFetchSeqNum,omitempty"`
}
}
// New function to init paracross env
// New function to init paracross env
...
@@ -129,6 +133,14 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
...
@@ -129,6 +133,14 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
localCacheCount
=
subcfg
.
LocalCacheCount
localCacheCount
=
subcfg
.
LocalCacheCount
}
}
if
subcfg
.
BatchFetchSeqEnable
>
0
{
batchFetchSeqEnable
=
true
}
if
subcfg
.
BatchFetchSeqNum
>
0
{
batchFetchSeqNum
=
subcfg
.
BatchFetchSeqNum
}
pk
,
err
:=
hex
.
DecodeString
(
minerPrivateKey
)
pk
,
err
:=
hex
.
DecodeString
(
minerPrivateKey
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
...
plugin/consensus/para/paracreate.go
View file @
ce619cf7
This diff is collapsed.
Click to expand it.
plugin/consensus/para/pararpc.go
View file @
ce619cf7
...
@@ -145,3 +145,13 @@ func (client *client) GetBlockOnMainByHash(hash []byte) (*types.Block, error) {
...
@@ -145,3 +145,13 @@ func (client *client) GetBlockOnMainByHash(hash []byte) (*types.Block, error) {
return
blocks
.
Items
[
0
]
.
Block
,
nil
return
blocks
.
Items
[
0
]
.
Block
,
nil
}
}
func
(
client
*
client
)
QueryTxOnMainByHash
(
hash
[]
byte
)
(
*
types
.
TransactionDetail
,
error
)
{
detail
,
err
:=
client
.
grpcClient
.
QueryTransaction
(
context
.
Background
(),
&
types
.
ReqHash
{
Hash
:
hash
})
if
err
!=
nil
{
plog
.
Error
(
"QueryTxOnMainByHash Not found"
,
"txhash"
,
common
.
ToHex
(
hash
))
return
nil
,
err
}
return
detail
,
nil
}
plugin/dapp/paracross/executor/filtertxs.go
View file @
ce619cf7
...
@@ -72,6 +72,36 @@ func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDet
...
@@ -72,6 +72,36 @@ func filterParaTxGroup(title string, tx *types.Transaction, main *types.BlockDet
return
main
.
Block
.
Txs
[
headIdx
:
endIdx
],
endIdx
return
main
.
Block
.
Txs
[
headIdx
:
endIdx
],
endIdx
}
}
func
filterParaTxGroupPlus
(
title
string
,
tx
*
types
.
Transaction
,
allTxs
[]
*
pt
.
TxDetail
,
index
int
,
blockHeight
,
forkHeight
int64
)
([]
*
types
.
Transaction
,
int
)
{
var
headIdx
int
for
i
:=
index
;
i
>=
0
;
i
--
{
if
bytes
.
Equal
(
tx
.
Header
,
allTxs
[
i
]
.
Tx
.
Hash
())
{
headIdx
=
i
break
}
}
endIdx
:=
headIdx
+
int
(
tx
.
GroupCount
)
for
i
:=
headIdx
;
i
<
endIdx
;
i
++
{
if
types
.
IsPara
()
&&
blockHeight
<
forkHeight
{
if
types
.
IsSpecificParaExecName
(
title
,
string
(
allTxs
[
i
]
.
Tx
.
Execer
))
{
continue
}
}
if
!
checkReceiptExecOk
(
allTxs
[
i
]
.
Receipt
)
{
return
nil
,
endIdx
}
}
//全部是平行链交易 或平行链在主链执行成功的tx
var
retTxs
[]
*
types
.
Transaction
for
_
,
retTx
:=
range
allTxs
[
headIdx
:
endIdx
]
{
retTxs
=
append
(
retTxs
,
retTx
.
Tx
)
}
return
retTxs
,
endIdx
}
//FilterTxsForPara include some main tx in tx group before ForkParacrossCommitTx
//FilterTxsForPara include some main tx in tx group before ForkParacrossCommitTx
func
FilterTxsForPara
(
title
string
,
main
*
types
.
BlockDetail
)
[]
*
types
.
Transaction
{
func
FilterTxsForPara
(
title
string
,
main
*
types
.
BlockDetail
)
[]
*
types
.
Transaction
{
var
txs
[]
*
types
.
Transaction
var
txs
[]
*
types
.
Transaction
...
@@ -96,6 +126,30 @@ func FilterTxsForPara(title string, main *types.BlockDetail) []*types.Transactio
...
@@ -96,6 +126,30 @@ func FilterTxsForPara(title string, main *types.BlockDetail) []*types.Transactio
return
txs
return
txs
}
}
//FilterTxsForPara include some main tx in tx group before ForkParacrossCommitTx
func
FilterTxsForParaPlus
(
title
string
,
main
*
pt
.
ParaTxDetail
)
[]
*
types
.
Transaction
{
var
txs
[]
*
types
.
Transaction
forkHeight
:=
pt
.
GetDappForkHeight
(
pt
.
ForkCommitTx
)
for
i
:=
0
;
i
<
len
(
main
.
TxDetails
);
i
++
{
tx
:=
main
.
TxDetails
[
i
]
.
Tx
if
types
.
IsSpecificParaExecName
(
title
,
string
(
tx
.
Execer
))
{
if
tx
.
GroupCount
>=
2
{
mainTxs
,
endIdx
:=
filterParaTxGroupPlus
(
title
,
tx
,
main
.
TxDetails
,
i
,
main
.
Header
.
Height
,
forkHeight
)
txs
=
append
(
txs
,
mainTxs
...
)
i
=
endIdx
-
1
continue
}
//单独的paracross tx 如果主链执行失败也要排除, 6.2fork原因 没有排除 非user.p.xx.paracross的平行链交易
if
main
.
Header
.
Height
>=
forkHeight
&&
bytes
.
HasSuffix
(
tx
.
Execer
,
[]
byte
(
pt
.
ParaX
))
&&
!
checkReceiptExecOk
(
main
.
TxDetails
[
i
]
.
Receipt
)
{
continue
}
txs
=
append
(
txs
,
tx
)
}
}
return
txs
}
// FilterParaCrossTxHashes only all para chain cross txs like xx.paracross exec
// FilterParaCrossTxHashes only all para chain cross txs like xx.paracross exec
func
FilterParaCrossTxHashes
(
title
string
,
txs
[]
*
types
.
Transaction
)
[][]
byte
{
func
FilterParaCrossTxHashes
(
title
string
,
txs
[]
*
types
.
Transaction
)
[][]
byte
{
var
txHashs
[][]
byte
var
txHashs
[][]
byte
...
@@ -179,3 +233,32 @@ func CalcTxHashsHash(txHashs [][]byte) []byte {
...
@@ -179,3 +233,32 @@ func CalcTxHashsHash(txHashs [][]byte) []byte {
data
:=
types
.
Encode
(
totalTxHash
)
data
:=
types
.
Encode
(
totalTxHash
)
return
common
.
Sha256
(
data
)
return
common
.
Sha256
(
data
)
}
}
//BlockDetail2ParaTxs blockDetail transfer to paraTxDetail
func
BlockDetail2ParaTxs
(
seqType
int64
,
blockHash
[]
byte
,
blockDetail
*
types
.
BlockDetail
)
*
pt
.
ParaTxDetail
{
header
:=
&
types
.
Header
{
Version
:
blockDetail
.
Block
.
Version
,
ParentHash
:
blockDetail
.
Block
.
ParentHash
,
TxHash
:
blockDetail
.
Block
.
TxHash
,
StateHash
:
blockDetail
.
Block
.
StateHash
,
Height
:
blockDetail
.
Block
.
Height
,
BlockTime
:
blockDetail
.
Block
.
BlockTime
,
Difficulty
:
blockDetail
.
Block
.
Difficulty
,
Signature
:
blockDetail
.
Block
.
Signature
,
}
header
.
Hash
=
blockHash
txDetail
:=
&
pt
.
ParaTxDetail
{
Type
:
seqType
,
Header
:
header
,
}
for
i
,
tx
:=
range
blockDetail
.
Block
.
Txs
{
detail
:=
&
pt
.
TxDetail
{
Tx
:
tx
,
Receipt
:
blockDetail
.
Receipts
[
i
],
}
txDetail
.
TxDetails
=
append
(
txDetail
.
TxDetails
,
detail
)
}
return
txDetail
}
plugin/dapp/paracross/proto/paracross.proto
View file @
ce619cf7
...
@@ -310,6 +310,30 @@ message ParaLocalDbBlock {
...
@@ -310,6 +310,30 @@ message ParaLocalDbBlock {
repeated
Transaction
txs
=
6
;
repeated
Transaction
txs
=
6
;
}
}
message
ReqParaTxByTitle
{
int64
start
=
1
;
int64
end
=
2
;
string
title
=
3
;
}
message
TxDetail
{
uint32
index
=
1
;
Transaction
tx
=
2
;
ReceiptData
receipt
=
3
;
repeated
bytes
proofs
=
4
;
}
message
ParaTxDetail
{
int64
type
=
1
;
Header
header
=
2
;
repeated
TxDetail
txDetails
=
3
;
}
message
ParaTxDetails
{
repeated
ParaTxDetail
items
=
1
;
}
service
paracross
{
service
paracross
{
rpc
GetTitle
(
ReqString
)
returns
(
ParacrossConsensusStatus
)
{}
rpc
GetTitle
(
ReqString
)
returns
(
ParacrossConsensusStatus
)
{}
...
...
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