From 0c344498dece7ba289c602d3c8e6419a58f6c214 Mon Sep 17 00:00:00 2001 From: Fedor Partanskiy Date: Tue, 17 Sep 2024 18:53:12 +0300 Subject: [PATCH] fabric batch operations Signed-off-by: Fedor Partanskiy --- .github/workflows/verify-build.yml | 2 +- core/chaincode/chaincode_support.go | 4 + core/chaincode/config.go | 34 +- core/chaincode/handler.go | 236 +++++-- core/chaincode/handler_test.go | 16 +- go.mod | 5 + go.sum | 8 +- integration/chaincode/onlyput/chaincode.go | 56 ++ integration/chaincode/onlyput/cmd/main.go | 23 + integration/e2e/bench_put_state_test.go | 144 ++++ integration/nwo/network.go | 2 + integration/nwo/template/core_template.go | 3 + integration/pvtdatapurge/data_purge_test.go | 2 +- internal/peer/node/start.go | 2 + orderer/consensus/smartbft/chain_test.go | 4 + .../consensus/smartbft/util_network_test.go | 6 + sampleconfig/core.yaml | 8 + .../SmartBFT/internal/bft/controller.go | 4 + .../fabric-chaincode-go/v2/shim/handler.go | 166 +++++ .../common/collection.pb.go | 2 +- .../common/common.pb.go | 2 +- .../common/configtx.pb.go | 2 +- .../common/configuration.pb.go | 2 +- .../common/ledger.pb.go | 2 +- .../common/policies.pb.go | 2 +- .../discovery/protocol.pb.go | 2 +- .../gateway/gateway.pb.go | 2 +- .../gossip/message.pb.go | 2 +- .../ledger/queryresult/kv_query_result.pb.go | 2 +- .../ledger/rwset/kvrwset/kv_rwset.pb.go | 2 +- .../ledger/rwset/rwset.pb.go | 2 +- .../msp/identities.pb.go | 2 +- .../msp/msp_config.pb.go | 2 +- .../msp/msp_principal.pb.go | 2 +- .../fabric-protos-go-apiv2/orderer/ab.pb.go | 2 +- .../orderer/blockattestation.pb.go | 2 +- .../orderer/cluster.pb.go | 2 +- .../orderer/clusterserver.pb.go | 2 +- .../orderer/configuration.pb.go | 2 +- .../orderer/etcdraft/configuration.pb.go | 2 +- .../orderer/etcdraft/metadata.pb.go | 2 +- .../orderer/smartbft/configuration.pb.go | 2 +- .../peer/chaincode.pb.go | 117 +++- .../peer/chaincode_event.pb.go | 2 +- .../peer/chaincode_shim.pb.go | 628 ++++++++++++------ .../peer/collection.pb.go | 2 +- .../peer/configuration.pb.go | 2 +- .../fabric-protos-go-apiv2/peer/events.pb.go | 2 +- .../peer/lifecycle/chaincode_definition.pb.go | 2 +- .../peer/lifecycle/db.pb.go | 2 +- .../peer/lifecycle/lifecycle.pb.go | 2 +- .../fabric-protos-go-apiv2/peer/peer.pb.go | 2 +- .../fabric-protos-go-apiv2/peer/policy.pb.go | 2 +- .../peer/proposal.pb.go | 2 +- .../peer/proposal_response.pb.go | 2 +- .../fabric-protos-go-apiv2/peer/query.pb.go | 2 +- .../peer/resources.pb.go | 2 +- .../peer/signed_cc_dep_spec.pb.go | 2 +- .../peer/snapshot.pb.go | 2 +- .../peer/transaction.pb.go | 2 +- .../transientstore/transientstore.pb.go | 2 +- .../github.com/onsi/gomega/gmeasure/cache.go | 202 ++++++ .../onsi/gomega/gmeasure/enum_support.go | 43 ++ .../onsi/gomega/gmeasure/experiment.go | 527 +++++++++++++++ .../onsi/gomega/gmeasure/measurement.go | 235 +++++++ .../github.com/onsi/gomega/gmeasure/rank.go | 141 ++++ .../github.com/onsi/gomega/gmeasure/stats.go | 153 +++++ .../onsi/gomega/gmeasure/stopwatch.go | 117 ++++ .../onsi/gomega/gmeasure/table/table.go | 370 +++++++++++ vendor/modules.txt | 8 +- 70 files changed, 3004 insertions(+), 342 deletions(-) create mode 100644 integration/chaincode/onlyput/chaincode.go create mode 100644 integration/chaincode/onlyput/cmd/main.go create mode 100644 integration/e2e/bench_put_state_test.go create mode 100644 vendor/github.com/onsi/gomega/gmeasure/cache.go create mode 100644 vendor/github.com/onsi/gomega/gmeasure/enum_support.go create mode 100644 vendor/github.com/onsi/gomega/gmeasure/experiment.go create mode 100644 vendor/github.com/onsi/gomega/gmeasure/measurement.go create mode 100644 vendor/github.com/onsi/gomega/gmeasure/rank.go create mode 100644 vendor/github.com/onsi/gomega/gmeasure/stats.go create mode 100644 vendor/github.com/onsi/gomega/gmeasure/stopwatch.go create mode 100644 vendor/github.com/onsi/gomega/gmeasure/table/table.go diff --git a/.github/workflows/verify-build.yml b/.github/workflows/verify-build.yml index e59648e07be..e97dc16ce9d 100644 --- a/.github/workflows/verify-build.yml +++ b/.github/workflows/verify-build.yml @@ -58,7 +58,7 @@ jobs: strategy: fail-fast: false matrix: - INTEGRATION_TEST_SUITE: ["raft","pvtdata","pvtdatapurge","ledger","lifecycle","e2e smartbft","discovery gossip devmode pluggable","gateway idemix pkcs11 configtx configtxlator","sbe nwo msp"] + INTEGRATION_TEST_SUITE: ["raft","pvtdata","pvtdatapurge e2e","ledger","lifecycle","smartbft","discovery gossip devmode pluggable","gateway idemix pkcs11 configtx configtxlator","sbe nwo msp"] runs-on: ${{ github.repository == 'hyperledger/fabric' && 'fabric-ubuntu-22.04' || 'ubuntu-22.04' }} steps: - uses: actions/checkout@v4 diff --git a/core/chaincode/chaincode_support.go b/core/chaincode/chaincode_support.go index 700a801ad65..ec5e5200c59 100644 --- a/core/chaincode/chaincode_support.go +++ b/core/chaincode/chaincode_support.go @@ -73,6 +73,8 @@ type ChaincodeSupport struct { Runtime Runtime TotalQueryLimit int UserRunsCC bool + UsePutStateBatch bool + MaxSizePutStateBatch uint32 } // Launch starts executing chaincode if it is not already running. This method @@ -126,6 +128,8 @@ func (cs *ChaincodeSupport) HandleChaincodeStream(stream ccintf.ChaincodeStream) AppConfig: cs.AppConfig, Metrics: cs.HandlerMetrics, TotalQueryLimit: cs.TotalQueryLimit, + UsePutStateBatch: cs.UsePutStateBatch, + MaxSizePutStateBatch: cs.MaxSizePutStateBatch, } return handler.ProcessStream(stream) diff --git a/core/chaincode/config.go b/core/chaincode/config.go index 4459ba41400..78e1a81d208 100644 --- a/core/chaincode/config.go +++ b/core/chaincode/config.go @@ -16,21 +16,24 @@ import ( ) const ( - defaultExecutionTimeout = 30 * time.Second - minimumStartupTimeout = 5 * time.Second + defaultExecutionTimeout = 30 * time.Second + minimumStartupTimeout = 5 * time.Second + defaultMaxSizePutStateBatch = 1000 ) type Config struct { - TotalQueryLimit int - TLSEnabled bool - Keepalive time.Duration - ExecuteTimeout time.Duration - InstallTimeout time.Duration - StartupTimeout time.Duration - LogFormat string - LogLevel string - ShimLogLevel string - SCCAllowlist map[string]bool + TotalQueryLimit int + TLSEnabled bool + Keepalive time.Duration + ExecuteTimeout time.Duration + InstallTimeout time.Duration + StartupTimeout time.Duration + LogFormat string + LogLevel string + ShimLogLevel string + SCCAllowlist map[string]bool + UsePutStateBatch bool + MaxSizePutStateBatch uint32 } func GlobalConfig() *Config { @@ -71,6 +74,13 @@ func (c *Config) load() { if viper.IsSet("ledger.state.totalQueryLimit") { c.TotalQueryLimit = viper.GetInt("ledger.state.totalQueryLimit") } + if viper.IsSet("chaincode.additionalParams.usePutStateBatch") { + c.UsePutStateBatch = viper.GetBool("chaincode.additionalParams.usePutStateBatch") + } + c.MaxSizePutStateBatch = viper.GetUint32("ledger.state.maxSizePutStateBatch") + if c.MaxSizePutStateBatch <= 0 { + c.MaxSizePutStateBatch = defaultMaxSizePutStateBatch + } } func parseBool(s string) bool { diff --git a/core/chaincode/handler.go b/core/chaincode/handler.go index 1152cbf77d0..42f666fe3ed 100644 --- a/core/chaincode/handler.go +++ b/core/chaincode/handler.go @@ -130,6 +130,10 @@ type Handler struct { AppConfig ApplicationConfigRetriever // Metrics holds chaincode handler metrics Metrics *HandlerMetrics + // UsePutStateBatch an indication that the peer can accept changes from chaincode in batches + UsePutStateBatch bool + // MaxSizePutStateBatch maximum batch size for the change segment + MaxSizePutStateBatch uint32 // stateLock is used to read and set State. stateLock sync.RWMutex @@ -215,6 +219,8 @@ func (h *Handler) handleMessageReadyState(msg *pb.ChaincodeMessage) error { go h.HandleTransaction(msg, h.HandlePutStateMetadata) case pb.ChaincodeMessage_PURGE_PRIVATE_DATA: go h.HandleTransaction(msg, h.HandlePurgePrivateData) + case pb.ChaincodeMessage_CHANGE_STATE_BATCH: + go h.HandleTransaction(msg, h.HandleChangeStateBatch) default: return fmt.Errorf("[%s] Fabric side handler cannot handle message (%s) while in ready state", msg.Txid, msg.Type) } @@ -441,10 +447,22 @@ func (h *Handler) ProcessStream(stream ccintf.ChaincodeStream) error { // sendReady sends READY to chaincode serially (just like REGISTER) func (h *Handler) sendReady() error { chaincodeLogger.Debugf("sending READY for chaincode %s", h.chaincodeID) - ccMsg := &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_READY} + + chaincodeAdditionalParams := &pb.ChaincodeAdditionalParams{ + UsePutStateBatch: h.UsePutStateBatch, + MaxSizePutStateBatch: h.MaxSizePutStateBatch, + } + payloadBytes, err := proto.Marshal(chaincodeAdditionalParams) + if err != nil { + return errors.WithStack(err) + } + ccMsg := &pb.ChaincodeMessage{ + Type: pb.ChaincodeMessage_READY, + Payload: payloadBytes, + } // if error in sending tear down the h - if err := h.serialSend(ccMsg); err != nil { + if err = h.serialSend(ccMsg); err != nil { chaincodeLogger.Errorf("error sending READY (%s) for chaincode %s", err, h.chaincodeID) return err } @@ -504,7 +522,7 @@ func (h *Handler) HandleRegister(msg *pb.ChaincodeMessage) { } chaincodeLogger.Debugf("Got %s for chaincodeID = %s, sending back %s", pb.ChaincodeMessage_REGISTER, h.chaincodeID, pb.ChaincodeMessage_REGISTERED) - if err := h.serialSend(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}); err != nil { + if err = h.serialSend(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}); err != nil { chaincodeLogger.Errorf("error sending %s: %s", pb.ChaincodeMessage_REGISTERED, err) h.notifyRegistry(err) return @@ -555,10 +573,10 @@ func (h *Handler) registerTxid(msg *pb.ChaincodeMessage) bool { return false } -func (h *Handler) checkMetadataCap(msg *pb.ChaincodeMessage) error { - ac, exists := h.AppConfig.GetApplicationConfig(msg.ChannelId) +func (h *Handler) checkMetadataCap(channelId string) error { + ac, exists := h.AppConfig.GetApplicationConfig(channelId) if !exists { - return errors.Errorf("application config does not exist for %s", msg.ChannelId) + return errors.Errorf("application config does not exist for %s", channelId) } if !ac.Capabilities().KeyLevelEndorsement() { @@ -567,10 +585,10 @@ func (h *Handler) checkMetadataCap(msg *pb.ChaincodeMessage) error { return nil } -func (h *Handler) checkPurgePrivateDataCap(msg *pb.ChaincodeMessage) error { - ac, exists := h.AppConfig.GetApplicationConfig(msg.ChannelId) +func (h *Handler) checkPurgePrivateDataCap(channelId string) error { + ac, exists := h.AppConfig.GetApplicationConfig(channelId) if !exists { - return errors.Errorf("application config does not exist for %s", msg.ChannelId) + return errors.Errorf("application config does not exist for %s", channelId) } if !ac.Capabilities().PurgePvtData() { @@ -642,7 +660,7 @@ func (h *Handler) HandleGetState(msg *pb.ChaincodeMessage, txContext *Transactio if txContext.IsInitTransaction { return nil, errors.New("private data APIs are not allowed in chaincode Init()") } - if err := errorIfCreatorHasNoReadPermission(namespaceID, collection, txContext); err != nil { + if err = errorIfCreatorHasNoReadPermission(namespaceID, collection, txContext); err != nil { return nil, err } res, err = txContext.TXSimulator.GetPrivateData(namespaceID, collection, getState.Key) @@ -687,7 +705,7 @@ func (h *Handler) HandleGetPrivateDataHash(msg *pb.ChaincodeMessage, txContext * // Handles query to ledger to get state metadata func (h *Handler) HandleGetStateMetadata(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) { - err := h.checkMetadataCap(msg) + err := h.checkMetadataCap(msg.ChannelId) if err != nil { return nil, err } @@ -707,7 +725,7 @@ func (h *Handler) HandleGetStateMetadata(msg *pb.ChaincodeMessage, txContext *Tr if txContext.IsInitTransaction { return nil, errors.New("private data APIs are not allowed in chaincode Init()") } - if err := errorIfCreatorHasNoReadPermission(namespaceID, collection, txContext); err != nil { + if err = errorIfCreatorHasNoReadPermission(namespaceID, collection, txContext); err != nil { return nil, err } metadata, err = txContext.TXSimulator.GetPrivateDataMetadata(namespaceID, collection, getStateMetadata.Key) @@ -754,7 +772,7 @@ func (h *Handler) HandleGetStateByRange(msg *pb.ChaincodeMessage, txContext *Tra if txContext.IsInitTransaction { return nil, errors.New("private data APIs are not allowed in chaincode Init()") } - if err := errorIfCreatorHasNoReadPermission(namespaceID, collection, txContext); err != nil { + if err = errorIfCreatorHasNoReadPermission(namespaceID, collection, txContext); err != nil { return nil, err } rangeIter, err = txContext.TXSimulator.GetPrivateDataRangeScanIterator(namespaceID, collection, @@ -877,7 +895,7 @@ func (h *Handler) HandleGetQueryResult(msg *pb.ChaincodeMessage, txContext *Tran if txContext.IsInitTransaction { return nil, errors.New("private data APIs are not allowed in chaincode Init()") } - if err := errorIfCreatorHasNoReadPermission(namespaceID, collection, txContext); err != nil { + if err = errorIfCreatorHasNoReadPermission(namespaceID, collection, txContext); err != nil { return nil, err } executeIter, err = txContext.TXSimulator.ExecuteQueryOnPrivateData(namespaceID, collection, getQueryResult.Query) @@ -1033,123 +1051,215 @@ func (h *Handler) getTxContextForInvoke(channelID string, txid string, payload [ func (h *Handler) HandlePutState(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) { putState := &pb.PutState{} - err := proto.Unmarshal(msg.Payload, putState) - if err != nil { + if err := proto.Unmarshal(msg.Payload, putState); err != nil { return nil, errors.Wrap(err, "unmarshal failed") } + if err := h.putState(putState, txContext); err != nil { + return nil, errors.WithStack(err) + } + + return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil +} + +func (h *Handler) putState(msg *pb.PutState, txContext *TransactionContext) error { + var err error + namespaceID := txContext.NamespaceID - collection := putState.Collection + collection := msg.Collection if isCollectionSet(collection) { if txContext.IsInitTransaction { - return nil, errors.New("private data APIs are not allowed in chaincode Init()") + return errors.New("private data APIs are not allowed in chaincode Init()") } - if err := errorIfCreatorHasNoWritePermission(namespaceID, collection, txContext); err != nil { - return nil, err + if err = errorIfCreatorHasNoWritePermission(namespaceID, collection, txContext); err != nil { + return err } - err = txContext.TXSimulator.SetPrivateData(namespaceID, collection, putState.Key, putState.Value) + err = txContext.TXSimulator.SetPrivateData(namespaceID, collection, msg.Key, msg.Value) } else { - err = txContext.TXSimulator.SetState(namespaceID, putState.Key, putState.Value) + err = txContext.TXSimulator.SetState(namespaceID, msg.Key, msg.Value) } if err != nil { - return nil, errors.WithStack(err) + return errors.WithStack(err) } - return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil + return nil } func (h *Handler) HandlePutStateMetadata(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) { - err := h.checkMetadataCap(msg) - if err != nil { - return nil, err + putStateMetadata := &pb.PutStateMetadata{} + if err := proto.Unmarshal(msg.Payload, putStateMetadata); err != nil { + return nil, errors.Wrap(err, "unmarshal failed") } - putStateMetadata := &pb.PutStateMetadata{} - err = proto.Unmarshal(msg.Payload, putStateMetadata) + if err := h.putStateMetadata(putStateMetadata, txContext, msg.ChannelId); err != nil { + return nil, errors.WithStack(err) + } + + return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil +} + +func (h *Handler) putStateMetadata(msg *pb.PutStateMetadata, txContext *TransactionContext, channelId string) error { + err := h.checkMetadataCap(channelId) if err != nil { - return nil, errors.Wrap(err, "unmarshal failed") + return err } metadata := make(map[string][]byte) - metadata[putStateMetadata.Metadata.Metakey] = putStateMetadata.Metadata.Value + metadata[msg.Metadata.Metakey] = msg.Metadata.Value namespaceID := txContext.NamespaceID - collection := putStateMetadata.Collection + collection := msg.Collection if isCollectionSet(collection) { if txContext.IsInitTransaction { - return nil, errors.New("private data APIs are not allowed in chaincode Init()") + return errors.New("private data APIs are not allowed in chaincode Init()") } - if err := errorIfCreatorHasNoWritePermission(namespaceID, collection, txContext); err != nil { - return nil, err + if err = errorIfCreatorHasNoWritePermission(namespaceID, collection, txContext); err != nil { + return err } - err = txContext.TXSimulator.SetPrivateDataMetadata(namespaceID, collection, putStateMetadata.Key, metadata) + err = txContext.TXSimulator.SetPrivateDataMetadata(namespaceID, collection, msg.Key, metadata) } else { - err = txContext.TXSimulator.SetStateMetadata(namespaceID, putStateMetadata.Key, metadata) + err = txContext.TXSimulator.SetStateMetadata(namespaceID, msg.Key, metadata) } if err != nil { - return nil, errors.WithStack(err) + return errors.WithStack(err) } - return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil + return nil } func (h *Handler) HandleDelState(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) { delState := &pb.DelState{} - err := proto.Unmarshal(msg.Payload, delState) - if err != nil { + if err := proto.Unmarshal(msg.Payload, delState); err != nil { return nil, errors.Wrap(err, "unmarshal failed") } + if err := h.delState(delState, txContext); err != nil { + return nil, errors.WithStack(err) + } + + // Send response msg back to chaincode. + return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil +} + +func (h *Handler) delState(msg *pb.DelState, txContext *TransactionContext) error { + var err error + namespaceID := txContext.NamespaceID - collection := delState.Collection + collection := msg.Collection if isCollectionSet(collection) { if txContext.IsInitTransaction { - return nil, errors.New("private data APIs are not allowed in chaincode Init()") + return errors.New("private data APIs are not allowed in chaincode Init()") } - if err := errorIfCreatorHasNoWritePermission(namespaceID, collection, txContext); err != nil { - return nil, err + if err = errorIfCreatorHasNoWritePermission(namespaceID, collection, txContext); err != nil { + return err } - err = txContext.TXSimulator.DeletePrivateData(namespaceID, collection, delState.Key) + err = txContext.TXSimulator.DeletePrivateData(namespaceID, collection, msg.Key) } else { - err = txContext.TXSimulator.DeleteState(namespaceID, delState.Key) + err = txContext.TXSimulator.DeleteState(namespaceID, msg.Key) } if err != nil { - return nil, errors.WithStack(err) + return errors.WithStack(err) } - // Send response msg back to chaincode. - return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil + return nil } func (h *Handler) HandlePurgePrivateData(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) { - err := h.checkPurgePrivateDataCap(msg) - if err != nil { - return nil, err - } delState := &pb.DelState{} if err := proto.Unmarshal(msg.Payload, delState); err != nil { return nil, errors.Wrap(err, "unmarshal failed") } + if err := h.purgePrivateData(delState, txContext, msg.ChannelId); err != nil { + return nil, errors.WithStack(err) + } + + // Send response msg back to chaincode. + return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil +} + +func (h *Handler) purgePrivateData(msg *pb.DelState, txContext *TransactionContext, channelId string) error { + err := h.checkPurgePrivateDataCap(channelId) + if err != nil { + return err + } + namespaceID := txContext.NamespaceID - collection := delState.Collection + collection := msg.Collection if collection == "" { - return nil, errors.New("only applicable for private data") + return errors.New("only applicable for private data") } if txContext.IsInitTransaction { - return nil, errors.New("private data APIs are not allowed in chaincode Init()") + return errors.New("private data APIs are not allowed in chaincode Init()") } - if err := errorIfCreatorHasNoWritePermission(namespaceID, collection, txContext); err != nil { - return nil, err + if err = errorIfCreatorHasNoWritePermission(namespaceID, collection, txContext); err != nil { + return err } - if err := txContext.TXSimulator.PurgePrivateData(namespaceID, collection, delState.Key); err != nil { - return nil, errors.WithStack(err) + if err = txContext.TXSimulator.PurgePrivateData(namespaceID, collection, msg.Key); err != nil { + return errors.WithStack(err) + } + + return nil +} + +func (h *Handler) HandleChangeStateBatch(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) { + batch := &pb.ChangeStateBatch{} + err := proto.Unmarshal(msg.Payload, batch) + if err != nil { + return nil, errors.Wrap(err, "unmarshal failed") + } + + for _, kv := range batch.GetKvs() { + switch kv.GetType() { + case pb.StateKV_PUT_STATE: + putState := &pb.PutState{ + Key: kv.GetKey(), + Value: kv.GetValue(), + Collection: kv.GetCollection(), + } + if err = h.putState(putState, txContext); err != nil { + return nil, errors.WithStack(err) + } + + case pb.StateKV_DEL_STATE: + delState := &pb.DelState{ + Key: kv.GetKey(), + Collection: kv.GetCollection(), + } + if err = h.delState(delState, txContext); err != nil { + return nil, errors.WithStack(err) + } + + case pb.StateKV_PURGE_PRIVATE_DATA: + delState := &pb.DelState{ + Key: kv.GetKey(), + Collection: kv.GetCollection(), + } + if err = h.purgePrivateData(delState, txContext, msg.ChannelId); err != nil { + return nil, err + } + + case pb.StateKV_PUT_STATE_METADATA: + putStateMetadata := &pb.PutStateMetadata{ + Key: kv.GetKey(), + Collection: kv.GetCollection(), + Metadata: &pb.StateMetadata{ + Metakey: kv.GetMetadata().GetMetakey(), + Value: kv.GetMetadata().GetValue(), + }, + } + if err = h.putStateMetadata(putStateMetadata, txContext, msg.ChannelId); err != nil { + return nil, err + } + + default: + return nil, errors.New("unknown operation type") + } } - // Send response msg back to chaincode. return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil } @@ -1252,7 +1362,7 @@ func (h *Handler) Execute(txParams *ccprovider.TransactionParams, namespace stri } defer h.TXContexts.Delete(msg.ChannelId, msg.Txid) - if err := h.setChaincodeProposal(txParams.SignedProp, txParams.Proposal, msg); err != nil { + if err = h.setChaincodeProposal(txParams.SignedProp, txParams.Proposal, msg); err != nil { return nil, err } diff --git a/core/chaincode/handler_test.go b/core/chaincode/handler_test.go index 5aed680678e..155e95040d0 100644 --- a/core/chaincode/handler_test.go +++ b/core/chaincode/handler_test.go @@ -123,8 +123,10 @@ var _ = Describe("Handler", func() { UUIDGenerator: chaincode.UUIDGeneratorFunc(func() string { return "generated-query-id" }), - AppConfig: fakeApplicationConfigRetriever, - Metrics: chaincodeMetrics, + AppConfig: fakeApplicationConfigRetriever, + Metrics: chaincodeMetrics, + UsePutStateBatch: true, + MaxSizePutStateBatch: 1000, } chaincode.SetHandlerChatStream(handler, fakeChatStream) chaincode.SetHandlerChaincodeID(handler, "test-handler-name:1.0") @@ -2783,8 +2785,16 @@ var _ = Describe("Handler", func() { Type: pb.ChaincodeMessage_REGISTERED, })) + chaincodeAdditionalParams := &pb.ChaincodeAdditionalParams{ + UsePutStateBatch: true, + MaxSizePutStateBatch: 1000, + } + payloadBytes, err := proto.Marshal(chaincodeAdditionalParams) + Expect(err).NotTo(HaveOccurred()) + Expect(readyMessage).To(ProtoEqual(&pb.ChaincodeMessage{ - Type: pb.ChaincodeMessage_READY, + Type: pb.ChaincodeMessage_READY, + Payload: payloadBytes, })) }) diff --git a/go.mod b/go.mod index f1ad637ac89..b04bc9a70f7 100644 --- a/go.mod +++ b/go.mod @@ -119,3 +119,8 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) + +replace ( + github.com/hyperledger/fabric-chaincode-go/v2 => github.com/scientificideas/fabric-chaincode-go/v2 v2.0.0-20240917062040-734ea7e39c20 + github.com/hyperledger/fabric-protos-go-apiv2 => github.com/scientificideas/fabric-protos-go-apiv2 v0.0.0-20240917052027-e43d30d02e8c +) diff --git a/go.sum b/go.sum index 486803e3c04..c5d62d013af 100644 --- a/go.sum +++ b/go.sum @@ -968,14 +968,10 @@ github.com/hyperledger/aries-bbs-go v0.0.0-20240528084656-761671ea73bc h1:3Ykk6M github.com/hyperledger/aries-bbs-go v0.0.0-20240528084656-761671ea73bc/go.mod h1:Kofn6A6WWea1ZM8Rys5aBW9dszwJ7Ywa0kyyYL0TPYw= github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 h1:B1Nt8hKb//KvgGRprk0h1t4lCnwhE9/ryb1WqfZbV+M= github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2/go.mod h1:X+DIyUsaTmalOpmpQfIvFZjKHQedrURQ5t4YqquX7lE= -github.com/hyperledger/fabric-chaincode-go/v2 v2.0.0 h1:IhkHfrl5X/fVnmB6pWeCYCdIJRi9bxj+WTnVN8DtW3c= -github.com/hyperledger/fabric-chaincode-go/v2 v2.0.0/go.mod h1:PHHaFffjw7p7n9bmCfcm7RqDqYdivNEsJdiNIKZo5Lk= github.com/hyperledger/fabric-config v0.3.0 h1:FS5/dc9GAniljP6RYxQRG92AaiBVoN2vTvtOvnWqeQs= github.com/hyperledger/fabric-config v0.3.0/go.mod h1:kSevTn78K83Suc++JsEo7Nt1tYIPqDajW+ORz3OhWlg= github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5 h1:RPWTL5wxAb+xDOrsCU3QYZP65305F8v3PaOyzdbPVMU= github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5/go.mod h1:SHNCq8AB0VpHAmvJEtdbzabv6NNV1F48JdmDihasBjc= -github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3 h1:Xpd6fzG/KjAOHJsq7EQXY2l+qi/y8muxBaY7R6QWABk= -github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3/go.mod h1:2pq0ui6ZWA0cC8J+eCErgnMDCS1kPOEYVY+06ZAK0qE= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -1217,6 +1213,10 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb github.com/sagikazarmark/locafero v0.6.0 h1:ON7AQg37yzcRPU69mt7gwhFEBwxI6P9T4Qu3N51bwOk= github.com/sagikazarmark/locafero v0.6.0/go.mod h1:77OmuIc6VTraTXKXIs/uvUxKGUXjE1GbemJYHqdNjX0= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= +github.com/scientificideas/fabric-chaincode-go/v2 v2.0.0-20240917062040-734ea7e39c20 h1:/BlcEC/uR0/kgLZ2d4PxKHp8yrmxYh6AQAci00Rjjtw= +github.com/scientificideas/fabric-chaincode-go/v2 v2.0.0-20240917062040-734ea7e39c20/go.mod h1:TbldEYooqtR1AVWsdF6K4h123JAUNUEhD8VvHlASCk0= +github.com/scientificideas/fabric-protos-go-apiv2 v0.0.0-20240917052027-e43d30d02e8c h1:nPuFGreSUglrB87k4zVXr8lVN/A0uYy37qRorJmTO8A= +github.com/scientificideas/fabric-protos-go-apiv2 v0.0.0-20240917052027-e43d30d02e8c/go.mod h1:1x9TFdg5b2M9vema7s4EdQZ1qUV4peAtF2jQj8FjLjc= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= diff --git a/integration/chaincode/onlyput/chaincode.go b/integration/chaincode/onlyput/chaincode.go new file mode 100644 index 00000000000..f86b3c509b8 --- /dev/null +++ b/integration/chaincode/onlyput/chaincode.go @@ -0,0 +1,56 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package onlyput + +import ( + "fmt" + "strconv" + + "github.com/hyperledger/fabric-chaincode-go/v2/shim" + pb "github.com/hyperledger/fabric-protos-go-apiv2/peer" +) + +type OnlyPut struct{} + +// Init initializes chaincode +// =========================== +func (t *OnlyPut) Init(_ shim.ChaincodeStubInterface) *pb.Response { + return shim.Success(nil) +} + +// Invoke - Our entry point for Invocations +// ======================================== +func (t *OnlyPut) Invoke(stub shim.ChaincodeStubInterface) *pb.Response { + function, args := stub.GetFunctionAndParameters() + fmt.Println("invoke is running " + function) + + switch function { + case "invoke": + return t.put(stub, args) + default: + // error + fmt.Println("invoke did not find func: " + function) + return shim.Error("Received unknown function invocation") + } +} + +// both params should be marshalled json data and base64 encoded +func (t *OnlyPut) put(stub shim.ChaincodeStubInterface, args []string) *pb.Response { + if len(args) != 1 { + return shim.Error("Incorrect number of arguments. Expecting 1") + } + num, _ := strconv.Atoi(args[0]) + + for i := range num { + key := "key" + strconv.Itoa(i) + err := stub.PutState(key, []byte(key)) + if err != nil { + return shim.Error(err.Error()) + } + } + return shim.Success(nil) +} diff --git a/integration/chaincode/onlyput/cmd/main.go b/integration/chaincode/onlyput/cmd/main.go new file mode 100644 index 00000000000..6d410890687 --- /dev/null +++ b/integration/chaincode/onlyput/cmd/main.go @@ -0,0 +1,23 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package main + +import ( + "fmt" + "os" + + "github.com/hyperledger/fabric-chaincode-go/v2/shim" + "github.com/hyperledger/fabric/integration/chaincode/onlyput" +) + +func main() { + err := shim.Start(&onlyput.OnlyPut{}) + if err != nil { + fmt.Fprintf(os.Stderr, "Exiting SBE chaincode: %s", err) + os.Exit(2) + } +} diff --git a/integration/e2e/bench_put_state_test.go b/integration/e2e/bench_put_state_test.go new file mode 100644 index 00000000000..349854b1f1d --- /dev/null +++ b/integration/e2e/bench_put_state_test.go @@ -0,0 +1,144 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package e2e + +import ( + "fmt" + "os" + "path/filepath" + "syscall" + + docker "github.com/fsouza/go-dockerclient" + "github.com/hyperledger/fabric/integration/channelparticipation" + "github.com/hyperledger/fabric/integration/nwo" + "github.com/hyperledger/fabric/integration/nwo/commands" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/onsi/gomega/gbytes" + "github.com/onsi/gomega/gexec" + "github.com/onsi/gomega/gmeasure" + "github.com/tedsuo/ifrit" + ginkgomon "github.com/tedsuo/ifrit/ginkgomon_v2" +) + +var _ = Describe("Network", func() { + var ( + client *docker.Client + tempDir string + ) + + BeforeEach(func() { + var err error + tempDir, err = os.MkdirTemp("", "nwo") + Expect(err).NotTo(HaveOccurred()) + + client, err = docker.NewClientFromEnv() + Expect(err).NotTo(HaveOccurred()) + }) + + AfterEach(func() { + os.RemoveAll(tempDir) + }) + + DescribeTableSubtree("etcdraft network", func(desc string, usePutStateBatch bool) { + var network *nwo.Network + var ordererRunner *ginkgomon.Runner + var ordererProcess, peerProcess ifrit.Process + + BeforeEach(func() { + network = nwo.New(nwo.BasicEtcdRaft(), tempDir, client, StartPort(), components) + network.UsePutStateBatch = usePutStateBatch + + // Generate config and bootstrap the network + network.GenerateConfigTree() + network.Bootstrap() + + // Start all of the fabric processes + ordererRunner, ordererProcess, peerProcess = network.StartSingleOrdererNetwork("orderer") + }) + + AfterEach(func() { + if ordererProcess != nil { + ordererProcess.Signal(syscall.SIGTERM) + Eventually(ordererProcess.Wait(), network.EventuallyTimeout).Should(Receive()) + } + + if peerProcess != nil { + peerProcess.Signal(syscall.SIGTERM) + Eventually(peerProcess.Wait(), network.EventuallyTimeout).Should(Receive()) + } + + network.Cleanup() + }) + + It("deploys and executes chaincode (simple) using _lifecycle", func() { + orderer := network.Orderer("orderer") + channelparticipation.JoinOrdererJoinPeersAppChannel(network, "testchannel", orderer, ordererRunner) + peer := network.Peer("Org1", "peer0") + + chaincode := nwo.Chaincode{ + Name: "mycc", + Version: "0.0", + Path: "github.com/hyperledger/fabric/integration/chaincode/onlyput/cmd", + Lang: "golang", + PackageFile: filepath.Join(tempDir, "onlyput.tar.gz"), + Ctor: `{"Args":["init"]}`, + SignaturePolicy: `AND ('Org1MSP.member','Org2MSP.member')`, + Sequence: "1", + InitRequired: true, + Label: "my_onlyput_chaincode", + } + + network.VerifyMembership(network.PeersWithChannel("testchannel"), "testchannel") + + nwo.EnableCapabilities( + network, + "testchannel", + "Application", "V2_0", + orderer, + network.PeersWithChannel("testchannel")..., + ) + nwo.DeployChaincode(network, "testchannel", orderer, chaincode) + + By("run invoke where onli put state") + experiment := gmeasure.NewExperiment("Only PUT State " + desc) + AddReportEntry(experiment.Name, experiment) + + experiment.SampleDuration("invoke N-5 cycle-1", func(idx int) { + RunInvokeOnlyPutState(network, orderer, peer, "invoke", 1) + }, gmeasure.SamplingConfig{N: 5}) + + experiment.SampleDuration("invoke N-10 cycle-1000", func(idx int) { + RunInvokeOnlyPutState(network, orderer, peer, "invoke", 1000) + }, gmeasure.SamplingConfig{N: 10}) + + experiment.SampleDuration("invoke N-10 cycle-10000", func(idx int) { + RunInvokeOnlyPutState(network, orderer, peer, "invoke", 10000) + }, gmeasure.SamplingConfig{N: 10}) + }) + }, + Entry("without batch", "without batch", false), + Entry("with batch", "with batch", true), + ) +}) + +func RunInvokeOnlyPutState(n *nwo.Network, orderer *nwo.Orderer, peer *nwo.Peer, fn string, initial int) { + sess, err := n.PeerUserSession(peer, "User1", commands.ChaincodeInvoke{ + ChannelID: "testchannel", + Orderer: n.OrdererAddress(orderer, nwo.ListenPort), + Name: "mycc", + Ctor: `{"Args":["` + fn + `","` + fmt.Sprint(initial) + `"]}`, + PeerAddresses: []string{ + n.PeerAddress(n.Peer("Org1", "peer0"), nwo.ListenPort), + n.PeerAddress(n.Peer("Org2", "peer0"), nwo.ListenPort), + }, + WaitForEvent: true, + }) + Expect(err).NotTo(HaveOccurred()) + Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) + Expect(sess.Err).To(gbytes.Say("Chaincode invoke successful. result: status:200")) +} diff --git a/integration/nwo/network.go b/integration/nwo/network.go index cc0d888b07d..5b29d744582 100644 --- a/integration/nwo/network.go +++ b/integration/nwo/network.go @@ -160,6 +160,7 @@ type Network struct { GatewayEnabled bool OrdererReplicationPolicy string PeerDeliveryClientPolicy string + UsePutStateBatch bool PortsByOrdererID map[string]Ports PortsByPeerID map[string]Ports @@ -192,6 +193,7 @@ func New(c *Config, rootDir string, dockerClient *docker.Client, startPort int, PortsByOrdererID: map[string]Ports{}, PortsByPeerID: map[string]Ports{}, PeerDeliveryClientPolicy: "", + UsePutStateBatch: true, Organizations: c.Organizations, Consensus: c.Consensus, diff --git a/integration/nwo/template/core_template.go b/integration/nwo/template/core_template.go index 1747c49e196..cf398e8008f 100644 --- a/integration/nwo/template/core_template.go +++ b/integration/nwo/template/core_template.go @@ -187,6 +187,9 @@ chaincode: cscc: enable lscc: enable qscc: enable + additionalParams: + usePutStateBatch: {{ .UsePutStateBatch }} + maxSizePutStateBatch: 1000 logging: level: info shim: warning diff --git a/integration/pvtdatapurge/data_purge_test.go b/integration/pvtdatapurge/data_purge_test.go index fb416c92d7c..bb6cd27e838 100644 --- a/integration/pvtdatapurge/data_purge_test.go +++ b/integration/pvtdatapurge/data_purge_test.go @@ -164,7 +164,7 @@ var _ = Describe("Pvtdata purge", func() { WaitForEvent: true, } - marblechaincodeutil.AssertInvokeChaincodeFails(network, org2Peer0, purgeCommand, "Failed to purge state:PURGE_PRIVATE_DATA failed: transaction ID: [a-f0-9]{64}: purge private data is not enabled, channel application capability of V2_5 or later is required") + marblechaincodeutil.AssertInvokeChaincodeFails(network, org2Peer0, purgeCommand, "failed: transaction ID: [a-f0-9]{64}: purge private data is not enabled, channel application capability of V2_5 or later is required") }) }) diff --git a/internal/peer/node/start.go b/internal/peer/node/start.go index 719801fae5c..388739af3b4 100644 --- a/internal/peer/node/start.go +++ b/internal/peer/node/start.go @@ -693,6 +693,8 @@ func serve(args []string) error { BuiltinSCCs: builtinSCCs, TotalQueryLimit: chaincodeConfig.TotalQueryLimit, UserRunsCC: userRunsCC, + UsePutStateBatch: chaincodeConfig.UsePutStateBatch, + MaxSizePutStateBatch: chaincodeConfig.MaxSizePutStateBatch, } custodianLauncher := custodianLauncherAdapter{ diff --git a/orderer/consensus/smartbft/chain_test.go b/orderer/consensus/smartbft/chain_test.go index 8470ab5dbb5..216df883588 100644 --- a/orderer/consensus/smartbft/chain_test.go +++ b/orderer/consensus/smartbft/chain_test.go @@ -12,6 +12,7 @@ import ( "testing" "time" + "github.com/hyperledger/fabric-lib-go/common/flogging" cb "github.com/hyperledger/fabric-protos-go-apiv2/common" "github.com/hyperledger/fabric-protos-go-apiv2/msp" "github.com/hyperledger/fabric/common/channelconfig" @@ -358,6 +359,9 @@ func TestAddAndRemoveNodeWithoutStop(t *testing.T) { dir := t.TempDir() channelId := "testchannel" + flogging.ActivateSpec("debug") + defer flogging.ActivateSpec("info") + // start a network networkSetupInfo := NewNetworkSetupInfo(t, channelId, dir) networkSetupInfo.configInfo.leaderHeartbeatTimeout = time.Minute diff --git a/orderer/consensus/smartbft/util_network_test.go b/orderer/consensus/smartbft/util_network_test.go index 58bb710e8cb..f2d93bb2c84 100644 --- a/orderer/consensus/smartbft/util_network_test.go +++ b/orderer/consensus/smartbft/util_network_test.go @@ -11,6 +11,7 @@ import ( "path" "path/filepath" "reflect" + "runtime" "slices" "sort" "sync" @@ -576,6 +577,11 @@ func createBFTChainUsingMocks(t *testing.T, node *Node, configInfo *ConfigInfo) synchronizerMock.EXPECT().Sync().RunAndReturn( func() types.SyncResponse { t.Logf("Sync Called by node %v", node.NodeId) + + buf := make([]byte, 1<<16) + l := runtime.Stack(buf, false) + t.Logf("PFI10: %s", buf[:l]) + // iterate over the ledger of the other nodes and find the highest ledger to sync with ledgerToCopy := findLargestDifferentLedger(node.nodesMap, node.NodeId) diff --git a/sampleconfig/core.yaml b/sampleconfig/core.yaml index 5a721554d26..14683ba2fa3 100644 --- a/sampleconfig/core.yaml +++ b/sampleconfig/core.yaml @@ -669,6 +669,14 @@ chaincode: # Format for the chaincode container logs format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}' + # AdditionalParams section for parameters that are passed to chaincode + # to specify additional operation modes in which the peer operates. + additionalParams: + # UsePutStateBatch an indication that the peer can accept changes from chaincode in batches + usePutStateBatch: true + # MaxSizePutStateBatch maximum batch size for the change segment + maxSizePutStateBatch: 1000 + ############################################################################### # # Ledger section - ledger configuration encompasses both the blockchain diff --git a/vendor/github.com/hyperledger-labs/SmartBFT/internal/bft/controller.go b/vendor/github.com/hyperledger-labs/SmartBFT/internal/bft/controller.go index 9ced3bb4ec0..ea0e956ea36 100644 --- a/vendor/github.com/hyperledger-labs/SmartBFT/internal/bft/controller.go +++ b/vendor/github.com/hyperledger-labs/SmartBFT/internal/bft/controller.go @@ -6,6 +6,7 @@ package bft import ( + "runtime" "sync" "sync/atomic" "time" @@ -450,6 +451,9 @@ func (c *Controller) Sync() { if iAmLeader, _ := c.iAmTheLeader(); iAmLeader { c.Batcher.Close() } + buf := make([]byte, 1<<16) + l := runtime.Stack(buf, false) + c.Logger.Infof("PFI11: %s", buf[:l]) c.grabSyncToken() } diff --git a/vendor/github.com/hyperledger/fabric-chaincode-go/v2/shim/handler.go b/vendor/github.com/hyperledger/fabric-chaincode-go/v2/shim/handler.go index a465ae2639f..e7f0e40fcfe 100644 --- a/vendor/github.com/hyperledger/fabric-chaincode-go/v2/shim/handler.go +++ b/vendor/github.com/hyperledger/fabric-chaincode-go/v2/shim/handler.go @@ -18,6 +18,10 @@ const ( created state = "created" // start state established state = "established" // connection established ready state = "ready" // ready for requests + + defaultMaxSizePutStateBatch = 100 + prefixMetaData = "m" + prefixStateData = "s" ) // PeerChaincodeStream is the common stream interface for Peer - chaincode communication. @@ -46,6 +50,11 @@ type Handler struct { cc Chaincode // state holds the current state of this handler. state state + // if you can send the changes in batches. + usePutStateBatch bool + maxSizePutStateBatch uint32 + stateDataMutex sync.RWMutex + stateData map[string]map[string]*peer.StateKV // Multiple queries (and one transaction) with different txids can be executing in parallel for this chaincode // responseChannels is the channel on which responses are communicated by the shim to the chaincodeStub. @@ -150,6 +159,7 @@ func newChaincodeHandler(peerChatStream PeerChaincodeStream, chaincode Chaincode cc: chaincode, responseChannels: map[string]chan *peer.ChaincodeMessage{}, state: created, + stateData: map[string]map[string]*peer.StateKV{}, } } @@ -188,6 +198,11 @@ func (h *Handler) handleInit(msg *peer.ChaincodeMessage) (*peer.ChaincodeMessage return nil, fmt.Errorf("failed to marshal response: %s", err) } + err = h.sendBatch(msg.ChannelId, msg.Txid) + if err != nil { + return nil, fmt.Errorf("failed send batch: %s", err) + } + return &peer.ChaincodeMessage{Type: peer.ChaincodeMessage_COMPLETED, Payload: resBytes, Txid: msg.Txid, ChaincodeEvent: stub.chaincodeEvent, ChannelId: stub.ChannelID}, nil } @@ -214,6 +229,11 @@ func (h *Handler) handleTransaction(msg *peer.ChaincodeMessage) (*peer.Chaincode return nil, fmt.Errorf("failed to marshal response: %s", err) } + err = h.sendBatch(msg.ChannelId, msg.Txid) + if err != nil { + return nil, fmt.Errorf("failed send batch: %s", err) + } + return &peer.ChaincodeMessage{Type: peer.ChaincodeMessage_COMPLETED, Payload: resBytes, Txid: msg.Txid, ChaincodeEvent: stub.chaincodeEvent, ChannelId: stub.ChannelID}, nil } @@ -312,6 +332,17 @@ func (h *Handler) handleGetStateMetadata(collection string, key string, channelI // handlePutState communicates with the peer to put state information into the ledger. func (h *Handler) handlePutState(collection string, key string, value []byte, channelID string, txid string) error { + if h.usePutStateBatch { + st := h.stateDataByID(channelID, txid) + st[prefixStateData+collection+key] = &peer.StateKV{ + Key: key, + Value: value, + Collection: collection, + Type: peer.StateKV_PUT_STATE, + } + return nil + } + // Construct payload for PUT_STATE payloadBytes := marshalOrPanic(&peer.PutState{Collection: collection, Key: key, Value: value}) @@ -340,6 +371,19 @@ func (h *Handler) handlePutState(collection string, key string, value []byte, ch func (h *Handler) handlePutStateMetadataEntry(collection string, key string, metakey string, metadata []byte, channelID string, txID string) error { // Construct payload for PUT_STATE_METADATA md := &peer.StateMetadata{Metakey: metakey, Value: metadata} + + if h.usePutStateBatch { + st := h.stateDataByID(channelID, txID) + st[prefixMetaData+collection+key] = &peer.StateKV{ + Key: key, + Collection: collection, + Metadata: md, + Type: peer.StateKV_PUT_STATE_METADATA, + } + + return nil + } + payloadBytes := marshalOrPanic(&peer.PutStateMetadata{Collection: collection, Key: key, Metadata: md}) msg := &peer.ChaincodeMessage{Type: peer.ChaincodeMessage_PUT_STATE_METADATA, Payload: payloadBytes, Txid: txID, ChannelId: channelID} @@ -365,6 +409,16 @@ func (h *Handler) handlePutStateMetadataEntry(collection string, key string, met // handleDelState communicates with the peer to delete a key from the state in the ledger. func (h *Handler) handleDelState(collection string, key string, channelID string, txid string) error { + if h.usePutStateBatch { + st := h.stateDataByID(channelID, txid) + st[prefixStateData+collection+key] = &peer.StateKV{ + Key: key, + Collection: collection, + Type: peer.StateKV_DEL_STATE, + } + return nil + } + payloadBytes := marshalOrPanic(&peer.DelState{Collection: collection, Key: key}) msg := &peer.ChaincodeMessage{Type: peer.ChaincodeMessage_DEL_STATE, Payload: payloadBytes, Txid: txid, ChannelId: channelID} // Execute the request and get response @@ -388,6 +442,16 @@ func (h *Handler) handleDelState(collection string, key string, channelID string // handlePurgeState communicates with the peer to purge a state from private data func (h *Handler) handlePurgeState(collection string, key string, channelID string, txid string) error { + if h.usePutStateBatch { + st := h.stateDataByID(channelID, txid) + st[prefixStateData+collection+key] = &peer.StateKV{ + Key: key, + Collection: collection, + Type: peer.StateKV_PURGE_PRIVATE_DATA, + } + return nil + } + payloadBytes := marshalOrPanic(&peer.DelState{Collection: collection, Key: key}) msg := &peer.ChaincodeMessage{Type: peer.ChaincodeMessage_PURGE_PRIVATE_DATA, Payload: payloadBytes, Txid: txid, ChannelId: channelID} // Execute the request and get response @@ -409,6 +473,69 @@ func (h *Handler) handlePurgeState(collection string, key string, channelID stri return fmt.Errorf("[%s] incorrect chaincode message %s received. Expecting %s or %s", shorttxid(responseMsg.Txid), responseMsg.Type, peer.ChaincodeMessage_RESPONSE, peer.ChaincodeMessage_ERROR) } +// handlePutStateBatch communicates with the peer to put state as batch all changes information into the ledger. +func (h *Handler) handlePutStateBatch(batch *peer.ChangeStateBatch, channelID string, txid string) error { + // Construct payload for PUT_STATE_BATCH + payloadBytes := marshalOrPanic(batch) + + msg := &peer.ChaincodeMessage{Type: peer.ChaincodeMessage_CHANGE_STATE_BATCH, Payload: payloadBytes, Txid: txid, ChannelId: channelID} + + // Execute the request and get response + responseMsg, err := h.callPeerWithChaincodeMsg(msg, channelID, txid) + if err != nil { + return fmt.Errorf("[%s] error sending %s: %s", msg.Txid, peer.ChaincodeMessage_CHANGE_STATE_BATCH, err) + } + + if responseMsg.Type == peer.ChaincodeMessage_RESPONSE { + // Success response + return nil + } + + if responseMsg.Type == peer.ChaincodeMessage_ERROR { + // Error response + return fmt.Errorf("%s", responseMsg.Payload[:]) + } + + // Incorrect chaincode message received + return fmt.Errorf("[%s] incorrect chaincode message %s received. Expecting %s or %s", shorttxid(responseMsg.Txid), responseMsg.Type, peer.ChaincodeMessage_RESPONSE, peer.ChaincodeMessage_ERROR) +} + +func (h *Handler) sendBatch(channelID string, txid string) error { + if !h.usePutStateBatch { + return nil + } + + st := h.stateDataByID(channelID, txid) + txCtxID := transactionContextID(channelID, txid) + + defer func() { + h.stateDataMutex.Lock() + delete(h.stateData, txCtxID) + h.stateDataMutex.Unlock() + }() + + batch := &peer.ChangeStateBatch{} + for _, kv := range st { + batch.Kvs = append(batch.Kvs, kv) + if len(batch.Kvs) >= int(h.maxSizePutStateBatch) { + err := h.handlePutStateBatch(batch, channelID, txid) + if err != nil { + return fmt.Errorf("failed send state batch: %s", err) + } + batch.Kvs = batch.Kvs[:0] + } + } + + if len(batch.Kvs) != 0 { + err := h.handlePutStateBatch(batch, channelID, txid) + if err != nil { + return fmt.Errorf("failed send state batch: %s", err) + } + } + + return nil +} + func (h *Handler) handleGetStateByRange(collection, startKey, endKey string, metadata []byte, channelID string, txid string) (*peer.QueryResponse, error) { // Send GET_STATE_BY_RANGE message to peer chaincode support @@ -655,6 +782,23 @@ func (h *Handler) handleEstablished(msg *peer.ChaincodeMessage) error { } h.state = ready + if len(msg.Payload) == 0 { + return nil + } + + ccAdditionalParams := &peer.ChaincodeAdditionalParams{} + err := proto.Unmarshal(msg.Payload, ccAdditionalParams) + if err != nil { + return nil + } + + h.usePutStateBatch = ccAdditionalParams.UsePutStateBatch + h.maxSizePutStateBatch = ccAdditionalParams.MaxSizePutStateBatch + + if h.usePutStateBatch && h.maxSizePutStateBatch < defaultMaxSizePutStateBatch { + h.maxSizePutStateBatch = defaultMaxSizePutStateBatch + } + return nil } @@ -697,6 +841,28 @@ func (h *Handler) handleMessage(msg *peer.ChaincodeMessage, errc chan error) err return nil } +func (h *Handler) stateDataByID(channelID string, txID string) map[string]*peer.StateKV { + txCtxID := transactionContextID(channelID, txID) + + h.stateDataMutex.RLock() + st, ok := h.stateData[txCtxID] + h.stateDataMutex.RUnlock() + if ok { + return st + } + + h.stateDataMutex.Lock() + defer h.stateDataMutex.Unlock() + st, ok = h.stateData[txCtxID] + if ok { + return st + } + + st = make(map[string]*peer.StateKV) + h.stateData[txCtxID] = st + return st +} + // marshalOrPanic attempts to marshal the provided protobbuf message but will panic // when marshaling fails instead of returning an error. func marshalOrPanic(msg proto.Message) []byte { diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/collection.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/collection.pb.go index 9fbca16a779..73e0f2a9993 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/collection.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/collection.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: common/collection.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/common.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/common.pb.go index 51d7d540d84..9cf7b419fb7 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/common.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/common.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: common/common.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/configtx.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/configtx.pb.go index b97727243ff..b4ad11d2151 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/configtx.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/configtx.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: common/configtx.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/configuration.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/configuration.pb.go index 927ebcf6fed..62d28549f93 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/configuration.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/configuration.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: common/configuration.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/ledger.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/ledger.pb.go index e486f78dfa9..5a0e64db346 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/ledger.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/ledger.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: common/ledger.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/policies.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/policies.pb.go index 3f2b35b3c77..0cce1cf6bd6 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/policies.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/common/policies.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: common/policies.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/discovery/protocol.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/discovery/protocol.pb.go index 99acaf7e06e..7587b616d60 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/discovery/protocol.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/discovery/protocol.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: discovery/protocol.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/gateway/gateway.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/gateway/gateway.pb.go index 63bf346f2b7..48063a42faa 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/gateway/gateway.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/gateway/gateway.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: gateway/gateway.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/gossip/message.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/gossip/message.pb.go index 2b7fd6d4030..c2a60197b60 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/gossip/message.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/gossip/message.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: gossip/message.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/queryresult/kv_query_result.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/queryresult/kv_query_result.pb.go index 24bebaa6142..4d3b3dd3121 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/queryresult/kv_query_result.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/queryresult/kv_query_result.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: ledger/queryresult/kv_query_result.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/kvrwset/kv_rwset.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/kvrwset/kv_rwset.pb.go index bee28b46a5e..1e57e454308 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/kvrwset/kv_rwset.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/kvrwset/kv_rwset.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: ledger/rwset/kvrwset/kv_rwset.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/rwset.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/rwset.pb.go index 5f13260adf8..3cf936e1369 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/rwset.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/rwset.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: ledger/rwset/rwset.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/identities.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/identities.pb.go index 7b906b36637..f1748959679 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/identities.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/identities.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: msp/identities.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/msp_config.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/msp_config.pb.go index 1001ae9f6e1..ae9b136295c 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/msp_config.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/msp_config.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: msp/msp_config.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/msp_principal.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/msp_principal.pb.go index 1dd13289099..b7b34c2b00c 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/msp_principal.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/msp/msp_principal.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: msp/msp_principal.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/ab.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/ab.pb.go index efbd5a1f7b4..0f04d2af92c 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/ab.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/ab.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: orderer/ab.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/blockattestation.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/blockattestation.pb.go index c286ddbd160..416eeaea193 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/blockattestation.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/blockattestation.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: orderer/blockattestation.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/cluster.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/cluster.pb.go index 52ce69365a5..7fb5a76a407 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/cluster.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/cluster.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: orderer/cluster.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/clusterserver.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/clusterserver.pb.go index 6012de414e1..2f6ca13febb 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/clusterserver.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/clusterserver.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: orderer/clusterserver.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/configuration.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/configuration.pb.go index 58f2f6a5e49..060718e6b3d 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/configuration.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/configuration.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: orderer/configuration.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/etcdraft/configuration.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/etcdraft/configuration.pb.go index e0b0b857e0b..98d567d313c 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/etcdraft/configuration.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/etcdraft/configuration.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: orderer/etcdraft/configuration.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/etcdraft/metadata.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/etcdraft/metadata.pb.go index 821265cba9c..3087ac0c5e7 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/etcdraft/metadata.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/etcdraft/metadata.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: orderer/etcdraft/metadata.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/smartbft/configuration.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/smartbft/configuration.pb.go index 9660b0b1e14..1ed8b1bfebf 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/smartbft/configuration.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/orderer/smartbft/configuration.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: orderer/smartbft/configuration.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode.pb.go index 6e0c2724594..c4a28b74455 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/chaincode.proto @@ -623,6 +623,62 @@ func (x *ChaincodeData) GetInstantiationPolicy() *common.SignaturePolicyEnvelope return nil } +// ChaincodeAdditionalParams - parameters passed to chaincode to notify about peer capabilities +type ChaincodeAdditionalParams struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UsePutStateBatch bool `protobuf:"varint,1,opt,name=use_put_state_batch,json=usePutStateBatch,proto3" json:"use_put_state_batch,omitempty"` // an indication that the peer can handle state change batches + MaxSizePutStateBatch uint32 `protobuf:"varint,2,opt,name=max_size_put_state_batch,json=maxSizePutStateBatch,proto3" json:"max_size_put_state_batch,omitempty"` // maximum size of batches with changed state +} + +func (x *ChaincodeAdditionalParams) Reset() { + *x = ChaincodeAdditionalParams{} + if protoimpl.UnsafeEnabled { + mi := &file_peer_chaincode_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ChaincodeAdditionalParams) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ChaincodeAdditionalParams) ProtoMessage() {} + +func (x *ChaincodeAdditionalParams) ProtoReflect() protoreflect.Message { + mi := &file_peer_chaincode_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ChaincodeAdditionalParams.ProtoReflect.Descriptor instead. +func (*ChaincodeAdditionalParams) Descriptor() ([]byte, []int) { + return file_peer_chaincode_proto_rawDescGZIP(), []int{8} +} + +func (x *ChaincodeAdditionalParams) GetUsePutStateBatch() bool { + if x != nil { + return x.UsePutStateBatch + } + return false +} + +func (x *ChaincodeAdditionalParams) GetMaxSizePutStateBatch() uint32 { + if x != nil { + return x.MaxSizePutStateBatch + } + return 0 +} + var File_peer_chaincode_proto protoreflect.FileDescriptor var file_peer_chaincode_proto_rawDesc = []byte{ @@ -705,18 +761,26 @@ var file_peer_chaincode_proto_rawDesc = []byte{ 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x65, 0x52, 0x13, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, - 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x42, 0xa0, 0x01, - 0x0a, 0x22, 0x6f, 0x72, 0x67, 0x2e, 0x68, 0x79, 0x70, 0x65, 0x72, 0x6c, 0x65, 0x64, 0x67, 0x65, - 0x72, 0x2e, 0x66, 0x61, 0x62, 0x72, 0x69, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, - 0x70, 0x65, 0x65, 0x72, 0x42, 0x0e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x50, - 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x68, 0x79, 0x70, 0x65, 0x72, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x2f, 0x66, - 0x61, 0x62, 0x72, 0x69, 0x63, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2d, 0x67, 0x6f, 0x2d, - 0x61, 0x70, 0x69, 0x76, 0x32, 0x2f, 0x70, 0x65, 0x65, 0x72, 0xa2, 0x02, 0x03, 0x50, 0x58, 0x58, - 0xaa, 0x02, 0x06, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0xca, 0x02, 0x06, 0x50, 0x72, 0x6f, 0x74, - 0x6f, 0x73, 0xe2, 0x02, 0x12, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x22, 0x82, 0x01, + 0x0a, 0x19, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x41, 0x64, 0x64, 0x69, 0x74, + 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x2d, 0x0a, 0x13, 0x75, + 0x73, 0x65, 0x5f, 0x70, 0x75, 0x74, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, 0x62, 0x61, 0x74, + 0x63, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x10, 0x75, 0x73, 0x65, 0x50, 0x75, 0x74, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x42, 0x61, 0x74, 0x63, 0x68, 0x12, 0x36, 0x0a, 0x18, 0x6d, 0x61, + 0x78, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x70, 0x75, 0x74, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, + 0x5f, 0x62, 0x61, 0x74, 0x63, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x14, 0x6d, 0x61, + 0x78, 0x53, 0x69, 0x7a, 0x65, 0x50, 0x75, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x42, 0x61, 0x74, + 0x63, 0x68, 0x42, 0xa0, 0x01, 0x0a, 0x22, 0x6f, 0x72, 0x67, 0x2e, 0x68, 0x79, 0x70, 0x65, 0x72, + 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x2e, 0x66, 0x61, 0x62, 0x72, 0x69, 0x63, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x42, 0x0e, 0x43, 0x68, 0x61, 0x69, 0x6e, + 0x63, 0x6f, 0x64, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x32, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x79, 0x70, 0x65, 0x72, 0x6c, 0x65, 0x64, + 0x67, 0x65, 0x72, 0x2f, 0x66, 0x61, 0x62, 0x72, 0x69, 0x63, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x73, 0x2d, 0x67, 0x6f, 0x2d, 0x61, 0x70, 0x69, 0x76, 0x32, 0x2f, 0x70, 0x65, 0x65, 0x72, 0xa2, + 0x02, 0x03, 0x50, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0xca, 0x02, + 0x06, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0xe2, 0x02, 0x12, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, + 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x50, + 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -732,7 +796,7 @@ func file_peer_chaincode_proto_rawDescGZIP() []byte { } var file_peer_chaincode_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_peer_chaincode_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_peer_chaincode_proto_msgTypes = make([]protoimpl.MessageInfo, 10) var file_peer_chaincode_proto_goTypes = []interface{}{ (ChaincodeSpec_Type)(0), // 0: protos.ChaincodeSpec.Type (*ChaincodeID)(nil), // 1: protos.ChaincodeID @@ -743,18 +807,19 @@ var file_peer_chaincode_proto_goTypes = []interface{}{ (*LifecycleEvent)(nil), // 6: protos.LifecycleEvent (*CDSData)(nil), // 7: protos.CDSData (*ChaincodeData)(nil), // 8: protos.ChaincodeData - nil, // 9: protos.ChaincodeInput.DecorationsEntry - (*common.SignaturePolicyEnvelope)(nil), // 10: common.SignaturePolicyEnvelope + (*ChaincodeAdditionalParams)(nil), // 9: protos.ChaincodeAdditionalParams + nil, // 10: protos.ChaincodeInput.DecorationsEntry + (*common.SignaturePolicyEnvelope)(nil), // 11: common.SignaturePolicyEnvelope } var file_peer_chaincode_proto_depIdxs = []int32{ - 9, // 0: protos.ChaincodeInput.decorations:type_name -> protos.ChaincodeInput.DecorationsEntry + 10, // 0: protos.ChaincodeInput.decorations:type_name -> protos.ChaincodeInput.DecorationsEntry 0, // 1: protos.ChaincodeSpec.type:type_name -> protos.ChaincodeSpec.Type 1, // 2: protos.ChaincodeSpec.chaincode_id:type_name -> protos.ChaincodeID 2, // 3: protos.ChaincodeSpec.input:type_name -> protos.ChaincodeInput 3, // 4: protos.ChaincodeDeploymentSpec.chaincode_spec:type_name -> protos.ChaincodeSpec 3, // 5: protos.ChaincodeInvocationSpec.chaincode_spec:type_name -> protos.ChaincodeSpec - 10, // 6: protos.ChaincodeData.policy:type_name -> common.SignaturePolicyEnvelope - 10, // 7: protos.ChaincodeData.instantiation_policy:type_name -> common.SignaturePolicyEnvelope + 11, // 6: protos.ChaincodeData.policy:type_name -> common.SignaturePolicyEnvelope + 11, // 7: protos.ChaincodeData.instantiation_policy:type_name -> common.SignaturePolicyEnvelope 8, // [8:8] is the sub-list for method output_type 8, // [8:8] is the sub-list for method input_type 8, // [8:8] is the sub-list for extension type_name @@ -864,6 +929,18 @@ func file_peer_chaincode_proto_init() { return nil } } + file_peer_chaincode_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ChaincodeAdditionalParams); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -871,7 +948,7 @@ func file_peer_chaincode_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_peer_chaincode_proto_rawDesc, NumEnums: 1, - NumMessages: 9, + NumMessages: 10, NumExtensions: 0, NumServices: 0, }, diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode_event.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode_event.pb.go index ab856c7a3d1..6e9e3c24456 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode_event.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode_event.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/chaincode_event.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode_shim.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode_shim.pb.go index 695668712d9..d4dbc57a719 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode_shim.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/chaincode_shim.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/chaincode_shim.proto @@ -51,6 +51,7 @@ const ( ChaincodeMessage_PUT_STATE_METADATA ChaincodeMessage_Type = 21 ChaincodeMessage_GET_PRIVATE_DATA_HASH ChaincodeMessage_Type = 22 ChaincodeMessage_PURGE_PRIVATE_DATA ChaincodeMessage_Type = 23 + ChaincodeMessage_CHANGE_STATE_BATCH ChaincodeMessage_Type = 24 ) // Enum value maps for ChaincodeMessage_Type. @@ -79,6 +80,7 @@ var ( 21: "PUT_STATE_METADATA", 22: "GET_PRIVATE_DATA_HASH", 23: "PURGE_PRIVATE_DATA", + 24: "CHANGE_STATE_BATCH", } ChaincodeMessage_Type_value = map[string]int32{ "UNDEFINED": 0, @@ -104,6 +106,7 @@ var ( "PUT_STATE_METADATA": 21, "GET_PRIVATE_DATA_HASH": 22, "PURGE_PRIVATE_DATA": 23, + "CHANGE_STATE_BATCH": 24, } ) @@ -134,6 +137,61 @@ func (ChaincodeMessage_Type) EnumDescriptor() ([]byte, []int) { return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{0, 0} } +type StateKV_Type int32 + +const ( + StateKV_UNDEFINED StateKV_Type = 0 + StateKV_PUT_STATE StateKV_Type = 9 + StateKV_DEL_STATE StateKV_Type = 10 + StateKV_PUT_STATE_METADATA StateKV_Type = 21 + StateKV_PURGE_PRIVATE_DATA StateKV_Type = 23 +) + +// Enum value maps for StateKV_Type. +var ( + StateKV_Type_name = map[int32]string{ + 0: "UNDEFINED", + 9: "PUT_STATE", + 10: "DEL_STATE", + 21: "PUT_STATE_METADATA", + 23: "PURGE_PRIVATE_DATA", + } + StateKV_Type_value = map[string]int32{ + "UNDEFINED": 0, + "PUT_STATE": 9, + "DEL_STATE": 10, + "PUT_STATE_METADATA": 21, + "PURGE_PRIVATE_DATA": 23, + } +) + +func (x StateKV_Type) Enum() *StateKV_Type { + p := new(StateKV_Type) + *p = x + return p +} + +func (x StateKV_Type) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (StateKV_Type) Descriptor() protoreflect.EnumDescriptor { + return file_peer_chaincode_shim_proto_enumTypes[1].Descriptor() +} + +func (StateKV_Type) Type() protoreflect.EnumType { + return &file_peer_chaincode_shim_proto_enumTypes[1] +} + +func (x StateKV_Type) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use StateKV_Type.Descriptor instead. +func (StateKV_Type) EnumDescriptor() ([]byte, []int) { + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{6, 0} +} + type ChaincodeMessage struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -476,6 +534,132 @@ func (x *PutStateMetadata) GetMetadata() *StateMetadata { return nil } +type ChangeStateBatch struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Kvs []*StateKV `protobuf:"bytes,1,rep,name=kvs,proto3" json:"kvs,omitempty"` +} + +func (x *ChangeStateBatch) Reset() { + *x = ChangeStateBatch{} + if protoimpl.UnsafeEnabled { + mi := &file_peer_chaincode_shim_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ChangeStateBatch) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ChangeStateBatch) ProtoMessage() {} + +func (x *ChangeStateBatch) ProtoReflect() protoreflect.Message { + mi := &file_peer_chaincode_shim_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ChangeStateBatch.ProtoReflect.Descriptor instead. +func (*ChangeStateBatch) Descriptor() ([]byte, []int) { + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{5} +} + +func (x *ChangeStateBatch) GetKvs() []*StateKV { + if x != nil { + return x.Kvs + } + return nil +} + +type StateKV struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + Collection string `protobuf:"bytes,3,opt,name=collection,proto3" json:"collection,omitempty"` + Metadata *StateMetadata `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"` + Type StateKV_Type `protobuf:"varint,5,opt,name=type,proto3,enum=protos.StateKV_Type" json:"type,omitempty"` +} + +func (x *StateKV) Reset() { + *x = StateKV{} + if protoimpl.UnsafeEnabled { + mi := &file_peer_chaincode_shim_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StateKV) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StateKV) ProtoMessage() {} + +func (x *StateKV) ProtoReflect() protoreflect.Message { + mi := &file_peer_chaincode_shim_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StateKV.ProtoReflect.Descriptor instead. +func (*StateKV) Descriptor() ([]byte, []int) { + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{6} +} + +func (x *StateKV) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *StateKV) GetValue() []byte { + if x != nil { + return x.Value + } + return nil +} + +func (x *StateKV) GetCollection() string { + if x != nil { + return x.Collection + } + return "" +} + +func (x *StateKV) GetMetadata() *StateMetadata { + if x != nil { + return x.Metadata + } + return nil +} + +func (x *StateKV) GetType() StateKV_Type { + if x != nil { + return x.Type + } + return StateKV_UNDEFINED +} + // DelState is the payload of a ChaincodeMessage. It contains a key which // needs to be recorded in the transaction's write set as a delete operation. // If the collection is specified, the key needs to be recorded in the @@ -492,7 +676,7 @@ type DelState struct { func (x *DelState) Reset() { *x = DelState{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[5] + mi := &file_peer_chaincode_shim_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -505,7 +689,7 @@ func (x *DelState) String() string { func (*DelState) ProtoMessage() {} func (x *DelState) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[5] + mi := &file_peer_chaincode_shim_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -518,7 +702,7 @@ func (x *DelState) ProtoReflect() protoreflect.Message { // Deprecated: Use DelState.ProtoReflect.Descriptor instead. func (*DelState) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{5} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{7} } func (x *DelState) GetKey() string { @@ -547,7 +731,7 @@ type PurgePrivateState struct { func (x *PurgePrivateState) Reset() { *x = PurgePrivateState{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[6] + mi := &file_peer_chaincode_shim_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -560,7 +744,7 @@ func (x *PurgePrivateState) String() string { func (*PurgePrivateState) ProtoMessage() {} func (x *PurgePrivateState) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[6] + mi := &file_peer_chaincode_shim_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -573,7 +757,7 @@ func (x *PurgePrivateState) ProtoReflect() protoreflect.Message { // Deprecated: Use PurgePrivateState.ProtoReflect.Descriptor instead. func (*PurgePrivateState) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{6} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{8} } func (x *PurgePrivateState) GetKey() string { @@ -608,7 +792,7 @@ type GetStateByRange struct { func (x *GetStateByRange) Reset() { *x = GetStateByRange{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[7] + mi := &file_peer_chaincode_shim_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -621,7 +805,7 @@ func (x *GetStateByRange) String() string { func (*GetStateByRange) ProtoMessage() {} func (x *GetStateByRange) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[7] + mi := &file_peer_chaincode_shim_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -634,7 +818,7 @@ func (x *GetStateByRange) ProtoReflect() protoreflect.Message { // Deprecated: Use GetStateByRange.ProtoReflect.Descriptor instead. func (*GetStateByRange) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{7} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{9} } func (x *GetStateByRange) GetStartKey() string { @@ -682,7 +866,7 @@ type GetQueryResult struct { func (x *GetQueryResult) Reset() { *x = GetQueryResult{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[8] + mi := &file_peer_chaincode_shim_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -695,7 +879,7 @@ func (x *GetQueryResult) String() string { func (*GetQueryResult) ProtoMessage() {} func (x *GetQueryResult) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[8] + mi := &file_peer_chaincode_shim_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -708,7 +892,7 @@ func (x *GetQueryResult) ProtoReflect() protoreflect.Message { // Deprecated: Use GetQueryResult.ProtoReflect.Descriptor instead. func (*GetQueryResult) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{8} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{10} } func (x *GetQueryResult) GetQuery() string { @@ -747,7 +931,7 @@ type QueryMetadata struct { func (x *QueryMetadata) Reset() { *x = QueryMetadata{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[9] + mi := &file_peer_chaincode_shim_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -760,7 +944,7 @@ func (x *QueryMetadata) String() string { func (*QueryMetadata) ProtoMessage() {} func (x *QueryMetadata) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[9] + mi := &file_peer_chaincode_shim_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -773,7 +957,7 @@ func (x *QueryMetadata) ProtoReflect() protoreflect.Message { // Deprecated: Use QueryMetadata.ProtoReflect.Descriptor instead. func (*QueryMetadata) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{9} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{11} } func (x *QueryMetadata) GetPageSize() int32 { @@ -803,7 +987,7 @@ type GetHistoryForKey struct { func (x *GetHistoryForKey) Reset() { *x = GetHistoryForKey{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[10] + mi := &file_peer_chaincode_shim_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -816,7 +1000,7 @@ func (x *GetHistoryForKey) String() string { func (*GetHistoryForKey) ProtoMessage() {} func (x *GetHistoryForKey) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[10] + mi := &file_peer_chaincode_shim_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -829,7 +1013,7 @@ func (x *GetHistoryForKey) ProtoReflect() protoreflect.Message { // Deprecated: Use GetHistoryForKey.ProtoReflect.Descriptor instead. func (*GetHistoryForKey) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{10} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{12} } func (x *GetHistoryForKey) GetKey() string { @@ -850,7 +1034,7 @@ type QueryStateNext struct { func (x *QueryStateNext) Reset() { *x = QueryStateNext{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[11] + mi := &file_peer_chaincode_shim_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -863,7 +1047,7 @@ func (x *QueryStateNext) String() string { func (*QueryStateNext) ProtoMessage() {} func (x *QueryStateNext) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[11] + mi := &file_peer_chaincode_shim_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -876,7 +1060,7 @@ func (x *QueryStateNext) ProtoReflect() protoreflect.Message { // Deprecated: Use QueryStateNext.ProtoReflect.Descriptor instead. func (*QueryStateNext) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{11} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{13} } func (x *QueryStateNext) GetId() string { @@ -897,7 +1081,7 @@ type QueryStateClose struct { func (x *QueryStateClose) Reset() { *x = QueryStateClose{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[12] + mi := &file_peer_chaincode_shim_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -910,7 +1094,7 @@ func (x *QueryStateClose) String() string { func (*QueryStateClose) ProtoMessage() {} func (x *QueryStateClose) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[12] + mi := &file_peer_chaincode_shim_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -923,7 +1107,7 @@ func (x *QueryStateClose) ProtoReflect() protoreflect.Message { // Deprecated: Use QueryStateClose.ProtoReflect.Descriptor instead. func (*QueryStateClose) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{12} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{14} } func (x *QueryStateClose) GetId() string { @@ -945,7 +1129,7 @@ type QueryResultBytes struct { func (x *QueryResultBytes) Reset() { *x = QueryResultBytes{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[13] + mi := &file_peer_chaincode_shim_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -958,7 +1142,7 @@ func (x *QueryResultBytes) String() string { func (*QueryResultBytes) ProtoMessage() {} func (x *QueryResultBytes) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[13] + mi := &file_peer_chaincode_shim_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -971,7 +1155,7 @@ func (x *QueryResultBytes) ProtoReflect() protoreflect.Message { // Deprecated: Use QueryResultBytes.ProtoReflect.Descriptor instead. func (*QueryResultBytes) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{13} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{15} } func (x *QueryResultBytes) GetResultBytes() []byte { @@ -1000,7 +1184,7 @@ type QueryResponse struct { func (x *QueryResponse) Reset() { *x = QueryResponse{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[14] + mi := &file_peer_chaincode_shim_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1013,7 +1197,7 @@ func (x *QueryResponse) String() string { func (*QueryResponse) ProtoMessage() {} func (x *QueryResponse) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[14] + mi := &file_peer_chaincode_shim_proto_msgTypes[16] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1026,7 +1210,7 @@ func (x *QueryResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use QueryResponse.ProtoReflect.Descriptor instead. func (*QueryResponse) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{14} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{16} } func (x *QueryResponse) GetResults() []*QueryResultBytes { @@ -1071,7 +1255,7 @@ type QueryResponseMetadata struct { func (x *QueryResponseMetadata) Reset() { *x = QueryResponseMetadata{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[15] + mi := &file_peer_chaincode_shim_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1084,7 +1268,7 @@ func (x *QueryResponseMetadata) String() string { func (*QueryResponseMetadata) ProtoMessage() {} func (x *QueryResponseMetadata) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[15] + mi := &file_peer_chaincode_shim_proto_msgTypes[17] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1097,7 +1281,7 @@ func (x *QueryResponseMetadata) ProtoReflect() protoreflect.Message { // Deprecated: Use QueryResponseMetadata.ProtoReflect.Descriptor instead. func (*QueryResponseMetadata) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{15} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{17} } func (x *QueryResponseMetadata) GetFetchedRecordsCount() int32 { @@ -1126,7 +1310,7 @@ type StateMetadata struct { func (x *StateMetadata) Reset() { *x = StateMetadata{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[16] + mi := &file_peer_chaincode_shim_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1139,7 +1323,7 @@ func (x *StateMetadata) String() string { func (*StateMetadata) ProtoMessage() {} func (x *StateMetadata) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[16] + mi := &file_peer_chaincode_shim_proto_msgTypes[18] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1152,7 +1336,7 @@ func (x *StateMetadata) ProtoReflect() protoreflect.Message { // Deprecated: Use StateMetadata.ProtoReflect.Descriptor instead. func (*StateMetadata) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{16} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{18} } func (x *StateMetadata) GetMetakey() string { @@ -1180,7 +1364,7 @@ type StateMetadataResult struct { func (x *StateMetadataResult) Reset() { *x = StateMetadataResult{} if protoimpl.UnsafeEnabled { - mi := &file_peer_chaincode_shim_proto_msgTypes[17] + mi := &file_peer_chaincode_shim_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1193,7 +1377,7 @@ func (x *StateMetadataResult) String() string { func (*StateMetadataResult) ProtoMessage() {} func (x *StateMetadataResult) ProtoReflect() protoreflect.Message { - mi := &file_peer_chaincode_shim_proto_msgTypes[17] + mi := &file_peer_chaincode_shim_proto_msgTypes[19] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1206,7 +1390,7 @@ func (x *StateMetadataResult) ProtoReflect() protoreflect.Message { // Deprecated: Use StateMetadataResult.ProtoReflect.Descriptor instead. func (*StateMetadataResult) Descriptor() ([]byte, []int) { - return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{17} + return file_peer_chaincode_shim_proto_rawDescGZIP(), []int{19} } func (x *StateMetadataResult) GetEntries() []*StateMetadata { @@ -1226,7 +1410,7 @@ var file_peer_chaincode_shim_proto_rawDesc = []byte{ 0x13, 0x70, 0x65, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xee, 0x05, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x86, 0x06, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, @@ -1246,7 +1430,7 @@ var file_peer_chaincode_shim_proto_rawDesc = []byte{ 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x0e, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, - 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x22, 0xaa, 0x03, 0x0a, 0x04, 0x54, 0x79, + 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x22, 0xc2, 0x03, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x44, 0x45, 0x46, 0x49, 0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x47, 0x49, 0x53, 0x54, 0x45, 0x52, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x52, 0x45, 0x47, 0x49, 0x53, 0x54, 0x45, 0x52, 0x45, 0x44, 0x10, 0x02, 0x12, @@ -1273,111 +1457,133 @@ var file_peer_chaincode_shim_proto_rawDesc = []byte{ 0x41, 0x10, 0x15, 0x12, 0x19, 0x0a, 0x15, 0x47, 0x45, 0x54, 0x5f, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x5f, 0x48, 0x41, 0x53, 0x48, 0x10, 0x16, 0x12, 0x16, 0x0a, 0x12, 0x50, 0x55, 0x52, 0x47, 0x45, 0x5f, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x5f, - 0x44, 0x41, 0x54, 0x41, 0x10, 0x17, 0x22, 0x3c, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x44, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, - 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, - 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, - 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x52, 0x0a, 0x08, 0x50, 0x75, - 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1e, - 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x77, - 0x0a, 0x10, 0x50, 0x75, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x31, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x08, 0x6d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0x3c, 0x0a, 0x08, 0x44, 0x65, 0x6c, 0x53, 0x74, - 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x45, 0x0a, 0x11, 0x50, 0x75, 0x72, 0x67, 0x65, 0x50, 0x72, - 0x69, 0x76, 0x61, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x44, 0x41, 0x54, 0x41, 0x10, 0x17, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, + 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x42, 0x41, 0x54, 0x43, 0x48, 0x10, 0x18, 0x22, 0x3c, + 0x0a, 0x08, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x81, 0x01, 0x0a, - 0x0f, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x42, 0x79, 0x52, 0x61, 0x6e, 0x67, 0x65, - 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, - 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x6e, - 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, + 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x44, 0x0a, 0x10, + 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x22, 0x52, 0x0a, 0x08, 0x50, 0x75, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x10, + 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, + 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, + 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x77, 0x0a, 0x10, 0x50, 0x75, 0x74, 0x53, 0x74, 0x61, + 0x74, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, + 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x31, 0x0a, 0x08, + 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, + 0x35, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x42, 0x61, + 0x74, 0x63, 0x68, 0x12, 0x21, 0x0a, 0x03, 0x6b, 0x76, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x0f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4b, + 0x56, 0x52, 0x03, 0x6b, 0x76, 0x73, 0x22, 0x93, 0x02, 0x0a, 0x07, 0x53, 0x74, 0x61, 0x74, 0x65, + 0x4b, 0x56, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, + 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x31, 0x0a, 0x08, 0x6d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, + 0x61, 0x74, 0x61, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x28, 0x0a, + 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4b, 0x56, 0x2e, 0x54, 0x79, 0x70, + 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x63, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x44, 0x45, 0x46, 0x49, 0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0d, + 0x0a, 0x09, 0x50, 0x55, 0x54, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x10, 0x09, 0x12, 0x0d, 0x0a, + 0x09, 0x44, 0x45, 0x4c, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x10, 0x0a, 0x12, 0x16, 0x0a, 0x12, + 0x50, 0x55, 0x54, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x5f, 0x4d, 0x45, 0x54, 0x41, 0x44, 0x41, + 0x54, 0x41, 0x10, 0x15, 0x12, 0x16, 0x0a, 0x12, 0x50, 0x55, 0x52, 0x47, 0x45, 0x5f, 0x50, 0x52, + 0x49, 0x56, 0x41, 0x54, 0x45, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x10, 0x17, 0x22, 0x3c, 0x0a, 0x08, + 0x44, 0x65, 0x6c, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, + 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x45, 0x0a, 0x11, 0x50, 0x75, + 0x72, 0x67, 0x65, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x22, 0x81, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x42, 0x79, + 0x52, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, + 0x79, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, + 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, + 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x6d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0x62, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x51, 0x75, 0x65, 0x72, + 0x79, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x12, 0x1e, 0x0a, + 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, + 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0x47, 0x0a, 0x0d, 0x51, 0x75, 0x65, + 0x72, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, + 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x61, + 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x6f, 0x6f, 0x6b, 0x6d, 0x61, + 0x72, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x6f, 0x6f, 0x6b, 0x6d, 0x61, + 0x72, 0x6b, 0x22, 0x24, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, + 0x46, 0x6f, 0x72, 0x4b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x20, 0x0a, 0x0e, 0x51, 0x75, 0x65, 0x72, + 0x79, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4e, 0x65, 0x78, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x21, 0x0a, 0x0f, 0x51, 0x75, + 0x65, 0x72, 0x79, 0x53, 0x74, 0x61, 0x74, 0x65, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x34, 0x0a, + 0x10, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x79, 0x74, 0x65, + 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x79, 0x74, 0x65, 0x73, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x79, + 0x74, 0x65, 0x73, 0x22, 0x8a, 0x01, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x32, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, + 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x79, 0x74, 0x65, 0x73, + 0x52, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x68, 0x61, 0x73, + 0x5f, 0x6d, 0x6f, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x68, 0x61, 0x73, + 0x4d, 0x6f, 0x72, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, - 0x22, 0x62, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x75, - 0x6c, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, - 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, - 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0x22, 0x47, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x4d, 0x65, 0x74, - 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, - 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, - 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x6f, 0x6f, 0x6b, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x6f, 0x6f, 0x6b, 0x6d, 0x61, 0x72, 0x6b, 0x22, 0x24, 0x0a, - 0x10, 0x47, 0x65, 0x74, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x46, 0x6f, 0x72, 0x4b, 0x65, - 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, - 0x6b, 0x65, 0x79, 0x22, 0x20, 0x0a, 0x0e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x74, 0x61, 0x74, - 0x65, 0x4e, 0x65, 0x78, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x21, 0x0a, 0x0f, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x74, - 0x61, 0x74, 0x65, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x34, 0x0a, 0x10, 0x51, 0x75, 0x65, 0x72, - 0x79, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x20, 0x0a, 0x0b, - 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x79, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x0b, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x79, 0x74, 0x65, 0x73, 0x22, 0x8a, - 0x01, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x32, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, - 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x07, 0x72, 0x65, 0x73, - 0x75, 0x6c, 0x74, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x68, 0x61, 0x73, 0x5f, 0x6d, 0x6f, 0x72, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x68, 0x61, 0x73, 0x4d, 0x6f, 0x72, 0x65, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, - 0x1a, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0x67, 0x0a, 0x15, 0x51, - 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0x12, 0x32, 0x0a, 0x15, 0x66, 0x65, 0x74, 0x63, 0x68, 0x65, 0x64, 0x5f, - 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x05, 0x52, 0x13, 0x66, 0x65, 0x74, 0x63, 0x68, 0x65, 0x64, 0x52, 0x65, 0x63, 0x6f, - 0x72, 0x64, 0x73, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x6f, 0x6f, 0x6b, - 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x6f, 0x6f, 0x6b, - 0x6d, 0x61, 0x72, 0x6b, 0x22, 0x3f, 0x0a, 0x0d, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, - 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x74, 0x61, 0x6b, 0x65, 0x79, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x74, 0x61, 0x6b, 0x65, 0x79, 0x12, - 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x46, 0x0a, 0x13, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4d, 0x65, - 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x2f, 0x0a, 0x07, - 0x65, 0x6e, 0x74, 0x72, 0x69, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0x52, 0x07, 0x65, 0x6e, 0x74, 0x72, 0x69, 0x65, 0x73, 0x32, 0x56, 0x0a, - 0x10, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x53, 0x75, 0x70, 0x70, 0x6f, 0x72, - 0x74, 0x12, 0x42, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x18, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, - 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, - 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x28, 0x01, 0x30, 0x01, 0x32, 0x4e, 0x0a, 0x09, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, - 0x64, 0x65, 0x12, 0x41, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x12, 0x18, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, - 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, - 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x28, 0x01, 0x30, 0x01, 0x42, 0xa4, 0x01, 0x0a, 0x22, 0x6f, 0x72, 0x67, 0x2e, 0x68, 0x79, - 0x70, 0x65, 0x72, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x2e, 0x66, 0x61, 0x62, 0x72, 0x69, 0x63, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x70, 0x65, 0x65, 0x72, 0x42, 0x12, 0x43, 0x68, - 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x53, 0x68, 0x69, 0x6d, 0x50, 0x72, 0x6f, 0x74, 0x6f, - 0x50, 0x01, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, - 0x79, 0x70, 0x65, 0x72, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x2f, 0x66, 0x61, 0x62, 0x72, 0x69, - 0x63, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2d, 0x67, 0x6f, 0x2d, 0x61, 0x70, 0x69, 0x76, - 0x32, 0x2f, 0x70, 0x65, 0x65, 0x72, 0xa2, 0x02, 0x03, 0x50, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x50, - 0x72, 0x6f, 0x74, 0x6f, 0x73, 0xca, 0x02, 0x06, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0xe2, 0x02, - 0x12, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, - 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x22, 0x67, 0x0a, 0x15, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x32, 0x0a, 0x15, 0x66, 0x65, 0x74, + 0x63, 0x68, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x5f, 0x63, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x13, 0x66, 0x65, 0x74, 0x63, 0x68, 0x65, + 0x64, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1a, 0x0a, + 0x08, 0x62, 0x6f, 0x6f, 0x6b, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x62, 0x6f, 0x6f, 0x6b, 0x6d, 0x61, 0x72, 0x6b, 0x22, 0x3f, 0x0a, 0x0d, 0x53, 0x74, 0x61, + 0x74, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x74, 0x61, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x74, + 0x61, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x46, 0x0a, 0x13, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x75, 0x6c, + 0x74, 0x12, 0x2f, 0x0a, 0x07, 0x65, 0x6e, 0x74, 0x72, 0x69, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x53, 0x74, 0x61, 0x74, + 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x07, 0x65, 0x6e, 0x74, 0x72, 0x69, + 0x65, 0x73, 0x32, 0x56, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x53, + 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x42, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, + 0x65, 0x72, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x69, + 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x18, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x28, 0x01, 0x30, 0x01, 0x32, 0x4e, 0x0a, 0x09, 0x43, 0x68, + 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x41, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x6e, 0x65, + 0x63, 0x74, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x69, + 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x18, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x28, 0x01, 0x30, 0x01, 0x42, 0xa4, 0x01, 0x0a, 0x22, 0x6f, + 0x72, 0x67, 0x2e, 0x68, 0x79, 0x70, 0x65, 0x72, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x2e, 0x66, + 0x61, 0x62, 0x72, 0x69, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x70, 0x65, 0x65, + 0x72, 0x42, 0x12, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x53, 0x68, 0x69, 0x6d, + 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x79, 0x70, 0x65, 0x72, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x2f, + 0x66, 0x61, 0x62, 0x72, 0x69, 0x63, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2d, 0x67, 0x6f, + 0x2d, 0x61, 0x70, 0x69, 0x76, 0x32, 0x2f, 0x70, 0x65, 0x65, 0x72, 0xa2, 0x02, 0x03, 0x50, 0x58, + 0x58, 0xaa, 0x02, 0x06, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0xca, 0x02, 0x06, 0x50, 0x72, 0x6f, + 0x74, 0x6f, 0x73, 0xe2, 0x02, 0x12, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x5c, 0x47, 0x50, 0x42, + 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1392,49 +1598,55 @@ func file_peer_chaincode_shim_proto_rawDescGZIP() []byte { return file_peer_chaincode_shim_proto_rawDescData } -var file_peer_chaincode_shim_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_peer_chaincode_shim_proto_msgTypes = make([]protoimpl.MessageInfo, 18) +var file_peer_chaincode_shim_proto_enumTypes = make([]protoimpl.EnumInfo, 2) +var file_peer_chaincode_shim_proto_msgTypes = make([]protoimpl.MessageInfo, 20) var file_peer_chaincode_shim_proto_goTypes = []interface{}{ (ChaincodeMessage_Type)(0), // 0: protos.ChaincodeMessage.Type - (*ChaincodeMessage)(nil), // 1: protos.ChaincodeMessage - (*GetState)(nil), // 2: protos.GetState - (*GetStateMetadata)(nil), // 3: protos.GetStateMetadata - (*PutState)(nil), // 4: protos.PutState - (*PutStateMetadata)(nil), // 5: protos.PutStateMetadata - (*DelState)(nil), // 6: protos.DelState - (*PurgePrivateState)(nil), // 7: protos.PurgePrivateState - (*GetStateByRange)(nil), // 8: protos.GetStateByRange - (*GetQueryResult)(nil), // 9: protos.GetQueryResult - (*QueryMetadata)(nil), // 10: protos.QueryMetadata - (*GetHistoryForKey)(nil), // 11: protos.GetHistoryForKey - (*QueryStateNext)(nil), // 12: protos.QueryStateNext - (*QueryStateClose)(nil), // 13: protos.QueryStateClose - (*QueryResultBytes)(nil), // 14: protos.QueryResultBytes - (*QueryResponse)(nil), // 15: protos.QueryResponse - (*QueryResponseMetadata)(nil), // 16: protos.QueryResponseMetadata - (*StateMetadata)(nil), // 17: protos.StateMetadata - (*StateMetadataResult)(nil), // 18: protos.StateMetadataResult - (*timestamppb.Timestamp)(nil), // 19: google.protobuf.Timestamp - (*SignedProposal)(nil), // 20: protos.SignedProposal - (*ChaincodeEvent)(nil), // 21: protos.ChaincodeEvent + (StateKV_Type)(0), // 1: protos.StateKV.Type + (*ChaincodeMessage)(nil), // 2: protos.ChaincodeMessage + (*GetState)(nil), // 3: protos.GetState + (*GetStateMetadata)(nil), // 4: protos.GetStateMetadata + (*PutState)(nil), // 5: protos.PutState + (*PutStateMetadata)(nil), // 6: protos.PutStateMetadata + (*ChangeStateBatch)(nil), // 7: protos.ChangeStateBatch + (*StateKV)(nil), // 8: protos.StateKV + (*DelState)(nil), // 9: protos.DelState + (*PurgePrivateState)(nil), // 10: protos.PurgePrivateState + (*GetStateByRange)(nil), // 11: protos.GetStateByRange + (*GetQueryResult)(nil), // 12: protos.GetQueryResult + (*QueryMetadata)(nil), // 13: protos.QueryMetadata + (*GetHistoryForKey)(nil), // 14: protos.GetHistoryForKey + (*QueryStateNext)(nil), // 15: protos.QueryStateNext + (*QueryStateClose)(nil), // 16: protos.QueryStateClose + (*QueryResultBytes)(nil), // 17: protos.QueryResultBytes + (*QueryResponse)(nil), // 18: protos.QueryResponse + (*QueryResponseMetadata)(nil), // 19: protos.QueryResponseMetadata + (*StateMetadata)(nil), // 20: protos.StateMetadata + (*StateMetadataResult)(nil), // 21: protos.StateMetadataResult + (*timestamppb.Timestamp)(nil), // 22: google.protobuf.Timestamp + (*SignedProposal)(nil), // 23: protos.SignedProposal + (*ChaincodeEvent)(nil), // 24: protos.ChaincodeEvent } var file_peer_chaincode_shim_proto_depIdxs = []int32{ 0, // 0: protos.ChaincodeMessage.type:type_name -> protos.ChaincodeMessage.Type - 19, // 1: protos.ChaincodeMessage.timestamp:type_name -> google.protobuf.Timestamp - 20, // 2: protos.ChaincodeMessage.proposal:type_name -> protos.SignedProposal - 21, // 3: protos.ChaincodeMessage.chaincode_event:type_name -> protos.ChaincodeEvent - 17, // 4: protos.PutStateMetadata.metadata:type_name -> protos.StateMetadata - 14, // 5: protos.QueryResponse.results:type_name -> protos.QueryResultBytes - 17, // 6: protos.StateMetadataResult.entries:type_name -> protos.StateMetadata - 1, // 7: protos.ChaincodeSupport.Register:input_type -> protos.ChaincodeMessage - 1, // 8: protos.Chaincode.Connect:input_type -> protos.ChaincodeMessage - 1, // 9: protos.ChaincodeSupport.Register:output_type -> protos.ChaincodeMessage - 1, // 10: protos.Chaincode.Connect:output_type -> protos.ChaincodeMessage - 9, // [9:11] is the sub-list for method output_type - 7, // [7:9] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 22, // 1: protos.ChaincodeMessage.timestamp:type_name -> google.protobuf.Timestamp + 23, // 2: protos.ChaincodeMessage.proposal:type_name -> protos.SignedProposal + 24, // 3: protos.ChaincodeMessage.chaincode_event:type_name -> protos.ChaincodeEvent + 20, // 4: protos.PutStateMetadata.metadata:type_name -> protos.StateMetadata + 8, // 5: protos.ChangeStateBatch.kvs:type_name -> protos.StateKV + 20, // 6: protos.StateKV.metadata:type_name -> protos.StateMetadata + 1, // 7: protos.StateKV.type:type_name -> protos.StateKV.Type + 17, // 8: protos.QueryResponse.results:type_name -> protos.QueryResultBytes + 20, // 9: protos.StateMetadataResult.entries:type_name -> protos.StateMetadata + 2, // 10: protos.ChaincodeSupport.Register:input_type -> protos.ChaincodeMessage + 2, // 11: protos.Chaincode.Connect:input_type -> protos.ChaincodeMessage + 2, // 12: protos.ChaincodeSupport.Register:output_type -> protos.ChaincodeMessage + 2, // 13: protos.Chaincode.Connect:output_type -> protos.ChaincodeMessage + 12, // [12:14] is the sub-list for method output_type + 10, // [10:12] is the sub-list for method input_type + 10, // [10:10] is the sub-list for extension type_name + 10, // [10:10] is the sub-list for extension extendee + 0, // [0:10] is the sub-list for field type_name } func init() { file_peer_chaincode_shim_proto_init() } @@ -1506,7 +1718,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DelState); i { + switch v := v.(*ChangeStateBatch); i { case 0: return &v.state case 1: @@ -1518,7 +1730,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PurgePrivateState); i { + switch v := v.(*StateKV); i { case 0: return &v.state case 1: @@ -1530,7 +1742,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetStateByRange); i { + switch v := v.(*DelState); i { case 0: return &v.state case 1: @@ -1542,7 +1754,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetQueryResult); i { + switch v := v.(*PurgePrivateState); i { case 0: return &v.state case 1: @@ -1554,7 +1766,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*QueryMetadata); i { + switch v := v.(*GetStateByRange); i { case 0: return &v.state case 1: @@ -1566,7 +1778,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetHistoryForKey); i { + switch v := v.(*GetQueryResult); i { case 0: return &v.state case 1: @@ -1578,7 +1790,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*QueryStateNext); i { + switch v := v.(*QueryMetadata); i { case 0: return &v.state case 1: @@ -1590,7 +1802,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*QueryStateClose); i { + switch v := v.(*GetHistoryForKey); i { case 0: return &v.state case 1: @@ -1602,7 +1814,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*QueryResultBytes); i { + switch v := v.(*QueryStateNext); i { case 0: return &v.state case 1: @@ -1614,7 +1826,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*QueryResponse); i { + switch v := v.(*QueryStateClose); i { case 0: return &v.state case 1: @@ -1626,7 +1838,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*QueryResponseMetadata); i { + switch v := v.(*QueryResultBytes); i { case 0: return &v.state case 1: @@ -1638,7 +1850,7 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*StateMetadata); i { + switch v := v.(*QueryResponse); i { case 0: return &v.state case 1: @@ -1650,6 +1862,30 @@ func file_peer_chaincode_shim_proto_init() { } } file_peer_chaincode_shim_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*QueryResponseMetadata); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_peer_chaincode_shim_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StateMetadata); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_peer_chaincode_shim_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*StateMetadataResult); i { case 0: return &v.state @@ -1667,8 +1903,8 @@ func file_peer_chaincode_shim_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_peer_chaincode_shim_proto_rawDesc, - NumEnums: 1, - NumMessages: 18, + NumEnums: 2, + NumMessages: 20, NumExtensions: 0, NumServices: 2, }, diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/collection.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/collection.pb.go index c55fa1a2a9e..7f100490733 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/collection.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/collection.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/collection.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/configuration.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/configuration.pb.go index 238b3e4835e..9d3f82495ca 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/configuration.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/configuration.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/configuration.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/events.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/events.pb.go index 27c810d4b75..37c2f38fe1c 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/events.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/events.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/events.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/chaincode_definition.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/chaincode_definition.pb.go index dc14e8fface..7b4976bdb5b 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/chaincode_definition.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/chaincode_definition.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/lifecycle/chaincode_definition.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/db.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/db.pb.go index bbe1a748449..4e02ace1e9f 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/db.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/db.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/lifecycle/db.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/lifecycle.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/lifecycle.pb.go index af83baacd38..af42d7078b8 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/lifecycle.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/lifecycle/lifecycle.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/lifecycle/lifecycle.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/peer.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/peer.pb.go index b8172e6586f..ac100fb8342 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/peer.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/peer.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/peer.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/policy.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/policy.pb.go index 38a220f5550..99e99044f2b 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/policy.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/policy.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/policy.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/proposal.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/proposal.pb.go index c737a9da2e7..46b7f13d844 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/proposal.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/proposal.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/proposal.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/proposal_response.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/proposal_response.pb.go index 40a48d3ac56..5524b3e748b 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/proposal_response.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/proposal_response.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/proposal_response.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/query.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/query.pb.go index fc263cdddcf..3341d6e1c3a 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/query.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/query.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/query.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/resources.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/resources.pb.go index a7c2eef34f9..e94129daa11 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/resources.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/resources.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/resources.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/signed_cc_dep_spec.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/signed_cc_dep_spec.pb.go index 4c31baa7736..cb6ab9ddf3b 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/signed_cc_dep_spec.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/signed_cc_dep_spec.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/signed_cc_dep_spec.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/snapshot.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/snapshot.pb.go index 4f9494c9af4..a80153b1bf3 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/snapshot.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/snapshot.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/snapshot.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/transaction.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/transaction.pb.go index dc094f2627f..4b0ae311331 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/transaction.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/peer/transaction.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: peer/transaction.proto diff --git a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/transientstore/transientstore.pb.go b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/transientstore/transientstore.pb.go index b4ee02279a3..fc793fbeeab 100644 --- a/vendor/github.com/hyperledger/fabric-protos-go-apiv2/transientstore/transientstore.pb.go +++ b/vendor/github.com/hyperledger/fabric-protos-go-apiv2/transientstore/transientstore.pb.go @@ -4,7 +4,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: transientstore/transientstore.proto diff --git a/vendor/github.com/onsi/gomega/gmeasure/cache.go b/vendor/github.com/onsi/gomega/gmeasure/cache.go new file mode 100644 index 00000000000..27fab63757a --- /dev/null +++ b/vendor/github.com/onsi/gomega/gmeasure/cache.go @@ -0,0 +1,202 @@ +package gmeasure + +import ( + "crypto/md5" + "encoding/json" + "fmt" + "os" + "path/filepath" + + "github.com/onsi/gomega/internal/gutil" +) + +const CACHE_EXT = ".gmeasure-cache" + +/* +ExperimentCache provides a director-and-file based cache of experiments +*/ +type ExperimentCache struct { + Path string +} + +/* +NewExperimentCache creates and initializes a new cache. Path must point to a directory (if path does not exist, NewExperimentCache will create a directory at path). + +Cached Experiments are stored as separate files in the cache directory - the filename is a hash of the Experiment name. Each file contains two JSON-encoded objects - a CachedExperimentHeader that includes the experiment's name and cache version number, and then the Experiment itself. +*/ +func NewExperimentCache(path string) (ExperimentCache, error) { + stat, err := os.Stat(path) + if os.IsNotExist(err) { + err := os.MkdirAll(path, 0777) + if err != nil { + return ExperimentCache{}, err + } + } else if !stat.IsDir() { + return ExperimentCache{}, fmt.Errorf("%s is not a directory", path) + } + + return ExperimentCache{ + Path: path, + }, nil +} + +/* +CachedExperimentHeader captures the name of the Cached Experiment and its Version +*/ +type CachedExperimentHeader struct { + Name string + Version int +} + +func (cache ExperimentCache) hashOf(name string) string { + return fmt.Sprintf("%x", md5.Sum([]byte(name))) +} + +func (cache ExperimentCache) readHeader(filename string) (CachedExperimentHeader, error) { + out := CachedExperimentHeader{} + f, err := os.Open(filepath.Join(cache.Path, filename)) + if err != nil { + return out, err + } + defer f.Close() + err = json.NewDecoder(f).Decode(&out) + return out, err +} + +/* +List returns a list of all Cached Experiments found in the cache. +*/ +func (cache ExperimentCache) List() ([]CachedExperimentHeader, error) { + var out []CachedExperimentHeader + names, err := gutil.ReadDir(cache.Path) + if err != nil { + return out, err + } + for _, name := range names { + if filepath.Ext(name) != CACHE_EXT { + continue + } + header, err := cache.readHeader(name) + if err != nil { + return out, err + } + out = append(out, header) + } + return out, nil +} + +/* +Clear empties out the cache - this will delete any and all detected cache files in the cache directory. Use with caution! +*/ +func (cache ExperimentCache) Clear() error { + names, err := gutil.ReadDir(cache.Path) + if err != nil { + return err + } + for _, name := range names { + if filepath.Ext(name) != CACHE_EXT { + continue + } + err := os.Remove(filepath.Join(cache.Path, name)) + if err != nil { + return err + } + } + return nil +} + +/* +Load fetches an experiment from the cache. Lookup occurs by name. Load requires that the version numer in the cache is equal to or greater than the passed-in version. + +If an experiment with corresponding name and version >= the passed-in version is found, it is unmarshaled and returned. + +If no experiment is found, or the cached version is smaller than the passed-in version, Load will return nil. + +When paired with Ginkgo you can cache experiments and prevent potentially expensive recomputation with this pattern: + + const EXPERIMENT_VERSION = 1 //bump this to bust the cache and recompute _all_ experiments + + Describe("some experiments", func() { + var cache gmeasure.ExperimentCache + var experiment *gmeasure.Experiment + + BeforeEach(func() { + cache = gmeasure.NewExperimentCache("./gmeasure-cache") + name := CurrentSpecReport().LeafNodeText + experiment = cache.Load(name, EXPERIMENT_VERSION) + if experiment != nil { + AddReportEntry(experiment) + Skip("cached") + } + experiment = gmeasure.NewExperiment(name) + AddReportEntry(experiment) + }) + + It("foo runtime", func() { + experiment.SampleDuration("runtime", func() { + //do stuff + }, gmeasure.SamplingConfig{N:100}) + }) + + It("bar runtime", func() { + experiment.SampleDuration("runtime", func() { + //do stuff + }, gmeasure.SamplingConfig{N:100}) + }) + + AfterEach(func() { + if !CurrentSpecReport().State.Is(types.SpecStateSkipped) { + cache.Save(experiment.Name, EXPERIMENT_VERSION, experiment) + } + }) + }) +*/ +func (cache ExperimentCache) Load(name string, version int) *Experiment { + path := filepath.Join(cache.Path, cache.hashOf(name)+CACHE_EXT) + f, err := os.Open(path) + if err != nil { + return nil + } + defer f.Close() + dec := json.NewDecoder(f) + header := CachedExperimentHeader{} + dec.Decode(&header) + if header.Version < version { + return nil + } + out := NewExperiment("") + err = dec.Decode(out) + if err != nil { + return nil + } + return out +} + +/* +Save stores the passed-in experiment to the cache with the passed-in name and version. +*/ +func (cache ExperimentCache) Save(name string, version int, experiment *Experiment) error { + path := filepath.Join(cache.Path, cache.hashOf(name)+CACHE_EXT) + f, err := os.Create(path) + if err != nil { + return err + } + defer f.Close() + enc := json.NewEncoder(f) + err = enc.Encode(CachedExperimentHeader{ + Name: name, + Version: version, + }) + if err != nil { + return err + } + return enc.Encode(experiment) +} + +/* +Delete removes the experiment with the passed-in name from the cache +*/ +func (cache ExperimentCache) Delete(name string) error { + path := filepath.Join(cache.Path, cache.hashOf(name)+CACHE_EXT) + return os.Remove(path) +} diff --git a/vendor/github.com/onsi/gomega/gmeasure/enum_support.go b/vendor/github.com/onsi/gomega/gmeasure/enum_support.go new file mode 100644 index 00000000000..b5404f96200 --- /dev/null +++ b/vendor/github.com/onsi/gomega/gmeasure/enum_support.go @@ -0,0 +1,43 @@ +package gmeasure + +import "encoding/json" + +type enumSupport struct { + toString map[uint]string + toEnum map[string]uint + maxEnum uint +} + +func newEnumSupport(toString map[uint]string) enumSupport { + toEnum, maxEnum := map[string]uint{}, uint(0) + for k, v := range toString { + toEnum[v] = k + if maxEnum < k { + maxEnum = k + } + } + return enumSupport{toString: toString, toEnum: toEnum, maxEnum: maxEnum} +} + +func (es enumSupport) String(e uint) string { + if e > es.maxEnum { + return es.toString[0] + } + return es.toString[e] +} + +func (es enumSupport) UnmarshJSON(b []byte) (uint, error) { + var dec string + if err := json.Unmarshal(b, &dec); err != nil { + return 0, err + } + out := es.toEnum[dec] // if we miss we get 0 which is what we want anyway + return out, nil +} + +func (es enumSupport) MarshJSON(e uint) ([]byte, error) { + if e == 0 || e > es.maxEnum { + return json.Marshal(nil) + } + return json.Marshal(es.toString[e]) +} diff --git a/vendor/github.com/onsi/gomega/gmeasure/experiment.go b/vendor/github.com/onsi/gomega/gmeasure/experiment.go new file mode 100644 index 00000000000..a8341c5e662 --- /dev/null +++ b/vendor/github.com/onsi/gomega/gmeasure/experiment.go @@ -0,0 +1,527 @@ +/* +Package gomega/gmeasure provides support for benchmarking and measuring code. It is intended as a more robust replacement for Ginkgo V1's Measure nodes. + +gmeasure is organized around the metaphor of an Experiment that can record multiple Measurements. A Measurement is a named collection of data points and gmeasure supports +measuring Values (of type float64) and Durations (of type time.Duration). + +Experiments allows the user to record Measurements directly by passing in Values (i.e. float64) or Durations (i.e. time.Duration) +or to measure measurements by passing in functions to measure. When measuring functions Experiments take care of timing the duration of functions (for Duration measurements) +and/or recording returned values (for Value measurements). Experiments also support sampling functions - when told to sample Experiments will run functions repeatedly +and measure and record results. The sampling behavior is configured by passing in a SamplingConfig that can control the maximum number of samples, the maximum duration for sampling (or both) +and the number of concurrent samples to take. + +Measurements can be decorated with additional information. This is supported by passing in special typed decorators when recording measurements. These include: + +- Units("any string") - to attach units to a Value Measurement (Duration Measurements always have units of "duration") +- Style("any Ginkgo color style string") - to attach styling to a Measurement. This styling is used when rendering console information about the measurement in reports. Color style strings are documented at TODO. +- Precision(integer or time.Duration) - to attach precision to a Measurement. This controls how many decimal places to show for Value Measurements and how to round Duration Measurements when rendering them to screen. + +In addition, individual data points in a Measurement can be annotated with an Annotation("any string"). The annotation is associated with the individual data point and is intended to convey additional context about the data point. + +Once measurements are complete, an Experiment can generate a comprehensive report by calling its String() or ColorableString() method. + +Users can also access and analyze the resulting Measurements directly. Use Experiment.Get(NAME) to fetch the Measurement named NAME. This returned struct will have fields containing +all the data points and annotations recorded by the experiment. You can subsequently fetch the Measurement.Stats() to get a Stats struct that contains basic statistical information about the +Measurement (min, max, median, mean, standard deviation). You can order these Stats objects using RankStats() to identify best/worst performers across multpile experiments or measurements. + +gmeasure also supports caching Experiments via an ExperimentCache. The cache supports storing and retreiving experiments by name and version. This allows you to rerun code without +repeating expensive experiments that may not have changed (which can be controlled by the cache version number). It also enables you to compare new experiment runs with older runs to detect +variations in performance/behavior. + +When used with Ginkgo, you can emit experiment reports and encode them in test reports easily using Ginkgo V2's support for Report Entries. +Simply pass your experiment to AddReportEntry to get a report every time the tests run. You can also use AddReportEntry with Measurements to emit all the captured data +and Rankings to emit measurement summaries in rank order. + +Finally, Experiments provide an additional mechanism to measure durations called a Stopwatch. The Stopwatch makes it easy to pepper code with statements that measure elapsed time across +different sections of code and can be useful when debugging or evaluating bottlenecks in a given codepath. +*/ +package gmeasure + +import ( + "fmt" + "math" + "reflect" + "sync" + "time" + + "github.com/onsi/gomega/gmeasure/table" +) + +/* +SamplingConfig configures the Sample family of experiment methods. +These methods invoke passed-in functions repeatedly to sample and record a given measurement. +SamplingConfig is used to control the maximum number of samples or time spent sampling (or both). When both are specified sampling ends as soon as one of the conditions is met. +SamplingConfig can also ensure a minimum interval between samples and can enable concurrent sampling. +*/ +type SamplingConfig struct { + // N - the maximum number of samples to record + N int + // Duration - the maximum amount of time to spend recording samples + Duration time.Duration + // MinSamplingInterval - the minimum time that must elapse between samplings. It is an error to specify both MinSamplingInterval and NumParallel. + MinSamplingInterval time.Duration + // NumParallel - the number of parallel workers to spin up to record samples. It is an error to specify both MinSamplingInterval and NumParallel. + NumParallel int +} + +// The Units decorator allows you to specify units (an arbitrary string) when recording values. It is ignored when recording durations. +// +// e := gmeasure.NewExperiment("My Experiment") +// e.RecordValue("length", 3.141, gmeasure.Units("inches")) +// +// Units are only set the first time a value of a given name is recorded. In the example above any subsequent calls to e.RecordValue("length", X) will maintain the "inches" units even if a new set of Units("UNIT") are passed in later. +type Units string + +// The Annotation decorator allows you to attach an annotation to a given recorded data-point: +// +// For example: +// +// e := gmeasure.NewExperiment("My Experiment") +// e.RecordValue("length", 3.141, gmeasure.Annotation("bob")) +// e.RecordValue("length", 2.71, gmeasure.Annotation("jane")) +// +// ...will result in a Measurement named "length" that records two values )[3.141, 2.71]) annotation with (["bob", "jane"]) +type Annotation string + +// The Style decorator allows you to associate a style with a measurement. This is used to generate colorful console reports using Ginkgo V2's +// console formatter. Styles are strings in curly brackets that correspond to a color or style. +// +// For example: +// +// e := gmeasure.NewExperiment("My Experiment") +// e.RecordValue("length", 3.141, gmeasure.Style("{{blue}}{{bold}}")) +// e.RecordValue("length", 2.71) +// e.RecordDuration("cooking time", 3 * time.Second, gmeasure.Style("{{red}}{{underline}}")) +// e.RecordDuration("cooking time", 2 * time.Second) +// +// will emit a report with blue bold entries for the length measurement and red underlined entries for the cooking time measurement. +// +// Units are only set the first time a value or duration of a given name is recorded. In the example above any subsequent calls to e.RecordValue("length", X) will maintain the "{{blue}}{{bold}}" style even if a new Style is passed in later. +type Style string + +// The PrecisionBundle decorator controls the rounding of value and duration measurements. See Precision(). +type PrecisionBundle struct { + Duration time.Duration + ValueFormat string +} + +// Precision() allows you to specify the precision of a value or duration measurement - this precision is used when rendering the measurement to screen. +// +// To control the precision of Value measurements, pass Precision an integer. This will denote the number of decimal places to render (equivalen to the format string "%.Nf") +// To control the precision of Duration measurements, pass Precision a time.Duration. Duration measurements will be rounded oo the nearest time.Duration when rendered. +// +// For example: +// +// e := gmeasure.NewExperiment("My Experiment") +// e.RecordValue("length", 3.141, gmeasure.Precision(2)) +// e.RecordValue("length", 2.71) +// e.RecordDuration("cooking time", 3214 * time.Millisecond, gmeasure.Precision(100*time.Millisecond)) +// e.RecordDuration("cooking time", 2623 * time.Millisecond) +func Precision(p interface{}) PrecisionBundle { + out := DefaultPrecisionBundle + switch reflect.TypeOf(p) { + case reflect.TypeOf(time.Duration(0)): + out.Duration = p.(time.Duration) + case reflect.TypeOf(int(0)): + out.ValueFormat = fmt.Sprintf("%%.%df", p.(int)) + default: + panic("invalid precision type, must be time.Duration or int") + } + return out +} + +// DefaultPrecisionBundle captures the default precisions for Vale and Duration measurements. +var DefaultPrecisionBundle = PrecisionBundle{ + Duration: 100 * time.Microsecond, + ValueFormat: "%.3f", +} + +type extractedDecorations struct { + annotation Annotation + units Units + precisionBundle PrecisionBundle + style Style +} + +func extractDecorations(args []interface{}) extractedDecorations { + var out extractedDecorations + out.precisionBundle = DefaultPrecisionBundle + + for _, arg := range args { + switch reflect.TypeOf(arg) { + case reflect.TypeOf(out.annotation): + out.annotation = arg.(Annotation) + case reflect.TypeOf(out.units): + out.units = arg.(Units) + case reflect.TypeOf(out.precisionBundle): + out.precisionBundle = arg.(PrecisionBundle) + case reflect.TypeOf(out.style): + out.style = arg.(Style) + default: + panic(fmt.Sprintf("unrecognized argument %#v", arg)) + } + } + + return out +} + +/* +Experiment is gmeasure's core data type. You use experiments to record Measurements and generate reports. +Experiments are thread-safe and all methods can be called from multiple goroutines. +*/ +type Experiment struct { + Name string + + // Measurements includes all Measurements recorded by this experiment. You should access them by name via Get() and GetStats() + Measurements Measurements + lock *sync.Mutex +} + +/* +NexExperiment creates a new experiment with the passed-in name. + +When using Ginkgo we recommend immediately registering the experiment as a ReportEntry: + + experiment = NewExperiment("My Experiment") + AddReportEntry(experiment.Name, experiment) + +this will ensure an experiment report is emitted as part of the test output and exported with any test reports. +*/ +func NewExperiment(name string) *Experiment { + experiment := &Experiment{ + Name: name, + lock: &sync.Mutex{}, + } + return experiment +} + +func (e *Experiment) report(enableStyling bool) string { + t := table.NewTable() + t.TableStyle.EnableTextStyling = enableStyling + t.AppendRow(table.R( + table.C("Name"), table.C("N"), table.C("Min"), table.C("Median"), table.C("Mean"), table.C("StdDev"), table.C("Max"), + table.Divider("="), + "{{bold}}", + )) + + for _, measurement := range e.Measurements { + r := table.R(measurement.Style) + t.AppendRow(r) + switch measurement.Type { + case MeasurementTypeNote: + r.AppendCell(table.C(measurement.Note)) + case MeasurementTypeValue, MeasurementTypeDuration: + name := measurement.Name + if measurement.Units != "" { + name += " [" + measurement.Units + "]" + } + r.AppendCell(table.C(name)) + r.AppendCell(measurement.Stats().cells()...) + } + } + + out := e.Name + "\n" + if enableStyling { + out = "{{bold}}" + out + "{{/}}" + } + out += t.Render() + return out +} + +/* +ColorableString returns a Ginkgo formatted summary of the experiment and all its Measurements. +It is called automatically by Ginkgo's reporting infrastructure when the Experiment is registered as a ReportEntry via AddReportEntry. +*/ +func (e *Experiment) ColorableString() string { + return e.report(true) +} + +/* +ColorableString returns an unformatted summary of the experiment and all its Measurements. +*/ +func (e *Experiment) String() string { + return e.report(false) +} + +/* +RecordNote records a Measurement of type MeasurementTypeNote - this is simply a textual note to annotate the experiment. It will be emitted in any experiment reports. + +RecordNote supports the Style() decoration. +*/ +func (e *Experiment) RecordNote(note string, args ...interface{}) { + decorations := extractDecorations(args) + + e.lock.Lock() + defer e.lock.Unlock() + e.Measurements = append(e.Measurements, Measurement{ + ExperimentName: e.Name, + Type: MeasurementTypeNote, + Note: note, + Style: string(decorations.style), + }) +} + +/* +RecordDuration records the passed-in duration on a Duration Measurement with the passed-in name. If the Measurement does not exist it is created. + +RecordDuration supports the Style(), Precision(), and Annotation() decorations. +*/ +func (e *Experiment) RecordDuration(name string, duration time.Duration, args ...interface{}) { + decorations := extractDecorations(args) + e.recordDuration(name, duration, decorations) +} + +/* +MeasureDuration runs the passed-in callback and times how long it takes to complete. The resulting duration is recorded on a Duration Measurement with the passed-in name. If the Measurement does not exist it is created. + +MeasureDuration supports the Style(), Precision(), and Annotation() decorations. +*/ +func (e *Experiment) MeasureDuration(name string, callback func(), args ...interface{}) time.Duration { + t := time.Now() + callback() + duration := time.Since(t) + e.RecordDuration(name, duration, args...) + return duration +} + +/* +SampleDuration samples the passed-in callback and times how long it takes to complete each sample. +The resulting durations are recorded on a Duration Measurement with the passed-in name. If the Measurement does not exist it is created. + +The callback is given a zero-based index that increments by one between samples. The Sampling is configured via the passed-in SamplingConfig + +SampleDuration supports the Style(), Precision(), and Annotation() decorations. When passed an Annotation() the same annotation is applied to all sample measurements. +*/ +func (e *Experiment) SampleDuration(name string, callback func(idx int), samplingConfig SamplingConfig, args ...interface{}) { + decorations := extractDecorations(args) + e.Sample(func(idx int) { + t := time.Now() + callback(idx) + duration := time.Since(t) + e.recordDuration(name, duration, decorations) + }, samplingConfig) +} + +/* +SampleDuration samples the passed-in callback and times how long it takes to complete each sample. +The resulting durations are recorded on a Duration Measurement with the passed-in name. If the Measurement does not exist it is created. + +The callback is given a zero-based index that increments by one between samples. The callback must return an Annotation - this annotation is attached to the measured duration. + +The Sampling is configured via the passed-in SamplingConfig + +SampleAnnotatedDuration supports the Style() and Precision() decorations. +*/ +func (e *Experiment) SampleAnnotatedDuration(name string, callback func(idx int) Annotation, samplingConfig SamplingConfig, args ...interface{}) { + decorations := extractDecorations(args) + e.Sample(func(idx int) { + t := time.Now() + decorations.annotation = callback(idx) + duration := time.Since(t) + e.recordDuration(name, duration, decorations) + }, samplingConfig) +} + +func (e *Experiment) recordDuration(name string, duration time.Duration, decorations extractedDecorations) { + e.lock.Lock() + defer e.lock.Unlock() + idx := e.Measurements.IdxWithName(name) + if idx == -1 { + measurement := Measurement{ + ExperimentName: e.Name, + Type: MeasurementTypeDuration, + Name: name, + Units: "duration", + Durations: []time.Duration{duration}, + PrecisionBundle: decorations.precisionBundle, + Style: string(decorations.style), + Annotations: []string{string(decorations.annotation)}, + } + e.Measurements = append(e.Measurements, measurement) + } else { + if e.Measurements[idx].Type != MeasurementTypeDuration { + panic(fmt.Sprintf("attempting to record duration with name '%s'. That name is already in-use for recording values.", name)) + } + e.Measurements[idx].Durations = append(e.Measurements[idx].Durations, duration) + e.Measurements[idx].Annotations = append(e.Measurements[idx].Annotations, string(decorations.annotation)) + } +} + +/* +NewStopwatch() returns a stopwatch configured to record duration measurements with this experiment. +*/ +func (e *Experiment) NewStopwatch() *Stopwatch { + return newStopwatch(e) +} + +/* +RecordValue records the passed-in value on a Value Measurement with the passed-in name. If the Measurement does not exist it is created. + +RecordValue supports the Style(), Units(), Precision(), and Annotation() decorations. +*/ +func (e *Experiment) RecordValue(name string, value float64, args ...interface{}) { + decorations := extractDecorations(args) + e.recordValue(name, value, decorations) +} + +/* +MeasureValue runs the passed-in callback and records the return value on a Value Measurement with the passed-in name. If the Measurement does not exist it is created. + +MeasureValue supports the Style(), Units(), Precision(), and Annotation() decorations. +*/ +func (e *Experiment) MeasureValue(name string, callback func() float64, args ...interface{}) float64 { + value := callback() + e.RecordValue(name, value, args...) + return value +} + +/* +SampleValue samples the passed-in callback and records the return value on a Value Measurement with the passed-in name. If the Measurement does not exist it is created. + +The callback is given a zero-based index that increments by one between samples. The callback must return a float64. The Sampling is configured via the passed-in SamplingConfig + +SampleValue supports the Style(), Units(), Precision(), and Annotation() decorations. When passed an Annotation() the same annotation is applied to all sample measurements. +*/ +func (e *Experiment) SampleValue(name string, callback func(idx int) float64, samplingConfig SamplingConfig, args ...interface{}) { + decorations := extractDecorations(args) + e.Sample(func(idx int) { + value := callback(idx) + e.recordValue(name, value, decorations) + }, samplingConfig) +} + +/* +SampleAnnotatedValue samples the passed-in callback and records the return value on a Value Measurement with the passed-in name. If the Measurement does not exist it is created. + +The callback is given a zero-based index that increments by one between samples. The callback must return a float64 and an Annotation - the annotation is attached to the recorded value. + +The Sampling is configured via the passed-in SamplingConfig + +SampleValue supports the Style(), Units(), and Precision() decorations. +*/ +func (e *Experiment) SampleAnnotatedValue(name string, callback func(idx int) (float64, Annotation), samplingConfig SamplingConfig, args ...interface{}) { + decorations := extractDecorations(args) + e.Sample(func(idx int) { + var value float64 + value, decorations.annotation = callback(idx) + e.recordValue(name, value, decorations) + }, samplingConfig) +} + +func (e *Experiment) recordValue(name string, value float64, decorations extractedDecorations) { + e.lock.Lock() + defer e.lock.Unlock() + idx := e.Measurements.IdxWithName(name) + if idx == -1 { + measurement := Measurement{ + ExperimentName: e.Name, + Type: MeasurementTypeValue, + Name: name, + Style: string(decorations.style), + Units: string(decorations.units), + PrecisionBundle: decorations.precisionBundle, + Values: []float64{value}, + Annotations: []string{string(decorations.annotation)}, + } + e.Measurements = append(e.Measurements, measurement) + } else { + if e.Measurements[idx].Type != MeasurementTypeValue { + panic(fmt.Sprintf("attempting to record value with name '%s'. That name is already in-use for recording durations.", name)) + } + e.Measurements[idx].Values = append(e.Measurements[idx].Values, value) + e.Measurements[idx].Annotations = append(e.Measurements[idx].Annotations, string(decorations.annotation)) + } +} + +/* +Sample samples the passed-in callback repeatedly. The sampling is governed by the passed in SamplingConfig. + +The SamplingConfig can limit the total number of samples and/or the total time spent sampling the callback. +The SamplingConfig can also instruct Sample to run with multiple concurrent workers. + +The callback is called with a zero-based index that incerements by one between samples. +*/ +func (e *Experiment) Sample(callback func(idx int), samplingConfig SamplingConfig) { + if samplingConfig.N == 0 && samplingConfig.Duration == 0 { + panic("you must specify at least one of SamplingConfig.N and SamplingConfig.Duration") + } + if samplingConfig.MinSamplingInterval > 0 && samplingConfig.NumParallel > 1 { + panic("you cannot specify both SamplingConfig.MinSamplingInterval and SamplingConfig.NumParallel") + } + maxTime := time.Now().Add(100000 * time.Hour) + if samplingConfig.Duration > 0 { + maxTime = time.Now().Add(samplingConfig.Duration) + } + maxN := math.MaxInt32 + if samplingConfig.N > 0 { + maxN = samplingConfig.N + } + numParallel := 1 + if samplingConfig.NumParallel > numParallel { + numParallel = samplingConfig.NumParallel + } + minSamplingInterval := samplingConfig.MinSamplingInterval + + work := make(chan int) + defer close(work) + if numParallel > 1 { + for worker := 0; worker < numParallel; worker++ { + go func() { + for idx := range work { + callback(idx) + } + }() + } + } + + idx := 0 + var avgDt time.Duration + for { + t := time.Now() + if numParallel > 1 { + work <- idx + } else { + callback(idx) + } + dt := time.Since(t) + if numParallel == 1 && dt < minSamplingInterval { + time.Sleep(minSamplingInterval - dt) + dt = time.Since(t) + } + if idx >= numParallel { + avgDt = (avgDt*time.Duration(idx-numParallel) + dt) / time.Duration(idx-numParallel+1) + } + idx += 1 + if idx >= maxN { + return + } + if time.Now().Add(avgDt).After(maxTime) { + return + } + } +} + +/* +Get returns the Measurement with the associated name. If no Measurement is found a zero Measurement{} is returned. +*/ +func (e *Experiment) Get(name string) Measurement { + e.lock.Lock() + defer e.lock.Unlock() + idx := e.Measurements.IdxWithName(name) + if idx == -1 { + return Measurement{} + } + return e.Measurements[idx] +} + +/* +GetStats returns the Stats for the Measurement with the associated name. If no Measurement is found a zero Stats{} is returned. + +experiment.GetStats(name) is equivalent to experiment.Get(name).Stats() +*/ +func (e *Experiment) GetStats(name string) Stats { + measurement := e.Get(name) + e.lock.Lock() + defer e.lock.Unlock() + return measurement.Stats() +} diff --git a/vendor/github.com/onsi/gomega/gmeasure/measurement.go b/vendor/github.com/onsi/gomega/gmeasure/measurement.go new file mode 100644 index 00000000000..103d3ea9d06 --- /dev/null +++ b/vendor/github.com/onsi/gomega/gmeasure/measurement.go @@ -0,0 +1,235 @@ +package gmeasure + +import ( + "fmt" + "math" + "sort" + "time" + + "github.com/onsi/gomega/gmeasure/table" +) + +type MeasurementType uint + +const ( + MeasurementTypeInvalid MeasurementType = iota + MeasurementTypeNote + MeasurementTypeDuration + MeasurementTypeValue +) + +var letEnumSupport = newEnumSupport(map[uint]string{uint(MeasurementTypeInvalid): "INVALID LOG ENTRY TYPE", uint(MeasurementTypeNote): "Note", uint(MeasurementTypeDuration): "Duration", uint(MeasurementTypeValue): "Value"}) + +func (s MeasurementType) String() string { return letEnumSupport.String(uint(s)) } +func (s *MeasurementType) UnmarshalJSON(b []byte) error { + out, err := letEnumSupport.UnmarshJSON(b) + *s = MeasurementType(out) + return err +} +func (s MeasurementType) MarshalJSON() ([]byte, error) { return letEnumSupport.MarshJSON(uint(s)) } + +/* +Measurement records all captured data for a given measurement. You generally don't make Measurements directly - but you can fetch them from Experiments using Get(). + +When using Ginkgo, you can register Measurements as Report Entries via AddReportEntry. This will emit all the captured data points when Ginkgo generates the report. +*/ +type Measurement struct { + // Type is the MeasurementType - one of MeasurementTypeNote, MeasurementTypeDuration, or MeasurementTypeValue + Type MeasurementType + + // ExperimentName is the name of the experiment that this Measurement is associated with + ExperimentName string + + // If Type is MeasurementTypeNote, Note is populated with the note text. + Note string + + // If Type is MeasurementTypeDuration or MeasurementTypeValue, Name is the name of the recorded measurement + Name string + + // Style captures the styling information (if any) for this Measurement + Style string + + // Units capture the units (if any) for this Measurement. Units is set to "duration" if the Type is MeasurementTypeDuration + Units string + + // PrecisionBundle captures the precision to use when rendering data for this Measurement. + // If Type is MeasurementTypeDuration then PrecisionBundle.Duration is used to round any durations before presentation. + // If Type is MeasurementTypeValue then PrecisionBundle.ValueFormat is used to format any values before presentation + PrecisionBundle PrecisionBundle + + // If Type is MeasurementTypeDuration, Durations will contain all durations recorded for this measurement + Durations []time.Duration + + // If Type is MeasurementTypeValue, Values will contain all float64s recorded for this measurement + Values []float64 + + // If Type is MeasurementTypeDuration or MeasurementTypeValue then Annotations will include string annotations for all recorded Durations or Values. + // If the user does not pass-in an Annotation() decoration for a particular value or duration, the corresponding entry in the Annotations slice will be the empty string "" + Annotations []string +} + +type Measurements []Measurement + +func (m Measurements) IdxWithName(name string) int { + for idx, measurement := range m { + if measurement.Name == name { + return idx + } + } + + return -1 +} + +func (m Measurement) report(enableStyling bool) string { + out := "" + style := m.Style + if !enableStyling { + style = "" + } + switch m.Type { + case MeasurementTypeNote: + out += fmt.Sprintf("%s - Note\n%s\n", m.ExperimentName, m.Note) + if style != "" { + out = style + out + "{{/}}" + } + return out + case MeasurementTypeValue, MeasurementTypeDuration: + out += fmt.Sprintf("%s - %s", m.ExperimentName, m.Name) + if m.Units != "" { + out += " [" + m.Units + "]" + } + if style != "" { + out = style + out + "{{/}}" + } + out += "\n" + out += m.Stats().String() + "\n" + } + t := table.NewTable() + t.TableStyle.EnableTextStyling = enableStyling + switch m.Type { + case MeasurementTypeValue: + t.AppendRow(table.R(table.C("Value", table.AlignTypeCenter), table.C("Annotation", table.AlignTypeCenter), table.Divider("="), style)) + for idx := range m.Values { + t.AppendRow(table.R( + table.C(fmt.Sprintf(m.PrecisionBundle.ValueFormat, m.Values[idx]), table.AlignTypeRight), + table.C(m.Annotations[idx], "{{gray}}", table.AlignTypeLeft), + )) + } + case MeasurementTypeDuration: + t.AppendRow(table.R(table.C("Duration", table.AlignTypeCenter), table.C("Annotation", table.AlignTypeCenter), table.Divider("="), style)) + for idx := range m.Durations { + t.AppendRow(table.R( + table.C(m.Durations[idx].Round(m.PrecisionBundle.Duration).String(), style, table.AlignTypeRight), + table.C(m.Annotations[idx], "{{gray}}", table.AlignTypeLeft), + )) + } + } + out += t.Render() + return out +} + +/* +ColorableString generates a styled report that includes all the data points for this Measurement. +It is called automatically by Ginkgo's reporting infrastructure when the Measurement is registered as a ReportEntry via AddReportEntry. +*/ +func (m Measurement) ColorableString() string { + return m.report(true) +} + +/* +String generates an unstyled report that includes all the data points for this Measurement. +*/ +func (m Measurement) String() string { + return m.report(false) +} + +/* +Stats returns a Stats struct summarizing the statistic of this measurement +*/ +func (m Measurement) Stats() Stats { + if m.Type == MeasurementTypeInvalid || m.Type == MeasurementTypeNote { + return Stats{} + } + + out := Stats{ + ExperimentName: m.ExperimentName, + MeasurementName: m.Name, + Style: m.Style, + Units: m.Units, + PrecisionBundle: m.PrecisionBundle, + } + + switch m.Type { + case MeasurementTypeValue: + out.Type = StatsTypeValue + out.N = len(m.Values) + if out.N == 0 { + return out + } + indices, sum := make([]int, len(m.Values)), 0.0 + for idx, v := range m.Values { + indices[idx] = idx + sum += v + } + sort.Slice(indices, func(i, j int) bool { + return m.Values[indices[i]] < m.Values[indices[j]] + }) + out.ValueBundle = map[Stat]float64{ + StatMin: m.Values[indices[0]], + StatMax: m.Values[indices[out.N-1]], + StatMean: sum / float64(out.N), + StatStdDev: 0.0, + } + out.AnnotationBundle = map[Stat]string{ + StatMin: m.Annotations[indices[0]], + StatMax: m.Annotations[indices[out.N-1]], + } + + if out.N%2 == 0 { + out.ValueBundle[StatMedian] = (m.Values[indices[out.N/2]] + m.Values[indices[out.N/2-1]]) / 2.0 + } else { + out.ValueBundle[StatMedian] = m.Values[indices[(out.N-1)/2]] + } + + for _, v := range m.Values { + out.ValueBundle[StatStdDev] += (v - out.ValueBundle[StatMean]) * (v - out.ValueBundle[StatMean]) + } + out.ValueBundle[StatStdDev] = math.Sqrt(out.ValueBundle[StatStdDev] / float64(out.N)) + case MeasurementTypeDuration: + out.Type = StatsTypeDuration + out.N = len(m.Durations) + if out.N == 0 { + return out + } + indices, sum := make([]int, len(m.Durations)), time.Duration(0) + for idx, v := range m.Durations { + indices[idx] = idx + sum += v + } + sort.Slice(indices, func(i, j int) bool { + return m.Durations[indices[i]] < m.Durations[indices[j]] + }) + out.DurationBundle = map[Stat]time.Duration{ + StatMin: m.Durations[indices[0]], + StatMax: m.Durations[indices[out.N-1]], + StatMean: sum / time.Duration(out.N), + } + out.AnnotationBundle = map[Stat]string{ + StatMin: m.Annotations[indices[0]], + StatMax: m.Annotations[indices[out.N-1]], + } + + if out.N%2 == 0 { + out.DurationBundle[StatMedian] = (m.Durations[indices[out.N/2]] + m.Durations[indices[out.N/2-1]]) / 2 + } else { + out.DurationBundle[StatMedian] = m.Durations[indices[(out.N-1)/2]] + } + stdDev := 0.0 + for _, v := range m.Durations { + stdDev += float64(v-out.DurationBundle[StatMean]) * float64(v-out.DurationBundle[StatMean]) + } + out.DurationBundle[StatStdDev] = time.Duration(math.Sqrt(stdDev / float64(out.N))) + } + + return out +} diff --git a/vendor/github.com/onsi/gomega/gmeasure/rank.go b/vendor/github.com/onsi/gomega/gmeasure/rank.go new file mode 100644 index 00000000000..1544cd8f4de --- /dev/null +++ b/vendor/github.com/onsi/gomega/gmeasure/rank.go @@ -0,0 +1,141 @@ +package gmeasure + +import ( + "fmt" + "sort" + + "github.com/onsi/gomega/gmeasure/table" +) + +/* +RankingCriteria is an enum representing the criteria by which Stats should be ranked. The enum names should be self explanatory. e.g. LowerMeanIsBetter means that Stats with lower mean values are considered more beneficial, with the lowest mean being declared the "winner" . +*/ +type RankingCriteria uint + +const ( + LowerMeanIsBetter RankingCriteria = iota + HigherMeanIsBetter + LowerMedianIsBetter + HigherMedianIsBetter + LowerMinIsBetter + HigherMinIsBetter + LowerMaxIsBetter + HigherMaxIsBetter +) + +var rcEnumSupport = newEnumSupport(map[uint]string{uint(LowerMeanIsBetter): "Lower Mean is Better", uint(HigherMeanIsBetter): "Higher Mean is Better", uint(LowerMedianIsBetter): "Lower Median is Better", uint(HigherMedianIsBetter): "Higher Median is Better", uint(LowerMinIsBetter): "Lower Mins is Better", uint(HigherMinIsBetter): "Higher Min is Better", uint(LowerMaxIsBetter): "Lower Max is Better", uint(HigherMaxIsBetter): "Higher Max is Better"}) + +func (s RankingCriteria) String() string { return rcEnumSupport.String(uint(s)) } +func (s *RankingCriteria) UnmarshalJSON(b []byte) error { + out, err := rcEnumSupport.UnmarshJSON(b) + *s = RankingCriteria(out) + return err +} +func (s RankingCriteria) MarshalJSON() ([]byte, error) { return rcEnumSupport.MarshJSON(uint(s)) } + +/* +Ranking ranks a set of Stats by a specified RankingCritera. Use RankStats to create a Ranking. + +When using Ginkgo, you can register Rankings as Report Entries via AddReportEntry. This will emit a formatted table representing the Stats in rank-order when Ginkgo generates the report. +*/ +type Ranking struct { + Criteria RankingCriteria + Stats []Stats +} + +/* +RankStats creates a new ranking of the passed-in stats according to the passed-in criteria. +*/ +func RankStats(criteria RankingCriteria, stats ...Stats) Ranking { + sort.Slice(stats, func(i int, j int) bool { + switch criteria { + case LowerMeanIsBetter: + return stats[i].FloatFor(StatMean) < stats[j].FloatFor(StatMean) + case HigherMeanIsBetter: + return stats[i].FloatFor(StatMean) > stats[j].FloatFor(StatMean) + case LowerMedianIsBetter: + return stats[i].FloatFor(StatMedian) < stats[j].FloatFor(StatMedian) + case HigherMedianIsBetter: + return stats[i].FloatFor(StatMedian) > stats[j].FloatFor(StatMedian) + case LowerMinIsBetter: + return stats[i].FloatFor(StatMin) < stats[j].FloatFor(StatMin) + case HigherMinIsBetter: + return stats[i].FloatFor(StatMin) > stats[j].FloatFor(StatMin) + case LowerMaxIsBetter: + return stats[i].FloatFor(StatMax) < stats[j].FloatFor(StatMax) + case HigherMaxIsBetter: + return stats[i].FloatFor(StatMax) > stats[j].FloatFor(StatMax) + } + return false + }) + + out := Ranking{ + Criteria: criteria, + Stats: stats, + } + + return out +} + +/* +Winner returns the Stats with the most optimal rank based on the specified ranking criteria. For example, if the RankingCriteria is LowerMaxIsBetter then the Stats with the lowest value or duration for StatMax will be returned as the "winner" +*/ +func (c Ranking) Winner() Stats { + if len(c.Stats) == 0 { + return Stats{} + } + return c.Stats[0] +} + +func (c Ranking) report(enableStyling bool) string { + if len(c.Stats) == 0 { + return "Empty Ranking" + } + t := table.NewTable() + t.TableStyle.EnableTextStyling = enableStyling + t.AppendRow(table.R( + table.C("Experiment"), table.C("Name"), table.C("N"), table.C("Min"), table.C("Median"), table.C("Mean"), table.C("StdDev"), table.C("Max"), + table.Divider("="), + "{{bold}}", + )) + + for idx, stats := range c.Stats { + name := stats.MeasurementName + if stats.Units != "" { + name = name + " [" + stats.Units + "]" + } + experimentName := stats.ExperimentName + style := stats.Style + if idx == 0 { + style = "{{bold}}" + style + name += "\n*Winner*" + experimentName += "\n*Winner*" + } + r := table.R(style) + t.AppendRow(r) + r.AppendCell(table.C(experimentName), table.C(name)) + r.AppendCell(stats.cells()...) + + } + out := fmt.Sprintf("Ranking Criteria: %s\n", c.Criteria) + if enableStyling { + out = "{{bold}}" + out + "{{/}}" + } + out += t.Render() + return out +} + +/* +ColorableString generates a styled report that includes a table of the rank-ordered Stats +It is called automatically by Ginkgo's reporting infrastructure when the Ranking is registered as a ReportEntry via AddReportEntry. +*/ +func (c Ranking) ColorableString() string { + return c.report(true) +} + +/* +String generates an unstyled report that includes a table of the rank-ordered Stats +*/ +func (c Ranking) String() string { + return c.report(false) +} diff --git a/vendor/github.com/onsi/gomega/gmeasure/stats.go b/vendor/github.com/onsi/gomega/gmeasure/stats.go new file mode 100644 index 00000000000..8c02e1bdf1f --- /dev/null +++ b/vendor/github.com/onsi/gomega/gmeasure/stats.go @@ -0,0 +1,153 @@ +package gmeasure + +import ( + "fmt" + "time" + + "github.com/onsi/gomega/gmeasure/table" +) + +/* +Stat is an enum representing the statistics you can request of a Stats struct +*/ +type Stat uint + +const ( + StatInvalid Stat = iota + StatMin + StatMax + StatMean + StatMedian + StatStdDev +) + +var statEnumSupport = newEnumSupport(map[uint]string{uint(StatInvalid): "INVALID STAT", uint(StatMin): "Min", uint(StatMax): "Max", uint(StatMean): "Mean", uint(StatMedian): "Median", uint(StatStdDev): "StdDev"}) + +func (s Stat) String() string { return statEnumSupport.String(uint(s)) } +func (s *Stat) UnmarshalJSON(b []byte) error { + out, err := statEnumSupport.UnmarshJSON(b) + *s = Stat(out) + return err +} +func (s Stat) MarshalJSON() ([]byte, error) { return statEnumSupport.MarshJSON(uint(s)) } + +type StatsType uint + +const ( + StatsTypeInvalid StatsType = iota + StatsTypeValue + StatsTypeDuration +) + +var statsTypeEnumSupport = newEnumSupport(map[uint]string{uint(StatsTypeInvalid): "INVALID STATS TYPE", uint(StatsTypeValue): "StatsTypeValue", uint(StatsTypeDuration): "StatsTypeDuration"}) + +func (s StatsType) String() string { return statsTypeEnumSupport.String(uint(s)) } +func (s *StatsType) UnmarshalJSON(b []byte) error { + out, err := statsTypeEnumSupport.UnmarshJSON(b) + *s = StatsType(out) + return err +} +func (s StatsType) MarshalJSON() ([]byte, error) { return statsTypeEnumSupport.MarshJSON(uint(s)) } + +/* +Stats records the key statistics for a given measurement. You generally don't make Stats directly - but you can fetch them from Experiments using GetStats() and from Measurements using Stats(). + +When using Ginkgo, you can register Measurements as Report Entries via AddReportEntry. This will emit all the captured data points when Ginkgo generates the report. +*/ +type Stats struct { + // Type is the StatType - one of StatTypeDuration or StatTypeValue + Type StatsType + + // ExperimentName is the name of the Experiment that recorded the Measurement from which this Stat is derived + ExperimentName string + + // MeasurementName is the name of the Measurement from which this Stat is derived + MeasurementName string + + // Units captures the Units of the Measurement from which this Stat is derived + Units string + + // Style captures the Style of the Measurement from which this Stat is derived + Style string + + // PrecisionBundle captures the precision to use when rendering data for this Measurement. + // If Type is StatTypeDuration then PrecisionBundle.Duration is used to round any durations before presentation. + // If Type is StatTypeValue then PrecisionBundle.ValueFormat is used to format any values before presentation + PrecisionBundle PrecisionBundle + + // N represents the total number of data points in the Meassurement from which this Stat is derived + N int + + // If Type is StatTypeValue, ValueBundle will be populated with float64s representing this Stat's statistics + ValueBundle map[Stat]float64 + + // If Type is StatTypeDuration, DurationBundle will be populated with float64s representing this Stat's statistics + DurationBundle map[Stat]time.Duration + + // AnnotationBundle is populated with Annotations corresponding to the data points that can be associated with a Stat. + // For example AnnotationBundle[StatMin] will return the Annotation for the data point that has the minimum value/duration. + AnnotationBundle map[Stat]string +} + +// String returns a minimal summary of the stats of the form "MIN < [MEDIAN] | ±STDDEV < MAX" +func (s Stats) String() string { + return fmt.Sprintf("%s < [%s] | <%s> ±%s < %s", s.StringFor(StatMin), s.StringFor(StatMedian), s.StringFor(StatMean), s.StringFor(StatStdDev), s.StringFor(StatMax)) +} + +// ValueFor returns the float64 value for a particular Stat. You should only use this if the Stats has Type StatsTypeValue +// For example: +// +// median := experiment.GetStats("length").ValueFor(gmeasure.StatMedian) +// +// will return the median data point for the "length" Measurement. +func (s Stats) ValueFor(stat Stat) float64 { + return s.ValueBundle[stat] +} + +// DurationFor returns the time.Duration for a particular Stat. You should only use this if the Stats has Type StatsTypeDuration +// For example: +// +// mean := experiment.GetStats("runtime").ValueFor(gmeasure.StatMean) +// +// will return the mean duration for the "runtime" Measurement. +func (s Stats) DurationFor(stat Stat) time.Duration { + return s.DurationBundle[stat] +} + +// FloatFor returns a float64 representation of the passed-in Stat. +// When Type is StatsTypeValue this is equivalent to s.ValueFor(stat). +// When Type is StatsTypeDuration this is equivalent to float64(s.DurationFor(stat)) +func (s Stats) FloatFor(stat Stat) float64 { + switch s.Type { + case StatsTypeValue: + return s.ValueFor(stat) + case StatsTypeDuration: + return float64(s.DurationFor(stat)) + } + return 0 +} + +// StringFor returns a formatted string representation of the passed-in Stat. +// The formatting honors the precision directives provided in stats.PrecisionBundle +func (s Stats) StringFor(stat Stat) string { + switch s.Type { + case StatsTypeValue: + return fmt.Sprintf(s.PrecisionBundle.ValueFormat, s.ValueFor(stat)) + case StatsTypeDuration: + return s.DurationFor(stat).Round(s.PrecisionBundle.Duration).String() + } + return "" +} + +func (s Stats) cells() []table.Cell { + out := []table.Cell{} + out = append(out, table.C(fmt.Sprintf("%d", s.N))) + for _, stat := range []Stat{StatMin, StatMedian, StatMean, StatStdDev, StatMax} { + content := s.StringFor(stat) + if s.AnnotationBundle[stat] != "" { + content += "\n" + s.AnnotationBundle[stat] + } + out = append(out, table.C(content)) + } + return out +} diff --git a/vendor/github.com/onsi/gomega/gmeasure/stopwatch.go b/vendor/github.com/onsi/gomega/gmeasure/stopwatch.go new file mode 100644 index 00000000000..634f11f2a46 --- /dev/null +++ b/vendor/github.com/onsi/gomega/gmeasure/stopwatch.go @@ -0,0 +1,117 @@ +package gmeasure + +import "time" + +/* +Stopwatch provides a convenient abstraction for recording durations. There are two ways to make a Stopwatch: + +You can make a Stopwatch from an Experiment via experiment.NewStopwatch(). This is how you first get a hold of a Stopwatch. + +You can subsequently call stopwatch.NewStopwatch() to get a fresh Stopwatch. +This is only necessary if you need to record durations on a different goroutine as a single Stopwatch is not considered thread-safe. + +The Stopwatch starts as soon as it is created. You can Pause() the stopwatch and Reset() it as needed. + +Stopwatches refer back to their parent Experiment. They use this reference to record any measured durations back with the Experiment. +*/ +type Stopwatch struct { + Experiment *Experiment + t time.Time + pauseT time.Time + pauseDuration time.Duration + running bool +} + +func newStopwatch(experiment *Experiment) *Stopwatch { + return &Stopwatch{ + Experiment: experiment, + t: time.Now(), + running: true, + } +} + +/* +NewStopwatch returns a new Stopwatch pointing to the same Experiment as this Stopwatch +*/ +func (s *Stopwatch) NewStopwatch() *Stopwatch { + return newStopwatch(s.Experiment) +} + +/* +Record captures the amount of time that has passed since the Stopwatch was created or most recently Reset(). It records the duration on it's associated Experiment in a Measurement with the passed-in name. + +Record takes all the decorators that experiment.RecordDuration takes (e.g. Annotation("...") can be used to annotate this duration) + +Note that Record does not Reset the Stopwatch. It does, however, return the Stopwatch so the following pattern is common: + + stopwatch := experiment.NewStopwatch() + // first expensive operation + stopwatch.Record("first operation").Reset() //records the duration of the first operation and resets the stopwatch. + // second expensive operation + stopwatch.Record("second operation").Reset() //records the duration of the second operation and resets the stopwatch. + +omitting the Reset() after the first operation would cause the duration recorded for the second operation to include the time elapsed by both the first _and_ second operations. + +The Stopwatch must be running (i.e. not paused) when Record is called. +*/ +func (s *Stopwatch) Record(name string, args ...interface{}) *Stopwatch { + if !s.running { + panic("stopwatch is not running - call Resume or Reset before calling Record") + } + duration := time.Since(s.t) - s.pauseDuration + s.Experiment.RecordDuration(name, duration, args...) + return s +} + +/* +Reset resets the Stopwatch. Subsequent recorded durations will measure the time elapsed from the moment Reset was called. +If the Stopwatch was Paused it is unpaused after calling Reset. +*/ +func (s *Stopwatch) Reset() *Stopwatch { + s.running = true + s.t = time.Now() + s.pauseDuration = 0 + return s +} + +/* +Pause pauses the Stopwatch. While pasued the Stopwatch does not accumulate elapsed time. This is useful for ignoring expensive operations that are incidental to the behavior you are attempting to characterize. +Note: You must call Resume() before you can Record() subsequent measurements. + +For example: + + stopwatch := experiment.NewStopwatch() + // first expensive operation + stopwatch.Record("first operation").Reset() + // second expensive operation - part 1 + stopwatch.Pause() + // something expensive that we don't care about + stopwatch.Resume() + // second expensive operation - part 2 + stopwatch.Record("second operation").Reset() // the recorded duration captures the time elapsed during parts 1 and 2 of the second expensive operation, but not the bit in between + + +The Stopwatch must be running when Pause is called. +*/ +func (s *Stopwatch) Pause() *Stopwatch { + if !s.running { + panic("stopwatch is not running - call Resume or Reset before calling Pause") + } + s.running = false + s.pauseT = time.Now() + return s +} + +/* +Resume resumes a paused Stopwatch. Any time that elapses after Resume is called will be accumulated as elapsed time when a subsequent duration is Recorded. + +The Stopwatch must be Paused when Resume is called +*/ +func (s *Stopwatch) Resume() *Stopwatch { + if s.running { + panic("stopwatch is running - call Pause before calling Resume") + } + s.running = true + s.pauseDuration = s.pauseDuration + time.Since(s.pauseT) + return s +} diff --git a/vendor/github.com/onsi/gomega/gmeasure/table/table.go b/vendor/github.com/onsi/gomega/gmeasure/table/table.go new file mode 100644 index 00000000000..f980b9c7aac --- /dev/null +++ b/vendor/github.com/onsi/gomega/gmeasure/table/table.go @@ -0,0 +1,370 @@ +package table + +// This is a temporary package - Table will move to github.com/onsi/consolable once some more dust settles + +import ( + "reflect" + "strings" + "unicode/utf8" +) + +type AlignType uint + +const ( + AlignTypeLeft AlignType = iota + AlignTypeCenter + AlignTypeRight +) + +type Divider string + +type Row struct { + Cells []Cell + Divider string + Style string +} + +func R(args ...interface{}) *Row { + r := &Row{ + Divider: "-", + } + for _, arg := range args { + switch reflect.TypeOf(arg) { + case reflect.TypeOf(Divider("")): + r.Divider = string(arg.(Divider)) + case reflect.TypeOf(r.Style): + r.Style = arg.(string) + case reflect.TypeOf(Cell{}): + r.Cells = append(r.Cells, arg.(Cell)) + } + } + return r +} + +func (r *Row) AppendCell(cells ...Cell) *Row { + r.Cells = append(r.Cells, cells...) + return r +} + +func (r *Row) Render(widths []int, totalWidth int, tableStyle TableStyle, isLastRow bool) string { + out := "" + if len(r.Cells) == 1 { + out += strings.Join(r.Cells[0].render(totalWidth, r.Style, tableStyle), "\n") + "\n" + } else { + if len(r.Cells) != len(widths) { + panic("row vs width mismatch") + } + renderedCells := make([][]string, len(r.Cells)) + maxHeight := 0 + for colIdx, cell := range r.Cells { + renderedCells[colIdx] = cell.render(widths[colIdx], r.Style, tableStyle) + if len(renderedCells[colIdx]) > maxHeight { + maxHeight = len(renderedCells[colIdx]) + } + } + for colIdx := range r.Cells { + for len(renderedCells[colIdx]) < maxHeight { + renderedCells[colIdx] = append(renderedCells[colIdx], strings.Repeat(" ", widths[colIdx])) + } + } + border := strings.Repeat(" ", tableStyle.Padding) + if tableStyle.VerticalBorders { + border += "|" + border + } + for lineIdx := 0; lineIdx < maxHeight; lineIdx++ { + for colIdx := range r.Cells { + out += renderedCells[colIdx][lineIdx] + if colIdx < len(r.Cells)-1 { + out += border + } + } + out += "\n" + } + } + if tableStyle.HorizontalBorders && !isLastRow && r.Divider != "" { + out += strings.Repeat(string(r.Divider), totalWidth) + "\n" + } + + return out +} + +type Cell struct { + Contents []string + Style string + Align AlignType +} + +func C(contents string, args ...interface{}) Cell { + c := Cell{ + Contents: strings.Split(contents, "\n"), + } + for _, arg := range args { + switch reflect.TypeOf(arg) { + case reflect.TypeOf(c.Style): + c.Style = arg.(string) + case reflect.TypeOf(c.Align): + c.Align = arg.(AlignType) + } + } + return c +} + +func (c Cell) Width() (int, int) { + w, minW := 0, 0 + for _, line := range c.Contents { + lineWidth := utf8.RuneCountInString(line) + if lineWidth > w { + w = lineWidth + } + for _, word := range strings.Split(line, " ") { + wordWidth := utf8.RuneCountInString(word) + if wordWidth > minW { + minW = wordWidth + } + } + } + return w, minW +} + +func (c Cell) alignLine(line string, width int) string { + lineWidth := utf8.RuneCountInString(line) + if lineWidth == width { + return line + } + if lineWidth < width { + gap := width - lineWidth + switch c.Align { + case AlignTypeLeft: + return line + strings.Repeat(" ", gap) + case AlignTypeRight: + return strings.Repeat(" ", gap) + line + case AlignTypeCenter: + leftGap := gap / 2 + rightGap := gap - leftGap + return strings.Repeat(" ", leftGap) + line + strings.Repeat(" ", rightGap) + } + } + return line +} + +func (c Cell) splitWordToWidth(word string, width int) []string { + out := []string{} + n, subWord := 0, "" + for _, c := range word { + subWord += string(c) + n += 1 + if n == width-1 { + out = append(out, subWord+"-") + n, subWord = 0, "" + } + } + return out +} + +func (c Cell) splitToWidth(line string, width int) []string { + lineWidth := utf8.RuneCountInString(line) + if lineWidth <= width { + return []string{line} + } + + outLines := []string{} + words := strings.Split(line, " ") + outWords := []string{words[0]} + length := utf8.RuneCountInString(words[0]) + if length > width { + splitWord := c.splitWordToWidth(words[0], width) + lastIdx := len(splitWord) - 1 + outLines = append(outLines, splitWord[:lastIdx]...) + outWords = []string{splitWord[lastIdx]} + length = utf8.RuneCountInString(splitWord[lastIdx]) + } + + for _, word := range words[1:] { + wordLength := utf8.RuneCountInString(word) + if length+wordLength+1 <= width { + length += wordLength + 1 + outWords = append(outWords, word) + continue + } + outLines = append(outLines, strings.Join(outWords, " ")) + + outWords = []string{word} + length = wordLength + if length > width { + splitWord := c.splitWordToWidth(word, width) + lastIdx := len(splitWord) - 1 + outLines = append(outLines, splitWord[:lastIdx]...) + outWords = []string{splitWord[lastIdx]} + length = utf8.RuneCountInString(splitWord[lastIdx]) + } + } + if len(outWords) > 0 { + outLines = append(outLines, strings.Join(outWords, " ")) + } + + return outLines +} + +func (c Cell) render(width int, style string, tableStyle TableStyle) []string { + out := []string{} + for _, line := range c.Contents { + out = append(out, c.splitToWidth(line, width)...) + } + for idx := range out { + out[idx] = c.alignLine(out[idx], width) + } + + if tableStyle.EnableTextStyling { + style = style + c.Style + if style != "" { + for idx := range out { + out[idx] = style + out[idx] + "{{/}}" + } + } + } + + return out +} + +type TableStyle struct { + Padding int + VerticalBorders bool + HorizontalBorders bool + MaxTableWidth int + MaxColWidth int + EnableTextStyling bool +} + +var DefaultTableStyle = TableStyle{ + Padding: 1, + VerticalBorders: true, + HorizontalBorders: true, + MaxTableWidth: 120, + MaxColWidth: 40, + EnableTextStyling: true, +} + +type Table struct { + Rows []*Row + + TableStyle TableStyle +} + +func NewTable() *Table { + return &Table{ + TableStyle: DefaultTableStyle, + } +} + +func (t *Table) AppendRow(row *Row) *Table { + t.Rows = append(t.Rows, row) + return t +} + +func (t *Table) Render() string { + out := "" + totalWidth, widths := t.computeWidths() + for rowIdx, row := range t.Rows { + out += row.Render(widths, totalWidth, t.TableStyle, rowIdx == len(t.Rows)-1) + } + return out +} + +func (t *Table) computeWidths() (int, []int) { + nCol := 0 + for _, row := range t.Rows { + if len(row.Cells) > nCol { + nCol = len(row.Cells) + } + } + + // lets compute the contribution to width from the borders + padding + borderWidth := t.TableStyle.Padding + if t.TableStyle.VerticalBorders { + borderWidth += 1 + t.TableStyle.Padding + } + totalBorderWidth := borderWidth * (nCol - 1) + + // lets compute the width of each column + widths := make([]int, nCol) + minWidths := make([]int, nCol) + for colIdx := range widths { + for _, row := range t.Rows { + if colIdx >= len(row.Cells) { + // ignore rows with fewer columns + continue + } + w, minWid := row.Cells[colIdx].Width() + if w > widths[colIdx] { + widths[colIdx] = w + } + if minWid > minWidths[colIdx] { + minWidths[colIdx] = minWid + } + } + } + + // do we already fit? + if sum(widths)+totalBorderWidth <= t.TableStyle.MaxTableWidth { + // yes! we're done + return sum(widths) + totalBorderWidth, widths + } + + // clamp the widths and minWidths to MaxColWidth + for colIdx := range widths { + widths[colIdx] = min(widths[colIdx], t.TableStyle.MaxColWidth) + minWidths[colIdx] = min(minWidths[colIdx], t.TableStyle.MaxColWidth) + } + + // do we fit now? + if sum(widths)+totalBorderWidth <= t.TableStyle.MaxTableWidth { + // yes! we're done + return sum(widths) + totalBorderWidth, widths + } + + // hmm... still no... can we possibly squeeze the table in without violating minWidths? + if sum(minWidths)+totalBorderWidth >= t.TableStyle.MaxTableWidth { + // nope - we're just going to have to exceed MaxTableWidth + return sum(minWidths) + totalBorderWidth, minWidths + } + + // looks like we don't fit yet, but we should be able to fit without violating minWidths + // lets start scaling down + n := 0 + for sum(widths)+totalBorderWidth > t.TableStyle.MaxTableWidth { + budget := t.TableStyle.MaxTableWidth - totalBorderWidth + baseline := sum(widths) + + for colIdx := range widths { + widths[colIdx] = max((widths[colIdx]*budget)/baseline, minWidths[colIdx]) + } + n += 1 + if n > 100 { + break // in case we somehow fail to converge + } + } + + return sum(widths) + totalBorderWidth, widths +} + +func sum(s []int) int { + out := 0 + for _, v := range s { + out += v + } + return out +} + +func min(a int, b int) int { + if a < b { + return a + } + return b +} + +func max(a int, b int) int { + if a > b { + return a + } + return b +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 14fd0a742e0..0724353683c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -220,7 +220,7 @@ github.com/hyperledger/fabric-amcl/amcl github.com/hyperledger/fabric-amcl/amcl/FP256BN github.com/hyperledger/fabric-amcl/core github.com/hyperledger/fabric-amcl/core/FP256BN -# github.com/hyperledger/fabric-chaincode-go/v2 v2.0.0 +# github.com/hyperledger/fabric-chaincode-go/v2 v2.0.0 => github.com/scientificideas/fabric-chaincode-go/v2 v2.0.0-20240917062040-734ea7e39c20 ## explicit; go 1.21.0 github.com/hyperledger/fabric-chaincode-go/v2/pkg/statebased github.com/hyperledger/fabric-chaincode-go/v2/shim @@ -260,7 +260,7 @@ github.com/hyperledger/fabric-lib-go/common/metrics/prometheus github.com/hyperledger/fabric-lib-go/common/metrics/statsd github.com/hyperledger/fabric-lib-go/common/metrics/statsd/goruntime github.com/hyperledger/fabric-lib-go/healthz -# github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3 +# github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3 => github.com/scientificideas/fabric-protos-go-apiv2 v0.0.0-20240917052027-e43d30d02e8c ## explicit; go 1.17 github.com/hyperledger/fabric-protos-go-apiv2/common github.com/hyperledger/fabric-protos-go-apiv2/discovery @@ -380,6 +380,8 @@ github.com/onsi/gomega github.com/onsi/gomega/format github.com/onsi/gomega/gbytes github.com/onsi/gomega/gexec +github.com/onsi/gomega/gmeasure +github.com/onsi/gomega/gmeasure/table github.com/onsi/gomega/gstruct github.com/onsi/gomega/gstruct/errors github.com/onsi/gomega/internal @@ -721,3 +723,5 @@ gopkg.in/yaml.v3 ## explicit; go 1.17 rsc.io/tmplfunc rsc.io/tmplfunc/internal/parse +# github.com/hyperledger/fabric-chaincode-go/v2 => github.com/scientificideas/fabric-chaincode-go/v2 v2.0.0-20240917062040-734ea7e39c20 +# github.com/hyperledger/fabric-protos-go-apiv2 => github.com/scientificideas/fabric-protos-go-apiv2 v0.0.0-20240917052027-e43d30d02e8c