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
b24eac06
Commit
b24eac06
authored
Nov 20, 2018
by
mdj33
Committed by
vipwzw
Nov 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct linter err of golint govet ineffasign
parent
71f4916a
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
59 additions
and
42 deletions
+59
-42
para.go
plugin/consensus/para/para.go
+0
-0
para_test.go
plugin/consensus/para/para_test.go
+1
-1
paracommitmsg.go
plugin/consensus/para/paracommitmsg.go
+19
-19
paracommitmsg_test.go
plugin/consensus/para/paracommitmsg_test.go
+4
-4
ticket.go
plugin/consensus/ticket/ticket.go
+22
-12
paracross_test.go
plugin/dapp/paracross/executor/paracross_test.go
+4
-4
relayd.go
plugin/dapp/relay/cmd/relayd/relayd/relayd.go
+4
-1
relaybtc_test.go
plugin/dapp/relay/executor/relaybtc_test.go
+1
-1
relaydb.go
plugin/dapp/relay/executor/relaydb.go
+4
-0
No files found.
plugin/consensus/para/para.go
View file @
b24eac06
This diff is collapsed.
Click to expand it.
plugin/consensus/para/para_test.go
View file @
b24eac06
...
...
@@ -112,7 +112,7 @@ func TestFilterTxsForPara(t *testing.T) {
Receipts
:
receipts
,
}
para
:=
&
ParaC
lient
{}
para
:=
&
c
lient
{}
rst
:=
para
.
FilterTxsForPara
(
detail
)
filterTxs
:=
[]
*
types
.
Transaction
{
tx3
,
tx4
,
tx5
,
tx6
,
txA
,
txB
,
txC
}
assert
.
Equal
(
t
,
filterTxs
,
rst
)
...
...
plugin/consensus/para/paracommitmsg.go
View file @
b24eac06
...
...
@@ -21,8 +21,8 @@ var (
consensusInterval
=
16
//about 1 new block interval
)
type
C
ommitMsgClient
struct
{
paraClient
*
ParaC
lient
type
c
ommitMsgClient
struct
{
paraClient
*
c
lient
waitMainBlocks
int32
commitMsgNotify
chan
int64
delMsgNotify
chan
int64
...
...
@@ -33,7 +33,7 @@ type CommitMsgClient struct {
quit
chan
struct
{}
}
func
(
client
*
C
ommitMsgClient
)
handler
()
{
func
(
client
*
c
ommitMsgClient
)
handler
()
{
var
isSync
bool
var
notification
[]
int64
//记录每次系统重启后 min and current height
var
finishHeight
int64
...
...
@@ -185,7 +185,7 @@ out:
client
.
paraClient
.
wg
.
Done
()
}
func
(
client
*
C
ommitMsgClient
)
calcCommitMsgTxs
(
notifications
[]
*
pt
.
ParacrossNodeStatus
)
(
*
types
.
Transaction
,
int64
,
error
)
{
func
(
client
*
c
ommitMsgClient
)
calcCommitMsgTxs
(
notifications
[]
*
pt
.
ParacrossNodeStatus
)
(
*
types
.
Transaction
,
int64
,
error
)
{
txs
,
count
,
err
:=
client
.
batchCalcTxGroup
(
notifications
)
if
err
!=
nil
{
txs
,
err
=
client
.
singleCalcTx
((
notifications
)[
0
])
...
...
@@ -199,7 +199,7 @@ func (client *CommitMsgClient) calcCommitMsgTxs(notifications []*pt.ParacrossNod
return
txs
,
int64
(
count
),
nil
}
func
(
client
*
C
ommitMsgClient
)
getTxsGroup
(
txsArr
*
types
.
Transactions
)
(
*
types
.
Transaction
,
error
)
{
func
(
client
*
c
ommitMsgClient
)
getTxsGroup
(
txsArr
*
types
.
Transactions
)
(
*
types
.
Transaction
,
error
)
{
if
len
(
txsArr
.
Txs
)
<
2
{
tx
:=
txsArr
.
Txs
[
0
]
tx
.
Sign
(
types
.
SECP256K1
,
client
.
privateKey
)
...
...
@@ -224,7 +224,7 @@ func (client *CommitMsgClient) getTxsGroup(txsArr *types.Transactions) (*types.T
return
newtx
,
nil
}
func
(
client
*
C
ommitMsgClient
)
batchCalcTxGroup
(
notifications
[]
*
pt
.
ParacrossNodeStatus
)
(
*
types
.
Transaction
,
int
,
error
)
{
func
(
client
*
c
ommitMsgClient
)
batchCalcTxGroup
(
notifications
[]
*
pt
.
ParacrossNodeStatus
)
(
*
types
.
Transaction
,
int
,
error
)
{
var
rawTxs
types
.
Transactions
for
_
,
status
:=
range
notifications
{
tx
,
err
:=
paracross
.
CreateRawCommitTx4MainChain
(
status
,
pt
.
ParaX
,
0
)
...
...
@@ -242,7 +242,7 @@ func (client *CommitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNod
return
txs
,
len
(
notifications
),
nil
}
func
(
client
*
C
ommitMsgClient
)
singleCalcTx
(
status
*
pt
.
ParacrossNodeStatus
)
(
*
types
.
Transaction
,
error
)
{
func
(
client
*
c
ommitMsgClient
)
singleCalcTx
(
status
*
pt
.
ParacrossNodeStatus
)
(
*
types
.
Transaction
,
error
)
{
tx
,
err
:=
paracross
.
CreateRawCommitTx4MainChain
(
status
,
pt
.
ParaX
,
0
)
if
err
!=
nil
{
plog
.
Error
(
"para get commit tx"
,
"block height"
,
status
.
Height
)
...
...
@@ -258,7 +258,7 @@ func (client *CommitMsgClient) singleCalcTx(status *pt.ParacrossNodeStatus) (*ty
// if sendCommitMsgTx block quite long, write channel will be block in handle(), addBlock will not send new msg until rpc send over
// if sendCommitMsgTx block quite long, if delMsg occur, after send over, ignore previous tx succ or fail, new msg will be rcv and sent
// if sendCommitMsgTx fail, wait 1s resend the failed tx, if new tx rcv from ch, send the new one.
func
(
client
*
C
ommitMsgClient
)
sendCommitMsg
(
ch
chan
*
types
.
Transaction
)
{
func
(
client
*
c
ommitMsgClient
)
sendCommitMsg
(
ch
chan
*
types
.
Transaction
)
{
var
err
error
var
tx
*
types
.
Transaction
resendTimer
:=
time
.
After
(
time
.
Second
*
1
)
...
...
@@ -286,7 +286,7 @@ out:
client
.
paraClient
.
wg
.
Done
()
}
func
(
client
*
C
ommitMsgClient
)
sendCommitMsgTx
(
tx
*
types
.
Transaction
)
error
{
func
(
client
*
c
ommitMsgClient
)
sendCommitMsgTx
(
tx
*
types
.
Transaction
)
error
{
if
tx
==
nil
{
return
nil
}
...
...
@@ -319,7 +319,7 @@ func checkTxInMainBlock(targetTx *types.Transaction, detail *types.BlockDetail)
//当前未考虑获取key非常多失败的场景, 如果获取height非常多,block模块会比较大,但是使用完了就释放了
//如果有必要也可以考虑每次最多取20个一个txgroup,发送共识部分循环获取发送也没问题
func
(
client
*
C
ommitMsgClient
)
getNodeStatus
(
start
,
end
int64
)
([]
*
pt
.
ParacrossNodeStatus
,
error
)
{
func
(
client
*
c
ommitMsgClient
)
getNodeStatus
(
start
,
end
int64
)
([]
*
pt
.
ParacrossNodeStatus
,
error
)
{
var
ret
[]
*
pt
.
ParacrossNodeStatus
if
start
==
0
{
geneStatus
,
err
:=
client
.
getGenesisNodeStatus
()
...
...
@@ -402,7 +402,7 @@ func (client *CommitMsgClient) getNodeStatus(start, end int64) ([]*pt.ParacrossN
}
func
(
client
*
C
ommitMsgClient
)
getGenesisNodeStatus
()
(
*
pt
.
ParacrossNodeStatus
,
error
)
{
func
(
client
*
c
ommitMsgClient
)
getGenesisNodeStatus
()
(
*
pt
.
ParacrossNodeStatus
,
error
)
{
var
status
pt
.
ParacrossNodeStatus
req
:=
&
types
.
ReqBlocks
{
Start
:
0
,
End
:
0
}
msg
:=
client
.
paraClient
.
GetQueueClient
()
.
NewMessage
(
"blockchain"
,
types
.
EventGetBlocks
,
req
)
...
...
@@ -425,7 +425,7 @@ func (client *CommitMsgClient) getGenesisNodeStatus() (*pt.ParacrossNodeStatus,
return
&
status
,
nil
}
func
(
client
*
C
ommitMsgClient
)
onBlockAdded
(
height
int64
)
error
{
func
(
client
*
c
ommitMsgClient
)
onBlockAdded
(
height
int64
)
error
{
select
{
case
client
.
commitMsgNotify
<-
height
:
case
<-
client
.
quit
:
...
...
@@ -434,14 +434,14 @@ func (client *CommitMsgClient) onBlockAdded(height int64) error {
return
nil
}
func
(
client
*
C
ommitMsgClient
)
onBlockDeleted
(
height
int64
)
{
func
(
client
*
c
ommitMsgClient
)
onBlockDeleted
(
height
int64
)
{
select
{
case
client
.
delMsgNotify
<-
height
:
case
<-
client
.
quit
:
}
}
func
(
client
*
C
ommitMsgClient
)
onMainBlockAdded
(
block
*
types
.
BlockDetail
)
{
func
(
client
*
c
ommitMsgClient
)
onMainBlockAdded
(
block
*
types
.
BlockDetail
)
{
select
{
case
client
.
mainBlockAdd
<-
block
:
case
<-
client
.
quit
:
...
...
@@ -449,7 +449,7 @@ func (client *CommitMsgClient) onMainBlockAdded(block *types.BlockDetail) {
}
//only sync once, as main usually sync, here just need the first sync status after start up
func
(
client
*
C
ommitMsgClient
)
mainSync
()
error
{
func
(
client
*
c
ommitMsgClient
)
mainSync
()
error
{
req
:=
&
types
.
ReqNil
{}
reply
,
err
:=
client
.
paraClient
.
grpcClient
.
IsSync
(
context
.
Background
(),
req
)
if
err
!=
nil
{
...
...
@@ -466,7 +466,7 @@ func (client *CommitMsgClient) mainSync() error {
}
func
(
client
*
C
ommitMsgClient
)
getConsensusHeight
(
consensusRst
chan
*
pt
.
ParacrossStatus
)
{
func
(
client
*
c
ommitMsgClient
)
getConsensusHeight
(
consensusRst
chan
*
pt
.
ParacrossStatus
)
{
ticker
:=
time
.
NewTicker
(
time
.
Second
*
time
.
Duration
(
consensusInterval
))
isSync
:=
false
defer
ticker
.
Stop
()
...
...
@@ -486,7 +486,7 @@ out:
}
ret
,
err
:=
client
.
paraClient
.
paraClient
.
GetTitle
(
context
.
Background
(),
&
types
.
ReqString
{
types
.
GetTitle
()})
&
types
.
ReqString
{
Data
:
types
.
GetTitle
()})
if
err
!=
nil
{
plog
.
Error
(
"getConsensusHeight "
,
"err"
,
err
.
Error
())
continue
...
...
@@ -499,7 +499,7 @@ out:
client
.
paraClient
.
wg
.
Done
()
}
func
(
client
*
C
ommitMsgClient
)
fetchPrivacyKey
(
ch
chan
crypto
.
PrivKey
)
{
func
(
client
*
c
ommitMsgClient
)
fetchPrivacyKey
(
ch
chan
crypto
.
PrivKey
)
{
defer
client
.
paraClient
.
wg
.
Done
()
if
client
.
paraClient
.
authAccount
==
""
{
close
(
ch
)
...
...
@@ -544,7 +544,7 @@ out:
}
func
C
heckMinerTx
(
current
*
types
.
BlockDetail
)
error
{
func
c
heckMinerTx
(
current
*
types
.
BlockDetail
)
error
{
//检查第一个笔交易的execs, 以及执行状态
if
len
(
current
.
Block
.
Txs
)
==
0
{
return
types
.
ErrEmptyTx
...
...
plugin/consensus/para/paracommitmsg_test.go
View file @
b24eac06
...
...
@@ -42,7 +42,7 @@ func init() {
type
suiteParaCommitMsg
struct
{
// Include our basic suite logic.
suite
.
Suite
para
*
ParaC
lient
para
*
c
lient
grpcCli
*
typesmocks
.
Chain33Client
q
queue
.
Queue
block
*
blockchain
.
BlockChain
...
...
@@ -70,7 +70,7 @@ func (s *suiteParaCommitMsg) initEnv(cfg *types.Config, sub *types.ConfigSubModu
s
.
store
=
store
.
New
(
cfg
.
Store
,
sub
.
Store
)
s
.
store
.
SetQueueClient
(
q
.
Client
())
s
.
para
=
New
(
cfg
.
Consensus
,
sub
.
Consensus
[
"para"
])
.
(
*
ParaC
lient
)
s
.
para
=
New
(
cfg
.
Consensus
,
sub
.
Consensus
[
"para"
])
.
(
*
c
lient
)
s
.
grpcCli
=
&
typesmocks
.
Chain33Client
{}
//data := &types.Int64{1}
s
.
grpcCli
.
On
(
"GetLastBlockSequence"
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
nil
,
errors
.
New
(
"nil"
))
...
...
@@ -97,7 +97,7 @@ func (s *suiteParaCommitMsg) initEnv(cfg *types.Config, sub *types.ConfigSubModu
}
func
walletProcess
(
q
queue
.
Queue
,
para
*
ParaC
lient
)
{
func
walletProcess
(
q
queue
.
Queue
,
para
*
c
lient
)
{
defer
para
.
wg
.
Done
()
client
:=
q
.
Client
()
...
...
@@ -109,7 +109,7 @@ func walletProcess(q queue.Queue, para *ParaClient) {
return
case
msg
:=
<-
client
.
Recv
()
:
if
msg
.
Ty
==
types
.
EventDumpPrivkey
{
msg
.
Reply
(
client
.
NewMessage
(
""
,
types
.
EventHeader
,
&
types
.
ReplyString
{
"6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
}))
msg
.
Reply
(
client
.
NewMessage
(
""
,
types
.
EventHeader
,
&
types
.
ReplyString
{
Data
:
"6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
}))
}
}
}
...
...
plugin/consensus/ticket/ticket.go
View file @
b24eac06
...
...
@@ -36,6 +36,7 @@ func init() {
drivers
.
QueryData
.
Register
(
"ticket"
,
&
Client
{})
}
// Client export ticket client struct
type
Client
struct
{
*
drivers
.
BaseClient
//ticket list for miner
...
...
@@ -57,6 +58,7 @@ type subConfig struct {
Genesis
[]
*
genesisTicket
`json:"genesis"`
}
// New ticket's init env
func
New
(
cfg
*
types
.
Consensus
,
sub
[]
byte
)
queue
.
Module
{
c
:=
drivers
.
NewBaseClient
(
cfg
)
var
subcfg
subConfig
...
...
@@ -86,12 +88,14 @@ Loop:
}
}
// Close ticket close
func
(
client
*
Client
)
Close
()
{
close
(
client
.
done
)
client
.
BaseClient
.
Close
()
tlog
.
Info
(
"consensus ticket closed"
)
}
// CreateGenesisTx ticket create genesis tx
func
(
client
*
Client
)
CreateGenesisTx
()
(
ret
[]
*
types
.
Transaction
)
{
for
_
,
genesis
:=
range
client
.
subcfg
.
Genesis
{
tx1
:=
createTicket
(
genesis
.
MinerAddr
,
genesis
.
ReturnAddr
,
genesis
.
Count
,
0
)
...
...
@@ -119,7 +123,7 @@ func createTicket(minerAddr, returnAddr string, count int32, height int64) (ret
tx2
.
To
=
driver
.
ExecAddress
(
"ticket"
)
//gen payload
g
=
&
cty
.
CoinsAction_Genesis
{}
g
.
Genesis
=
&
types
.
AssetsGenesis
{
int64
(
count
)
*
types
.
GetP
(
height
)
.
TicketPrice
,
returnAddr
}
g
.
Genesis
=
&
types
.
AssetsGenesis
{
Amount
:
int64
(
count
)
*
types
.
GetP
(
height
)
.
TicketPrice
,
ReturnAddress
:
returnAddr
}
tx2
.
Payload
=
types
.
Encode
(
&
cty
.
CoinsAction
{
Value
:
g
,
Ty
:
cty
.
CoinsActionGenesis
})
ret
=
append
(
ret
,
&
tx2
)
...
...
@@ -127,26 +131,29 @@ func createTicket(minerAddr, returnAddr string, count int32, height int64) (ret
tx3
.
Execer
=
[]
byte
(
"ticket"
)
tx3
.
To
=
driver
.
ExecAddress
(
"ticket"
)
gticket
:=
&
ty
.
TicketAction_Genesis
{}
gticket
.
Genesis
=
&
ty
.
TicketGenesis
{
minerAddr
,
returnAddr
,
count
}
gticket
.
Genesis
=
&
ty
.
TicketGenesis
{
MinerAddress
:
minerAddr
,
ReturnAddress
:
returnAddr
,
Count
:
count
}
tx3
.
Payload
=
types
.
Encode
(
&
ty
.
TicketAction
{
Value
:
gticket
,
Ty
:
ty
.
TicketActionGenesis
})
ret
=
append
(
ret
,
&
tx3
)
return
ret
}
// Query_GetTicketCount ticket query ticket count function
func
(
client
*
Client
)
Query_GetTicketCount
(
req
*
types
.
ReqNil
)
(
types
.
Message
,
error
)
{
var
ret
types
.
Int64
ret
.
Data
=
client
.
getTicketCount
()
return
&
ret
,
nil
}
// Query_FlushTicket ticket query flush ticket function
func
(
client
*
Client
)
Query_FlushTicket
(
req
*
types
.
ReqNil
)
(
types
.
Message
,
error
)
{
err
:=
client
.
flushTicket
()
if
err
!=
nil
{
return
nil
,
err
}
return
&
types
.
Reply
{
true
,
[]
byte
(
"OK"
)},
nil
return
&
types
.
Reply
{
IsOk
:
true
,
Msg
:
[]
byte
(
"OK"
)},
nil
}
// ProcEvent ticket reply not support action err
func
(
client
*
Client
)
ProcEvent
(
msg
queue
.
Message
)
bool
{
msg
.
ReplyErr
(
"Client"
,
types
.
ErrActionNotSupport
)
return
true
...
...
@@ -207,7 +214,7 @@ func (client *Client) flushTicket() error {
tlog
.
Error
(
"flushTicket error"
,
"err"
,
err
)
return
err
}
client
.
setTicket
(
&
ty
.
ReplyTicketList
{
tickets
},
getPrivMap
(
privs
))
client
.
setTicket
(
&
ty
.
ReplyTicketList
{
Tickets
:
tickets
},
getPrivMap
(
privs
))
return
nil
}
...
...
@@ -242,7 +249,7 @@ func (client *Client) getMinerTx(current *types.Block) (*ty.TicketAction, error)
return
&
ticketAction
,
nil
}
func
(
client
*
Client
)
getModify
(
block
*
types
.
Block
)
([]
byte
,
error
)
{
func
(
client
*
Client
)
getM
inerM
odify
(
block
*
types
.
Block
)
([]
byte
,
error
)
{
ticketAction
,
err
:=
client
.
getMinerTx
(
block
)
if
err
!=
nil
{
return
defaultModify
,
err
...
...
@@ -250,7 +257,7 @@ func (client *Client) getModify(block *types.Block) ([]byte, error) {
return
ticketAction
.
GetMiner
()
.
GetModify
(),
nil
}
func
(
client
*
Client
)
G
etModify
(
beg
,
end
int64
)
([]
byte
,
error
)
{
func
(
client
*
Client
)
g
etModify
(
beg
,
end
int64
)
([]
byte
,
error
)
{
//通过某个区间计算modify
timeSource
:=
int64
(
0
)
total
:=
int64
(
0
)
...
...
@@ -280,6 +287,7 @@ func (client *Client) GetModify(beg, end int64) ([]byte, error) {
return
[]
byte
(
modify
),
nil
}
// CheckBlock ticket implete checkblock func
func
(
client
*
Client
)
CheckBlock
(
parent
*
types
.
Block
,
current
*
types
.
BlockDetail
)
error
{
cfg
:=
types
.
GetP
(
current
.
Block
.
Height
)
if
current
.
Block
.
BlockTime
-
types
.
Now
()
.
Unix
()
>
cfg
.
FutureBlockTime
{
...
...
@@ -348,7 +356,7 @@ func (client *Client) getNextTarget(block *types.Block, bits uint32) (*big.Int,
powLimit
:=
difficulty
.
CompactToBig
(
types
.
GetP
(
0
)
.
PowLimitBits
)
return
powLimit
,
defaultModify
,
nil
}
targetBits
,
modify
,
err
:=
client
.
G
etNextRequiredDifficulty
(
block
,
bits
)
targetBits
,
modify
,
err
:=
client
.
g
etNextRequiredDifficulty
(
block
,
bits
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
...
...
@@ -370,7 +378,7 @@ func (client *Client) getCurrentTarget(blocktime int64, id string, modify []byte
// This function differs from the exported CalcNextRequiredDifficulty in that
// the exported version uses the current best chain as the previous block node
// while this function accepts any block node.
func
(
client
*
Client
)
G
etNextRequiredDifficulty
(
block
*
types
.
Block
,
bits
uint32
)
(
uint32
,
[]
byte
,
error
)
{
func
(
client
*
Client
)
g
etNextRequiredDifficulty
(
block
*
types
.
Block
,
bits
uint32
)
(
uint32
,
[]
byte
,
error
)
{
// Genesis block.
if
block
==
nil
{
return
types
.
GetP
(
0
)
.
PowLimitBits
,
defaultModify
,
nil
...
...
@@ -382,7 +390,7 @@ func (client *Client) GetNextRequiredDifficulty(block *types.Block, bits uint32)
if
(
block
.
Height
+
1
)
<=
blocksPerRetarget
||
(
block
.
Height
+
1
)
%
blocksPerRetarget
!=
0
{
// For the main network (or any unrecognized networks), simply
// return the previous block's difficulty requirements.
modify
,
err
:=
client
.
getModify
(
block
)
modify
,
err
:=
client
.
getM
inerM
odify
(
block
)
if
err
!=
nil
{
return
bits
,
defaultModify
,
err
}
...
...
@@ -399,7 +407,7 @@ func (client *Client) GetNextRequiredDifficulty(block *types.Block, bits uint32)
return
cfg
.
PowLimitBits
,
defaultModify
,
types
.
ErrBlockNotFound
}
modify
,
err
:=
client
.
G
etModify
(
block
.
Height
+
1
-
blocksPerRetarget
,
block
.
Height
)
modify
,
err
:=
client
.
g
etModify
(
block
.
Height
+
1
-
blocksPerRetarget
,
block
.
Height
)
if
err
!=
nil
{
return
cfg
.
PowLimitBits
,
defaultModify
,
err
}
...
...
@@ -443,7 +451,7 @@ func (client *Client) GetNextRequiredDifficulty(block *types.Block, bits uint32)
tlog
.
Info
(
"Timespan"
,
"Actual timespan"
,
time
.
Duration
(
actualTimespan
)
*
time
.
Second
,
"adjusted timespan"
,
time
.
Duration
(
adjustedTimespan
)
*
time
.
Second
,
"target timespan"
,
cfg
.
TargetTimespan
)
prevmodify
,
err
:=
client
.
getModify
(
block
)
prevmodify
,
err
:=
client
.
getM
inerM
odify
(
block
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -511,6 +519,7 @@ func (client *Client) delTicket(ticket *ty.Ticket, index int) {
}
}
// Miner ticket miner function
func
(
client
*
Client
)
Miner
(
parent
,
block
*
types
.
Block
)
bool
{
//add miner address
ticket
,
priv
,
diff
,
modify
,
index
,
err
:=
client
.
searchTargetTicket
(
parent
,
block
)
...
...
@@ -577,7 +586,7 @@ func (client *Client) addMinerTx(parent, block *types.Block, diff *big.Int, priv
return
err
}
miner
.
PrivHash
=
privHash
ticketAction
.
Value
=
&
ty
.
TicketAction_Miner
{
miner
}
ticketAction
.
Value
=
&
ty
.
TicketAction_Miner
{
Miner
:
miner
}
ticketAction
.
Ty
=
ty
.
TicketActionMiner
//构造transaction
tx
:=
client
.
createMinerTx
(
&
ticketAction
,
priv
)
...
...
@@ -648,6 +657,7 @@ func (client *Client) updateBlock(newblock *types.Block, txHashList [][]byte) (*
return
lastBlock
,
txHashList
}
// CreateBlock ticket create block func
func
(
client
*
Client
)
CreateBlock
()
{
for
{
if
!
client
.
IsMining
()
||
!
(
client
.
IsCaughtUp
()
||
client
.
Cfg
.
ForceMining
)
{
...
...
plugin/dapp/paracross/executor/paracross_test.go
View file @
b24eac06
...
...
@@ -226,11 +226,11 @@ func commitOnce(suite *CommitTestSuite, privkeyStr string) (receipt *types.Recei
}
func
commitOnceImpl
(
suite
suite
.
Suite
,
exec
*
Paracross
,
privkeyStr
string
)
(
receipt
*
types
.
Receipt
)
{
tx
,
err
:=
fillRawCommitTx
(
suite
)
tx
,
err
=
signTx
(
suite
,
tx
,
privkeyStr
)
tx
,
_
:=
fillRawCommitTx
(
suite
)
tx
,
_
=
signTx
(
suite
,
tx
,
privkeyStr
)
suite
.
T
()
.
Log
(
tx
.
From
())
receipt
,
err
=
exec
.
Exec
(
tx
,
0
)
receipt
,
err
:
=
exec
.
Exec
(
tx
,
0
)
suite
.
T
()
.
Log
(
receipt
)
assert
.
NotNil
(
suite
.
T
(),
receipt
)
assert
.
Nil
(
suite
.
T
(),
err
)
...
...
@@ -526,7 +526,7 @@ func createTxsGroup(s suite.Suite, txs []*types.Transaction) ([]*types.Transacti
if
err
!=
nil
{
return
nil
,
err
}
privKey
,
err
:=
getPrivKey
(
s
,
PrivKeyA
)
privKey
,
_
:=
getPrivKey
(
s
,
PrivKeyA
)
for
i
:=
range
group
.
Txs
{
group
.
SignN
(
i
,
int32
(
types
.
SECP256K1
),
privKey
)
}
...
...
plugin/dapp/relay/cmd/relayd/relayd/relayd.go
View file @
b24eac06
...
...
@@ -67,9 +67,12 @@ func NewRelayd(config *Config) *Relayd {
}
currentHeight
,
err
:=
db
.
Get
(
currentBtcBlockheightKey
[
:
])
if
err
!=
nil
{
log
.
Warn
(
"NewRelayd"
,
"db get error: "
,
err
.
Error
())
}
height
,
err
:=
strconv
.
Atoi
(
string
(
currentHeight
))
if
err
!=
nil
{
log
.
Warn
(
"NewRelayd"
,
"atoi height error: "
,
err
)
log
.
Warn
(
"NewRelayd"
,
"atoi height error: "
,
err
.
Error
()
)
}
if
height
<
firstHeight
||
isResetBtcHeight
{
...
...
plugin/dapp/relay/executor/relaybtc_test.go
View file @
b24eac06
...
...
@@ -80,7 +80,7 @@ func (s *suiteBtcStore) TestSaveBlockHead() {
Time
:
1231731025
,
Height
:
2
,
}
val
,
err
:=
proto
.
Marshal
(
head
)
val
,
_
:=
proto
.
Marshal
(
head
)
key
:=
calcBtcHeaderKeyHash
(
head
.
Hash
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
key
,
val
})
key
=
calcBtcHeaderKeyHeight
(
int64
(
head
.
Height
))
...
...
plugin/dapp/relay/executor/relaydb.go
View file @
b24eac06
...
...
@@ -451,6 +451,10 @@ func (action *relayDB) confirmTx(confirm *ty.RelayConfirmTx) (*types.Receipt, er
//report Error if coinTxHash has been used and not same orderId, if same orderId, means to modify the txHash
coinTxOrder
,
err
:=
action
.
getOrderByCoinHash
([]
byte
(
calcCoinHash
(
confirm
.
TxHash
)))
if
err
!=
nil
{
relaylog
.
Error
(
"confirmTx getOrderByCoinHash"
,
"orderid"
,
confirm
.
OrderId
,
"err"
,
err
.
Error
())
return
nil
,
err
}
if
coinTxOrder
!=
nil
{
if
coinTxOrder
.
Id
!=
confirm
.
OrderId
{
relaylog
.
Error
(
"confirmTx"
,
"coinTxHash"
,
confirm
.
TxHash
,
"has been used in other order"
,
coinTxOrder
.
Id
)
...
...
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