Skip to content

Commit

Permalink
fix: Compress transaction history upon update (#4555)
Browse files Browse the repository at this point in the history
## Explanation

The TransactionController has been updated to compress transaction
history if it exceeds the max transaction history size, which for now
has been set to 100. Each time a new entry is added to a transaction
history already at max size, we merge two entries to make room for the
new one.

Note that we never compress entries used for display in the transaction
activity log, because compressing those entries might hide events that
we want to display. If there are no non-displayed entries to compress,
history is allowed to exceed the max size.

This is a temporary solution to prevent unbounded growth of the
transaction history. While technically it is still unbounded at this
level because we don't strictly limit displayed history entries, we
don't know of any cases where displayed entries can be repeated a
significant number of times, so this will solve that problem in
practice.

## References

Fixes #4549

## Changelog

For the `@metamask/transaction-controller` package:
```markdown
### Added

- Add `DISPLAYED_TRANSACTION_HISTORY_PATHS` constant, representing the transaction history paths that may be used for display ([#4555](#4555))
  - This was exported so that it might be used to ensure display logic and internal history logic remains in-sync.
  - Any paths listed here will have their timestamps preserved. Unlisted paths may be compressed by the controller to minimize history size, losing the timestamp.
- Add `MAX_TRANSACTION_HISTORY_LENGTH` constant, representing the expected maximum size of the `history` property for a given transaction ([#4555](#4555))
  - Note that this is not strictly enforced, the length may exceed this number of all entries are "displayed" entries, but we expect this to be extremely improbable in practice.

### Fixed

- Prevent transaction history from growing endlessly in size ([#4555](#4555))
```
## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate

---------

Co-authored-by: Matthew Walsh <matthew.walsh@consensys.net>
  • Loading branch information
2 people authored and AugmentedMode committed Jul 30, 2024
1 parent e9aa1e9 commit a5559c5
Show file tree
Hide file tree
Showing 4 changed files with 527 additions and 6 deletions.
12 changes: 12 additions & 0 deletions packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `DISPLAYED_TRANSACTION_HISTORY_PATHS` constant, representing the transaction history paths that may be used for display ([#4555](https://github.com/MetaMask/core/pull/4555))
- This was exported so that it might be used to ensure display logic and internal history logic remains in-sync.
- Any paths listed here will have their timestamps preserved. Unlisted paths may be compressed by the controller to minimize history size, losing the timestamp.
- Add `MAX_TRANSACTION_HISTORY_LENGTH` constant, representing the expected maximum size of the `history` property for a given transaction ([#4555](https://github.com/MetaMask/core/pull/4555))
- Note that this is not strictly enforced, the length may exceed this number of all entries are "displayed" entries, but we expect this to be extremely improbable in practice.

### Fixed

- Prevent transaction history from growing endlessly in size ([#4555](https://github.com/MetaMask/core/pull/4555))

## [35.0.1]

### Changed
Expand Down
4 changes: 4 additions & 0 deletions packages/transaction-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export {
WalletDevice,
} from './types';
export type { EtherscanTransactionMeta } from './utils/etherscan';
export {
DISPLAYED_TRANSACTION_HISTORY_PATHS,
MAX_TRANSACTION_HISTORY_LENGTH,
} from './utils/history';
export { determineTransactionType } from './utils/transaction-type';
export { mergeGasFeeEstimates } from './utils/gas-flow';
export {
Expand Down
Loading

0 comments on commit a5559c5

Please sign in to comment.