Commit e30ad65c authored by mdj33's avatar mdj33 Committed by vipwzw

improve

parent 369b8945
...@@ -102,13 +102,14 @@ func checkCommitInfo(commit *pt.ParacrossCommitAction) error { ...@@ -102,13 +102,14 @@ func checkCommitInfo(commit *pt.ParacrossCommitAction) error {
clog.Debug("paracross.Commit check input", "height", commit.Status.Height, "mainHeight", commit.Status.MainBlockHeight, clog.Debug("paracross.Commit check input", "height", commit.Status.Height, "mainHeight", commit.Status.MainBlockHeight,
"mainHash", hex.EncodeToString(commit.Status.MainBlockHash), "blockHash", hex.EncodeToString(commit.Status.BlockHash)) "mainHash", hex.EncodeToString(commit.Status.MainBlockHash), "blockHash", hex.EncodeToString(commit.Status.BlockHash))
if !pt.IsParaForkHeight(commit.Status.MainBlockHeight, pt.ForkLoopCheckCommitTxDone) {
if commit.Status.Height == 0 { if commit.Status.Height == 0 {
if len(commit.Status.Title) == 0 || len(commit.Status.BlockHash) == 0 { if len(commit.Status.Title) == 0 || len(commit.Status.BlockHash) == 0 {
return types.ErrInvalidParam return types.ErrInvalidParam
} }
return nil return nil
} }
if !pt.IsParaForkHeight(commit.Status.MainBlockHeight, pt.ForkLoopCheckCommitTxDone) {
if len(commit.Status.MainBlockHash) == 0 || len(commit.Status.Title) == 0 || commit.Status.Height < 0 || if len(commit.Status.MainBlockHash) == 0 || len(commit.Status.Title) == 0 || commit.Status.Height < 0 ||
len(commit.Status.PreBlockHash) == 0 || len(commit.Status.BlockHash) == 0 || len(commit.Status.PreBlockHash) == 0 || len(commit.Status.BlockHash) == 0 ||
len(commit.Status.StateHash) == 0 || len(commit.Status.PreStateHash) == 0 { len(commit.Status.StateHash) == 0 || len(commit.Status.PreStateHash) == 0 {
...@@ -117,13 +118,8 @@ func checkCommitInfo(commit *pt.ParacrossCommitAction) error { ...@@ -117,13 +118,8 @@ func checkCommitInfo(commit *pt.ParacrossCommitAction) error {
return nil return nil
} }
if commit.Status.Height == 0 { if len(commit.Status.MainBlockHash) == 0 || len(commit.Status.BlockHash) == 0 ||
if len(commit.Status.Title) == 0 || len(commit.Status.BlockHash) == 0 { commit.Status.MainBlockHeight < 0 || commit.Status.Height < 0 {
return types.ErrInvalidParam
}
return nil
}
if len(commit.Status.MainBlockHash) == 0 || commit.Status.Height < 0 || len(commit.Status.BlockHash) == 0 {
return types.ErrInvalidParam return types.ErrInvalidParam
} }
...@@ -356,21 +352,30 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error ...@@ -356,21 +352,30 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
// 主链 (1)Bn1 (3) rollback-Bn1 (4) commit-done in Bn2 // 主链 (1)Bn1 (3) rollback-Bn1 (4) commit-done in Bn2
// 平行链 (2)commit (5) 将得到一个错误的块 // 平行链 (2)commit (5) 将得到一个错误的块
// 所以有必要做这个检测 // 所以有必要做这个检测
commitHeight := commit.Status.MainBlockHeight var dbMainHash []byte
commitHash := commit.Status.MainBlockHash if !types.IsPara(){
if types.IsPara() { blockHash, err := getBlockHash(a.api, commit.Status.MainBlockHeight)
commitHeight = commit.Status.Height
commitHash = commit.Status.BlockHash
}
blockHash, err := getBlockHash(a.api, commitHeight)
if err != nil { if err != nil {
clog.Error("paracross.Commit getBlockHash", "err", err, clog.Error("paracross.Commit getBlockHash", "err", err,
"commit tx height", commitHeight, "isMain", !types.IsPara(), "from", a.fromaddr) "commit tx height", commit.Status.MainBlockHeight, "from", a.fromaddr)
return nil, err return nil, err
} }
if !bytes.Equal(blockHash.Hash, commitHash) && commit.Status.Height > 0 { dbMainHash = blockHash.Hash
clog.Error("paracross.Commit blockHash not match", "isMain", !types.IsPara(), "db", hex.EncodeToString(blockHash.Hash),
"commit tx", hex.EncodeToString(commitHash), "commitHeight", commit.Status.Height, }else {
block,err := getBlockInfo(a.api,commit.Status.Height)
if err != nil{
clog.Error("paracross.Commit getBlockInfo", "err", err,"height", commit.Status.Height, "from", a.fromaddr)
return nil, err
}
dbMainHash = block.MainHash
}
//对于主链,校验的是主链高度对应的blockhash是否和commit的一致
//对于平行链, 校验的是commit信息的平行链height block对应的mainHash是否和本地相同高度对应的mainHash一致, 在主链hash一致的时候看平行链共识blockhash是否一致
if !bytes.Equal(dbMainHash, commit.Status.MainBlockHash) && commit.Status.Height > 0 {
clog.Error("paracross.Commit blockHash not match", "isMain", !types.IsPara(), "db", hex.EncodeToString(dbMainHash),
"commit", hex.EncodeToString(commit.Status.MainBlockHash), "commitHeight", commit.Status.Height,
"commitMainHeight", commit.Status.MainBlockHeight, "from", a.fromaddr) "commitMainHeight", commit.Status.MainBlockHeight, "from", a.fromaddr)
return nil, types.ErrBlockHashNoMatch return nil, types.ErrBlockHashNoMatch
} }
...@@ -519,6 +524,20 @@ func (a *action) commitTxDoneStep2(nodeStatus *pt.ParacrossNodeStatus, stat *pt. ...@@ -519,6 +524,20 @@ func (a *action) commitTxDoneStep2(nodeStatus *pt.ParacrossNodeStatus, stat *pt.
//parallel chain not need to process cross commit tx here //parallel chain not need to process cross commit tx here
if types.IsPara() { if types.IsPara() {
//平行链自共识校验
selfBlockHash, err := getBlockHash(a.api, nodeStatus.Height)
if err != nil {
clog.Error("paracross.CommitDone getBlockHash", "err", err,"commit tx height", nodeStatus.Height, "tx", hex.EncodeToString(a.txhash))
return nil, err
}
//说明本节点blockhash和共识hash不一致,需要停止本节点执行
if !bytes.Equal(selfBlockHash.Hash,nodeStatus.BlockHash){
clog.Error("paracross.CommitDone mosthash not match", "height", nodeStatus.Height,
"blockHash", hex.EncodeToString(selfBlockHash.Hash),"mosthash",hex.EncodeToString(nodeStatus.BlockHash))
return nil, pt.ErrParaCurHashNotMatch
}
//平行连进行奖励分配 //平行连进行奖励分配
rewardReceipt, err := a.reward(nodeStatus, stat) rewardReceipt, err := a.reward(nodeStatus, stat)
//错误会导致和主链处理的共识结果不一致 //错误会导致和主链处理的共识结果不一致
......
...@@ -20,7 +20,7 @@ func getTitle(db dbm.KV, key []byte) (*pt.ParacrossStatus, error) { ...@@ -20,7 +20,7 @@ func getTitle(db dbm.KV, key []byte) (*pt.ParacrossStatus, error) {
return nil, err return nil, err
} }
// 平行链如果是从其他链上移过来的, 需要增加配置, 对应title的平行链的起始高度 // 平行链如果是从其他链上移过来的, 需要增加配置, 对应title的平行链的起始高度
clog.Info("first time load title", "key", string(key)) clog.Debug("first time load title", "key", string(key))
return &pt.ParacrossStatus{Height: -1}, nil return &pt.ParacrossStatus{Height: -1}, nil
} }
...@@ -39,7 +39,7 @@ func getTitleHeight(db dbm.KV, key []byte) (*pt.ParacrossHeightStatus, error) { ...@@ -39,7 +39,7 @@ func getTitleHeight(db dbm.KV, key []byte) (*pt.ParacrossHeightStatus, error) {
if err != nil { if err != nil {
// 对应高度第一次提交commit // 对应高度第一次提交commit
if isNotFound(err) { if isNotFound(err) {
clog.Info("paracross.Commit first commit", "key", string(key)) clog.Debug("paracross.Commit first commit", "key", string(key))
} }
return nil, err return nil, err
} }
...@@ -83,6 +83,20 @@ func getBlockHash(api client.QueueProtocolAPI, height int64) (*types.ReplyHash, ...@@ -83,6 +83,20 @@ func getBlockHash(api client.QueueProtocolAPI, height int64) (*types.ReplyHash,
return hash, nil return hash, nil
} }
func getBlockInfo(api client.QueueProtocolAPI, height int64) (*types.Block, error) {
blockDetails, err := api.GetBlocks(&types.ReqBlocks{Start: height, End: height})
if err != nil {
clog.Error("paracross.Commit getBlockInfo","height",height,"err",err.Error())
return nil, err
}
if 1 != int64(len(blockDetails.Items)) {
clog.Error("paracross.Commit getBlockInfo count")
return nil, types.ErrInvalidParam
}
return blockDetails.Items[0].Block, nil
}
func isNotFound(err error) bool { func isNotFound(err error) bool {
if err != nil && (err == dbm.ErrNotFoundInDb || err == types.ErrNotFound) { if err != nil && (err == dbm.ErrNotFoundInDb || err == types.ErrNotFound) {
return true return true
......
...@@ -248,10 +248,8 @@ func (e *Paracross) ExecLocal_Miner(payload *pt.ParacrossMinerAction, tx *types. ...@@ -248,10 +248,8 @@ func (e *Paracross) ExecLocal_Miner(payload *pt.ParacrossMinerAction, tx *types.
var set types.LocalDBSet var set types.LocalDBSet
txs := e.GetTxs() txs := e.GetTxs()
forkHeight := pt.GetDappForkHeight(pt.ForkCommitTx)
//removed the 0 vote tx //removed the 0 vote tx
if payload.Status.MainBlockHeight >= forkHeight { if pt.IsParaForkHeight(payload.Status.MainBlockHeight, pt.ForkCommitTx) {
err := setMinerTxResultFork(payload.Status, txs[1:], e.GetReceipt()[1:]) err := setMinerTxResultFork(payload.Status, txs[1:], e.GetReceipt()[1:])
if err != nil { if err != nil {
return nil, err return 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