diff --git a/core/types/suave_structs.go b/core/types/suave_structs.go index c40fea7da..e5693f10d 100755 --- a/core/types/suave_structs.go +++ b/core/types/suave_structs.go @@ -1,5 +1,5 @@ // Code generated by suave/gen. DO NOT EDIT. -// Hash: c60f303834fbdbbd940aae7cb3679cf3755a25f7384f1052c20bf6c38d9a0451 +// Hash: 1b2183df3127caea5fb80668f8b8da537f196a37d0b32af0c0fbce70a6a1a651 package types import "github.com/ethereum/go-ethereum/common" @@ -27,7 +27,7 @@ type DataRecord struct { DecryptionCondition uint64 AllowedPeekers []common.Address AllowedStores []common.Address - Version string + Namespace string } type HttpRequest struct { diff --git a/core/vm/contracts_suave.go b/core/vm/contracts_suave.go index ed4160d8d..0094aafe5 100644 --- a/core/vm/contracts_suave.go +++ b/core/vm/contracts_suave.go @@ -89,13 +89,13 @@ func (b *suaveRuntime) confidentialRetrieve(dataId types.DataId, key string) ([] /* Data Record precompiles */ -func (b *suaveRuntime) newDataRecord(decryptionCondition uint64, allowedPeekers []common.Address, allowedStores []common.Address, RecordType string) (types.DataRecord, error) { +func (b *suaveRuntime) newDataRecord(decryptionCondition uint64, allowedPeekers []common.Address, allowedStores []common.Address, namespace string) (types.DataRecord, error) { record, err := b.suaveContext.Backend.ConfidentialStore.InitRecord(types.DataRecord{ Salt: suave.RandomDataRecordId(), DecryptionCondition: decryptionCondition, AllowedPeekers: allowedPeekers, AllowedStores: allowedStores, - Version: RecordType, // TODO : make generic + Namespace: namespace, // TODO : make generic }) if err != nil { return types.DataRecord{}, err @@ -105,7 +105,7 @@ func (b *suaveRuntime) newDataRecord(decryptionCondition uint64, allowedPeekers } func (b *suaveRuntime) fetchDataRecords(targetBlock uint64, namespace string) ([]types.DataRecord, error) { - records1 := b.suaveContext.Backend.ConfidentialStore.FetchRecordsByProtocolAndBlock(targetBlock, namespace) + records1 := b.suaveContext.Backend.ConfidentialStore.FetchRecordsByNamespaceAndBlock(targetBlock, namespace) records := make([]types.DataRecord, 0, len(records1)) for _, record := range records1 { diff --git a/core/vm/contracts_suave_eth.go b/core/vm/contracts_suave_eth.go index 5c95ee36b..0279199c1 100644 --- a/core/vm/contracts_suave_eth.go +++ b/core/vm/contracts_suave_eth.go @@ -142,7 +142,7 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, dataID type var mergedBundles []types.SBundle for _, record := range recordsToMerge { - switch record.Version { + switch record.Namespace { case "mevshare:v0:matchDataRecords": // fetch the matched ids and merge the bundle matchedBundleIdsBytes, err := b.suaveContext.Backend.ConfidentialStore.Retrieve(record.Id, buildEthBlockAddr, "mevshare:v0:mergedDataRecords") @@ -204,7 +204,7 @@ func (b *suaveRuntime) buildEthBlock(blockArgs types.BuildBlockArgs, dataID type } mergedBundles = append(mergedBundles, bundle) default: - return nil, nil, fmt.Errorf("unknown record version %s", record.Version) + return nil, nil, fmt.Errorf("unknown record version %s", record.Namespace) } } diff --git a/core/vm/contracts_suave_runtime_adapter.go b/core/vm/contracts_suave_runtime_adapter.go index 3463fd6bc..a9290136c 100644 --- a/core/vm/contracts_suave_runtime_adapter.go +++ b/core/vm/contracts_suave_runtime_adapter.go @@ -1,5 +1,5 @@ // Code generated by suave/gen. DO NOT EDIT. -// Hash: c60f303834fbdbbd940aae7cb3679cf3755a25f7384f1052c20bf6c38d9a0451 +// Hash: 1b2183df3127caea5fb80668f8b8da537f196a37d0b32af0c0fbce70a6a1a651 package vm import ( @@ -27,7 +27,7 @@ type SuaveRuntime interface { fetchDataRecords(cond uint64, namespace string) ([]types.DataRecord, error) fillMevShareBundle(dataId types.DataId) ([]byte, error) newBuilder() (string, error) - newDataRecord(decryptionCondition uint64, allowedPeekers []common.Address, allowedStores []common.Address, dataType string) (types.DataRecord, error) + newDataRecord(decryptionCondition uint64, allowedPeekers []common.Address, allowedStores []common.Address, namespace string) (types.DataRecord, error) signEthTransaction(txn []byte, chainId string, signingKey string) ([]byte, error) signMessage(digest []byte, signingKey string) ([]byte, error) simulateBundle(bundleData []byte) (uint64, error) @@ -527,19 +527,19 @@ func (b *SuaveRuntimeAdapter) newDataRecord(input []byte) (res []byte, err error decryptionCondition uint64 allowedPeekers []common.Address allowedStores []common.Address - dataType string + namespace string ) decryptionCondition = unpacked[0].(uint64) allowedPeekers = unpacked[1].([]common.Address) allowedStores = unpacked[2].([]common.Address) - dataType = unpacked[3].(string) + namespace = unpacked[3].(string) var ( dataRecord types.DataRecord ) - if dataRecord, err = b.impl.newDataRecord(decryptionCondition, allowedPeekers, allowedStores, dataType); err != nil { + if dataRecord, err = b.impl.newDataRecord(decryptionCondition, allowedPeekers, allowedStores, namespace); err != nil { return } diff --git a/core/vm/suave.go b/core/vm/suave.go index 1ab5a224d..f29c06476 100644 --- a/core/vm/suave.go +++ b/core/vm/suave.go @@ -21,7 +21,7 @@ type ConfidentialStore interface { Store(id suave.DataId, caller common.Address, key string, value []byte) (suave.DataRecord, error) Retrieve(record types.DataId, caller common.Address, key string) ([]byte, error) FetchRecordByID(suave.DataId) (suave.DataRecord, error) - FetchRecordsByProtocolAndBlock(blockNumber uint64, namespace string) []suave.DataRecord + FetchRecordsByNamespaceAndBlock(blockNumber uint64, namespace string) []suave.DataRecord Finalize() error } diff --git a/suave/artifacts/SuaveLib.json b/suave/artifacts/SuaveLib.json index 577e67478..b00593788 100644 --- a/suave/artifacts/SuaveLib.json +++ b/suave/artifacts/SuaveLib.json @@ -1 +1 @@ -[{"type":"error","name":"PeekerReverted","inputs":[{"name":"addr","type":"address"},{"name":"err","type":"bytes"}]},{"type":"function","name":"buildEthBlock","inputs":[{"name":"blockArgs","type":"tuple","internalType":"struct Suave.BuildBlockArgs","components":[{"name":"slot","type":"uint64","internalType":"uint64"},{"name":"proposerPubkey","type":"bytes","internalType":"bytes"},{"name":"parent","type":"bytes32","internalType":"bytes32"},{"name":"timestamp","type":"uint64","internalType":"uint64"},{"name":"feeRecipient","type":"address","internalType":"address"},{"name":"gasLimit","type":"uint64","internalType":"uint64"},{"name":"random","type":"bytes32","internalType":"bytes32"},{"name":"withdrawals","type":"tuple[]","internalType":"struct Suave.Withdrawal[]","components":[{"name":"index","type":"uint64","internalType":"uint64"},{"name":"validator","type":"uint64","internalType":"uint64"},{"name":"Address","type":"address","internalType":"address"},{"name":"amount","type":"uint64","internalType":"uint64"}]},{"name":"extra","type":"bytes","internalType":"bytes"},{"name":"fillPending","type":"bool","internalType":"bool"}]},{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"blockBid","type":"bytes","internalType":"bytes"},{"name":"executionPayload","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialInputs","outputs":[{"name":"confindentialData","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialRetrieve","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"key","type":"string","internalType":"string"}],"outputs":[{"name":"value","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialStore","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"key","type":"string","internalType":"string"},{"name":"value","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"doHTTPRequest","inputs":[{"name":"request","type":"tuple","internalType":"struct Suave.HttpRequest","components":[{"name":"url","type":"string","internalType":"string"},{"name":"method","type":"string","internalType":"string"},{"name":"headers","type":"string[]","internalType":"string[]"},{"name":"body","type":"bytes","internalType":"bytes"},{"name":"withFlashbotsSignature","type":"bool","internalType":"bool"}]}],"outputs":[{"name":"httpResponse","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"ethcall","inputs":[{"name":"contractAddr","type":"address","internalType":"address"},{"name":"input1","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"callOutput","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"extractHint","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"hints","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"fetchDataRecords","inputs":[{"name":"cond","type":"uint64","internalType":"uint64"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"dataRecords","type":"tuple[]","internalType":"struct Suave.DataRecord[]","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"fillMevShareBundle","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"}],"outputs":[{"name":"encodedBundle","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"newBuilder","outputs":[{"name":"sessionid","type":"string","internalType":"string"}]},{"type":"function","name":"newDataRecord","inputs":[{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"dataType","type":"string","internalType":"string"}],"outputs":[{"name":"dataRecord","type":"tuple","internalType":"struct Suave.DataRecord","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"signEthTransaction","inputs":[{"name":"txn","type":"bytes","internalType":"bytes"},{"name":"chainId","type":"string","internalType":"string"},{"name":"signingKey","type":"string","internalType":"string"}],"outputs":[{"name":"signedTxn","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"signMessage","inputs":[{"name":"digest","type":"bytes","internalType":"bytes"},{"name":"signingKey","type":"string","internalType":"string"}],"outputs":[{"name":"signature","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"simulateBundle","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"effectiveGasPrice","type":"uint64","internalType":"uint64"}]},{"type":"function","name":"simulateTransaction","inputs":[{"name":"sessionid","type":"string","internalType":"string"},{"name":"txn","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"simulationResult","type":"tuple","internalType":"struct Suave.SimulateTransactionResult","components":[{"name":"egp","type":"uint64","internalType":"uint64"},{"name":"logs","type":"tuple[]","internalType":"struct Suave.SimulatedLog[]","components":[{"name":"data","type":"bytes","internalType":"bytes"},{"name":"addr","type":"address","internalType":"address"},{"name":"topics","type":"bytes32[]","internalType":"bytes32[]"}]},{"name":"success","type":"bool","internalType":"bool"},{"name":"error","type":"string","internalType":"string"}]}]},{"type":"function","name":"submitBundleJsonRPC","inputs":[{"name":"url","type":"string","internalType":"string"},{"name":"method","type":"string","internalType":"string"},{"name":"params","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"errorMessage","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"submitEthBlockToRelay","inputs":[{"name":"relayUrl","type":"string","internalType":"string"},{"name":"builderBid","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"blockBid","type":"bytes","internalType":"bytes"}]}] \ No newline at end of file +[{"type":"error","name":"PeekerReverted","inputs":[{"name":"addr","type":"address"},{"name":"err","type":"bytes"}]},{"type":"function","name":"buildEthBlock","inputs":[{"name":"blockArgs","type":"tuple","internalType":"struct Suave.BuildBlockArgs","components":[{"name":"slot","type":"uint64","internalType":"uint64"},{"name":"proposerPubkey","type":"bytes","internalType":"bytes"},{"name":"parent","type":"bytes32","internalType":"bytes32"},{"name":"timestamp","type":"uint64","internalType":"uint64"},{"name":"feeRecipient","type":"address","internalType":"address"},{"name":"gasLimit","type":"uint64","internalType":"uint64"},{"name":"random","type":"bytes32","internalType":"bytes32"},{"name":"withdrawals","type":"tuple[]","internalType":"struct Suave.Withdrawal[]","components":[{"name":"index","type":"uint64","internalType":"uint64"},{"name":"validator","type":"uint64","internalType":"uint64"},{"name":"Address","type":"address","internalType":"address"},{"name":"amount","type":"uint64","internalType":"uint64"}]},{"name":"extra","type":"bytes","internalType":"bytes"},{"name":"fillPending","type":"bool","internalType":"bool"}]},{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"blockBid","type":"bytes","internalType":"bytes"},{"name":"executionPayload","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialInputs","outputs":[{"name":"confindentialData","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialRetrieve","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"key","type":"string","internalType":"string"}],"outputs":[{"name":"value","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialStore","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"key","type":"string","internalType":"string"},{"name":"value","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"doHTTPRequest","inputs":[{"name":"request","type":"tuple","internalType":"struct Suave.HttpRequest","components":[{"name":"url","type":"string","internalType":"string"},{"name":"method","type":"string","internalType":"string"},{"name":"headers","type":"string[]","internalType":"string[]"},{"name":"body","type":"bytes","internalType":"bytes"},{"name":"withFlashbotsSignature","type":"bool","internalType":"bool"}]}],"outputs":[{"name":"httpResponse","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"ethcall","inputs":[{"name":"contractAddr","type":"address","internalType":"address"},{"name":"input1","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"callOutput","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"extractHint","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"hints","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"fetchDataRecords","inputs":[{"name":"cond","type":"uint64","internalType":"uint64"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"dataRecords","type":"tuple[]","internalType":"struct Suave.DataRecord[]","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"fillMevShareBundle","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"}],"outputs":[{"name":"encodedBundle","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"newBuilder","outputs":[{"name":"sessionid","type":"string","internalType":"string"}]},{"type":"function","name":"newDataRecord","inputs":[{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"dataRecord","type":"tuple","internalType":"struct Suave.DataRecord","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"signEthTransaction","inputs":[{"name":"txn","type":"bytes","internalType":"bytes"},{"name":"chainId","type":"string","internalType":"string"},{"name":"signingKey","type":"string","internalType":"string"}],"outputs":[{"name":"signedTxn","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"signMessage","inputs":[{"name":"digest","type":"bytes","internalType":"bytes"},{"name":"signingKey","type":"string","internalType":"string"}],"outputs":[{"name":"signature","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"simulateBundle","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"effectiveGasPrice","type":"uint64","internalType":"uint64"}]},{"type":"function","name":"simulateTransaction","inputs":[{"name":"sessionid","type":"string","internalType":"string"},{"name":"txn","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"simulationResult","type":"tuple","internalType":"struct Suave.SimulateTransactionResult","components":[{"name":"egp","type":"uint64","internalType":"uint64"},{"name":"logs","type":"tuple[]","internalType":"struct Suave.SimulatedLog[]","components":[{"name":"data","type":"bytes","internalType":"bytes"},{"name":"addr","type":"address","internalType":"address"},{"name":"topics","type":"bytes32[]","internalType":"bytes32[]"}]},{"name":"success","type":"bool","internalType":"bool"},{"name":"error","type":"string","internalType":"string"}]}]},{"type":"function","name":"submitBundleJsonRPC","inputs":[{"name":"url","type":"string","internalType":"string"},{"name":"method","type":"string","internalType":"string"},{"name":"params","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"errorMessage","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"submitEthBlockToRelay","inputs":[{"name":"relayUrl","type":"string","internalType":"string"},{"name":"builderBid","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"blockBid","type":"bytes","internalType":"bytes"}]}] \ No newline at end of file diff --git a/suave/artifacts/addresses.go b/suave/artifacts/addresses.go index f07051220..77396b983 100644 --- a/suave/artifacts/addresses.go +++ b/suave/artifacts/addresses.go @@ -1,5 +1,5 @@ // Code generated by suave/gen. DO NOT EDIT. -// Hash: c60f303834fbdbbd940aae7cb3679cf3755a25f7384f1052c20bf6c38d9a0451 +// Hash: 1b2183df3127caea5fb80668f8b8da537f196a37d0b32af0c0fbce70a6a1a651 package artifacts import ( diff --git a/suave/core/types.go b/suave/core/types.go index 98c8c602a..c070e8815 100644 --- a/suave/core/types.go +++ b/suave/core/types.go @@ -23,7 +23,7 @@ type DataRecord struct { DecryptionCondition uint64 AllowedPeekers []common.Address AllowedStores []common.Address - Version string + Namespace string CreationTx *types.Transaction Signature []byte } @@ -35,7 +35,7 @@ func (b *DataRecord) ToInnerRecord() types.DataRecord { DecryptionCondition: b.DecryptionCondition, AllowedPeekers: b.AllowedPeekers, AllowedStores: b.AllowedStores, - Version: b.Version, + Namespace: b.Namespace, } } diff --git a/suave/cstore/backend_testing.go b/suave/cstore/backend_testing.go index 9ab1ff7ef..263a87d25 100644 --- a/suave/cstore/backend_testing.go +++ b/suave/cstore/backend_testing.go @@ -13,7 +13,7 @@ func testBackendStore(t *testing.T, store ConfidentialStorageBackend) { Id: suave.RandomDataRecordId(), DecryptionCondition: 10, AllowedPeekers: []common.Address{common.HexToAddress("0x424344")}, - Version: "default:v0:ethBundles", + Namespace: "default:v0:ethBundles", } err := store.InitRecord(record) @@ -30,7 +30,7 @@ func testBackendStore(t *testing.T, store ConfidentialStorageBackend) { require.NoError(t, err) require.Equal(t, []byte{0x43, 0x14}, retrievedData) - records := store.FetchRecordsByProtocolAndBlock(10, "default:v0:ethBundles") + records := store.FetchRecordsByNamespaceAndBlock(10, "default:v0:ethBundles") require.Len(t, records, 1) require.Equal(t, record, records[0]) } diff --git a/suave/cstore/engine.go b/suave/cstore/engine.go index 64f26be24..6b2c44c3d 100644 --- a/suave/cstore/engine.go +++ b/suave/cstore/engine.go @@ -22,7 +22,7 @@ type ConfidentialStorageBackend interface { Store(record suave.DataRecord, caller common.Address, key string, value []byte) (suave.DataRecord, error) Retrieve(record suave.DataRecord, caller common.Address, key string) ([]byte, error) FetchRecordByID(suave.DataId) (suave.DataRecord, error) - FetchRecordsByProtocolAndBlock(blockNumber uint64, namespace string) []suave.DataRecord + FetchRecordsByNamespaceAndBlock(blockNumber uint64, namespace string) []suave.DataRecord Stop() error } @@ -191,7 +191,7 @@ func (e *CStoreEngine) InitRecord(record types.DataRecord, creationTx *types.Tra DecryptionCondition: record.DecryptionCondition, AllowedPeekers: record.AllowedPeekers, AllowedStores: record.AllowedStores, - Version: record.Version, + Namespace: record.Namespace, CreationTx: creationTx, } @@ -219,8 +219,8 @@ func (e *CStoreEngine) FetchRecordByID(id suave.DataId) (suave.DataRecord, error } // FetchRecordsByProtocolAndBlock fetches data records based on protocol and block number. -func (e *CStoreEngine) FetchRecordsByProtocolAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { - return e.storage.FetchRecordsByProtocolAndBlock(blockNumber, namespace) +func (e *CStoreEngine) FetchRecordsByNamespaceAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { + return e.storage.FetchRecordsByNamespaceAndBlock(blockNumber, namespace) } // Retrieve fetches data associated with a record. @@ -333,7 +333,7 @@ func (e *CStoreEngine) NewMessage(message DAMessage) error { DecryptionCondition: sw.DataRecord.DecryptionCondition, AllowedPeekers: sw.DataRecord.AllowedPeekers, AllowedStores: sw.DataRecord.AllowedStores, - Version: sw.DataRecord.Version, + Namespace: sw.DataRecord.Namespace, }) if err != nil { return fmt.Errorf("confidential engine: could not calculate received records id: %w", err) @@ -401,7 +401,7 @@ func SerializeDataRecord(record *suave.DataRecord) ([]byte, error) { DecryptionCondition: record.DecryptionCondition, AllowedPeekers: record.AllowedPeekers, AllowedStores: record.AllowedStores, - Version: record.Version, + Namespace: record.Namespace, CreationTx: record.CreationTx, }) if err != nil { diff --git a/suave/cstore/engine_test.go b/suave/cstore/engine_test.go index be9609d4b..924384395 100644 --- a/suave/cstore/engine_test.go +++ b/suave/cstore/engine_test.go @@ -48,7 +48,7 @@ func (*FakeStoreBackend) FetchRecordById(suave.DataId) (suave.DataRecord, error) return suave.DataRecord{}, nil } -func (*FakeStoreBackend) FetchRecordsByProtocolAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { +func (*FakeStoreBackend) FetchRecordsByNamespaceAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { return nil } diff --git a/suave/cstore/local_store_backend.go b/suave/cstore/local_store_backend.go index adbe3478f..db076c962 100644 --- a/suave/cstore/local_store_backend.go +++ b/suave/cstore/local_store_backend.go @@ -54,7 +54,7 @@ func (l *LocalConfidentialStore) InitRecord(record suave.DataRecord) error { l.records[record.Id] = record // index the record by (protocol, block number) - indexKey := fmt.Sprintf("protocol-%s-bn-%d", record.Version, record.DecryptionCondition) + indexKey := fmt.Sprintf("protocol-%s-bn-%d", record.Namespace, record.DecryptionCondition) recordIds := l.index[indexKey] recordIds = append(recordIds, record.Id) l.index[indexKey] = recordIds @@ -97,7 +97,7 @@ func (l *LocalConfidentialStore) FetchRecordByID(dataId suave.DataId) (suave.Dat return bid, nil } -func (l *LocalConfidentialStore) FetchRecordsByProtocolAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { +func (l *LocalConfidentialStore) FetchRecordsByNamespaceAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { l.lock.Lock() defer l.lock.Unlock() diff --git a/suave/cstore/pebble_store_backend.go b/suave/cstore/pebble_store_backend.go index becee0846..817b1848c 100644 --- a/suave/cstore/pebble_store_backend.go +++ b/suave/cstore/pebble_store_backend.go @@ -19,7 +19,7 @@ type PebbleStoreBackend struct { db *pebble.DB } -var recordByBlockAndProtocolIndexDbKey = func(blockNumber uint64, namespace string) []byte { +var recordByBlockAndNamespaceIndexDbKey = func(blockNumber uint64, namespace string) []byte { return []byte(fmt.Sprintf("records-block-%d-ns-%s", blockNumber, namespace)) } @@ -88,7 +88,7 @@ func (b *PebbleStoreBackend) InitRecord(record suave.DataRecord) error { // index update var currentValues recordByBlockAndProtocolIndexType - dbBlockProtoIndexKey := recordByBlockAndProtocolIndexDbKey(record.DecryptionCondition, record.Version) + dbBlockProtoIndexKey := recordByBlockAndNamespaceIndexDbKey(record.DecryptionCondition, record.Namespace) rawCurrentValues, closer, err := b.db.Get(dbBlockProtoIndexKey) if err != nil { if !errors.Is(err, pebble.ErrNotFound) { @@ -148,8 +148,8 @@ func (b *PebbleStoreBackend) Retrieve(record suave.DataRecord, caller common.Add return ret, nil } -func (b *PebbleStoreBackend) FetchRecordsByProtocolAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { - dbBlockProtoIndexKey := recordByBlockAndProtocolIndexDbKey(blockNumber, namespace) +func (b *PebbleStoreBackend) FetchRecordsByNamespaceAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { + dbBlockProtoIndexKey := recordByBlockAndNamespaceIndexDbKey(blockNumber, namespace) rawCurrentValues, closer, err := b.db.Get(dbBlockProtoIndexKey) if err != nil { return nil diff --git a/suave/cstore/redis_backends_test.go b/suave/cstore/redis_backends_test.go index 7a2cfa20d..310f93efd 100644 --- a/suave/cstore/redis_backends_test.go +++ b/suave/cstore/redis_backends_test.go @@ -30,7 +30,7 @@ func TestRedisTransport(t *testing.T) { Id: suave.DataId{0x42}, DecryptionCondition: uint64(13), AllowedPeekers: []common.Address{{0x41, 0x39}}, - Version: string("vv"), + Namespace: string("vv"), }, Value: suave.Bytes{}, }}, @@ -95,7 +95,7 @@ func TestEngineOnRedis(t *testing.T) { DecryptionCondition: uint64(13), AllowedPeekers: []common.Address{{0x41, 0x39}}, AllowedStores: []common.Address{{}}, - Version: string("vv"), + Namespace: string("vv"), }, dummyCreationTx) require.NoError(t, err) @@ -124,7 +124,7 @@ func TestEngineOnRedis(t *testing.T) { DecryptionCondition: record.DecryptionCondition, AllowedPeekers: record.AllowedPeekers, AllowedStores: record.AllowedStores, - Version: record.Version, + Namespace: record.Namespace, CreationTx: dummyCreationTx, } diff --git a/suave/cstore/redis_store_backend.go b/suave/cstore/redis_store_backend.go index d647fbd0e..1917ec738 100644 --- a/suave/cstore/redis_store_backend.go +++ b/suave/cstore/redis_store_backend.go @@ -172,19 +172,19 @@ func (r *RedisStoreBackend) indexRecord(record suave.DataRecord) error { defer log.Info("record submitted", "record", record, "store", r.Store) var recordsByBlockAndProtocol []suave.DataId - recordsByBlockAndProtocolBytes, err := r.Retrieve(mempoolConfidentialStoreRecord, mempoolConfStoreAddr, fmt.Sprintf("protocol-%s-bn-%d", record.Version, record.DecryptionCondition)) + recordsByBlockAndProtocolBytes, err := r.Retrieve(mempoolConfidentialStoreRecord, mempoolConfStoreAddr, fmt.Sprintf("protocol-%s-bn-%d", record.Namespace, record.DecryptionCondition)) if err == nil { recordsByBlockAndProtocol = suave.MustDecode[[]suave.DataId](recordsByBlockAndProtocolBytes) } // store record by block number and by protocol + block number recordsByBlockAndProtocol = append(recordsByBlockAndProtocol, record.Id) - r.Store(mempoolConfidentialStoreRecord, mempoolConfStoreAddr, fmt.Sprintf("protocol-%s-bn-%d", record.Version, record.DecryptionCondition), suave.MustEncode(recordsByBlockAndProtocol)) + r.Store(mempoolConfidentialStoreRecord, mempoolConfStoreAddr, fmt.Sprintf("protocol-%s-bn-%d", record.Namespace, record.DecryptionCondition), suave.MustEncode(recordsByBlockAndProtocol)) return nil } -func (r *RedisStoreBackend) FetchRecordsByProtocolAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { +func (r *RedisStoreBackend) FetchRecordsByNamespaceAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { recordsByProtocolBytes, err := r.Retrieve(mempoolConfidentialStoreRecord, mempoolConfStoreAddr, fmt.Sprintf("protocol-%s-bn-%d", namespace, blockNumber)) if err != nil { return nil diff --git a/suave/cstore/transactional_store.go b/suave/cstore/transactional_store.go index 4e0bfc088..805562aa3 100644 --- a/suave/cstore/transactional_store.go +++ b/suave/cstore/transactional_store.go @@ -33,13 +33,13 @@ func (s *TransactionalStore) FetchRecordByID(dataId suave.DataId) (suave.DataRec return s.engine.FetchRecordByID(dataId) } -func (s *TransactionalStore) FetchRecordsByProtocolAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { - records := s.engine.FetchRecordsByProtocolAndBlock(blockNumber, namespace) +func (s *TransactionalStore) FetchRecordsByNamespaceAndBlock(blockNumber uint64, namespace string) []suave.DataRecord { + records := s.engine.FetchRecordsByNamespaceAndBlock(blockNumber, namespace) s.pendingLock.Lock() defer s.pendingLock.Unlock() for _, record := range s.pendingRecords { - if record.Version == namespace && record.DecryptionCondition == blockNumber { + if record.Namespace == namespace && record.DecryptionCondition == blockNumber { records = append(records, record) } } diff --git a/suave/cstore/transactional_store_test.go b/suave/cstore/transactional_store_test.go index 1efb391b6..2bd3e61e3 100644 --- a/suave/cstore/transactional_store_test.go +++ b/suave/cstore/transactional_store_test.go @@ -29,7 +29,7 @@ func TestTransactionalStore(t *testing.T) { DecryptionCondition: 46, AllowedStores: []common.Address{{0x42}}, AllowedPeekers: []common.Address{{0x43}}, - Version: "v0-test", + Namespace: "v0-test", }) require.NoError(t, err) @@ -40,10 +40,10 @@ func TestTransactionalStore(t *testing.T) { require.NoError(t, err) require.Equal(t, testBid, tfetchedBid.ToInnerRecord()) - require.Empty(t, tstore.FetchRecordsByProtocolAndBlock(45, "v0-test")) - require.Empty(t, tstore.FetchRecordsByProtocolAndBlock(46, "v1-test")) + require.Empty(t, tstore.FetchRecordsByNamespaceAndBlock(45, "v0-test")) + require.Empty(t, tstore.FetchRecordsByNamespaceAndBlock(46, "v1-test")) - tfetchedBids := tstore.FetchRecordsByProtocolAndBlock(46, "v0-test") + tfetchedBids := tstore.FetchRecordsByNamespaceAndBlock(46, "v0-test") require.Equal(t, 1, len(tfetchedBids)) require.Equal(t, testBid, tfetchedBids[0].ToInnerRecord()) @@ -63,7 +63,7 @@ func TestTransactionalStore(t *testing.T) { // Not finalized, engine should return empty _, err = engine.FetchRecordByID(testBid.Id) require.Error(t, err) - require.Empty(t, engine.FetchRecordsByProtocolAndBlock(46, "v0-test")) + require.Empty(t, engine.FetchRecordsByNamespaceAndBlock(46, "v0-test")) _, err = engine.Retrieve(testBid.Id, testBid.AllowedPeekers[0], "xx") require.Error(t, err) @@ -73,7 +73,7 @@ func TestTransactionalStore(t *testing.T) { require.NoError(t, err) require.Equal(t, testBid, efetchedBid.ToInnerRecord()) - efetchedBids := engine.FetchRecordsByProtocolAndBlock(46, "v0-test") + efetchedBids := engine.FetchRecordsByNamespaceAndBlock(46, "v0-test") require.Equal(t, 1, len(efetchedBids)) require.Equal(t, testBid, efetchedBids[0].ToInnerRecord()) diff --git a/suave/e2e/workflow_test.go b/suave/e2e/workflow_test.go index 1f2b8c963..669e55332 100644 --- a/suave/e2e/workflow_test.go +++ b/suave/e2e/workflow_test.go @@ -144,7 +144,7 @@ func TestMempool(t *testing.T) { Salt: suave.RandomDataRecordId(), DecryptionCondition: targetBlock, AllowedPeekers: []common.Address{common.HexToAddress("0x424344")}, - Version: "default:v0:ethBundles", + Namespace: "default:v0:ethBundles", }, creationTx) require.NoError(t, err) @@ -153,7 +153,7 @@ func TestMempool(t *testing.T) { Salt: suave.RandomDataRecordId(), DecryptionCondition: targetBlock, AllowedPeekers: []common.Address{common.HexToAddress("0x424344")}, - Version: "default:v0:ethBundles", + Namespace: "default:v0:ethBundles", }, creationTx) require.NoError(t, err) @@ -184,13 +184,13 @@ func TestMempool(t *testing.T) { require.Equal(t, bid1.Salt, bids[0].Salt) require.Equal(t, bid1.DecryptionCondition, bids[0].DecryptionCondition) require.Equal(t, bid1.AllowedPeekers, bids[0].AllowedPeekers) - require.Equal(t, bid1.Version, bids[0].Version) + require.Equal(t, bid1.Namespace, bids[0].Namespace) require.Equal(t, bid2.Id, bids[1].Id) require.Equal(t, bid2.Salt, bids[1].Salt) require.Equal(t, bid2.DecryptionCondition, bids[1].DecryptionCondition) require.Equal(t, bid2.AllowedPeekers, bids[1].AllowedPeekers) - require.Equal(t, bid2.Version, bids[1].Version) + require.Equal(t, bid2.Namespace, bids[1].Namespace) // Verify via transaction confidentialRequestTx, err := types.SignTx(types.NewTx(&types.ConfidentialComputeRequest{ @@ -824,7 +824,7 @@ func TestBlockBuildingPrecompiles(t *testing.T) { DecryptionCondition: uint64(1), AllowedPeekers: []common.Address{suave.AllowedPeekerAny}, AllowedStores: []common.Address{fr.KettleAddress()}, - Version: "default:v0:ethBundles", + Namespace: "default:v0:ethBundles", }, dummyCreationTx) require.NoError(t, err) diff --git a/suave/gen/suave_spec.yaml b/suave/gen/suave_spec.yaml index 44c51247f..aaac8b28f 100644 --- a/suave/gen/suave_spec.yaml +++ b/suave/gen/suave_spec.yaml @@ -101,7 +101,7 @@ functions: - name: allowedStores type: address[] description: "Addresses can set data" - - name: dataType + - name: namespace type: string description: "Namespace of the data" output: diff --git a/suave/sol/libraries/Suave.sol b/suave/sol/libraries/Suave.sol index bcaf758bb..7b3a6848a 100644 --- a/suave/sol/libraries/Suave.sol +++ b/suave/sol/libraries/Suave.sol @@ -206,10 +206,10 @@ library Suave { uint64 decryptionCondition, address[] memory allowedPeekers, address[] memory allowedStores, - string memory dataType + string memory namespace ) internal view returns (DataRecord memory) { (bool success, bytes memory data) = - NEW_DATA_RECORD.staticcall(abi.encode(decryptionCondition, allowedPeekers, allowedStores, dataType)); + NEW_DATA_RECORD.staticcall(abi.encode(decryptionCondition, allowedPeekers, allowedStores, namespace)); if (!success) { revert PeekerReverted(NEW_DATA_RECORD, data); }