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

refactor(state/gateway)!: remove SubmitTx endpoint from RPC and Gateway #3391

Merged
merged 2 commits into from
Jul 4, 2024

Conversation

distractedm1nd
Copy link
Collaborator

This PR removes the state.SubmitTx endpoint from the RPC, and the submit_tx endpoint from the gateway.

Related: #3348

Rationale

This endpoint was never fully documented, and no usage examples exist.
When creating usage examples after a discussion in #3345 , we realized the endpoint is not very useful at all. In order to use it, you need to construct a transaction, importing app, tendermint... all to then proxy it to an app instance via node anyways. Here is a snippet from @jcstein in the docs tutorial for submitting data.

The example for celestia-openrpc/celestia-node would essentially be exactly the same, except we build a rpc connection to node instead of a grpc to app. I think it is clear from this example why SubmitTx is too much of a hassle to use, and if users do need this functionality for their use-case, it is likely a sign that they should be interacting with app directly instead anyways.

To verify this, @Bidon15 reached out to teams to get feedback on this decision. All teams confirmed that the endpoint is not being used and not needed.

We support enough transaction types in the state module. If users need more functionality, we should either add the granularity to the current methods or add specific methods for specific transaction types/use cases. Dropping down a level to SubmitTx should never be needed if our API is good enough.

Example (using app conn)

import (
    "context"
    "fmt"

    "github.com/celestiaorg/celestia-app/app"
    "github.com/celestiaorg/celestia-app/app/encoding"
    "github.com/celestiaorg/celestia-app/pkg/appconsts"
    "github.com/celestiaorg/celestia-app/pkg/namespace"
    "github.com/celestiaorg/celestia-app/pkg/user"
    blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"
    "github.com/cosmos/cosmos-sdk/crypto/keyring"
    tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials/insecure"
)

// SubmitData is a demo function that shows how to use the signer to submit data
// to the blockchain directly via a celestia node. We can manage this keyring
// using the `celestia-appd keys` or `celestia keys` sub commands and load this
// keyring from a file and use it to programmatically sign transactions.
func DemoSubmitData(grpcAddr string, kr keyring.Keyring) error {
    // create an encoding config that can decode and encode all celestia-app
    // data structures.
    ecfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)

    // create a connection to the grpc server on the consensus node.
    conn, err := grpc.Dial(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
    if err != nil {
        return err
    }
    defer conn.Close()

    // get the address of the account we want to use to sign transactions.
    rec, err := kr.Key("accountName")
    if err != nil {
        return err
    }

    addr, err := rec.GetAddress()
    if err != nil {
        return err
    }

    // Setup the signer. This function will automatically query the relevant
    // account information such as sequence (nonce) and account number.
    signer, err := user.SetupSigner(context.TODO(), kr, conn, addr, ecfg)
    if err != nil {
        return err
    }

    ns := namespace.MustNewV0([]byte("1234567890"))

    fmt.Println("namespace", len(ns.Bytes()))

    blob, err := blobtypes.NewBlob(ns, []byte("some data"), appconsts.ShareVersionZero)
    if err != nil {
        return err
    }

    gasLimit := blobtypes.DefaultEstimateGas([]uint32{uint32(len(blob.Data))})

    options := []user.TxOption{
        // here we're setting estimating the gas limit from the above estimated
        // function, and then setting the gas price to 0.1utia per unit of gas.
        user.SetGasLimitAndFee(gasLimit, 0.1),
    }

    // this function will submit the transaction and block until a timeout is
    // reached or the transaction is committed.
    resp, err := signer.SubmitPayForBlob(context.TODO(), []*tmproto.Blob{blob}, options...)
    if err != nil {
        return err
    }

    // check the response code to see if the transaction was successful.
    if resp.Code != 0 {
        // handle code
        fmt.Println(resp.Code, resp.Codespace, resp.RawLog)
    }

    // if we don't want to wait for the transaction to be confirmed, we can
    // manually sign and submit the transaction using the same package.
    blobTx, err := signer.CreatePayForBlob([]*tmproto.Blob{blob}, options...)
    if err != nil {
        return err
    }

    resp, err = signer.BroadcastTx(context.TODO(), blobTx)
    if err != nil {
        return err
    }

    // check the response code to see if the transaction was successful. Note
    // that this time we're not waiting for the transaction to be committed.
    // Therefore the code here is only from the consensus node's mempool.
    if resp.Code != 0 {
        // handle code
        fmt.Println(resp.Code, resp.Codespace, resp.RawLog)
    }

    return err
}

@distractedm1nd distractedm1nd added kind:break! Attached to breaking PRs area:api Related to celestia-node API labels May 10, 2024
@distractedm1nd distractedm1nd self-assigned this May 10, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 45.48%. Comparing base (2469e7a) to head (67a7d53).
Report is 137 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3391      +/-   ##
==========================================
+ Coverage   44.83%   45.48%   +0.65%     
==========================================
  Files         265      274       +9     
  Lines       14620    15397     +777     
==========================================
+ Hits         6555     7004     +449     
- Misses       7313     7585     +272     
- Partials      752      808      +56     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

walldiss
walldiss previously approved these changes May 10, 2024
Copy link
Member

@walldiss walldiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fav type of PRs - deletions only! 🚀 Less is more, right?

ramin
ramin previously approved these changes May 13, 2024
vgonkivs
vgonkivs previously approved these changes May 13, 2024
@distractedm1nd
Copy link
Collaborator Author

@walldiss
Slash It

@distractedm1nd distractedm1nd merged commit 4d116a8 into celestiaorg:main Jul 4, 2024
28 checks passed
@vgonkivs vgonkivs mentioned this pull request Jul 5, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:api Related to celestia-node API kind:break! Attached to breaking PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants