[翻譯]HyperLedger下一代總賬架構提案

來源:互聯網
上載者:User
[翻譯]Next-Ledger-Architecture-Proposal

原文:https://github.com/hyperledger/fabric/blob/master/proposals/r1/Next-Ledger-Architecture-Proposal.md

翻譯:梧桐樹

草案 / 進行中

該文檔是基於社區反饋的未來ledger架構的一個提案。 所有的輸入都是社區努力的目標。 目錄

目的
API
時間點查詢
查詢語言 目的

探索新ledger架構的動機來自於社區反饋。現存的ledger可以支援一些(但不是所有)下面的需求,我們要探索一種新的ledger來滿足已經瞭解的所有需求。 根據在很多社區(Slack、Github等)及面對面的討論,很顯然,大家強烈希望支援以下需求: 時間點查詢 - 在上一區塊查詢chaincode state,容易跟蹤沒有重放交易的譜系 像SQL一樣的的查詢語言 隱私 - 完整的ledger可能不會存在於所有的committers 加密的安全ledger - 資料完整性不參照其他節點 支援像PBFT那樣提供即時終結的共識演算法 支援像PoW、PoET那樣需要隨機收斂的共識演算法 裁剪 - 根據需要刪除舊的交易資料 支援背書從共識中分離,詳情見 下一代共識架構提案。 這意味著,某些peer在沒有執行交易或查看chaincode邏輯的情況下想他們的ledger申請背書結果。 API / Enginer 分離。按需插入不同的儲存引擎。 API

以Go虛擬碼寫成的建議API

package ledgerimport "github.com/hyperledger/fabric/protos"// Encryptor is an interface that a ledger implementation can use for Encrypt/Decrypt the chaincode statetype Encryptor interface {Encrypt([]byte) []byteDecrypt([]byte) []byte}// PeerMgmt is an interface that a ledger implementation expects from peer implementation// type PeerMgmt interface {// IsPeerEndorserFor returns 'true' if the peer is endorser for given chaincodeIDIsPeerEndorserFor(chaincodeID string) bool// ListEndorsingChaincodes return the chaincodeIDs for which the peer acts as one of the endorsersListEndorsingChaincodes() []string// GetEncryptor returns the Encryptor for the given chaincodeIDGetEncryptor(chaincodeID string) (Encryptor, error)}// In the case of a confidential chaincode, the simulation results from ledger are expected to be encrypted using the 'Encryptor' corresponding to the chaincode.// Similarly, the blocks returned by the GetBlock(s) method of the ledger are expected to have the state updates in the encrypted form.// However, internally, the ledger can maintain the latest and historical state for the chaincodes for which the peer is one of the endorsers - in plain text form.// TODO - Is this assumption correct?// General purpose interface for forcing a data element to be serializable/de-serializabletype DataHolder interface {GetData() interface{}GetBytes() []byteDecodeBytes(b []byte) interface{}}type SimulationResults interface {DataHolder}type QueryResult interface {DataHolder}type BlockHeader struct {}type PrunePolicy interface {}type BlockRangePrunePolicy struct {FirstBlockHash stringLastBlockHash  string}// QueryExecutor executes the queries// Get* methods are for supporting KV-based data model. ExecuteQuery method is for supporting a rich datamodel and query support//// ExecuteQuery method in the case of a rich data model is expected to support queries on// latest state, historical state and on the intersection of state and transactionstype QueryExecutor interface {GetState(key string) ([]byte, error)GetStateRangeScanIterator(startKey string, endKey string) (ResultsIterator, error)GetStateMultipleKeys(keys []string) ([][]byte, error)GetTransactionsForKey(key string) (ResultsIterator, error)ExecuteQuery(query string) (ResultsIterator, error)}// TxSimulator simulates a transaction on a consistent snapshot of the as recent state as possibletype TxSimulator interface {QueryExecutorStartNewTx()// KV data modelSetState(key string, value []byte)DeleteState(key string)SetStateMultipleKeys(kvs map[string][]byte)// for supporting rich data model (see comments on QueryExecutor above)ExecuteUpdate(query string)// This can be a large payloadCopyState(sourceChaincodeID string) error// GetTxSimulationResults encapsulates the results of the transaction simulation.// This should contain enough detail for// - The update in the chaincode state that would be caused if the transaction is to be committed// - The environment in which the transaction is executed so as to be able to decide the validity of the enviroment//   (at a later time on a different peer) during committing the transactions// Different ledger implementation (or configurations of a single implementation) may want to represent the above two pieces// of information in different way in order to support different data-models or optimize the information representations.// TODO detailed illustration of a couple of representations.GetTxSimulationResults() SimulationResultsHasConflicts() boolClear()}type ResultsIterator interface {// Next moves to next key-value. Returns true if next key-value existsNext() bool// GetKeyValue returns next key-valueGetResult() QueryResult// Close releases resources occupied by the iteratorClose()}// Ledger represents the 'final ledger'. In addition to implement the methods inherited from the BasicLedger,// it provides the handle to objects for querying the chaincode state and executing chaincode transactions.type ValidatedLedger interface {Ledger// NewTxSimulator gives handle to a transaction simulator for given chaincode and given fork (represented by blockHash)// A client can obtain more than one 'TxSimulator's for parallel execution. Any synchronization should be performed at the// implementation level if requiredNewTxSimulator(chaincodeID string, blockHash string) (TxSimulator, error)// NewQueryExecuter gives handle to a query executer for given chaincode and given fork (represented by blockHash)// A client can obtain more than one 'QueryExecutor's for parallel execution. Any synchronization should be performed at the// implementation level if requiredNewQueryExecuter(chaincodeID string, blockHash string) (QueryExecutor, error)// CheckpointPerformed is expected to be invoked by the consensus algorithm when it completes a checkpoint across peers// On the invoke of this method, the block in the 'RawLedger' between the 'corresponding to the block currently checkpointed' and// 'corresponding to the block checkpointed last time' can be pruned.// (Pruning the raw blocks would need an additional time based factor as well, if forks are to be supported in the raw ledger.)// (Does raw ledger in the case of a consensus that allow forks (e.g., PoW) make sense at all? Or practically, these consensus// would always produce the final blocks that contains validated transactions).CheckpointPerformed(blockHash string)RemoveInvalidTransactions(block *protos.Block) (*protos.Block, error)}// RawLedger implements methods required by 'raw ledger'// CommitBlock() of RawLedger is expected to be invoked by the consensus algorithm when a new block is constructed.// Upon receiving the new block, it is expected to be 'processed' by the ledger - the processing includes -// preserving the raw block, validating each transaction in the block, discarding the invalid transactions,// preparing the final block with the rmaining (i.e. valid) transactions and committing the final block (including updating the state).// The raw block should not be deleted as yet - until the corresponding 'final block' is included in one of the following checkpoint performed by the consensus.type RawLedger interface {Ledger}//Ledger captures the methods that are common across the 'raw ledger' and the 'final ledger'type Ledger interface {//GetTopBlockHashes returns the hashes of the top most block in each fork.GetTopBlockHashes() []string//CommitBlock adds a new blockCommitBlock(block *protos.Block) error//GetTransactionByID retrieves a transaction by idGetTransactionByID(txID string) (*protos.Transaction, error)//GetBlockChain returns an instance of chain that starts at theGetBlockChain(topBlockHash string) (BlockChain, error)//Prune prunes the blocks/transactions that satisfy the given policyPrune(policy PrunePolicy) error}//BlockChain represents an instance of a block chain. In the case of a consensus algorithm that could cause a fork, an instance of BlockChain// represent one of the forks (i.e., one of the chains starting from the genesis block to the one of the top most blocks)type BlockChain interface {GetTopBlockHash() stringGetBlockchainInfo() (*protos.BlockchainInfo, error)GetBlockHeaders(startingBlockHash, endingBlockHash string) []*BlockHeaderGetBlocks(startingBlockHash, endingBlockHash string) []*protos.BlockGetBlockByNumber(blockNumber uint64) *protos.BlockGetBlocksByNumber(startingBlockNumber, endingBlockNumber uint64) []*protos.BlockGetBlockchainSize() uint64VerifyChain(highBlock, lowBlock uint64) (uint64, error)}
Engine 具體思路 時間點查詢

