diff --git a/common/chain.go b/common/chain.go index 0952a64b49..c0286a1f8d 100644 --- a/common/chain.go +++ b/common/chain.go @@ -102,12 +102,6 @@ func IsEVMChain(chainID int64) bool { chainID == 137 // polygon mainnet } -func IsEthereum(chainID int64) bool { - return chainID == 5 || // Goerli - chainID == 1337 || // eth privnet - chainID == 1 // eth mainnet -} - func (chain Chain) IsKlaytnChain() bool { return chain.ChainId == 1001 } diff --git a/rpc/websockets.go b/rpc/websockets.go index 1346aad955..84d334e952 100644 --- a/rpc/websockets.go +++ b/rpc/websockets.go @@ -25,6 +25,7 @@ import ( "net" "net/http" "sync" + "time" "github.com/cosmos/cosmos-sdk/client" "github.com/ethereum/go-ethereum/common" @@ -47,6 +48,13 @@ import ( const ( messageSizeLimit = 32 * 1024 * 1024 // 32MB + +) + +var ( + readTimeout = 15 * time.Second // Time to read the request + writeTimeout = 15 * time.Second // Time to write the response + idleTimeout = 60 * time.Second // Max time for connections using TCP Keep-Alive ) type WebsocketsServer interface { @@ -111,13 +119,21 @@ func (s *websocketsServer) Start() { ws := mux.NewRouter() ws.Handle("/", s) + // configuring the HTTP server + server := &http.Server{ + Addr: s.wsAddr, + Handler: ws, + ReadTimeout: readTimeout, + WriteTimeout: writeTimeout, + IdleTimeout: idleTimeout, + } + go func() { var err error - /* #nosec G114 -- http functions have no support for timeouts */ if s.certFile == "" || s.keyFile == "" { - err = http.ListenAndServe(s.wsAddr, ws) + err = server.ListenAndServe() } else { - err = http.ListenAndServeTLS(s.wsAddr, s.certFile, s.keyFile, ws) + err = server.ListenAndServeTLS(s.certFile, s.keyFile) } if err != nil { diff --git a/x/crosschain/keeper/keeper_out_tx_tracker.go b/x/crosschain/keeper/keeper_out_tx_tracker.go index 0eb2a7191a..308f4c13b0 100644 --- a/x/crosschain/keeper/keeper_out_tx_tracker.go +++ b/x/crosschain/keeper/keeper_out_tx_tracker.go @@ -124,17 +124,15 @@ func (k Keeper) OutTxTrackerAllByChain(c context.Context, req *types.QueryAllOut var outTxTrackers []types.OutTxTracker ctx := sdk.UnwrapSDKContext(c) - store := ctx.KVStore(k.storeKey) - outTxTrackerStore := prefix.NewStore(store, types.KeyPrefix(types.OutTxTrackerKeyPrefix)) + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.OutTxTrackerKeyPrefix)) + chainStore := prefix.NewStore(store, types.KeyPrefix(fmt.Sprintf("%d-", req.Chain))) - pageRes, err := query.Paginate(outTxTrackerStore, req.Pagination, func(key []byte, value []byte) error { + pageRes, err := query.Paginate(chainStore, req.Pagination, func(key []byte, value []byte) error { var outTxTracker types.OutTxTracker if err := k.cdc.Unmarshal(value, &outTxTracker); err != nil { return err } - if outTxTracker.ChainId == req.Chain { - outTxTrackers = append(outTxTrackers, outTxTracker) - } + outTxTrackers = append(outTxTrackers, outTxTracker) return nil }) diff --git a/x/emissions/client/tests/suite.go b/x/emissions/client/tests/suite.go index b9e950289d..b59adf9483 100644 --- a/x/emissions/client/tests/suite.go +++ b/x/emissions/client/tests/suite.go @@ -81,12 +81,13 @@ func RandomBallotGenerator(numberOfBallots int, voterList []string) []*observerT // #nosec G404 randomness is not a security issue here for i := 0; i < numberOfBallots; i++ { ballots[i] = &observerTypes.Ballot{ - Index: "", - BallotIdentifier: "TestBallot" + strconv.Itoa(i), - VoterList: voterList, - Votes: CreateRandomVoteList(len(voterList)), - ObservationType: observerTypes.ObservationType_InBoundTx, - BallotThreshold: sdk.MustNewDecFromStr("0.66"), + Index: "", + BallotIdentifier: "TestBallot" + strconv.Itoa(i), + VoterList: voterList, + Votes: CreateRandomVoteList(len(voterList)), + ObservationType: observerTypes.ObservationType_InBoundTx, + BallotThreshold: sdk.MustNewDecFromStr("0.66"), + // #nosec G404 randomness used for testing BallotStatus: ballotStatus[rand.Intn(max-min)+min], BallotCreationHeight: 0, } diff --git a/x/observer/module_simulation.go b/x/observer/module_simulation.go index 806a28c1db..08b52bcc08 100644 --- a/x/observer/module_simulation.go +++ b/x/observer/module_simulation.go @@ -11,6 +11,7 @@ import ( /* #nosec */ const ( + // #nosec G101 not a hardcoded credential opWeightMsgUpdateClientParams = "op_weight_msg_update_client_params" defaultWeightMsgUpdateClientParams int = 100 ) diff --git a/x/observer/types/messages_add_block_header.go b/x/observer/types/messages_add_block_header.go index 453a2f1b10..cfa2867128 100644 --- a/x/observer/types/messages_add_block_header.go +++ b/x/observer/types/messages_add_block_header.go @@ -52,7 +52,7 @@ func (msg *MsgAddBlockHeader) ValidateBasic() error { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, err.Error()) } - if common.IsEthereum(msg.ChainId) || common.IsBitcoinChain(msg.ChainId) { + if common.IsEthereumChain(msg.ChainId) || common.IsBitcoinChain(msg.ChainId) { if len(msg.BlockHash) != 32 { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block hash length (%d)", len(msg.BlockHash)) }