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

exp/services/soroban-rpc: Add getTransactionStatus and sendTransaction json rpc methods #4609

Merged
merged 3 commits into from
Sep 27, 2022

Conversation

tamirms
Copy link
Contributor

@tamirms tamirms commented Sep 26, 2022

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Add json rpc methods for sending a transaction and querying a transaction status. This is implemented by proxying to the horizon txsub endpoint and the horizon transaction detail endpoint.

Why

#4595
#4595

Known limitations

  • As a shortcut to save time ahead of meridian, we proxy transaction submissions to Horizon instead of submitting directly to captive core
  • Pending transactions and transaction submission validation errors are stored in an memory data structure
  • I have not yet tested creating soroban smart contracts or invoking host functions because horizon does not support that functionality yet
  • No websocket functionality implemented, so the client will need to poll the getTransactionStatus method

@tamirms tamirms requested a review from a team September 26, 2022 13:38
Copy link
Contributor

@tsachiherman tsachiherman left a comment

Choose a reason for hiding this comment

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

Overall looks good. Beside the notes added, I have one more request:
can you add a Stop()/Shutdown() that would cancel the context and block until all the child go routines are done ?
i.e. use sync/workgroup + child context so you could shut it down.
The goal here is to allow deterministic cleanup.

exp/services/soroban-rpc/internal/jsonrpc.go Outdated Show resolved Hide resolved
exp/services/soroban-rpc/internal/methods/transaction.go Outdated Show resolved Hide resolved
type TransactionStatusResponse struct {
ID string `json:"id"`
Status string `json:"status"`
Result *horizon.Transaction `json:"result"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, error handling here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, error handling here?

+1, if not a big stretch to populate error as optionally mentioned in the api docs, seems like could help diagnostics for clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I will try to follow that format but I will keep Result to have type *horizon.Transaction for now. Once we're able to submit soroban transactions through horizon I will update the TransactionStatusResponse to include the the smart contract return value. We will also need stellar/stellar-core#3543 to be merged to include the smart contract return value

exp/services/soroban-rpc/internal/methods/transaction.go Outdated Show resolved Hide resolved
exp/services/soroban-rpc/internal/methods/transaction.go Outdated Show resolved Hide resolved
exp/services/soroban-rpc/internal/test/transaction_test.go Outdated Show resolved Hide resolved
exp/services/soroban-rpc/main.go Outdated Show resolved Hide resolved
return TransactionStatusResponse{}, err
}
} else {
return TransactionStatusResponse{
Copy link
Contributor

Choose a reason for hiding this comment

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

could p.deletePendingEntry(request.Hash) be done at this point as optimization, since tx status is known now, to keep the pending queue size down, rather than letting it wait longer for the expired loop to purge it.

}
txHash := hex.EncodeToString(hash[:])

p.lock.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

in general, and not suggesting for now, unless you saw value in it and not a stretch, has a context-aware lock been considered for usage, like go-lock with tryLockWithContext(ctx) just curious with advanced threading, potential for getting locked up and not honoring the callers ctx.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sreuland where do we have a use case where we use tryLockWithContext ? I'm familiar with the concept, but always found it too of a headache to implement.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking on ln 109, if there were a mis-matchted lock/unlock at some point, then ensuing caller requests would get stuck there on the Lock(), also if the caller defined a ctx with timeout shorter than the http client timeout(is configurable, I think is default of 10s) and passes that in here, could be another potential way that caller's context is ignored if the http response takes longer.

Copy link
Contributor

Choose a reason for hiding this comment

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

I generally agree with your observation here; as you've noted, in this case the lock is taken only for a short amount of time, and never for a blocking operation ( therefore, I can't see any concrete potential issue here )

func TestDeleteExpiredTransaction(t *testing.T) {
ttl := time.Minute
proxy := NewTransactionProxy(
nil,
Copy link
Contributor

Choose a reason for hiding this comment

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

great test coverage btw, from this unit test layer, noticed may have been able to mock out HTTP in horizonclient.Client, and possibly exercise much of the new code paths, rather than system integration tests later, just thinking out loud, not suggesting change.

Copy link
Contributor

@sreuland sreuland left a comment

Choose a reason for hiding this comment

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

great approach and implementation to get this realized!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

services/soroban-rpc: getTransactionStatus method services/soroban-rpc: sendTransaction method
4 participants