AIOU Chain Docs

AIOU Chain Docs

  • Docs
  • Languages iconEnglish
    • 中文

›AIOU Tech Internals

Getting started

  • Overview
  • Quickstart

AIOU Design and Concepts

  • Account
  • Economic model

Smart Contract

  • Smart Contract Quick Start
  • AIOU Blockchain API
  • Update Contract
  • Generate Receipt in Smart Contract
  • Create IRC20 Token

Running AIOU node

  • Join AIOU Network
  • Become Servi Node

Reference

  • API
  • System Contract
  • Economic Contract
  • Token Contract
  • Gas Charge Table

AIOU Javascript SDK

  • AIOU
  • Blockchain
  • KeyPair
  • Transaction

AIOU Tech Internals

  • VM
  • Database
  • Network layer

VM

We believe a good implementation of virtual machine needs to be both elegantly designed, easy to use, and secure. After comparing the pros and cons of EVM, EOS, C Lua and V8, we have fundamentally resolved unreasonable designs of EVM and EOS. We have managed to build the AIOU VM based on V8 due to on the its high performance on Chrome.

1. AIOU V8VM structure and designs

VMManager is at the core of V8VM. It has three main features:

statedb

  • VM Entrance. It interfaces external requests from other modules, including RPC requests, block validation, Tx validation, etc. The work is handed off to VMWorker after preprocessing and formatting.
  • VMWorker lifecycle management. The number of workers are set dynamically based on system load. It achieves reuse of workers. Within the workers, JavaScript hot launch and persistence of hotspot Sandbox snapshots help reduce frequent creation of VMs, and avoid heavy load in CPU and memory when the same code is loaded. This will increase the throughput of the system, allowing the AIOU V8VM to breathe even when processing contracts with a massive user base, such as fomo3D.
  • Management of interface with State database. This ensures atomicity of each AIOU transaction, denying the entire transaction when there is an error of insufficient funds. At the same time, two-level cache is achieved in the State database, before being flushed to RocksDB.

2. Sandbox core design

statedb

As the payload of JavaScript smart contract execution, Sandbox interfaces with V8VM, and packs for calling in Chrome V8. There are two stages, Compile and Execution.

Compile Stage

Mainly for smart contract development and publishing, it has two features:

  • Contract Pack. Pack smart contracts using webpack. It will pack all javascript source codes in the project and install all dependencies, making AIOU V8VM easy to develop large projects. Besides, AIOU V8VM shares almost all features of Node.js, so developers will feel familiar.
  • Contract Snapshot. With the snapshot technology, compilation increases the performance of creating an isolate and contexts — an anti-serialization of the snapshot will achieve the result in runtime, and tremendously increase loading and execution speed of JavaScript.

Execute Stage

Mainly for execution of on-chain contracts, it has two features, too:

  • LoadVM. Completes initialization of VM, including the generation of Chrome V8 object, setting system execution parameters, importing relevant JavaScript class libraries, etc. Some JavaScript class libraries include:
Class LibraryFeatures
BlockchainNode.js-like modular system, including module caching, pre-compilation, cycle calls, etc.
EventRead/write of JavaScript with State Library, and rollback when contracts encounter errors.
NativeModuleBlockchain-related functions including transfer, withdraw and obtaining information on current block and Tx.
StorageImplementation of events. JavaScript contracts internal events can receive callbacks after going on-chain.
  • Execute. Finally executes JavaScript smart contract. AIOU V8VM will run the contract on a standalone thread, monitor the status of the run, and will Terminate the current run when there is an error, insufficient resource, or timeout, and return abnormal results.
← TransactionDatabase →
  • 1. AIOU V8VM structure and designs
  • 2. Sandbox core design
    • Compile Stage
    • Execute Stage
AIOU Chain Docs
Community
BlogGitHubStar
Facebook Open Source
Copyright © 2021 Your Name or Your Company Name