NULS “Air Class Sharing” - Account System in Blockchain

in #nuls6 years ago

微信图片_20190228174601.png

Overview

Self introduction

Hello, members of the NULS community. Good evenings. I am very happy and honored to share with you my understanding of the blockchain account system here.

Before the official sharing, let me introduce myself. I am a member of NULS CCC. Chinese name Xue Chen. The English name is Edward. Now working as an architect in a technology company, the main job is the design, implementation of the microservice architecture of the company's business systems, and management of R & D team. I have 11 years of programming experience from the beginning of the postgraduate study in 2008 to the present. Although I am mainly engaged in architecture design and R&D team management, the programming work has never stopped and will not stop. "Cease to programming and you cease to live." This sentence is very suitable for me.

My first time to know the blockchain was probably in May 2017, when the computer ransomware was rampant, but it was extorted by BTC instead of RMB. Whether intentionally or not, which gave Bitcoin a skyrocketing opportunity. Through this incident, I ended my prejudice against Bitcoin as a speculative machine for many years. I began to formally study the technical principles of Bitcoin, the realization of the scene, the financial value brought from it, and began to join in this circle.

I will introduce my luckychance with NULS. The Internet environment of Chongqing is not very good. But in the blockchain field, NULS project is a leading project here. I am a bit geographically sense of superiority. I joined NULS CCC on November 19th. About a month or two before joining, I have already undertaken some system development tasks of NULS2.0. From joining to now, my main job is to develop, design, and coordinate the account system functions of NULS2.0. This function is currently in the joint debugging. From the whole development cycle, it is already at the end of the development of joint debugging. I recently started to look at the code of other modules of NULS. One goal to be achieved is a clear understanding of the entire system architecture and code of Nuls2.0. If I don't achieve this recognition for NULS, I will feel such unsafe.

The topic I shared today is the account system in the blockchain. The topic itself is somewhat too technical knowledge. To avoid being less friendly to other non-technical members of the community, I will mainly share the business boundary of the account system. That's what the account system does. If there are a technology enthusiast, you are welcome to come to the NULS community to communicate.

When it comes to the account system, everyone should be familiar with it. Because the accounts are all in contact with us. The most intuitive feeling is how much money is in my WeChat account, and how much money is in my Alipay account and bank card. For the cryptocurrency investors, I will also talk about how many Tokens I have in my account. These are all right, and they are the actual embodiment of the account system. Combined with my experience, I share four aspects of the account system today.

  • The first is a centralized system, such as WeChat, Alipay, what its account system looks like;
  • The second is the Bitcoin account system;
  • The third Ethereum account system;
  • The fourth is the account system of NULS2.0.

Three-party payment account system

I have worked in a three-party payment company for coding, project management, and architecture design for eight years. The account system was designed mainly based on Alipay's online open materials at that time.

First introduce what the account system does:

In our system, it is mainly managed accounts. That is, how many assets are under each account. Regardless of the member information, who you are, what is your name, and what is your ID number, but it will be associated with the member information via a string or ID, such as an ID number.

Since it is managing assets, how should we manage it?

The first is to create one or more accounts for users (personal users or enterprise users). This account can be classified, such as cash accounts, escrow accounts, etc., and there is a corresponding balance on the account; The second is establish one or more accounts for merchants. There is also a balance on the account; The third is to create a lot of accounts for the platform, such as platform income account, platform margin account and so on. These three parts together form the account system of the three-party payment platform, and provide services through external interfaces, such as recharge, withdrawal, and judicial freeze. When these business processes are in use, they will call the interface of the account system to complete the corresponding increase, decrease, and freeze.

It's worth noting that in order to ensure the correctness of the account system and the early detection of problems in the account, accounting double-entry debits are usually used to design accounts and record transaction details. The core idea is that there must be loans when borrow,and amount must be equal. Because it involves some expertise, I won't go into the design here.

Bitcoin "Account System"

