Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix & improve developer guide #1

Merged
merged 1 commit into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Documentation/articles/blockchain/account_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ In NEO, the account model and UTXO model coexist. Accounts record the UTXO-type
| Size | Field | Type | Descriptoin |
|------|-------|------|------|
| 20 | ScriptHash | UInt160 | The hash of account's script contract. |
| 1 | IsFrozen | bool | Fronzen accounts cannot transfer. |
| 1 | IsFrozen | bool | Fronzen accounts cannot transfer. This field is not currently used. |
| ? * ? | Votes | ECPoint[] | the voted address list |
| ? | Balances |Dict<UInt256, Fixed8> | UTXO assets, mapping from assetId to amount. |

8 changes: 4 additions & 4 deletions Documentation/articles/blockchain/block.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<center><h2>Block</h2></center>

<!-- &emsp;&emsp;在比特币系统中,可以存在多条链并存,即暂时分叉,但经过足够长的时间后最长的链条(提供了最多的工作量证明)成为确认的区块链。 Neo因为采用了dBFT共识算法,在系统正常运行时,不会同时出现一条以上的链。请参见`共识`部分。 -->
&emsp;&emsp; The Blockchain is a data structure. The block is composed of block header and block body. As each block has a crpytographic hash of the previous block, a timestamp, and transaction data (generally represented as a merkle tree root hash), and a chain structure is formed.
&emsp;&emsp; The Blockchain is a data structure. The block is composed of block header and block body. As each block has a crpytographic hash of the previous block, a timestamp, and transaction data (generally represented as a merkle tree root hash), a chain structure is formed.

&emsp;&emsp; The data structure of block as following:

Expand All @@ -27,7 +27,7 @@

&emsp;&emsp; The block header contains the basic information of a block and provide verification of a block. The first 10 attributes of the block constitute the header.

&emsp;&emsp;Block `hash` and `index` can be used to identify a block. The hash value is obtained by concating the first seven attributes of the block header and performing SHA256 operation twice. Normally, NEO has only one chain, and each block will be added to the blockchain after it is confirmed by more than two-thirds of all the consensus nodes. Therefore, the height of the each block is unique. Block height must be equal to the previous block height plus 1, and the Genesis Block's height is 0.
&emsp;&emsp;Block `hash` and `index` can be used to identify a block. The hash value is obtained by concatenating the first seven attributes of the block header and performing SHA256 operation twice. Normally, NEO has only one chain, and each block will be added to the blockchain after it is confirmed by more than two-thirds of all the consensus nodes. Therefore, the height of the each block is unique. Block height must be equal to the previous block height plus 1, and the Genesis Block's height is 0.


&emsp;&emsp;`Timestamp` is the block's timestamp, must be bigger than the previous block's timestamp. The interval between two blocks is about 15 seconds, which is defined by the variable `SecondsPerBlock` in configuration file `protocol.json`.
Expand All @@ -41,10 +41,10 @@

### **Block Body**

&emsp;&emsp; The block body is a transaction list. In one round of consensus activity, the Speaker selects all the transactions in memeory pool, have them sorted and filtered by plugins, and then package them into a new proposal block. For more details about consensus, please read "Consensus Mechanism" section.
&emsp;&emsp; The block body is a transaction list. In one round of consensus activity, the Speaker selects all the transactions in the memory pool, have them sorted and filtered by plugins, and then package them into a new proposal block. For more details about consensus, please read "Consensus Mechanism" section.

&emsp;&emsp; The first transaction of each block must be a `MinerTransaction`, which is used to record all transaction's network fee in the block. At present, a block can hold up to 500 transactions in total, including up to 20 free transactions and a MinerTransaction as the first transaction in the block.


> [!NOTE]
> When a block is persisted, it stores a hash list of transactions that belong to the block. And the transaction data is stored separately to facilitate query.
> When a block is persisted, it stores a hash list of transactions that belong to the block. And the transaction data is stored separately to facilitate query.
2 changes: 1 addition & 1 deletion Documentation/articles/blockchain/charging_model.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<center><h2>Charging Model</h2></center>

