Research on Asch source code of blockchain open source project

Source: Internet
Author: User
Tags data structures json

The name Asch is the abbreviation for App Side Chain. is a blockchain-based cross-chain technology application development platform, all the core code has been open source on GitHub.

Blockchain is the underlying technology of Bitcoin, but the reputation is lower than bitcoin, but the individual thinks the potential is far greater than Bitcoin. is one of the most deserving technical attention.

I generally study a new technology and tend to study newer and older code. Because very mature and well-known code is often over-engineered, getting started with reading code is not necessarily a good choice. And some are out of project early code, and easier to read to understand its core principles. Asch is now a very good open source project for getting started with blockchain learning.

"Overall Architecture"

At present, the entire Greek chain is mainly composed of the following source code library Asch Axi chain of core server source, mainly by node. JS Development. Asch-frontend Axi chain of Web Wallet source code. ASCH-JS&ASCH-CLI the client implementation of the Axi chain.

The current source reading is mainly based on asch@1.3.0 version

"Directory Structure" Proto/index.proto Genesisblock-mainnet.json Config-mainnet.json public/src/core src/base

"Proto/index.proto"

Asch block core data structures are serialized and deserialized through Protobuf and serialization. So Proto/index.proto is the data structure of the core block. According to my understanding, the name Index.proto should be called block.proto more appropriate.

"Directory public/"

The code root of the Web wallet, the Web wallet code generated by the Asch-frontend package.

"Source directory Structure src/"

Src/init.js is responsible for initializing, with async to deal with a variety of successively smooth, avoid callback hell, just start to look at the time will be more around, but understand it is very clear.
In the code many modules have common module variables, the most typical is the Var moduels, library, modules corresponding to the Src/core/module below. The library.base corresponds to the module below the src/base/.

"The trustee's rotational forging (forging) mechanism"

Asch not like the bitcoin mining mechanism, but the trustee's rotating forging mechanism, mainly the following process. Onblockchainready (core/delegates.js) starts forging initialization when the blockchain database is loaded and completed. Loadmydelegates: Get secret from the configuration file (read several sequentially) and generate a key pair (public and private) with secret. Accounts.getaccount: Use the public key to obtain the account from the Blockchain database, and check whether the account is a trustee, is the trustee continued. Loop: Start polling at each polling interval of 100ms. Slots.getslotnumber (utils/slots.js) gets epochtime first, Epochtime records how many seconds have elapsed since 2016-5-27t20:00:00 to a specific time. Then Getslotnumber = epochtime/interval, Interval = 10. That is, every 10s a new slot appears. Blocks.getlastblock: As the name implies, get the current latest chunk getblockslotdata->generatedelegatelist (core/delegates.js) to get the current list of trustees, sorted by number of votes To obtain the public key of the 101 trustees with the highest number of votes. And the list of these trustees is "randomly" sorted. Here the random should be the same as each node random, not completely random. Getblockslotdata: Gets the Check Trustee list for the current slot and, if the trustee's key pair is in the configuration, goes to the "block generation process".

"Block generation Process" loop (Core/delegates.js): For a node registered with a trustee, there will be a timed trigger that invokes the generateblock inside the blocks.js. Generateblock (core/blocks.js): First get an unconfirmed list of transactions from transactions.
Generateblock: A list of transactions that have been validated through a list of unconfirmed transactions is filtered.
Base.block.create: Create a new chunk containing these trading lists to verify that the chunk is legal.
Hasenoughvotes: Check if the trustee has enough votes and cannot generate blocks if the number of votes is not sufficient. (This step should be done in advance.) )
Processblock: Queries the local database through Block.id, and continues with the following behavior if it does not already exist. Applyblock: Entry into force the list of transactions that have just been verified is a transfer of some of the accounts involved in the transaction, and this logic is implemented in the Src/base/transaction.js apply function. There are several types of transactions, which are detailed later. Base.block.dbSave: Storage block Base.transaction.dbSave: Store transaction list accounts.mergeaccountandget: Update data for new block creators The creator is actually the node that registered the trustee. Setlastblock: Set this new chunk to the current block. Bus.message (' Newblock ') broadcasts this new chunk.

"ToDo" Asch chain of trading process Asch chain of HTTP Interface Implementation principle DAPP principle and development process ...

Original link: http://yanyiwu.com/work/2017/07/29/read-asch-source-code.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.