The core content of digital money details the development of the underlying technology tutorial

Source: Internet
Author: User

Blockchain Enthusiast (qq:53016353)

1.1 Digital currency The digital currency is the account Book of a digital event (transaction), which is shared by multiple participants and each participant has an interest in the system. Books can only be updated if all participants agree, and once the information is recorded, it can never be modified. Each recorded event can be validated using cryptography based on the participant's consensus.


The transaction is secure, private and confidential. Each participant uses identity certificates to register with the network member Services (membership service) to gain access to the system. Participants generate transactions using non-traceable export certificates, which can be completely anonymous on the network. The content of the transaction is encrypted using a complex function derived from the key to ensure that only the specified participant can see the content to protect the confidentiality of the business transaction.


All or part of the ledger can be audited to meet regulatory requirements. In the event of co-operation, the auditor can obtain a limited time certificate to view the books and transaction details, thus making an accurate assessment of the operation.


Digital currency is the implementation of blockchain technology, Bitcoin can be used as a simple application on the basis of digital currency construction. The digital currency uses a modular architecture that allows different components to plug and Play based on the implementation protocol. Powerful container technology can be used to run mainstream programming languages for the development of smart contracts. The use of familiar and proven technologies is the purpose of the digital currency architecture.


1.2 Reasons for using Fabic
Early blockchain technology enables some functionality, but lacks complete support for specific industry needs. To meet the demands of the modern market, digital currencies are designed for industry-specific applications, and are further advanced in areas such as scalability design than pioneers in this field. The digital currency uses the new method to realize the authorization network, the private and the secrecy on the multiple blockchain network.




2.1 Digital Currency architecture
The architecture of the digital currency consists of three major categories of member Services (membership), Blockchain Services (Blockchain), and Chain Code services (Chaincode). These categories are just the logical structure of the digital currency, not physically dividing the components into different processes, address spaces, or virtual machines.




2.1.1 Member Services
Member Services are responsible for managing user identities, privacy, and the confidentiality and auditable nature of the network. In a non-privileged blockchain, the participant does not need authorization, and all nodes can commit the transaction equally or accumulate the transaction into chunks, that is, there is no difference between roles. The member service consolidates the basic elements of the public Key Infrastructure (PKI) and the de-centralized consensus mechanism to transform the non-privileged blockchain into a privileged blockchain. In a privileged blockchain, participants are required to register for long-term identity credentials (enrollment certificates) and can be differentiated by identity type. In the case of the user, the transaction Certificate Manager (TCA) can issue kana credentials. This credential (i.e., the transaction certificate) is used to authorize the submission of the transaction. The trading certificate is saved on the blockchain and allows authorized auditors to categorize the transaction, otherwise these transactions will not be linked.


2.1.2 Blockchain Services
Blockchain services manage distributed books by using HTTP2-based peer-to-peer protocols. The data structures on the blockchain are highly optimized to provide the most efficient hash algorithm to hold a copy of the World State. Different consensus algorithms can be used and configured in the deployment, including PBFT, Raft, PoW, POS, etc.


2.1.3 Chain Code Service
The Chain Code service provides a secure and lightweight sandbox for chain code (CHAINCODE) execution on the authentication node. The sandbox environment is a locking and security container with a set of signed base disk images that contain a secure operating system and link-code languages, runtimes, and SDKs that support go, Java, and node. js, and other languages can be enabled as needed.


2.1.4 Events
Authentication nodes and chain codes can send events on the blockchain network, and the application can listen to and respond to these events. A set of pre-defined events already exists, and the chain code can generate custom events as well. Events can be handled by one or more event adapters, and the adapter can use a web hook or Kafka to further deliver the event.


2.1.5 Application Interface (API)
The main programming interface for digital currencies is the rest API, and the Swagger2.0-based variant. These APIs allow applications to register users, query blockchain, and send transactions. There is a set of APIs designed specifically to link code to interact with the underlying platform to execute transactions and to query trading results.


