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
d9986fc5
Commit
d9986fc5
authored
May 26, 2020
by
madengji
Committed by
33cn
Jun 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
routine bls cmt msg process
parent
66d7594d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
221 additions
and
48 deletions
+221
-48
para.go
plugin/consensus/para/para.go
+1
-5
parablssign.go
plugin/consensus/para/parablssign.go
+25
-0
parablssign_test.go
plugin/consensus/para/parablssign_test.go
+67
-0
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+19
-10
paraquery.go
plugin/consensus/para/paraquery.go
+25
-0
testcase.sh
plugin/dapp/paracross/cmd/build/testcase.sh
+0
-0
paracross.go
plugin/dapp/paracross/commands/paracross.go
+41
-10
action.go
plugin/dapp/paracross/executor/action.go
+16
-19
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+4
-0
rpc.go
plugin/dapp/paracross/rpc/rpc.go
+23
-4
No files found.
plugin/consensus/para/para.go
View file @
d9986fc5
...
@@ -18,7 +18,6 @@ import (
...
@@ -18,7 +18,6 @@ import (
"time"
"time"
"github.com/33cn/chain33/client/api"
"github.com/33cn/chain33/client/api"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/merkle"
"github.com/33cn/chain33/common/merkle"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/queue"
...
@@ -333,10 +332,7 @@ func (client *client) ProcEvent(msg *queue.Message) bool {
...
@@ -333,10 +332,7 @@ func (client *client) ProcEvent(msg *queue.Message) bool {
plog
.
Info
(
"paracross ProcEvent from"
,
"from"
,
req
.
GetFrom
(),
"topic:"
,
req
.
GetTopic
(),
"ty"
,
sub
.
GetTy
())
plog
.
Info
(
"paracross ProcEvent from"
,
"from"
,
req
.
GetFrom
(),
"topic:"
,
req
.
GetTopic
(),
"ty"
,
sub
.
GetTy
())
switch
sub
.
GetTy
()
{
switch
sub
.
GetTy
()
{
case
P2pSubCommitTx
:
case
P2pSubCommitTx
:
err
:=
client
.
blsSignCli
.
rcvCommitTx
(
sub
.
GetCommitTx
())
go
client
.
blsSignCli
.
rcvCommitTx
(
sub
.
GetCommitTx
())
if
err
!=
nil
{
plog
.
Error
(
"paracross ProcEvent commit tx"
,
"err"
,
err
,
"txhash"
,
common
.
ToHex
(
sub
.
GetCommitTx
()
.
Hash
()),
"from"
,
sub
.
GetCommitTx
()
.
From
())
}
case
P2pSubLeaderSyncMsg
:
case
P2pSubLeaderSyncMsg
:
err
:=
client
.
blsSignCli
.
rcvLeaderSyncTx
(
sub
.
GetSyncMsg
())
err
:=
client
.
blsSignCli
.
rcvLeaderSyncTx
(
sub
.
GetSyncMsg
())
if
err
!=
nil
{
if
err
!=
nil
{
...
...
plugin/consensus/para/parablssign.go
View file @
d9986fc5
...
@@ -231,6 +231,7 @@ func (b *blsClient) sendAggregateTx(nodes []string) error {
...
@@ -231,6 +231,7 @@ func (b *blsClient) sendAggregateTx(nodes []string) error {
func
(
b
*
blsClient
)
rcvCommitTx
(
tx
*
types
.
Transaction
)
error
{
func
(
b
*
blsClient
)
rcvCommitTx
(
tx
*
types
.
Transaction
)
error
{
if
!
b
.
isValidNodes
(
tx
.
From
())
{
if
!
b
.
isValidNodes
(
tx
.
From
())
{
b
.
updatePeers
(
tx
.
From
(),
false
)
b
.
updatePeers
(
tx
.
From
(),
false
)
plog
.
Error
(
"rcvCommitTx is not valid node"
,
"addr"
,
tx
.
From
())
return
pt
.
ErrParaNodeAddrNotExisted
return
pt
.
ErrParaNodeAddrNotExisted
}
}
...
@@ -238,6 +239,7 @@ func (b *blsClient) rcvCommitTx(tx *types.Transaction) error {
...
@@ -238,6 +239,7 @@ func (b *blsClient) rcvCommitTx(tx *types.Transaction) error {
if
count
:=
tx
.
GetGroupCount
();
count
>
0
{
if
count
:=
tx
.
GetGroupCount
();
count
>
0
{
group
,
err
:=
tx
.
GetTxGroup
()
group
,
err
:=
tx
.
GetTxGroup
()
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"rcvCommitTx GetTxGroup "
,
"err"
,
err
)
return
errors
.
Wrap
(
err
,
"GetTxGroup"
)
return
errors
.
Wrap
(
err
,
"GetTxGroup"
)
}
}
txs
=
group
.
Txs
txs
=
group
.
Txs
...
@@ -245,9 +247,13 @@ func (b *blsClient) rcvCommitTx(tx *types.Transaction) error {
...
@@ -245,9 +247,13 @@ func (b *blsClient) rcvCommitTx(tx *types.Transaction) error {
commits
,
err
:=
b
.
checkCommitTx
(
txs
)
commits
,
err
:=
b
.
checkCommitTx
(
txs
)
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"rcvCommitTx checkCommitTx "
,
"err"
,
err
)
return
errors
.
Wrap
(
err
,
"checkCommitTx"
)
return
errors
.
Wrap
(
err
,
"checkCommitTx"
)
}
}
b
.
updatePeers
(
tx
.
From
(),
true
)
b
.
updatePeers
(
tx
.
From
(),
true
)
if
len
(
commits
)
>
0
{
plog
.
Debug
(
"rcvCommitTx tx"
,
"addr"
,
tx
.
From
(),
"height"
,
commits
[
0
]
.
Status
.
Height
)
}
b
.
rcvCommitTxCh
<-
commits
b
.
rcvCommitTxCh
<-
commits
return
nil
return
nil
...
@@ -415,6 +421,9 @@ func aggregateSigns(signs [][]byte) (*g2pubs.Signature, error) {
...
@@ -415,6 +421,9 @@ func aggregateSigns(signs [][]byte) (*g2pubs.Signature, error) {
}
}
func
(
b
*
blsClient
)
updatePeers
(
id
string
,
add
bool
)
{
func
(
b
*
blsClient
)
updatePeers
(
id
string
,
add
bool
)
{
b
.
mutex
.
Lock
()
defer
b
.
mutex
.
Unlock
()
if
_
,
ok
:=
b
.
peers
[
id
];
ok
{
if
_
,
ok
:=
b
.
peers
[
id
];
ok
{
if
!
add
{
if
!
add
{
delete
(
b
.
peers
,
id
)
delete
(
b
.
peers
,
id
)
...
@@ -451,6 +460,19 @@ func getBlsPriKey(key []byte) *g2pubs.SecretKey {
...
@@ -451,6 +460,19 @@ func getBlsPriKey(key []byte) *g2pubs.SecretKey {
}
}
//transfer secp Private key to bls pub key
func
secpPrikey2BlsPub
(
key
string
)
(
string
,
error
)
{
secpPrkKey
,
err
:=
getSecpPriKey
(
key
)
if
err
!=
nil
{
plog
.
Error
(
"getSecpPriKey"
,
"err"
,
err
)
return
""
,
err
}
blsPriKey
:=
getBlsPriKey
(
secpPrkKey
.
Bytes
())
blsPubKey
:=
g2pubs
.
PrivToPub
(
blsPriKey
)
serial
:=
blsPubKey
.
Serialize
()
return
common
.
ToHex
(
serial
[
:
]),
nil
}
func
(
b
*
blsClient
)
blsSign
(
commits
[]
*
pt
.
ParacrossCommitAction
)
error
{
func
(
b
*
blsClient
)
blsSign
(
commits
[]
*
pt
.
ParacrossCommitAction
)
error
{
for
_
,
cmt
:=
range
commits
{
for
_
,
cmt
:=
range
commits
{
data
:=
types
.
Encode
(
cmt
.
Status
)
data
:=
types
.
Encode
(
cmt
.
Status
)
...
@@ -509,6 +531,9 @@ func isCommitDone(nodes, mostSame int) bool {
...
@@ -509,6 +531,9 @@ func isCommitDone(nodes, mostSame int) bool {
}
}
func
(
b
*
blsClient
)
getBlsPubKey
(
addr
string
)
(
*
g2pubs
.
PublicKey
,
error
)
{
func
(
b
*
blsClient
)
getBlsPubKey
(
addr
string
)
(
*
g2pubs
.
PublicKey
,
error
)
{
b
.
mutex
.
Lock
()
defer
b
.
mutex
.
Unlock
()
//先从缓存中获取
//先从缓存中获取
if
v
,
ok
:=
b
.
peersBlsPubKey
[
addr
];
ok
{
if
v
,
ok
:=
b
.
peersBlsPubKey
[
addr
];
ok
{
return
v
,
nil
return
v
,
nil
...
...
plugin/consensus/para/parablssign_test.go
0 → 100644
View file @
d9986fc5
// 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
(
"testing"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/magiconair/properties/assert"
)
func
TestSetAddrsBitMap
(
t
*
testing
.
T
)
{
nodes
:=
[]
string
{
"aa"
,
"bb"
,
"cc"
,
"dd"
}
addrs
:=
[]
string
{}
rst
,
rem
:=
setAddrsBitMap
(
nodes
,
addrs
)
assert
.
Equal
(
t
,
len
(
rst
),
0
)
assert
.
Equal
(
t
,
len
(
rem
),
0
)
addrs
=
[]
string
{
"aa"
}
rst
,
rem
=
setAddrsBitMap
(
nodes
,
addrs
)
assert
.
Equal
(
t
,
rst
,
[]
byte
{
0x1
})
assert
.
Equal
(
t
,
len
(
rem
),
0
)
addrs
=
[]
string
{
"aa"
,
"cc"
}
rst
,
rem
=
setAddrsBitMap
(
nodes
,
addrs
)
assert
.
Equal
(
t
,
rst
,
[]
byte
{
0x5
})
assert
.
Equal
(
t
,
len
(
rem
),
0
)
addrs
=
[]
string
{
"aa"
,
"cc"
,
"dd"
}
rst
,
rem
=
setAddrsBitMap
(
nodes
,
addrs
)
assert
.
Equal
(
t
,
rst
,
[]
byte
{
0xd
})
assert
.
Equal
(
t
,
len
(
rem
),
0
)
}
func
TestIntegrateCommits
(
t
*
testing
.
T
)
{
pool
:=
make
(
map
[
int64
]
*
pt
.
ParaBlsSignSumDetails
)
var
commits
[]
*
pt
.
ParacrossCommitAction
cmt1
:=
&
pt
.
ParacrossCommitAction
{
Status
:
&
pt
.
ParacrossNodeStatus
{
Height
:
0
},
Bls
:
&
pt
.
ParacrossCommitBlsInfo
{
Addrs
:
[]
string
{
"aa"
},
Sign
:
[]
byte
{}},
}
cmt2
:=
&
pt
.
ParacrossCommitAction
{
Status
:
&
pt
.
ParacrossNodeStatus
{
Height
:
0
},
Bls
:
&
pt
.
ParacrossCommitBlsInfo
{
Addrs
:
[]
string
{
"bb"
},
Sign
:
[]
byte
{}},
}
commits
=
[]
*
pt
.
ParacrossCommitAction
{
cmt1
,
cmt1
,
cmt1
,
cmt2
,
cmt1
}
integrateCommits
(
pool
,
commits
)
assert
.
Equal
(
t
,
len
(
pool
[
0
]
.
Addrs
),
2
)
assert
.
Equal
(
t
,
len
(
pool
[
0
]
.
Msgs
),
2
)
assert
.
Equal
(
t
,
len
(
pool
[
0
]
.
Signs
),
2
)
assert
.
Equal
(
t
,
pool
[
0
]
.
Addrs
[
0
],
"aa"
)
assert
.
Equal
(
t
,
pool
[
0
]
.
Addrs
[
1
],
"bb"
)
}
func
TestSecpPrikey2BlsPub
(
t
*
testing
.
T
)
{
key
:=
""
ret
,
_
:=
secpPrikey2BlsPub
(
key
)
assert
.
Equal
(
t
,
""
,
ret
)
key
=
"0xcacb1f5d51700aea07fca2246ab43b0917d70405c65edea9b5063d72eb5c6b71"
q
:=
"0x87c58bb6cce41842462a0030335bb95948dcfba77e47e2d8ee893c0b2c34ac20d08c9e98a883ef2a6492d0ad808ace9a1730e8bae5d3b0861aaf743449df5de510073e2991c7274cab47f327e48d7eacf300e4b24174dae2e8603d1904b8a015"
ret
,
_
=
secpPrikey2BlsPub
(
key
)
assert
.
Equal
(
t
,
q
,
ret
)
}
plugin/consensus/para/paracommitmsg.go
View file @
d9986fc5
...
@@ -328,7 +328,7 @@ func (client *commitMsgClient) checkConsensusStop(checks *commitCheckParams) {
...
@@ -328,7 +328,7 @@ func (client *commitMsgClient) checkConsensusStop(checks *commitCheckParams) {
if
client
.
sendingHeight
>
consensHeight
{
if
client
.
sendingHeight
>
consensHeight
{
checks
.
consensStopTimes
++
checks
.
consensStopTimes
++
if
checks
.
consensStopTimes
>
client
.
waitConsensStopTimes
{
if
checks
.
consensStopTimes
>
client
.
waitConsensStopTimes
{
plog
.
Debug
(
"para c
ommitMsg-checkConsensusStop"
,
"times"
,
checks
.
consensStopTimes
)
plog
.
Debug
(
"para c
heckConsensusStop"
,
"times"
,
checks
.
consensStopTimes
,
"consens"
,
consensHeight
,
"send"
,
client
.
sendingHeight
)
checks
.
consensStopTimes
=
0
checks
.
consensStopTimes
=
0
client
.
resetSendEnv
()
client
.
resetSendEnv
()
}
}
...
@@ -961,24 +961,33 @@ func (client *commitMsgClient) onWalletAccount(acc *types.Account) {
...
@@ -961,24 +961,33 @@ func (client *commitMsgClient) onWalletAccount(acc *types.Account) {
}
}
func
(
client
*
commitMsgClient
)
fetchPriKey
()
error
{
func
getSecpPriKey
(
key
string
)
(
crypto
.
PrivKey
,
error
)
{
req
:=
&
types
.
ReqString
{
Data
:
client
.
authAccount
}
pk
,
err
:=
common
.
FromHex
(
key
)
resp
,
err
:=
client
.
paraClient
.
GetAPI
()
.
ExecWalletFunc
(
"wallet"
,
"DumpPrivkey"
,
req
)
str
:=
resp
.
(
*
types
.
ReplyString
)
.
Data
pk
,
err
:=
common
.
FromHex
(
str
)
if
err
!=
nil
&&
pk
==
nil
{
if
err
!=
nil
&&
pk
==
nil
{
return
err
return
nil
,
errors
.
Wrapf
(
err
,
"fromhex=%s"
,
key
)
}
}
secp
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
secp
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
nil
,
errors
.
Wrapf
(
err
,
"crypto=%s"
,
key
)
}
}
priKey
,
err
:=
secp
.
PrivKeyFromBytes
(
pk
)
priKey
,
err
:=
secp
.
PrivKeyFromBytes
(
pk
)
if
err
!=
nil
{
if
err
!=
nil
{
plog
.
Error
(
"para commit msg get priKey"
,
"err"
,
err
.
Error
())
return
nil
,
errors
.
Wrapf
(
err
,
"fromBytes=%s"
,
key
)
}
return
priKey
,
nil
}
func
(
client
*
commitMsgClient
)
fetchPriKey
()
error
{
req
:=
&
types
.
ReqString
{
Data
:
client
.
authAccount
}
resp
,
err
:=
client
.
paraClient
.
GetAPI
()
.
ExecWalletFunc
(
"wallet"
,
"DumpPrivkey"
,
req
)
str
:=
resp
.
(
*
types
.
ReplyString
)
.
Data
priKey
,
err
:=
getSecpPriKey
(
str
)
if
err
!=
nil
{
plog
.
Error
(
"para commit msg get priKey"
,
"err"
,
err
)
return
err
return
err
}
}
...
...
plugin/consensus/para/paraquery.go
View file @
d9986fc5
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
package
para
package
para
import
(
import
(
"errors"
"fmt"
"fmt"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
...
@@ -72,6 +73,30 @@ func (client *client) Query_CommitTxInfo(req *types.ReqNil) (types.Message, erro
...
@@ -72,6 +73,30 @@ func (client *client) Query_CommitTxInfo(req *types.ReqNil) (types.Message, erro
return
rt
,
nil
return
rt
,
nil
}
}
func
(
client
*
client
)
Query_BlsPubKey
(
req
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
if
client
==
nil
||
req
==
nil
{
return
nil
,
fmt
.
Errorf
(
"%s"
,
"client not bind message queue."
)
}
var
pub
pt
.
BlsPubKey
if
len
(
req
.
Data
)
>
0
{
p
,
err
:=
secpPrikey2BlsPub
(
req
.
Data
)
if
err
!=
nil
{
return
nil
,
err
}
pub
.
Key
=
p
return
&
pub
,
nil
}
//缺省获取钱包的
if
nil
!=
client
.
blsSignCli
.
blsPubKey
{
t
:=
client
.
blsSignCli
.
blsPubKey
.
Serialize
()
pub
.
Key
=
common
.
ToHex
(
t
[
:
])
return
&
pub
,
nil
}
return
nil
,
errors
.
New
(
"no bls prikey init"
)
}
// Query_CreateNewAccount 通知para共识模块钱包创建了一个新的账户
// Query_CreateNewAccount 通知para共识模块钱包创建了一个新的账户
func
(
client
*
client
)
Query_CreateNewAccount
(
acc
*
types
.
Account
)
(
types
.
Message
,
error
)
{
func
(
client
*
client
)
Query_CreateNewAccount
(
acc
*
types
.
Account
)
(
types
.
Message
,
error
)
{
if
acc
==
nil
{
if
acc
==
nil
{
...
...
plugin/dapp/paracross/cmd/build/testcase.sh
View file @
d9986fc5
This diff is collapsed.
Click to expand it.
plugin/dapp/paracross/commands/paracross.go
View file @
d9986fc5
...
@@ -44,8 +44,7 @@ func ParcCmd() *cobra.Command {
...
@@ -44,8 +44,7 @@ func ParcCmd() *cobra.Command {
GetBlockInfoCmd
(),
GetBlockInfoCmd
(),
GetLocalBlockInfoCmd
(),
GetLocalBlockInfoCmd
(),
GetConsensDoneInfoCmd
(),
GetConsensDoneInfoCmd
(),
LeaderCmd
(),
blsCmd
(),
CmtTxInfoCmd
(),
)
)
return
cmd
return
cmd
}
}
...
@@ -315,7 +314,7 @@ func createCrossAssetTransfer(cmd *cobra.Command, args []string) {
...
@@ -315,7 +314,7 @@ func createCrossAssetTransfer(cmd *cobra.Command, args []string) {
func
superNodeCmd
()
*
cobra
.
Command
{
func
superNodeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"
super_
node"
,
Use
:
"node"
,
Short
:
"super node manage cmd"
,
Short
:
"super node manage cmd"
,
}
}
cmd
.
AddCommand
(
nodeJoinCmd
())
cmd
.
AddCommand
(
nodeJoinCmd
())
...
@@ -953,11 +952,22 @@ func isSync(cmd *cobra.Command, args []string) {
...
@@ -953,11 +952,22 @@ func isSync(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
// IsSyncCmd query parachain is sync
func
blsCmd
()
*
cobra
.
Command
{
func
LeaderCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"bls"
,
Short
:
"bls sign manager cmd"
,
}
cmd
.
AddCommand
(
leaderCmd
())
cmd
.
AddCommand
(
cmtTxInfoCmd
())
cmd
.
AddCommand
(
blsPubKeyCmd
())
return
cmd
}
// leaderCmd query parachain is sync
func
leaderCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"leader"
,
Use
:
"leader"
,
Short
:
"
node leader info
"
,
Short
:
"
current bls sign leader
"
,
Run
:
leaderInfo
,
Run
:
leaderInfo
,
}
}
return
cmd
return
cmd
...
@@ -970,11 +980,11 @@ func leaderInfo(cmd *cobra.Command, args []string) {
...
@@ -970,11 +980,11 @@ func leaderInfo(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
//
IsSync
Cmd query parachain is sync
//
cmtTxInfo
Cmd query parachain is sync
func
C
mtTxInfoCmd
()
*
cobra
.
Command
{
func
c
mtTxInfoCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"cmt
info
"
,
Use
:
"cmt
s
"
,
Short
:
"c
ommit tx
info"
,
Short
:
"c
urrent bls sign commits
info"
,
Run
:
cmtTxInfo
,
Run
:
cmtTxInfo
,
}
}
return
cmd
return
cmd
...
@@ -987,6 +997,27 @@ func cmtTxInfo(cmd *cobra.Command, args []string) {
...
@@ -987,6 +997,27 @@ func cmtTxInfo(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
// cmtTxInfoCmd query parachain is sync
func
blsPubKeyCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"pubkey"
,
Short
:
"get bls pub key by secp256 prikey or current wallet bls pubkey"
,
Run
:
blsPubKey
,
}
return
cmd
}
func
blsPubKey
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
cmd
.
Flags
()
.
StringP
(
"prikey"
,
"p"
,
""
,
"secp256 private key"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
prikey
,
_
:=
cmd
.
Flags
()
.
GetString
(
"prikey"
)
req
:=
&
types
.
ReqString
{
Data
:
prikey
}
var
res
pt
.
BlsPubKey
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"paracross.GetParaBlsPubKey"
,
req
,
&
res
)
ctx
.
Run
()
}
func
consusHeight
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
consusHeight
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
...
...
plugin/dapp/paracross/executor/action.go
View file @
d9986fc5
...
@@ -412,14 +412,9 @@ func getValidAddrs(nodes map[string]struct{}, addrs []string) []string {
...
@@ -412,14 +412,9 @@ func getValidAddrs(nodes map[string]struct{}, addrs []string) []string {
return
ret
return
ret
}
}
//bls签名共识交易验证 大约耗时100ms
//bls签名共识交易验证 大约平均耗时30ms (20~40ms)
func
(
a
*
action
)
verifyBlsSign
(
commit
*
pt
.
ParacrossCommitAction
)
([]
string
,
error
)
{
func
(
a
*
action
)
verifyBlsSign
(
nodesArry
[]
string
,
commit
*
pt
.
ParacrossCommitAction
)
([]
string
,
error
)
{
_
,
nodesArry
,
err
:=
a
.
getNodesGroup
(
commit
.
Status
.
Title
)
//1. 获取addr对应的bls 公钥 单独耗时3ms (3 addrs)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"getNodegroup"
)
}
//1. 获取addr对应的bls 公钥
signAddrs
:=
getAddrsByBitMap
(
nodesArry
,
commit
.
Bls
.
AddrsMap
)
signAddrs
:=
getAddrsByBitMap
(
nodesArry
,
commit
.
Bls
.
AddrsMap
)
var
pubs
[]
string
var
pubs
[]
string
for
_
,
addr
:=
range
signAddrs
{
for
_
,
addr
:=
range
signAddrs
{
...
@@ -429,6 +424,7 @@ func (a *action) verifyBlsSign(commit *pt.ParacrossCommitAction) ([]string, erro
...
@@ -429,6 +424,7 @@ func (a *action) verifyBlsSign(commit *pt.ParacrossCommitAction) ([]string, erro
}
}
pubs
=
append
(
pubs
,
pub
)
pubs
=
append
(
pubs
,
pub
)
}
}
//单独deserial 5ms, g2pubs的公钥结构不好整合到protobuf,就不好压缩到数据库直接读取
pubKeys
:=
make
([]
*
g2pubs
.
PublicKey
,
0
)
pubKeys
:=
make
([]
*
g2pubs
.
PublicKey
,
0
)
for
_
,
p
:=
range
pubs
{
for
_
,
p
:=
range
pubs
{
k
:=
[
96
]
byte
{}
k
:=
[
96
]
byte
{}
...
@@ -444,10 +440,11 @@ func (a *action) verifyBlsSign(commit *pt.ParacrossCommitAction) ([]string, erro
...
@@ -444,10 +440,11 @@ func (a *action) verifyBlsSign(commit *pt.ParacrossCommitAction) ([]string, erro
pubKeys
=
append
(
pubKeys
,
key
)
pubKeys
=
append
(
pubKeys
,
key
)
}
}
//2. 聚合公钥
//2. 聚合公钥 单独耗时200us
aPub
:=
g2pubs
.
AggregatePublicKeys
(
pubKeys
)
aPub
:=
g2pubs
.
AggregatePublicKeys
(
pubKeys
)
//3. 获取聚合的签名
//3. 获取聚合的签名
, deserial 5ms
signkey
:=
[
48
]
byte
{}
signkey
:=
[
48
]
byte
{}
copy
(
signkey
[
:
],
commit
.
Bls
.
Sign
)
copy
(
signkey
[
:
],
commit
.
Bls
.
Sign
)
sign
,
err
:=
g2pubs
.
DeserializeSignature
(
signkey
)
sign
,
err
:=
g2pubs
.
DeserializeSignature
(
signkey
)
...
@@ -478,27 +475,27 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
...
@@ -478,27 +475,27 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
}
}
}
}
nodesMap
,
nodesArry
,
err
:=
a
.
getNodesGroup
(
commit
.
Status
.
Title
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"getNodesGroup"
)
}
//获取commitAddrs, bls sign 包含多个账户的聚合签名
//获取commitAddrs, bls sign 包含多个账户的聚合签名
commitAddrs
:=
[]
string
{
a
.
fromaddr
}
commitAddrs
:=
[]
string
{
a
.
fromaddr
}
if
commit
.
Bls
!=
nil
{
if
commit
.
Bls
!=
nil
{
addrs
,
err
:=
a
.
verifyBlsSign
(
commit
)
addrs
,
err
:=
a
.
verifyBlsSign
(
nodesArry
,
commit
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"verifyBlsSign"
)
return
nil
,
errors
.
Wrap
(
err
,
"verifyBlsSign"
)
}
}
commitAddrs
=
addrs
commitAddrs
=
addrs
}
}
nodesMap
,
_
,
err
:=
a
.
getNodesGroup
(
commit
.
Status
.
Title
)
validAddrs
:=
getValidAddrs
(
nodesMap
,
commitAddrs
)
if
err
!=
nil
{
if
len
(
validAddrs
)
<=
0
{
return
nil
,
errors
.
Wrap
(
err
,
"getNodesGroup"
)
}
correctAddrs
:=
getValidAddrs
(
nodesMap
,
commitAddrs
)
if
len
(
correctAddrs
)
<=
0
{
return
nil
,
errors
.
Wrapf
(
err
,
"getValidAddrs nil commitAddrs=%s"
,
strings
.
Join
(
commitAddrs
,
","
))
return
nil
,
errors
.
Wrapf
(
err
,
"getValidAddrs nil commitAddrs=%s"
,
strings
.
Join
(
commitAddrs
,
","
))
}
}
return
a
.
proCommitMsg
(
commit
.
Status
,
nodesMap
,
correct
Addrs
)
return
a
.
proCommitMsg
(
commit
.
Status
,
nodesMap
,
valid
Addrs
)
}
}
func
(
a
*
action
)
proCommitMsg
(
commit
*
pt
.
ParacrossNodeStatus
,
nodes
map
[
string
]
struct
{},
commitAddrs
[]
string
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
proCommitMsg
(
commit
*
pt
.
ParacrossNodeStatus
,
nodes
map
[
string
]
struct
{},
commitAddrs
[]
string
)
(
*
types
.
Receipt
,
error
)
{
...
...
plugin/dapp/paracross/proto/paracross.proto
View file @
d9986fc5
...
@@ -449,11 +449,15 @@ message ParaP2PSubMsg {
...
@@ -449,11 +449,15 @@ message ParaP2PSubMsg {
}
}
//bls sign leader info
message
ElectionStatus
{
message
ElectionStatus
{
bool
isLeader
=
1
;
bool
isLeader
=
1
;
LeaderSyncInfo
leader
=
2
;
LeaderSyncInfo
leader
=
2
;
}
}
message
BlsPubKey
{
string
key
=
1
;
}
service
paracross
{
service
paracross
{
rpc
IsSync
(
ReqNil
)
returns
(
IsCaughtUp
)
{}
rpc
IsSync
(
ReqNil
)
returns
(
IsCaughtUp
)
{}
...
...
plugin/dapp/paracross/rpc/rpc.go
View file @
d9986fc5
...
@@ -53,7 +53,7 @@ func (c *Jrpc) GetParaLocalBlockInfo(in *types.ReqInt, result *interface{}) erro
...
@@ -53,7 +53,7 @@ func (c *Jrpc) GetParaLocalBlockInfo(in *types.ReqInt, result *interface{}) erro
return
nil
return
nil
}
}
// GetPara
LocalBlockInfo query para chain the download layer's local height
// GetPara
NodeLeaderInfo query para bls sign leader info
func
(
c
*
channelClient
)
GetParaNodeLeaderInfo
(
ctx
context
.
Context
,
in
*
types
.
ReqNil
)
(
*
pt
.
ElectionStatus
,
error
)
{
func
(
c
*
channelClient
)
GetParaNodeLeaderInfo
(
ctx
context
.
Context
,
in
*
types
.
ReqNil
)
(
*
pt
.
ElectionStatus
,
error
)
{
data
,
err
:=
c
.
QueryConsensusFunc
(
"para"
,
"LeaderInfo"
,
in
)
data
,
err
:=
c
.
QueryConsensusFunc
(
"para"
,
"LeaderInfo"
,
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -62,7 +62,7 @@ func (c *channelClient) GetParaNodeLeaderInfo(ctx context.Context, in *types.Req
...
@@ -62,7 +62,7 @@ func (c *channelClient) GetParaNodeLeaderInfo(ctx context.Context, in *types.Req
return
data
.
(
*
pt
.
ElectionStatus
),
nil
return
data
.
(
*
pt
.
ElectionStatus
),
nil
}
}
// GetPara
LocalBlockInfo query para local height
// GetPara
NodeLeaderInfo query para bls sign leader info
func
(
c
*
Jrpc
)
GetParaNodeLeaderInfo
(
in
*
types
.
ReqNil
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
GetParaNodeLeaderInfo
(
in
*
types
.
ReqNil
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
GetParaNodeLeaderInfo
(
context
.
Background
(),
in
)
data
,
err
:=
c
.
cli
.
GetParaNodeLeaderInfo
(
context
.
Background
(),
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -72,7 +72,7 @@ func (c *Jrpc) GetParaNodeLeaderInfo(in *types.ReqNil, result *interface{}) erro
...
@@ -72,7 +72,7 @@ func (c *Jrpc) GetParaNodeLeaderInfo(in *types.ReqNil, result *interface{}) erro
return
nil
return
nil
}
}
// GetPara
LocalBlockInfo query para chain the download layer's local height
// GetPara
CmtTxInfo query para chain commit tx info to bls sign
func
(
c
*
channelClient
)
GetParaCmtTxInfo
(
ctx
context
.
Context
,
in
*
types
.
ReqNil
)
(
*
pt
.
ParaBlsSignSumInfo
,
error
)
{
func
(
c
*
channelClient
)
GetParaCmtTxInfo
(
ctx
context
.
Context
,
in
*
types
.
ReqNil
)
(
*
pt
.
ParaBlsSignSumInfo
,
error
)
{
data
,
err
:=
c
.
QueryConsensusFunc
(
"para"
,
"CommitTxInfo"
,
in
)
data
,
err
:=
c
.
QueryConsensusFunc
(
"para"
,
"CommitTxInfo"
,
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -81,7 +81,7 @@ func (c *channelClient) GetParaCmtTxInfo(ctx context.Context, in *types.ReqNil)
...
@@ -81,7 +81,7 @@ func (c *channelClient) GetParaCmtTxInfo(ctx context.Context, in *types.ReqNil)
return
data
.
(
*
pt
.
ParaBlsSignSumInfo
),
nil
return
data
.
(
*
pt
.
ParaBlsSignSumInfo
),
nil
}
}
// GetPara
LocalBlockInfo query para local height
// GetPara
CmtTxInfo query para commit tx info
func
(
c
*
Jrpc
)
GetParaCmtTxInfo
(
in
*
types
.
ReqNil
,
result
*
interface
{})
error
{
func
(
c
*
Jrpc
)
GetParaCmtTxInfo
(
in
*
types
.
ReqNil
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
GetParaCmtTxInfo
(
context
.
Background
(),
in
)
data
,
err
:=
c
.
cli
.
GetParaCmtTxInfo
(
context
.
Background
(),
in
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -90,3 +90,22 @@ func (c *Jrpc) GetParaCmtTxInfo(in *types.ReqNil, result *interface{}) error {
...
@@ -90,3 +90,22 @@ func (c *Jrpc) GetParaCmtTxInfo(in *types.ReqNil, result *interface{}) error {
*
result
=
data
*
result
=
data
return
nil
return
nil
}
}
// GetParaBlsPubKey query para chain bls pubkey
func
(
c
*
channelClient
)
GetParaBlsPubKey
(
ctx
context
.
Context
,
in
*
types
.
ReqString
)
(
*
pt
.
BlsPubKey
,
error
)
{
data
,
err
:=
c
.
QueryConsensusFunc
(
"para"
,
"BlsPubKey"
,
in
)
if
err
!=
nil
{
return
nil
,
err
}
return
data
.
(
*
pt
.
BlsPubKey
),
nil
}
// GetParaBlsPubKey query para local height
func
(
c
*
Jrpc
)
GetParaBlsPubKey
(
in
*
types
.
ReqString
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
GetParaBlsPubKey
(
context
.
Background
(),
in
)
if
err
!=
nil
{
return
err
}
*
result
=
data
return
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