Commit 1ebeedb2 authored by yukang's avatar yukang Committed by vipwzw

correct code style

parent 83fa966c
...@@ -370,8 +370,6 @@ func (client *blockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc ...@@ -370,8 +370,6 @@ func (client *blockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc
//添加一个区块 //添加一个区块
func (client *blockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.ParaLocalDbBlock) error { func (client *blockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.ParaLocalDbBlock) error {
var newBlock types.Block var newBlock types.Block
client.printDebugInfo(fmt.Sprintf("Para sync - the len txs is: %v", len(localBlock.Txs)))
newBlock.ParentHash = lastBlock.Hash() newBlock.ParentHash = lastBlock.Hash()
newBlock.Height = lastBlock.Height + 1 newBlock.Height = lastBlock.Height + 1
newBlock.Txs = localBlock.Txs newBlock.Txs = localBlock.Txs
...@@ -388,7 +386,8 @@ func (client *blockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.P ...@@ -388,7 +386,8 @@ func (client *blockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.P
err = client.writeBlock(lastBlock.StateHash, &newBlock) err = client.writeBlock(lastBlock.StateHash, &newBlock)
client.printDebugInfo("Para sync - para create new Block", "newblock.ParentHash", common.ToHex(newBlock.ParentHash), client.printDebugInfo("Para sync - create new Block",
"newblock.ParentHash", common.ToHex(newBlock.ParentHash),
"newblock.Height", newBlock.Height, "newblock.TxHash", common.ToHex(newBlock.TxHash), "newblock.Height", newBlock.Height, "newblock.TxHash", common.ToHex(newBlock.TxHash),
"newblock.BlockTime", newBlock.BlockTime) "newblock.BlockTime", newBlock.BlockTime)
...@@ -397,34 +396,35 @@ func (client *blockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.P ...@@ -397,34 +396,35 @@ func (client *blockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.P
// 向blockchain删区块 // 向blockchain删区块
func (client *blockSyncClient) rollbackBlock(block *types.Block) error { func (client *blockSyncClient) rollbackBlock(block *types.Block) error {
client.printDebugInfo("Para sync - delete block in parachain")
start := block.Height start := block.Height
if start == 0 { if start <= 0 {
panic("Para sync - Parachain attempt to Delete GenesisBlock !") return errors.New("para sync - attempt to rollbackBlock genesisBlock")
} }
msg := client.paraClient.GetQueueClient().NewMessage("blockchain", types.EventGetBlocks, &types.ReqBlocks{Start: start, End: start, IsDetail: true, Pid: []string{""}}) reqBlocks := &types.ReqBlocks{Start: start, End: start, IsDetail: true, Pid: []string{""}}
msg := client.paraClient.GetQueueClient().NewMessage("blockchain", types.EventGetBlocks, reqBlocks)
err := client.paraClient.GetQueueClient().Send(msg, true) err := client.paraClient.GetQueueClient().Send(msg, true)
if err != nil { if err != nil {
return err return err
} }
resp, err := client.paraClient.GetQueueClient().Wait(msg) resp, err := client.paraClient.GetQueueClient().Wait(msg)
if err != nil { if err != nil {
return err return err
} }
blocks := resp.GetData().(*types.BlockDetails)
blocks := resp.GetData().(*types.BlockDetails)
if len(blocks.Items) == 0 { if len(blocks.Items) == 0 {
return errors.New("para sync -blocks Items len = 0 ") return errors.New("para sync -blocks Items len = 0 ")
} }
parablockDetail := &types.ParaChainBlockDetail{Blockdetail: blocks.Items[0]} paraBlockDetail := &types.ParaChainBlockDetail{Blockdetail: blocks.Items[0]}
msg = client.paraClient.GetQueueClient().NewMessage("blockchain", types.EventDelParaChainBlockDetail, parablockDetail) msg = client.paraClient.GetQueueClient().NewMessage("blockchain", types.EventDelParaChainBlockDetail, paraBlockDetail)
err = client.paraClient.GetQueueClient().Send(msg, true) err = client.paraClient.GetQueueClient().Send(msg, true)
if err != nil { if err != nil {
return err return err
} }
resp, err = client.paraClient.GetQueueClient().Wait(msg) resp, err = client.paraClient.GetQueueClient().Wait(msg)
if err != nil { if err != nil {
return err return err
...@@ -442,23 +442,24 @@ func (client *blockSyncClient) rollbackBlock(block *types.Block) error { ...@@ -442,23 +442,24 @@ func (client *blockSyncClient) rollbackBlock(block *types.Block) error {
func (client *blockSyncClient) writeBlock(prev []byte, paraBlock *types.Block) error { func (client *blockSyncClient) writeBlock(prev []byte, paraBlock *types.Block) error {
//共识模块不执行block,统一由blockchain模块执行block并做去重的处理,返回执行后的blockdetail //共识模块不执行block,统一由blockchain模块执行block并做去重的处理,返回执行后的blockdetail
blockDetail := &types.BlockDetail{Block: paraBlock} blockDetail := &types.BlockDetail{Block: paraBlock}
paraBlockDetail := &types.ParaChainBlockDetail{Blockdetail: blockDetail}
parablockDetail := &types.ParaChainBlockDetail{Blockdetail: blockDetail} msg := client.paraClient.GetQueueClient().NewMessage("blockchain", types.EventAddParaChainBlockDetail, paraBlockDetail)
msg := client.paraClient.GetQueueClient().NewMessage("blockchain", types.EventAddParaChainBlockDetail, parablockDetail)
err := client.paraClient.GetQueueClient().Send(msg, true) err := client.paraClient.GetQueueClient().Send(msg, true)
if err != nil { if err != nil {
return err return err
} }
resp, err := client.paraClient.GetQueueClient().Wait(msg) resp, err := client.paraClient.GetQueueClient().Wait(msg)
if err != nil { if err != nil {
return err return err
} }
blkdetail := resp.GetData().(*types.BlockDetail)
if blkdetail == nil { respBlockDetail := resp.GetData().(*types.BlockDetail)
return errors.New("Para sync - block detail is nil") if respBlockDetail == nil {
return errors.New("para sync - block detail is nil")
} }
client.paraClient.SetCurrentBlock(blkdetail.Block) client.paraClient.SetCurrentBlock(respBlockDetail.Block)
return nil return nil
} }
......
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