Commit 71d7abb0 authored by mdj33's avatar mdj33 Committed by vipwzw

add UT

parent 32d57ba1
...@@ -289,9 +289,9 @@ func (client *commitMsgClient) getSendingTx(startHeight, endHeight int64) (*type ...@@ -289,9 +289,9 @@ func (client *commitMsgClient) getSendingTx(startHeight, endHeight int64) (*type
} }
sendingMsgs := status[:count] sendingMsgs := status[:count]
plog.Info("paracommitmsg sending", "txhash", common.ToHex(signTx.Hash()), "exec", string(signTx.Execer)) plog.Debug("paracommitmsg sending", "txhash", common.ToHex(signTx.Hash()), "exec", string(signTx.Execer))
for i, msg := range sendingMsgs { for i, msg := range sendingMsgs {
plog.Info("paracommitmsg sending", "idx", i, "height", msg.Height, "mainheight", msg.MainBlockHeight, plog.Debug("paracommitmsg sending", "idx", i, "height", msg.Height, "mainheight", msg.MainBlockHeight,
"blockhash", common.HashHex(msg.BlockHash), "mainHash", common.HashHex(msg.MainBlockHash), "blockhash", common.HashHex(msg.BlockHash), "mainHash", common.HashHex(msg.MainBlockHash),
"from", client.paraClient.authAccount) "from", client.paraClient.authAccount)
} }
...@@ -606,7 +606,6 @@ out: ...@@ -606,7 +606,6 @@ out:
//如果主链的共识高度产生了回滚,本地链也需要重新检查共识高度 //如果主链的共识高度产生了回滚,本地链也需要重新检查共识高度
if status.Height < atomic.LoadInt64(&client.consensHeight) { if status.Height < atomic.LoadInt64(&client.consensHeight) {
plog.Debug("para getMainConsensusStatus rollback", "height", status.Height, "lastHeight", atomic.LoadInt64(&client.consensHeight))
atomic.StoreInt64(&client.consensHeight, status.Height) atomic.StoreInt64(&client.consensHeight, status.Height)
client.resetNotify() client.resetNotify()
} else { } else {
...@@ -618,7 +617,7 @@ out: ...@@ -618,7 +617,7 @@ out:
if selfStatus != nil { if selfStatus != nil {
selfHeight = selfStatus.Height selfHeight = selfStatus.Height
} }
plog.Debug("para consensusHeight", "mainHeight", status.Height, "selfHeight", selfHeight) plog.Info("para consensusHeight", "mainHeight", status.Height, "selfHeight", selfHeight)
} }
} }
......
...@@ -389,7 +389,12 @@ func verifyMainBlocks(preMainBlockHash []byte, mainBlocks *pt.ParaTxDetails) err ...@@ -389,7 +389,12 @@ func verifyMainBlocks(preMainBlockHash []byte, mainBlocks *pt.ParaTxDetails) err
if err != nil { if err != nil {
return err return err
} }
pre = block.Header.Hash if block.Type == addAct {
pre = block.Header.Hash
} else {
pre = block.Header.ParentHash
}
} }
return nil return nil
} }
...@@ -525,7 +530,7 @@ out: ...@@ -525,7 +530,7 @@ out:
continue continue
} }
plog.Info("Parachain CreateBlock", "curSeq", currSeq, "count", count, "lastSeqMainHash", common.ToHex(lastSeqMainHash)) plog.Debug("Parachain CreateBlock", "curSeq", currSeq, "count", count, "lastSeqMainHash", common.ToHex(lastSeqMainHash))
paraTxs, err := client.RequestTx(currSeq, count, lastSeqMainHash) paraTxs, err := client.RequestTx(currSeq, count, lastSeqMainHash)
if err != nil { if err != nil {
currSeq, lastSeqMainHash, err = client.processHashNotMatchError(currSeq, lastSeqMainHash, err) currSeq, lastSeqMainHash, err = client.processHashNotMatchError(currSeq, lastSeqMainHash, err)
......
...@@ -138,3 +138,75 @@ func TestSendCommitMsg(t *testing.T) { ...@@ -138,3 +138,75 @@ func TestSendCommitMsg(t *testing.T) {
close(commitCli.quit) close(commitCli.quit)
} }
func TestVerifyMainBlocks(t *testing.T) {
hash0 := []byte("0")
hash1 := []byte("1")
hash2 := []byte("2")
hash3 := []byte("3")
//hash4 := []byte("4")
//hash5 := []byte("5")
hash6 := []byte("6")
header1 := &types.Header{
ParentHash: hash0,
Hash: hash1,
}
block1 := &pt.ParaTxDetail{
Type: addAct,
Header: header1,
}
header2 := &types.Header{
ParentHash: hash1,
Hash: hash2,
}
block2 := &pt.ParaTxDetail{
Type: addAct,
Header: header2,
}
header3 := &types.Header{
ParentHash: hash2,
Hash: hash3,
}
block3 := &pt.ParaTxDetail{
Type: addAct,
Header: header3,
}
//del3
header4 := &types.Header{
ParentHash: hash2,
Hash: hash3,
}
block4 := &pt.ParaTxDetail{
Type: delAct,
Header: header4,
}
//del2
header5 := &types.Header{
ParentHash: hash1,
Hash: hash2,
}
block5 := &pt.ParaTxDetail{
Type: delAct,
Header: header5,
}
header6 := &types.Header{
ParentHash: hash1,
Hash: hash6,
}
block6 := &pt.ParaTxDetail{
Type: addAct,
Header: header6,
}
mainBlocks := &pt.ParaTxDetails{
Items: []*pt.ParaTxDetail{block1, block2, block3, block4, block5, block6},
}
err := verifyMainBlocks(hash0, mainBlocks)
assert.Equal(t, nil, err)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment