policy: Shorten policy contract keys #71
No reviewers
Labels
No labels
P0
P1
P2
P3
good first issue
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
6 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-contract#71
Loading…
Reference in a new issue
No description provided.
Delete branch "aarifullin/frostfs-contract:feature/61-shorten_policy_keys"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Close #71
@ -89,0 +101,4 @@
// by AddChain invocation.
func mapToNumeric(ctx storage.Context, name []byte) []byte {
if len(name) <= maxAllowedEntityNameLength {
return name
I'm not sure that we can use plain
namespace
if its length is less than 8 bytes because it seems we can conflict with mapped one.Let's consider namespace with name
a
, it's []byte representation is[]byte{97}
, but we will get the same representation for 97 container that length is greater 8 as I can undersandYou're absolutely right. I haven't considered this collision. Alright, I'll remove this out then
Fixed. Since all names are mapped to numbers
@ -45,2 +50,4 @@
storage.Put(ctx, []byte{ownerKeyPrefix}, args.Admin)
}
storage.Put(ctx, counterKey, uint64(0))
Isn't
int
in contracts isuint64
anyway and we can skip conversion?I think you're right. I have replaced
uint64
byint
@ -82,3 +89,3 @@
func storageKey(prefix Kind, entityName string, name []byte) []byte {
func storageKey(prefix Kind, entityName, name []byte) []byte {
ln := len(entityName)
key := append([]byte{byte(prefix)}, byte(ln&0xFF), byte(ln>>8))
Shouldn't we simplify this to
key := append([]byte{byte(prefix)}, entityName...)
Appending
entityName
's length wasn't idea of mine (it has been introduced by @fyrchik), but I think it is fine because it helps to determine where a chain ID starts in a storage key.entityName
now always 8 bytes long. So we can save two bytes here if I understand it correctlyAlright. I've removed this append
598089d3da
to9f49a70d65
9f49a70d65
toe0c9e5848f
e0c9e5848f
toce7d6fed44
@ -89,0 +104,4 @@
return nil
}
mapped := numericID.(int)
return common.ToFixedWidth64(int(mapped))
Can be just
return common.ToFixedWidth64(mapped)
Fixed
ce7d6fed44
tofacd7e40fb
@ -83,3 +88,1 @@
ln := len(entityName)
key := append([]byte{byte(prefix)}, byte(ln&0xFF), byte(ln>>8))
key = append(key, entityName...)
// storageKey recieves fixed-length entityName. See: mapToNumeric, mapToNumericCreateIfNotExists.
Why not calculate this inside
storageKey()
The invariant is hard to enforce.
Otherwise, let's rename
entityName
parameter, it iscounter
now?mapToNumeric
could returnint
, this would solve all mentioned problems.You've asked
Because:
This method is also invoked by
GetChain
that yields read-only context. If we consider your suggestion, then it leads to a situation when we need to makestorageKey
to determine whether it can create mapping or not, i.e. write to the storage or not (storage.Put
) -> we need to pass two more params:ctx
andisReadOnlyCtx
: actually, I tried to avoid thisFusing these methods would look like that:
Are we okay with that?
Doesn't look nice either, but we could just move
common.ToFixedWidth64
invocation: so thatstorageKey
acceptsint
returned frommapToNumeric
.Alright. Since mapping methods return
int
andstorageKey
recievesint
facd7e40fb
toa8c75874a7