Skip to content

Commit

Permalink
fix(state/coreAccessor): fix txResponse (#3336)
Browse files Browse the repository at this point in the history
Resolves #3322

Marshaling TxResponse fails because TxResponse.Tx is not empty but does not contain respective codec for encoding using the standard json.MarshalJSON()
  • Loading branch information
vgonkivs committed Apr 25, 2024
1 parent fa23cba commit 286a389
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ func (ca *CoreAccessor) SubmitPayForBlob(
}

if err != nil && errors.Is(err, sdkerrors.ErrNotFound) && !ca.granter.Empty() {
return response, errors.New("granter has revoked the grant")
return unsetTx(response), errors.New("granter has revoked the grant")
}
return response, err
return unsetTx(response), err
}
return nil, fmt.Errorf("failed to submit blobs after %d attempts: %w", maxRetries, lastErr)
}
Expand Down Expand Up @@ -388,7 +388,7 @@ func (ca *CoreAccessor) SubmitTx(ctx context.Context, tx Tx) (*TxResponse, error
if err != nil {
return nil, err
}
return txResp.TxResponse, nil
return unsetTx(txResp.TxResponse), nil
}

func (ca *CoreAccessor) SubmitTxWithBroadcastMode(
Expand All @@ -400,7 +400,7 @@ func (ca *CoreAccessor) SubmitTxWithBroadcastMode(
if err != nil {
return nil, err
}
return txResp.TxResponse, nil
return unsetTx(txResp.TxResponse), nil
}

func (ca *CoreAccessor) Transfer(
Expand Down Expand Up @@ -428,8 +428,8 @@ func (ca *CoreAccessor) Transfer(
return nil, fmt.Errorf("estimating gas: %w", err)
}
}

return signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), user.SetFee(fee.Uint64()))
resp, err := signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), user.SetFee(fee.Uint64()))
return unsetTx(resp), err
}

func (ca *CoreAccessor) CancelUnbondingDelegation(
Expand Down Expand Up @@ -459,7 +459,8 @@ func (ca *CoreAccessor) CancelUnbondingDelegation(
}
}

return signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), user.SetFee(fee.Uint64()))
resp, err := signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), user.SetFee(fee.Uint64()))
return unsetTx(resp), err
}

func (ca *CoreAccessor) BeginRedelegate(
Expand Down Expand Up @@ -489,7 +490,8 @@ func (ca *CoreAccessor) BeginRedelegate(
}
}

return signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), user.SetFee(fee.Uint64()))
resp, err := signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), user.SetFee(fee.Uint64()))
return unsetTx(resp), err
}

func (ca *CoreAccessor) Undelegate(
Expand Down Expand Up @@ -517,7 +519,8 @@ func (ca *CoreAccessor) Undelegate(
return nil, fmt.Errorf("estimating gas: %w", err)
}
}
return signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), user.SetFee(fee.Uint64()))
resp, err := signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), user.SetFee(fee.Uint64()))
return unsetTx(resp), err
}

func (ca *CoreAccessor) Delegate(
Expand Down Expand Up @@ -545,7 +548,8 @@ func (ca *CoreAccessor) Delegate(
return nil, fmt.Errorf("estimating gas: %w", err)
}
}
return signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), user.SetFee(fee.Uint64()))
resp, err := signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), user.SetFee(fee.Uint64()))
return unsetTx(resp), err
}

func (ca *CoreAccessor) QueryDelegation(
Expand Down Expand Up @@ -607,7 +611,8 @@ func (ca *CoreAccessor) GrantFee(
return nil, nil
}

return signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), withFee(fee))
resp, err := signer.SubmitTx(ctx, []sdktypes.Msg{msg}, user.SetGasLimit(gasLim), withFee(fee))
return unsetTx(resp), err
}

func (ca *CoreAccessor) RevokeGrantFee(
Expand All @@ -624,7 +629,8 @@ func (ca *CoreAccessor) RevokeGrantFee(
granter := signer.Address()

msg := feegrant.NewMsgRevokeAllowance(granter, grantee)
return signer.SubmitTx(ctx, []sdktypes.Msg{&msg}, user.SetGasLimit(gasLim), withFee(fee))
resp, err := signer.SubmitTx(ctx, []sdktypes.Msg{&msg}, user.SetGasLimit(gasLim), withFee(fee))
return unsetTx(resp), err
}

func (ca *CoreAccessor) LastPayForBlob() int64 {
Expand Down Expand Up @@ -699,3 +705,17 @@ func withFee(fee Int) user.TxOption {
gasFee := sdktypes.NewCoins(sdktypes.NewCoin(app.BondDenom, fee))
return user.SetFeeAmount(gasFee)
}

// THIS IS A TEMPORARY SOLUTION!!!
// unsetTx helps to fix issue in TxResponse marshaling. Marshaling TxReponse
// fails because `TxResponse.Tx` is not empty but does not contain respective codec
// for encoding using the standard `json.MarshalJSON()`. It becomes empty when
// https://github.com/celestiaorg/celestia-core/issues/1281 will be merged.
// The `TxResponse.Tx` contains the transaction that is sent to the cosmos-sdk in the form
// in which it is processed there, so the user should not be aware of it.
func unsetTx(txResponse *TxResponse) *TxResponse {
if txResponse != nil && txResponse.Tx != nil {
txResponse.Tx = nil
}
return txResponse
}

0 comments on commit 286a389

Please sign in to comment.