How ava-labs/hypersdk works
Main Components
• Blockchain Core & Chain Logic:
– Represent the core chain components found in the “chain” directory (e.g., chain.go, builder.go, parser.go, transaction processing, genesis handling).
– Include the “internal/chain”, “internal/executor”, “internal/mempool”, and other internal modules that manage block validation, state transitions, and consensus-related data flows.
• Virtual Machine (VM) and Services:
– Highlight the “vm” directory, especially “vm/defaultvm/vm.go” and “vm/option.go”. This covers the VM instantiation and its customization.
– Indicate that “Services” can be registered as options to the VM (see explanations in the README about how Options enable APIs and event notifications).
– Show how these services plug into the blockchain for custom APIs, state syncing, and fee management.
• API Layers:
– Separate the API endpoints into components – “api” with its submodules (indexer, JSON-RPC, state, websocket).
– Note that these interfaces allow external clients or explorers to interact with the blockchain.
• Action and Transaction Handling:
– Mention the linkage between action parsing (in “chain/transaction_codec.go” and “chain/transaction_marshaller.go”) and state transition functions.
• Authentication & Cryptography:
– Emphasize the “auth” directory for signature and key management (using bls, ed25519, secp256r1 algorithms from “crypto”).
• State Management & Storage:
– Include the “state” directory for managing the persistent state (key-value store interactions).
– Include “storage” and components from “internal/pebble” which indicate that the framework supports pluggable storage backends.
• Networking & Communication:
– Capture networking components like “pubsub”, “statesync”, and the “api/ws” module to illustrate inter-node communication and client connectivity.
– Include reference to “snow” modules that indicate network and state syncing capabilities.
• Development Tools and Build Infrastructure:
– Show ancillary components like “cli” and “cmd” directories, used for command-line tools and client interactions.
– Optionally reference the extensive “tests” structure (unit, integration, e2e), “scripts”, and “examples” (like MorpheusVM) that help developers interact with and test the system.
Relationships and Interactions
• Data Flow & Execution Pipeline:
– Follow the flow from the action’s execution (implementing Execute) → processed by the blockchain engine (chain/executor) → state update (state/storage).
– Highlight the VM layer as mediating customization via options and services.
• Modular Architecture:
– Emphasize how components interact:
• The “chain” orchestrates block creation and parsing.
• The “internal” packages (executor, mempool, etc.) support processing and ordering.
• The “api” layer exposes the functionality externally.
• The “crypto” and “auth” modules validate and secure the transactions.
Architectural Patterns and Technologies
• Modular & Pluggable Design:
– Note that HyperSDK is built in a highly modular fashion. Components like the VM can be customized with different “Options” and services and storage can be swapped (as indicated by “Customizability” in the README).
• Service Registration and Dependency Injection:
– Emphasize the pattern where services are registered via “Options” at VM initialization. This facilitates easier integration of custom behavior (such as the Indexer, custom API, or event subscriptions).
• Technologies and Frameworks:
– Go is the primary language, with testing handled in a structured manner (see “*_test.go” files).
– The project utilizes Docker for containerized development (e.g., Dockerfile, .devcontainer files) and GitHub Actions for CI/CD pipelines.