• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版4cc5b5edfe14dff2fa19455779dcaedc503662f7 (tree)
时间2020-02-20 09:09:35
作者ipqhjjybj <250657661@qq.c...>
Commiteripqhjjybj

Log Message

re design reorganizeChain

更改概述

差异

--- a/protocol/block.go
+++ b/protocol/block.go
@@ -137,6 +137,41 @@ func (c *Chain) connectBlock(block *types.Block) (err error) {
137137 return nil
138138 }
139139
140+func (c *Chain) detachBlock(detachBlockHeader *types.BlockHeader, consensusResult *state.ConsensusResult, utxoView *state.UtxoViewpoint) (*types.Block, error) {
141+ detachHash := detachBlockHeader.Hash()
142+ block, err := c.store.GetBlock(&detachHash)
143+ if err != nil {
144+ return block, err
145+ }
146+
147+ detachBlock := types.MapBlock(block)
148+ if err := consensusResult.DetachBlock(block); err != nil {
149+ return block, err
150+ }
151+
152+ if err := c.store.GetTransactionsUtxo(utxoView, detachBlock.Transactions); err != nil {
153+ return block, err
154+ }
155+
156+ txStatus, err := c.GetTransactionStatus(&detachBlock.ID)
157+ if err != nil {
158+ return block, err
159+ }
160+
161+ if err := utxoView.DetachBlock(detachBlock, txStatus); err != nil {
162+ return block, err
163+ }
164+
165+ for _, p := range c.subProtocols {
166+ if err := p.DetachBlock(block); err != nil {
167+ return block, errors.Wrap(err, p.Name(), "sub protocol detach block")
168+ }
169+ }
170+
171+ log.WithFields(log.Fields{"module": logModule, "height": detachBlockHeader.Height, "hash": detachHash.String()}).Debug("detach from mainchain")
172+ return block, nil
173+}
174+
140175 func (c *Chain) reorganizeChain(blockHeader *types.BlockHeader) error {
141176 attachBlockHeaders, detachBlockHeaders, err := c.calcReorganizeChain(blockHeader, c.bestBlockHeader)
142177 if err != nil {
@@ -158,42 +193,14 @@ func (c *Chain) reorganizeChain(blockHeader *types.BlockHeader) error {
158193
159194 txsToRestore := map[bc.Hash]*types.Tx{}
160195 for _, detachBlockHeader := range detachBlockHeaders {
161- detachHash := detachBlockHeader.Hash()
162- b, err := c.store.GetBlock(&detachHash)
196+ b, err := c.detachBlock(detachBlockHeader, consensusResult, utxoView)
163197 if err != nil {
164198 return err
165199 }
166200
167- detachBlock := types.MapBlock(b)
168- if err := c.store.GetTransactionsUtxo(utxoView, detachBlock.Transactions); err != nil {
169- return err
170- }
171-
172- txStatus, err := c.GetTransactionStatus(&detachBlock.ID)
173- if err != nil {
174- return err
175- }
176-
177- if err := utxoView.DetachBlock(detachBlock, txStatus); err != nil {
178- return err
179- }
180-
181- if err := consensusResult.DetachBlock(b); err != nil {
182- return err
183- }
184-
185- for _, p := range c.subProtocols {
186- if err := p.DetachBlock(b); err != nil {
187- return errors.Wrap(err, p.Name(), "sub protocol detach block")
188- }
189- }
190-
191201 for _, tx := range b.Transactions {
192202 txsToRestore[tx.ID] = tx
193203 }
194-
195- blockHash := blockHeader.Hash()
196- log.WithFields(log.Fields{"module": logModule, "height": blockHeader.Height, "hash": blockHash.String()}).Debug("detach from mainchain")
197204 }
198205
199206 txsToRemove := map[bc.Hash]*types.Tx{}
Show on old repository browser