- log.WithFields(log.Fields{"module": logModule, "height": node.Height, "hash": node.Hash.String()}).Debug("attach from mainchain")
+ for _, tx := range b.Transactions {
+ if _, ok := txsToRestore[tx.ID]; !ok {
+ txsToRemove[tx.ID] = tx
+ } else {
+ delete(txsToRestore, tx.ID)
+ }
+ }
+
+ blockHash := blockHeader.Hash()
+ log.WithFields(log.Fields{"module": logModule, "height": blockHeader.Height, "hash": blockHash.String()}).Debug("attach from mainchain")
+ }
+
+ if len(detachBlockHeaders) > 0 &&
+ detachBlockHeaders[len(detachBlockHeaders)-1].Height <= c.lastIrrBlockHeader.Height &&
+ irrBlockHeader.Height <= c.lastIrrBlockHeader.Height {
+ return errors.New("rollback block below the height of irreversible block")
+ }
+
+ consensusResults = append(consensusResults, consensusResult.Fork())
+ if err := c.setState(blockHeader, irrBlockHeader, attachBlockHeaders, utxoView, consensusResults); err != nil {
+ return err
+ }
+
+ for txHash := range txsToRemove {
+ c.txPool.RemoveTransaction(&txHash)