TON Blockchain Reference Implementation

repository·master·Indexed 26 days ago

https://github.com/ton-blockchain/ton

The reference implementation for The Open Network (TON) blockchain, featuring the node/validator, lite-client, tonlib, and the FunC compiler. Includes documentation for deploying validators via Docker and Kubernetes across various environments including AWS, GCP, and Ali Cloud, as well as configuration for the validator-engine and lite-server.

Tokens
11.1K
Snippets
30
Records
71
Agent score
85%

What's inside ton

  1. Overview of the Storage Provider smart-contract system

    master

    The Storage Provider is a smart-contract system designed for concluding storage agreements. It ensures that a provider stores a file by linking payments to proof of storage. Key features include:

    • Guarantees that the provider stores the file.
    • Payment is only released if storage is proven (no storage - no payment).
    • Clients can stop payments at any time if the provider fails to store the file or if the client is unsatisfied with the upload.
    • There are no penalties for the provider if the client stops payment.
  2. Understand TON Global Versions and Features

    master
    The TON blockchain uses a Global version parameter (specified in ConfigParam 8 of block.tlb) to enable or disable specific features. As the blockchain evolves, new versions introduce new TVM instructions, changes to the c7 tuple (the context tuple available to smart contracts), and modifications to gas limits or fee calculations. Developers must ensure their smart contracts are compatible with the global version active on the network (e.g., Mainnet vs Testnet).
  3. Build TON tests using Ninja or CMake

    master

    To build the TON test suite, navigate to your build directory. You can build specific test targets using either ninja or cmake.

    Available test targets include:

    • test-ed25519
    • test-bigint
    • test-vm
    • test-fift
    • test-cells
    • test-smartcont
    • test-net
    • test-tdactor
    • test-tdutils
    • test-tonlib-offline
    • test-adnl
    • test-dht
    • test-rldp
    • test-rldp2
    • test-catchain
    • test-fec
    • test-tddb
    • test-db
    • test-validator-session-state
    ninja test-ed25519 test-bigint test-vm test-fift test-cells test-smartcont test-net test-tdactor test-tdutils test-tonlib-offline test-adnl test-dht test-rldp test-rldp2 test-catchain test-fec test-tddb test-db test-validator-session-state
    cmake --build . --target test-ed25519 test-bigint test-vm test-fift test-cells test-smartcont test-net test-tdactor test-tdutils test-tonlib-offline test-adnl test-dht test-rldp test-rldp2 test-catchain test-fec test-tddb test-db test-validator-session-state
  4. Configure Amazon EBS CSI driver for EKS PersistentVolumeClaims

    master

    If you encounter a Pending PersistentVolumeClaim error stating it is waiting for an external provisioner (ebs.csi.aws.com), follow these steps to configure the Amazon EBS CSI driver in EKS:

    1. Enable IAM OIDC provider:
      eksctl utils associate-iam-oidc-provider --region=us-west-2 --cluster=k8s-my --approve
    2. Create the Amazon EBS CSI driver IAM role:
      eksctl create iamserviceaccount \
      --region us-west-2 \
      --name ebs-csi-controller-sa \
      --namespace kube-system \
      --cluster k8s-my \
      --attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
      --approve \
      --role-only \
      --role-name AmazonEKS_EBS_CSI_DriverRole
    3. Add the Amazon EBS CSI add-on:
      eksctl create addon --name aws-ebs-csi-driver --cluster k8s-my --service-account-role-arn arn:aws:iam::$(aws sts get-caller-identity --query Account --output text):role/AmazonEKS_EBS_CSI_DriverRole --force
      Note: Replace us-west-2 and k8s-my with your actual region and cluster name.
    eksctl utils associate-iam-oidc-provider --region=us-west-2 --cluster=k8s-my --approve
    
    eksctl create iamserviceaccount \
    --region us-west-2 \
    --name ebs-csi-controller-sa \
    --namespace kube-system \
    --cluster k8s-my \
    --attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
    --approve \
    --role-only \
    --role-name AmazonEKS_EBS_CSI_DriverRole
    
    eksctl create addon --name aws-ebs-csi-driver --cluster k8s-my --service-account-role-arn arn:aws:iam::$(aws sts get-caller-identity --query Account --output text):role/AmazonEKS_EBS_CSI_DriverRole --force
  5. Deploy TON validator on AWS EKS

    master

    Deploy to AWS EKS using an Elastic IP and a LoadBalancer service.

    Prerequisites:

    • EKS worker nodes must have CoreDNS, kube-proxy, and Amazon VPC CNI enabled.
    • An allocated Elastic IP.

    Setup Steps:

    1. Edit ton-aws.yaml:
      • Replace <PUBLIC_IP> with your Elastic IP.
      • Replace <ELASTIC_IP_ID> with the Elastic IP allocation ID from the AWS console.
      • Adjust the StorageClass name to use fast storage.
    2. Install: kubectl apply -f ton-aws.yaml

    Verification:

    • Use standard verification commands (logs, endpoints, etc.).
  6. Build TON blockchain on Ubuntu 22.04, 24.04 (x86-64, aarch64)

    master

    To build TON binaries on Ubuntu, first install the required system libraries and LLVM 21 clang, then execute the provided build script.

    1. Install dependencies:
    sudo apt-get update
    sudo apt-get install -y build-essential git cmake ninja-build
    
    wget https://apt.llvm.org/llvm.sh
    chmod +x llvm.sh
    sudo ./llvm.sh 21 clang
    1. Compile binaries:
    cp assembly/native/build-ubuntu-shared.sh .
    chmod +x build-ubuntu-shared.sh
    ./build-ubuntu-shared.sh
    sudo apt-get update
    sudo apt-get install -y build-essential git cmake ninja-build
    
    wget https://apt.llvm.org/llvm.sh
    chmod +x llvm.sh
    sudo ./llvm.sh 21 clang
    
    cp assembly/native/build-ubuntu-shared.sh .
    chmod +x build-ubuntu-shared.sh
    ./build-ubuntu-shared.sh
  7. Generate Tonlib libraries for iOS in Xcode

    master

    To generate Tonlib libraries for iOS using Xcode, follow these steps:

    1. Clone the https://github.com/labraburn/tonlib-xcframework repository.
    2. Open the repository directory in your Terminal.
    3. Run the Swift builder to generate the framework: swift run builder --output ./build --clean
    4. Copy the headers into the build directory: echo ./build/TON.xcframework/* | xargs -n 1 cp -R ./Resources/Headers
    5. In Xcode, import both OpenSSL.xcframework and TON.xcframework in the "Frameworks, Libraries, and Embedded Content" section.
    6. Use the Tonlib client by importing the header in C or Objective-C files.
    swift run builder --output ./build --clean
    echo ./build/TON.xcframework/* | xargs -n 1 cp -R ./Resources/Headers