2.1.6 Command Line interface (CLI)
The CLI includes a subset of rest APIs to help developers quickly test the chain code and query the trading status. The CLI is implemented by the go language and supports a variety of operating systems.


2.2 Topological structure
Digital currency deployments can include member services, multiple authentication nodes (peer) and non-authentication nodes, and one or more applications. All of these components form a blockchain. Multiple blockchain can exist, each of which can have its own operational parameters and security requirements.


2.2.1 Single authentication Node
On the feature, the non-authentication node is a subset of the authentication nodes, which means that the functionality on each non-authentication node can also be implemented on the authentication node, so that the simplest blockchain network can have only one authentication node component. This configuration is best used as a development environment, and a single authentication node can be started quickly in the edit-compile-debug cycle.


A single authentication node does not require a consensus mechanism, so the default consensus mechanism plug-in is Noops, in which case the transaction is executed immediately so that the developer can get immediate feedback during the development process.


2.2. More than 2 authentication nodes
Blockchain networks for production or test environments typically consist of multiple authentication nodes and non-verified nodes. Non-authentication nodes can assume a portion of the work that is stripped from the authentication node, such as processing API requests and handling events.


All authentication nodes constitute a fully connected network, where each authentication node is connected to another authentication node. A non-authentication node connects to a neighboring authentication node that allows connections. Non-authentication nodes are optional because the application can communicate directly with the authentication node.


2.2.3 Multi-Strand
Each network consisting of a validation node and a non-verified node constitutes a blockchain. Multiple blockchain can be created to meet different needs, as many Web sites can serve different purposes.




The point-to-point communication of digital currency is built based on GRPC, which realizes the bidirectional message communication based on flow. GRPC uses Google's protocol buffers to serialize the data structure to achieve the transfer between nodes. Protocol buffers is a language-neutral, platform-neutral, and extensible data structure serialization technology. Data structures, messages, and services are described in Proto3 language.


3.1 News
Messages transmitted between nodes are encapsulated by the proto structure of message, with four different types: Discovery (Discovery), Trade (Transaction), Synchronization (synchronization), and consensus (Consensus). Each type can define more subtypes in the payload field in which it is embedded.


Message Message {
Enum Type {
UNDEFINED = 0;


Disc_hello = 1;
Disc_disconnect = 2;
Disc_get_peers = 3;
Disc_peers = 4;
Disc_newmsg = 5;


Chain_status = 6;
Chain_transaction = 7;
Chain_get_transactions = 8;
Chain_query = 9;


Sync_get_blocks = 11;
Sync_blocks = 12;
sync_block_added = 13;


Sync_state_get_snapshot = 14;
Sync_state_snapshot = 15;
Sync_state_get_deltas = 16;
Sync_state_deltas = 17;


RESPONSE = 20;
CONSENSUS = 21;
}
Type type = 1;
Bytes payload = 2;
Google.protobuf.Timestamp Timestamp = 3;
}
The payload field is an opaque byte array that contains other objects (transaction or response), for example, payload is a transaction object when type is chain_transaction.


3.1.1 Discovery Message
After the node is started, the Discovery protocol runs if the Core_peer_discovery_rootnode field exists. Core_peer_discovery_rootnode is the IP address of another network node (any node) that can serve as a starting point for discovering all the other nodes on the network. The protocol sequence starts with Disc_hello and its payload is a HelloMessage object:


Message HelloMessage {
Peerendpoint peerendpoint = 1;
UInt64 blocknumber = 2;
}
Message Peerendpoint {
Peerid ID = 1;
string address = 2;
Enum Type {
UNDEFINED = 0;
VALIDATOR = 1;
Non_validator = 2;
}
Type type = 3;
Bytes Pkiid = 4;
}


Message Peerid {
string name = 1;
}


Peerid is the name given when a node is started, or it can be defined in a configuration file.
Peerendpoint used to describe authentication nodes or non-authentication nodes
PKIID is the cryptographic ID of the node
Address is the IP addresses and ports of the nodes (Ip:port)
Blocknumber is the current height of the blockchain on the node


