Skip to content

Commit

Permalink
fix: don't simulate transactions since we don't use gas
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed May 26, 2020
1 parent 79bd316 commit 3f92256
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/cosmic-swingset/x/swingset/blockers.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func CommitBlock(keeper Keeper) error {
BlockHeight: endBlockHeight,
BlockTime: endBlockTime,
}
committedHeight = endBlockHeight

b, err := json.Marshal(action)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions packages/cosmic-swingset/x/swingset/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var committedHeight int64 = 0

type deliverInboundAction struct {
Type string `json:"type"`
Peer string `json:"peer"`
Expand All @@ -25,6 +27,11 @@ type deliverInboundAction struct {
// NewHandler returns a handler for "swingset" type messages.
func NewHandler(keeper Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
if committedHeight == ctx.BlockHeight() {
// We don't support simulation.
return &sdk.Result{}, nil
}

switch msg := msg.(type) {
// Legacy deliver inbound.
// TODO: Sometime merge with IBC?
Expand Down
45 changes: 45 additions & 0 deletions packages/cosmic-swingset/x/swingset/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ func (am AppModule) OnChanOpenInit(
counterparty channeltypes.Counterparty,
version string,
) error {
if committedHeight == ctx.BlockHeight() {
// We don't support simulation.
return nil
}

event := channelOpenInitEvent{
Type: "IBC_EVENT",
Event: "channelOpenInit",
Expand Down Expand Up @@ -252,6 +257,10 @@ func (am AppModule) OnChanOpenTry(
version,
counterpartyVersion string,
) error {
if committedHeight == ctx.BlockHeight() {
// We don't support simulation.
return nil
}

event := channelOpenTryEvent{
Type: "IBC_EVENT",
Expand Down Expand Up @@ -301,6 +310,10 @@ func (am AppModule) OnChanOpenAck(
channelID string,
counterpartyVersion string,
) error {
if committedHeight == ctx.BlockHeight() {
// We don't support simulation.
return nil
}

event := channelOpenAckEvent{
Type: "IBC_EVENT",
Expand Down Expand Up @@ -335,6 +348,11 @@ func (am AppModule) OnChanOpenConfirm(
portID,
channelID string,
) error {
if committedHeight == ctx.BlockHeight() {
// We don't support simulation.
return nil
}

event := channelOpenConfirmEvent{
Type: "IBC_EVENT",
Event: "channelOpenConfirm",
Expand Down Expand Up @@ -368,6 +386,11 @@ func (am AppModule) OnChanCloseInit(
portID,
channelID string,
) error {
if committedHeight == ctx.BlockHeight() {
// We don't support simulation.
return nil
}

event := channelCloseInitEvent{
Type: "IBC_EVENT",
Event: "channelCloseInit",
Expand Down Expand Up @@ -400,6 +423,11 @@ func (am AppModule) OnChanCloseConfirm(
portID,
channelID string,
) error {
if committedHeight == ctx.BlockHeight() {
// We don't support simulation.
return nil
}

event := channelCloseConfirmEvent{
Type: "IBC_EVENT",
Event: "channelCloseConfirm",
Expand Down Expand Up @@ -430,6 +458,15 @@ func (am AppModule) OnRecvPacket(
ctx sdk.Context,
packet channeltypes.Packet,
) (*sdk.Result, error) {
if committedHeight == ctx.BlockHeight() {
// We don't support simulation.
return &sdk.Result{}, nil
}
if packet.GetTimeoutTimestamp() == 0 {
// FIXME: Don't know why, but for every relayed packet, we receive
// a second nearly-identical packet with a zero Timestamp.
return &sdk.Result{}, nil
}

event := receivePacketEvent{
Type: "IBC_EVENT",
Expand Down Expand Up @@ -468,6 +505,10 @@ func (am AppModule) OnAcknowledgementPacket(
packet channeltypes.Packet,
acknowledgement []byte,
) (*sdk.Result, error) {
if committedHeight == ctx.BlockHeight() {
// We don't support simulation.
return &sdk.Result{}, nil
}

event := acknowledgementPacketEvent{
Type: "IBC_EVENT",
Expand Down Expand Up @@ -505,6 +546,10 @@ func (am AppModule) OnTimeoutPacket(
ctx sdk.Context,
packet channeltypes.Packet,
) (*sdk.Result, error) {
if committedHeight == ctx.BlockHeight() {
// We don't support simulation.
return &sdk.Result{}, nil
}

event := timeoutPacketEvent{
Type: "IBC_EVENT",
Expand Down

0 comments on commit 3f92256

Please sign in to comment.