This is a manual backport of the changes from these commits:
- bc49f66 Add more unit tests for the priority mempool. (#8961)
- 9b02094 Fix unbounded heap growth in the priority mempool. (#8944)
Imports and type signatures have been updated to match the v0.34 usage.