github.com/lzy4123/fabric@v2.1.1+incompatible/internal/peer/node/rollback.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package node 8 9 import ( 10 "github.com/hyperledger/fabric/core/ledger/kvledger" 11 "github.com/hyperledger/fabric/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. When the peer starts after the rollback, it will receive blocks, which got removed during the rollback, from an orderer or another peer to rebuild the block store and state database.`, 34 RunE: func(cmd *cobra.Command, args []string) error { 35 if channelID == common.UndefinedParamValue { 36 return errors.New("Must supply channel ID") 37 } 38 39 config := ledgerConfig() 40 return kvledger.RollbackKVLedger(config.RootFSPath, channelID, blockNumber) 41 }, 42 }