Skip to content

Add more granular tx and op errors for soroban - #141

Closed
sisuresh wants to merge 3 commits into
stellar:nextfrom
sisuresh:errors
Closed

sisuresh wants to merge 3 commits into
stellar:nextfrom
sisuresh:errors

Conversation

@sisuresh

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread Stellar-transaction.x Outdated
INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE = -5
INVOKE_HOST_FUNCTION_INSUFFICIENT_REFUNDABLE_FEE = -5,
INVOKE_HOST_FUNCTION_CODE_SIZE_ABOVE_NETWORK_LIMIT = -6,
INVOKE_HOST_FUNCTION_DATA_SIZE_ABOVE_NETWORK_LIMIT = -7

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On one hand, this is a bit risky because the apply-time errors are canonical and thus we won't be able to e.g. change order for checking the entry sizes and total read bytes or even change the fetching order between code and data entries. On the other hand, we could expand INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED as well if we're going for more granular error codes anyway. I don't have a strong opinion on this really, but introducing granular codes for just a couple of cases seems a bit weird.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we're going for the network limits only here, the events may exceed it as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was just a fix for the inaccurate code, but yeah this isn't consistent with the changes in TransactionFrame. I agree that adding more error codes complicates the operation (I think this was Jon's original point in not having granular error codes in Soroban). Maybe I should just use a single INVOKE_HOST_FUNCTION_ENTRY_SIZE_ABOVE_NETWORK_LIMIT error? Or just undo this change? Maybe we just need to document every failure case?

Btw in addition to the events, memory is also checked against network config.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the safest way would be to revert the operation change or maybe distinguish between exceeding the network limit and transaction-level limit. In any case, it would be nice to synthesize a diagnostic event that specifies what has been exceeded and how (good thing is that we don't have to do that immediately). Documentation unfortunately doesn't help debugging much (like one would know that one of 10 different things failed) and granular codes are risky. I'm also curious what @graydon and @MonsieurNicolas think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'll just undo the op change and we can add diagnostic events later.

Comment thread Stellar-transaction.x
case txSOROBAN_WRITE_ENTRIES_ABOVE_NETWORK_LIMIT:
case txSOROBAN_TX_SIZE_ABOVE_NETWORK_LIMIT:
case txSOROBAN_INVALID_READ_FOOTPRINT:
case txSOROBAN_INVALID_WRITE_FOOTPRINT:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we want to, possibly, make these a SorobanTransactionResult to encompass all Soroban errors rather than having the txSOROBAN_ prefix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the error to the end user should still mention soroban (for example TX_SIZE_ABOVE_NETWORK_LIMIT could confuse a downstream user into thinking the limit they're looking for applies to classic ops as well). @MonsieurNicolas do you have an opinion on this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the point that Dima made above (wrt operations) probably applies for tx level errors:
adding error codes like this does not really give enough information for people (end users, not client devs) to do much and forces clients to handle those errors (even though the only thing they can tell end users is "re-run preflight").

For example, when getting txSOROBAN_INVALID_READ_FOOTPRINT, people (developers) want to know "which footprint" during their debugging session.

The only error code we need at this layer is probably just a txSOROBAN_TRY_AGAIN or something like that (that tells people to re-run preflight).

In stellar/stellar-core#3816 (comment) what I was suggesting for "transaction submission errors" was to add a new node in the http tx json endpoint:
right now error contains the TransactionResult, we can relatively easily add diagnostics (that contains soroban diagnostic events for example). Of course this would only be populated if core has diagnostic events enabled (which is the case for "Soroban-RPC").

This approach is the most flexible and the least disruptive for v1.
In the future, we could decide to "first class" certain error codes (and name them clearly as "tx submission time"), if there are certain scenarios where we expect clients to do something other than "retry".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Most of these errors cannot be solved by re-running preflight, so rpc would need to pass these errors back to the user somehow (cc @2opremio). You are describing an additional "logging" mechanism in TransactionFrame where the infomation is passed back in the tx endpoint. This will take an additional day, so that should be kept in mind wrt the timeline (@tsachiherman @ire-and-curses).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reason I say "re-run preflight" is because those errors should be caught well before submitting to the network and the solution (from a end user point of view), is to retry:

  • over limits type of error -> tx should fail during preflight, don't even need to sign it
  • bad footprints -> most likely stale footprint, preflight will resolve this

with information from preflight, clients can actually surface a lot more useful information to the end-users.

On the other hand, the later errors get surfaced to end-users, the more frustrating the experience, especially if people don't submit the transaction right away.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If they are system rather than diagnostic, then 👍

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Diagnostic events are opt out in soroban rpc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Diagnostic events are structured: they don't just have a string / data field. They also have a more-structured topic vector intended for machine filtering, and for errors we are doing the same thing here (at tx validation time) as we do with error diagnostic events emitted at execution time into the meta: the topics array is always [SCSymbol("error"), SCError(SCErrorType,SCErrorCode)].

For example in the PR I just pushed, if you submit a tx that wants more instructions than the network limit, you'll get a diagnostic event during tx? endpoint submission that decodes to the following:

{ inSuccessfulContractCall = FALSE,
  event = {
    ext = {
      v = 0
    },
    contractID = NULL,
    type = DIAGNOSTIC,
    body = {
      v = 0,
      v0 = {
        topics = [
          { type = SCV_SYMBOL,
            sym = "error" },
          { type = SCV_ERROR,
            error = {
              type = SCE_BUDGET,
              code = SCEC_EXCEEDED_LIMIT
            } }
        ],
        data = {
          type = SCV_VEC,
          vec = [
            { type = SCV_STRING,
              str = "transaction instructions resources exceed network config limit" },
            { type = SCV_U64,
              u64 = 2000000000 },
            { type = SCV_U64,
              u64 = 100000000 }
          ]
        }
      }
    }
  } }

Unlike error codes, error strings can change over time

Just to be clear, this is not an accidental or negative side effect. This is something pursued intentionally here, by choice. The ability to change these over time is one of the reasons why we want to use something like diagnostic events -- which are not hashed into the canonical history of the ledger -- rather than error codes. Because error codes impose a higher level of rigidity and maintenance burden, prevent evolution of the implementation or protocol. Any error code we emit gets hashed into the history and we must reproduce it bit-identically in every past circumstance that ever produced it. We want to limit the quantity of things like that.

Some other reasons to prefer DiagnosticEvents that might appeal to people outside the core team:

  • They're more open-ended, there's really no maintenance burden on making them as specific as we can, every single line of code that fails one way or another can have its own diagnostic event message, it's not like they chew up scarce numbers or produce annoying error lists in XDR that spam all the downstream SDK users.
  • They're not performance sensitive (turned off on validators, not part of canonical history) so:
    • They can contain a mix of SCError-like error codes, static messages, and also live / dynamic data, like the example above that shows the requested value as well as the limit. This allows far more meaningful diagnostics.
    • They can contain multiple events, producing a trail of things-that-happened, including errors but also including general step-by-step debugging information. We can even vary the granularity of that, have core or the env dial up or down the debug level while it runs.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@graydon the above, from my perspective, is beyond what we need. As long as we'll get these for all error cases, I think it would work. Unfortunately, consuming that data structure would require some more work on the downstream systems, so I wouldn't expect it to be fully supported for the testnet release.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this looks great for aiding with development and debugging - thanks!

@graydon

graydon commented Sep 1, 2023

Copy link
Copy Markdown
Contributor

Closing this since I believe we're not doing it.

@graydon graydon closed this Sep 1, 2023
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.

8 participants