Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(state/coreAccessor): fix txResponse #3336

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
walldiss marked this conversation as resolved.
Show resolved Hide resolved
}

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
Wondertan marked this conversation as resolved.
Show resolved Hide resolved
}
return txResponse
}
Loading