diff --git a/platform/common/core/generic/vault/vault.go b/platform/common/core/generic/vault/vault.go index 23a89f713..3b04466c4 100644 --- a/platform/common/core/generic/vault/vault.go +++ b/platform/common/core/generic/vault/vault.go @@ -409,7 +409,7 @@ func versionedValues(keyMap NamespaceWrites, block driver.BlockNum, indexInBloc func versionedMetaValues(keyMap KeyedMetaWrites, block driver.BlockNum, indexInBloc driver.TxNum) map[driver.PKey]driver.VersionedMetadataValue { vals := make(map[driver.PKey]driver.VersionedMetadataValue, len(keyMap)) for pkey, val := range keyMap { - vals[pkey] = driver.VersionedMetadataValue{Metadata: val, Block: block, TxNum: indexInBloc} + vals[pkey] = driver.VersionedMetadataValue{Metadata: val, Version: fver.ToBytes(block, indexInBloc)} } return vals } diff --git a/platform/common/driver/vault.go b/platform/common/driver/vault.go index f778238f0..220593884 100644 --- a/platform/common/driver/vault.go +++ b/platform/common/driver/vault.go @@ -26,14 +26,8 @@ type VersionedRead struct { Version RawVersion } -type VersionedMetadata struct { - Metadata Metadata - Version RawVersion -} - type VersionedMetadataValue struct { - Block BlockNum - TxNum TxNum + Version RawVersion Metadata Metadata } diff --git a/platform/view/services/db/driver/badger/badger.go b/platform/view/services/db/driver/badger/badger.go index 6649fcb29..53d26bc49 100644 --- a/platform/view/services/db/driver/badger/badger.go +++ b/platform/view/services/db/driver/badger/badger.go @@ -171,10 +171,10 @@ func (db *DB) SetStateMetadata(namespace driver2.Namespace, key driver2.PKey, me return nil } -func (db *DB) SetStateMetadatas(ns driver2.Namespace, kvs map[driver2.PKey]driver2.Metadata, version driver2.RawVersion) map[driver2.PKey]error { +func (db *DB) SetStateMetadatas(ns driver2.Namespace, kvs map[driver2.PKey]driver.VersionedMetadataValue) map[driver2.PKey]error { errs := make(map[driver2.PKey]error) for pkey, value := range kvs { - if err := db.SetStateMetadata(ns, pkey, value, version); err != nil { + if err := db.SetStateMetadata(ns, pkey, value.Metadata, value.Version); err != nil { errs[pkey] = err } } diff --git a/platform/view/services/db/driver/driver.go b/platform/view/services/db/driver/driver.go index e38d6dd5b..c7a875918 100644 --- a/platform/view/services/db/driver/driver.go +++ b/platform/view/services/db/driver/driver.go @@ -96,7 +96,7 @@ type VersionedPersistence interface { // SetStateMetadata sets the given metadata for the given namespace, key, and version SetStateMetadata(namespace driver.Namespace, key driver.PKey, metadata driver.Metadata, version driver.RawVersion) error // SetStateMetadatas sets the given metadata for the given namespace, keys, and version - SetStateMetadatas(ns driver.Namespace, kvs map[driver.PKey]driver.Metadata, version driver.RawVersion) map[driver.PKey]error + SetStateMetadatas(ns driver.Namespace, kvs map[driver.PKey]driver.VersionedMetadataValue) map[driver.PKey]error } type WriteTransaction interface { diff --git a/platform/view/services/db/driver/notifier/persistence.go b/platform/view/services/db/driver/notifier/persistence.go index c47808af2..9224acf7e 100644 --- a/platform/view/services/db/driver/notifier/persistence.go +++ b/platform/view/services/db/driver/notifier/persistence.go @@ -199,8 +199,8 @@ func (db *VersionedPersistenceNotifier[P]) SetStateMetadata(namespace driver2.Na return db.Persistence.SetStateMetadata(namespace, key, metadata, nil) } -func (db *VersionedPersistenceNotifier[P]) SetStateMetadatas(ns driver2.Namespace, kvs map[driver2.PKey]driver2.Metadata, version driver2.RawVersion) map[driver2.PKey]error { - return db.Persistence.SetStateMetadatas(ns, kvs, nil) +func (db *VersionedPersistenceNotifier[P]) SetStateMetadatas(ns driver2.Namespace, kvs map[driver2.PKey]driver2.VersionedMetadataValue) map[driver2.PKey]error { + return db.Persistence.SetStateMetadatas(ns, kvs) } func (db *VersionedPersistenceNotifier[P]) GetStateRangeScanIterator(namespace driver2.Namespace, startKey, endKey driver2.PKey) (driver.VersionedResultsIterator, error) { diff --git a/platform/view/services/db/driver/sql/common/versioned.go b/platform/view/services/db/driver/sql/common/versioned.go index c8e5c6d39..9c870e8f7 100644 --- a/platform/view/services/db/driver/sql/common/versioned.go +++ b/platform/view/services/db/driver/sql/common/versioned.go @@ -11,12 +11,10 @@ import ( "database/sql" "encoding/gob" "fmt" - "strings" "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors" driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver" "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver" - errors2 "github.com/pkg/errors" ) func NewVersionedReadScanner() *versionedReadScanner { return &versionedReadScanner{} } @@ -60,7 +58,7 @@ func (s *versionedMetadataValueScanner) Columns() []string { func (s *versionedMetadataValueScanner) ReadValue(txs scannable) (driver2.VersionedMetadataValue, error) { var r driver2.VersionedMetadataValue var metadata []byte - if err := txs.Scan(&metadata, &r.Block, &r.TxNum); err != nil { + if err := txs.Scan(&metadata, &r.Version); err != nil { return r, err } else if meta, err := unmarshalMetadata(metadata); err != nil { return r, fmt.Errorf("error decoding metadata: %w", err) @@ -75,7 +73,7 @@ func (s *versionedMetadataValueScanner) WriteValue(value driver2.VersionedMetada if err != nil { return nil, err } - return []any{metadata, value.Block, value.TxNum}, nil + return []any{metadata, value.Version}, nil } type basePersistence[V any, R any] interface { @@ -106,11 +104,14 @@ func NewVersioned(readDB *sql.DB, writeDB *sql.DB, table string, errorWrapper dr return NewVersionedPersistence(base, base.table, base.errorWrapper, base.readDB, base.writeDB) } -func (db *VersionedPersistence) SetStateMetadata(ns driver2.Namespace, key driver2.PKey, metadata driver2.Metadata, block driver2.BlockNum, txnum driver2.TxNum) error { +func (db *VersionedPersistence) SetStateMetadata(ns driver2.Namespace, key driver2.PKey, metadata driver2.Metadata, version driver2.RawVersion) error { if len(metadata) == 0 { return nil } - return db.SetStateMetadatas(ns, map[driver2.PKey]driver2.VersionedMetadataValue{key: {Block: block, TxNum: txnum, Metadata: metadata}})[key] + return db.SetStateMetadatas( + ns, + map[driver2.PKey]driver2.VersionedMetadataValue{key: {Version: version, Metadata: metadata}}, + )[key] } func (db *VersionedPersistence) SetStateMetadatas(ns driver2.Namespace, kvs map[driver2.PKey]driver2.VersionedMetadataValue) map[driver2.PKey]error { diff --git a/platform/view/services/db/driver/sql/postgres/versioned.go b/platform/view/services/db/driver/sql/postgres/versioned.go index bd39f0e33..ff92bbddb 100644 --- a/platform/view/services/db/driver/sql/postgres/versioned.go +++ b/platform/view/services/db/driver/sql/postgres/versioned.go @@ -83,8 +83,8 @@ func (db *VersionedPersistence) SetStateMetadata(namespace driver2.Namespace, ke return db.p.SetStateMetadata(namespace, key, metadata, nil) } -func (db *VersionedPersistence) SetStateMetadatas(ns driver2.Namespace, kvs map[driver2.PKey]driver2.Metadata, version driver2.RawVersion) map[driver2.PKey]error { - return db.p.SetStateMetadatas(ns, kvs, nil) +func (db *VersionedPersistence) SetStateMetadatas(ns driver2.Namespace, kvs map[driver2.PKey]driver2.VersionedMetadataValue) map[driver2.PKey]error { + return db.p.SetStateMetadatas(ns, kvs) } func (db *VersionedPersistence) CreateSchema() error {