If the chunk height obtained by Disc_hello exceeds the blockchain height of the current node, the node immediately initiates the synchronization protocol to update the node state to the current state of the network.


After Disc_hello, the node periodically sends Disc_get_peers to discover additional nodes that are newly added to the network. As a response to a disc_get_peers message, the node that receives the message sends a ' disc_peers ' message, and the payload field in the message contains a set of Peerendpoint. Other discovery messages are not currently in use.


3.1.2 Trading Messages
There are 3 types of transactions: Deployment (Deploy), Invoke (Invoke), and queries (query). The deployment transaction installs the specified chain code into the blockchain network, while the call and query transactions invoke the chain code functions that have been deployed to the blockchain. There is also a create transaction that instantiates and loads a chain code that has already been deployed on a blockchain, but is not currently implemented in this transaction type.


3.1.2.1 Transaction Data structure
Message Transaction {
Enum Type {
UNDEFINED = 0;
Chaincode_deploy = 1;
Chaincode_invoke = 2;
Chaincode_query = 3;
Chaincode_terminate = 4;
}
Type type = 1;
string uuid = 5;
Bytes Chaincodeid = 2;
Bytes Payloadhash = 3;


Confidentialitylevel confidentialitylevel = 7;
Bytes Nonce = 8;
Bytes cert = 9;
Bytes Signature = 10;


Bytes metadata = 4;
Google.protobuf.Timestamp Timestamp = 6;
}


Message Transactionpayload {
Bytes payload = 1;
}


Enum Confidentialitylevel {
public = 0;
confidential = 1;
}


3.1.3 Synchronizing messages
When a node discovers that it is behind or inconsistent with a blockchain network by discovering a protocol, it immediately opens the synchronization protocol. Nodes broadcast sync_get_blocks, Sync_state_get_snapshot, or Sync_state_get_deltas, receiving sync_blocks, sync_state_snapshot, or sync_ accordingly State_deltas.


The installed consensus mechanism plug-in determines how the synchronization protocol executes, with each message targeting a different situation:


Sync_get_blocks requests a contiguous range of chunks in the payload field of the message, which is expressed using Syncblockrange:


Message Syncblockrange {
UInt64 start = 1;
UInt64 end = 2;
}


The node response Sync_blocks message that received the Sync_get_blocks contains syncblocks in its payload field:


Message Syncblocks {
Syncblockrange range = 1;
Repeated Block blocks = 2;
}


3.1.4 Consensus message
The consensus mechanism is used to process transactions, so consensus messages are sent by the internal consensus framework after receiving the chain_transaction message. The consensus framework translates chain_transaction into consensus and then broadcasts to all authentication nodes. After the consensus plugin receives the message, it processes the message according to its own algorithm.


3.2 Books
The Book of Accounts (ledger) consists of two parts, the blockchain (blockchain) and the state of the world. A blockchain is a group of linked chunks used to record transactions in a ledger. The world state is a key-value database that is used to store state during chain code execution.


3.2.1 Block Chain
3.2.1.1 Block
A blockchain is defined as a set of blocks that are joined together, because each chunk contains the hash of the previous chunk in the chain. The other 2 important pieces of information in the block are the list of transactions and the hash value of the world state after all the trades in the chunk have been executed.


Message Block {
Version = 1;
Google.protobuf.Timestamp Timestamp = 2;
Bytes Transactionshash = 3;
Bytes Statehash = 4;
Bytes Previousblockhash = 5;
Bytes Consensusmetadata = 6;
Nonhashdata nonhashdata = 7;
}


Message Blocktransactions {
Repeated Transaction transactions = 1;
}


Transactionshash is the hash value of the Merkle root of the trade list in the chunk
Statehash is the hash value of the World State Merkle root
Previousblockhash is the hash value of the previous chunk
Blocktransactions.transactions is an array of trading messages, and the transaction list is not directly contained within the block because of its size.


3.2.2 World State
The world State in a node is a collection of all deployed chain codes that are actually key-value pairs {Chaincodeid, ckey}.

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.