perf(escrow): reduce TempoStreamChannel storage from 6 to 3 slots#2868
Open
perf(escrow): reduce TempoStreamChannel storage from 6 to 3 slots#2868
Conversation
Remove token and authorizedSigner from Channel struct (derivable from channelId). Repack remaining fields for optimal slot layout: Slot 0: payer(20) + closeRequestedAt(8) + finalized(1) = 29 bytes Slot 1: payee(20) = 20 bytes Slot 2: deposit(16) + settled(16) = 32 bytes Functions that need token/authorizedSigner now accept them as calldata params and verify via channelId recomputation. requestClose() is unchanged (doesn't use either field). Estimated gas savings on Tempo (250k gas/SSTORE): ~750k gas on open(). Amp-Thread-ID: https://ampcode.com/threads/T-019c96fc-d95b-758c-908d-6264fa3872b4 Co-authored-by: Amp <amp@ampcode.com>
📊 Tempo Precompiles CoverageprecompilesCoverage: 20752/21815 lines (95.13%) File details
contractsCoverage: 209/383 lines (54.57%) File details
Total: 20961/22198 lines (94.43%) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduces
open()gas from ~1.3M to ~550-600k on Tempo by cutting storage slots from 6 to 3.Motivation
Tempo charges 250k gas per new storage slot (TIP-1000). The
Channelstruct was using 6 slots —tokenandauthorizedSignerare already baked into thechannelIdhash and don't need to be stored.Changes
tokenandauthorizedSignerfromChannelstruct (derivable fromchannelId)payer+closeRequestedAt+finalized(slot 0),payee(slot 1),deposit+settled(slot 2)settle(),close(),topUp(),withdraw()now accepttoken,authorizedSigner,saltas calldata and verify viacomputeChannelIdrequestClose()unchanged (doesn't use either field)InvalidChannelParamserror +_verifyChannelParamsinternal helperITempoStreamChannelinterfaceDownstream impact
ABI changes needed in:
tempoxyz/mpp-rs— updatesol!ABI blocks forgetChannel(),settle(),close(),withdraw(),topUp()tempoxyz/presto— samesol!ABI updates insession.rswevm/mppx— equivalent TS-side ABI changesAll three already store
token,authorizedSigner,saltlocally — no architectural changes needed.Testing
All 57 existing tests updated and passing.
Prompted by: jxom