Hyperledger Fabric sorting node processing Deliver request Process

Source: Internet
Author: User
Tags hyperledger fabric

Hyperledger source code Analysis of Fabric

Deliver means that the client obtains data from the ordering service via the Grpc interface (for example, data from a specified block).

The Orderer node receives the request message, which is first given to the Deliver of the server structure in the Orderer.common.server package (SRV ab. Atomicbroadcast_deliverserver) Error method processing. This method further invokes the Handle of the deliverserver structure in the Orderer.common.deliver package (SRV ab. Atomicbroadcast_deliverserver) Error method for processing.

Deliverserver structure is very important to complete the process of Deliver request.

Type deliverserver struct {
    error
Overall Process

The overall process is shown in the following illustration.


Handle (SRV ab. Atomicbroadcast_deliverserver) The error method opens a loop to continuously read and process the request message from SRV until the end.

The core code is as follows, including two steps to extract the message and handle the message.

For {
    envelope, err: = srv. RECV ()//extracts a Envelope message from the request
    ds.deliverblocks (SRV, Envelope)//handles the message and replies, core Process}

Visible, processing of a single request is deliverblocks (SRV ab. Atomicbroadcast_deliverserver, envelope *CB. Envelope) method. The processing of the method includes four steps for parsing the message, checking the legality, sending the block, and returning the response.

The following specific analysis of its specific. parsing Messages

First, the load (Payload) is extracted from the requested Envelope structure to further extract the channel head information from the load. Take the channel header information to obtain the corresponding local chain structure and get the current configuration sequence number.

Extract load payload, err: = Utils. Unmarshalpayload (envelope. Payload)//Extract channel header Chdr, err: = Utils. Unmarshalchannelheader (payload. Header.channelheader)//Get chain structure, map to Orderer.common.multichannel package registrar structure in the corresponding method chain, OK: = Ds.sm.GetChain (CHDR. Channelid)//Get current configuration serial number lastconfigsequence: = Chain. Sequence ()
Check Legality

Includes checking for permissions and seekinfo data.

First, check to see if the requester has read access to the channel.

SF: = Msgprocessor. Newsigfilter (policies. Channelreaders, chain. Policymanager ()) If err: = SF. Apply (envelope); Err!= Nil {
    logger. WARNINGF ("[Channel:%s] Received unauthorized deliver request from%s:%s", Chdr. Channelid, addr, err) return
    sendstatusreply (SRV, CB. Status_forbidden)}

Next, the SEEKINFO structure is parsed from the Payload.data domain of the Envelope structure, and its legality is examined.

Proto. Unmarshal (payload. Data, Seekinfo) chain. Reader (). Iterator (Seekinfo.start)/check seekinfo cursor, number: = Chain. Reader (). Iterator (seekinfo.start) switch stop: = SeekInfo.Stop.Type. (type) {Case *ab. Seekposition_oldest://Until the earliest block
    stopnum = Numbercase *ab. Seekposition_newest://Up to the newest block
    stopnum = chain. Reader (). Height ()-1case *ab. Seekposition_specified://Up to a specific block
    Stopnum = stop. Specified.number
    If Stopnum < number {
        logger. WARNINGF ("[Channel:%s] Received invalid Seekinfo message from%s:start number%d greater than stop number%d", Chdr. Channelid, addr, number, stopnum) return
        sendstatusreply (SRV, CB. status_bad_request)
    }}
Send block

Reads the blocks from the local ledger and sends the corresponding chunk data within the specified starting and closing ranges,

The core code is shown below.

For {block
    , Status: = Cursor. Next ()//Get chunk
    sendblockreply (SRV, block)//Send blocks
    if Stopnum = block. Header.number {
        break
    }}
return Response

If the processing succeeds, a successful response message is returned.

Sendstatusreply (SRV, CB. STATUS_SUCCESS)


===========================


"Block chain principle, design and application" a book has been officially published, with the Super Ledger project as an example, introduced the block chain and distributed ledger technology, the underlying principles, design framework, the application of a large number of details, welcome to read.


===== about Techfirst Public number =====

Focus on financial technology, artificial intelligence, cloud computing, large data-related areas of hot technology and forward-looking direction.

Send keywords (such as block chain, cloud computing, large data, containers), get popular comments and technical dry goods.

Welcome to contribute.

If you like the public number, please encourage a cup of coffee~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.