Skip to content

Commit

Permalink
chore(share/availability)!: Remove ProbabilityOfAvailability endpoi…
Browse files Browse the repository at this point in the history
…nt (celestiaorg#2797)

Resolves celestiaorg#2769

---------

Co-authored-by: ramin <[email protected]>
  • Loading branch information
2 people authored and distractedm1nd committed Oct 9, 2023
1 parent 321b3aa commit 9747432
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 73 deletions.
14 changes: 3 additions & 11 deletions api/gateway/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const heightAvailabilityEndpoint = "/data_available"
// AvailabilityResponse represents the response to a
// `/data_available` request.
type AvailabilityResponse struct {
Available bool `json:"available"`
Probability string `json:"probability_of_availability"`
Available bool `json:"available"`
}

func (h *Handler) handleHeightAvailabilityRequest(w http.ResponseWriter, r *http.Request) {
Expand All @@ -33,16 +32,10 @@ func (h *Handler) handleHeightAvailabilityRequest(w http.ResponseWriter, r *http
return
}

availResp := &AvailabilityResponse{
Probability: strconv.FormatFloat(
h.share.ProbabilityOfAvailability(r.Context()), 'g', -1, 64),
}

err = h.share.SharesAvailable(r.Context(), header.DAH)
switch err {
case nil:
availResp.Available = true
resp, err := json.Marshal(availResp)
resp, err := json.Marshal(&AvailabilityResponse{Available: true})
if err != nil {
writeError(w, http.StatusInternalServerError, heightAvailabilityEndpoint, err)
return
Expand All @@ -52,8 +45,7 @@ func (h *Handler) handleHeightAvailabilityRequest(w http.ResponseWriter, r *http
log.Errorw("serving request", "endpoint", heightAvailabilityEndpoint, "err", err)
}
case share.ErrNotAvailable:
availResp.Available = false
resp, err := json.Marshal(availResp)
resp, err := json.Marshal(&AvailabilityResponse{Available: false})
if err != nil {
writeError(w, http.StatusInternalServerError, heightAvailabilityEndpoint, err)
return
Expand Down
17 changes: 0 additions & 17 deletions nodebuilder/share/cmd/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
func init() {
Cmd.AddCommand(
sharesAvailableCmd,
probabilityOfAvailabilityCmd,
getSharesByNamespaceCmd,
getShare,
getEDS,
Expand Down Expand Up @@ -73,22 +72,6 @@ var sharesAvailableCmd = &cobra.Command{
},
}

var probabilityOfAvailabilityCmd = &cobra.Command{
Use: "availability",
Short: "Calculates the probability of the data square being available based on the number of samples collected.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := cmdnode.ParseClientFromCtx(cmd.Context())
if err != nil {
return err
}
defer client.Close()

prob := client.Share.ProbabilityOfAvailability(cmd.Context())
return cmdnode.PrintOutput(prob, nil, nil)
},
}

var getSharesByNamespaceCmd = &cobra.Command{
Use: "get-by-namespace [dah, namespace]",
Short: "Gets all shares from an EDS within the given namespace.",
Expand Down
17 changes: 1 addition & 16 deletions nodebuilder/share/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions nodebuilder/share/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ type Module interface {
// SharesAvailable subjectively validates if Shares committed to the given Root are available on
// the Network.
SharesAvailable(context.Context, *share.Root) error
// ProbabilityOfAvailability calculates the probability of the data square
// being available based on the number of samples collected.
ProbabilityOfAvailability(context.Context) float64
// GetShare gets a Share by coordinates in EDS.
GetShare(ctx context.Context, dah *share.Root, row, col int) (share.Share, error)
// GetEDS gets the full EDS identified by the given root.
Expand All @@ -46,9 +43,8 @@ type Module interface {
// TODO(@distractedm1nd): These structs need to be autogenerated.
type API struct {
Internal struct {
SharesAvailable func(context.Context, *share.Root) error `perm:"public"`
ProbabilityOfAvailability func(context.Context) float64 `perm:"public"`
GetShare func(
SharesAvailable func(context.Context, *share.Root) error `perm:"public"`
GetShare func(
ctx context.Context,
dah *share.Root,
row, col int,
Expand All @@ -69,10 +65,6 @@ func (api *API) SharesAvailable(ctx context.Context, root *share.Root) error {
return api.Internal.SharesAvailable(ctx, root)
}

func (api *API) ProbabilityOfAvailability(ctx context.Context) float64 {
return api.Internal.ProbabilityOfAvailability(ctx)
}

func (api *API) GetShare(ctx context.Context, dah *share.Root, row, col int) (share.Share, error) {
return api.Internal.GetShare(ctx, dah, row, col)
}
Expand Down
3 changes: 2 additions & 1 deletion nodebuilder/tests/fraud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"
"time"

"github.com/celestiaorg/go-fraud"
"github.com/ipfs/go-datastore"
ds_sync "github.com/ipfs/go-datastore/sync"
"github.com/libp2p/go-libp2p/core/host"
Expand All @@ -14,6 +13,8 @@ import (
"github.com/tendermint/tendermint/types"
"go.uber.org/fx"

"github.com/celestiaorg/go-fraud"

"github.com/celestiaorg/celestia-node/header"
headerfraud "github.com/celestiaorg/celestia-node/header/headertest/fraud"
"github.com/celestiaorg/celestia-node/nodebuilder"
Expand Down
4 changes: 0 additions & 4 deletions share/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,4 @@ type Availability interface {
// SharesAvailable subjectively validates if Shares committed to the given Root are available on
// the Network.
SharesAvailable(context.Context, *Root) error
// ProbabilityOfAvailability calculates the probability of the data square
// being available based on the number of samples collected.
// TODO(@Wondertan): Merge with SharesAvailable method, eventually
ProbabilityOfAvailability(context.Context) float64
}
4 changes: 0 additions & 4 deletions share/availability/full/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,3 @@ func (fa *ShareAvailability) SharesAvailable(ctx context.Context, root *share.Ro
}
return nil
}

func (fa *ShareAvailability) ProbabilityOfAvailability(context.Context) float64 {
return 1
}
10 changes: 0 additions & 10 deletions share/availability/light/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package light
import (
"context"
"errors"
"math"
"sync"

"github.com/ipfs/go-datastore"
Expand Down Expand Up @@ -140,15 +139,6 @@ func (la *ShareAvailability) SharesAvailable(ctx context.Context, dah *share.Roo
return nil
}

// ProbabilityOfAvailability calculates the probability that the
// data square is available based on the amount of samples collected
// (params.SampleAmount).
//
// Formula: 1 - (0.75 ** amount of samples)
func (la *ShareAvailability) ProbabilityOfAvailability(context.Context) float64 {
return 1 - math.Pow(0.75, float64(la.params.SampleAmount))
}

func rootKey(root *share.Root) datastore.Key {
return datastore.NewKey(root.String())
}
Expand Down

0 comments on commit 9747432

Please sign in to comment.