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

feat: add error log to txstatus #3788

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions app/grpc/tx/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (s *txServer) TxStatus(ctx context.Context, req *TxStatusRequest) (*TxStatu
Height: resTx.Height,
Index: resTx.Index,
ExecutionCode: resTx.ExecutionCode,
Error: resTx.Error,
Status: resTx.Status,
}, nil
}
99 changes: 76 additions & 23 deletions app/grpc/tx/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions app/test/big_blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ func (s *BigBlobSuite) TestErrBlobsTooLarge() {
res, err := txClient.SubmitPayForBlob(subCtx, []*share.Blob{tc.blob}, user.SetGasLimitAndGasPrice(1e9, appconsts.DefaultMinGasPrice))
require.Error(t, err)
require.NotNil(t, res)
// FIXME: assert RawLog once TxStatus supports it.
require.Equal(t, tc.want, res.Code)
require.Equal(t, tc.want, res.Code, err.Error())
})
}
}
2 changes: 0 additions & 2 deletions app/test/prepare_proposal_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ func TestTimeInPrepareProposalContext(t *testing.T) {
msgs, _ := tt.msgFunc()
res, err := txClient.SubmitTx(cctx.GoContext(), msgs, user.SetGasLimit(1000000), user.SetFee(2000))
require.NoError(t, err)
// FIXME: Temporary way of querying the raw log.
// TxStatus will natively support this in the future.
serviceClient := sdktx.NewServiceClient(cctx.GRPCClient)
getTxResp, err := serviceClient.GetTx(cctx.GoContext(), &sdktx.GetTxRequest{Hash: res.TxHash})
require.NoError(t, err)
Expand Down
2 changes: 0 additions & 2 deletions app/test/square_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ func (s *SquareSizeIntegrationTest) setBlockSizeParams(t *testing.T, squareSize,

res, err := txClient.SubmitTx(s.cctx.GoContext(), []sdk.Msg{msg}, blobfactory.DefaultTxOpts()...)
require.NoError(t, err)
// FIXME: Temporary way of querying the raw log.
// TxStatus will natively support this in the future.
serviceClient := sdktx.NewServiceClient(s.cctx.GRPCClient)
getTxResp, err := serviceClient.GetTx(s.cctx.GoContext(), &sdktx.GetTxRequest{Hash: res.TxHash})
require.NoError(t, err)
Expand Down
2 changes: 0 additions & 2 deletions app/test/std_sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ func (s *StandardSDKIntegrationTestSuite) TestStandardSDK() {
} else {
require.NoError(t, err)
}
// FIXME: Temporary way of querying the raw log.
// TxStatus will natively support this in the future.
serviceClient := sdktx.NewServiceClient(s.cctx.GRPCClient)
getTxResp, err := serviceClient.GetTx(s.cctx.GoContext(), &sdktx.GetTxRequest{Hash: res.TxHash})
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,5 @@ replace (
github.com/cosmos/ledger-cosmos-go => github.com/cosmos/ledger-cosmos-go v0.12.4
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.39.0-tm-v0.34.29
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.40.0-tm-v0.34.29
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ github.com/celestiaorg/bittwister v0.0.0-20231213180407-65cdbaf5b8c7 h1:nxplQi8w
github.com/celestiaorg/bittwister v0.0.0-20231213180407-65cdbaf5b8c7/go.mod h1:1EF5MfOxVf0WC51Gb7pJ6bcZxnXKNAf9pqWtjgPBAYc=
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw=
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ=
github.com/celestiaorg/celestia-core v1.39.0-tm-v0.34.29 h1:9Co/2peu4+9S6KMVNPFS0NTI/RYIRirNpM4N7dmi9ak=
github.com/celestiaorg/celestia-core v1.39.0-tm-v0.34.29/go.mod h1:5jJ5magtH7gQOwSYfS/m5fliIS7irKunLV7kLNaD8o0=
github.com/celestiaorg/celestia-core v1.40.0-tm-v0.34.29 h1:J79TAjizxwIvm7/k+WI3PPH1aFj4AjOSjajoq5UzAwI=
github.com/celestiaorg/celestia-core v1.40.0-tm-v0.34.29/go.mod h1:5jJ5magtH7gQOwSYfS/m5fliIS7irKunLV7kLNaD8o0=
github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 h1:SeQ7Y/CyOcUMKo7mQiexaj/pZ/xIgyuZFIwYZwpSkWE=
github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16/go.mod h1:Bpl1LSWiDpQumgOhhMTZBMopqa0j7fRasIhvTZB44P0=
github.com/celestiaorg/go-square/v2 v2.0.0-rc2 h1:4D+ASgZGYVCsffc2uhPagACrvNiLZu9/CqNYvnlHCgg=
Expand Down
37 changes: 19 additions & 18 deletions pkg/user/tx_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/celestia-app/v3/x/minfee"
"github.com/tendermint/tendermint/rpc/core"
)

const (
Expand Down Expand Up @@ -211,10 +212,8 @@ func SetupTxClient(
// TxOptions may be provided to set the fee and gas limit.
func (client *TxClient) SubmitPayForBlob(ctx context.Context, blobs []*share.Blob, opts ...TxOption) (*TxResponse, error) {
resp, err := client.BroadcastPayForBlob(ctx, blobs, opts...)
if err != nil && resp != nil {
return &TxResponse{Code: resp.Code, TxHash: resp.TxHash}, fmt.Errorf("failed to broadcast pay for blob: %v", err)
} else if err != nil {
return &TxResponse{}, fmt.Errorf("failed to broadcast pay for blob: %v", err)
if err != nil {
return parseTxResponse(resp, fmt.Errorf("failed to broadcast pay for blob: %v", err))
}

return client.ConfirmTx(ctx, resp.TxHash)
Expand All @@ -224,10 +223,8 @@ func (client *TxClient) SubmitPayForBlob(ctx context.Context, blobs []*share.Blo
// TxOptions may be provided to set the fee and gas limit.
func (client *TxClient) SubmitPayForBlobWithAccount(ctx context.Context, account string, blobs []*share.Blob, opts ...TxOption) (*TxResponse, error) {
resp, err := client.BroadcastPayForBlobWithAccount(ctx, account, blobs, opts...)
if err != nil && resp != nil {
return &TxResponse{Code: resp.Code, TxHash: resp.TxHash}, fmt.Errorf("failed to broadcast pay for blob with account: %v", err)
} else if err != nil {
return &TxResponse{}, fmt.Errorf("failed to broadcast pay for blob with account: %v", err)
if err != nil {
return parseTxResponse(resp, fmt.Errorf("failed to broadcast pay for blob with account: %v", err))
}

return client.ConfirmTx(ctx, resp.TxHash)
Expand Down Expand Up @@ -270,10 +267,8 @@ func (client *TxClient) BroadcastPayForBlobWithAccount(ctx context.Context, acco
// may be provided to set the fee and gas limit.
func (client *TxClient) SubmitTx(ctx context.Context, msgs []sdktypes.Msg, opts ...TxOption) (*TxResponse, error) {
resp, err := client.BroadcastTx(ctx, msgs, opts...)
if err != nil && resp != nil {
return &TxResponse{Code: resp.Code, TxHash: resp.TxHash}, fmt.Errorf("failed to broadcast tx: %v", err)
} else if err != nil {
return &TxResponse{}, fmt.Errorf("failed to broadcast tx: %v", err)
if err != nil {
return parseTxResponse(resp, fmt.Errorf("failed to broadcast tx: %v", err))
}

return client.ConfirmTx(ctx, resp.TxHash)
Expand Down Expand Up @@ -445,27 +440,26 @@ func (client *TxClient) ConfirmTx(ctx context.Context, txHash string) (*TxRespon

if err == nil && resp != nil {
switch resp.Status {
// FIXME: replace hardcoded status with constants
case "PENDING":
case core.TxStatusPending:
// Continue polling if the transaction is still pending
select {
case <-ctx.Done():
return &TxResponse{}, ctx.Err()
case <-pollTicker.C:
continue
}
case "COMMITTED":
case core.TxStatusCommitted:
txResponse := &TxResponse{
Height: resp.Height,
TxHash: txHash,
Code: resp.ExecutionCode,
}
if resp.ExecutionCode != 0 {
return txResponse, fmt.Errorf("tx was included but failed with code %d: %s", resp.ExecutionCode, resp.Status)
return txResponse, fmt.Errorf("tx was committed but failed with code %d: %s", resp.ExecutionCode, resp.Error)
}
return txResponse, nil
case "EVICTED":
return &TxResponse{}, fmt.Errorf("tx: %s was evicted from the mempool", txHash)
case core.TxStatusEvicted:
return &TxResponse{TxHash: txHash}, fmt.Errorf("tx: %s was evicted from the mempool", txHash)
default:
return &TxResponse{}, fmt.Errorf("unknown tx: %s", txHash)
}
Expand Down Expand Up @@ -575,6 +569,13 @@ func (client *TxClient) getAccountNameFromMsgs(msgs []sdktypes.Msg) (string, err
return record.Name, nil
}

func parseTxResponse(resp *sdktypes.TxResponse, err error) (*TxResponse, error) {
if resp != nil {
return &TxResponse{Code: resp.Code, TxHash: resp.TxHash}, err
}
return &TxResponse{}, err
}

// Signer exposes the tx clients underlying signer
func (client *TxClient) Signer() *Signer {
return client.signer
Expand Down
13 changes: 11 additions & 2 deletions pkg/user/tx_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/celestiaorg/celestia-app/v3/pkg/user"
"github.com/celestiaorg/celestia-app/v3/test/util/blobfactory"
"github.com/celestiaorg/celestia-app/v3/test/util/testnode"
"github.com/cosmos/cosmos-sdk/x/authz"
)

func TestTxClientTestSuite(t *testing.T) {
Expand Down Expand Up @@ -47,8 +48,6 @@ func (suite *TxClientTestSuite) SetupSuite() {
suite.Require().NoError(err)
suite.txClient, err = user.SetupTxClient(suite.ctx.GoContext(), suite.ctx.Keyring, suite.ctx.GRPCClient, suite.encCfg, user.WithGasMultiplier(1.2))
suite.Require().NoError(err)
// FIXME: Temporary way of querying the raw log.
// TxStatus will natively support this in the future.
suite.serviceClient = sdktx.NewServiceClient(suite.ctx.GRPCClient)
cmwaters marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -179,6 +178,16 @@ func (suite *TxClientTestSuite) TestConfirmTx() {
require.Contains(t, err.Error(), "unknown tx: E32BD15CAF57AF15D17B0D63CF4E63A9835DD1CEBB059C335C79586BC3013728")
})

t.Run("should return error log when execution fails", func(t *testing.T) {
innerMsg := bank.NewMsgSend(testnode.RandomAddress().(sdk.AccAddress), testnode.RandomAddress().(sdk.AccAddress), sdk.NewCoins(sdk.NewInt64Coin(app.BondDenom, 10)))
msg := authz.NewMsgExec(suite.txClient.DefaultAddress(), []sdk.Msg{innerMsg})
resp, err := suite.txClient.BroadcastTx(suite.ctx.GoContext(), []sdk.Msg{&msg}, fee, gas)
require.NoError(t, err)
_, err = suite.txClient.ConfirmTx(suite.ctx.GoContext(), resp.TxHash)
require.Error(t, err)
require.Contains(t, err.Error(), "authorization not found")
})

t.Run("should success when tx is found immediately", func(t *testing.T) {
addr := suite.txClient.DefaultAddress()
msg := bank.NewMsgSend(addr, testnode.RandomAddress().(sdk.AccAddress), sdk.NewCoins(sdk.NewInt64Coin(app.BondDenom, 10)))
Expand Down
4 changes: 3 additions & 1 deletion proto/celestia/core/v1/tx/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ message TxStatusResponse {
// and returns whether it was successful or errored. A non zero
// execution code indicated an error.
uint32 execution_code = 3;
// error log for failed transactions.
string error = 4;
// status is the status of the transaction.
string status = 4;
string status = 5;
ninabarbakadze marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 2 additions & 2 deletions test/interchain/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/celestiaorg/nmt v0.21.0 // indirect
github.com/celestiaorg/nmt v0.22.0 // indirect
github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.10 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down Expand Up @@ -229,5 +229,5 @@ replace (
github.com/docker/docker => github.com/docker/docker v24.0.1+incompatible
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.38.0-tm-v0.34.29
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.40.0-tm-v0.34.29
)
8 changes: 4 additions & 4 deletions test/interchain/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOF
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ=
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o=
github.com/celestiaorg/celestia-core v1.38.0-tm-v0.34.29 h1:HwbA4OegRvXX0aNchBA7Cmu+oIxnH7xRcOhISuDP0ak=
github.com/celestiaorg/celestia-core v1.38.0-tm-v0.34.29/go.mod h1:MyElURdWAOJkOp84WZnfEUJ+OLvTwOOHG2lbK9E8XRI=
github.com/celestiaorg/celestia-core v1.40.0-tm-v0.34.29 h1:J79TAjizxwIvm7/k+WI3PPH1aFj4AjOSjajoq5UzAwI=
github.com/celestiaorg/celestia-core v1.40.0-tm-v0.34.29/go.mod h1:5jJ5magtH7gQOwSYfS/m5fliIS7irKunLV7kLNaD8o0=
github.com/celestiaorg/cosmos-sdk v1.24.0-sdk-v0.46.16 h1:AlBZS4WykzrwfcNbKD+yQQM1RTMz7lYDC1NS7ClAidM=
github.com/celestiaorg/cosmos-sdk v1.24.0-sdk-v0.46.16/go.mod h1:Bpl1LSWiDpQumgOhhMTZBMopqa0j7fRasIhvTZB44P0=
github.com/celestiaorg/nmt v0.21.0 h1:81MBqxNn3orByoiCtdNVjwi5WsLgMkzHwP02ZMhTBHM=
github.com/celestiaorg/nmt v0.21.0/go.mod h1:ia/EpCk0enD5yO5frcxoNoFToz2Ghtk2i+blmCRjIY8=
github.com/celestiaorg/nmt v0.22.0 h1:AGtfmBiVgreR1KkIV5R7XFNeMp/H4IUDLlBbLjZZ3zk=
github.com/celestiaorg/nmt v0.22.0/go.mod h1:ia/EpCk0enD5yO5frcxoNoFToz2Ghtk2i+blmCRjIY8=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4=
github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
Expand Down
2 changes: 0 additions & 2 deletions x/blobstream/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ func (s *BlobstreamIntegrationSuite) TestBlobstream() {
} else {
require.Error(t, err)
}
// FIXME: Temporary way of querying the raw log.
// TxStatus will natively support this in the future.
serviceClient := sdktx.NewServiceClient(s.cctx.GRPCClient)
getTxResp, err := serviceClient.GetTx(s.cctx.GoContext(), &sdktx.GetTxRequest{Hash: res.TxHash})
require.NoError(t, err)
Expand Down
Loading
Loading