Example #1
0
func (txmgr *CouchDBTxMgr) validateTx(txRWSet *rwset.TxReadWriteSet) (bool, error) {

	var err error
	var currentVersion *version.Height

	for _, nsRWSet := range txRWSet.NsRWs {
		ns := nsRWSet.NameSpace
		for _, kvRead := range nsRWSet.Reads {
			compositeKey := constructCompositeKey(ns, kvRead.Key)
			if txmgr.updateSet != nil && txmgr.updateSet.exists(compositeKey) {
				return false, nil
			}
			if currentVersion, err = txmgr.getCommitedVersion(ns, kvRead.Key); err != nil {
				return false, err
			}
			if !version.AreSame(currentVersion, kvRead.Version) {
				logger.Debugf("Version mismatch for key [%s:%s]. Current version = [%d], Version in readSet [%d]",
					ns, kvRead.Key, currentVersion, kvRead.Version)
				return false, nil
			}
		}
	}
	return true, nil
}
func (v *Validator) validateTx(txRWSet *rwset.TxReadWriteSet, updates *statedb.UpdateBatch) (bool, error) {
	for _, nsRWSet := range txRWSet.NsRWs {
		ns := nsRWSet.NameSpace
		for _, kvRead := range nsRWSet.Reads {
			if updates.Exists(ns, kvRead.Key) {
				return false, nil
			}
			versionedValue, err := v.db.GetState(ns, kvRead.Key)
			if err != nil {
				return false, nil
			}
			var committedVersion *version.Height
			if versionedValue != nil {
				committedVersion = versionedValue.Version
			}
			if !version.AreSame(committedVersion, kvRead.Version) {
				logger.Debugf("Version mismatch for key [%s:%s]. Committed version = [%s], Version in readSet [%s]",
					ns, kvRead.Key, committedVersion, kvRead.Version)
				return false, nil
			}
		}
	}
	return true, nil
}