日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

百度超级链XChain(4)核心数据结构

發布時間:2025/3/21 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 百度超级链XChain(4)核心数据结构 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

注意為“區塊”、“交易”、“UTXO”和“讀寫集”。

1. 區塊

區塊以DAG方式鏈接起來形成的鏈。因此,區塊是區塊鏈的基本單元。

  • 功能
    區塊是區塊鏈的基本單元,通常為了提高區塊鏈網絡的吞吐,礦工會在一個區塊中打包若干個交易。一個區塊通常由區塊頭以及區塊體組成。

  • 代碼
    區塊的Proto如下
1message InternalBlock {2 // block version3 // 區塊版本4 int32 version = 1;5 // Random number used to avoid replay attacks6 // 隨機數,用來避免重放攻擊7 int32 nonce = 2;8 // blockid generate the hash sign of the block used by sha2569 // 區塊的唯一標識 10 bytes blockid = 3; 11 // pre_hash is the parent blockid of the block 12 // 區塊的前置依賴區塊ID 13 bytes pre_hash = 4; 14 // The miner id 15 // 礦工ID 16 bytes proposer = 5; 17 // 礦工對區塊的簽名 18 // The sign which miner signed: blockid + nonce + timestamp 19 bytes sign = 6; 20 // The pk of the miner 21 // 礦工公鑰 22 bytes pubkey = 7; 23 // The Merkle Tree root 24 // 默克爾樹樹根 25 bytes merkle_root = 8; 26 // The height of the blockchain 27 // 區塊所在高度 28 int64 height = 9; 29 // Timestamp of the block 30 // 打包區塊的時間戳 31 int64 timestamp = 10; 32 // Transactions of the block, only txid stored on kv, the detail information 33 // stored in another table 34 // 交易內容 35 repeated Transaction transactions = 11; 36 // The transaction count of the block 37 // 區塊中包含的交易數量 38 int32 tx_count = 12; 39 // 所有交易hash的merkle tree 40 repeated bytes merkle_tree = 13; 41 // 采用DPOS共識算法時,當前是第幾輪 42 int64 curTerm = 16; 43 int64 curBlockNum = 17; 44 // 區塊中執行失敗的交易以及對應的失敗原因 45 map<string, string> failed_txs = 18; // txid -> failed reason 46 // 采用POW共識算法時,對應的挖礦難度值 47 int32 targetBits = 19; 48 // 下面的屬性會動態變化 49 // If the block is on the trunk 50 // 該區塊是否在主干上 51 bool in_trunk = 14; 52 // Next next block which on trunk 53 // 當前區塊的后繼區塊ID 54 bytes next_hash = 15; 55}

2. 交易

  • 背景
    區塊鏈網絡中的每個節點都是一個狀態機,為了給每個節點傳遞狀態,系統引入了交易,作為區塊鏈網絡狀態更改的最小操作單元。
  • 功能
    通常表現為普通轉賬以及智能合約調用。
  • 代碼
    交易的Proto如下
1message Transaction {2 // txid is the id of this transaction3 // 交易的唯一標識4 bytes txid = 1;5 // the blockid the transaction belong to6 // 交易被打包在哪個區塊中7 bytes blockid = 2;8 // Transaction input list9 // UTXO來源 10 repeated TxInput tx_inputs = 3; 11 // Transaction output list 12 // UTXO去處 13 repeated TxOutput tx_outputs = 4; 14 // Transaction description or system contract 15 // 交易內容描述或系統合約 16 bytes desc = 6; 17 // Mining rewards 18 // 礦工獎勵 19 bool coinbase = 7; 20 // Random number used to avoid replay attacks 21 // 隨機數 22 string nonce = 8; 23 // Timestamp to launch the transaction 24 // 發起交易的時間戳 25 int64 timestamp = 9; 26 // tx format version; tx格式版本號 27 int32 version = 10; 28 // auto generated tx 29 // 該交易是否屬于系統自動生成的交易 30 bool autogen = 11; 31 // 讀寫集中的讀集 32 repeated TxInputExt tx_inputs_ext = 23; 33 // 讀寫集中的寫集 34 repeated TxOutputExt tx_outputs_ext = 24; 35 // 該交易包含的合約調用請求 36 repeated InvokeRequest contract_requests = 25; 37 // 權限系統新增字段 38 // 交易發起者, 可以是一個Address或者一個Account 39 string initiator = 26; 40 // 交易發起需要被收集簽名的AddressURL集合信息,包括用于utxo轉賬和用于合約調用 41 repeated string auth_require = 27; 42 // 交易發起者對交易元數據簽名,簽名的內容包括auth_require字段 43 repeated SignatureInfo initiator_signs = 28; 44 // 收集到的簽名 45 repeated SignatureInfo auth_require_signs = 29; 46 // 節點收到tx的時間戳,不參與簽名 47 int64 received_timestamp = 30; 48 // 統一簽名(支持多重簽名/環簽名等,與initiator_signs/auth_require_signs不同時使用) 49 XuperSignature xuper_sign = 31; 50}

3. UTXO

  • 背景
    區塊鏈中比較常見的兩種操作,包括普通轉賬以及合約調用,這兩種操作都涉及到了數據狀態的引用以及更新。為了描述普通轉賬涉及到的數據狀態的引用以及更新,引入了UTXO(Unspent Transaction Output)。
  • 功能
    一種記賬方式,用來描述普通轉賬時涉及到的數據狀態的引用以及更新。通常由轉賬來源數據(UtxoInput)以及轉賬去處數據(UtxoOutput)組成。
  • 代碼
    UTXO的Proto如下
1message Utxo {2 // 轉賬數量3 bytes amount = 1;4 // 轉給誰5 bytes toAddr = 2;6 // 轉給誰的公鑰7 bytes toPubkey = 3;8 // 該Utxo屬于哪一個交易9 bytes refTxid = 4; 10 // 該Utxo數據哪一個交易的哪一個offset 11 int32 refOffset = 5; 12} 13// UtxoInput query info to query utxos 14// UTXO的轉賬來源 15message UtxoInput { 16 Header header = 1; 17 // which bcname to select 18 // UTXO來源屬于哪一條鏈 19 string bcname = 2; 20 // address to select 21 // UTXO來源屬于哪個address 22 string address = 3; 23 // publickey of the address 24 // UTXO來源對應的公鑰 25 string publickey = 4; 26 // totalNeed refer the total need utxos to select 27 // 需要的UTXO總額 28 string totalNeed = 5; 29 // userSign of input 30 // UTXO來源的簽名 31 bytes userSign = 7; 32 // need lock 33 // 該UTXO是否需要鎖定(內存級別鎖定) 34 bool needLock = 8; 35} 36// UtxoOutput query results 37// UTXO的轉賬去處 38message UtxoOutput { 39 Header header = 1; 40 // utxo list 41 // UTXO去處 42 repeated Utxo utxoList = 2; 43 // total selected amount 44 // UTXO去處總額 45 string totalSelected = 3; 46}

4. 讀寫集

  • 背景:區塊鏈中比較常見的兩種操作,包括普通轉賬以及合約調用,這兩種操作都涉及到了數據狀態的引用以及更新。為了描述合約調用涉及到的數據狀態的引用以及更新,引入了讀寫集。
  • 功能:一種用來描述合約調用時涉及到的數據狀態的引用以及更新的技術。通常由讀集(TxInputExt)以及寫集(TxOutputExt)組成。
  • 代碼:讀寫集的Proto如下
1// 擴展輸入2message TxInputExt {3 // 讀集屬于哪一個bucket4 string bucket = 1;5 // 讀集對應的key6 bytes key = 2;7 // 讀集屬于哪一個txid8 bytes ref_txid = 3;9 // 讀集屬于哪一個txid的哪一個offset 10 int32 ref_offset = 4; 11} 12// 擴展輸出 13message TxOutputExt { 14 // 寫集屬于哪一個bucket 15 string bucket = 1; 16 // 寫集對應的key 17 bytes key = 2; 18 // 寫集對應的value 19 bytes value = 3; 20} 《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的百度超级链XChain(4)核心数据结构的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。