Speaking of Bitcoin's account system, people who are more familiar with Bitcoin accounts will question that there is no account system in the Bitcoin code, how do we complete the transfer, and how to define the Bitcoin “account system”.
There is no separate account system in the Bitcoin system, but "UTXO" (Unspent Transaction Output), which is the unspent transaction output. When we transfer money in Bitcoin, the source of funds used is the transaction record that was previously received at that address and has not been spent, not the balance. A bitcoin transaction information includes one or more transfer out addresses, one or more transfer in addresses, amounts, and a hash value of one or more transaction records previously transferred to the transfer address without being spent. When verifying the legality of the transaction, the Bitcoin system will verify whether the original transaction records corresponding to these hash values have been spent. If not, the sum of the amounts is greater than the total amount of funds transferred out of the transaction.
The Bitcoin system has a UTXO pool, and all unspent transaction records are recorded in this pool. After the cost is removed, it will be removed from the pool. Therefore, if the verification record is spent, only the hash value needs to be queried through the pool.If the query is founded, means it is not spent, if it is not founded, it has already been spent.

Ethereum Account System

Like Bitcoin, Ethereum does not store account balances on the block. It stores a single transaction record. Of course, the data stored on the block may have other data, such as the compiled smart contract. I won't go into details here.
The source of funds for Bitcoin is the unspent transaction record. Ethereum is different from Bitcoin. When the Ethereum node receives the block in the network, it will verify and process the block. At this time, there is one in the Ethereum node. The module or function based on the LevelDB database is used to save the balance under an account. This balance is calculated based on the transaction records in the block, for example:
The node receives two transaction records:
The content of transaction record A is: Zhang has obtained 10 Ethereum by mining. And the content of transaction record B is: Zhang transferred to Li’s 5 Ethereum. Then discharged other information, just look at the two informations, when the first record is received, the account system of the Ethereum node or the database that saves the account balance will add 10 Ethereum coins to Zhang’s account. If Zhang did not have Ethereum before, then Zhang’s Ethereum account's balance is 10. When the second record is received, 5 Ethereum will be deleted from Zhang’s account, and then 5 Ethereum will be added to Li’s account. Of course, there is a handling fee, and the process of processing the fee is similar. It is subtracted from the account of the transferor and added to the account of the miner.

Therefore, an important change point of Ethereum relative to Bitcoin is that it joins the concept of account and account balance, and when verifying whether the source of funds for the transaction is sufficient, it is the account balance directly taken, not the transaction record. Some people may question whether it is not possible to transfer funds if the account balance on the local node is changed to infinity.

The characteristic of the blockchain is that it is achievable to modify the local authentication, but it cannot be passed when it is sent to the Ethereum network for verification. Because other nodes verify that the account balance is not correct, then the transaction is naturally can't pass.

NULS Account System

NULS2.0 is based on the micro-service architecture. There are multiple independent modules in the implementation. Modules and modules can communicate with each other. They work together to complete specific business processes. This is similar to a car. The engine provides power output. The gearbox converts power into torque. The tire converts torque into friction with the ground to advance the car. There are two important modules in these modules: the account module and the ledger module. Of course, this is not to say that other modules are not important, but that I have more contact with these two modules.

As mentioned above, there are also account modules in the three-party account. This module is used to manage accounts. The account module in NULS is somewhat inconsistent with it. It is used to manage the account information of the user on the current node. For example, if the private key is imported on the current node, then the account information is available under the account of the current node. The information including the password corresponding to the address is included, and the user information is stored here, but the account balance is not saved. In addition to the account module, there is also a book module. When the transaction in the blockchain is confirmed, the account module will be called to submit the transaction interface. At this time, the account module will calculate the account balance according to the transaction. The balance is balance of account we mentioned. The account balance can be used to verify the user's balance when the transaction is sufficient etc..

OK, here, my sharing today is over. I only read a part of source code of Bitcoin and Ethereum, so the knowledge here mainly comes from online learning. But for the three-party payment, NULS2.0 account system, I have had development experience. If you have more ideas about the account system, I am very happy to communicate with you.

Sort:  

Congratulations @carlyduan! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

The new SteemFest⁴ badge is ready
Vote for @Steemitboard as a witness to get one more award and increased upvotes!