Skip to content

Commit

Permalink
Merge PR cosmos#319: Remove GetSignBytes usage
Browse files Browse the repository at this point in the history
* Merge PR cosmos#314: Fix timeout determination

* fix mutex

* fix timeout bug

* fix GetSignBytes

* address other calls to GetSignBytes

Co-authored-by: Jack Zampolin <[email protected]>
  • Loading branch information
colin-axner and jackzampolin authored Oct 23, 2020
1 parent fec5c81 commit a0e6aac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cosmos/cosmos-sdk v0.40.0-rc0 h1:GY+jzuVILZ7wlx5Zic2W0rWlo47fZgN048xV458sUAo=
github.com/cosmos/cosmos-sdk v0.40.0-rc0/go.mod h1:YZcO00Tq/qqj4ncsfn+PobyTelsot7wEMGPpxEbEAT0=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/iavl v0.15.0-rc4 h1:P1wmET7BueqCzfxsn+BzVkDWDLY9ij2JNwkbIdM7RG8=
Expand Down
3 changes: 2 additions & 1 deletion relayer/naive-strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func (nrs *NaiveStrategy) sendTxFromEventPackets(src, dst *Chain, rlyPackets []r
MaxTxSize: nrs.MaxTxSize,
MaxMsgLength: nrs.MaxMsgLength,
}
unlock()

// add the packet msgs to RelayPackets
for _, rp := range rlyPackets {
Expand Down Expand Up @@ -464,7 +465,7 @@ func relayPacketFromQueryResponse(src, dst *PathEnd, res *ctypes.ResultTx,

// if we have decided not to relay this packet, don't add it
switch {
case sh.GetHeight(src.ChainID) >= rp.timeout:
case rp.timeout != 0 && sh.GetHeight(dst.ChainID) >= rp.timeout:
timeoutPackets = append(timeoutPackets, rp.timeoutPacket())
case rp.timeoutStamp != 0 && time.Now().UnixNano() >= int64(rp.timeoutStamp):
timeoutPackets = append(timeoutPackets, rp.timeoutPacket())
Expand Down
20 changes: 16 additions & 4 deletions relayer/relayMsgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strings"

"github.com/gogo/protobuf/proto"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -60,15 +62,20 @@ func (r *RelayMsgs) Send(src, dst *Chain) {

// submit batches of relay transactions
for _, msg := range r.Src {
bz, err := proto.Marshal(msg)
if err != nil {
panic(err)
}

msgLen++
txSize += uint64(len(msg.GetSignBytes()))
txSize += uint64(len(bz))

if r.IsMaxTx(msgLen, txSize) {
// Submit the transactions to src chain and update its status
r.success = r.success && send(src, msgs)

// clear the current batch and reset variables
msgLen, txSize = 1, uint64(len(msg.GetSignBytes()))
msgLen, txSize = 1, uint64(len(bz))
msgs = []sdk.Msg{}
}
msgs = append(msgs, msg)
Expand All @@ -84,15 +91,20 @@ func (r *RelayMsgs) Send(src, dst *Chain) {
msgs = []sdk.Msg{}

for _, msg := range r.Dst {
bz, err := proto.Marshal(msg)
if err != nil {
panic(err)
}

msgLen++
txSize += uint64(len(msg.GetSignBytes()))
txSize += uint64(len(bz))

if r.IsMaxTx(msgLen, txSize) {
// Submit the transaction to dst chain and update its status
r.success = r.success && send(dst, msgs)

// clear the current batch and reset variables
msgLen, txSize = 1, uint64(len(msg.GetSignBytes()))
msgLen, txSize = 1, uint64(len(bz))
msgs = []sdk.Msg{}
}
msgs = append(msgs, msg)
Expand Down

0 comments on commit a0e6aac

Please sign in to comment.