Cortensor
  • Home
  • Abstract
    • Value Proposition
    • Whitepaper
      • Page 1: Introduction and Vision
      • Page 2: Architecture and Technical Overview
      • Page 3: Incentive Structure and Tokenomics
      • Page4: Development Roadmap and Phases
      • Page5: Summary
  • Introduction
    • What is Cortensor?
    • Key Features & Benefits
    • Vision & Mission
    • Team
  • Getting Started
    • Quick Start Guide
    • System Requirements
    • Installation & Setup
      • Getting Test ETH
      • Setup Own RPC Endpoint
      • Router Node Setup
        • Router API Reference
  • Core Concepts
    • Decentralized AI Inference
      • Community-Powered Network
      • Gamification and Quality Control
      • Incentive Structure
    • Universal AI Accessibility
    • Multi-layer Blockchain Architecture
  • Technical Architecture
    • Design Principles
    • Node Roles
    • Node Lifecycle
      • Ephemeral Node State
    • Node Reputation
    • Network & Flow
    • Type of Services
    • Coordination & Orchestration
      • Multi-Oracle Node Reliability & Leadership Rotation
    • AI Inference
      • Open Source Models
        • Centralized vs Decentralized Models
      • Quantization
      • Performance and Scalability
    • Consensus & Validation
      • Proof of Inference (PoI) & Proof of Useful Work (PoUW
      • aka Mining
      • Proof of Useful Work (PoUW)
      • Proof of Useful Work (PoUW) State Machine
        • Miner & Oracle Nodes in PoUW State Machine
      • Sampling in Large Distributed Systems
      • Parallel Processing
      • Embedding Vector Distance
    • Multi-Layered Blockchain Architecture
    • Modular Architecture and Smart Contract Interactions
      • Session Queue
      • Node Pool
      • Session Payment
    • Mining Overview
    • User Interaction & Node Communication
      • Session, Session Queue, Router, and Miner in Cortensor
    • Data Management
      • IPFS Integration
    • Security & Privacy
    • Dashboard
    • Development Previews
      • Multiple Miners Collaboration with Oracle Node
      • Web3 SDK Client & Session/Session Queue Interaction
    • Technical Threads
      • AI Agents and Cortensor's Decentralized AI Inference
    • Infographic Archive
  • Community & Ecosystem
    • Tokenomics
      • Network Incentive Allocation
      • Token Allocations & Safe Wallet Management
    • Staking Pool Overview
    • Contributing to Cortensor
    • Incentives & Reward System
    • Governance & Compliance
    • Safety Measures and Restricted Addresses
    • Buyback Program
    • Liquidity Additions
    • Partnerships
      • Partnership Offering for Demand-Side Partnerships
    • Community Testing
      • Closed Alpha Testing Phase #1
        • Closed Alpha Testing Phase #1 Contest: Closing & Winners Announcement
      • Closed Alpha Testing Phase #2
      • Closed Alpha Testing Phase #3
      • Discord Roles & Mainnet Privileges
      • DevNet Mapping
      • DevNet Modules & Parameters
    • Jobs
      • Technical Writer
      • Communication & Social Media Manager
      • Web3 Frontend Developer
      • Distributed Systems Engineer
  • Integration Guide
    • Web2
      • REST API
      • WebSocket
      • Client SDK
    • Web3
      • Web3 SDK
  • Use Cases
  • Roadmap
    • Technical Roadmap: Launch to Next 365 Days Breakdown
    • Long-term Vision: Beyond Inference
  • Glossary
  • Legal
    • Terms of Use
    • Privacy Policy
    • Disclaimer
    • Agreement for Sale of Tokens
Powered by GitBook
On this page
  • Purpose
  • Inheritance
  • Roles
  • Key Data Structures
  • Core Payment Flow
  • Key Functions
  • Security Features
  • Events
  • Summary
  1. Technical Architecture
  2. Modular Architecture and Smart Contract Interactions

Session Payment

The SessionPayment smart contract forms the financial backbone of the Cortensor session system. It manages deposits, payments, and withdrawals between users (sessions) and service providers (nodes/miners), ensuring a secure and transparent accounting process for AI inference services across the decentralized network.


Purpose

  • Allow users to deposit ETH or ERC20 tokens for session-based inference requests.

  • Track session ownership and network contribution per session.

  • Facilitate and allocate payments to nodes based on actual usage.

  • Enable nodes to claim their earned payments securely.


Inheritance

  • AccessControl: Provides role-based permissions for contract functions.

  • ReentrancyGuard: Prevents reentrant calls during fund transfers.


Roles

Role
Description

ADMIN_ROLE

Full administrative control for emergency actions or token recovery

SESSION_CONTRACT_ROLE

Authorized to call payment-related session functions (usually the Session contract)


Key Data Structures

  • Account: Tracks session data like ID, owner, payment amount, and timestamps.

  • sessionBalances: ETH/token balance associated with each session.

  • nodeLastUsedTimestamps: Timestamp logs for node activity.

  • sessions: Maps session IDs to owner addresses.

  • sessionNetworkUsage: Records cumulative session payments made to the network.

  • totalNetworkBalance: Tracks available funds for node payments.

  • nodePendingPayments: Accumulated payments owed to nodes before withdrawal.


Core Payment Flow

1. Session Deposits

Users deposit ETH (or tokens) via depositToSession. Funds are held in the session’s internal balance.

2. Network Contribution

Session-based tasks pay into the network treasury using payFromSessionToNetwork, recording usage via sessionNetworkUsage.

3. Node Allocation

Payments are distributed to eligible nodes through allocateNodePayments, using tracked usage and performance metrics.

4. Node Withdrawals

Nodes can withdraw earned funds via withdrawNodePayment once they’re allocated.


Key Functions

Session Management

  • registerSession(sessionId, owner): Registers a new session.

  • getSessionBalance(sessionId): Returns balance of the session.

  • depositToSession(sessionId): Allows ETH deposits to a session.

  • withdrawFromSession(sessionId): Allows ETH withdrawal by session owner.

Network Treasury

  • payFromSessionToNetwork(sessionId, amount): Transfers balance from session to network.

  • getSessionNetworkUsage(sessionId): Returns total contribution of a session to the network.

Node Payments

  • allocateNodePayments(address[] nodes, uint256 amountPerNode): Allocates payments to active nodes.

  • withdrawNodePayment(address node): Allows nodes to withdraw their funds.

  • updateNodeLastUsedTimestamp(address node): Updates node's last usage.

  • deleteNodeLastUsedTimestamp(address node): Removes node usage entry.

Admin & Emergency

  • adminWithdrawToken(tokenAddress): Allows recovery of mistakenly sent tokens.

  • Emergency ETH withdrawal for recovery and debugging.


Security Features

  • Role-Based Access: Only authorized contracts and admins can perform sensitive actions.

  • ReentrancyGuard: Protects ETH withdrawal functions.

  • Balance & Session Validations: Prevent overdrafts or unauthorized access.

  • Per-Session Tracking: Clear accounting for funds paid into the network.


Events

Event
Trigger

DepositToSession(sessionId, amount)

When user deposits ETH

WithdrawFromSession(sessionId, amount)

When session owner withdraws ETH

SessionRegistered(sessionId, owner)

New session registration

NodeTimestampUpdated(node)

Node activity timestamp update

PaymentToNetwork(sessionId, amount)

Session pays into the network

NodePaymentAllocated(node, amount)

Payment allocated to node

NodePaymentWithdrawn(node, amount)

Node claims their earned payment


Summary

The SessionPayment contract plays a crucial role in managing payments between users and the network. It ensures:

  • Transparent and secure session-level accounting.

  • Accurate tracking of network contributions.

  • Fair and reliable reward distribution to nodes.

  • Protection against common security vulnerabilities.

This module is essential for sustaining Cortensor's decentralized economic model while maintaining operational accountability and trust across participants.

PreviousNode PoolNextMining Overview

Last updated 1 month ago