&emsp;&emsp;Participants in NEO ecology need to pay network fee and system fee by GAS when using NEO network. Network fee is paid to consensus node as new block incentive. System fee and new GAS generated in each block belongs to NEO holders. NEO holders can claim gas with `ClaimTransaction`. Fee distribution rule is as follows:
&emsp;&emsp;Participants in NEO economy need to pay network fees and system fees with GAS when using the NEO network. Network fee is paid to consensus node as new block incentive. System fee and new GAS generated in each block belongs to NEO holders. NEO holders can claim gas with `ClaimTransaction`. Fee distribution rule is as follows:

[![economic model](../../images/blockchain/economic_model.jpg)](../../images/blockchain/economic_model.jpg)

Expand Down
4 changes: 2 additions & 2 deletions Documentation/articles/blockchain/neo_system.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<center><h2>Neo Blockchain Model</h2></center>

&emsp;&emsp;Asset is the core of Neo system. Transaction, contract, account and walet serves asset registration, flowing and administration. Neo CLI, compiler and virtual machine, etc, are technical means for function realization. Their function is as follows:
&emsp;&emsp;Asset is the core of Neo system. Transaction, contract, account and wallet serve asset registration, flowing and administration. Neo CLI, compiler and virtual machine, etc, are technical means for function realization. Their function is as follows:

[![neo system](../../images/blockchain/system1_em.jpg)](../../images/blockchain/system1_em.jpg)

Expand All @@ -9,7 +9,7 @@
> [!NOTE]
> A 'ContractTransaction' is not a SmartContract, but the most common transaction type that transfer assets from accounts to accounts.

&emsp;&emsp;In Bitcoin, Script is responsible for transaction signature verification. Contracts take corresponding responsibility in NEO. Contract can be simply regarded as an upgrade of Bitcoin Script. Bitcoin Script is not Turing complete. Even though it's able to complete transaction signature verification, its functionality is limited. Bitcoin has only UTXO model and concerns only transaction itself. Writing language for Neo smart contract like C# and Python, are all Turing-complete, and can satify varies needs in real world. In case of accounting method, Bitcoin uses UTXO model; Ethereum uses a widely-used model, account balance, or balance model. In Neo system, UTXO model and account balance model both exist. UTXO model is mainly used for global assets, while account balance model is mainly used for user-published NEP-5 assets like stock, token, etc.
&emsp;&emsp;In Bitcoin, Script is responsible for transaction signature verification. Contracts take corresponding responsibility in NEO. Contract can be simply regarded as an upgrade of Bitcoin Script. Bitcoin Script is not Turing complete. Even though it's able to complete transaction signature verification, its functionality is limited. Bitcoin has only UTXO model and concerns only transaction itself. Writing language for Neo smart contract like C# and Python, are all Turing-complete, and can satify various needs in the real world. In case of accounting method, Bitcoin uses UTXO model; Ethereum uses a widely-used model, account balance, or balance model. In Neo system, UTXO model and account balance model both exist. UTXO model is mainly used for global assets, while account balance model is mainly used for user-published NEP-5 assets like stock, token, etc.

&emsp;&emsp;In Neo system, assets exist in the token's form. There are many kinds of assets like NEO, GAS and NEP-5. There are also equity assets like stock. All assets, including NEP-5 assets, and corresponding transaction information of a specifed address can be shown in the following steps: open a wallet in Neo Tracker (https://neotracker.io/), and choose one `address`. Address is also called "account". An address can be computed from specified private key with encryption algotithm and code switching, and used directly in transaction settlement. It can also be smart contract address used during smart contract execution. Method computing address please refer to `Address` section in `Wallet` chapter.

Expand Down
2 changes: 1 addition & 1 deletion Documentation/articles/consensus/consensus_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ When a consensus message enters the P2P network, it's broadcasted and transmitte

### Verification

1. Ignore the message if the `ConsensusPayload.BlockIndex` is no more than current block height.
1. Ignore the message if the `ConsensusPayload.BlockIndex` is lower than current block height.

2. Ignore the message if the verification script failed or the script hash does not equal to `ConsensusPayload.ValidatorIndex` address's script hash.

