Commit 2147da5c authored by mdj33's avatar mdj33 Committed by 33cn

para chain check hash in advance

parent 98fd0905
...@@ -159,7 +159,7 @@ out: ...@@ -159,7 +159,7 @@ out:
selfConsensusHeight := rsp.selfStatus.Height selfConsensusHeight := rsp.selfStatus.Height
mainConsensHeight := rsp.mainStatus.Height mainConsensHeight := rsp.mainStatus.Height
plog.Info("para consensus rcv", "notify", notification, "sending", len(sendingMsgs), plog.Info("para consensus rcv", "notify", notification, "sending", len(sendingMsgs),
"mainHeigt", rsp.mainStatus.Height, "mainlockhash", common.ToHex(rsp.mainStatus.BlockHash), "mainHeigt", rsp.mainStatus.Height, "mainHash", common.ToHex(rsp.mainStatus.BlockHash),
"selfHeight", rsp.selfStatus.Height, "selfHash", common.ToHex(rsp.selfStatus.BlockHash), "sync", isSync) "selfHeight", rsp.selfStatus.Height, "selfHash", common.ToHex(rsp.selfStatus.BlockHash), "sync", isSync)
if notification == nil || isRollback { if notification == nil || isRollback {
......
...@@ -248,20 +248,25 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error ...@@ -248,20 +248,25 @@ 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) 将得到一个错误的块
// 所以有必要做这个检测 // 所以有必要做这个检测
if !types.IsPara() { commitHeight := commit.Status.MainBlockHeight
blockHash, err := getBlockHash(a.api, commit.Status.MainBlockHeight) commitHash := commit.Status.MainBlockHash
if err != nil { if types.IsPara() {
clog.Error("paracross.Commit getBlockHash", "err", err, commitHeight = commit.Status.Height
"commit tx Main.height", commit.Status.MainBlockHeight, "from", a.fromaddr) commitHash = commit.Status.BlockHash
return nil, err
}
if !bytes.Equal(blockHash.Hash, commit.Status.MainBlockHash) && commit.Status.Height > 0 {
clog.Error("paracross.Commit blockHash not match", "db", hex.EncodeToString(blockHash.Hash),
"commit tx", hex.EncodeToString(commit.Status.MainBlockHash), "commitHeight", commit.Status.Height,
"commitMainHeight", commit.Status.MainBlockHeight, "from", a.fromaddr)
return nil, types.ErrBlockHashNoMatch
}
} }
blockHash, err := getBlockHash(a.api, commitHeight)
if err != nil {
clog.Error("paracross.Commit getBlockHash", "err", err,
"commit tx height", commitHeight, "isMain", !types.IsPara(), "from", a.fromaddr)
return nil, err
}
if !bytes.Equal(blockHash.Hash, commitHash) && commit.Status.Height > 0 {
clog.Error("paracross.Commit blockHash not match", "isMain", !types.IsPara(), "db", hex.EncodeToString(blockHash.Hash),
"commit tx", hex.EncodeToString(commitHash), "commitHeight", commit.Status.Height,
"commitMainHeight", commit.Status.MainBlockHeight, "from", a.fromaddr)
return nil, types.ErrBlockHashNoMatch
}
clog.Debug("paracross.Commit check input done") clog.Debug("paracross.Commit check input done")
// 在完成共识之后来的, 增加 record log, 只记录不修改已经达成的共识 // 在完成共识之后来的, 增加 record log, 只记录不修改已经达成的共识
if commit.Status.Height <= titleStatus.Height { if commit.Status.Height <= titleStatus.Height {
......
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