policy: Fix IteratorChainsByPrefix
#84
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-contract#84
Loading…
Reference in a new issue
No description provided.
Delete branch "aarifullin/frostfs-contract:fix/policy_map_key"
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?
Null/Integer
conversion when there were no chains yet.policy: Fixto WIP: policy: FixmapToNumeric
helpermapToNumeric
helperd412991452
to465d0b10f1
WIP: policy: Fixto policy: FixmapToNumeric
helpermapToNumeric
helperpolicy: Fixto policy: FixmapToNumeric
helperIteratorChainsByPrefix
@ -246,1 +246,3 @@
id, _ := mapToNumeric(ctx, entity, []byte(entityName))
id, mappingExists := mapToNumeric(ctx, entity, []byte(entityName))
if !mappingExists {
// All exising numeric mappings starts with 1. So, if id is set to 0, then
exising -> existing
Please fix commit message.
465d0b10f1
to4ab2e59333
@ -244,3 +244,3 @@
func IteratorChainsByPrefix(entity Kind, entityName string, prefix []byte) iterator.Iterator {
ctx := storage.GetReadOnlyContext()
id, _ := mapToNumeric(ctx, entity, []byte(entityName))
id, mappingExists := mapToNumeric(ctx, entity, []byte(entityName))
Why can we return
0
in the first place?Why can we return 0 from
mappingExists
in the first place?mappingExists
returns false, ifentityType + entityName
was never mapped.When we deploy contract
When we create a mapping
So, as you can see, all mappings start from
1
<-counter++
. Here I use0
to intentionally fail iteration: we suppose mapping to0
does not exist -> no chains for0
-> iteration over empty listAgain,
4ab2e59333/policy/policy_contract.go (L118)
here we could return0, false
explicitlyNull/Integer
conversion is most likely a bug in the compiler, explicit returns should fix this.Okay. Before, I did it like you said but then I concluded it is better to explain with a comment that iterating over
0
is fine.Yes. That's correct. So, it really makes sense to return changes to prevent occurring of this bug
I returned back the change (but made it
return 0, false
instead explicit assignment at the very beginning). Please, check this outWill be fixed, but not soon https://github.com/nspcc-dev/neo-go/pull/3401
4ab2e59333
to694daebb19