feat: Add mptoken_issuance_history RPC - #3141
Conversation
12615d0 to
f3d1c1f
Compare
f3d1c1f to
05f2826
Compare
|
The handler PR should not contain the migration code |
The mptoken_issuance_history gate went through MigrationInspectorInterface, which required threading a MigrationInspector through ClioApplication and ProductionHandlerProvider purely for one status lookup. MigratorsRegister::getMigratorStatus ultimately just calls BackendInterface::fetchMigratorStatus wrapped in data::synchronous, which spins up a nested io_context and blocks the calling thread. Querying the backend directly with the request's yield context keeps the gate async and drops the extra dependency: ClioApplication, ProductionHandlerProvider and their tests return to their previous shape, and MockMigrationInspector is no longer needed. A missing status row and an unregistered migrator name are now indistinguishable (both nullopt), so the NotKnown warn log is gone. Both already failed closed with the same notReady error, so behaviour is unchanged; tests cover the absent-row and unparseable-status paths instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new Clio-only RPC method, mptoken_issuance_history, to retrieve transaction history for a specific MPToken issuance, optionally filtered by account and/or tx_type, and gated behind completion of the MPT transaction-history backfill to avoid serving partial history.
Changes:
- Introduces
MPTokenIssuanceHistoryHandlerwith ledger-range handling, paging/markers, binary/forward options, and optional post-fetchtx_typefiltering. - Registers the new RPC in the handler provider and RPC center, and links
clio_rpcagainstclio_migrationfor migrator-status gating. - Adds comprehensive unit tests covering parameter validation, routing, gating, paging/markers, binary modes, and
tx_typefiltering behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/rpc/handlers/MPTokenIssuanceHistoryTests.cpp | Adds extensive unit coverage for the new handler’s validation, gating, paging, and response shapes across API versions. |
| tests/unit/CMakeLists.txt | Includes the new unit test file in the unit test target. |
| src/rpc/RPCCenter.cpp | Adds mptoken_issuance_history to the handled RPC list. |
| src/rpc/handlers/MPTokenIssuanceHistory.hpp | Defines the new handler, input/output models, and RPC spec (including tx_type validation/modifiers). |
| src/rpc/handlers/MPTokenIssuanceHistory.cpp | Implements migrator gating, ledger range resolution, backend routing, marker/limit behavior, and response formatting. |
| src/rpc/common/impl/HandlerProvider.cpp | Registers the handler as Clio-only under mptoken_issuance_history. |
| src/rpc/CMakeLists.txt | Builds the new handler source and links clio_rpc with clio_migration for migrator-status usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@maria-robobug Please note there is an extra RPC handler we are adding to clio |
mathbunnyru
left a comment
There was a problem hiding this comment.
Please, merge latest changes - CI doesn't seem to have run, and you also didn't allow maintainers to update your branch, so I can't do it myself
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@BryanJ1ang Could you add more tests regarding the coverage report? |
mathbunnyru
left a comment
There was a problem hiding this comment.
I think process function is quite difficult to read, because it's too long, so this should be refactored.
General comments:
- Please, fix clang-tidy
- And PR title
- And add more test coverage (I agree with @PeterChen13579)
| util::Logger log_{"RPC"}; | ||
| std::shared_ptr<BackendInterface> sharedPtrBackend_; | ||
| // Status is monotonic, so the terminal Migrated result is cached across handler copies. | ||
| std::shared_ptr<std::atomic_bool> migrated_ = std::make_shared<std::atomic_bool>(false); |
There was a problem hiding this comment.
Do we actually copy our handlers?
If not, we should probably get rid of shared_ptr and make this class non-copyable
There was a problem hiding this comment.
Yes, handlers are copied per request. getHandler() returns AnyHandler by value, and clone() copies the concrete handler.
The shared atomic keeps the cached Migrated state across those copies. otherwise each request would query the status again.
| namespace rpc { | ||
|
|
||
| MPTokenIssuanceHistoryHandler::Result | ||
| MPTokenIssuanceHistoryHandler::process( |
There was a problem hiding this comment.
This function is very long, could you please refactor it in smaller, but meaningful private methods?
| { | ||
| // Fail closed unless the backfill is done: partial history must never be served. | ||
| if (not migrated_->load(std::memory_order_relaxed)) { | ||
| auto const statusString = sharedPtrBackend_->fetchMigratorStatus(kMigratorName, ctx.yield); |
There was a problem hiding this comment.
I'm not sure if it's a good idea, but maybe we should have a small refactoring PR, so fetchMigratorStatus returns MigratorStatus, or optional or sth like that?
There was a problem hiding this comment.
Yeah I think this would make sense for a separate PR
| cursor = {input.marker->ledger, input.marker->seq}; | ||
| } else { | ||
| if (input.forward) { | ||
| cursor = {minIndex, 0}; | ||
| } else { | ||
| cursor = {maxIndex, std::numeric_limits<int32_t>::max()}; | ||
| } |
There was a problem hiding this comment.
Can we use designated initializers here to make it more clear what's going on?
There was a problem hiding this comment.
TransactionsCursor has user declared constructors so we can't use designated initializers here. Added some comments to make it more clear
| ) | ||
|
|
||
| target_link_libraries(clio_rpc PUBLIC clio_util clio_data) | ||
| target_link_libraries(clio_rpc PUBLIC clio_util clio_data clio_migration) |
There was a problem hiding this comment.
This line should be reverted as well
feat: add mptoken_issuance_history RPC
Summary
Adds mptoken_issuance_history, a Clio-only method that returns the transaction history for a given MPT issuance — the MPT-scoped sibling of nft_history. You can optionally filter by account and/or tx_type.
The index tables, backend fetch methods, and live ETL indexing landed earlier; this wires up the handler on top of them.
The handler