Back to catalog
LabfreeFoundations

Mesh-Native Calculator

Your very first Mesh-Native app — distributed arithmetic across devices to learn mesh routing basics.

beginner 45mFree

What you'll build

Vertical stack context: DOSFIUniversity (research) → DOSFI Academy (this course) → MeshNativeExchange (publishing & monetizing). Students progress from Learning → Building → Publishing → Monetizing. This module provides a comprehensive technical foundation for developing Mesh-Native applications within the DOSFI ecosystem. Participants will learn how to leverage the DIU (Distributed Intelligence Unit) and Vital subsystems to create a distributed Mesh-Native Calculator, focusing on state management, message propagation via the Transport Layer, and secure execution within the Identity Fabric. The course emphasizes architectural patterns that ensure deterministic, high-availability compute across distributed nodes.

Skills you'll practice

  • Implement a stateful Mesh-Native application using the DIU model.
  • Configure basic Routing Policy for intra-node communication.
  • Verify data integrity through the Bundle Schema definition.
  • Validate application performance within the Vital runtime environment.

Before you start

  • Familiarity with distributed systems concepts.
  • Understanding of JSON-based declarative configurations.
  • Basic knowledge of DOSFI node architecture.

Lab steps6 steps

  1. 1
    Architecture of a Distributed Mesh-Native Calculator

    Welcome to the Mesh-Native Calculator lab. In this lesson, we will establish the conceptual foundations of building applications within the DOSFI ecosystem. At the heart of our calculator is the requirement to perform mathematical operations across a distributed network rather than on a single central server. We utilize the Distributed Intelligence Unit (DIU) as our primary settlement asset. Unlike traditional tokens, the DIU acts as the unit of measure for computation and storage cost across the Vital settlement layer. The architecture of our calculator follows a request-response pattern routed via the Transport Layer. Imagine a network of nodes where each node is capable of performing basic arithmetic functions. When a user inputs a calculation, it is encapsulated into a Bundle—the fundamental unit of distributed work in DOSFI. The Bundle travels across the Transport Layer, finding its destination node via the Identity Fabric, which ensures that only authorized entities can request calculations. [ASCII Diagram: User -> Identity Fabric -> Bundle -> Transport Layer -> Compute Node (DIU settlement) -> Result Bundle -> User]. In this lab, we will configure the Identity Fabric to manage node reputation and access tokens. Implementing the system requires defining the Bundle Schema. A bundle for our calculator will contain the operation (add, subtract, etc.), the operands, and a transaction fee in DIU. Step-by-step: 1. Initialize the project repository with the DOSFI CLI. 2. Define the Identity Fabric environment by creating a secure node manifest. 3. Validate the connection to the Vital settlement layer. Pitfalls to avoid include misconfiguring the node gateway, which leads to stalled bundles. Always ensure the transport heartbeat is active. This lesson connects to the next by establishing the basic node environment required to start sending packets.

  2. 2
    Configuring the Transport Layer for Bundle Propagation

    The Transport Layer is the backbone of DOSFI. It handles the routing, prioritization, and propagation of bundles across the distributed mesh. In a Mesh-Native Calculator, every arithmetic operation is a payload wrapped in a Bundle. If the Transport Layer is misconfigured, your calculator will suffer from high latency or packet loss, resulting in failed DIU settlements. The Transport Layer operates on an asynchronous, multi-hop routing protocol. When node A sends a request to node B, the bundle may pass through nodes C and D. Configuration is done via the 'transport.config.json' file. Example config: { 'routing_policy': 'lowest_latency', 'max_hops': 5, 'retry_limit': 3, 'transport_protocol': 'mesh_v2' }. Practical exercise: You must configure your local node to act as a routing relay. Use the command 'dosfi-transport-config --mode relay --peer-list [peer_ips]'. Verify connectivity using the mesh-probe tool. Common pitfalls involve firewall restrictions on the underlying network ports used by the Transport Layer. Ensure that ports 9000-9010 are open on all nodes. Pay special attention to the TTL (Time-To-Live) settings in your bundle header; if the TTL is too low, the bundle will expire before reaching the compute node. As you successfully establish network routing, we will move to the next lesson, where we define the mathematical logic inside the Bundle State Machine.

  3. 3
    Implementing the Bundle Schema and State Machine

    Now that the Transport Layer is moving packets, we must define what the packets contain. A Bundle is not just a container; it is a smart packet containing data and state transitions. For our calculator, the state machine must track the status of a calculation: 'Pending', 'Processing', 'Settling', and 'Complete'. Defining the Bundle Schema: { 'type': 'object', 'properties': { 'op': 'string', 'a': 'number', 'b': 'number', 'diu_fee': 'float', 'status': 'string' } }. The state machine logic is triggered by the arrival of a bundle at a compute node. When a 'Pending' bundle arrives, the node checks the Vital layer for valid DIU collateral, then moves the state to 'Processing'. After calculating the result, the node updates the bundle with the answer and switches status to 'Settling'. Finally, the bundle is propagated back to the user. Implementation: Write a simple handler in Python or JavaScript that listens for bundle events: 'if (bundle.status == 'Pending') { execute(bundle); update_state(bundle, 'Settling'); }'. Exercises: Create a custom schema that supports binary operations. Deploy it to your local node. Monitor the state transition logs using 'dosfi-logs -f'. A common pitfall is 'dead-locking' the state machine by forgetting to emit a final status. Always ensure every state branch has a transition path to 'Complete' or 'Failed'. This prepares us for the integration with the MeshInfer layer for more complex mathematical models.

  4. 4
    Integrating MeshInfer for Distributed Calculations

    While a simple addition can be done locally, our calculator demonstrates the power of the MeshInfer distributed inference fabric. MeshInfer allows us to offload complex mathematical operations (like matrix multiplication or neural network inference) to specialized nodes within the mesh. This lesson integrates the calculator bundle into the MeshInfer ecosystem. Instead of a hard-coded 'add' function, the calculator bundle will query a remote 'MathInference' model hosted on the network. The bundle schema is updated to include a 'model_id'. Configuration: { 'model_id': 'arithmetic-v1', 'input_tensor': [10, 20] }. The interaction involves sending the bundle to the MeshInfer node, which then processes the calculation and returns a proof of computation along with the result. This proof is then used by the Vital settlement layer to verify that the DIU spent was proportional to the compute power used. Practical exercise: Set up a MeshInfer provider node. Register your calculator's model schema with the local identity fabric. Use the 'dosfi-infer' tool to dispatch a test bundle. Pitfalls: Discrepancies between the requested model version and the available model version. Always check model availability before dispatching. By successfully connecting to MeshInfer, you have built a scalable, distributed engine that exceeds the capacity of any single machine.

  5. 5
    Settlement and Economics with MeshNativeExchange

    Calculation is not free in a distributed mesh; it consumes resources. The MeshNativeExchange (MNE) handles the economic incentives. When our calculator finishes a task, the MNE records the transaction on the Vital layer. This ensures that the compute provider is paid in DIU for their effort, while the requester is debited accordingly. In this lesson, we configure the MNE policy. We must define the 'gas' cost for each mathematical operation. Configuration example: { 'operation_gas': { 'add': 0.01, 'multiply': 0.05, 'infer': 0.1 } }. The MNE monitors the Bundle stream and automatically initiates a settlement call if the result is valid and the signature is verified. Exercise: Monitor the MNE ledger during a series of calculations. Compare the balance in your wallet before and after running 50 calculations. Pitfalls: Running out of DIU in your wallet is the most common issue. Ensure you have properly funded your node's address on the Vital testnet. Understanding MNE is critical for the final deployment phase as it defines the viability of your distributed application.

  6. 6
    Deployment and System Verification

    You have reached the final stage: deploying your distributed calculator to the live mesh. This lesson focuses on packaging your components, hardening the identity fabric, and verifying the end-to-end flow. We will package the Bundle Schema, the Transport Layer routing policies, and the MNE settlement logic into a single 'DOSFI-Package'. Deployment command: 'dosfi-deploy --package ./calculator --network mesh-main'. We will perform a final verification test: submitting a complex calculation to a remote node in another geography, observing the bundle travel across the Transport Layer, tracking its state transition in the local logs, and witnessing the DIU movement in the Vital explorer. Common pitfalls: Networking issues such as NAT traversal or closed ports that were not evident in local testing. Use the 'dosfi-health' suite to audit the node before final submission. Upon successful completion, your calculator is now a permanent, distributed entity, resilient to central failures and capable of serving requests anywhere in the world. Congratulations on becoming a certified Mesh-Native developer.