github.com/defanghe/fabric@v2.1.1+incompatible/core/common/validation/statebased/vpmanager.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package statebased 8 9 import ( 10 "fmt" 11 ) 12 13 // ValidationParameterUpdatedErr is returned whenever 14 // Validation Parameters for a key could not be 15 // supplied because they are being updated 16 type ValidationParameterUpdatedError struct { 17 CC string 18 Coll string 19 Key string 20 Height uint64 21 Txnum uint64 22 } 23 24 func (f *ValidationParameterUpdatedError) Error() string { 25 return fmt.Sprintf("validation parameters for key [%s] in namespace [%s:%s] have been changed in transaction %d of block %d", f.Key, f.CC, f.Coll, f.Txnum, f.Height) 26 } 27 28 // KeyLevelValidationParameterManager is used by validation plugins in order 29 // to retrieve validation parameters for individual KVS keys. 30 // The functions are supposed to be called in the following order: 31 // 1) the validation plugin called to validate a certain tx calls ExtractValidationParameterDependency 32 // in order for the manager to be able to determine whether validation parameters from the ledger 33 // can be used or whether they are being updated by a transaction in this block. 34 // 2) the validation plugin issues 0 or more calls to GetValidationParameterForKey. 35 // 3) the validation plugin determines the validation code for the tx and calls SetTxValidationCode. 36 type KeyLevelValidationParameterManager interface { 37 // GetValidationParameterForKey returns the validation parameter for the 38 // supplied KVS key identified by (cc, coll, key) at the specified block 39 // height h. The function returns the validation parameter and no error in case of 40 // success, or nil and an error otherwise. One particular error that may be 41 // returned is ValidationParameterUpdatedErr, which is returned in case the 42 // validation parameters for the given KVS key have been changed by a transaction 43 // with txNum smaller than the one supplied by the caller. This protects from a 44 // scenario where a transaction changing validation parameters is marked as valid 45 // by VSCC and is later invalidated by the committer for other reasons (e.g. MVCC 46 // conflicts). This function may be blocking until sufficient information has 47 // been passed (by calling ApplyRWSetUpdates and ApplyValidatedRWSetUpdates) for 48 // all txes with txNum smaller than the one supplied by the caller. 49 GetValidationParameterForKey(cc, coll, key string, blockNum, txNum uint64) ([]byte, error) 50 51 // ExtractValidationParameterDependency is used to determine which validation parameters are 52 // updated by transaction at height `blockNum, txNum`. This is needed 53 // to determine which txes have dependencies for specific validation parameters and will 54 // determine whether GetValidationParameterForKey may block. 55 ExtractValidationParameterDependency(blockNum, txNum uint64, rwset []byte) 56 57 // SetTxValidationResult sets the validation result for transaction at height 58 // `blockNum, txNum` for the specified chaincode `cc`. 59 // This is used to determine whether the dependencies set by 60 // ExtractValidationParameterDependency matter or not. 61 SetTxValidationResult(cc string, blockNum, txNum uint64, err error) 62 }