Custom connector


andZka
 

Hi all,
I created a custom connector to benchmark the Cosmos blockchain.
The connector works but the preparation phase is currently slow due to the fact that the creation of identities for testing is done in the getContext function and therefore is performed by every worker.
By inserting this process into other functions, digital identities are not found by workers.
My intention is to effect the creation of the accounts in the init function by the process manager and then distribute it to the workers with the prepareWorkerArguments function, as suggested among other things by the documentation on the writing-connectors page: https://hyperledger.github.io/caliper/v0.5.0/writing-connectors/
However, I did not understand how these objects returned by the prepareWorkerArguments function can be used by workers, I also checked the code of the connectors already implemented but I could not find concrete examples.
For example, given the result object returned by the prepareWorkerArguments function, how can I use it in the _sendSingleRequest function?
andZka


Attila Klenik
 

Hi! 

It's good to hear that you're writing a custom connector for Caliper. If you'd like to share any feedback with us, you can do so here or in the Caliper contributor discord channel after registration (https://discord.com/channels/905194001349627914/941417722946924554).

To answer your question with concrete examples:
  1. The Caliper manager process will call your connector's prepareWorkerArguments function (after initializing the connector through its init function), passing it the number of configured workers as a parameter.
  2. The function can return arbitrary objects for each worker as an array (each element corresponds to a worker). For example, the Ethereum connector's implementation returns the same object for all workers, namely the detailed information of deployed contracts (https://github.com/hyperledger/caliper/blob/91870b7e51425ecc472e3c114eadee3026d18d42/packages/caliper-ethereum/lib/ethereum-connector.js#L421-L427)
  3. Then, before every round, your connector's getContext function is called on every worker (Ethereum connector example: https://github.com/hyperledger/caliper/blob/91870b7e51425ecc472e3c114eadee3026d18d42/packages/caliper-ethereum/lib/ethereum-connector.js#L146). The args parameter is the worker's corresponding object/element from the above array. You process it in any way you want; for example, save it in a class instance variable (once, on the first getContext call) and use the data from the _sendSingleRequest function.

I hope the above explanation clarifies things; let us know if you need further help (either here or in the discord channel)!

Best Regards,
Attila