Commit 29629ee7 authored by mdj33's avatar mdj33 Committed by vipwzw

node quit trigger commit done

parent e989b8fb
......@@ -113,6 +113,8 @@ genesisAmount=100000000
MainForkParacrossCommitTx=2270000
#平行链自共识开启对应的主链高度,需要大于等于MainForkParacrossCommitTx=2270000, -1 不开启
MainParaSelfConsensusForkHeight=-1
#主链开启循环检查共识交易done的fork高度
MainLoopCheckCommitTxDoneForkHeight=-1
[store]
name="kvmvccmavl"
......
This diff is collapsed.
......@@ -77,6 +77,25 @@ func (e *Paracross) ExecDelLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *
}
key := calcLocalNodeTitleDone(g.Title, g.TargetAddr)
set.KV = append(set.KV, &types.KeyValue{Key: key, Value: nil})
}else if log.Ty == pt.TyLogParacrossCommitDone {
var g pt.ReceiptParacrossDone
types.Decode(log.Log, &g)
g.Height = g.Height - 1
key := calcLocalTitleKey(g.Title)
set.KV = append(set.KV, &types.KeyValue{Key: key, Value: types.Encode(&g)})
key = calcLocalHeightKey(g.Title, g.Height)
set.KV = append(set.KV, &types.KeyValue{Key: key, Value: nil})
if !types.IsPara() {
r, err := e.saveLocalParaTxsFork(&g, true)
if err != nil {
return nil, err
}
set.KV = append(set.KV, r.KV...)
}
}
}
return &set, nil
......
......@@ -81,6 +81,23 @@ func (e *Paracross) ExecLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *typ
}
key := calcLocalNodeTitleDone(g.Title, g.TargetAddr)
set.KV = append(set.KV, &types.KeyValue{Key: key, Value: types.Encode(&g)})
}else if log.Ty == pt.TyLogParacrossCommitDone {
var g pt.ReceiptParacrossDone
types.Decode(log.Log, &g)
key := calcLocalTitleKey(g.Title)
set.KV = append(set.KV, &types.KeyValue{Key: key, Value: types.Encode(&g)})
key = calcLocalHeightKey(g.Title, g.Height)
set.KV = append(set.KV, &types.KeyValue{Key: key, Value: types.Encode(&g)})
if !types.IsPara() {
r, err := e.saveLocalParaTxsFork(&g, false)
if err != nil {
return nil, err
}
set.KV = append(set.KV, r.KV...)
}
}
}
return &set, nil
......
......@@ -68,7 +68,7 @@ func (c *Paracross) checkTxGroup(tx *types.Transaction, index int) ([]*types.Tra
}
func (c *Paracross) saveLocalParaTxs(tx *types.Transaction, isDel bool) (*types.LocalDBSet, error) {
var set types.LocalDBSet
var payload pt.ParacrossAction
err := types.Decode(tx.Payload, &payload)
......@@ -80,10 +80,41 @@ func (c *Paracross) saveLocalParaTxs(tx *types.Transaction, isDel bool) (*types.
}
commit := payload.GetCommit()
crossTxHashs, crossTxResult, err := getCrossTxHashs(c.GetAPI(), commit)
crossTxHashs, crossTxResult, err := getCrossTxHashs(c.GetAPI(), commit.Status)
if err != nil {
return nil, err
}
return c.udpateLocalParaTxs(commit.Status.Title, commit.Status.Height,crossTxHashs,crossTxResult,isDel)
}
//无法获取到commit tx信息,从commitDone 结构里面构建
func (c *Paracross) saveLocalParaTxsFork(commitDone *pt.ReceiptParacrossDone,isDel bool) (*types.LocalDBSet, error) {
status := &pt.ParacrossNodeStatus{
MainBlockHash: commitDone.MainBlockHash,
MainBlockHeight: commitDone.MainBlockHeight,
Title: commitDone.Title,
Height: commitDone.Height,
BlockHash:commitDone.BlockHash,
TxResult: commitDone.TxResult,
TxHashs: commitDone.TxHashs,
CrossTxResult: commitDone.CrossTxResult,
CrossTxHashs: commitDone.CrossTxHashs,
}
crossTxHashs, crossTxResult, err := getCrossTxHashs(c.GetAPI(), status)
if err != nil {
return nil, err
}
return c.udpateLocalParaTxs(commitDone.Title, commitDone.Height,crossTxHashs,crossTxResult,isDel)
}
func (c *Paracross) udpateLocalParaTxs(paraTitle string, paraHeight int64,crossTxHashs [][]byte, crossTxResult []byte, isDel bool) (*types.LocalDBSet, error) {
var set types.LocalDBSet
if len(crossTxHashs) == 0 {
return &set, nil
}
......@@ -93,8 +124,8 @@ func (c *Paracross) saveLocalParaTxs(tx *types.Transaction, isDel bool) (*types.
paraTx, err := GetTx(c.GetAPI(), crossTxHashs[i])
if err != nil {
clog.Crit("paracross.Commit Load Tx failed", "para title", commit.Status.Title,
"para height", commit.Status.Height, "para tx index", i, "error", err, "txHash",
clog.Crit("paracross.Commit Load Tx failed", "para title", paraTitle,
"para height", paraHeight, "para tx index", i, "error", err, "txHash",
hex.EncodeToString(crossTxHashs[i]))
return nil, err
}
......@@ -102,19 +133,19 @@ func (c *Paracross) saveLocalParaTxs(tx *types.Transaction, isDel bool) (*types.
var payload pt.ParacrossAction
err = types.Decode(paraTx.Tx.Payload, &payload)
if err != nil {
clog.Crit("paracross.Commit Decode Tx failed", "para title", commit.Status.Title,
"para height", commit.Status.Height, "para tx index", i, "error", err, "txHash",
clog.Crit("paracross.Commit Decode Tx failed", "para title", paraTitle,
"para height", paraHeight, "para tx index", i, "error", err, "txHash",
hex.EncodeToString(crossTxHashs[i]))
return nil, err
}
if payload.Ty == pt.ParacrossActionAssetTransfer {
kv, err := c.updateLocalAssetTransfer(tx, paraTx.Tx, success, isDel)
kv, err := c.updateLocalAssetTransfer(paraHeight,paraTx.Tx ,success, isDel)
if err != nil {
return nil, err
}
set.KV = append(set.KV, kv)
} else if payload.Ty == pt.ParacrossActionAssetWithdraw {
kv, err := c.initLocalAssetWithdraw(tx, paraTx.Tx, true, success, isDel)
kv, err := c.initLocalAssetWithdraw(paraHeight, paraTx.Tx, true, success, isDel)
if err != nil {
return nil, err
}
......@@ -185,7 +216,7 @@ func (c *Paracross) initLocalAssetTransfer(tx *types.Transaction, success, isDel
return &types.KeyValue{Key: key, Value: types.Encode(&asset)}, nil
}
func (c *Paracross) initLocalAssetWithdraw(txCommit, tx *types.Transaction, isWithdraw, success, isDel bool) (*types.KeyValue, error) {
func (c *Paracross) initLocalAssetWithdraw(paraHeight int64, tx *types.Transaction, isWithdraw, success, isDel bool) (*types.KeyValue, error) {
key := calcLocalAssetKey(tx.Hash())
if isDel {
c.GetLocalDB().Set(key, nil)
......@@ -198,10 +229,7 @@ func (c *Paracross) initLocalAssetWithdraw(txCommit, tx *types.Transaction, isWi
if err != nil {
return nil, err
}
asset.ParaHeight, err = getCommitHeight(txCommit.Payload)
if err != nil {
return nil, err
}
asset.ParaHeight = paraHeight
var payload pt.ParacrossAction
err = types.Decode(tx.Payload, &payload)
......@@ -239,7 +267,7 @@ func (c *Paracross) initLocalAssetWithdraw(txCommit, tx *types.Transaction, isWi
return &types.KeyValue{Key: key, Value: types.Encode(&asset)}, nil
}
func (c *Paracross) updateLocalAssetTransfer(txCommit, tx *types.Transaction, success, isDel bool) (*types.KeyValue, error) {
func (c *Paracross) updateLocalAssetTransfer(paraHeight int64, tx *types.Transaction, success, isDel bool) (*types.KeyValue, error) {
clog.Debug("para execLocal", "tx hash", hex.EncodeToString(tx.Hash()))
key := calcLocalAssetKey(tx.Hash())
......@@ -253,10 +281,8 @@ func (c *Paracross) updateLocalAssetTransfer(txCommit, tx *types.Transaction, su
panic(err)
}
if !isDel {
asset.ParaHeight, err = getCommitHeight(txCommit.Payload)
if err != nil {
return nil, err
}
asset.ParaHeight = paraHeight
asset.CommitDoneHeight = c.GetHeight()
asset.Success = success
} else {
......
......@@ -545,7 +545,7 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
updateVotes(stat, nodes)
most, vote := getMostVote(stat)
if !isCommitDone(stat, nodes, most) {
if !isCommitDone(nodes, most) {
superManagerPass := false
if isSuperManager(a.fromaddr) {
//如果主链执行失败,交易不会过滤到平行链,如果主链成功,平行链直接成功
......@@ -612,6 +612,15 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
}
receipt = mergeReceipt(receipt, r)
if a.exec.GetMainHeight() > getDappForkHeight(pt.ForkLoopCheckCommitTxDone){
//node quit后,如果committx满足2/3目标,自动触发commitDone
r,err = a.loopCommitTxDone(config.Title)
if err != nil{
clog.Error("unpdateNodeGroup.loopCommitTxDone", "title", title,"err",err.Error())
}
receipt = mergeReceipt(receipt, r)
}
stat.Status = pt.ParacrossNodeClosed
stat.Height = a.height
}
......@@ -664,7 +673,10 @@ func unpdateNodeGroup(db dbm.KV, title, addr string, add bool) (*types.Receipt,
}
}
}
err = db.Set(key,types.Encode(&item))
if err != nil {
return nil, errors.Wrapf(err,"unpdateNodeGroup set dbkey=%s",key)
}
return makeParaNodeGroupReceipt(title, &copyItem, &item), nil
}
......
......@@ -11,6 +11,10 @@ package types;
message ParacrossStatusDetails {
repeated string addrs = 1;
repeated bytes blockHash = 2;
repeated bytes txResult = 3;
repeated bytes txHashs = 4;
repeated bytes crossTxResult = 5;
repeated bytes crossTxHashs = 6;
}
message ParacrossHeightStatus {
......@@ -38,6 +42,8 @@ message ParacrossStatus {
string title = 1;
int64 height = 2;
bytes blockHash = 3;
int64 mainHeight = 4;
bytes mainHash = 5;
}
message ParacrossConsensusStatus {
......@@ -227,6 +233,12 @@ message ReceiptParacrossDone {
bytes stateHash = 6;
uint32 txCounts = 7;
bytes txResult = 8;
bytes blockHash = 9;
repeated bytes txHashs = 10;
bytes crossTxResult = 11;
repeated bytes crossTxHashs = 12;
bytes mainBlockHash = 13;
int64 mainBlockHeight = 14;
}
message ReceiptParacrossRecord {
......
......@@ -49,4 +49,6 @@ var (
ErrParaNodeOpStatusWrong = errors.New("ErrParaNodeOpStatusWrong")
//ErrParaConsensStopBlocksNotReach consensus stop blocks not reach
ErrParaConsensStopBlocksNotReach = errors.New("ErrParaConsensStopBlocksNotReach")
//ErrForkHeightNotReach fork height not reach
ErrForkHeightNotReach = errors.New("ErrForkHeightNotReach")
)
......@@ -18,8 +18,14 @@ var (
glog = log.New("module", ParaX)
// ForkCommitTx main chain support paracross commit tx
ForkCommitTx = "ForkParacrossCommitTx"
//平行链配置项对应主链的ForkCommitTx 高度
MainForkParacrossCommitTx="MainForkParacrossCommitTx"
// ParaSelfConsensForkHeight para self consens height string
ParaSelfConsensForkHeight = "MainParaSelfConsensusForkHeight"
//ForkLoopCheckCommitTxDone 循环检查共识交易done的fork
ForkLoopCheckCommitTxDone ="ForkLoopCheckCommitTxDone"
//MainLoopCheckCommitTxDoneForkHeight 平行链的配置项,对应主链的ForkLoopCheckCommitTxDone高度
MainLoopCheckCommitTxDoneForkHeight="MainLoopCheckCommitTxDoneForkHeight"
)
func init() {
......@@ -29,6 +35,7 @@ func init() {
types.RegisterDappFork(ParaX, "Enable", 0)
types.RegisterDappFork(ParaX, "ForkParacrossWithdrawFromParachain", 1298600)
types.RegisterDappFork(ParaX, ForkCommitTx, 1850000)
types.RegisterDappFork(ParaX, ForkLoopCheckCommitTxDone, -1)
}
// GetExecName get para exec name
......
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