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
6ebd67fb
Commit
6ebd67fb
authored
Sep 16, 2020
by
QM
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bls sign
parent
777b2619
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
156 additions
and
33 deletions
+156
-33
parablssign.go
plugin/consensus/para/parablssign.go
+26
-1
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+21
-0
action.go
plugin/dapp/paracross/executor/action.go
+61
-22
query.go
plugin/dapp/paracross/executor/query.go
+31
-0
superaccount.go
plugin/dapp/paracross/executor/superaccount.go
+0
-9
supervisionaccount.go
plugin/dapp/paracross/executor/supervisionaccount.go
+10
-1
paracross.go
plugin/dapp/paracross/types/paracross.go
+7
-0
No files found.
plugin/consensus/para/parablssign.go
View file @
6ebd67fb
...
...
@@ -170,7 +170,23 @@ func (b *blsClient) getLeaderInfo() ([]string, int32, int32, int32, bool) {
offIdx
:=
atomic
.
LoadInt32
(
&
b
.
leaderOffset
)
leaderIdx
:=
(
baseIdx
+
offIdx
)
%
int32
(
len
(
nodes
))
return
nodes
,
leaderIdx
,
baseIdx
,
offIdx
,
nodes
[
leaderIdx
]
==
b
.
selfID
}
func
(
b
*
blsClient
)
getSupervisionLeaderInfo
()
([]
string
,
int32
,
int32
,
int32
,
bool
)
{
//在未同步前 不处理聚合消息
if
!
b
.
paraClient
.
commitMsgClient
.
isSync
()
{
return
nil
,
0
,
0
,
0
,
false
}
supervisionNodes
,
_
:=
b
.
getSupervisionSuperNodes
()
if
len
(
supervisionNodes
)
<=
0
{
return
nil
,
0
,
0
,
0
,
false
}
h
:=
b
.
paraClient
.
commitMsgClient
.
getConsensusHeight
()
//间隔的除数再根据nodes取余数,平均覆盖所有节点
baseIdx
:=
int32
((
h
/
int64
(
b
.
leaderSwitchInt
))
%
int64
(
len
(
supervisionNodes
)))
offIdx
:=
atomic
.
LoadInt32
(
&
b
.
leaderOffset
)
leaderIdx
:=
(
baseIdx
+
offIdx
)
%
int32
(
len
(
supervisionNodes
))
return
supervisionNodes
,
leaderIdx
,
baseIdx
,
offIdx
,
supervisionNodes
[
leaderIdx
]
==
b
.
selfID
}
func
(
b
*
blsClient
)
getSuperNodes
()
([]
string
,
string
)
{
...
...
@@ -181,6 +197,15 @@ func (b *blsClient) getSuperNodes() ([]string, string) {
return
strings
.
Split
(
nodeStr
,
","
),
nodeStr
}
// 获取监督节点
func
(
b
*
blsClient
)
getSupervisionSuperNodes
()
([]
string
,
string
)
{
nodeStr
,
err
:=
b
.
paraClient
.
commitMsgClient
.
getSupervisionNodeGroupAddrs
()
if
err
!=
nil
{
return
nil
,
""
}
return
strings
.
Split
(
nodeStr
,
","
),
nodeStr
}
func
(
b
*
blsClient
)
isValidNodes
(
id
string
)
bool
{
_
,
nodes
:=
b
.
getSuperNodes
()
return
strings
.
Contains
(
nodes
,
id
)
...
...
@@ -209,7 +234,7 @@ out:
//自己是Leader,则聚合并发送交易
_
,
_
,
_
,
_
,
isLeader
:=
b
.
getLeaderInfo
()
if
isLeader
{
b
.
sendAggregateTx
(
nodes
)
_
=
b
.
sendAggregateTx
(
nodes
)
}
//聚合签名总共消耗大约1.5ms
//清空txsBuff,重新收集
...
...
plugin/consensus/para/paracommitmsg.go
View file @
6ebd67fb
...
...
@@ -929,6 +929,27 @@ func (client *commitMsgClient) getNodeGroupAddrs() (string, error) {
return
resp
.
Value
,
nil
}
//Supervision node group会在主链和平行链都同时配置,只本地查询就可以
func
(
client
*
commitMsgClient
)
getSupervisionNodeGroupAddrs
()
(
string
,
error
)
{
cfg
:=
client
.
paraClient
.
GetAPI
()
.
GetConfig
()
ret
,
err
:=
client
.
paraClient
.
GetAPI
()
.
QueryChain
(
&
types
.
ChainExecutor
{
Driver
:
"paracross"
,
FuncName
:
"GetSupervisionNodeGroupAddrs"
,
Param
:
types
.
Encode
(
&
pt
.
ReqParacrossNodeInfo
{
Title
:
cfg
.
GetTitle
()}),
})
if
err
!=
nil
{
plog
.
Error
(
"commitmsg.getSupervisionNodeGroupAddrs "
,
"err"
,
err
.
Error
())
return
""
,
err
}
resp
,
ok
:=
ret
.
(
*
types
.
ReplyConfig
)
if
!
ok
{
plog
.
Error
(
"commitmsg.getSupervisionNodeGroupAddrs rsp nok"
)
return
""
,
err
}
return
resp
.
Value
,
nil
}
func
(
client
*
commitMsgClient
)
onWalletStatus
(
status
*
types
.
WalletStatus
)
{
if
status
==
nil
||
client
.
authAccount
==
""
{
plog
.
Info
(
"para onWalletStatus"
,
"status"
,
status
==
nil
,
"auth"
,
client
.
authAccount
==
""
)
...
...
plugin/dapp/paracross/executor/action.go
View file @
6ebd67fb
...
...
@@ -300,15 +300,20 @@ func (a *action) getNodesGroup(title string) (map[string]struct{}, []string, err
return
nodes
,
nodesArray
,
err
}
func
(
a
*
action
)
getSupervisionNodesGroup
(
title
string
)
(
map
[
string
]
struct
{},
[]
string
,
error
)
{
func
getSupervisionConfigNodes
(
db
dbm
.
KV
,
title
string
)
(
map
[
string
]
struct
{},
[]
string
,
[]
byte
,
error
)
{
key
:=
calcParaSupervisionNodeGroupAddrsKey
(
title
)
nodes
,
nodesArray
,
err
:=
getNodes
(
a
.
db
,
key
)
nodes
,
nodesArray
,
err
:=
getNodes
(
db
,
key
)
if
err
!=
nil
{
if
errors
.
Cause
(
err
)
!=
pt
.
ErrTitleNotExist
{
return
nil
,
nil
,
errors
.
Wrapf
(
err
,
"getSupervisionNodesGroup para for title:%s"
,
title
)
return
nil
,
nil
,
nil
,
errors
.
Wrapf
(
err
,
"getSupervisionNodesGroup para for title:%s"
,
title
)
}
}
return
nodes
,
nodesArray
,
key
,
nil
}
func
(
a
*
action
)
getSupervisionNodesGroup
(
title
string
)
(
map
[
string
]
struct
{},
[]
string
,
error
)
{
nodes
,
nodesArray
,
_
,
err
:=
getSupervisionConfigNodes
(
a
.
db
,
title
)
return
nodes
,
nodesArray
,
err
}
...
...
@@ -446,12 +451,31 @@ func getValidAddrs(nodes map[string]struct{}, addrs []string) []string {
return
ret
}
//get secp256 addr's bls pubkey
func
getAddrBlsPubKey
(
db
dbm
.
KV
,
title
,
addr
string
,
commitNodeType
uint32
)
(
string
,
error
)
{
if
commitNodeType
==
pt
.
ParaCommitSuperNode
{
addrStat
,
err
:=
getNodeAddr
(
db
,
title
,
addr
)
if
err
!=
nil
{
return
""
,
errors
.
Wrapf
(
err
,
"nodeAddr:%s-%s get error"
,
title
,
addr
)
}
return
addrStat
.
BlsPubKey
,
nil
}
else
if
commitNodeType
==
pt
.
ParaCommitSupervisionNode
{
addrStat
,
err
:=
getSupervisionNodeAddr
(
db
,
title
,
addr
)
if
err
!=
nil
{
return
""
,
errors
.
Wrapf
(
err
,
"Supervision nodeAddr:%s-%s get error"
,
title
,
addr
)
}
return
addrStat
.
BlsPubKey
,
nil
}
else
{
return
""
,
errors
.
New
(
"commitNodeType is ParaCommitNode"
)
}
}
//bls签名共识交易验证 大约平均耗时3ms (2~4ms)
func
(
a
*
action
)
procBlsSign
(
nodesArry
[]
string
,
commit
*
pt
.
ParacrossCommitAction
)
([]
string
,
error
)
{
func
(
a
*
action
)
procBlsSign
(
nodesArry
[]
string
,
commit
*
pt
.
ParacrossCommitAction
,
commitNodeType
uint32
)
([]
string
,
error
)
{
signAddrs
:=
util
.
GetAddrsByBitMap
(
nodesArry
,
commit
.
Bls
.
AddrsMap
)
var
pubs
[]
string
for
_
,
addr
:=
range
signAddrs
{
pub
,
err
:=
getAddrBlsPubKey
(
a
.
db
,
commit
.
Status
.
Title
,
addr
)
pub
,
err
:=
getAddrBlsPubKey
(
a
.
db
,
commit
.
Status
.
Title
,
addr
,
commitNodeType
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"pubkey not exist to addr=%s"
,
addr
)
}
...
...
@@ -521,35 +545,50 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
return
nil
,
errors
.
Wrap
(
err
,
"getNodesGroup"
)
}
//获取commitAddrs, bls sign 包含多个账户的聚合签名
commitAddrs
:=
[]
string
{
a
.
fromaddr
}
if
commit
.
Bls
!=
nil
{
addrs
,
err
:=
a
.
procBlsSign
(
nodesArry
,
commit
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"procBlsSign"
)
var
commitAddrs
,
commitSupervisionAddrs
,
validAddrs
,
supervisionValidAddrs
[]
string
for
_
,
addr
:=
range
nodesArry
{
if
addr
==
a
.
fromaddr
{
// 授权节点共识
//获取commitAddrs, bls sign 包含多个账户的聚合签名
commitAddrs
=
[]
string
{
a
.
fromaddr
}
if
commit
.
Bls
!=
nil
{
addrs
,
err
:=
a
.
procBlsSign
(
nodesArry
,
commit
,
pt
.
ParaCommitSuperNode
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"procBlsSign"
)
}
commitAddrs
=
addrs
}
validAddrs
=
getValidAddrs
(
nodesMap
,
commitAddrs
)
break
}
commitAddrs
=
addrs
}
validAddrs
:=
getValidAddrs
(
nodesMap
,
commitAddrs
)
// 获取监督节点的数据 监督节点在高度分叉后
supervisionNodesMap
,
supervisionNodesArry
,
err
:=
a
.
getSupervisionNodesGroup
(
commit
.
Status
.
Title
)
if
err
!=
nil
&&
errors
.
Cause
(
err
)
!=
pt
.
ErrTitleNotExist
&&
a
.
exec
.
GetMainHeight
()
>=
pt
.
GetDappForkHeight
(
cfg
,
pt
.
ForkCommitTx
)
{
return
nil
,
errors
.
Wrap
(
err
,
"getSupervisionNodesGroup"
)
}
//获取commitAddrs, bls sign 包含多个账户的聚合签名
commitSupervisionAddrs
:=
[]
string
{
a
.
fromaddr
}
if
commit
.
Bls
!=
nil
{
addrs
,
err
:=
a
.
procBlsSign
(
supervisionNodesArry
,
commit
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"procBlsSign"
)
for
_
,
addr
:=
range
supervisionNodesArry
{
if
addr
==
a
.
fromaddr
{
// 监督节点共识
//获取commitAddrs, bls sign 包含多个账户的聚合签名
commitSupervisionAddrs
=
[]
string
{
a
.
fromaddr
}
if
commit
.
Bls
!=
nil
{
addrs
,
err
:=
a
.
procBlsSign
(
supervisionNodesArry
,
commit
,
pt
.
ParaCommitSupervisionNode
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"procBlsSign"
)
}
commitSupervisionAddrs
=
addrs
}
supervisionValidAddrs
=
getValidAddrs
(
supervisionNodesMap
,
commitSupervisionAddrs
)
break
}
commitSupervisionAddrs
=
addrs
}
supervisionValidAddrs
:=
getValidAddrs
(
supervisionNodesMap
,
commitSupervisionAddrs
)
if
len
(
validAddrs
)
<=
0
&&
len
(
supervisionValidAddrs
)
<=
0
{
return
nil
,
errors
.
Wrapf
(
err
,
"getValidAddrs nil commitAddrs=%s commitSupervisionAddrs=%s"
,
strings
.
Join
(
commitAddrs
,
","
),
strings
.
Join
(
commitSupervisionAddrs
,
","
))
}
...
...
plugin/dapp/paracross/executor/query.go
View file @
6ebd67fb
...
...
@@ -95,6 +95,37 @@ func (p *Paracross) Query_GetNodeGroupAddrs(in *pt.ReqParacrossNodeInfo) (types.
return
&
reply
,
nil
}
//Query_GetNodeGroupAddrs get node group addrs
func
(
p
*
Paracross
)
Query_GetSupervisionNodeGroupAddrs
(
in
*
pt
.
ReqParacrossNodeInfo
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
cfg
:=
p
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsPara
()
{
in
.
Title
=
cfg
.
GetTitle
()
}
else
if
in
.
Title
==
""
{
return
nil
,
errors
.
Wrap
(
types
.
ErrInvalidParam
,
"title is null"
)
}
_
,
nodesArry
,
key
,
err
:=
getSupervisionConfigNodes
(
p
.
GetStateDB
(),
in
.
GetTitle
())
if
err
!=
nil
{
return
nil
,
err
}
var
nodes
string
for
_
,
k
:=
range
nodesArry
{
if
len
(
nodes
)
==
0
{
nodes
=
k
continue
}
nodes
=
nodes
+
","
+
k
}
var
reply
types
.
ReplyConfig
reply
.
Key
=
string
(
key
)
reply
.
Value
=
nodes
return
&
reply
,
nil
}
//Query_GetNodeAddrInfo get specific node addr info
func
(
p
*
Paracross
)
Query_GetNodeAddrInfo
(
in
*
pt
.
ReqParacrossNodeInfo
)
(
types
.
Message
,
error
)
{
if
in
==
nil
||
in
.
Addr
==
""
{
...
...
plugin/dapp/paracross/executor/superaccount.go
View file @
6ebd67fb
...
...
@@ -208,15 +208,6 @@ func makeParaNodeGroupReceipt(title string, prev, current *types.ConfigItem) *ty
}
}
//get secp256 addr's bls pubkey
func
getAddrBlsPubKey
(
db
dbm
.
KV
,
title
,
addr
string
)
(
string
,
error
)
{
addrStat
,
err
:=
getNodeAddr
(
db
,
title
,
addr
)
if
err
!=
nil
{
return
""
,
errors
.
Wrapf
(
err
,
"nodeAddr:%s-%s get error"
,
title
,
addr
)
}
return
addrStat
.
BlsPubKey
,
nil
}
func
(
a
*
action
)
checkValidNode
(
config
*
pt
.
ParaNodeAddrConfig
)
(
bool
,
error
)
{
nodes
,
_
,
err
:=
getParacrossNodes
(
a
.
db
,
config
.
Title
)
if
err
!=
nil
{
...
...
plugin/dapp/paracross/executor/supervisionaccount.go
View file @
6ebd67fb
...
...
@@ -299,8 +299,17 @@ func (a *action) updateSupervisionNodeAddrStatus(stat *pt.ParaNodeIdStatus) (*ty
}
func
(
a
*
action
)
supervisionNodeGroupApply
(
config
*
pt
.
ParaNodeAddrConfig
)
(
*
types
.
Receipt
,
error
)
{
// 不能跟授权节点一致
addrExist
,
err
:=
a
.
checkValidNode
(
config
)
if
err
!=
nil
{
return
nil
,
err
}
if
addrExist
{
return
nil
,
errors
.
Wrapf
(
pt
.
ErrParaNodeAddrExisted
,
"nodeAddr existed:%s in super"
,
config
.
Addr
)
}
// 是否已经申请
addrExist
,
err
:
=
a
.
checkValidSupervisionNode
(
config
)
addrExist
,
err
=
a
.
checkValidSupervisionNode
(
config
)
if
err
!=
nil
{
//return nil, err
fmt
.
Println
(
"err:"
,
err
)
...
...
plugin/dapp/paracross/types/paracross.go
View file @
6ebd67fb
...
...
@@ -179,6 +179,13 @@ const (
ParacrossSupervisionNodeQuit
)
// 0 普通节点共识 1 授权节点正在共识 2 监督节点正在共识
const
(
ParaCommitNode
=
iota
ParaCommitSuperNode
ParaCommitSupervisionNode
)
var
(
// ParacrossActionCommitStr Commit string
ParacrossActionCommitStr
=
string
(
"Commit"
)
...
...
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