Skip to content

Commit

Permalink
Merge remote-tracking branch 'walldiss/fix-light-node-pruner' into fi…
Browse files Browse the repository at this point in the history
…x-light-node-pruner
  • Loading branch information
walldiss committed Jun 4, 2024
2 parents 750e1c1 + 75d6828 commit d2d325b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/grafana/otel-profiling-go v0.5.1
github.com/grafana/pyroscope-go v1.1.1
github.com/hashicorp/go-retryablehttp v0.7.6
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/imdario/mergo v0.3.16
github.com/ipfs/boxo v0.18.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.7.6 h1:TwRYfx2z2C4cLbXmT8I5PgP/xmuqASDyiVuGYfs9GZM=
github.com/hashicorp/go-retryablehttp v0.7.6/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
Expand Down
2 changes: 1 addition & 1 deletion share/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type NamespacedShares []NamespacedRow

// Flatten returns the concatenated slice of all NamespacedRow shares.
func (ns NamespacedShares) Flatten() []Share {
shares := make([]Share, 0)
var shares []Share
for _, row := range ns {
shares = append(shares, row.Shares...)
}
Expand Down
4 changes: 2 additions & 2 deletions share/getters/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestStoreGetter(t *testing.T) {
randNamespace := sharetest.RandV0Namespace()
emptyShares, err := sg.GetSharesByNamespace(ctx, eh, randNamespace)
require.NoError(t, err)
require.Empty(t, emptyShares.Flatten())
require.Nil(t, emptyShares.Flatten())

// root not found
emptyRoot := da.MinDataAvailabilityHeader()
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestIPLDGetter(t *testing.T) {
randNamespace := sharetest.RandV0Namespace()
emptyShares, err := sg.GetSharesByNamespace(ctx, eh, randNamespace)
require.NoError(t, err)
require.Empty(t, emptyShares.Flatten())
require.Nil(t, emptyShares.Flatten())

// nid doesn't exist in root
emptyRoot := da.MinDataAvailabilityHeader()
Expand Down
15 changes: 14 additions & 1 deletion share/getters/shrex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func TestShrexGetter(t *testing.T) {
Height: 1,
})

// namespace inside root range
nID, err := addToNamespace(maxNamespace, -1)
require.NoError(t, err)
// check for namespace to be between max and min namespace in root
Expand All @@ -118,7 +119,19 @@ func TestShrexGetter(t *testing.T) {
emptyShares, err := getter.GetSharesByNamespace(ctx, eh, nID)
require.NoError(t, err)
// no shares should be returned
require.Empty(t, emptyShares.Flatten())
require.Nil(t, emptyShares.Flatten())
require.Nil(t, emptyShares.Verify(dah, nID))

// namespace outside root range
nID, err = addToNamespace(maxNamespace, 1)
require.NoError(t, err)
// check for namespace to be not in root
require.Len(t, ipld.FilterRootByNamespace(dah, nID), 0)

emptyShares, err = getter.GetSharesByNamespace(ctx, eh, nID)
require.NoError(t, err)
// no shares should be returned
require.Nil(t, emptyShares.Flatten())
require.Nil(t, emptyShares.Verify(dah, nID))
})

Expand Down
5 changes: 4 additions & 1 deletion share/ipld/get_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ func GetSharesByNamespace(
}

leaves := data.Leaves()
if len(leaves) == 0 {
return nil, data.Proof(), nil
}

shares := make([]share.Share, len(leaves))
for i, leaf := range leaves {
if leaf != nil {
shares[i] = leafToShare(leaf)
}
}
return shares, data.Proof(), err
return shares, data.Proof(), nil
}

// leafToShare converts an NMT leaf into a Share.
Expand Down

0 comments on commit d2d325b

Please sign in to comment.