Search code examples
node.jsdockerhyperledger-fabrichyperledger

Why do I take more than 2 seconds to just do a transaction?


I have my Hyperledger Fabric working with the docker containers up. I have my Hyperledger client, writte in Node.js, using the Fabric Node SDK.

I have an API pointer /createEntity that calls the function "createEntity" on the contract with contract.submitTransaction() and writes some data on the Blockchain.

I send the data and I correctly see on the docker logs of the peer that the contract function is invoked correctly and it terminates after just some milliseconds, adding the new data inside the Blockchain. But it tooks around 2 seconds to actually respond to the Node.js server that the transaction has been done and the data is written. So, my Node.js server is waiting for answers for 2 seconds.

Just to have some timings:

This is printed by Node.js server as soon as I invoke the createEntity API: Create Entity: 2019-07-08T13:29:28.781Z

This is printed by the docker logs of Hyperledger: createEntity 2019-07-08 13:29:28.814697426

So after some milliseconds the transaction arrives, and in some milliseconds the transaction is created and written on the ledger, in fact I write the timings after the createEntity function on the contract finishes and I have: createEntity finished at: 2019-07-08 13:29:28.818830574

But the answer to the Node.js server arrives at: Transaction has been submitted 2019-07-08T13:29:30.842Z

Do someone know what is this delay? I don't want transaction to take 2 seconds, it has to be immediate.

Thanks


Solution

  • The submitTransaction function would take its time to finish,as by default the commit listener is enabled.

    So it would wait for the data to be committed and then respond back.

    You can disable the commitListener by adding eventHandlerOptions:{strategy:null} in the connection option while setting up the gateway.

    Hope The bellow code snipped would help you out.

     let connectionOptions = {
            identity: USER_ID,
            wallet: wallet,
            discovery: { enabled: false, asLocalhost: true },
            eventHandlerOptions: {
                 strategy: null
                 }
             }
    
        await gateway.connect(connectionProfile, connectionOptions)