針對以上提出的問題,本說明書提供了一種區塊鏈資料的壓縮處理方法,所述區塊鏈的N個節點設備對應的區塊資料副本被儲存於與所述區塊鏈對接的儲存系統,所述方法包括:
從所述N個節點設備中選擇一個節點設備作為目標節點設備,並將所述目標節點設備對應的區塊資料副本加入一壓縮資料副本集合;
執行甄選迭代步驟,直到所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,所述甄選步驟包括:從所述N個節點設備中所述目標節點設備以外的節點設備中,依次選擇一節點設備作為對比節點設備;確定所述目標節點設備與所述對比節點設備對應的區塊資料副本是否匹配,如果是,將所述對比節點對應的區塊資料副本加入所述壓縮資料副本集合。
更優的,上述方法還包括:如果執行所述甄選迭代步驟,所述壓縮資料副本集合內的區塊資料副本的數量仍未大於所述區塊鏈的系統容錯數,則從所述N個節點設備中重新選擇一節點設備作為目標節點設備,並重複執行所述甄選迭代步驟,直至所述壓縮資料副本集合內的區塊資料副本的數量大於所述區塊鏈的系統容錯數。
更優的,所述儲存系統支援的容錯演算法為拜占庭容錯演算法;上述方法中所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,包括:
所述壓縮資料副本集合內匹配的區塊資料副本的數量既大於所述區塊鏈的系統容錯數,又大於所述壓縮資料副本集合在所述儲存系統中的拜占庭容錯值的三倍。
更優的,上述方法還包括:
當所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,刪除所述儲存系統中儲存的除所述壓縮資料副本集合中的資料副本以外的資料副本;
以及,將刪除的區塊資料副本的資料存取路徑變更為所述壓縮資料副本集合中的區塊資料副本的資料存取路徑。
更優的,上述方法中所述儲存系統為與所述區塊鏈對接的雲端儲存系統。
相應地,本說明書還提供了一種區塊鏈資料的壓縮處理裝置,所述區塊鏈的N個節點設備對應的區塊資料副本被儲存於與所述區塊鏈對接的儲存系統,所述裝置包括:
目標資料選擇單元,從所述N個節點設備中選擇一個節點設備作為目標節點設備,並將所述目標節點設備對應的區塊資料副本加入一壓縮資料副本集合;
甄選迭代執行單元,執行甄選迭代步驟,直到所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,所述甄選步驟包括:從所述N個節點設備中所述目標節點設備以外的節點設備中,依次選擇一節點設備作為對比節點設備;確定所述目標節點設備與所述對比節點設備對應的區塊資料副本是否匹配,如果是,將所述對比節點對應的區塊資料副本加入所述壓縮資料副本集合。
更優的,上述裝置的甄選迭代執行單元,如果執行所述甄選迭代步驟,所述壓縮資料副本集合內的區塊資料副本的數量仍未大於所述區塊鏈的系統容錯數,則從所述N個節點設備中重新選擇一節點設備作為目標節點設備,並重複執行所述甄選迭代步驟,直至所述壓縮資料副本集合內的區塊資料副本的數量大於所述區塊鏈的系統容錯數。
更優的,所述儲存系統支援的容錯演算法為拜占庭容錯演算法;上述裝置中所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,包括:
所述壓縮資料副本集合內匹配的區塊資料副本的數量既大於所述區塊鏈的系統容錯數,又大於所述壓縮資料副本集合在所述儲存系統中的拜占庭容錯值的三倍。
更優的,上述裝置還包括:
資料刪除單元,當所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,刪除所述儲存系統中儲存的除所述壓縮資料副本集合中的資料副本以外的資料副本;
以及,存取路徑變更單元,將刪除的區塊資料副本的資料存取路徑變更為所述壓縮資料副本集合中的區塊資料副本的資料存取路徑。
更優的,上述裝置中所述儲存系統為與所述區塊鏈對接的雲端儲存系統。
相應地,本說明書還提供了一種電腦設備,包括:記憶體和處理器;所述記憶體上儲存有可由處理器運行的電腦程式;所述處理器運行所述電腦程式時,執行如上述區塊鏈資料的壓縮處理方法所述的步驟。
相應地,本說明書還提供了一種電腦可讀儲存媒體,其上儲存有電腦程式,所述電腦程式被處理器運行時,執行如上述區塊鏈資料的壓縮處理方法所述的步驟。
應用本說明書所提供的區塊鏈資料的壓縮處理方法、裝置、電腦設備和電腦可讀儲存媒體,可將區塊鏈系統儲存於一儲存系統的區塊資料副本進行整理和壓縮,將上述區塊鏈系統儲存於上述儲存系統的區塊資料副本整理成滿足區塊鏈的系統容錯規則、且資料內容完全相同的區塊資料副本,剔除由無效資料、及過多有效資料的儲存造成的儲存資源浪費。In response to the above-mentioned problems, this specification provides a method for compressing blockchain data. Block data copies corresponding to the N node devices of the blockchain are stored in a storage system connected to the blockchain. The method includes:
Selecting one node device from the N node devices as the target node device, and adding the block data copy corresponding to the target node device to a compressed data copy set;
Performing a selection iteration step until the number of matching block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain, the selection step includes: selecting the target node from the N node devices In the node devices other than the device, select a node device as the comparison node device in turn; determine whether the copy of the block data corresponding to the target node device and the comparison node device match, and if so, the block corresponding to the comparison node The data copy is added to the compressed data copy set.
More preferably, the above method further includes: if the selection iteration step is performed and the number of block data copies in the compressed data copy set is still not greater than the system fault tolerance of the blockchain, then the N The node device reselects a node device as the target node device, and repeatedly performs the selection iteration step until the number of block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain.
More preferably, the fault-tolerant algorithm supported by the storage system is a Byzantine fault-tolerant algorithm; in the above method, the number of matched block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain, including:
The number of matching block data copies in the compressed data copy set is both greater than the system fault tolerance of the blockchain and three times the Byzantine fault tolerance value of the compressed data copy set in the storage system.
More preferably, the above method also includes:
When the number of matching block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain, delete the data copies stored in the storage system except the data copies in the compressed data copy set ;
And, the data access path of the deleted block data copy is changed to the data access path of the block data copy in the compressed data copy set.
More preferably, in the above method, the storage system is a cloud storage system connected to the blockchain.
Correspondingly, this specification also provides a block data compression processing device, block data copies corresponding to the N node devices of the block chain are stored in a storage system connected to the block chain, the The device includes:
The target data selection unit selects one node device from the N node devices as the target node device, and adds the block data copy corresponding to the target node device to a compressed data copy set;
The selection iteration execution unit executes the selection iteration step until the number of matching block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain. The selection step includes: selecting from the N node devices In the node devices other than the target node device, select a node device as the comparison node device in turn; determine whether the block data copies corresponding to the target node device and the comparison node device match, and if so, compare the comparison The block data copy corresponding to the node is added to the compressed data copy set.
More preferably, if the selection and iteration execution unit of the above device performs the selection and iteration step, the number of block data copies in the compressed data copy set is still not greater than the system fault tolerance of the blockchain, then Re-select one node device as the target node device among the N node devices, and repeat the selection iteration step until the number of block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain .
More preferably, the fault-tolerant algorithm supported by the storage system is a Byzantine fault-tolerant algorithm; the number of matching block data copies in the compressed data copy set in the above device is greater than the system fault tolerance of the blockchain, including:
The number of matching block data copies in the compressed data copy set is both greater than the system fault tolerance of the blockchain and three times the Byzantine fault tolerance value of the compressed data copy set in the storage system.
More preferably, the above device also includes:
A data deletion unit, when the number of matching block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain, delete the data copies stored in the storage system except the compressed data copy set Copies of other materials;
And, the access path changing unit changes the data access path of the deleted block data copy to the data access path of the block data copy in the compressed data copy set.
More preferably, the storage system in the above device is a cloud storage system connected to the blockchain.
Correspondingly, this specification also provides a computer device, including: a memory and a processor; a computer program that can be executed by the processor is stored on the memory; when the processor runs the computer program, the execution is as described above The steps described in the block chain data compression method.
Correspondingly, this specification also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps described in the above-mentioned method for compressing blockchain data are executed.
Using the method, device, computer equipment and computer-readable storage medium for the compression of blockchain data provided in this manual, the blockchain system can store and copy the block data stored in a storage system to compress the above-mentioned areas Block chain system The block data copies stored in the above storage system are organized into block data copies that satisfy the system fault tolerance rules of the block chain and have the same data content, excluding storage resources caused by invalid data and excessive effective data storage waste.
“區塊鏈”,具體可指一個各節點透過共識機制達成的、具有分散式資料儲存結構的P2P網路系統,該區塊鏈內的資料分佈在時間上相連的一個個“區塊(block)”之內,後一區塊包含前一區塊的資料摘要,且根據具體的共識機制(如POW、POS、DPOS或PBFT等)的不同,達成全部或部分節點的資料全副本。由於雲端儲存技術的發展,區塊鏈系統的節點可以將其應儲存的全部或部分的區塊資料副本儲存上雲端,甚至還可以將整個節點設備部署上雲端。當部署上雲端空間的區塊鏈系統的節點越多,或區塊鏈系統的節點將其應儲存的區塊資料副本在雲端空間儲存得越多,雲端上儲存資源的消耗也就越多。
另外,本領域的技術人員應知,區塊鏈各個節點儲存的區塊資料副本在區塊鏈共識機制的保證下基本完全一致,僅有少部分節點由於惡意、故障或其他原因導致其儲存的區塊資料與其他節點不完全一致,各個區塊鏈從自身應用場景的實際出發,均設置有各自的容錯機制,上述少部分節點儲存的區塊資料由於不契合區塊鏈的共識,可被視為無效資料。上述少部分節點儲存的區塊資料副本如果也被部署上雲端,則進一步增加了雲端空間的浪費。
為解決如上所述的問題,圖1示意了本說明書一示意性實施例提供的一種區塊鏈資料的壓縮處理方法,所述區塊鏈的N個節點設備對應的區塊資料副本被儲存於與所述區塊鏈對接的儲存系統,所述方法包括:
從所述N個節點設備中選擇一個節點設備作為目標節點設備,並將所述目標節點設備對應的區塊資料副本加入一壓縮資料副本集合;
執行甄選迭代步驟,直到所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,所述甄選步驟包括:從所述N個節點設備中所述目標節點設備以外的節點設備中,依次選擇一節點設備作為對比節點設備;確定所述目標節點設備與所述對比節點設備對應的區塊資料副本是否匹配,如果是,將所述對比節點對應的區塊資料副本加入所述壓縮資料副本集合。
上述實施例所述的儲存系統,是指可儲存區塊鏈的N個節點對應的區塊資料副本的空間,包括但不限於雲端空間、儲存伺服器、儲存伺服器集群等,可透過集群應用、網路技術或分散式檔案系統等功能,將網路中大量的儲存設備集合起來協同工作,從而對外提供資料儲存和業務存取功能的系統。
上述實施例所述的區塊資料是指區塊鏈上每個區塊內的全部資料,上述實施例所述的N個節點對應的區塊資料副本,可以是上述N個節點對應的全部區塊資料副本,也可以是上述N個節點對應的部分區塊資料副本,如N個節點對應的、區塊高度從1000至2000的區塊資料副本。
上述實施例所述的從所述N個節點設備中選擇一個節點設備作為目標節點設備,該“選擇”目標節點設備的方式不作限定,可以為隨機選擇,也可以為按照預設的規則進行選擇。上述壓縮資料副本集合可初始化為空,專用於收集與所述目標節點設備對應的區塊資料副本相同的區塊資料副本,是經過本說明書所提供的區塊鏈資料的壓縮處理後得到的區塊壓縮資料副本集合;可選的,上述壓縮資料副本集合也可是上述N個節點對應的全部區塊資料副本經壓縮處理後所得集合的子集。
上述實施例所述的甄選迭代步驟,用於為上述壓縮資料副本集合甄選出滿足系統設定閾值的區塊資料副本數量。區塊鏈各個節點儲存的區塊資料副本在區塊鏈共識機制的保證下基本完全一致,僅有少部分節點由於惡意、故障或其他原因導致其儲存的區塊資料與其他節點不完全一致,各個區塊鏈從自身應用場景的實際出發,均設置有各自的容錯機制。因此經過上述甄選迭代步驟,上述壓縮資料副本集合中的匹配的區塊資料副本(包括目標節點設備對應的區塊資料副本)的數量至少要大於上述區塊鏈的系統容錯數,即n>f,其中n為上述壓縮資料副本集合中匹配的區塊資料副本的數量,f為上述區塊鏈的系統容錯數,n與f都為自然數,因此n至少應為f+1。本領域的技術人員熟知,區塊鏈系統的容錯數通常由區塊鏈系統的共識機制確定,例如在PBFS共識協定下,區塊鏈系統的容錯數f應滿足:f<(P-1)/3,P為所述區塊鏈參與共識的節點個數。本說明書並不限定區塊鏈系統的共識協定類型,但上述壓縮資料副本集合中匹配的區塊資料副本的數量n至少應大於區塊鏈系統的容錯數f,從而保證上述壓縮資料副本集合中的區塊資料副本屬於上述區塊鏈共識的有效資料副本。
上述實施例所述的甄選迭代步驟中,所述依次選擇一節點設備作為對比節點設備中,所述“依次選擇”的方式可以有多種,例如,儲存系統可以為在其內儲存的各個節點設備編號,按照編號從小到大的順序或從大到小的順序或其他任何常用的順序方式進行依次選擇,在本說明書中不作限定。
上述實施例所述的確定所述目標節點設備與所述對比節點設備對應的區塊資料副本是否匹配,是指確定所述目標節點設備與所述對比節點設備對應的區塊資料副本是否完全相同,如果是,將所述對比節點對應的區塊資料副本加入所述壓縮資料副本集合;如上所述,當所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數時,上述壓縮資料副本集合內的區塊資料副本一定是經過區塊鏈系統共識確認後的正確的區塊資料,至此,儲存系統將原本儲存的、N個節點設備對應的區塊資料副本,捨去(可以刪除)不符合區塊鏈的系統共識結果的區塊資料副本,進而壓縮為上述壓縮資料副本集合,上述壓縮資料副本集合的數量至少大於上述區塊鏈的系統容錯數,但一定小於N,因此起到了節約上述儲存系統的儲存資源的作用。
在又一示出的實施例中,上述區塊鏈資料的壓縮處理方法還包括:
如果執行所述甄選迭代步驟,所述壓縮資料副本集合內的區塊資料副本的數量仍未大於所述區塊鏈的系統容錯數,則從所述N個節點設備中重新選擇一節點設備作為目標節點設備,並重複執行所述甄選迭代步驟,直至所述壓縮資料副本集合內的區塊資料副本的數量大於所述區塊鏈的系統容錯數。
在上述的實施例中,當一輪甄選迭代步驟執行完畢後,所述壓縮資料副本集合內匹配的區塊資料副本的數量不大於(即小於或等於)所述區塊鏈的系統容錯數時,上述目標節點設備對應的區塊資料副本可能包含有惡意或故障資料,與區塊鏈系統經共識機制確認後的共識資料不同,因此,儲存系統需將原壓縮資料副本集合清空,重新選取另一個節點設備作為目標節點設備,並將其對應的區塊資料副本加入上述壓縮資料副本集合,進行下一輪次的甄選迭代步驟,直至所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,所述壓縮資料副本集合甄選完畢。
當上述輪次的甄選迭代步驟執行完畢,若儲存系統仍未甄選出符合目標數量(數量至少大於區塊鏈系統的容錯數)的壓縮資料副本集合,則儲存系統應迭代執行清空上輪次所得的壓縮資料副本集合、重新選擇目標節點設備、重新執行針對新選擇的目標節電設備對應的區塊資料副本的甄選迭代步驟的全部步驟,具體過程如上,在此不再贅述。
值得注意的是,上述實施例所述的清空所述壓縮資料副本集合,可以表現為清空上次甄選迭代步驟所得的壓縮資料副本集合,也可表現為再重新建立一個新的壓縮資料副本集合空集(或空子集),在本說明書中不做限定。
在本說明書示出的又一實施例中,當所述儲存系統支援的容錯演算法為拜占庭容錯演算法時,上述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,包括:所述壓縮資料副本集合內匹配的區塊資料副本的數量既大於所述區塊鏈的系統容錯數,又大於所述壓縮資料副本集合在所述儲存系統中的拜占庭容錯值的三倍。
本領域的技術人員應知,為保證上述壓縮資料副本集合內收集的區塊資料副本為經過區塊鏈系統的共識認定的資料,而非惡意節點或故障節點保存的錯誤資料,該壓縮資料副本集合內匹配的區塊資料副本的數量需大於所述區塊鏈系統的容錯數;進一步地,由於儲存系統可設置多台服務設備以儲存上述區塊鏈中多個節點設備對應的區塊資料副本,該儲存系統會基於自身的服務設備的運行情況進行拜占庭容錯的設置,例如,在該儲存系統中,設置有M個儲存伺服器以儲存上述區塊鏈中壓縮資料副本集合內匹配的區塊資料副本,為容納上述M個儲存伺服器可能發生的故障或其他錯誤,該儲存系統通常應設置一容錯數s,且需滿足M>3s,該容錯數s被稱為該儲存系統的拜占庭容錯數。關於該拜占庭容錯數s與儲存系統的儲存伺服器的數量M(可視為發起系統回應的節點數量M)的關係,是由以下過程導出:
系統在向M個儲存伺服器或節點發起指令時,由於存在s個錯誤節點,那麼系統接收到的M-s個應答收到的正常節點的回答應大於有問題的節點,所以儲存系統需滿足,M-s-s>s’由於M與s均為自然數,M至少應為3s+1。因此上述壓縮資料副本集合內的區塊資料副本需大於上述儲存系統的拜占庭容錯數的3倍。
在本說明書示出的又一實施例中,當所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,刪除所述儲存系統中儲存的除了所述壓縮資料副本集合中的資料副本以外的資料副本;以及,將刪除的資料副本的資料存取路徑變更為所述壓縮資料副本集合中的資料副本的資料存取路徑。
在上述實施例中,當所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數時,即上述壓縮資料副本集合甄選完畢,儲存系統可刪除所述儲存系統中儲存的除所述壓縮資料副本集合中的資料副本以外的資料副本,以節約儲存系統的儲存資源;同時,由於上述區塊鏈中一些節點設備對應的區塊資料副本已經被刪除,上述節點設備應業務需求在上述儲存系統中存取其對應的區塊資料副本時,儲存系統應將已刪除的區塊資料副本的資料存取路徑變更為指向上述壓縮資料副本集合中的區塊資料副本的資料存取路徑,例如,儲存系統可將上述節點設備與被刪除的區塊資料副本的映射,更新為上述節點設備與壓縮資料副本集合中的區塊資料副本的映射,以説明上述節點設備存取其對應的區塊資料副本。
在本說明書示出的又一實施例中,上述儲存系統可以為與所述區塊鏈對接的雲端儲存系統。
與上述流程實現對應,本說明書的實施例還提供了一種區塊鏈資料的壓縮處理裝置。該裝置可以透過軟體實現,也可以透過硬體或者軟硬體結合的方式實現。以軟體實現為例,作為邏輯意義上的裝置,是透過所在設備的CPU(Central Process Unit,中央處理器)將對應的電腦程式指令讀取到記憶體中運行形成的。從硬體層面而言,除了圖3所示的CPU、記憶體以及記憶體之外,該資料處理裝置所在的設備通常還包括用於進行無線信號收發的晶片等其他硬體,和/或用於實現網路通信功能的板卡等其他硬體。
圖2所示為本說明書所提供的一種區塊鏈資料的壓縮處理裝置20,所述區塊鏈的N個節點設備對應的區塊資料副本被儲存於與所述區塊鏈對接的儲存系統,所述裝置20包括:
目標資料選擇單元202,從所述N個節點設備中選擇一個節點設備作為目標節點設備,並將所述目標節點設備對應的區塊資料副本加入一壓縮資料副本集合;
甄選迭代執行單元204,執行甄選迭代步驟,直到所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,所述甄選步驟包括:從所述N個節點設備中所述目標節點設備以外的節點設備中,依次選擇一節點設備作為對比節點設備;確定所述目標節點設備與所述對比節點設備對應的區塊資料副本是否匹配,如果是,將所述對比節點對應的區塊資料副本加入所述壓縮資料副本集合。
更優的,上述裝置20的甄選迭代執行單元204,如果執行所述甄選迭代步驟,所述壓縮資料副本集合內的區塊資料副本的數量仍未大於所述區塊鏈的系統容錯數,則從所述N個節點設備中重新選擇一節點設備作為目標節點設備,並重複執行所述甄選迭代步驟,直至所述壓縮資料副本集合內的區塊資料副本的數量大於所述區塊鏈的系統容錯數。
更優的,所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,包括:
所述壓縮資料副本集合內匹配的區塊資料副本的數量既大於所述區塊鏈的系統容錯數,又大於所述壓縮資料副本集合在所述儲存系統中的拜占庭容錯值的三倍。
更優的,上述裝置20還包括:
資料刪除單元208,當所述壓縮資料副本集合內匹配的區塊資料副本的數量大於所述區塊鏈的系統容錯數,刪除所述儲存系統中儲存的除所述壓縮資料副本集合中的資料副本以外的資料副本;
以及,存取路徑變更單元210,將刪除的區塊資料副本的資料存取路徑變更為所述壓縮資料副本集合中的區塊資料副本的資料存取路徑。
更優的,所述儲存系統為與所述區塊鏈對接的雲端儲存系統。
上述裝置中各個單元的功能和作用的實現過程具體詳見上述方法中對應步驟的實現過程,相關之處參見方法實施例的部分說明即可,在此不再贅述。
以上所描述的裝置實施例僅僅是示意性的,其中所述作為分離部件說明的單元可以是或者也可以不是實體上分開的,作為單元顯示的部件可以是或者也可以不是實體模組,即可以位於一個地方,或者也可以分佈到多個網路模組上。可以根據實際的需要選擇其中的部分或者全部單元或模組來實現本說明書方案的目的。本領域普通技術人員在不付出創造性勞動的情況下,即可以理解並實施。
上述實施例闡明的裝置、單元、模組,具體可以由電腦晶片或實體實現,或者由具有某種功能的產品來實現。一種典型的實現設備為電腦,電腦的具體形式可以是個人電腦、膝上型電腦、蜂窩電話、相機電話、智慧型電話、個人數位助理、媒體播放機、導航設備、電子郵件收發設備、遊戲控制台、平板電腦、可穿戴設備或者這些設備中的任意幾種設備的組合。
與上述方法實施例相對應,本說明書的實施例還提供了一種電腦設備,該電腦設備包括記憶體和處理器。其中,記憶體上儲存有能夠由處理器運行的電腦程式;處理器在運行儲存的電腦程式時,執行本說明書實施例中區塊鏈資料的壓縮處理方法的各個步驟。對儲存系統對區塊鏈資料的壓縮處理方法的各個步驟的詳細描述請參見之前的內容,不再重複。
與上述方法實施例相對應,本說明書的實施例還提供了一種電腦可讀儲存媒體,該儲存媒體上儲存有電腦程式,這些電腦程式在被處理器運行時,執行本說明書實施例中區塊鏈資料的壓縮處理方法的各個步驟。對儲存系統對區塊鏈資料的壓縮處理方法的各個步驟的詳細描述請參見之前的內容,不再重複。
以上所述僅為本說明書的較佳實施例而已,並不用以限制本說明書,凡在本說明書的精神和原則之內,所做的任何修改、等同替換、改進等,均應包含在本說明書保護的範圍之內。
在一個典型的配置中,計算設備包括一個或多個處理器(CPU)、輸入/輸出介面、網路介面和記憶體。
記憶體可能包括電腦可讀媒體中的非永久性記憶體,隨機存取記憶體(RAM)和/或非揮發性記憶體等形式,如唯讀記憶體(ROM)或快閃記憶體(flash RAM)。記憶體是電腦可讀媒體的示例。
電腦可讀媒體包括永久性和非永久性、可移動和非可移動媒體可以由任何方法或技術來實現資訊儲存。資訊可以是電腦可讀指令、資料結構、程式的模組或其他資料。
電腦的儲存媒體的例子包括,但不限於相變記憶體(PRAM)、靜態隨機存取記憶體(SRAM)、動態隨機存取記憶體(DRAM)、其他類型的隨機存取記憶體(RAM)、唯讀記憶體(ROM)、電可擦除可程式設計唯讀記憶體(EEPROM)、快閃記憶體或其他記憶體技術、唯讀光碟唯讀記憶體(CD-ROM)、數位多功能光碟(DVD)或其他光學儲存、磁盒式磁帶,磁帶磁磁片儲存或其他磁性存放裝置或任何其他非傳輸媒體,可用於儲存可以被計算設備存取的資訊。按照本文中的界定,電腦可讀媒體不包括暫存電腦可讀媒體(transitory media),如調變的資料信號和載波。
還需要說明的是,術語“包括”、“包含”或者其任何其他變體意在涵蓋非排他性的包含,從而使得包括一系列要素的過程、方法、商品或者設備不僅包括那些要素,而且還包括沒有明確列出的其他要素,或者是還包括為這種過程、方法、商品或者設備所固有的要素。在沒有更多限制的情況下,由語句“包括一個……”限定的要素,並不排除在包括所述要素的過程、方法、商品或者設備中還存在另外的相同要素。
本領域技術人員應明白,本說明書的實施例可提供為方法、系統或電腦程式產品。因此,本說明書的實施例可採用完全硬體實施例、完全軟體實施例或結合軟體和硬體方面的實施例的形式。而且,本說明書的實施例可採用在一個或多個其中包含有電腦可用程式碼的電腦可用儲存媒體(包括但不限於磁碟記憶體、CD-ROM、光學記憶體等)上實施的電腦程式產品的形式。"Blockchain" can specifically refer to a P2P network system with distributed data storage structure reached by each node through a consensus mechanism. The data in the blockchain is distributed in time. )", the latter block contains the data summary of the previous block, and according to the specific consensus mechanism (such as POW, POS, DPOS or PBFT, etc.), a full copy of the data of all or some nodes is reached. Due to the development of cloud storage technology, the nodes of the blockchain system can store all or part of the block data copies they should store on the cloud, and even deploy the entire node device on the cloud. When the number of nodes of the blockchain system deployed in the cloud space is more, or the nodes of the blockchain system store more copies of the block data that should be stored in the cloud space, the more storage resources are consumed on the cloud.
In addition, those skilled in the art should know that the copy of the block data stored by each node of the blockchain is basically consistent under the guarantee of the blockchain consensus mechanism. Only a small number of nodes store their data due to maliciousness, failure, or other reasons. The block data is not completely consistent with other nodes. Each block chain has its own fault tolerance mechanism based on the actual application scenario. The block data stored by a small number of the above nodes does not fit the consensus of the block chain. Treated as invalid data. If copies of the block data stored by the above few nodes are also deployed on the cloud, the waste of cloud space is further increased.
In order to solve the above-mentioned problems, FIG. 1 illustrates a method for compressing blockchain data provided by an exemplary embodiment of the present specification. Copies of block data corresponding to N node devices of the blockchain are stored in For a storage system docked with the blockchain, the method includes:
Selecting one node device from the N node devices as the target node device, and adding the block data copy corresponding to the target node device to a compressed data copy set;
Performing a selection iteration step until the number of matching block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain, the selection step includes: selecting the target node from the N node devices In the node devices other than the device, select a node device as the comparison node device in turn; determine whether the copy of the block data corresponding to the target node device and the comparison node device match, and if so, the block corresponding to the comparison node The data copy is added to the compressed data copy set.
The storage system described in the above embodiment refers to a space that can store block data copies corresponding to N nodes of the blockchain, including but not limited to cloud space, storage server, storage server cluster, etc., which can be applied through the cluster , Network technology or decentralized file system and other functions, a large number of storage devices in the network work together to provide a system for external data storage and business access functions.
The block data in the above embodiment refers to all data in each block on the blockchain. The copy of the block data corresponding to the N nodes in the above embodiment may be all the areas corresponding to the N nodes. The block data copy may also be a part of the block data copy corresponding to the N nodes, such as the block data copy corresponding to the N nodes and having a block height from 1000 to 2000.
In the above embodiment, one node device is selected as the target node device from the N node devices. The manner of "selecting" the target node device is not limited, and may be random selection or selection according to preset rules. . The above-mentioned compressed data copy set can be initialized to be empty, and is dedicated to collecting the same block data copy corresponding to the block data copy corresponding to the target node device, which is the area obtained after the compression processing of the block chain data provided in this specification Block compressed data copy set; optionally, the compressed data copy set may also be a subset of the set obtained by compressing all block data copies corresponding to the N nodes.
The selection iteration step described in the foregoing embodiment is used to select the number of block data copies that satisfy the system-set threshold for the compressed data copy set. The block data copies stored by each node of the blockchain are basically consistent under the guarantee of the blockchain consensus mechanism. Only a small number of nodes cause the stored block data to be inconsistent with other nodes due to maliciousness, failure, or other reasons. Each blockchain has its own fault tolerance mechanism based on the actual application scenario. Therefore, after the selection and iteration steps, the number of matching block data copies (including the block data copies corresponding to the target node device) in the compressed data copy set is at least greater than the system fault tolerance of the block chain, ie n>f , Where n is the number of matching block data copies in the compressed data copy set, f is the number of system fault tolerance of the block chain, n and f are both natural numbers, so n should be at least f+1. It is well known to those skilled in the art that the fault tolerance of the blockchain system is usually determined by the consensus mechanism of the blockchain system. For example, under the PBFS consensus agreement, the fault tolerance of the blockchain system f should satisfy: f <(P-1) /3, P is the number of nodes in the blockchain participating in consensus. This specification does not limit the type of consensus agreement of the blockchain system, but the number n of matching block data copies in the above compressed data copy set should be at least greater than the fault tolerance number f of the blockchain system, so as to ensure that the above compressed data copy set The copy of the block data belongs to the valid data copy of the above blockchain consensus.
In the selection iteration step described in the above embodiment, in the sequentially selecting a node device as the comparison node device, there may be multiple ways of "sequential selection", for example, the storage system may be each node device stored therein The numbers are selected in order from the smallest number to the largest number, or from the largest to the smallest number, or any other commonly used sequence method, and are not limited in this specification.
Determining whether the copy of the block data corresponding to the target node device and the comparison node device match in the foregoing embodiment refers to determining whether the copy of the block data corresponding to the target node device and the comparison node device are exactly the same If it is, add the block data copy corresponding to the comparison node to the compressed data copy set; as described above, when the number of matching block data copies in the compressed data copy set is greater than that of the blockchain When the system is fault tolerant, the block data copy in the compressed data copy set must be the correct block data after the consensus of the blockchain system. At this point, the storage system will store the originally stored blocks corresponding to the N node devices. Data copy, discard (can delete) the block data copy that does not meet the consensus result of the blockchain system, and then compress to the compressed data copy set, the number of the compressed data copy set is at least greater than the blockchain system fault tolerance , But it must be less than N, so it plays a role in saving the storage resources of the above storage system.
In yet another illustrated embodiment, the above-mentioned blockchain data compression processing method further includes:
If the selection iteration step is performed and the number of block data copies in the compressed data copy set is still not greater than the system fault tolerance of the blockchain, then a node device is re-selected from the N node devices as The target node device, and repeatedly performs the selection iteration step until the number of block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain.
In the above embodiment, when the round of selection iteration steps is completed, when the number of matching block data copies in the compressed data copy set is not greater than (ie, less than or equal to) the system fault tolerance of the blockchain, The block data copy corresponding to the above target node device may contain malicious or faulty data, which is different from the consensus data confirmed by the consensus mechanism of the blockchain system. Therefore, the storage system needs to empty the original compressed data copy set and select another one. The node device serves as the target node device, and adds its corresponding block data copies to the above-mentioned compressed data copy set, and performs the next selection and iteration step until the number of matching block data copies in the compressed data copy set is greater than The system fault tolerance of the blockchain, the selection of the compressed data copy set is completed.
After the selection and iteration steps of the above rounds are completed, if the storage system has not selected a set of compressed data copies that meet the target number (the number is at least greater than the fault tolerance of the blockchain system), the storage system should iteratively execute the emptying of the previous round. The compressed data copy set, reselecting the target node device, and re-executing all the steps of the selection and iteration steps for the block data copy corresponding to the newly selected target power-saving device. The specific process is as described above and will not be repeated here.
It is worth noting that emptying the compressed data copy set described in the above embodiment may be represented as emptying the compressed data copy set obtained in the last selection iteration step, or may be manifested by re-creating a new compressed data copy set empty The set (or empty subset) is not limited in this specification.
In another embodiment shown in this specification, when the fault-tolerant algorithm supported by the storage system is a Byzantine fault-tolerant algorithm, the number of matching block data copies in the compressed data copy set is greater than that of the blockchain The number of system fault tolerances includes: the number of matching block data copies in the compressed data copy set is both greater than the system fault tolerance of the blockchain and greater than the Byzantine fault tolerance of the compressed data copy set in the storage system Three times the value.
Those skilled in the art should know that in order to ensure that the block data copies collected in the above set of compressed data copies are the data recognized by the consensus of the blockchain system, rather than the erroneous data stored by malicious nodes or faulty nodes, the compressed data copies The number of matching block data copies in the set needs to be greater than the fault tolerance of the blockchain system; further, because the storage system can set up multiple service devices to store block data corresponding to multiple node devices in the above-mentioned blockchain Replica, the storage system will set Byzantine fault tolerance based on the operation of its own service equipment. For example, in this storage system, M storage servers are set up to store the matching areas in the compressed data copy set in the blockchain Block data copy, in order to accommodate the possible failures or other errors of the M storage servers mentioned above, the storage system should generally be set with a fault tolerance number s, and must satisfy M>3s. The fault tolerance number s is called the Byzantine of the storage system Fault tolerance. The relationship between the Byzantine fault tolerance number s and the number M of storage servers in the storage system (which can be regarded as the number M of nodes that initiate system responses) is derived by the following process:
When the system initiates commands to M storage servers or nodes, because there are s wrong nodes, the Ms responses received by the system should be larger than the problem nodes, so the storage system needs to meet, Mss >s' Since M and s are both natural numbers, M should be at least 3s+1. Therefore, the block data copy in the compressed data copy set must be greater than 3 times the Byzantine fault tolerance of the storage system.
In yet another embodiment shown in this specification, when the number of matching block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain, delete the data stored in the storage system except the Compressing data copies other than the data copies in the data copy set; and changing the data access path of the deleted data copy to the data access path of the data copy in the compressed data copy set.
In the above embodiment, when the number of matching block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain, that is, the compressed data copy set is selected, the storage system may delete the storage Data copies stored in the system other than the data copies in the compressed data copy set to save storage resources of the storage system; at the same time, because the block data copies corresponding to some node devices in the above blockchain have been deleted, the above When the node device accesses its corresponding block data copy in the storage system according to business requirements, the storage system should change the data access path of the deleted block data copy to point to the block data in the compressed data copy set The data access path of the copy, for example, the storage system may update the mapping between the node device and the deleted block data copy to the mapping between the node device and the block data copy in the compressed data copy set to illustrate the node The device accesses its corresponding block data copy.
In yet another embodiment shown in this specification, the above storage system may be a cloud storage system connected to the blockchain.
Corresponding to the implementation of the above process, the embodiments of the present specification also provide a compression processing device for blockchain data. The device can be realized by software, or by hardware or a combination of hardware and software. Taking software implementation as an example, as a logical device, it is formed by reading the corresponding computer program instructions into the memory through the CPU (Central Process Unit) of the device. From the hardware level, in addition to the CPU, memory, and memory shown in FIG. 3, the device where the data processing device is located usually includes other hardware such as chips for wireless signal transmission and reception, and/or It is used for other hardware such as boards and cards for network communication.
FIG. 2 shows a block data compression processing device 20 provided in this specification. Block data copies corresponding to the N node devices of the block chain are stored in a storage system connected to the block chain , The device 20 includes:
The target data selection unit 202 selects one node device from the N node devices as the target node device, and adds the block data copy corresponding to the target node device to a compressed data copy set;
The selection iteration execution unit 204 executes the selection iteration step until the number of matching block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain. The selection step includes: selecting from the N nodes In the node devices other than the target node device in the device, select a node device as the comparison node device in turn; determine whether the copy of the block data corresponding to the target node device and the comparison node device match, and if so, change the The block data copy corresponding to the comparison node is added to the compressed data copy set.
More preferably, if the selection iteration execution unit 204 of the above device 20 executes the selection iteration step, the number of block data copies in the compressed data copy set is still not greater than the system fault tolerance of the blockchain, then Re-select a node device from the N node devices as the target node device, and repeat the selection iteration step until the number of block data copies in the compressed data copy set is greater than that of the blockchain system Fault tolerance.
More preferably, the number of matching block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain, including:
The number of matching block data copies in the compressed data copy set is both greater than the system fault tolerance of the blockchain and three times the Byzantine fault tolerance value of the compressed data copy set in the storage system.
More preferably, the above device 20 further includes:
The data deleting unit 208 deletes the data stored in the storage system except the compressed data copy set when the number of matching block data copies in the compressed data copy set is greater than the system fault tolerance of the blockchain Copies of materials other than copies;
And, the access path changing unit 210 changes the data access path of the deleted block data copy to the data access path of the block data copy in the compressed data copy set.
More preferably, the storage system is a cloud storage system connected to the blockchain.
For the implementation process of the functions and functions of the units in the above device, please refer to the implementation process of the corresponding steps in the above method for specific details. For the relevant parts, please refer to the description of the method embodiments, which will not be repeated here.
The device embodiments described above are only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical modules, that is, may Located in one place, or can be distributed to multiple network modules. Some or all of the units or modules can be selected according to actual needs to achieve the purpose of the solution in this specification. Those of ordinary skill in the art can understand and implement without paying creative labor.
The devices, units, and modules illustrated in the above embodiments may be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, and the specific form of the computer may be a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email sending and receiving device, and a game control Desk, tablet, wearable device, or any combination of these devices.
Corresponding to the above method embodiments, the embodiments of the present specification also provide a computer device, which includes a memory and a processor. Among them, a computer program that can be executed by the processor is stored on the memory; when the processor runs the stored computer program, each step of the compression processing method of the blockchain data in the embodiment of the present specification is executed. For a detailed description of the various steps of the storage system's compression processing method for blockchain data, please refer to the previous content, and it will not be repeated.
Corresponding to the above method embodiments, the embodiments of the present specification also provide a computer-readable storage medium that stores computer programs on the storage medium. When the computer programs are executed by the processor, the blocks in the embodiments of the present specification are executed. The various steps of the chain data compression processing method. For a detailed description of the various steps of the storage system's compression processing method for blockchain data, please refer to the previous content, and it will not be repeated.
The above are only the preferred embodiments of this specification and are not intended to limit this specification. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of this specification should be included in this specification Within the scope of protection.
In a typical configuration, the computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
Memory may include non-permanent memory, random access memory (RAM) and/or non-volatile memory in computer-readable media, such as read-only memory (ROM) or flash memory (flash) RAM). Memory is an example of computer-readable media.
Computer-readable media, including permanent and non-permanent, removable and non-removable media, can be stored by any method or technology. The information can be computer readable instructions, data structures, modules of programs, or other data.
Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM) , Read-only memory (ROM), electrically erasable and programmable read-only memory (EEPROM), flash memory or other memory technologies, read-only disc read-only memory (CD-ROM), digital multifunction Optical discs (DVDs) or other optical storage, magnetic cassette tapes, magnetic tape magnetic tape storage or other magnetic storage devices or any other non-transmission media can be used to store information that can be accessed by computing devices. According to the definition in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
It should also be noted that the terms "include", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device that includes a series of elements includes not only those elements, but also includes Other elements not explicitly listed, or include elements inherent to this process, method, commodity, or equipment. Without more restrictions, the element defined by the sentence "include one..." does not exclude that there are other identical elements in the process, method, commodity, or equipment that includes the element.
Those skilled in the art should understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, the embodiments of the present specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present specification may employ computer programs implemented on one or more computer usable storage media (including but not limited to disk memory, CD-ROM, optical memory, etc.) containing computer usable program code The form of the product.