Skip to content

Commit

Permalink
Merge branch 'main' into submit_multiple_blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
sontrinh16 authored Jan 11, 2024
2 parents 7587f80 + 9b2d82a commit 9ccfbb1
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 55 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ require (
github.com/libp2p/go-libp2p-routing-helpers v0.7.3
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-base32 v0.1.0
github.com/multiformats/go-multiaddr v0.12.0
github.com/multiformats/go-multiaddr v0.12.1
github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/multiformats/go-multihash v0.2.3
github.com/open-rpc/meta-schema v0.0.0-20201029221707-1b72ef2ea333
Expand All @@ -68,7 +68,7 @@ require (
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.17.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sync v0.5.0
golang.org/x/sync v0.6.0
golang.org/x/text v0.14.0
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.32.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1830,8 +1830,8 @@ github.com/multiformats/go-multiaddr v0.5.0/go.mod h1:3KAxNkUqLTJ20AAwN4XVX4kZar
github.com/multiformats/go-multiaddr v0.6.0/go.mod h1:F4IpaKZuPP360tOMn2Tpyu0At8w23aRyVqeK0DbFeGM=
github.com/multiformats/go-multiaddr v0.7.0/go.mod h1:Fs50eBDWvZu+l3/9S6xAE7ZYj6yhxlvaVZjakWN7xRs=
github.com/multiformats/go-multiaddr v0.8.0/go.mod h1:Fs50eBDWvZu+l3/9S6xAE7ZYj6yhxlvaVZjakWN7xRs=
github.com/multiformats/go-multiaddr v0.12.0 h1:1QlibTFkoXJuDjjYsMHhE73TnzJQl8FSWatk/0gxGzE=
github.com/multiformats/go-multiaddr v0.12.0/go.mod h1:WmZXgObOQOYp9r3cslLlppkrz1FYSHmE834dfz/lWu8=
github.com/multiformats/go-multiaddr v0.12.1 h1:vm+BA/WZA8QZDp1pF1FWhi5CT3g1tbi5GJmqpb6wnlk=
github.com/multiformats/go-multiaddr v0.12.1/go.mod h1:7mPkiBMmLeFipt+nNSq9pHZUeJSt8lHBgH6yhj0YQzE=
github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q=
github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q=
github.com/multiformats/go-multiaddr-dns v0.2.0/go.mod h1:TJ5pr5bBO7Y1B18djPuRsVkduhQH2YqYSbxWJzYGdK0=
Expand Down Expand Up @@ -2712,8 +2712,8 @@ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
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 9ccfbb1

Please sign in to comment.