Skip to content

Commit

Permalink
Merge branch 'main' into fix/ci-version-bump
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Oct 30, 2024
2 parents 74a96e0 + c913b13 commit cade562
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
6 changes: 4 additions & 2 deletions pruner/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ func (s *Service) findPruneableHeaders(
return nil, err
}

if lastPruned.Height() == estimatedCutoffHeight {
if lastPruned.Height() >= estimatedCutoffHeight {
// nothing left to prune
return nil, nil
}

log.Debugw("finder: fetching header range", "last pruned", lastPruned.Height(),
"target height", estimatedCutoffHeight)

headers, err := s.getter.GetRangeByHeight(ctx, lastPruned, estimatedCutoffHeight)
// GetRangeByHeight requests (from:to), where `to` is non-inclusive, we need
// to request one more header than the estimated cutoff
headers, err := s.getter.GetRangeByHeight(ctx, lastPruned, estimatedCutoffHeight+1)
if err != nil {
log.Errorw("failed to get range from header store", "from", lastPruned.Height(),
"to", estimatedCutoffHeight, "error", err)
Expand Down
15 changes: 8 additions & 7 deletions share/availability/light/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package light
import (
"context"
"errors"
"fmt"
"sync"

"github.com/ipfs/go-datastore"
Expand Down Expand Up @@ -123,19 +124,19 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, header *header
}
wg.Wait()

if errors.Is(ctx.Err(), context.Canceled) {
// Availability did not complete due to context cancellation, return context error instead of
// share.ErrNotAvailable
return ctx.Err()
}

// store the result of the sampling session
bs := encodeSamples(failedSamples)
la.dsLk.Lock()
err = la.ds.Put(ctx, key, bs)
la.dsLk.Unlock()
if err != nil {
log.Errorw("Failed to store sampling result", "error", err)
return fmt.Errorf("failed to store sampling result: %w", err)
}

if errors.Is(ctx.Err(), context.Canceled) {
// Availability did not complete due to context cancellation, return context error instead of
// share.ErrNotAvailable
return ctx.Err()
}

// if any of the samples failed, return an error
Expand Down
28 changes: 0 additions & 28 deletions share/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package share

import (
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
libshare "github.com/celestiaorg/go-square/v2/share"
"github.com/celestiaorg/nmt"
"github.com/celestiaorg/rsmt2d"
)

// DefaultRSMT2DCodec sets the default rsmt2d.Codec for shares.
Expand All @@ -13,28 +10,3 @@ var DefaultRSMT2DCodec = appconsts.DefaultCodec
// MaxSquareSize is currently the maximum size supported for unerasured data in
// rsmt2d.ExtendedDataSquare.
var MaxSquareSize = appconsts.SquareSizeUpperBound(appconsts.LatestVersion)

// ShareWithProof contains data with corresponding Merkle Proof
type ShareWithProof struct { //nolint: revive
// Share is a full data including namespace
libshare.Share
// Proof is a Merkle Proof of current share
Proof *nmt.Proof
// Axis is a type of axis against which the share proof is computed
Axis rsmt2d.Axis
}

// Validate validates inclusion of the share under the given root CID.
func (s *ShareWithProof) Validate(rootHash []byte, x, y, edsSize int) bool {
isParity := x >= edsSize/2 || y >= edsSize/2
namespace := libshare.ParitySharesNamespace
if !isParity {
namespace = s.Share.Namespace()
}
return s.Proof.VerifyInclusion(
NewSHA256Hasher(),
namespace.Bytes(),
[][]byte{s.Share.ToBytes()},
rootHash,
)
}

0 comments on commit cade562

Please sign in to comment.