Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Commit

Permalink
Merge PR #23: Improve run for loop logic and fix lint issues
Browse files Browse the repository at this point in the history
* Improved run loop

* Fixed lint issues
  • Loading branch information
jhernandezb authored Mar 20, 2020
1 parent 95ee7ec commit a4a2aba
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
4 changes: 3 additions & 1 deletion cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ func getTimeout(cmd *cobra.Command) (time.Duration, error) {

func urlFlag(cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagURL, "u", "", "url to fetch data from")
viper.BindPFlag(flagURL, cmd.Flags().Lookup(flagURL))
if err := viper.BindPFlag(flagURL, cmd.Flags().Lookup(flagURL)); err != nil {
panic(err)
}
return cmd
}

Expand Down
1 change: 0 additions & 1 deletion cmd/testnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ LimitNOFILE=4096
[Install]
WantedBy=multi-user.target
`, args[0], args[1], args[1])
return
},
}
return cmd
Expand Down
16 changes: 8 additions & 8 deletions relayer/codespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func GetCodespace(codespace string, code int) (msg string, err error) {
}

var codespaces = map[string]map[int]string{
"client": map[int]string{
"client": {
1: "light client already exists",
2: "light client not found",
3: "light client is frozen due to misbehaviour",
Expand All @@ -35,7 +35,7 @@ var codespaces = map[string]map[int]string{
19: "next sequence receive verification failed",
20: "self consensus state not found",
},
"connection": map[int]string{
"connection": {
1: "connection already exists",
2: "connection not found",
3: "light client connection paths not found",
Expand All @@ -44,7 +44,7 @@ var codespaces = map[string]map[int]string{
6: "invalid counterparty connection",
7: "invalid connection",
},
"channels": map[int]string{
"channels": {
1: "channel already exists",
2: "channel not found",
3: "invalid channel",
Expand All @@ -59,23 +59,23 @@ var codespaces = map[string]map[int]string{
12: "too many connection hops",
13: "acknowledgement too long",
},
"tendermint": map[int]string{
"tendermint": {
1: "invalid trusting period",
2: "invalid unbonding period",
3: "invalid header",
},
"transfer": map[int]string{
"transfer": {
1: "invalid packet timeout",
},
"commitment": map[int]string{
"commitment": {
1: "invalid proof",
2: "invalid prefix",
},
"ibc": map[int]string{
"ibc": {
1: "invalid height",
2: "invalid version",
},
"sdk": map[int]string{
"sdk": {
2: "tx parse error",
3: "invalid sequence",
4: "unauthorized",
Expand Down
5 changes: 4 additions & 1 deletion relayer/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
w.Write(response)
_, err := w.Write(response)
if err != nil {
fmt.Printf("error writing to the underlying response")
}
}

// FaucetRequest represents a request to the facuet
Expand Down
12 changes: 6 additions & 6 deletions relayer/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ func QueryClientConsensusStatePair(src, dst *Chain, srcH, dstH, srcClientConsH,
var wg sync.WaitGroup

chps := []chh{
chh{src, srcH, srcClientConsH},
chh{dst, dstH, dstClientConsH},
{src, srcH, srcClientConsH},
{dst, dstH, dstClientConsH},
}

for _, chain := range chps {
Expand Down Expand Up @@ -390,8 +390,8 @@ func QueryConnectionPair(src, dst *Chain, srcH, dstH int64) (map[string]connType
var wg sync.WaitGroup

chps := []chpair{
chpair{src, srcH},
chpair{dst, dstH},
{src, srcH},
{dst, dstH},
}

for _, chain := range chps {
Expand Down Expand Up @@ -471,8 +471,8 @@ func QueryChannelPair(src, dst *Chain, srcH, dstH int64) (map[string]chanTypes.C
var wg sync.WaitGroup

chps := []chpair{
chpair{src, srcH},
chpair{dst, dstH},
{src, srcH},
{dst, dstH},
}

for _, chain := range chps {
Expand Down
16 changes: 2 additions & 14 deletions relayer/strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strconv"
"strings"
"syscall"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
chanState "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
Expand Down Expand Up @@ -116,22 +115,11 @@ func (nrs NaiveStrategy) Run(src, dst *Chain) error {
go dst.handlePacket(src, srcMsg.Events)
case dstMsg := <-dstEvents:
go src.handlePacket(dst, dstMsg.Events)
default:
time.Sleep(10 * time.Millisecond)
// NOTE: This causes the for loop to run continuously and not to
// wait for messages before advancing. This allows for quick exit
}

// TODO: This seems to leak goroutines when there are blocking cases, if
// there is a more "go" way to do this, lets move to that
if len(done) > 0 {
<-done
case <-done:
fmt.Println("shutdown activated")
break
return nil
}
}

return nil
}

func (src *Chain) handlePacket(dst *Chain, events map[string][]string) {
Expand Down

0 comments on commit a4a2aba

Please sign in to comment.