Skip to content

Add: Cross-Check Transaction via Horizon API#79

Open
Osuochasam wants to merge 1 commit into
Dfunder:mainfrom
Osuochasam:foxbranch53
Open

Add: Cross-Check Transaction via Horizon API#79
Osuochasam wants to merge 1 commit into
Dfunder:mainfrom
Osuochasam:foxbranch53

Conversation

@Osuochasam

Copy link
Copy Markdown

Horizon-Based On-Chain Donation Verification Pipeline

Overview

Implemented an on-chain transaction verification workflow that validates submitted donations against the Stellar network before marking them as confirmed. The new verification layer integrates with Horizon to ensure that only successfully finalized transactions are accepted, preventing false confirmations and improving the integrity of the donation system.

This enhancement introduces a secure verification process that checks transaction existence, execution success, ledger inclusion, and transaction metadata before updating donation state.


What Was Implemented

1. Horizon Transaction Verification Service

Added a dedicated verification flow that cross-checks submitted donation transaction hashes against the Stellar Horizon API.

Verification Process

For each pending donation:

  1. Retrieve the transaction from Horizon using the submitted hash.
  2. Confirm the transaction exists on-chain.
  3. Validate that the transaction completed successfully.
  4. Verify ledger inclusion metadata.
  5. Verify transaction creation timestamp.
  6. Update donation status based on verification outcome.

This ensures the platform only recognizes transactions that have been successfully committed to the Stellar ledger.


2. Transaction Existence Validation

Integrated Horizon transaction lookup using:

HorizonClient::get_transaction(hash)

Validation Rules

  • Transaction must exist on-chain
  • Transaction hash must match the submitted donation record
  • Missing transactions are treated as verification failures

This prevents invalid or fabricated transaction references from being confirmed.


3. Transaction Result Verification

Implemented transaction outcome validation.

Success Requirement

Only transactions with:

result_code = txSUCCESS

are eligible for confirmation.

Failure Handling

Transactions returning any non-success result code are automatically marked as failed and excluded from confirmation.

This ensures that failed network operations cannot be mistakenly treated as successful donations.


4. Ledger & Timestamp Validation

Added additional integrity checks against Horizon transaction metadata.

Ledger Verification

Confirms:

  • Transaction was included in a finalized ledger
  • Ledger information is present and valid
  • Transaction achieved network consensus

Timestamp Verification

Validates:

  • created_at metadata exists
  • Transaction timing information is available
  • Auditability requirements are satisfied

These checks provide stronger guarantees around transaction authenticity and traceability.


5. Donation State Management

Implemented secure donation lifecycle transitions.

Supported Status Flow

Pending
   ↓
Verification
   ↓
Confirmed | Failed

Confirmation Rule

A donation is marked as:

confirmed

only after all Horizon verification checks succeed.

Failure Rule

A donation is marked as:

failed

when:

  • Transaction is not found
  • Transaction execution failed
  • Required metadata validation fails
  • Verification cannot be completed successfully

This strictly enforces the platform's acceptance criteria.


6. Robust Error Handling

Added defensive handling for external service failures and unexpected verification scenarios.

Covered Scenarios

Transaction Not Found (404)

Handled gracefully by:

  • Logging verification failure
  • Preventing confirmation
  • Marking donation appropriately
Network Timeouts

Implemented retry-safe error handling for temporary Horizon connectivity issues.

Rate Limiting

Added handling for Horizon throttling responses to prevent incorrect state transitions.

Service Unavailability

Protects against accidental confirmation when Horizon cannot be reached.

Unexpected API Responses

Defensive validation prevents malformed or incomplete transaction responses from producing false positives.


7. Race Condition Protection

Implemented safe database update patterns to prevent concurrent verification processes from incorrectly confirming the same donation.

Safeguards

  • Conditional status updates
  • Atomic state transitions
  • Verification performed against the latest database state
  • Duplicate confirmation prevention

These protections ensure data consistency even under concurrent workloads.


8. Database Integrity Controls

Added secure persistence logic around donation verification.

Features

  • Verification results persisted transactionally
  • Failed validations recorded appropriately
  • Confirmation status only written after successful Horizon validation
  • Prevents premature state promotion

This guarantees accurate donation lifecycle tracking.


Testing Coverage

Implemented a comprehensive test suite covering both successful and failure scenarios.

Successful Verification Tests

Validated:

  • Transaction exists on Horizon
  • Result code equals txSUCCESS
  • Ledger metadata present
  • Timestamp metadata present
  • Donation transitions from pending to confirmed

Transaction Not Found Tests

Validated:

  • Horizon returns 404
  • Donation is not confirmed
  • Failure handling executes correctly

Failed Transaction Tests

Validated:

  • Non-success result codes
  • Donation remains unconfirmed
  • Failure status applied correctly

Network Error Tests

Validated:

  • Timeout scenarios
  • Temporary Horizon failures
  • Proper exception handling

Database Update Tests

Validated:

  • Correct state transitions
  • Atomic updates
  • Prevention of invalid confirmations

Mock-Based Verification Tests

Created unit tests using mocked:

  • Horizon client responses
  • Database repositories
  • Status update operations

This enables deterministic testing of all verification paths without requiring live network access.


Security & Reliability Improvements

Prevents False Confirmations

Only verified on-chain transactions are accepted.

Stronger Financial Integrity

Donation records now reflect actual Stellar ledger state.

Improved Auditability

Ledger and timestamp verification provide a clear verification trail.

Resilient External Integration

Robust error handling protects against Horizon outages and transient failures.

Concurrency Safety

Atomic state transitions prevent race-condition-related inconsistencies.


Acceptance Criteria Achieved

  • Horizon transaction lookup implemented
  • Transaction existence validation completed
  • txSUCCESS verification enforced
  • Ledger validation implemented
  • created_at validation implemented
  • Donation status transitions implemented
  • Pending → Confirmed flow secured
  • Pending → Failed flow implemented
  • Robust Horizon error handling added
  • Race condition protections implemented
  • Database state integrity safeguards added
  • Unit tests with mocked Horizon client completed
  • Confirmation occurs only after successful Horizon verification
    Closes Cross-Check Transaction via Horizon API #53

@ayshadogo ayshadogo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Osuochasam Job well done boss

Please fix the workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-Check Transaction via Horizon API

2 participants