Make the multi-value slice permanent (#15414)

* Remove Old State Paths

* Changelog

* Gazelle

* Lint

* Fix State Tests

* fix tests, update native state code

* move ErrOutOfBounds error from consensus types to mvslice

* fix TestStreamEvents_OperationsEvents

* add missing gc to fuzz tests

* more test fixes

* build fix

---------

Co-authored-by: nisdas <nishdas93@gmail.com>
This commit is contained in:
Radosław Kapka
2025-07-08 19:45:20 +02:00
committed by GitHub
parent 961ea05454
commit 7025e50a6c
38 changed files with 490 additions and 1707 deletions

View File

@@ -101,6 +101,9 @@ import (
// fragmented.
const fragmentationLimit = 50000
// ErrOutOfBounds happens when the provided index is higher than the largest index of the slice.
var ErrOutOfBounds = errors.New("out of bounds")
// Id is an object identifier.
type Id = uint64
@@ -255,7 +258,7 @@ func (s *Slice[V]) At(obj Identifiable, index uint64) (V, error) {
if index >= uint64(len(s.sharedItems)+len(s.appendedItems)) {
var def V
return def, fmt.Errorf("index %d out of bounds", index)
return def, fmt.Errorf("index %d %w", index, ErrOutOfBounds)
}
isOriginal := index < uint64(len(s.sharedItems))
@@ -282,7 +285,7 @@ func (s *Slice[V]) At(obj Identifiable, index uint64) (V, error) {
}
}
var def V
return def, fmt.Errorf("index %d out of bounds", index)
return def, fmt.Errorf("index %d %w", index, ErrOutOfBounds)
}
}
@@ -292,7 +295,7 @@ func (s *Slice[V]) UpdateAt(obj Identifiable, index uint64, val V) error {
defer s.lock.Unlock()
if index >= uint64(len(s.sharedItems)+len(s.appendedItems)) {
return fmt.Errorf("index %d out of bounds", index)
return fmt.Errorf("index %d %w", index, ErrOutOfBounds)
}
isOriginal := index < uint64(len(s.sharedItems))
@@ -560,7 +563,7 @@ func (s *Slice[V]) updateAppendedItem(obj Identifiable, index uint64, val V) err
}
}
if !found {
return fmt.Errorf("index %d out of bounds", index)
return fmt.Errorf("index %d %w", index, ErrOutOfBounds)
}
newValue := true
@@ -606,7 +609,7 @@ func (e EmptyMVSlice[V]) Len(_ Identifiable) int {
func (e EmptyMVSlice[V]) At(_ Identifiable, index uint64) (V, error) {
if index >= uint64(len(e.fullSlice)) {
var def V
return def, errors.Errorf("index %d out of bounds", index)
return def, fmt.Errorf("index %d %w", index, ErrOutOfBounds)
}
return e.fullSlice[index], nil
}

View File

@@ -476,6 +476,20 @@ func TestFragmentation_IndividualAndAppendedReferences(t *testing.T) {
assert.Equal(t, true, s.IsFragmented())
}
func TestNil(t *testing.T) {
obj := &testObject{}
s := &Slice[int]{}
s.Init(nil)
assert.Equal(t, 0, s.Len(obj))
assert.DeepEqual(t, []int{}, s.Value(obj))
_, err := s.At(obj, 0)
assert.NotNil(t, err)
s.Append(obj, 1)
assert.Equal(t, 1, s.Len(obj))
assert.DeepEqual(t, []int{1}, s.Value(obj))
}
// Share the slice between 2 objects.
// Index 0: Shared value
// Index 1: Different individual value