canopy

tx.go - Transaction Processing and Memory Pool Management

This file implements the logic for transaction sending, handling, and memory pooling in the Canopy blockchain. It’s a critical component that manages how transactions flow through the network and are stored before being included in blocks.

Overview

The transaction handling system is designed to:

Core Components

Controller

The Controller manages the overall transaction flow in the blockchain. It:

Mempool

The Mempool is a temporary storage area for valid but unconfirmed transactions. It:

Transaction Validation

The validation system ensures only valid transactions enter the mempool:

Processes

flowchart TD
    A[Local Transaction] -->|SendTxMsg| B[Controller]
    C[Network Transaction] -->|ListenForTx| B
    B -->|HandleTransaction| D{Already in blockchain?}
    D -->|Yes| E[Reject as Duplicate]
    D -->|No| F{Already in mempool?}
    F -->|Yes| G[Reject as Already Pending]
    F -->|No| H[Mempool]
    H -->|HandleTransaction| I{Valid against state?}
    I -->|No| J[Cache as Failed]
    I -->|Yes| K[Add to Mempool]
    K -->|If needed| L[Recheck Mempool]
    L -->|For each tx| M{Still valid?}
    M -->|No| N[Evict from Mempool]
    M -->|Yes| O[Keep in Mempool]
    B -->|If valid| P[Gossip to Peers]

Component Interactions

The transaction handling system interacts with several other components:

flowchart TD
    A[Controller] <-->|Transaction Handling| B[Mempool]
    A <-->|Network Communication| C[P2P Layer]
    B <-->|State Validation| D[State Machine/FSM]
    A <-->|Transaction Lookup| E[Blockchain Store]
    A <-->|Reputation Management| C
    F[RPC Interface] -->|Transaction Queries| A

Security Features

The transaction handling system includes several security measures: