-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add host function that enforces transaction nesting depth #10811
Conversation
Why not enforce this in the runtime? |
So there is a PR that does this but it uses runtime storage to hold the current depth which would add two host functions calls for every transaction spawned: #10808 Another way would be to somehow leverage the |
Yeah that is what confused me ;) Good point about the two host calls.
I can help with this if wanted, should not be that hard. I first had some problem with this because they client could just ignore the The only real difference between this approach and the |
Yes if you could make it work with The main challenge would be to find the correct location to put the |
Exactly. Here should be the position you are searching for: https://github.com/paritytech/substrate/blob/master/frame/support/procedural/src/construct_runtime/expand/call.rs#L122-L127 |
Okay, maybe not the best position, because we can also reach this position if we are running nested transactions. I mean we could check before if there is already a context and reuse this context. But, we could also add this here: https://github.com/paritytech/substrate/blob/master/primitives/runtime/src/generic/checked_extrinsic.rs#L81 |
I think this is where Shawn put it in his first test and it failed for this reason.
This seems like a better position. I can't really tell if this is the only position dispatchables can be called from, though. |
I just want to point out that we do tons of unnecessary host function calls. Every storage access calls the I don't think that we have any policy regarding new host functions, but adding a new host function is a huge commitment. Host functions, once added, can never ever be removed. Adding a new host function just because it "seems" like an overhead, without this overhead even being measured, seems a bit eager to me. |
I agree. We should have a formal process around adding new host functions. And for this PR especially I think it should be solved within the runtime. |
The client does not enforce any limit on the nesting depth when the runtime spawns a new storage transaction. Without a limit a user could construct (without other barriers) a
Call
likebatch(batch(batch(write_many_keys)))
.We clearly want a limit here. @shawntabrizi and me came to the conclusion that the most efficient solution would be to fuse this operation with when we are calling into the client to create a new transaction anyways.
This adds:
Needed for #10806