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

engine: create a max procedure call stack depth #609

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

jchappelow
Copy link
Member

This resolves a bug with the handling of deeply nested action calls. Ultimately the fix may be a gas cost for each action call, possibly exponentially increasing with depth, but I think a hard limit is still a good idea when user-defined recursion is a possibility. See code comments for more.

I don't think we want to scheme authors to write recursive algorithms, but if we change our mind I think we can life this restriction.

values: make(map[string]any),
DBID: p.DBID,
Procedure: p.Procedure,
StackDepth: p.StackDepth,
Copy link
Member Author

Choose a reason for hiding this comment

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

Initially I had this with a +1 from the parent procedure's context, but (*baseDataset).Call also does NewScope so it can get incremented twice unintentionally.

// Call calls a procedure from the dataset.
// If the procedure is not public, it will return an error.
// It implements the Namespace interface.
// It satisfies precompiles.Instance.
Copy link
Member Author

Choose a reason for hiding this comment

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

I think these interfaces have been renamed a few times. This seems to be the one it should mention.

// abusive recursive calls, but a hard upper limit will likely be necessary
// unless the price of an action call is extremely expensive or rises
// exponentially at each level of the call stack.
const MaxStackDepth = 1000
Copy link
Member Author

Choose a reason for hiding this comment

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

We can do up to 10,000, but that sort of txn requires about 0.1sec to exec even with no actual queries and that is too much baseline IMO.

We sorta do need to spend each time an action is entered though, to make gas reflect DB utilization, but we can't just hard crash either.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think 1000 is certainly more than enough

@brennanjl brennanjl merged commit 77d35a9 into kwilteam:main Mar 19, 2024
1 check passed
@jchappelow jchappelow deleted the max-call-stack branch March 20, 2024 04:05
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.

2 participants