Expand Down
4 changes: 2 additions & 2 deletions Documentation/articles/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

 Two different hash functions are used in the NEO system: SHA256 and RIPEMD160. The former is used to generate a longer hash value (32 bytes) and the latter is used to generate a shorter hash value (20 bytes). Usually when a hash value of an object is generated, hash functions are used twice. For example, when a hash of a block or transaction is generated, SHA256 is calculated twice; when a contract address is generated, the SHA256 hash of the script is calculated, then the NSPEMD160 hash of the previous hash is calculated.

 In addition, the block will also use a hash structure called a Merkle Tree. It computes the hash of each transaction and combines one with the next and then hash again. Repeats this process until there is only one root hash (Merkle Root).
 In addition, the block will also use a hash structure called a Merkle Tree. It computes the hash of each transaction and combines one with the next and then hashes again, repeating this process until there is only one root hash (Merkle Root).

 Details will be described in subsequent chapters.

Expand Down Expand Up @@ -43,4 +43,4 @@

## Fixed-point Number(Fixed8)

 Data in NEO such as amount or price are 64 bit fixed-point number and the precision of decimal part is 10<sup>-8</sup>,range:[-2<sup>63</sup>/10<sup>8</sup>, +2<sup>63</sup>/10<sup>8</sup>)
 Data in NEO such as amount or price are 64 bit fixed-point number and the precision of decimal part is 10<sup>-8</sup>,range:[-2<sup>63</sup>/10<sup>8</sup>, +2<sup>63</sup>/10<sup>8</sup>)
12 changes: 6 additions & 6 deletions Documentation/articles/cryptography/hash_algorithm.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<center><h2> Hash Algorithm </h2></center>

 Hash function, or hash algorithm, is a method creating digital finger print from any kind of data. Hash function compresses message or data into a digested version to shrink the data into a fixed data size. This function disorgnizes and remixes data, rebuilding a finger print data and name it as hash-value. Hash value is always represented by a short string consisted of random letters and digits.
 Hash function, or hash algorithm, is a method creating digital finger print from any kind of data. Hash function compresses message or data into a digested version to shrink the data into a fixed data size. This function disorganizes and remixes data, rebuilding a data fingerprint as a hash-value. Hash value is always represented by a short string consisting of random letters and digits.

### RIPEMD160

Expand Down Expand Up @@ -77,15 +77,15 @@ Scenarios:
  Scrypt is a kind of secure-cryptographic algorithm based on PBKDF2-HMAC-SHA-256 algorithm. It's developed by Colin Percival, a famous FreeBSD hacker, for his backup service Tarsnap.
The original design was to reduce CPU load, minimize CPU reliance, and use CPU idle time for calculations.
Therefore, scrypt not only takes a long time to calculate, but also consumes a lot of memory, making it difficult to calculate multiple digests in parallel.
Therefore it is more difficult to use the rainbow table for brutal-force-attacks.
Therefore it is more difficult to use the rainbow table for brute-force-attacks.

​ Neo mainly use SCRYPT algorithm to generate encryption secret key satisfying NEP-2 standard. Parameters are defined as follows:
​ Neo mainly uses SCRYPT algorithm to generate encryption secret key satisfying NEP-2 standard. Parameters are defined as follows:

  N: CPU/RAM cost. Generally take a number of powers of 2. Default value is 16384.
  N: CPU/RAM cost. Generally is a power of 2. Default value is 16384.

  p: Parallelization parameter, a positive integer ranges from 1 to 255. Bigger value represents heavier rely upon concurrent computation. Default value is 8.
  p: Parallelization parameter, a positive integer that ranges from 1 to 255. Bigger value represents a heavier reliance upon concurrent computation. Default value is 8.

  r: Block size,theoretically ranges from 1 to 255. Bigger value represents heavier rely upon RAM & bandwidth. Default value is 8.
  r: Block size,theoretically ranges from 1 to 255. Bigger value represents a heavier reliance upon RAM & bandwidth. Default value is 8.

Example:

Expand Down
12 changes: 6 additions & 6 deletions Documentation/articles/neo_cli_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[![neo p2p network](../images/neo_cli_structure/neo-p2p-network.png)](../images/neo_cli_structure/neo-p2p-network.png)

 Each node in the network runs a neo-cli program or a protocol-compatible program. Among them, the consensus nodes involve in the consensus. Non-consensus nodes are not involved in the consensus. The consensus will be described in subsequent chapters.
 Each node in the network runs a neo-cli program or a protocol-compatible program. Among them, the consensus nodes involved in the consensus. Non-consensus nodes are not involved in the consensus. The consensus will be described in subsequent chapters.

