# Layered Structure

{% hint style="info" %}
AIA Core Architecture
{% endhint %}

<figure><img src="/files/bCfdl3WWn2XRWfLwM3pq" alt=""><figcaption></figcaption></figure>

As shown in Figure 1, the core architecture of AIA Chain consists of the following layers from top to bottom:

* **Top-Level Applications**: This includes Solidity smart contracts, decentralized applications (DApps), and standard payment transactions.
* **API Interface Services**: Provides relevant Http and TCP interfaces for RPC framework services.
* **Distributed Ledger**: Comprises transactions, blocks, block validation tools, receipts, state data, and transaction pool information.
* **AIA Chain Virtual Machine (EVM)**: The core execution layer for smart contracts.
* **Consensus**: AIA Chain operates with a PoS consensus algorithm.
* **Network Services**: Includes peer-to-peer node discovery, connection services, and blockchain synchronization.
* **Underlying Services**: Consists of databases (e.g., LevelDB), cryptographic algorithms (such as elliptic curve algorithms), and foundational algorithms (MPT, Bloom filter, RLP, etc.).

{% hint style="info" %}
Transaction lifecycle in AIA Chain
{% endhint %}

<figure><img src="/files/z7JMSTOttD356b9tbviX" alt=""><figcaption></figcaption></figure>

The lifecycle model within the AIA Chain cluster mirrors that of Ethereum, comprising eight main stages:

1. **Link Establishment:** When an AIA Chain node starts, has too few links, or receives a link request, it initiates connections with other nodes via the P2P network. This involves node discovery through the Kad protocol, establishing TCP connections, and setting up the session model.
2. **Transaction/Block Synchronization:** After linking with nearby nodes, the node synchronizes blockchain data to build the best chain in alignment with the network. This includes active synchronization and transaction synchronization, where the latest block information is propagated across the network.
3. **Receiving Client Transactions:** AIA Chain nodes accept client requests from DApps or payment transactions. Following validation (e.g., double-spend prevention), the transaction is added to the transaction pool (TxPool) to await synchronization or packaging.
4. **Transaction Packaging:** Depending on the consensus algorithm (e.g., PBFT for block-producing nodes or PoS for longest chain nodes), nodes package N transactions from the pool into an unconfirmed block. The block then undergoes transaction execution and consensus.
5. **Transaction Execution:** Each transaction in a new block is executed by the AIA Chain Virtual Machine (EVM), involving contract account initialization, stack operations, and state changes. This results in transaction receipts and updates, and prepares the block header with transaction-related details.
6. **Block Consensus:** AIA Chain currently employs a PoS consensus mechanism, focusing on validating nodes through Ethash proof of work.
7. **Block Import:** After packaging and consensus, the block is finalized and added to storage, including transaction details, state trees, and indices, while managing chain forks and updating the longest chain.
8. **Client Query:** Once a block is mined, clients can query transaction results, the latest block, receipts, and contract data.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aia-chain-1.gitbook.io/aialabs/technical-framework/core-architecture/layered-structure.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
