convector icon indicating copy to clipboard operation
convector copied to clipboard

fix: preserve context with cls-hooked

Open diestrin opened this issue 4 years ago • 0 comments

Proposed changes

Use a context data library, cls-hooked to fix a context issue reported in #105.

Previously, convector had problems with concurrent transaction, because it was setting a global variable BaseStorage.current on each chaincode @Invoke. This variable contains a reference to the Fabric STUB object, where operations (reads and writes to the ledger) get written for each transaction. So when a second @Invoke is received, the STUB gets overwritten, and all the operations of the first transaction still pending to run (because asynchronicity) end up being registered in the incorrect STUB. This causes all sorts of wrong behaviors, like trying to write in a transaction STUB that has already finished, or simply putting the reads and writes in different blocks, which is not accurate at all.

Types of changes

  • [x] Bugfix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • [x] I have read the CONTRIBUTING doc
  • [x] Lint and unit tests pass locally with my changes
  • [x] All the commits have been squashed into a single commit following the conventional commits guide
  • [x] All the commits are signed with git sign-off
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] I have added necessary documentation (if appropriate)

diestrin avatar Jan 08 '21 06:01 diestrin