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
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
107 additions
and
91 deletions
+107
-91
para.go
plugin/consensus/para/para.go
+48
-49
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
...
...
@@ -29,43 +29,44 @@ import (
)
const
(
AddAct
int64
=
1
DelAct
int64
=
2
//reference blockstore.go
addAct
int64
=
1
//add para block action
delAct
int64
=
2
//reference blockstore.go, del para block action
P
araCrossTxCount
=
2
//current only support 2 txs for cross
p
araCrossTxCount
=
2
//current only support 2 txs for cross
)
var
(
plog
=
log
.
New
(
"module"
,
"para"
)
grpcSite
=
"localhost:8802"
genesisBlockTime
int64
=
1514533390
startHeight
int64
=
0
//parachain sync from startHeight in mainchain
searchSeq
int64
=
0
//start sequence to search startHeight in mainchain
startHeight
int64
//parachain sync from startHeight in mainchain
searchSeq
int64
//start sequence to search startHeight in mainchain
blockSec
int64
=
5
//write block interval, second
emptyBlockInterval
int64
=
4
//write empty block every interval blocks in mainchain
zeroHash
[
32
]
byte
grpcRecSize
int
=
30
*
1024
*
1024
//the size should be limited in server
grpcRecSize
=
30
*
1024
*
1024
//the size should be limited in server
//current miner tx take any privatekey for unify all nodes sign purpose, and para chain is free
minerPrivateKey
string
=
"6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
minerPrivateKey
=
"6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
)
func
init
()
{
drivers
.
Reg
(
"para"
,
New
)
drivers
.
QueryData
.
Register
(
"para"
,
&
ParaC
lient
{})
drivers
.
QueryData
.
Register
(
"para"
,
&
c
lient
{})
}
type
ParaC
lient
struct
{
type
c
lient
struct
{
*
drivers
.
BaseClient
conn
*
grpc
.
ClientConn
grpcClient
types
.
Chain33Client
paraClient
paracross
.
ParacrossClient
isCatchingUp
bool
commitMsgClient
*
C
ommitMsgClient
commitMsgClient
*
c
ommitMsgClient
authAccount
string
privateKey
crypto
.
PrivKey
wg
sync
.
WaitGroup
}
// New function to init paracross env
func
New
(
cfg
*
types
.
Consensus
,
sub
[]
byte
)
queue
.
Module
{
c
:=
drivers
.
NewBaseClient
(
cfg
)
if
cfg
.
ParaRemoteGrpcClient
!=
""
{
...
...
@@ -106,7 +107,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
grpcClient
:=
types
.
NewChain33Client
(
conn
)
paraCli
:=
paracross
.
NewParacrossClient
(
conn
)
para
:=
&
ParaC
lient
{
para
:=
&
c
lient
{
BaseClient
:
c
,
conn
:
conn
,
grpcClient
:
grpcClient
,
...
...
@@ -118,7 +119,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
if
cfg
.
WaitBlocks4CommitMsg
<
2
{
panic
(
"config WaitBlocks4CommitMsg should not less 2"
)
}
para
.
commitMsgClient
=
&
C
ommitMsgClient
{
para
.
commitMsgClient
=
&
c
ommitMsgClient
{
paraClient
:
para
,
waitMainBlocks
:
cfg
.
WaitBlocks4CommitMsg
,
commitMsgNotify
:
make
(
chan
int64
,
1
),
...
...
@@ -132,22 +133,20 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
return
para
}
func
calcSearchseq
(
height
int64
)
(
seq
int64
)
{
func
calcSearchseq
(
height
int64
)
int64
{
if
height
<
1000
{
return
0
}
else
{
seq
=
height
-
1000
}
return
seq
return
height
-
1000
}
//para 不检查任何的交易
func
(
client
*
ParaC
lient
)
CheckBlock
(
parent
*
types
.
Block
,
current
*
types
.
BlockDetail
)
error
{
err
:=
C
heckMinerTx
(
current
)
func
(
client
*
c
lient
)
CheckBlock
(
parent
*
types
.
Block
,
current
*
types
.
BlockDetail
)
error
{
err
:=
c
heckMinerTx
(
current
)
return
err
}
func
(
client
*
ParaC
lient
)
Close
()
{
func
(
client
*
c
lient
)
Close
()
{
client
.
BaseClient
.
Close
()
close
(
client
.
commitMsgClient
.
quit
)
client
.
wg
.
Wait
()
...
...
@@ -155,7 +154,7 @@ func (client *ParaClient) Close() {
plog
.
Info
(
"consensus para closed"
)
}
func
(
client
*
ParaC
lient
)
SetQueueClient
(
c
queue
.
Client
)
{
func
(
client
*
c
lient
)
SetQueueClient
(
c
queue
.
Client
)
{
plog
.
Info
(
"Enter SetQueueClient method of Para consensus"
)
client
.
InitClient
(
c
,
func
()
{
client
.
InitBlock
()
...
...
@@ -167,7 +166,7 @@ func (client *ParaClient) SetQueueClient(c queue.Client) {
go
client
.
CreateBlock
()
}
func
(
client
*
ParaC
lient
)
InitBlock
()
{
func
(
client
*
c
lient
)
InitBlock
()
{
block
,
err
:=
client
.
RequestLastBlock
()
if
err
!=
nil
{
panic
(
err
)
...
...
@@ -192,7 +191,7 @@ func (client *ParaClient) InitBlock() {
}
}
func
(
client
*
ParaC
lient
)
GetSeqByHeightOnMain
(
height
int64
,
originSeq
int64
)
int64
{
func
(
client
*
c
lient
)
GetSeqByHeightOnMain
(
height
int64
,
originSeq
int64
)
int64
{
lastSeq
,
err
:=
client
.
GetLastSeqOnMainChain
()
plog
.
Info
(
"Searching for the sequence"
,
"heightOnMain"
,
height
,
"searchSeq"
,
searchSeq
,
"lastSeq"
,
lastSeq
)
if
err
!=
nil
{
...
...
@@ -209,7 +208,7 @@ func (client *ParaClient) GetSeqByHeightOnMain(height int64, originSeq int64) in
if
err
!=
nil
{
panic
(
err
)
}
if
blockDetail
.
Block
.
Height
==
height
&&
seqTy
==
A
ddAct
{
if
blockDetail
.
Block
.
Height
==
height
&&
seqTy
==
a
ddAct
{
plog
.
Info
(
"the target sequence in mainchain"
,
"heightOnMain"
,
height
,
"targetSeq"
,
originSeq
)
return
originSeq
}
...
...
@@ -219,7 +218,7 @@ func (client *ParaClient) GetSeqByHeightOnMain(height int64, originSeq int64) in
panic
(
"Main chain has not reached the height currently"
)
}
func
(
client
*
ParaC
lient
)
CreateGenesisTx
()
(
ret
[]
*
types
.
Transaction
)
{
func
(
client
*
c
lient
)
CreateGenesisTx
()
(
ret
[]
*
types
.
Transaction
)
{
var
tx
types
.
Transaction
tx
.
Execer
=
[]
byte
(
types
.
ExecName
(
cty
.
CoinsX
))
tx
.
To
=
client
.
Cfg
.
Genesis
...
...
@@ -232,7 +231,7 @@ func (client *ParaClient) CreateGenesisTx() (ret []*types.Transaction) {
return
}
func
(
client
*
ParaC
lient
)
ProcEvent
(
msg
queue
.
Message
)
bool
{
func
(
client
*
c
lient
)
ProcEvent
(
msg
queue
.
Message
)
bool
{
return
false
}
...
...
@@ -257,24 +256,24 @@ func calcParaCrossTxGroup(tx *types.Transaction, main *types.BlockDetail, index
}
if
main
.
Receipts
[
i
]
.
Ty
==
types
.
ExecOk
{
return
main
.
Block
.
Txs
[
headIdx
:
endIdx
],
endIdx
}
else
{
}
for
_
,
log
:=
range
main
.
Receipts
[
i
]
.
Logs
{
if
log
.
Ty
==
types
.
TyLogErr
{
return
nil
,
endIdx
}
}
}
}
//全部是平行链交易 或主链执行非失败的tx
return
main
.
Block
.
Txs
[
headIdx
:
endIdx
],
endIdx
}
func
(
client
*
ParaC
lient
)
FilterTxsForPara
(
main
*
types
.
BlockDetail
)
[]
*
types
.
Transaction
{
func
(
client
*
c
lient
)
FilterTxsForPara
(
main
*
types
.
BlockDetail
)
[]
*
types
.
Transaction
{
var
txs
[]
*
types
.
Transaction
for
i
:=
0
;
i
<
len
(
main
.
Block
.
Txs
);
i
++
{
tx
:=
main
.
Block
.
Txs
[
i
]
if
types
.
IsParaExecName
(
string
(
tx
.
Execer
))
{
if
tx
.
GroupCount
>=
P
araCrossTxCount
{
if
tx
.
GroupCount
>=
p
araCrossTxCount
{
mainTxs
,
endIdx
:=
calcParaCrossTxGroup
(
tx
,
main
,
i
)
txs
=
append
(
txs
,
mainTxs
...
)
i
=
endIdx
-
1
...
...
@@ -287,7 +286,7 @@ func (client *ParaClient) FilterTxsForPara(main *types.BlockDetail) []*types.Tra
}
//get the last sequence in parachain
func
(
client
*
ParaC
lient
)
GetLastSeq
()
(
int64
,
error
)
{
func
(
client
*
c
lient
)
GetLastSeq
()
(
int64
,
error
)
{
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"blockchain"
,
types
.
EventGetLastBlockSequence
,
""
)
client
.
GetQueueClient
()
.
Send
(
msg
,
true
)
resp
,
err
:=
client
.
GetQueueClient
()
.
Wait
(
msg
)
...
...
@@ -300,9 +299,9 @@ func (client *ParaClient) GetLastSeq() (int64, error) {
return
-
2
,
errors
.
New
(
"Not an int64 data"
)
}
func
(
client
*
ParaC
lient
)
GetBlockedSeq
(
hash
[]
byte
)
(
int64
,
error
)
{
func
(
client
*
c
lient
)
GetBlockedSeq
(
hash
[]
byte
)
(
int64
,
error
)
{
//from blockchain db
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"blockchain"
,
types
.
EventGetSeqByHash
,
&
types
.
ReqHash
{
hash
})
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"blockchain"
,
types
.
EventGetSeqByHash
,
&
types
.
ReqHash
{
Hash
:
hash
})
client
.
GetQueueClient
()
.
Send
(
msg
,
true
)
resp
,
_
:=
client
.
GetQueueClient
()
.
Wait
(
msg
)
if
blockedSeq
,
ok
:=
resp
.
GetData
()
.
(
*
types
.
Int64
);
ok
{
...
...
@@ -311,7 +310,7 @@ func (client *ParaClient) GetBlockedSeq(hash []byte) (int64, error) {
return
-
2
,
errors
.
New
(
"Not an int64 data"
)
}
func
(
client
*
ParaC
lient
)
GetLastSeqOnMainChain
()
(
int64
,
error
)
{
func
(
client
*
c
lient
)
GetLastSeqOnMainChain
()
(
int64
,
error
)
{
seq
,
err
:=
client
.
grpcClient
.
GetLastBlockSequence
(
context
.
Background
(),
&
types
.
ReqNil
{})
if
err
!=
nil
{
plog
.
Error
(
"GetLastSeqOnMainChain"
,
"Error"
,
err
.
Error
())
...
...
@@ -321,8 +320,8 @@ func (client *ParaClient) GetLastSeqOnMainChain() (int64, error) {
return
seq
.
Data
,
nil
}
func
(
client
*
ParaC
lient
)
GetBlocksByHashesFromMainChain
(
hashes
[][]
byte
)
(
*
types
.
BlockDetails
,
error
)
{
req
:=
&
types
.
ReqHashes
{
hashes
}
func
(
client
*
c
lient
)
GetBlocksByHashesFromMainChain
(
hashes
[][]
byte
)
(
*
types
.
BlockDetails
,
error
)
{
req
:=
&
types
.
ReqHashes
{
Hashes
:
hashes
}
blocks
,
err
:=
client
.
grpcClient
.
GetBlockByHashes
(
context
.
Background
(),
req
)
if
err
!=
nil
{
plog
.
Error
(
"GetBlocksByHashesFromMainChain"
,
"Error"
,
err
.
Error
())
...
...
@@ -331,8 +330,8 @@ func (client *ParaClient) GetBlocksByHashesFromMainChain(hashes [][]byte) (*type
return
blocks
,
nil
}
func
(
client
*
ParaC
lient
)
GetBlockHashFromMainChain
(
start
int64
,
end
int64
)
(
*
types
.
BlockSequences
,
error
)
{
req
:=
&
types
.
ReqBlocks
{
start
,
end
,
true
,
[]
string
{}}
func
(
client
*
c
lient
)
GetBlockHashFromMainChain
(
start
int64
,
end
int64
)
(
*
types
.
BlockSequences
,
error
)
{
req
:=
&
types
.
ReqBlocks
{
Start
:
start
,
End
:
end
,
IsDetail
:
true
,
Pid
:
[]
string
{}}
blockSeqs
,
err
:=
client
.
grpcClient
.
GetBlockSequences
(
context
.
Background
(),
req
)
if
err
!=
nil
{
plog
.
Error
(
"GetBlockHashFromMainChain"
,
"Error"
,
err
.
Error
())
...
...
@@ -341,7 +340,7 @@ func (client *ParaClient) GetBlockHashFromMainChain(start int64, end int64) (*ty
return
blockSeqs
,
nil
}
func
(
client
*
ParaC
lient
)
GetBlockOnMainBySeq
(
seq
int64
)
(
*
types
.
BlockDetail
,
int64
,
error
)
{
func
(
client
*
c
lient
)
GetBlockOnMainBySeq
(
seq
int64
)
(
*
types
.
BlockDetail
,
int64
,
error
)
{
blockSeqs
,
err
:=
client
.
GetBlockHashFromMainChain
(
seq
,
seq
)
if
err
!=
nil
{
plog
.
Error
(
"Not found block hash on seq"
,
"start"
,
seq
,
"end"
,
seq
)
...
...
@@ -366,7 +365,7 @@ func (client *ParaClient) GetBlockOnMainBySeq(seq int64) (*types.BlockDetail, in
return
blockDetails
.
Items
[
0
],
blockSeqs
.
Items
[
0
]
.
Type
,
nil
}
func
(
client
*
ParaC
lient
)
RequestTx
(
currSeq
int64
)
([]
*
types
.
Transaction
,
*
types
.
Block
,
int64
,
error
)
{
func
(
client
*
c
lient
)
RequestTx
(
currSeq
int64
)
([]
*
types
.
Transaction
,
*
types
.
Block
,
int64
,
error
)
{
plog
.
Debug
(
"Para consensus RequestTx"
)
lastSeq
,
err
:=
client
.
GetLastSeqOnMainChain
()
...
...
@@ -399,7 +398,7 @@ func (client *ParaClient) RequestTx(currSeq int64) ([]*types.Transaction, *types
}
//正常情况下,打包交易
func
(
client
*
ParaC
lient
)
CreateBlock
()
{
func
(
client
*
c
lient
)
CreateBlock
()
{
incSeqFlag
:=
true
currSeq
,
err
:=
client
.
GetLastSeq
()
if
err
!=
nil
{
...
...
@@ -451,7 +450,7 @@ func (client *ParaClient) CreateBlock() {
}
plog
.
Info
(
"Parachain process block"
,
"blockedSeq"
,
blockedSeq
,
"blockOnMain.Height"
,
blockOnMain
.
Height
,
"savedBlockOnMain.Height"
,
savedBlockOnMain
.
Block
.
Height
)
if
seqTy
==
D
elAct
{
if
seqTy
==
d
elAct
{
if
len
(
txs
)
==
0
{
if
blockOnMain
.
Height
>
savedBlockOnMain
.
Block
.
Height
{
incSeqFlag
=
true
...
...
@@ -464,7 +463,7 @@ func (client *ParaClient) CreateBlock() {
if
err
!=
nil
{
plog
.
Error
(
fmt
.
Sprintf
(
"********************err:%v"
,
err
.
Error
()))
}
}
else
if
seqTy
==
A
ddAct
{
}
else
if
seqTy
==
a
ddAct
{
if
len
(
txs
)
==
0
{
if
blockOnMain
.
Height
-
savedBlockOnMain
.
Block
.
Height
<
emptyBlockInterval
{
incSeqFlag
=
true
...
...
@@ -488,7 +487,7 @@ func (client *ParaClient) CreateBlock() {
}
// miner tx need all para node create, but not all node has auth account, here just not sign to keep align
func
(
client
*
ParaC
lient
)
addMinerTx
(
preStateHash
[]
byte
,
block
*
types
.
Block
,
main
*
types
.
Block
)
error
{
func
(
client
*
c
lient
)
addMinerTx
(
preStateHash
[]
byte
,
block
*
types
.
Block
,
main
*
types
.
Block
)
error
{
status
:=
&
pt
.
ParacrossNodeStatus
{
Title
:
types
.
GetTitle
(),
Height
:
block
.
Height
,
...
...
@@ -509,7 +508,7 @@ func (client *ParaClient) addMinerTx(preStateHash []byte, block *types.Block, ma
}
func
(
client
*
ParaC
lient
)
createBlock
(
lastBlock
*
types
.
Block
,
txs
[]
*
types
.
Transaction
,
seq
int64
,
mainBlock
*
types
.
Block
)
error
{
func
(
client
*
c
lient
)
createBlock
(
lastBlock
*
types
.
Block
,
txs
[]
*
types
.
Transaction
,
seq
int64
,
mainBlock
*
types
.
Block
)
error
{
var
newblock
types
.
Block
plog
.
Debug
(
fmt
.
Sprintf
(
"the len txs is: %v"
,
len
(
txs
)))
newblock
.
ParentHash
=
lastBlock
.
Hash
()
...
...
@@ -534,11 +533,11 @@ func (client *ParaClient) createBlock(lastBlock *types.Block, txs []*types.Trans
}
// 向blockchain写区块
func
(
client
*
ParaC
lient
)
WriteBlock
(
prev
[]
byte
,
paraBlock
*
types
.
Block
,
seq
int64
)
error
{
func
(
client
*
c
lient
)
WriteBlock
(
prev
[]
byte
,
paraBlock
*
types
.
Block
,
seq
int64
)
error
{
//共识模块不执行block,统一由blockchain模块执行block并做去重的处理,返回执行后的blockdetail
blockDetail
:=
&
types
.
BlockDetail
{
Block
:
paraBlock
}
parablockDetail
:=
&
types
.
ParaChainBlockDetail
{
blockDetail
,
seq
}
parablockDetail
:=
&
types
.
ParaChainBlockDetail
{
Blockdetail
:
blockDetail
,
Sequence
:
seq
}
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"blockchain"
,
types
.
EventAddParaChainBlockDetail
,
parablockDetail
)
client
.
GetQueueClient
()
.
Send
(
msg
,
true
)
resp
,
err
:=
client
.
GetQueueClient
()
.
Wait
(
msg
)
...
...
@@ -560,13 +559,13 @@ func (client *ParaClient) WriteBlock(prev []byte, paraBlock *types.Block, seq in
}
// 向blockchain删区块
func
(
client
*
ParaC
lient
)
DelBlock
(
block
*
types
.
Block
,
seq
int64
)
error
{
func
(
client
*
c
lient
)
DelBlock
(
block
*
types
.
Block
,
seq
int64
)
error
{
plog
.
Debug
(
"delete block in parachain"
)
start
:=
block
.
Height
if
start
==
0
{
panic
(
"Parachain attempt to Delete GenesisBlock !"
)
}
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"blockchain"
,
types
.
EventGetBlocks
,
&
types
.
ReqBlocks
{
start
,
start
,
true
,
[]
string
{
""
}})
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"blockchain"
,
types
.
EventGetBlocks
,
&
types
.
ReqBlocks
{
Start
:
start
,
End
:
start
,
IsDetail
:
true
,
Pid
:
[]
string
{
""
}})
client
.
GetQueueClient
()
.
Send
(
msg
,
true
)
resp
,
err
:=
client
.
GetQueueClient
()
.
Wait
(
msg
)
if
err
!=
nil
{
...
...
@@ -574,7 +573,7 @@ func (client *ParaClient) DelBlock(block *types.Block, seq int64) error {
}
blocks
:=
resp
.
GetData
()
.
(
*
types
.
BlockDetails
)
parablockDetail
:=
&
types
.
ParaChainBlockDetail
{
blocks
.
Items
[
0
],
seq
}
parablockDetail
:=
&
types
.
ParaChainBlockDetail
{
Blockdetail
:
blocks
.
Items
[
0
],
Sequence
:
seq
}
msg
=
client
.
GetQueueClient
()
.
NewMessage
(
"blockchain"
,
types
.
EventDelParaChainBlockDetail
,
parablockDetail
)
client
.
GetQueueClient
()
.
Send
(
msg
,
true
)
resp
,
err
=
client
.
GetQueueClient
()
.
Wait
(
msg
)
...
...
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