Skip to content

Module cache rebuild logic - #5175

Merged
graydon merged 3 commits into
stellar:masterfrom
graydon:module-cache-rebuild-logic
May 27, 2026
Merged

graydon merged 3 commits into
stellar:masterfrom
graydon:module-cache-rebuild-logic

Conversation

@graydon

@graydon graydon commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

This does a little simplification on the arithmetic we were doing to track thresholds of module cache rebuilding, as well as clarifying when we're measuring input vs. output values in the cost model. Also it moves the module cache tests to a separate file, as part of my long term dream to split InvokeHostFunctionTests.cpp into multiple files.

One disappointing part about this is that the tweak above reveals that the ApplyState state-invariant-checking that @SirTyson put in back in #4819 was actually slightly incorrect: the finishPendingCompilation method does actually write to ApplyState when it's in READY_TO_APPLY (it did back then too, it just didn't happen to occur in tests before). I can't think of any really great way to avoid this (the whole point is to defer the implied variable-update/stall until the last moment before we'll need it) besides I guess we could like add in another state? I don't know if that would win much, but I'd be willing to if that's your preference @SirTyson ?

Copilot AI review requested due to automatic review settings March 12, 2026 01:50
@graydon
graydon requested a review from SirTyson March 12, 2026 01:53

Copilot AI left a comment

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread src/ledger/LedgerManagerImpl.cpp Resolved

@SirTyson SirTyson left a comment

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.

Looking at the state transitions, I'm wondering if we should check for recompilation right after mApplyState.markEndOfCommitting();, and if compilation is necessary, transition to the SETTING_UP_STATE. I think semantically this makes the most sense, we aren't ready to apply (because we're setting up our module cache), but we also aren't committing anything. This would allow us to have stronger invariants on finishPendingCompilation, and I think is the most semantically correct. This also helps with our assert when we transition from READY_TO_APPLY -> APPLYING, as we can't enter the APPLYING phase until our compilation is done. What do you think?

Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Comment thread src/rust/src/soroban_proto_any.rs Resolved
@graydon

graydon commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Looking at the state transitions, I'm wondering if we should check for recompilation right after mApplyState.markEndOfCommitting();, and if compilation is necessary, transition to the SETTING_UP_STATE. I think semantically this makes the most sense, we aren't ready to apply (because we're setting up our module cache), but we also aren't committing anything. This would allow us to have stronger invariants on finishPendingCompilation, and I think is the most semantically correct. This also helps with our assert when we transition from READY_TO_APPLY -> APPLYING, as we can't enter the APPLYING phase until our compilation is done. What do you think?

Yeah, we could try that. I'll see how it goes.

@graydon
graydon force-pushed the module-cache-rebuild-logic branch from b474074 to ac5245e Compare March 17, 2026 08:37
@graydon

graydon commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Looking at the state transitions, I'm wondering if we should check for recompilation right after mApplyState.markEndOfCommitting();, and if compilation is necessary, transition to the SETTING_UP_STATE. I think semantically this makes the most sense, we aren't ready to apply (because we're setting up our module cache), but we also aren't committing anything. This would allow us to have stronger invariants on finishPendingCompilation, and I think is the most semantically correct. This also helps with our assert when we transition from READY_TO_APPLY -> APPLYING, as we can't enter the APPLYING phase until our compilation is done. What do you think?

Yeah, we could try that. I'll see how it goes.

It appears to work. Updated PR with change. Now needs even more careful scrutiny!

@graydon
graydon requested a review from SirTyson March 17, 2026 09:15
@graydon
graydon force-pushed the module-cache-rebuild-logic branch from ac5245e to 558e73f Compare March 18, 2026 05:33
@graydon

graydon commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

@jayz22 note: I changed the logic back to track and compare the count of modules * number of protocols, systematically. This is actually something we already have a test for and it's more honest about "actual memory pressure" so I think it's probably best to leave that way.

dmkozh
dmkozh previously approved these changes Mar 20, 2026
@graydon
graydon force-pushed the module-cache-rebuild-logic branch from 34533d0 to 5fe5342 Compare May 27, 2026 08:31
@graydon
graydon added this pull request to the merge queue May 27, 2026
Merged via the queue into stellar:master with commit 2f2294f May 27, 2026
68 checks passed
@graydon
graydon deleted the module-cache-rebuild-logic branch May 27, 2026 23:12
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.

5 participants