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
14b1bbc3
Commit
14b1bbc3
authored
May 06, 2019
by
mdj33
Committed by
vipwzw
May 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add para chain wallet mining process
parent
7c3f8b34
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
32 deletions
+62
-32
para.go
plugin/consensus/para/para.go
+3
-2
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+59
-30
No files found.
plugin/consensus/para/para.go
View file @
14b1bbc3
...
...
@@ -156,6 +156,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
commitMsgNotify
:
make
(
chan
int64
,
1
),
delMsgNotify
:
make
(
chan
int64
,
1
),
mainBlockAdd
:
make
(
chan
*
types
.
BlockDetail
,
1
),
minerSwitch
:
make
(
chan
bool
,
1
),
quit
:
make
(
chan
struct
{}),
}
c
.
SetChild
(
para
)
...
...
@@ -818,7 +819,7 @@ func checkMinerTx(current *types.BlockDetail) error {
func
(
client
*
client
)
Query_CreateNewAccount
(
acc
*
types
.
Account
)
(
types
.
Message
,
error
)
{
plog
.
Info
(
"Query_CreateNewAccount"
,
"acc"
,
acc
)
// 需要para共识这边处理新创建的账户是否是超级节点发送commit共识交易的账户
// 需要实现具体处理 to be。。。。
client
.
commitMsgClient
.
onWalletAccount
(
acc
)
return
&
types
.
Reply
{
IsOk
:
true
,
Msg
:
[]
byte
(
"OK"
)},
nil
}
...
...
@@ -826,6 +827,6 @@ func (client *client) Query_CreateNewAccount(acc *types.Account) (types.Message,
func
(
client
*
client
)
Query_WalletStatus
(
walletStatus
*
types
.
WalletStatus
)
(
types
.
Message
,
error
)
{
plog
.
Info
(
"Query_WalletStatus"
,
"walletStatus"
,
walletStatus
)
// 需要para共识这边根据walletStatus.IsWalletLock锁的状态开启/关闭发送共识交易
// 需要实现具体处理 to be。。。。
client
.
commitMsgClient
.
onWalletStatus
(
walletStatus
)
return
&
types
.
Reply
{
IsOk
:
true
,
Msg
:
[]
byte
(
"OK"
)},
nil
}
plugin/consensus/para/paracommitmsg.go
View file @
14b1bbc3
...
...
@@ -19,6 +19,7 @@ import (
var
(
consensusInterval
=
16
//about 1 new block interval
minerInterval
=
2
)
type
commitMsgClient
struct
{
...
...
@@ -27,6 +28,7 @@ type commitMsgClient struct {
commitMsgNotify
chan
int64
delMsgNotify
chan
int64
mainBlockAdd
chan
*
types
.
BlockDetail
minerSwitch
chan
bool
currentTx
*
types
.
Transaction
checkTxCommitTimes
int32
privateKey
crypto
.
PrivKey
...
...
@@ -41,16 +43,13 @@ func (client *commitMsgClient) handler() {
var
sendingHeight
int64
//当前发送的最大高度
var
sendingMsgs
[]
*
pt
.
ParacrossNodeStatus
var
readTick
<-
chan
time
.
Time
var
ticker
*
time
.
Ticker
client
.
paraClient
.
wg
.
Add
(
1
)
consensusCh
:=
make
(
chan
*
pt
.
ParacrossStatus
,
1
)
go
client
.
getConsensusHeight
(
consensusCh
)
client
.
paraClient
.
wg
.
Add
(
1
)
priKeyCh
:=
make
(
chan
crypto
.
PrivKey
,
1
)
go
client
.
fetchPrivacyKey
(
priKeyCh
)
client
.
paraClient
.
wg
.
Add
(
1
)
sendMsgCh
:=
make
(
chan
*
types
.
Transaction
,
1
)
go
client
.
sendCommitMsg
(
sendMsgCh
)
...
...
@@ -155,7 +154,7 @@ out:
case
rsp
:=
<-
consensusCh
:
consensHeight
:=
rsp
.
Height
plog
.
Info
(
"para consensus rcv"
,
"notify"
,
notification
,
"sending"
,
len
(
sendingMsgs
),
"consensHeigt"
,
rsp
.
Height
,
"finished"
,
finishHeight
,
"sync"
,
isSync
,
"consensBlockHash"
,
common
.
ToHex
(
rsp
.
BlockHash
))
"consensHeigt"
,
rsp
.
Height
,
"finished"
,
finishHeight
,
"sync"
,
isSync
,
"
miner"
,
readTick
!=
nil
,
"
consensBlockHash"
,
common
.
ToHex
(
rsp
.
BlockHash
))
if
notification
==
nil
||
isRollback
{
continue
...
...
@@ -194,13 +193,23 @@ out:
isSync
=
true
}
case
key
,
ok
:=
<-
priKeyCh
:
if
!
ok
{
priKeyCh
=
nil
case
miner
:=
<-
client
.
minerSwitch
:
plog
.
Info
(
"para consensus mining"
,
"miner"
,
miner
)
//停止挖矿
if
!
miner
{
readTick
=
nil
if
ticker
!=
nil
{
ticker
.
Stop
()
}
plog
.
Info
(
"para consensus stop mining"
)
continue
}
client
.
privateKey
=
key
readTick
=
time
.
Tick
(
time
.
Second
*
2
)
//开启挖矿
if
client
.
privateKey
!=
nil
&&
readTick
==
nil
{
ticker
=
time
.
NewTicker
(
time
.
Second
*
time
.
Duration
(
minerInterval
))
readTick
=
ticker
.
C
plog
.
Info
(
"para consensus start mining"
)
}
case
<-
client
.
quit
:
break
out
...
...
@@ -575,51 +584,71 @@ func (client *commitMsgClient) getConsensusStatus(block *types.Block) (*pt.Parac
}
func
(
client
*
commitMsgClient
)
fetchPrivacyKey
(
ch
chan
crypto
.
PrivKey
)
{
defer
client
.
paraClient
.
wg
.
Done
()
if
client
.
paraClient
.
authAccount
==
""
{
close
(
ch
)
func
(
client
*
commitMsgClient
)
onWalletStatus
(
status
*
types
.
WalletStatus
)
{
if
status
==
nil
||
client
.
paraClient
.
authAccount
==
""
{
return
}
if
!
status
.
IsWalletLock
&&
client
.
privateKey
==
nil
{
client
.
fetchPriKey
()
plog
.
Info
(
"para commit fetchPriKey"
)
}
req
:=
&
types
.
ReqString
{
Data
:
client
.
paraClient
.
authAccount
}
out
:
for
{
select
{
case
client
.
minerSwitch
<-
!
status
.
IsWalletLock
:
case
<-
client
.
quit
:
break
out
case
<-
time
.
NewTimer
(
time
.
Second
*
2
)
.
C
:
}
}
func
(
client
*
commitMsgClient
)
onWalletAccount
(
acc
*
types
.
Account
)
{
if
acc
==
nil
||
client
.
paraClient
.
authAccount
==
""
||
client
.
paraClient
.
authAccount
!=
acc
.
Addr
||
client
.
privateKey
!=
nil
{
return
}
err
:=
client
.
fetchPriKey
()
if
err
!=
nil
{
plog
.
Error
(
"para commit fetchPriKey"
,
"err"
,
err
.
Error
())
return
}
select
{
case
client
.
minerSwitch
<-
true
:
case
<-
client
.
quit
:
}
}
func
(
client
*
commitMsgClient
)
fetchPriKey
()
error
{
req
:=
&
types
.
ReqString
{
Data
:
client
.
paraClient
.
authAccount
}
msg
:=
client
.
paraClient
.
GetQueueClient
()
.
NewMessage
(
"wallet"
,
types
.
EventDumpPrivkey
,
req
)
err
:=
client
.
paraClient
.
GetQueueClient
()
.
Send
(
msg
,
true
)
if
err
!=
nil
{
plog
.
Error
(
"para commit send msg"
,
"err"
,
err
.
Error
())
break
out
return
err
}
resp
,
err
:=
client
.
paraClient
.
GetQueueClient
()
.
Wait
(
msg
)
if
err
!=
nil
{
plog
.
Error
(
"para commit msg sign to wallet"
,
"err"
,
err
.
Error
())
continue
return
err
}
str
:=
resp
.
GetData
()
.
(
*
types
.
ReplyString
)
.
Data
pk
,
err
:=
common
.
FromHex
(
str
)
if
err
!=
nil
&&
pk
==
nil
{
panic
(
err
)
return
err
}
secp
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
if
err
!=
nil
{
panic
(
err
)
return
err
}
priKey
,
err
:=
secp
.
PrivKeyFromBytes
(
pk
)
if
err
!=
nil
{
panic
(
err
)
}
ch
<-
priKey
close
(
ch
)
break
out
}
plog
.
Error
(
"para commit msg get priKey"
,
"err"
,
err
.
Error
())
return
err
}
client
.
privateKey
=
priKey
plog
.
Info
(
"para commit fetchPriKey success"
)
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