Читать книгу Introduction to Blockchain Technology - Tiana Laurence - Страница 11
What are nodes?
ОглавлениеWhen a computer connects to a blockchain network, the computer becomes a node. A node runs the blockchain software for the network and keeps the network healthy by engaging in the transfer of information. Anyone can run a node on a public network like Bitcoin. Nodes broadcast bitcoin transactions to other nodes throughout the network. However, not all nodes are the same.
There are several classifications of nodes depending on the level of participation and the type of blockchain network. Every network has different roles available. For example, when you run a node that has a complete history of the network’s transactions and verifies all of the rules of the system, it is called a full node. Full nodes download every block, and then they check each transaction and block to make sure they are compliant with the rules of the network. The network’s rules are called its consensus system. See figure 4.
Figure 4 What is a node?
Every blockchain has unique consensus rules. These rules cover things like the number of cryptocurrency units rewarded to miners and how transactions and blocks are formatted. When a full node finds a transaction or block that breaks the consensus rules, the node rejects the transaction or the block. Each full node works independently.
Operating a full node can be resource-intensive. It requires downloading every transaction for the full history of that blockchain. Full nodes need all new transaction records. They keep all block headers. Block headers identify a unique block and contain a hash of the previous block. All of this data adds up and takes up a lot of room. The Bitcoin blockchain is hundreds of gigabytes in size and growing every day.
However, there is a way to connect to a blockchain, without committing as many resources to the network. This is called a lightweight node or client. Lightweight nodes verify transactions by piggybacking on the work of full nodes. They only download the headers of all blocks and then check transactions utilizing a system called Simplified Payment Verification (SPV). As you may remember, the block headers contain hashes that prove that each block is in order and has all its transactions.
Operating a lightweight node may seem appealing. However, they are vulnerable to being tricked by bad actors. Because the SVP method is only checking the blockchain header, the lightweight node may accept transactions or blocks that are not valid. If you think you have received some bitcoin for example, but in reality you have not, this could cause financial issues. Full nodes provide the highest protection from fraud related to the transfer of cryptocurrency.
Another common way to connect to a blockchain network is to mine. A miner is a type of node that is adding transactions to new blocks. Miners compete to win the right to create a new complete block by solving a complex mathematical problem. Each miner will write their answer in the block header and if they are correct, they are then rewarded with cryptocurrency. The problem that miners are trying to solve is to guess a number that, when combined with the hashed transaction data from the block, returns an answer that is within a specific range called a “nonce”. For Bitcoin, a nonce is a number between 0 and 4,294,967,296.
The first miner to get a hash within the desired range broadcasts the winning number to the rest of the network. All the other miners promptly stop their work on that block and start guessing the nonce for the next block. At that point the competition for the next new block begins.
Miners opt into the ruleset by accepting the software upgrades. The network has available upgrades that users elect to adopt by updating their software. You can think of the upgrades as software patches. The upgrades are only as good as the acceptance and use by the miners.
There are three critical distinctions in blockchain nodes that are worth understanding as these affect the assumptions that are made around fairness, censorship, and permanence of data.
Public blockchain nodes
Public blockchains are open to anyone in the world to participate in the functions of the network, only limited by their access to the internet, hardware, and electricity. This means that you can be a miner earning cryptocurrency as your secure blocks, a full node checking transactions, or a lightweight node sending and receiving messages on the network. There are no gating mechanisms, no one to ask permission and no licensing fee. The software is held in an open license such as the Apache or MIT license. Prominent examples of this type of network include Bitcoin and Ethereum.
Permissioned blockchain nodes
Permissioned blockchains are private networks that utilize some blockchain technology but not all. Most don’t incorporate any kind of mining and so do not have a native cryptocurrency. This means that there are no disinterested third parties securing blocks, the blocks and transactions are all processed by known participants. The participants all have a vested interest in the integrity of the records. Often these networks are built by for-profit companies and are operated by consortiums such as R3.
Nodes on a Corda network
R3 (www.r3cev.com) built a consortium with more than 100 of the world’s leading banks and insurance companies. They work to streamline redundant business processes by integrating blockchain technology.
Corda is the blockchain protocol behind R3. It is a distributed ledger platform, often referred to as “DLT” (distributed ledger technology). Breaking down the jargon, a “ledger” is a general term for describing records used to account for something and “distributed” means that the record is kept in more than one location. It is designed specifically to manage and synchronize financial agreements between regulated financial institutions.
The R3 platform works very differently from public blockchains. There is no mining, and the transmission of data is not public in the same sense as it is on platforms such as Ethereum or Bitcoin. Unlike public blockchains that broadcast their transactions to the whole network, transactions execute in parallel on different nodes. Each node is unaware of the other’s transactions. The history of each network is on a need-to-know basis and cannot be viewed by the public.
Key features of Corda include the following:
■ Controlled access to the network;
■ Observer node for regulators;
■ Transactions are validated only by the parties involved;
■ Compatible with multiple consensus mechanisms;
■ No mining and no cryptocurrency.
Nodes on a Hyperledger Fabric network
Nodes on Hyperledger Fabric (see also: https://www.hyperledger.org/projects/fabric) are called Peers and Orderers. Unlike public blockchains that have nodes validating transactions or mining, the nodes on Fabric host the ledger’s data and make sure it’s in order. The data they host may include smart contracts, orderers, policies, channels, applications, organizations, identities, and membership. Another important distinction is that a Fabric peer can host more than one blockchain ledger. This feature allows for flexible architecture in the design of your private blockchain system.
Blockchain applications connect with peers on Fabric through APIs, application programming interfaces. The APIs allow you to invoke Fabric smart contracts in order to create transactions. Once you have submitted your transaction, they will be ordered and committed to Fabric. This does not just happen right away. The transaction must get approval from enough peers before the ledger is changed. It is possible to have two or more peers agree to cooperate privately. In Fabric this is called a channel. In the channel, the peers agree to collaborate to share and manage identical copies of the ledger associated with their channel.
Otherwise, when you submit a transaction, there is a three-phase process. This process ensures all peers keep their ledgers consistent with each other, see figure 5. This is where orderer peers are important. Their job is to ensure that every peer’s ledger is kept consistent. Single peers cannot update the ledger by themselves.
■ Phase 1: an update to the ledger is requested by a blockchain application. Peers will endorse the transaction. Once a transaction has gained enough endorsements, the transaction will move to phase 2.
■ Phase 2: the endorsed transactions are collected together and packaged into blocks. The orderer is crucial to this process. Peer audit by an orderer ensures this is done correctly.
Figure 5 The Fabric three-phase process.
■ Phase 3: the new block that was created is broadcast back to every peer so that they can update their blockchain record. Each transaction in the new block is then validated by the peer before being applied to its copy of the ledger.
Federated blockchain nodes
Federated blockchain nodes can exist in both public blockchains and private blockchains. Federation is when the system, or rather the user of a system, elect nodes to process transactions. Designating a few nodes to do most of the work of maintaining the blockchain records has its advantages and disadvantages.
One of the main reasons why systems choose this type of architecture is because it can reduce the raw cost of processing transactions and it can increase the speed at which the blockchain is updated and transactions are cleared.
However, there are some very good reasons to not have federated nodes. Blockchains are often judged to be less resilient to corruption when they have fewer nodes operating and securing the network. It is more feasible to take over a handful of computers and their operators then it is the ten thousand or more nodes that operate at any given time on the Bitcoin network.
Here are a few examples of blockchain networks that operate with some form of federation or designated nodes.
Factom is a public blockchain that has two classes of federated nodes, see figure 6. Half of these are processing transactions whilst the other half watch to make sure that the nodes processing the transactions are accurate and not censoring transactions. Users of the system elect nodes to be Federated Factom nodes. Factom does not use mining but does have a native cryptocurrency. The Federated nodes are rewarded with “Factoids” the Factom cryptocurrency for processing transactions. The nodes can then sell Factoids back into the market to those who wish to utilize the Factom blockchain.
Figure 6 The Factom federated network.
Waves is a public blockchain that limits participation in the network to nodes that hold sufficient “waves” of cryptocurrency. Currently, the limit is set to approximately 1,000 waves. The Waves blockchain is a peer-to-peer network, and any computer running the Waves software is considered a node and can propose new transactions. But only full nodes are allowed administrative duties. They relay blocks and transactions to miners and answer queries for end users about the state of the blockchain. Full nodes ensure that new blocks are valid. They check the format of the block in order to validate that all hashes in the new block are correct, that there is a hash of the previous block, and each transaction was signed by the right parties. Full nodes can mine new blocks. Mining on Waves consists only of generating new blocks, it does not require solving difficult math problems like Bitcoin. See figure 7.