func addWriteSetToBatch(txRWSet *rwset.TxReadWriteSet, txHeight *version.Height, batch *statedb.UpdateBatch) { for _, nsRWSet := range txRWSet.NsRWs { ns := nsRWSet.NameSpace for _, kvWrite := range nsRWSet.Writes { if kvWrite.IsDelete { batch.Delete(ns, kvWrite.Key, txHeight) } else { batch.Put(ns, kvWrite.Key, kvWrite.Value, txHeight) } } } }
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 }