## neo-cli

Expand All @@ -30,7 +30,7 @@

### LevelDBStore / Blockchain

 Blockchain data management module based on leveldb. Provide storage and query services of blockchain data for other parts.
 Blockchain data management module based on leveldb. Provides storage and query services of blockchain data to the other parts.

### LocalNode

Expand Down Expand Up @@ -171,7 +171,7 @@ Property Description:

Property Description:

- Magic : Magic Number. Mainnet: 7630401 (0x00746E41) Testnet: 1953787457 (0x74746E41) When building a private chain network, the magic number can be changed to any integer, but the magic number of the nodes in the same network must be the same.
- Magic : Magic Number. Mainnet: 7630401 (0x00746E41) Testnet: 1953787457 (0x74746E41) When building a private chain network, the magic number can be changed to any integer, but the magic number used by all the nodes in the same network must be the same.
- AddressVersion : The address version. Fixed value 23
- SecondsPerBlock : The block interval. The consensus nodes in the same network must have the same value.
- StandbyValidators: A list of public keys of the alternate consensus node.
Expand All @@ -181,8 +181,8 @@ Property Description:
protocol.mainnet.json and protocol.testnet.json are two backup files that store the configuration for the mainnet and the testnet.

> [!NOTE]
> 1. In neo-cli 2.7.6 it used a temporary file peers.dat to save IP addresses of known nodes, neo-cli 2.9.0+ no longer use the file.
> 2. If the neo-cli meets an exception during execution and terminated, the error content will be written to a file(error.log) to debug.
> 1. In neo-cli 2.7.6 a temporary file peers.dat was used to save IP addresses of known nodes, neo-cli 2.9.0+ no longer uses the file.
> 2. If neo-cli meets an exception during execution and is terminated, the error's content will be written to a file (error.log) for debugging.

---

Expand Down Expand Up @@ -220,7 +220,7 @@ protocol.mainnet.json and protocol.testnet.json are two backup files that store

2. Start a background loop and check the number of connections to other peers every 5 seconds. If it is less than the maximum number of connections (10), it will try to connect to more peers. If the information of other peers are unknown, it will connect to the seed nodes and then ask for the addresses and port number of other peers.

3. If the device is in a LAN and does not have an IP address on the internet, it will try to discover the UPnp external IP address for the device, and then start listening on port for TCP/IP connections and start listening on port for websocket connections on the external IP address.
3. If the device is in a LAN behind a NAT and does not have an IP address on the internet, it will try to discover the external IP address and set up a new port mapping using the Internet Gateway Device Protocol(IGD) implemented as part of UPnp. Then it'll start listening on port for TCP/IP connections and start listening on port for websocket connections on the external IP address.

4. Start listening on port locally and accept TCP/IP connections from other peers.

Expand Down
6 changes: 3 additions & 3 deletions Documentation/articles/neo_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ private bool value;

NeoVM has implemented 113 instructions (and four unrealized instructions). The categories are as follows:

| Contrant | Flow Control | Stack Operation | String Operation | Logical Operation | Arithmetic Operation | Cryptography | Advanced Data Structure |Stack Isolation| Exception Processing |
| Constant | Flow Control | Stack Operation | String Operation | Logical Operation | Arithmetic Operation | Cryptography | Advanced Data Structure |Stack Isolation| Exception Processing |
| ---- | -------- | ------ | ------ | -------- | -------- | ------ | -------- | ------ | ---- |
| 25 | 9| 16| 5 | 5 | 25 | 7 | 14 | 5 | 2 |


## 1. Contrant
## 1. Constant

The constant instructions mainly complete the function of pushing constants or arrays into the `EvaluationStack`.

Expand Down Expand Up @@ -915,4 +915,4 @@ It has implemented common operations for array, map, struct, etc.
| Function: | Read a boolean value from the top of the stack, and if it's False, then set the virtual machine state to `FAULT`. |


Note: The operation code with \* indicates that the result of the operation is not pushed back to the `EvaluationStack`.
Note: The operation code with \* indicates that the result of the operation is not pushed back to the `EvaluationStack`.
Loading