Skip to content

Commit

Permalink
Merge branch 'develop' into optimize-fund-gas-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis authored Oct 14, 2023
2 parents 9ca322d + fb82095 commit b0eec5c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
6 changes: 0 additions & 6 deletions common/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
22 changes: 19 additions & 3 deletions rpc/websockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net"
"net/http"
"sync"
"time"

"github.com/cosmos/cosmos-sdk/client"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 4 additions & 6 deletions x/crosschain/keeper/keeper_out_tx_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
13 changes: 7 additions & 6 deletions x/emissions/client/tests/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions x/observer/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

/* #nosec */
const (
// #nosec G101 not a hardcoded credential
opWeightMsgUpdateClientParams = "op_weight_msg_update_client_params"
defaultWeightMsgUpdateClientParams int = 100
)
Expand Down
2 changes: 1 addition & 1 deletion x/observer/types/messages_add_block_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit b0eec5c

Please sign in to comment.