Commit 4e3ba138 authored by mdj33's avatar mdj33 Committed by vipwzw

improve blockhash save

parent 18d709fb
...@@ -340,7 +340,7 @@ function para_cross_transfer_withdraw() { ...@@ -340,7 +340,7 @@ function para_cross_transfer_withdraw() {
echo "para_cross_transfer_withdraw failed" echo "para_cross_transfer_withdraw failed"
${CLI} tx query -s "$hash2" ${CLI} tx query -s "$hash2"
${PARA_CLI} tx query -s "$hash2" ${PARA_CLI} tx query -s "$hash2"
${PARA_CLI} asset balance -a 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -e user.p.para.paracross --asset_exec paracross --asset_symbol coins.para ${PARA_CLI} asset balance -a 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -e user.p.para.paracross --asset_exec paracross --asset_symbol coins.bty
exit 1 exit 1
fi fi
else else
......
...@@ -237,10 +237,10 @@ func getMostCommit(stat *pt.ParacrossHeightStatus) (int, string) { ...@@ -237,10 +237,10 @@ func getMostCommit(stat *pt.ParacrossHeightStatus) (int, string) {
} }
//需要在ForkLoopCheckCommitTxDone后使用 //需要在ForkLoopCheckCommitTxDone后使用
func getMostResults(mostHash []byte, stat *pt.ParacrossHeightStatus) ([]byte, []byte, []byte, []byte) { func getMostResults(mostHash []byte, stat *pt.ParacrossHeightStatus) ([]byte,[]byte, []byte, []byte, []byte) {
for i, hash := range stat.Details.BlockHash { for i, hash := range stat.BlockDetails.BlockHashs {
if bytes.Equal(mostHash, hash) { if bytes.Equal(mostHash, hash) {
return stat.Details.TxResult[i], stat.Details.TxHashs[i], stat.Details.CrossTxResult[i], stat.Details.CrossTxHashs[i] return stat.BlockDetails.StateHashs[i], stat.BlockDetails.TxResults[i], stat.BlockDetails.TxHashs[i], stat.BlockDetails.CrossTxResults[i], stat.BlockDetails.CrossTxHashs[i]
} }
} }
return nil, nil, nil, nil return nil, nil, nil, nil
...@@ -316,6 +316,21 @@ func (a *action) getNodesGroup(title string) (map[string]struct{}, error) { ...@@ -316,6 +316,21 @@ func (a *action) getNodesGroup(title string) (map[string]struct{}, error) {
} }
//相同的BlockHash,只保留一份数据
func updateCommitBlockHashs(stat *pt.ParacrossHeightStatus,commit *pt.ParacrossNodeStatus) {
for _, blockHash := range stat.BlockDetails.BlockHashs {
if bytes.Equal(blockHash,commit.BlockHash) {
return
}
}
stat.BlockDetails.BlockHashs = append(stat.BlockDetails.BlockHashs, commit.BlockHash)
stat.BlockDetails.StateHashs = append(stat.BlockDetails.StateHashs, commit.StateHash)
stat.BlockDetails.TxResults = append(stat.BlockDetails.TxResults, commit.TxResult)
stat.BlockDetails.TxHashs = append(stat.BlockDetails.TxHashs, commit.TxHashs[0])
stat.BlockDetails.CrossTxResults = append(stat.BlockDetails.CrossTxResults, commit.CrossTxResult)
stat.BlockDetails.CrossTxHashs = append(stat.BlockDetails.CrossTxHashs, commit.CrossTxHashs[0])
}
//根据nodes过滤掉可能退出了的addrs //根据nodes过滤掉可能退出了的addrs
func updateCommitAddrs(stat *pt.ParacrossHeightStatus, nodes map[string]struct{}) { func updateCommitAddrs(stat *pt.ParacrossHeightStatus, nodes map[string]struct{}) {
details := &pt.ParacrossStatusDetails{} details := &pt.ParacrossStatusDetails{}
...@@ -323,14 +338,6 @@ func updateCommitAddrs(stat *pt.ParacrossHeightStatus, nodes map[string]struct{} ...@@ -323,14 +338,6 @@ func updateCommitAddrs(stat *pt.ParacrossHeightStatus, nodes map[string]struct{}
if _, ok := nodes[addr]; ok { if _, ok := nodes[addr]; ok {
details.Addrs = append(details.Addrs, addr) details.Addrs = append(details.Addrs, addr)
details.BlockHash = append(details.BlockHash, stat.Details.BlockHash[i]) details.BlockHash = append(details.BlockHash, stat.Details.BlockHash[i])
if stat.MainHeight >= getDappForkHeight(pt.ForkLoopCheckCommitTxDone) {
details.TxResult = append(details.TxResult, stat.Details.TxResult[i])
details.TxHashs = append(details.TxHashs, stat.Details.TxHashs[i])
details.CrossTxResult = append(details.CrossTxResult, stat.Details.CrossTxResult[i])
details.CrossTxHashs = append(details.CrossTxHashs, stat.Details.CrossTxHashs[i])
}
} }
} }
stat.Details = details stat.Details = details
...@@ -424,10 +431,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error ...@@ -424,10 +431,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
stat.MainHash = commit.Status.MainBlockHash stat.MainHash = commit.Status.MainBlockHash
} }
if commit.Status.MainBlockHeight >= getDappForkHeight(pt.ForkLoopCheckCommitTxDone) { if commit.Status.MainBlockHeight >= getDappForkHeight(pt.ForkLoopCheckCommitTxDone) {
stat.Details.TxResult = append(stat.Details.TxResult, commit.Status.TxResult) updateCommitBlockHashs(stat,commit.Status)
stat.Details.TxHashs = append(stat.Details.TxHashs, commit.Status.TxHashs[0])
stat.Details.CrossTxResult = append(stat.Details.CrossTxResult, commit.Status.CrossTxResult)
stat.Details.CrossTxHashs = append(stat.Details.CrossTxHashs, commit.Status.CrossTxHashs[0])
} }
receipt = makeCommitReceipt(a.fromaddr, commit, nil, stat) receipt = makeCommitReceipt(a.fromaddr, commit, nil, stat)
...@@ -443,19 +447,13 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error ...@@ -443,19 +447,13 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
if found { if found {
stat.Details.BlockHash[index] = commit.Status.BlockHash stat.Details.BlockHash[index] = commit.Status.BlockHash
if commit.Status.MainBlockHeight >= getDappForkHeight(pt.ForkLoopCheckCommitTxDone) { if commit.Status.MainBlockHeight >= getDappForkHeight(pt.ForkLoopCheckCommitTxDone) {
stat.Details.TxResult[index] = commit.Status.TxResult updateCommitBlockHashs(stat,commit.Status)
stat.Details.TxHashs[index] = commit.Status.TxHashs[0]
stat.Details.CrossTxResult[index] = commit.Status.CrossTxResult
stat.Details.CrossTxHashs[index] = commit.Status.CrossTxHashs[0]
} }
} else { } else {
stat.Details.Addrs = append(stat.Details.Addrs, a.fromaddr) stat.Details.Addrs = append(stat.Details.Addrs, a.fromaddr)
stat.Details.BlockHash = append(stat.Details.BlockHash, commit.Status.BlockHash) stat.Details.BlockHash = append(stat.Details.BlockHash, commit.Status.BlockHash)
if commit.Status.MainBlockHeight >= getDappForkHeight(pt.ForkLoopCheckCommitTxDone) { if commit.Status.MainBlockHeight >= getDappForkHeight(pt.ForkLoopCheckCommitTxDone) {
stat.Details.TxResult = append(stat.Details.TxResult, commit.Status.TxResult) updateCommitBlockHashs(stat,commit.Status)
stat.Details.TxHashs = append(stat.Details.TxHashs, commit.Status.TxHashs[0])
stat.Details.CrossTxResult = append(stat.Details.CrossTxResult, commit.Status.CrossTxResult)
stat.Details.CrossTxHashs = append(stat.Details.CrossTxHashs, commit.Status.CrossTxHashs[0])
} }
} }
...@@ -654,13 +652,14 @@ func (a *action) commitTxDoneByStat(stat *pt.ParacrossHeightStatus, titleStatus ...@@ -654,13 +652,14 @@ func (a *action) commitTxDoneByStat(stat *pt.ParacrossHeightStatus, titleStatus
r := makeCommitStatReceipt(stat) r := makeCommitStatReceipt(stat)
receipt = mergeReceipt(receipt, r) receipt = mergeReceipt(receipt, r)
txRst, txHash, crossTxRst, crossTxHash := getMostResults([]byte(mostHash), stat) stateHash, txRst, txHash, crossTxRst, crossTxHash := getMostResults([]byte(mostHash), stat)
mostStatus := &pt.ParacrossNodeStatus{ mostStatus := &pt.ParacrossNodeStatus{
MainBlockHash: stat.MainHash, MainBlockHash: stat.MainHash,
MainBlockHeight: stat.MainHeight, MainBlockHeight: stat.MainHeight,
Title: stat.Title, Title: stat.Title,
Height: stat.Height, Height: stat.Height,
BlockHash: []byte(mostHash), BlockHash: []byte(mostHash),
StateHash: stateHash,
TxResult: txRst, TxResult: txRst,
TxHashs: [][]byte{txHash}, TxHashs: [][]byte{txHash},
CrossTxResult: crossTxRst, CrossTxResult: crossTxRst,
......
...@@ -11,10 +11,16 @@ package types; ...@@ -11,10 +11,16 @@ package types;
message ParacrossStatusDetails { message ParacrossStatusDetails {
repeated string addrs = 1; repeated string addrs = 1;
repeated bytes blockHash = 2; repeated bytes blockHash = 2;
repeated bytes txResult = 3; }
repeated bytes txHashs = 4;
repeated bytes crossTxResult = 5; //记录不同blockHash的详细数据
repeated bytes crossTxHashs = 6; message ParacrossStatusBlockDetails {
repeated bytes blockHashs = 1;
repeated bytes stateHashs = 2;
repeated bytes txResults = 3;
repeated bytes txHashs = 4;
repeated bytes crossTxResults = 5;
repeated bytes crossTxHashs = 6;
} }
message ParacrossHeightStatus { message ParacrossHeightStatus {
...@@ -25,6 +31,7 @@ message ParacrossHeightStatus { ...@@ -25,6 +31,7 @@ message ParacrossHeightStatus {
ParacrossStatusDetails details = 4; ParacrossStatusDetails details = 4;
int64 mainHeight = 5; int64 mainHeight = 5;
bytes mainHash = 6; bytes mainHash = 6;
ParacrossStatusBlockDetails blockDetails = 7;
} }
message ParacrossHeightStatusRsp { message ParacrossHeightStatusRsp {
......
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