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

fix last block main parent block hash

parent f6843e35
...@@ -309,7 +309,7 @@ func (client *client) removeBlocks(endHeight int64) error { ...@@ -309,7 +309,7 @@ func (client *client) removeBlocks(endHeight int64) error {
return err return err
} }
err = client.DelBlock(lastBlock, blockedSeq) err = client.DelBlock(lastBlock.Height, blockedSeq)
if err != nil { if err != nil {
plog.Error("Parachain GetBlockedSeq fail", "err", err) plog.Error("Parachain GetBlockedSeq fail", "err", err)
return err return err
...@@ -410,9 +410,9 @@ func (client *client) WriteBlock(prev []byte, paraBlock *types.Block, seq int64) ...@@ -410,9 +410,9 @@ func (client *client) WriteBlock(prev []byte, paraBlock *types.Block, seq int64)
} }
// 向blockchain删区块 // 向blockchain删区块
func (client *client) DelBlock(block *types.Block, seq int64) error { func (client *client) DelBlock(start, seq int64) error {
plog.Debug("delete block in parachain") plog.Debug("delete block in parachain")
start := block.Height //start := block.Height
if start == 0 { if start == 0 {
panic("Parachain attempt to Delete GenesisBlock !") panic("Parachain attempt to Delete GenesisBlock !")
} }
......
...@@ -67,18 +67,18 @@ func (client *commitMsgClient) handler() { ...@@ -67,18 +67,18 @@ func (client *commitMsgClient) handler() {
out: out:
for { for {
select { select {
//正常的触发检查 //正常commit 入口
case <-client.commitCh: case <-client.commitCh:
//回滚场景 //回滚场景
if atomic.LoadInt64(&client.chainHeight) < client.sendingHeight { if atomic.LoadInt64(&client.chainHeight) < client.sendingHeight {
client.clearSendingTx() client.clearSendingTx()
} }
client.procSendTx() client.procSendTx()
//发送出错场景,需要reset 重发 //出错场景入口,需要reset 重发
case <-client.resetCh: case <-client.resetCh:
client.clearSendingTx() client.clearSendingTx()
client.procSendTx() client.procSendTx()
//例行检查发送 //例行检查发送入口
case <-readTick: case <-readTick:
consensStopTimes = client.checkConsensusStop(consensStopTimes) consensStopTimes = client.checkConsensusStop(consensStopTimes)
client.procSendTx() client.procSendTx()
...@@ -104,9 +104,9 @@ func (client *commitMsgClient) clearSendingTx() { ...@@ -104,9 +104,9 @@ func (client *commitMsgClient) clearSendingTx() {
} }
func (client *commitMsgClient) procSendTx() { func (client *commitMsgClient) procSendTx() {
plog.Info("para procSendTx ---send", "consensHeight", atomic.LoadInt64(&client.consensHeight), plog.Info("para commitMsg---send", "chainHeight", atomic.LoadInt64(&client.chainHeight),"sendingHeight", client.sendingHeight,
"chainHeight", atomic.LoadInt64(&client.chainHeight), "consensHeight", atomic.LoadInt64(&client.consensHeight),"isSendingTx", client.isSendingCommitMsg(), "sync", client.isSync())
"sendingHeight", client.sendingHeight, "isSendingTx", client.isSendingCommitMsg(), "sync", client.isSync())
if client.isSendingCommitMsg() || !client.isSync() { if client.isSendingCommitMsg() || !client.isSync() {
return return
} }
...@@ -124,7 +124,7 @@ func (client *commitMsgClient) procSendTx() { ...@@ -124,7 +124,7 @@ func (client *commitMsgClient) procSendTx() {
} }
//已发送,未共识场景 //已发送,未共识场景
if client.sendingHeight > -1 && client.sendingHeight > consensHeight { if client.sendingHeight > consensHeight {
return return
} }
...@@ -135,7 +135,7 @@ func (client *commitMsgClient) procSendTx() { ...@@ -135,7 +135,7 @@ func (client *commitMsgClient) procSendTx() {
} }
client.sendingHeight = client.sendingHeight + count client.sendingHeight = client.sendingHeight + count
client.setCurrentTx(signTx) client.setCurrentTx(signTx)
client.checkTxCommitTimes = 0 atomic.StoreInt32(&client.checkTxCommitTimes,0)
client.sendMsgCh <- signTx client.sendMsgCh <- signTx
} }
...@@ -144,23 +144,23 @@ func (client *commitMsgClient) procSendTx() { ...@@ -144,23 +144,23 @@ func (client *commitMsgClient) procSendTx() {
func (client *commitMsgClient) isSync() bool { func (client *commitMsgClient) isSync() bool {
height := atomic.LoadInt64(&client.chainHeight) height := atomic.LoadInt64(&client.chainHeight)
if height <= 0 { if height <= 0 {
plog.Info("para isSync", "chainHeight", height) plog.Info("para is not Sync", "chainHeight", height)
return false return false
} }
height = atomic.LoadInt64(&client.consensHeight) height = atomic.LoadInt64(&client.consensHeight)
if height == -2 { if height == -2 {
plog.Info("para isSync", "consensHeight", height) plog.Info("para is not Sync", "consensHeight", height)
return false return false
} }
if atomic.LoadInt32(&client.authAccountIn) != 1 { if atomic.LoadInt32(&client.authAccountIn) != 1 {
plog.Info("para isSync ", "authAccountIn", atomic.LoadInt32(&client.authAccountIn)) plog.Info("para is not Sync", "authAccountIn", atomic.LoadInt32(&client.authAccountIn))
return false return false
} }
if atomic.LoadInt32(&client.minerSwitch) != 1 { if atomic.LoadInt32(&client.minerSwitch) != 1 {
plog.Info("para isSync ", "minerSwitch", atomic.LoadInt32(&client.minerSwitch)) plog.Info("para is not Sync", "minerSwitch", atomic.LoadInt32(&client.minerSwitch))
return false return false
} }
......
...@@ -98,7 +98,7 @@ func (client *client) createLocalBlock(lastBlock *pt.ParaLocalDbBlock, txs []*ty ...@@ -98,7 +98,7 @@ func (client *client) createLocalBlock(lastBlock *pt.ParaLocalDbBlock, txs []*ty
newblock.Height = lastBlock.Height + 1 newblock.Height = lastBlock.Height + 1
newblock.MainHash = mainBlock.Seq.Hash newblock.MainHash = mainBlock.Seq.Hash
newblock.MainHeight = mainBlock.Detail.Block.Height newblock.MainHeight = mainBlock.Detail.Block.Height
newblock.ParentMainHash = mainBlock.Detail.Block.ParentHash newblock.ParentMainHash = lastBlock.MainHash
newblock.BlockTime = mainBlock.Detail.Block.BlockTime newblock.BlockTime = mainBlock.Detail.Block.BlockTime
newblock.Txs = txs newblock.Txs = txs
...@@ -351,6 +351,11 @@ func (client *client) switchLocalHashMatchedBlock() (int64, []byte, error) { ...@@ -351,6 +351,11 @@ func (client *client) switchLocalHashMatchedBlock() (int64, []byte, error) {
return -2, nil, err return -2, nil, err
} }
//err = client.removeBlocks(height)
//if err != nil {
// return -2, nil, err
//}
plog.Info("switchLocalHashMatchedBlock succ", "currHeight", height, "initHeight", lastBlock.Height, plog.Info("switchLocalHashMatchedBlock succ", "currHeight", height, "initHeight", lastBlock.Height,
"currSeq", mainSeq, "currMainBlockHash", hex.EncodeToString(block.MainHash)) "currSeq", mainSeq, "currMainBlockHash", hex.EncodeToString(block.MainHash))
return mainSeq, block.MainHash, nil return mainSeq, block.MainHash, nil
...@@ -453,6 +458,7 @@ func (client *client) CreateBlock() { ...@@ -453,6 +458,7 @@ func (client *client) CreateBlock() {
plog.Info("Delete empty block") plog.Info("Delete empty block")
} }
err = client.delLocalBlock(lastBlock.Height) err = client.delLocalBlock(lastBlock.Height)
//client.DelBlock(lastBlock.Height,0)
} else if mainBlock.Seq.Type == addAct { } else if mainBlock.Seq.Type == addAct {
if len(txs) == 0 { if len(txs) == 0 {
if lastSeqMainHeight-lastBlock.MainHeight < emptyBlockInterval { if lastSeqMainHeight-lastBlock.MainHeight < emptyBlockInterval {
......
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