github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/internal/peer/node/rollback.go (about)

     1  /*
     2  Copyright hechain. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package node
     8  
     9  import (
    10  	"github.com/hechain20/hechain/core/ledger/kvledger"
    11  	"github.com/hechain20/hechain/internal/peer/common"
    12  	"github.com/pkg/errors"
    13  	"github.com/spf13/cobra"
    14  )
    15  
    16  var (
    17  	channelID   string
    18  	blockNumber uint64
    19  )
    20  
    21  func rollbackCmd() *cobra.Command {
    22  	nodeRollbackCmd.ResetFlags()
    23  	flags := nodeRollbackCmd.Flags()
    24  	flags.StringVarP(&channelID, "channelID", "c", common.UndefinedParamValue, "Channel to rollback.")
    25  	flags.Uint64VarP(&blockNumber, "blockNumber", "b", 0, "Block number to which the channel needs to be rolled back to.")
    26  
    27  	return nodeRollbackCmd
    28  }
    29  
    30  var nodeRollbackCmd = &cobra.Command{
    31  	Use:   "rollback",
    32  	Short: "Rolls back a channel.",
    33  	Long: "Rolls back a channel to a specified block number. When the command is executed, the peer must be offline." +
    34  		" When the peer starts after the rollback, it will receive blocks, which got removed during the rollback," +
    35  		" from an orderer or another peer to rebuild the block store and state database." +
    36  		" The command is not supported if the peer contains any channel that was bootstrapped from a snapshot.",
    37  	RunE: func(cmd *cobra.Command, args []string) error {
    38  		if channelID == common.UndefinedParamValue {
    39  			return errors.New("Must supply channel ID")
    40  		}
    41  
    42  		config := ledgerConfig()
    43  		return kvledger.RollbackKVLedger(config.RootFSPath, channelID, blockNumber)
    44  	},
    45  }