Skip to content

Commit

Permalink
chore(modstate): Remove IsStopped endpoint from StateModule (celestia…
Browse files Browse the repository at this point in the history
…org#2912)

@Wondertan is this what you expected?

Closes celestiaorg#2906
  • Loading branch information
Chirag018 authored and renaynay committed Jan 15, 2024
1 parent 920fca5 commit ed1d5c4
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 49 deletions.
20 changes: 0 additions & 20 deletions api/gateway/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ package gateway

import (
"context"
"errors"
"net/http"
"time"

"github.com/gorilla/mux"

"github.com/celestiaorg/celestia-node/nodebuilder/state"
)

const timeout = time.Minute

func (h *Handler) RegisterMiddleware(srv *Server) {
srv.RegisterMiddleware(
setContentType,
checkPostDisabled(h.state),
wrapRequestContext,
enableCors,
)
Expand All @@ -36,20 +30,6 @@ func setContentType(next http.Handler) http.Handler {
})
}

// checkPostDisabled ensures that context was canceled and prohibit POST requests.
func checkPostDisabled(state state.Module) mux.MiddlewareFunc {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// check if state service was halted and deny the transaction
if r.Method == http.MethodPost && state.IsStopped(r.Context()) {
writeError(w, http.StatusMethodNotAllowed, r.URL.Path, errors.New("not possible to submit data"))
return
}
next.ServeHTTP(w, r)
})
}
}

// wrapRequestContext ensures we implement a deadline on serving requests
// via the gateway server-side to prevent context leaks.
func wrapRequestContext(next http.Handler) http.Handler {
Expand Down
14 changes: 0 additions & 14 deletions nodebuilder/state/mocks/api.go

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

10 changes: 3 additions & 7 deletions nodebuilder/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ var _ Module = (*API)(nil)
// messages to the Celestia network.
//
//go:generate mockgen -destination=mocks/api.go -package=mocks . Module
//nolint:dupl
type Module interface {
// IsStopped checks if the Module's context has been stopped
IsStopped(ctx context.Context) bool

// AccountAddress retrieves the address of the node's account/signer
AccountAddress(ctx context.Context) (state.Address, error)
Expand Down Expand Up @@ -97,10 +96,11 @@ type Module interface {

// API is a wrapper around Module for the RPC.
// TODO(@distractedm1nd): These structs need to be autogenerated.
//
//nolint:dupl
type API struct {
Internal struct {
AccountAddress func(ctx context.Context) (state.Address, error) `perm:"read"`
IsStopped func(ctx context.Context) bool `perm:"read"`
Balance func(ctx context.Context) (*state.Balance, error) `perm:"read"`
BalanceForAddress func(ctx context.Context, addr state.Address) (*state.Balance, error) `perm:"read"`
Transfer func(
Expand Down Expand Up @@ -167,10 +167,6 @@ func (api *API) AccountAddress(ctx context.Context) (state.Address, error) {
return api.Internal.AccountAddress(ctx)
}

func (api *API) IsStopped(ctx context.Context) bool {
return api.Internal.IsStopped(ctx)
}

func (api *API) BalanceForAddress(ctx context.Context, addr state.Address) (*state.Balance, error) {
return api.Internal.BalanceForAddress(ctx, addr)
}
Expand Down
4 changes: 0 additions & 4 deletions nodebuilder/state/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ var ErrNoStateAccess = errors.New("node is running without state access. run wit
// to a core endpoint.
type stubbedStateModule struct{}

func (s stubbedStateModule) IsStopped(context.Context) bool {
return true
}

func (s stubbedStateModule) AccountAddress(context.Context) (state.Address, error) {
return state.Address{}, ErrNoStateAccess
}
Expand Down
4 changes: 0 additions & 4 deletions state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,6 @@ func (ca *CoreAccessor) queryMinimumGasPrice(
return coins.AmountOf(app.BondDenom).MustFloat64(), nil
}

func (ca *CoreAccessor) IsStopped(context.Context) bool {
return ca.ctx.Err() != nil
}

func withFee(fee Int) apptypes.TxBuilderOption {
gasFee := sdktypes.NewCoins(sdktypes.NewCoin(app.BondDenom, fee))
return apptypes.SetFeeAmount(gasFee)
Expand Down

0 comments on commit ed1d5c4

Please sign in to comment.