feat: Implement Testnet Reset and Reindex functionality#523
Open
directorfloo wants to merge 1 commit into
Open
feat: Implement Testnet Reset and Reindex functionality#523directorfloo wants to merge 1 commit into
directorfloo wants to merge 1 commit into
Conversation
- Add TestnetResetService for safely resetting testnet data with audit logging and metrics. - Create SorobanIndexerController with endpoints for resetting testnet data and reindexing. - Develop unit tests for TestnetResetService and SorobanIndexerController to ensure functionality and error handling. - Introduce TestnetReindexHandler for processing reindex jobs with environment validation and metrics recording. - Implement integration tests for the complete reset and reindex workflow, ensuring data integrity and logging.
Author
|
closes |
|
@directorfloo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #508
#508
Closed
Pull Request: Testnet Reset and Soroban Event Reindexing Tooling
Description
This PR implements comprehensive tooling to safely reset testnet data and reindex Soroban contract events for reproducible demos and contributor testing. All operations include environment safeguards to prevent mainnet data loss, audit logging, and metrics collection.
Closes: Task: Add tooling to reset testnet data and reindex Soroban events from a known checkpoint
Changes
Core Features
1. Testnet Reset Service
TestnetResetService(src/ingestion/testnet-reset.service.ts)escrow_eventsprivacy_eventsadmin_eventsstealth_eventsNULLfor clean reindexForbiddenExceptionUsage:
2. Testnet Reindex Job Handler
TestnetReindexHandler(src/job-queue/handlers/testnet-reindex.handler.ts)JobHandler<TestnetReindexPayload>for background processingJobType.TESTNET_REINDEXPermanentJobErroron mainnetPayload:
3. Actor Extraction Decorator
@ActorPublicKey()(src/auth/decorators/actor-public-key.decorator.ts)4. API Endpoint
POST /admin/testnet/resetadminscope)TestnetResetResultwith operation details:success: boolean flagtimestamp: when operation completedtruncatedTables: count per tablecheckpointCount: number of checkpoints resetauditLogId: for finding operation in audit logsmessage: human-readable summaryMetrics Added
Four new Prometheus metrics for operational monitoring:
testnet_reset_total(Counter)statustestnet_reindex_total(Counter)statustestnet_reset_records_removed(Histogram)testnet_checkpoints_reset(Histogram)Audit Logging
All operations logged to
admin_audit_logstable with:testnet_reset- successful resettestnet_reset_failed- reset errortestnet_reindex_completed- successful reindextestnet_reindex_failed_mainnet- mainnet block attempttestnet_dataorcontract:<contractId>Environment Safeguards
Testnet-Only Operations
STELLAR_NETWORKenvironment variable"testnet"|"mainnet"Mainnet Blocking
ForbiddenExceptionon mainnetPermanentJobErroron mainnet (non-retryable)Error Handling
InternalServerErrorExceptionAcceptance Criteria
✅ Criterion 1: Reset Only on Testnet
Status: Met
ForbiddenExceptionif not testnetPermanentJobErrorif not testnetTest Coverage:
testnet-reset.service.unit.spec.ts- Environment validation teststestnet-reindex.handler.unit.spec.ts- Mainnet blocking testssoroban-indexer.controller.unit.spec.ts- Authorization tests✅ Criterion 2: Deterministic Reindex State
Status: Met
Test Coverage:
testnet-reindex.handler.unit.spec.ts- Ledger range handlingsoroban-indexer.controller.unit.spec.ts- Force parameter tests✅ Criterion 3: Quick Completion Validation
Status: Met
TestnetResetResultreturns:successflag for immediate statustruncatedTableswith per-table countscheckpointCountfor quick validationauditLogIdto find operation in audit logstimestampfor when operation completedmessagewith human-readable summaryExample Response:
{ "success": true, "timestamp": "2024-06-01T12:34:56.789Z", "truncatedTables": { "escrow_events": 150, "privacy_events": 75, "admin_events": 25, "stealth_events": 10 }, "checkpointCount": 3, "auditLogId": "reset_1717318496789_abc123", "message": "Testnet reset completed: removed 260 event records and reset 3 checkpoints" }Testing
Unit Tests (32+ test cases)
src/ingestion/testnet-reset.service.unit.spec.ts(9 tests)src/job-queue/handlers/testnet-reindex.handler.unit.spec.ts(11 tests)PermanentJobErrorsrc/ingestion/soroban-indexer.controller.unit.spec.ts(12 tests)Integration Tests
test/testnet-reset-reindex.integration.spec.tsRunning Tests
Files Changed
New Files (10 total)
Core Implementation:
src/ingestion/testnet-reset.service.ts(250 lines)src/job-queue/handlers/testnet-reindex.handler.ts(180 lines)src/auth/decorators/actor-public-key.decorator.ts(30 lines)Tests:
src/ingestion/testnet-reset.service.unit.spec.ts(250 lines)src/job-queue/handlers/testnet-reindex.handler.unit.spec.ts(230 lines)src/ingestion/soroban-indexer.controller.unit.spec.ts(180 lines)test/testnet-reset-reindex.integration.spec.ts(100 lines)Documentation:
TESTNET_RESET_REINDEX_GUIDE.md(comprehensive operational guide)IMPLEMENTATION_SUMMARY.md(technical details)TESTNET_RESET_QUICKREF.md(quick reference)Modified Files (8 total)
Type Definitions:
src/job-queue/types/job.types.ts- AddedTESTNET_REINDEXtoJobTypeenumsrc/job-queue/types/job-payloads.types.ts- AddedTestnetReindexPayloadinterfacesrc/job-queue/types/index.ts- Exported new payload typeModule Configuration:
src/job-queue/handlers/index.ts- ExportedTestnetReindexHandlersrc/job-queue/job-queue.module.ts- Registered reindex handlersrc/ingestion/ingestion.module.ts- Registered reset service, added audit moduleServices:
src/metrics/metrics.service.ts- Added 4 new metrics + 3 recording methods (50 lines)src/ingestion/soroban-indexer.controller.ts- Added reset endpoint (60 lines)Usage
Reset Testnet Data
Success Response (200 OK):
{ "success": true, "timestamp": "2024-06-01T12:34:56.789Z", "truncatedTables": { "escrow_events": 150, "privacy_events": 75, "admin_events": 25, "stealth_events": 10 }, "checkpointCount": 3, "auditLogId": "reset_1717318496789_abc123", "message": "Testnet reset completed: removed 260 event records and reset 3 checkpoints" }Error Response (403 Forbidden on mainnet):
{ "message": "ERROR: Running on mainnet — testnet data reset is blocked for safety", "error": "Forbidden", "statusCode": 403 }Queue Reindex Job
Direct Reindex (Synchronous)
Breaking Changes
None. All changes are additive:
Migration Guide
No migration required. The implementation:
escrow_events,privacy_events,admin_events,stealth_events,indexer_checkpoints)admin_audit_logstable for loggingDeployment Checklist
Operational Considerations
For Demos
For Contributor Testing
For Incident Recovery
Related Documentation
Reviewers Checklist
Questions?
See the documentation files or review the test files for usage examples and expected behavior.