4.1 Overview of algorithms
In this paper, a practical Byzantine fault tolerant algorithm based on the Trust Equity Score (tPBFT) is presented for scalable nodes of federated block chains and high-frequency trading scenarios, as shown in Figure 2.
Consensus methods suitable for high-frequency trading scenarios in federation chains are mainly implemented by introducing a trust equity scoring mechanism and improving the Byzantine fault tolerance algorithm among consensus nodes in the federation chains. First, the client obtains the transaction list from the transaction pool, sorts the transaction list and packages it as message m, and attaches timestamp T and client signature information σc to form the REQUEST stage data package <<REQUEST,m,t,c > σc > . After the leader node receives the message, assign the sequence number n to the request packet, attach the view number V and other information, and package to form a PREPARE phase message package << PREPARE, v, n, d(m)>σP, m>, where d(m) is the summary of message m and σc is the primary node signature.
The nodes in the system are divided into two roles by the trust equity scoring mechanism: consensus nodes participating in consensus and common nodes participating in storage validation. During the confirmation phase, the leader node will <<PREPARE, v, n, d(m)>σP, m> be distributed to consensus nodes, which agree on the transaction list and form COMMIT phase packets << COMMIT, v, n, D(m), i > σi>, where I represents the i-th block chain node in the network, σi is the signature information for the i-th node. In the submission phase, the leader node collects up to 2f+1 nodes (f is the maximum number of fault tolerant nodes in the network) and sends a confirmation packet, which proves that the transaction is valid and packages the REPLY phase packets << REPLY, v, t, p > σP, m>, where p is the primary node, data packages are distributed to normal nodes, and valid confirmation replies are made to clients for transactions.
The traditional PBFT algorithm is simplified into three phases: PREPARE, COMMIT and REPLY. In the COMMIT and REPLY phases, after the improvement of PBFT by the tPBFT algorithm we designed, the transaction list in the packet only contains the Hash list of transaction hashes.
4.2 Establishing a Trust Equity Scoring Mechanism
The PBFT algorithm can solve the general Byzantine problem; that is, the distributed nodes can still reach a consensus when malicious nodes are allowed. However, the algorithm requires all nodes to participate in the consensus. As the number of nodes in the network increases, the consensus delay and network bandwidth consumption will increase dramatically, so the size of nodes in the network is a key factor that restricts the performance of the PBFT algorithm.
This paper establishes a trust model to score nodes in the network, periodically demotes the consensus nodes with lower scores, and the common nodes with higher scores can be elected as consensus nodes to participate in consensus accounting by substitution. The improvement of the Byzantine fault tolerance algorithm applied to extensible network nodes mainly reflects the increased dynamics and reliability of the network. The process is shown in Figure 3 below:
Combined with the response delay, processing delay, packet loss rate, historical node availability and reliability among nodes in the network, all nodes will score their trust every time they complete a transaction. After completing a fixed round of transactions, the nodes with low trust scores will be degraded to ordinary nodes, and the ordinary nodes with high scores can be elected as consensus nodes. At the same time, the historical trust scores of all consensus nodes are cleared and restarted. Based on the trust equity scoring mechanism, it ensures that the consensus node has the highest trust score. When a blockchain node has low response delay and low processing delay, it shows that the node has strong processing capacity. At the same time, the historical availability and reliability indicators of the node are introduced to reduce the risk of random selection of the master node and consensus node of the original PBFT algorithm, improving network security.
Because the trust equity score includes multiple dimension indicators, some indicators are high-quality (the higher the indicator, the better, such as historical node availability, reliability, throughput, etc.), and some indicators are low-quality (the lower the indicator value, the better, such as response delay, processing delay, packet loss rate, etc.). Therefore, a unified normalization method is established for high and excellent indexes, as follows:
Yij = \(\frac{{ {\text{y}}_{\text{i}\text{j}} - \text{y}}_{\text{j} \text{m}\text{i}\text{n}}}{{\text{y}}_{\text{j} \text{m}\text{a}\text{x}} - { \text{y}}_{\text{j} \text{m}\text{i}\text{n}}}\) (1)
In the formula, Yij is the actual measured value of the i-th node in the j-th high optimization index;
\({\text{y}}_{\text{j} \text{m}\text{a}\text{x}}\)is the actual measured maximum value of all nodes of the j-th high optimization index;
\({ \text{y}}_{\text{j} \text{m}\text{i}\text{n}}\)is the actual measured minimum value of all nodes of the j-th high optimization index.
Establish a unified normalization method for low and excellent indicators, as follows:
Yik = 1 \(- \frac{{ {\text{y}}_{\text{i}\text{k}} - \text{y}}_{\text{k} \text{m}\text{i}\text{n}}}{{\text{y}}_{\text{k} \text{m}\text{a}\text{x}} - { \text{y}}_{\text{k} \text{m}\text{i}\text{n}}}\)= \(\frac{{{\text{y}}_{\text{k} \text{m}\text{a}\text{x}} - \text{y}}_{\text{i}\text{k}} }{{\text{y}}_{\text{k} \text{m}\text{a}\text{x}} - { \text{y}}_{\text{k} \text{m}\text{i}\text{n}}}\) (2)
In the formula, Yik is the actual measured value of the i-th node in the k-th low optimal index;
\({\text{y}}_{\text{k} \text{m}\text{a}\text{x}}\)is the actual measured maximum value of all nodes of the k-th low optimal index;
\({ \text{y}}_{\text{k} \text{m}\text{i}\text{n}}\)is the actual measured minimum value of all nodes of the k-th low optimal index.
Assuming that the number of high-quality indicators and low-quality indicators in multiple dimensions of the trust equity score is M1 and M2, the index information of high-quality and low-quality dimensions is fused and weighted to obtain the trust equity score \(\text{Q}\left({\text{n}}_{\text{i}}\right)\) of the ith node in the network, as follows:
$$\text{Q}\left({\text{n}}_{\text{i}}\right)=\sum _{\text{j}=1}^{\text{m}1}\left(\frac{{ {\text{y}}_{\text{i}\text{j}} - \text{y}}_{\text{j} \text{m}\text{i}\text{n}}}{{\text{y}}_{\text{j} \text{m}\text{a}\text{x}} - { \text{y}}_{\text{j} \text{m}\text{i}\text{n}}}\right)\times {\text{w}}_{\text{j}} +\sum _{\text{k}=1}^{\text{m}2}\left(\frac{{{\text{y}}_{\text{k} \text{m}\text{a}\text{x}} - \text{y}}_{\text{i}\text{k}} }{{\text{y}}_{\text{k} \text{m}\text{a}\text{x}} - { \text{y}}_{\text{k} \text{m}\text{i}\text{n}}}\right)\times {\text{w}}_{\text{k}}$$
3
In the formula: i\(\in [\text{i},\text{n}]\).
4.3 Determine the classification and responsibilities of nodes in the network
In our design of the consensus algorithm tPBFT, network nodes are divided into consensus nodes and ordinary nodes. The consensus node participates in the block consensus of each node in the network and is responsible for receiving and signing the transactions sent by the client, analyzing the transaction content in combination with the status data of its own node, supervising and managing the transactions submitted by the client to prevent evil. The common node receives the data synchronization of the consensus node for signature verification and storage. After the consensus node is downgraded to the common node, the common node with a higher score can be elected as the consensus node.
4.4 Election of consensus nodes in networks
The number of consensus nodes is a configurable parameter. To ensure safety and fault tolerance, the number of consensus nodes in the actual production environment should be configured as an integer greater than or equal to 4. If the blockchain network is an alliance chain composed of trusted nodes or requires a high data link rate, the number of consensus nodes can be configured to be smaller to improve the consensus efficiency among nodes. If it is applied in the scenario of a public chain or low reliability between nodes, the number of consensus nodes can be configured to be larger to prevent evil nodes and fault nodes and improve the fault tolerance of the system. Consensus nodes and ordinary nodes can change each other under certain conditions, which solves the problem that the existing PBFT algorithm does not support the addition and exit of new nodes and improves the scalability of network nodes.
4.5 Elect leader node
The consensus nodes elected through the trust equity model in the network have equal opportunities to compete for the leader nodes. Each consensus node uses the verifiable random function VRF algorithm to generate a random number. The node that generates the same random number as the node in the system is the leader node of this round. The leader node is responsible for receiving the transactions packaged by the client, signing and distributing them to other nodes in the network.
4.6 Consensus execution process
The tPBFT consensus execution process is shown in Figure 4.
(1) First, the client obtains the transaction list from the transaction pool, sorts the transaction data and packs it into message m, and attaches timestamp t and client signature information σc to form the REQUEST phase data package <<REQUEST,m,t,c>σc>;
(2) After receiving the message, the leader node assigns the serial number n to the request data packet and attaches the view number v and other information to form the prepare stage message packet << prepare, v, n, d (m) > σp,m >, broadcast to other consensus nodes in other networks, where d (m) is the summary of message m, σP is the signature information of the primary node.
(3) After receiving the data packet << prepare, v, n, d (m) > σp,m > sent by the leader node, other consensus nodes in the network verify the request content and transaction list order in the view. After passing the verification, they enter the commit phase and broadcast the commit phase data packet <<COMMIT,v,n,d(m),i > σi > to other consensus nodes, where I represents the i-th blockchain node in the network, σi is the signature information of the i-th node;
(4) Each node in the network collects the commit broadcast data packets sent by 2F + 1 (F is the maximum number of fault tolerant nodes in the network) and enters the reply stage after legal verification, indicating that it has agreed to all transactions in the transaction list. At the same time, package the reply stage data packet << reply, v,i, d (m) > σi > and broadcast it to other consensus nodes in the network.
(5) After receiving more than 2F + 1 replies, the leader node will prove that the transaction is valid and write the transaction into the local ledger. If the intermediate process fails to pass the verification, the consensus node will broadcast the view change message, switch the view, and re elect the leader node.
(6) Finally, the leader node distributes the agreed packets to ordinary nodes and clients.
4.7 Commit and reply phases based on transaction hash
Based on the commit and reply phases of the transaction hash, in the confirmation and submission phases, the data packets of broadcast s between nodes cause repeated transmission of the transaction list. After the PBFT algorithm we designed improves the PBFT, the transaction list in the data packet only contains the Hash list of the transaction hash, and the authenticity of the transaction can be verified and confirmed only for the hash. A few MB packet. After optimization, a transaction state changes to hundreds of bytes. Finally, it is guaranteed that each node of the alliance blockchain will store the requests from the client in the blockchain in the same transaction list order.