在抽象的時間方面,有三種查詢對chaincode和應用開發人員非常重要: 查詢一個key的最新value。(類型: 當前; 例如,現在Alice的賬戶裡有多少錢。) 查詢一個key在某一特定時間的value。(類型: 曆史; 例如,在上個月Alice的賬戶餘額是多少。) 查詢一個key隨著時間變化的所有value。(類型: 系列; 例如,產生Alice的交易列表。)

當制定一個查詢時,開發人員將受益於過濾、預測以及交易間關聯等功能。考慮下面的例子: 簡單過濾:查詢所有上個月餘額低於100美元的賬戶。 複雜過濾:查詢所有Trudy的,發生在敘利亞或伊拉克的,總量大於一個閾值的,其他部分的名稱匹配一個Regex的交易。 關聯:確定是否Alice在同一天同一加油站買過不止一次油。將此資訊輸入詐騙檢測模型。 預測: 查詢Alice最後10個交易的市、州、國和金額。這些資訊被輸入風險/欺詐檢測模型。 查詢語言

開發一種查詢語言來支援不同的查詢範圍並不簡單。面臨的挑戰: 隨著開發人員需求的增長擴充查詢語言。截至目前,開發人員的請求已經不大。隨著Hyperledger項目的使用者增加,查詢將更複雜。 兩個不太相關的類的查詢: 查詢符合約束的單一value。適合現有的SQL和NoSQL文法。 查詢滿足約束的交易的一個chain或者多個chain。適合圖形查詢語言,如 Neo4J’s Cypher or SPARQL

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.