Skip to content

Commit

Permalink
Merge branch 'main' into feat-#21726
Browse files Browse the repository at this point in the history
  • Loading branch information
Teyz committed Sep 28, 2024
2 parents b0eaf1a + dd9e582 commit dd23fae
Show file tree
Hide file tree
Showing 31 changed files with 537 additions and 244 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/auto-assign-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Auto Assign Reviewers

on:
pull_request:
types: [opened, edited, review_requested]

jobs:
assign-reviewers:
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Assign reviewers as assignees
uses: actions/github-script@v7
with:
github-token: ${{ secrets.PRBOT_PAT }}
script: |
const { owner, repo } = context.repo;
async function getCurrentPR() {
if (context.payload.pull_request) {
return context.payload.pull_request;
}
const allPRs = await github.rest.pulls.list({
owner,
repo,
state: 'open',
});
return allPRs.data.find(pr => pr.head.sha === context.sha);
}
const pr = await getCurrentPR();
if (!pr) {
console.log('No matching PR found.');
return;
}
console.log(`Processing PR #${pr.number}`);
const reviewers = pr.requested_reviewers.map(reviewer => reviewer.login);
if (reviewers.length === 0) {
console.log('No reviewers found for this PR.');
return;
}
console.log(`Current reviewers: ${reviewers.join(', ')}`);
await github.rest.issues.addAssignees({
owner,
repo,
issue_number: pr.number,
assignees: reviewers,
});
console.log(`Assigned ${reviewers.join(', ')} as assignees to PR #${pr.number}`);
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (sims) [#21613](https://github.com/cosmos/cosmos-sdk/pull/21613) Add sims2 framework and factory methods for simpler message factories in modules

### Bug Fixes

* (sims) [21906](https://github.com/cosmos/cosmos-sdk/pull/21906) Skip sims test when running dry on validators
* (sims) [#21952](https://github.com/cosmos/cosmos-sdk/pull/21952) Use liveness matrix for validator sign status in sims
* (sims) [#21906](https://github.com/cosmos/cosmos-sdk/pull/21906) Skip sims test when running dry on validators
* (cli) [#21919](https://github.com/cosmos/cosmos-sdk/pull/21919) Query address-by-acc-num by account_id instead of id.

### API Breaking Changes
Expand Down Expand Up @@ -139,6 +139,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (internal) [#21412](https://github.com/cosmos/cosmos-sdk/pull/21412) Using unsafe.String and unsafe.SliceData.
* (client) [#21436](https://github.com/cosmos/cosmos-sdk/pull/21436) Use `address.Codec` from client.Context in `tx.Sign`.
* (x/genutil) [#21249](https://github.com/cosmos/cosmos-sdk/pull/21249) Incremental JSON parsing for AppGenesis where possible.
* (testnet) [#21941](https://github.com/cosmos/cosmos-sdk/pull/21941) Regenerate addrbook.json for in place testnet.

### Bug Fixes

Expand Down
1 change: 0 additions & 1 deletion buf.work.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ version: v1
directories:
- proto
- x/accounts/proto
- x/auth/proto
- x/authz/proto
- x/bank/proto
- x/circuit/proto
Expand Down
12 changes: 12 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"net"
"os"
"path/filepath"
"runtime/pprof"
"strings"
"time"
Expand Down Expand Up @@ -780,6 +781,17 @@ func testnetify[T types.Application](ctx *Context, testnetAppCreator types.AppCr
return nil, err
}

// Regenerate addrbook.json to prevent peers on old network from causing error logs.
addrBookPath := filepath.Join(config.RootDir, "config", "addrbook.json")
if err := os.Remove(addrBookPath); err != nil && !os.IsNotExist(err) {
return nil, fmt.Errorf("failed to remove existing addrbook.json: %w", err)
}

emptyAddrBook := []byte("{}")
if err := os.WriteFile(addrBookPath, emptyAddrBook, 0o600); err != nil {
return nil, fmt.Errorf("failed to create empty addrbook.json: %w", err)
}

// Load the comet genesis doc provider.
genDocProvider := node.DefaultGenesisDocProviderFunc(config)

Expand Down
9 changes: 2 additions & 7 deletions server/v2/api/grpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import "math"

func DefaultConfig() *Config {
return &Config{
Enable: true,
// DefaultGRPCAddress defines the default address to bind the gRPC server to.
Address: "localhost:9090",
// DefaultGRPCMaxRecvMsgSize defines the default gRPC max message size in
// bytes the server can receive.
Enable: true,
Address: "localhost:9090",
MaxRecvMsgSize: 1024 * 1024 * 10,
// DefaultGRPCMaxSendMsgSize defines the default gRPC max message size in
// bytes the server can send.
MaxSendMsgSize: math.MaxInt32,
}
}
Expand Down
29 changes: 11 additions & 18 deletions server/v2/api/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (s *Server[T]) Name() string {
}

func (s *Server[T]) Config() any {
if s.config == nil || s.config == (&Config{}) {
if s.config == nil || s.config.Address == "" {
cfg := DefaultConfig()
// overwrite the default config with the provided options
for _, opt := range s.cfgOptions {
Expand All @@ -163,6 +163,7 @@ func (s *Server[T]) Config() any {

func (s *Server[T]) Start(ctx context.Context) error {
if !s.config.Enable {
s.logger.Info(fmt.Sprintf("%s server is disabled via config", s.Name()))
return nil
}

Expand All @@ -171,24 +172,12 @@ func (s *Server[T]) Start(ctx context.Context) error {
return fmt.Errorf("failed to listen on address %s: %w", s.config.Address, err)
}

errCh := make(chan error)

// Start the gRPC in an external goroutine as Serve is blocking and will return
// an error upon failure, which we'll send on the error channel that will be
// consumed by the for block below.
go func() {
s.logger.Info("starting gRPC server...", "address", s.config.Address)
errCh <- s.grpcSrv.Serve(listener)
}()

// Start a blocking select to wait for an indication to stop the server or that
// the server failed to start properly.
err = <-errCh
if err != nil {
s.logger.Error("failed to start gRPC server", "err", err)
s.logger.Info("starting gRPC server...", "address", s.config.Address)
if err := s.grpcSrv.Serve(listener); err != nil {
return fmt.Errorf("failed to start gRPC server: %w", err)
}

return err
return nil
}

func (s *Server[T]) Stop(ctx context.Context) error {
Expand All @@ -198,6 +187,10 @@ func (s *Server[T]) Stop(ctx context.Context) error {

s.logger.Info("stopping gRPC server...", "address", s.config.Address)
s.grpcSrv.GracefulStop()

return nil
}

// GetGRPCServer returns the underlying gRPC server.
func (s *Server[T]) GetGRPCServer() *grpc.Server {
return s.grpcSrv
}
6 changes: 5 additions & 1 deletion server/v2/api/grpcgateway/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package grpcgateway

func DefaultConfig() *Config {
return &Config{
Enable: true,
Enable: true,
Address: "localhost:1317",
}
}

type Config struct {
// Enable defines if the gRPC-gateway should be enabled.
Enable bool `mapstructure:"enable" toml:"enable" comment:"Enable defines if the gRPC-gateway should be enabled."`

// Address defines the address the gRPC-gateway server binds to.
Address string `mapstructure:"address" toml:"address" comment:"Address defines the address the gRPC-gateway server binds to."`
}

type CfgOption func(*Config)
Expand Down
76 changes: 39 additions & 37 deletions server/v2/api/grpcgateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

gateway "github.com/cosmos/gogogateway"
"github.com/cosmos/gogoproto/jsonpb"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"

Expand All @@ -17,26 +16,25 @@ import (
serverv2 "cosmossdk.io/server/v2"
)

var _ serverv2.ServerComponent[transaction.Tx] = (*GRPCGatewayServer[transaction.Tx])(nil)

const (
ServerName = "grpc-gateway"

// GRPCBlockHeightHeader is the gRPC header for block height.
GRPCBlockHeightHeader = "x-cosmos-block-height"
var (
_ serverv2.ServerComponent[transaction.Tx] = (*Server[transaction.Tx])(nil)
_ serverv2.HasConfig = (*Server[transaction.Tx])(nil)
)

type GRPCGatewayServer[T transaction.Tx] struct {
const ServerName = "grpc-gateway"

type Server[T transaction.Tx] struct {
logger log.Logger
config *Config
cfgOptions []CfgOption

GRPCSrv *grpc.Server
GRPCGatewayRouter *runtime.ServeMux
server *http.Server
gRPCSrv *grpc.Server
gRPCGatewayRouter *runtime.ServeMux
}

// New creates a new gRPC-gateway server.
func New[T transaction.Tx](grpcSrv *grpc.Server, ir jsonpb.AnyResolver, cfgOptions ...CfgOption) *GRPCGatewayServer[T] {
func New[T transaction.Tx](grpcSrv *grpc.Server, ir jsonpb.AnyResolver, cfgOptions ...CfgOption) *Server[T] {
// The default JSON marshaller used by the gRPC-Gateway is unable to marshal non-nullable non-scalar fields.
// Using the gogo/gateway package with the gRPC-Gateway WithMarshaler option fixes the scalar field marshaling issue.
marshalerOption := &gateway.JSONPb{
Expand All @@ -46,9 +44,9 @@ func New[T transaction.Tx](grpcSrv *grpc.Server, ir jsonpb.AnyResolver, cfgOptio
AnyResolver: ir,
}

return &GRPCGatewayServer[T]{
GRPCSrv: grpcSrv,
GRPCGatewayRouter: runtime.NewServeMux(
return &Server[T]{
gRPCSrv: grpcSrv,
gRPCGatewayRouter: runtime.NewServeMux(
// Custom marshaler option is required for gogo proto
runtime.WithMarshalerOption(runtime.MIMEWildcard, marshalerOption),

Expand All @@ -64,12 +62,12 @@ func New[T transaction.Tx](grpcSrv *grpc.Server, ir jsonpb.AnyResolver, cfgOptio
}
}

func (g *GRPCGatewayServer[T]) Name() string {
func (s *Server[T]) Name() string {
return ServerName
}

func (s *GRPCGatewayServer[T]) Config() any {
if s.config == nil || s.config == (&Config{}) {
func (s *Server[T]) Config() any {
if s.config == nil || s.config.Address == "" {
cfg := DefaultConfig()
// overwrite the default config with the provided options
for _, opt := range s.cfgOptions {
Expand All @@ -82,50 +80,51 @@ func (s *GRPCGatewayServer[T]) Config() any {
return s.config
}

func (s *GRPCGatewayServer[T]) Init(appI serverv2.AppI[transaction.Tx], cfg map[string]any, logger log.Logger) error {
func (s *Server[T]) Init(appI serverv2.AppI[transaction.Tx], cfg map[string]any, logger log.Logger) error {
serverCfg := s.Config().(*Config)
if len(cfg) > 0 {
if err := serverv2.UnmarshalSubConfig(cfg, s.Name(), &serverCfg); err != nil {
return fmt.Errorf("failed to unmarshal config: %w", err)
}
}

// Register the gRPC-Gateway server.
// appI.RegisterGRPCGatewayRoutes(s.GRPCGatewayRouter, s.GRPCSrv)
// TODO: register the gRPC-Gateway routes

s.logger = logger
s.logger = logger.With(log.ModuleKey, s.Name())
s.config = serverCfg

return nil
}

func (s *GRPCGatewayServer[T]) Start(ctx context.Context) error {
func (s *Server[T]) Start(ctx context.Context) error {
if !s.config.Enable {
s.logger.Info(fmt.Sprintf("%s server is disabled via config", s.Name()))
return nil
}

// TODO start a normal Go http server (and do not leverage comet's like https://github.com/cosmos/cosmos-sdk/blob/9df6019de6ee7999fe9864bac836deb2f36dd44a/server/api/server.go#L98)
mux := http.NewServeMux()
mux.Handle("/", s.gRPCGatewayRouter)

return nil
}
s.server = &http.Server{
Addr: s.config.Address,
Handler: mux,
}

func (s *GRPCGatewayServer[T]) Stop(ctx context.Context) error {
if !s.config.Enable {
return nil
s.logger.Info("starting gRPC-Gateway server...", "address", s.config.Address)
if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
return fmt.Errorf("failed to start gRPC-Gateway server: %w", err)
}

return nil
}

// Register implements registers a grpc-gateway server
func (s *GRPCGatewayServer[T]) Register(r mux.Router) error {
// configure grpc-gatway server
r.PathPrefix("/").Handler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
// Fall back to grpc gateway server.
s.GRPCGatewayRouter.ServeHTTP(w, req)
}))
func (s *Server[T]) Stop(ctx context.Context) error {
if !s.config.Enable {
return nil
}

return nil
s.logger.Info("stopping gRPC-Gateway server...", "address", s.config.Address)
return s.server.Shutdown(ctx)
}

// CustomGRPCHeaderMatcher for mapping request headers to
Expand All @@ -134,6 +133,9 @@ func (s *GRPCGatewayServer[T]) Register(r mux.Router) error {
// gRPC metadata after removing prefix 'Grpc-Metadata-'. We can use this
// CustomGRPCHeaderMatcher if headers don't start with `Grpc-Metadata-`
func CustomGRPCHeaderMatcher(key string) (string, bool) {
// GRPCBlockHeightHeader is the gRPC header for block height.
const GRPCBlockHeightHeader = "x-cosmos-block-height"

switch strings.ToLower(key) {
case GRPCBlockHeightHeader:
return GRPCBlockHeightHeader, true
Expand Down
Loading

0 comments on commit dd23fae

Please sign in to comment.