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
8a3a2058
Commit
8a3a2058
authored
Dec 14, 2018
by
mdj33
Committed by
vipwzw
Dec 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ut more
parent
36ce6853
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
33 deletions
+56
-33
para.go
plugin/consensus/para/para.go
+9
-5
paratxrequest_test.go
plugin/consensus/para/paratxrequest_test.go
+47
-28
No files found.
plugin/consensus/para/para.go
View file @
8a3a2058
...
...
@@ -435,7 +435,7 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type
return
nil
,
nil
,
-
1
,
err
}
//genesis block with seq=-1 not check
//genesis block
start
with seq=-1 not check
if
currSeq
==
0
||
(
bytes
.
Equal
(
preMainBlockHash
,
blockDetail
.
Block
.
ParentHash
)
&&
seqTy
==
addAct
)
||
(
bytes
.
Equal
(
preMainBlockHash
,
blockDetail
.
Block
.
Hash
())
&&
seqTy
==
delAct
)
{
...
...
@@ -473,6 +473,9 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type
return
nil
,
nil
,
-
1
,
paracross
.
ErrParaCurHashNotMatch
}
//genesis block scenario, new main node's blockHash as preMainHash, genesis sequence+1 as currSeq
// for genesis seq=-1 scenario, mainHash not care, as the 0 seq instead of -1
// not seq=-1 scenario, mainHash needed
func
(
client
*
client
)
syncFromGenesisBlock
()
(
int64
,
[]
byte
,
error
)
{
lastSeq
,
_
,
lastSeqMainHash
,
_
,
err
:=
client
.
getLastBlockInfo
()
if
err
!=
nil
{
...
...
@@ -484,13 +487,13 @@ func (client *client) syncFromGenesisBlock() (int64, []byte, error) {
}
// search base on para block but not last MainBlockHash, last MainBlockHash can not back tracing
func
(
client
*
client
)
switchHashMatchedBlock
(
currSeq
int64
,
preMainBlockHash
[]
byte
)
(
int64
,
[]
byte
,
error
)
{
func
(
client
*
client
)
switchHashMatchedBlock
(
currSeq
int64
)
(
int64
,
[]
byte
,
error
)
{
lastBlock
,
err
:=
client
.
RequestLastBlock
()
if
err
!=
nil
{
plog
.
Error
(
"Parachain RequestLastBlock fail"
,
"err"
,
err
)
return
-
2
,
nil
,
err
}
//genesis block scenario, get new main node's blockHash as preMainHash, genesis sequence as currSeq
if
lastBlock
.
Height
==
0
{
return
client
.
syncFromGenesisBlock
()
}
...
...
@@ -535,7 +538,8 @@ func (client *client) switchHashMatchedBlock(currSeq int64, preMainBlockHash []b
return
currSeq
,
nil
,
nil
}
plog
.
Info
(
"switchHashMatchedBlock succ"
,
"currHeight"
,
height
,
"initHeight"
,
lastBlock
.
Height
,
"set new currSeq"
,
currSeq
,
"new preMainBlockHash"
,
common
.
Bytes2Hex
(
preMainBlockHash
))
plog
.
Info
(
"switchHashMatchedBlock succ"
,
"currHeight"
,
height
,
"initHeight"
,
lastBlock
.
Height
,
"new currSeq"
,
mainSeq
+
1
,
"new preMainBlockHash"
,
common
.
Bytes2Hex
(
miner
.
MainBlockHash
))
return
mainSeq
+
1
,
miner
.
MainBlockHash
,
nil
}
return
-
2
,
nil
,
paracross
.
ErrParaCurHashNotMatch
...
...
@@ -592,7 +596,7 @@ func (client *client) CreateBlock() {
txs
,
blockOnMain
,
seqTy
,
err
:=
client
.
RequestTx
(
currSeq
,
lastSeqMainHash
)
if
err
!=
nil
{
if
err
==
paracross
.
ErrParaCurHashNotMatch
{
newSeq
,
newSeqMainHash
,
err
:=
client
.
switchHashMatchedBlock
(
currSeq
,
lastSeqMainHash
)
newSeq
,
newSeqMainHash
,
err
:=
client
.
switchHashMatchedBlock
(
currSeq
)
if
err
==
nil
{
currSeq
=
newSeq
lastSeqMainHash
=
newSeqMainHash
...
...
plugin/consensus/para/paratxrequest_test.go
View file @
8a3a2058
...
...
@@ -115,6 +115,52 @@ func (s *suiteParaClient) initEnv(cfg *types.Config, sub *types.ConfigSubModule)
}
func
(
s
*
suiteParaClient
)
TestRun_Test
()
{
//s.testGetBlock()
lastBlock
,
err
:=
s
.
para
.
RequestLastBlock
()
if
err
!=
nil
{
plog
.
Error
(
"para test"
,
"err"
,
err
.
Error
())
}
plog
.
Info
(
"para test---------1"
,
"last height"
,
lastBlock
.
Height
)
s
.
para
.
createBlock
(
lastBlock
,
nil
,
0
,
getMainBlock
(
2
,
lastBlock
.
BlockTime
+
1
))
lastBlock
,
err
=
s
.
para
.
RequestLastBlock
()
if
err
!=
nil
{
plog
.
Error
(
"para test--2"
,
"err"
,
err
.
Error
())
}
plog
.
Info
(
"para test---------"
,
"last height"
,
lastBlock
.
Height
)
s
.
para
.
createBlock
(
lastBlock
,
nil
,
1
,
getMainBlock
(
3
,
lastBlock
.
BlockTime
+
1
))
time
.
Sleep
(
time
.
Second
*
1
)
s
.
testRunGetMinerTxInfo
()
s
.
testRunRmvBlock
()
}
func
(
s
*
suiteParaClient
)
testRunGetMinerTxInfo
()
{
lastBlock
,
err
:=
s
.
para
.
RequestLastBlock
()
s
.
Nil
(
err
)
plog
.
Info
(
"para test testRunGetMinerTxInfo"
,
"last height"
,
lastBlock
.
Height
)
s
.
True
(
lastBlock
.
Height
>
1
)
status
,
err
:=
getMinerTxInfo
(
lastBlock
)
s
.
Nil
(
err
)
s
.
Equal
(
int64
(
3
),
status
.
MainBlockHeight
)
}
func
(
s
*
suiteParaClient
)
testRunRmvBlock
()
{
lastBlock
,
err
:=
s
.
para
.
RequestLastBlock
()
s
.
Nil
(
err
)
plog
.
Info
(
"para test testRunGetMinerTxInfo"
,
"last height"
,
lastBlock
.
Height
)
s
.
True
(
lastBlock
.
Height
>
1
)
s
.
para
.
removeBlocks
(
1
)
lastBlock
,
err
=
s
.
para
.
RequestLastBlock
()
s
.
Nil
(
err
)
plog
.
Info
(
"para test testRunGetMinerTxInfo"
,
"last height"
,
lastBlock
.
Height
)
s
.
Equal
(
int64
(
1
),
lastBlock
.
Height
)
}
func
(
s
*
suiteParaClient
)
SetupSuite
()
{
s
.
initEnv
(
types
.
InitCfg
(
"../../../plugin/dapp/paracross/cmd/build/chain33.para.test.toml"
))
}
...
...
@@ -136,31 +182,4 @@ func (s *suiteParaClient) TearDownSuite() {
}
//func newMockParaNode() *testnode.Chain33Mock {
// //_, sub := testnode.GetDefaultConfig()
// //cfg.Consensus.Minerstart = false
// cfg, sub := types.InitCfg("../../../plugin/dapp/paracross/cmd/build/chain33.para.test.toml")
// cfg.Consensus.StartHeight=0
// mock33 := testnode.NewWithConfig(cfg, sub, nil)
// return mock33
//}
//
//func TestSwitchHashMatchedBlock(t *testing.T) {
// mockPara := newMockParaNode()
// defer mockPara.Close()
// mockPara.WaitHeight(0)
// block := mockPara.GetBlock(0)
// assert.Equal(t, block.Height, int64(0))
//
// //consens:=mockPara.GetCfg().Consensus
// //
// //paraCli := New(mockPara.GetCfg().Consensus,nil).(*client)
// ////paraCli.BaseClient.SetQueueClient(mock33.GetClient())
// //paraCli.SetQueueClient(mockPara.GetClient())
// var currSeq int64
// var preMainBlockHash []byte
// currSeq=2
// cs := mockPara.GetConsensClient().(*client)
// cs.switchHashMatchedBlock(&currSeq,&preMainBlockHash)
// assert.Equal(t,1,currSeq)
//}
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