# Resource Model

# Overview

Transactions on TOP Network mainchain can be divided into shard transactions, Beacon and Beacon system transactions. Each transaction consumes resources on the chain. The temporarily occupied resources such as NET/CPU, which are unified and abstracted into one type of resource called gas. Each account—including each contract account and each ordinary account—has free daily gas.

To obtain higher daily quotas, the account must deposit TOP tokens.

# Gas Consumption Rules

Gas consumption rules vary depending on the type of transaction and account.

  • For transactions that are not invoking contracts, only the transaction sender is charged.

  • The normal account runs the application contract and charges the transaction sender first, which is shared by th etransaction sender and the contract (the application contract may set the upper limit of the gas fee that the user is willing to pay for the transaction).

  • It will charge the initiator when ordinary accounts running the platform contract, and there is no charge for platform contract running triggered by the system.

The gas consumed by the transaction is shown in the following table.

Transaction Type Totoal Consumed Gas Paid by the Sender Paid by the Receiver Note
Single Account Transaction tx_len*1 tx_len*1 - -
Across Account Transaction Non-run Contract Transaction tx_len*3 tx_len*3 0 -
Platform Contract Transaction tx_len*3 tx_len*3 0 -
Application Contract Transaction tx_len*3+CPU ns(Contract Instruction Set)/40 Half of the transaction cost shall be paid by the sender, the other half shall be paid by the application contract first, and the other half shall be paid by the sender if the contract cannot pay. min(gasLimit,contract balance,receiver action consumed gas/2) gasLimit: The upper limit of the gas fee that the user is willing to pay for the transaction.

The system will automatically deduct 100*10^6 uTOP tokens from the transaction sender's account as the transaction fee for running Beacon system contract(registration node related, proposal related, starting node process) and burn it. This small fee to protect the Beacon system from flood transaction attacks.

The transactions that require Beacon transaction fees include:

Register node, node access to the network, update node information, stake deposit, unstake deposit, update node name, update node_sign_key, set dividend ratio, update node type, redeem node deposit, unregister node, submit proposal, withdraw proposal, vote on proposal.

# Calculate transaction fee

The formula for calculating transaction fees is as follows:

Transaction Fee = tx_fee + used_depost in send_block_info + used_deposit in confirm_block_info

For transfer transactions, tx_fee = 0, used_deposit in confirm_block_info = 0, so transaction fee = used_depost in send_block_info.

The code sample is as follows. You can view the meaning of each field through the getTransaction interface.

{
 "data" : {
    "original_tx_info" : {
       "amount" : 1000000,
       "authorization" : "0x01c00cf3c8ca7c883b7ab130ac56ccb53c2c066640659d9babe21655a6b3a073455a3b8d06ee5b1a955b756a7800f0230afc7299a97f3ca9c57555d7890518472b",
       "edge_nodeid" : "",
       "ext" : "",
       "last_tx_nonce" : 4,
       "note" : "",
       "premium_price" : 0,
       "receiver_account" : "T8000042537218707b66d49fc06143b60d029cfe2b65f4",
       "receiver_action_name" : "",
       "receiver_action_param" : "0x03000000544f5040420f0000000000",
       "send_timestamp" : 1645012819,
       "sender_account" : "T800008c5a874df3f8b6d1e357890f881704bf8849feeb",
       "sender_action_name" : "",
       "sender_action_param" : "0x03000000544f5040420f0000000000",
       "token_name" : "",
       "tx_deposit" : 100000,
       "tx_expire_duration" : 100,
       "tx_hash" : "0xb014bcfa3bb14f350531c95f0a5c32f32aaabb5aaaebe9cc214aab3776f483fe",
       "tx_len" : 137,
       "tx_structure_version" : 2,
       "tx_type" : 4
    },
    "tx_consensus_state" : {
       "confirm_block_info" : {
          "account" : "Ta0000@31",
          "exec_status" : "success",
          "height" : 28,
          "recv_tx_exec_status" : "success",
          "used_deposit" : 0,
          "used_gas" : 0
       },
       "recv_block_info" : {
          "account" : "Ta0000@27",
          "height" : 17,
          "used_gas" : 0
       },
       "send_block_info" : {
          "account" : "Ta0000@31",
          "height" : 25,
          "tx_fee" : 0,
          "used_deposit" : 0,
          "used_gas" : 411
       }
    },
    "tx_state" : "success"
 },
 "errmsg" : "OK",
 "errno" : 0,
 "sequence_id" : "1"
}

# Free Daily Gas

Be default, each account with a balance of at least 100 TOP is given a free 25000 Tgas every 24 hours. This allows for several free transactions per day. A minimum TOP balance is necessary to avoid mass account creation and mass transaction spamming using the free allotted gas.

The gas used by the account gradually decays with time. After 24 hours (on-chain governance parameter), it decays to 0, and the gas can be used to restore the original gas amount. The decay formula is as follows:

decay_formula

For example, at time T1, the gas usage of the account is U. At T1+12h, the gas used by the account again is u. At this time, the TGAS used by the account is U/2 + u.

# Gas Acquisition

Ordinary accounts as well as contract accounts can deposit TOP tokens to gain more gas credits. The formula for gas credits is as follows.

acquire_gas

Where the System Total Gas=single shard gas *number of shards(validator_group_count). This value can be adjusted via on-chain governance. The number of shards is currently set to 4, and the total gas of the system will increase as the number of shards increases. The total number of TOP tokens deposited in the system is updated every ten minutes, and the value is stored inside a platform contract.

Total TOP Tokens Locked In System=The system initial locked TOP tokens+user locked TOP tokens, to avoid the initial gasprice being 0.

An ordinary account can't obtain gas more than 200,000 Tgas(on-chain governance parameter) in a 24-hour. This roughly equates to 800 transactions.

A contract account can't obtain more than 10,000,000 Tgas (on-chain governance parameter) in a 24-hour. This equates to 40,000 transactions or 4s of CPUT time.

# Relationship between Gas Consumption and NET/CPU

1 Tgas is equivalent to 1 byte of bandwidth or 0.04 microseconds of CPU time. Bytes are counted based on the size of the original transaction. CPU time is only consumed when executing a contract,and the total CPU time is determined based on the contract instruction set.

A transaction is allowed to consume up to 25,000 Tgas.

# Transaction Deposit

Most users will have enough free gas for their daily needs, while those who send many transactions may run out of gas and need to pay a small amount of transaction deposit. When an account does not have enough gas to send a transaction, TOP token is deducted from their transaction deposit balance—which must be greater than or equal to 0.1 TOP—to offset the gas costs. This fee is then burned.

Each transaction deposit is frozen from the account balance other than the amount transferred.

The gas to TOP conversation ratio is currently set to: 1 Tgas=100 uTOP token.

The minimum transaction deposit parameter can be changed via on-chain governance.