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
2ec44b30
Commit
2ec44b30
authored
Apr 22, 2019
by
mdj33
Committed by
vipwzw
Apr 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ut cov
parent
f3f7aaaa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
147 additions
and
79 deletions
+147
-79
para.go
plugin/consensus/para/para.go
+10
-15
para_test.go
plugin/consensus/para/para_test.go
+106
-64
paratxrequest_test.go
plugin/consensus/para/paratxrequest_test.go
+30
-0
cfg.go
plugin/dapp/paracross/testnode/cfg.go
+1
-0
No files found.
plugin/consensus/para/para.go
View file @
2ec44b30
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
cty
"github.com/33cn/chain33/system/dapp/coins/types"
cty
"github.com/33cn/chain33/system/dapp/coins/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
paraexec
"github.com/33cn/plugin/plugin/dapp/paracross/executor"
paraexec
"github.com/33cn/plugin/plugin/dapp/paracross/executor"
paracross
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
)
)
...
@@ -326,12 +327,6 @@ func (client *client) getLastBlockInfo() (int64, *types.Block, error) {
...
@@ -326,12 +327,6 @@ func (client *client) getLastBlockInfo() (int64, *types.Block, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
-
2
,
nil
,
err
return
-
2
,
nil
,
err
}
}
if
main
.
Detail
.
Block
.
Height
!=
startHeight
{
plog
.
Error
(
"get start seq's main block height not expected as config"
,
"config"
,
startHeight
,
"main"
,
main
.
Detail
.
Block
.
Height
)
//main chain node is not the initial node and the startHeight not match as config
panic
(
"main chain node is not the initial node, need switch main node or delete db"
)
}
lastBlock
.
MainHash
=
main
.
Detail
.
Block
.
ParentHash
lastBlock
.
MainHash
=
main
.
Detail
.
Block
.
ParentHash
lastBlock
.
MainHeight
=
main
.
Detail
.
Block
.
Height
-
1
lastBlock
.
MainHeight
=
main
.
Detail
.
Block
.
Height
-
1
return
blockedSeq
,
lastBlock
,
nil
return
blockedSeq
,
lastBlock
,
nil
...
@@ -452,18 +447,18 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type
...
@@ -452,18 +447,18 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type
//not consistent case be processed at below
//not consistent case be processed at below
plog
.
Error
(
"RequestTx"
,
"preMainHash"
,
hex
.
EncodeToString
(
preMainBlockHash
),
"currSeq preMainHash"
,
hex
.
EncodeToString
(
blockSeq
.
Detail
.
Block
.
ParentHash
),
plog
.
Error
(
"RequestTx"
,
"preMainHash"
,
hex
.
EncodeToString
(
preMainBlockHash
),
"currSeq preMainHash"
,
hex
.
EncodeToString
(
blockSeq
.
Detail
.
Block
.
ParentHash
),
"currSeq mainHash"
,
hex
.
EncodeToString
(
blockSeq
.
Seq
.
Hash
),
"curr seq"
,
currSeq
,
"ty"
,
blockSeq
.
Seq
.
Type
,
"currSeq Mainheight"
,
blockSeq
.
Detail
.
Block
.
Height
)
"currSeq mainHash"
,
hex
.
EncodeToString
(
blockSeq
.
Seq
.
Hash
),
"curr seq"
,
currSeq
,
"ty"
,
blockSeq
.
Seq
.
Type
,
"currSeq Mainheight"
,
blockSeq
.
Detail
.
Block
.
Height
)
return
nil
,
nil
,
p
t
.
ErrParaCurHashNotMatch
return
nil
,
nil
,
p
aracross
.
ErrParaCurHashNotMatch
}
}
//lastSeq < CurrSeq case:
//lastSeq < CurrSeq case:
//lastSeq = currSeq-1, main node not update
//lastSeq = currSeq-1, main node not update
if
lastSeq
+
1
==
currSeq
{
if
lastSeq
+
1
==
currSeq
{
plog
.
Debug
(
"Waiting new sequence from main chain"
)
plog
.
Debug
(
"Waiting new sequence from main chain"
)
return
nil
,
nil
,
p
t
.
ErrParaWaitingNewSeq
return
nil
,
nil
,
p
aracross
.
ErrParaWaitingNewSeq
}
}
// 1. lastSeq < currSeq-1
// 1. lastSeq < currSeq-1
// 2. lastSeq >= currSeq and seq not consistent or fork case
// 2. lastSeq >= currSeq and seq not consistent or fork case
return
nil
,
nil
,
p
t
.
ErrParaCurHashNotMatch
return
nil
,
nil
,
p
aracross
.
ErrParaCurHashNotMatch
}
}
//genesis block scenario, new main node's blockHash as preMainHash, genesis sequence+1 as currSeq
//genesis block scenario, new main node's blockHash as preMainHash, genesis sequence+1 as currSeq
...
@@ -532,7 +527,7 @@ func (client *client) switchHashMatchedBlock(currSeq int64) (int64, []byte, erro
...
@@ -532,7 +527,7 @@ func (client *client) switchHashMatchedBlock(currSeq int64) (int64, []byte, erro
"new currSeq"
,
mainSeq
+
1
,
"new preMainBlockHash"
,
hex
.
EncodeToString
(
block
.
MainHash
))
"new currSeq"
,
mainSeq
+
1
,
"new preMainBlockHash"
,
hex
.
EncodeToString
(
block
.
MainHash
))
return
mainSeq
+
1
,
block
.
MainHash
,
nil
return
mainSeq
+
1
,
block
.
MainHash
,
nil
}
}
return
-
2
,
nil
,
p
t
.
ErrParaCurHashNotMatch
return
-
2
,
nil
,
p
aracross
.
ErrParaCurHashNotMatch
}
}
func
(
client
*
client
)
removeBlocks
(
endHeight
int64
)
error
{
func
(
client
*
client
)
removeBlocks
(
endHeight
int64
)
error
{
...
@@ -587,7 +582,7 @@ func (client *client) CreateBlock() {
...
@@ -587,7 +582,7 @@ func (client *client) CreateBlock() {
txs
,
blockOnMain
,
err
:=
client
.
RequestTx
(
currSeq
,
lastSeqMainHash
)
txs
,
blockOnMain
,
err
:=
client
.
RequestTx
(
currSeq
,
lastSeqMainHash
)
if
err
!=
nil
{
if
err
!=
nil
{
incSeqFlag
=
false
incSeqFlag
=
false
if
err
==
p
t
.
ErrParaCurHashNotMatch
{
if
err
==
p
aracross
.
ErrParaCurHashNotMatch
{
newSeq
,
newSeqMainHash
,
err
:=
client
.
switchHashMatchedBlock
(
currSeq
)
newSeq
,
newSeqMainHash
,
err
:=
client
.
switchHashMatchedBlock
(
currSeq
)
if
err
==
nil
{
if
err
==
nil
{
currSeq
=
newSeq
currSeq
=
newSeq
...
@@ -799,22 +794,22 @@ func checkMinerTx(current *types.BlockDetail) error {
...
@@ -799,22 +794,22 @@ func checkMinerTx(current *types.BlockDetail) error {
}
}
baseTx
:=
current
.
Block
.
Txs
[
0
]
baseTx
:=
current
.
Block
.
Txs
[
0
]
//判断交易类型和执行情况
//判断交易类型和执行情况
var
action
p
t
.
ParacrossAction
var
action
p
aracross
.
ParacrossAction
err
:=
types
.
Decode
(
baseTx
.
GetPayload
(),
&
action
)
err
:=
types
.
Decode
(
baseTx
.
GetPayload
(),
&
action
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
action
.
GetTy
()
!=
pt
.
ParacrossActionMiner
{
if
action
.
GetTy
()
!=
pt
.
ParacrossActionMiner
{
return
p
t
.
ErrParaMinerTxType
return
p
aracross
.
ErrParaMinerTxType
}
}
//判断交易执行是否OK
//判断交易执行是否OK
if
action
.
GetMiner
()
==
nil
{
if
action
.
GetMiner
()
==
nil
{
return
p
t
.
ErrParaEmptyMinerTx
return
p
aracross
.
ErrParaEmptyMinerTx
}
}
//判断exec 是否成功
//判断exec 是否成功
if
current
.
Receipts
[
0
]
.
Ty
!=
types
.
ExecOk
{
if
current
.
Receipts
[
0
]
.
Ty
!=
types
.
ExecOk
{
return
p
t
.
ErrParaMinerExecErr
return
p
aracross
.
ErrParaMinerExecErr
}
}
return
nil
return
nil
}
}
...
...
plugin/consensus/para/para_test.go
View file @
2ec44b30
...
@@ -8,16 +8,17 @@ import (
...
@@ -8,16 +8,17 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
//"github.com/stretchr/testify/mock"
//"github.com/stretchr/testify/mock"
"errors"
"errors"
"math/rand"
"testing"
"testing"
"time"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
typesmocks
"github.com/33cn/chain33/types/mocks"
typesmocks
"github.com/33cn/chain33/types/mocks"
paraexec
"github.com/33cn/plugin/plugin/dapp/paracross/executor"
paraexec
"github.com/33cn/plugin/plugin/dapp/paracross/executor"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/mock"
"encoding/hex"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/address"
"math/rand"
"time"
)
)
var
(
var
(
...
@@ -29,67 +30,9 @@ var (
...
@@ -29,67 +30,9 @@ var (
func
TestFilterTxsForPara
(
t
*
testing
.
T
)
{
func
TestFilterTxsForPara
(
t
*
testing
.
T
)
{
types
.
Init
(
Title
,
nil
)
types
.
Init
(
Title
,
nil
)
//all para tx group
detail
,
filterTxs
,
_
:=
createTestTxs
(
t
)
tx5
,
err
:=
createCrossParaTx
(
"toB"
,
5
)
assert
.
Nil
(
t
,
err
)
tx6
,
err
:=
createCrossParaTx
(
"toB"
,
6
)
assert
.
Nil
(
t
,
err
)
tx56
:=
[]
*
types
.
Transaction
{
tx5
,
tx6
}
txGroup56
,
err
:=
createTxsGroup
(
tx56
)
assert
.
Nil
(
t
,
err
)
//para cross tx group fail
tx7
,
_
:=
createCrossParaTx
(
"toA"
,
1
)
tx8
,
err
:=
createCrossParaTx
(
"toB"
,
8
)
assert
.
Nil
(
t
,
err
)
tx78
:=
[]
*
types
.
Transaction
{
tx7
,
tx8
}
txGroup78
,
err
:=
createTxsGroup
(
tx78
)
assert
.
Nil
(
t
,
err
)
//all para tx group
txB
,
err
:=
createCrossParaTx
(
"toB"
,
11
)
assert
.
Nil
(
t
,
err
)
txC
,
err
:=
createCrossParaTx
(
"toB"
,
12
)
assert
.
Nil
(
t
,
err
)
txBC
:=
[]
*
types
.
Transaction
{
txB
,
txC
}
txGroupBC
,
err
:=
createTxsGroup
(
txBC
)
assert
.
Nil
(
t
,
err
)
//single para tx
txD
,
err
:=
createCrossParaTempTx
(
"toB"
,
10
)
assert
.
Nil
(
t
,
err
)
txs
:=
[]
*
types
.
Transaction
{}
txs
=
append
(
txs
,
txGroup56
...
)
txs
=
append
(
txs
,
txGroup78
...
)
txs
=
append
(
txs
,
txGroupBC
...
)
txs
=
append
(
txs
,
txD
)
//for i, tx := range txs {
// t.Log("tx exec name", "i", i, "name", string(tx.Execer))
//}
recpt5
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
}
recpt6
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
}
log7
:=
&
types
.
ReceiptLog
{
Ty
:
types
.
TyLogErr
}
logs
:=
[]
*
types
.
ReceiptLog
{
log7
}
recpt7
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
,
Logs
:
logs
}
recpt8
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
}
recptB
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
}
recptC
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
}
recptD
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
}
receipts
:=
[]
*
types
.
ReceiptData
{
recpt5
,
recpt6
,
recpt7
,
recpt8
,
recptB
,
recptC
,
recptD
}
block
:=
&
types
.
Block
{
Txs
:
txs
}
detail
:=
&
types
.
BlockDetail
{
Block
:
block
,
Receipts
:
receipts
,
}
rst
:=
paraexec
.
FilterTxsForPara
(
Title
,
detail
)
rst
:=
paraexec
.
FilterTxsForPara
(
Title
,
detail
)
filterTxs
:=
[]
*
types
.
Transaction
{
tx5
,
tx6
,
txB
,
txC
}
assert
.
Equal
(
t
,
filterTxs
,
rst
)
assert
.
Equal
(
t
,
filterTxs
,
rst
)
}
}
...
@@ -180,3 +123,101 @@ func TestGetBlockHashForkHeightOnMainChain(t *testing.T) {
...
@@ -180,3 +123,101 @@ func TestGetBlockHashForkHeightOnMainChain(t *testing.T) {
assert
.
Equal
(
t
,
int64
(
1
),
ret
)
assert
.
Equal
(
t
,
int64
(
1
),
ret
)
}
}
func
createTestTxs
(
t
*
testing
.
T
)
(
*
types
.
BlockDetail
,[]
*
types
.
Transaction
,[]
*
types
.
Transaction
){
//all para tx group
tx5
,
err
:=
createCrossParaTx
(
"toB"
,
5
)
assert
.
Nil
(
t
,
err
)
tx6
,
err
:=
createCrossParaTx
(
"toB"
,
6
)
assert
.
Nil
(
t
,
err
)
tx56
:=
[]
*
types
.
Transaction
{
tx5
,
tx6
}
txGroup56
,
err
:=
createTxsGroup
(
tx56
)
assert
.
Nil
(
t
,
err
)
//para cross tx group fail
tx7
,
_
:=
createCrossParaTx
(
"toA"
,
1
)
tx8
,
err
:=
createCrossParaTx
(
"toB"
,
8
)
assert
.
Nil
(
t
,
err
)
tx78
:=
[]
*
types
.
Transaction
{
tx7
,
tx8
}
txGroup78
,
err
:=
createTxsGroup
(
tx78
)
assert
.
Nil
(
t
,
err
)
//all para tx group
txB
,
err
:=
createCrossParaTx
(
"toB"
,
11
)
assert
.
Nil
(
t
,
err
)
txC
,
err
:=
createCrossParaTx
(
"toB"
,
12
)
assert
.
Nil
(
t
,
err
)
txBC
:=
[]
*
types
.
Transaction
{
txB
,
txC
}
txGroupBC
,
err
:=
createTxsGroup
(
txBC
)
assert
.
Nil
(
t
,
err
)
//single para tx
txD
,
err
:=
createCrossParaTempTx
(
"toB"
,
10
)
assert
.
Nil
(
t
,
err
)
txs
:=
[]
*
types
.
Transaction
{}
txs
=
append
(
txs
,
txGroup56
...
)
txs
=
append
(
txs
,
txGroup78
...
)
txs
=
append
(
txs
,
txGroupBC
...
)
txs
=
append
(
txs
,
txD
)
//for i, tx := range txs {
// t.Log("tx exec name", "i", i, "name", string(tx.Execer))
//}
recpt5
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecOk
}
recpt6
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecOk
}
log7
:=
&
types
.
ReceiptLog
{
Ty
:
types
.
TyLogErr
}
logs
:=
[]
*
types
.
ReceiptLog
{
log7
}
recpt7
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
,
Logs
:
logs
}
recpt8
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
}
recptB
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
}
recptC
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
}
recptD
:=
&
types
.
ReceiptData
{
Ty
:
types
.
ExecPack
}
receipts
:=
[]
*
types
.
ReceiptData
{
recpt5
,
recpt6
,
recpt7
,
recpt8
,
recptB
,
recptC
,
recptD
}
block
:=
&
types
.
Block
{
Height
:
10
,
Txs
:
txs
}
detail
:=
&
types
.
BlockDetail
{
Block
:
block
,
Receipts
:
receipts
,
}
filterTxs
:=
[]
*
types
.
Transaction
{
tx5
,
tx6
,
txB
,
txC
}
return
detail
,
filterTxs
,
txs
}
func
TestAddMinerTx
(
t
*
testing
.
T
){
pk
,
err
:=
hex
.
DecodeString
(
minerPrivateKey
)
assert
.
Nil
(
t
,
err
)
secp
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
assert
.
Nil
(
t
,
err
)
priKey
,
err
:=
secp
.
PrivKeyFromBytes
(
pk
)
assert
.
Nil
(
t
,
err
)
mainForkParacrossCommitTx
=
1
block
:=
&
types
.
Block
{}
mainDetail
,
filterTxs
,
allTxs
:=
createTestTxs
(
t
)
mainBlock
:=
&
types
.
BlockSeq
{
Seq
:&
types
.
BlockSequence
{},
Detail
:
mainDetail
}
para
:=
new
(
client
)
para
.
privateKey
=
priKey
para
.
addMinerTx
(
nil
,
block
,
mainBlock
,
allTxs
)
ret
:=
checkTxInMainBlock
(
filterTxs
[
0
],
mainDetail
)
assert
.
True
(
t
,
ret
)
tx2
,
_
:=
createCrossMainTx
(
"toA"
)
ret
=
checkTxInMainBlock
(
tx2
,
mainDetail
)
assert
.
False
(
t
,
ret
)
}
\ No newline at end of file
plugin/consensus/para/paratxrequest_test.go
View file @
2ec44b30
...
@@ -25,6 +25,7 @@ import (
...
@@ -25,6 +25,7 @@ import (
typesmocks
"github.com/33cn/chain33/types/mocks"
typesmocks
"github.com/33cn/chain33/types/mocks"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"time"
)
)
func
init
()
{
func
init
()
{
...
@@ -273,3 +274,31 @@ func TestGetConsensusStatus(t *testing.T) {
...
@@ -273,3 +274,31 @@ func TestGetConsensusStatus(t *testing.T) {
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
1
),
ret
.
Height
)
assert
.
Equal
(
t
,
int64
(
1
),
ret
.
Height
)
}
}
func
TestSendCommitMsg
(
t
*
testing
.
T
){
para
:=
new
(
client
)
grpcClient
:=
&
typesmocks
.
Chain33Client
{}
//grpcClient.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, errors.New("err")).Once()
para
.
grpcClient
=
grpcClient
commitCli
:=
new
(
commitMsgClient
)
commitCli
.
paraClient
=
para
commitCli
.
quit
=
make
(
chan
struct
{})
commitCli
.
paraClient
.
wg
.
Add
(
1
)
sendMsgCh
:=
make
(
chan
*
types
.
Transaction
,
1
)
go
commitCli
.
sendCommitMsg
(
sendMsgCh
)
//reply := &types.Reply{
// IsOk: true,
// Msg: types.Encode(status),
//}
grpcClient
.
On
(
"SendTransaction"
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
nil
,
types
.
ErrNotFound
)
.
Twice
()
tx
:=
&
types
.
Transaction
{}
sendMsgCh
<-
tx
time
.
Sleep
(
3
*
time
.
Second
)
//para.BaseClient.Close()
close
(
commitCli
.
quit
)
}
\ No newline at end of file
plugin/dapp/paracross/testnode/cfg.go
View file @
2ec44b30
...
@@ -110,6 +110,7 @@ searchHashMatchedBlockDepth=10000
...
@@ -110,6 +110,7 @@ searchHashMatchedBlockDepth=10000
#创世地址额度
#创世地址额度
genesisAmount=100000000
genesisAmount=100000000
MainBlockHashForkHeight=1
MainBlockHashForkHeight=1
MainForkParacrossCommitTx=1
[store]
[store]
name="mavl"
name="mavl"
...
...
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