diff --git a/docs/fabric/fabricdev/core/fabricdev/vault/version.go b/docs/fabric/fabricdev/core/fabricdev/vault/version.go index 740d33566..86d60fcda 100644 --- a/docs/fabric/fabricdev/core/fabricdev/vault/version.go +++ b/docs/fabric/fabricdev/core/fabricdev/vault/version.go @@ -15,8 +15,6 @@ import ( "github.com/pkg/errors" ) -var zeroVersion = []byte{0, 0, 0, 0} - type CounterBasedVersionBuilder struct{} func (c *CounterBasedVersionBuilder) VersionedValues(rws *vault.ReadWriteSet, ns driver.Namespace, writes vault.NamespaceWrites, block driver.BlockNum, indexInBloc driver.TxNum) (map[driver.PKey]vault.VersionedValue, error) { @@ -72,16 +70,7 @@ func (c *CounterBasedVersionBuilder) VersionedMetaValues(rws *vault.ReadWriteSet type CounterBasedVersionComparator struct{} func (c *CounterBasedVersionComparator) Equal(v1, v2 driver.RawVersion) bool { - if bytes.Equal(v1, v2) { - return true - } - if len(v1) == 0 && bytes.Equal(zeroVersion, v2) { - return true - } - if len(v2) == 0 && bytes.Equal(zeroVersion, v1) { - return true - } - return false + return bytes.Equal(v1, v2) } func Marshal(v uint32) []byte { diff --git a/platform/common/core/generic/vault/vault.go b/platform/common/core/generic/vault/vault.go index bacf8da91..af97e558b 100644 --- a/platform/common/core/generic/vault/vault.go +++ b/platform/common/core/generic/vault/vault.go @@ -61,7 +61,7 @@ type NewInterceptorFunc[V driver.ValidationCode] func(logger Logger, qe Versione type ( VersionedPersistence = dbdriver.VersionedPersistence VersionedValue = dbdriver.VersionedValue - VersionedMetaData = dbdriver.VersionedMetaData + VersionedMetadataValue = dbdriver.VersionedMetadataValue VersionedRead = dbdriver.VersionedRead VersionedResultsIterator = dbdriver.VersionedResultsIterator QueryExecutor = dbdriver.QueryExecutor diff --git a/platform/common/driver/vault.go b/platform/common/driver/vault.go index 220593884..bf6d0fd7c 100644 --- a/platform/common/driver/vault.go +++ b/platform/common/driver/vault.go @@ -26,6 +26,11 @@ type VersionedRead struct { Version RawVersion } +type VersionedValue struct { + Raw RawValue + Version RawVersion +} + type VersionedMetadataValue struct { Version RawVersion Metadata Metadata diff --git a/platform/view/services/db/driver/badger/badger_test.go b/platform/view/services/db/driver/badger/badger_test.go index 4c01fce81..4757fe27c 100644 --- a/platform/view/services/db/driver/badger/badger_test.go +++ b/platform/view/services/db/driver/badger/badger_test.go @@ -18,7 +18,7 @@ import ( "github.com/dgraph-io/badger/v3" "github.com/golang/protobuf/proto" - driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver" + cdriver "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver" "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/dbtest" "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver" "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/badger/mock" @@ -290,26 +290,26 @@ func BenchmarkBuilder(b *testing.B) { type BlockTxIndexVersionMarshaller struct{} -func (m BlockTxIndexVersionMarshaller) FromBytes(data driver2.RawVersion) (driver2.BlockNum, driver2.TxNum, error) { +func (m BlockTxIndexVersionMarshaller) FromBytes(data cdriver.RawVersion) (cdriver.BlockNum, cdriver.TxNum, error) { if len(data) == 0 { return 0, 0, nil } if len(data) != 8 { return 0, 0, errors.Errorf("block number must be 8 bytes, but got %d", len(data)) } - Block := driver2.BlockNum(binary.BigEndian.Uint32(data[:4])) - TxNum := driver2.TxNum(binary.BigEndian.Uint32(data[4:])) + Block := cdriver.BlockNum(binary.BigEndian.Uint32(data[:4])) + TxNum := cdriver.TxNum(binary.BigEndian.Uint32(data[4:])) return Block, TxNum, nil } -func (m BlockTxIndexVersionMarshaller) ToBytes(bn driver2.BlockNum, txn driver2.TxNum) driver2.RawVersion { +func (m BlockTxIndexVersionMarshaller) ToBytes(bn cdriver.BlockNum, txn cdriver.TxNum) cdriver.RawVersion { return blockTxIndexToBytes(bn, txn) } -func blockTxIndexToBytes(Block driver2.BlockNum, TxNum driver2.TxNum) []byte { - buf := make([]byte, 8) - binary.BigEndian.PutUint32(buf[:4], uint32(Block)) - binary.BigEndian.PutUint32(buf[4:], uint32(TxNum)) +func blockTxIndexToBytes(block cdriver.BlockNum, txNum cdriver.TxNum) []byte { + buf := make([]byte, 16) + binary.BigEndian.PutUint64(buf[:8], block) + binary.BigEndian.PutUint64(buf[8:], txNum) return buf } diff --git a/platform/view/services/db/driver/driver.go b/platform/view/services/db/driver/driver.go index c7a875918..0a6c9ba7d 100644 --- a/platform/view/services/db/driver/driver.go +++ b/platform/view/services/db/driver/driver.go @@ -21,15 +21,7 @@ var ( type SQLError = error -type VersionedValue struct { - Raw driver.RawValue - Version driver.RawVersion -} - -type VersionedMetaData struct { - Metadata driver.Metadata - Version driver.RawVersion -} +type VersionedValue = driver.VersionedValue type VersionedMetadataValue = driver.VersionedMetadataValue diff --git a/platform/view/services/db/driver/sql/common/versioned.go b/platform/view/services/db/driver/sql/common/versioned.go index 431467dca..12372d55d 100644 --- a/platform/view/services/db/driver/sql/common/versioned.go +++ b/platform/view/services/db/driver/sql/common/versioned.go @@ -132,8 +132,8 @@ func (db *VersionedPersistence) SetStateMetadatas(ns driver2.Namespace, kvs map[ func (db *VersionedPersistence) GetStateMetadata(namespace driver2.Namespace, key driver2.PKey) (driver2.Metadata, driver2.RawVersion, error) { var m []byte - var meta map[string][]byte - var kversion []byte + var meta driver2.Metadata + var kversion driver2.RawVersion query := fmt.Sprintf("SELECT metadata, kversion FROM %s WHERE ns = $1 AND pkey = $2", db.table) logger.Debug(query, namespace, key)