Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Organize async task queues by network #375

Merged
merged 4 commits into from
Feb 7, 2018

Conversation

BMillman19
Copy link
Contributor

Description

Generalized the RequestQueue into a DispatchQueue that serializes any arbitrary asynchronous tasks.

Motivation and Context

Because the same address was being used to dispense both ETH and ZRX, sometimes the transaction nonces would get messed up. This fixes that problem by serializing transactions on a per network basis and only advancing the queue once the in-flight transaction resolves.

How Has This Been Tested?

Local testing

Types of changes

  • Bug fix (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 change)

Checklist:

  • Change requires a change to the documentation.
  • Added tests to cover my changes.

@coveralls
Copy link

coveralls commented Feb 7, 2018

Coverage Status

Coverage decreased (-0.02%) to 90.261% when pulling 2404ff0 on feature/testnet-faucets/queue-by-network into a26e770 on development.

Copy link
Contributor

@fabioberger fabioberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super pumped about this!

private _start() {
this._queueIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval(
async () => {
const task = this._queue.shift();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename task to taskAsync

await task();
},
this._queueIntervalMs,
_.noop,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should actually handle the error here. If we encounter one, let's log the error to Rollbar and stop the thrown error from crashing the process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see this is done in the individual actions. It would be cleaner to move it up here, then it only lives in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm its a bit tricky because the error reporting is asynchronous, let's sync up if theres a way to fix this

private _dispenseAsset(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType) {
const networkId = req.params.networkId;
const recipient = req.params.recipient;
const networkConfig = _.get(this._networkConfigByNetworkId, networkId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's simply index in here rather then use _.get.

* development: (24 commits)
  Fix Remco's github name in CODEOWNERS
  Fix ABI error message
  Stop using definite assignment assertion cause prettier doesn't handle that
  Special-case ZRXToken snake case conversion
  Fix linter errors
  Generate contract wrappers on pre-build
  Add missing async
  Remove noImplicitThis
  Tslint disable no-consecutive-blank-lines in generated files
  Change compiled sources in contracts
  Change utils
  Change tests
  Add base_contract.ts
  Remove generated files
  .gitignore gemerated files
  Change the list of generated wrappers
  Change contract templates
  Add indices for index parameters so that their names don't collide
  Use abi-gen for events in 0x.js
  Fix artifacts path
  ...
dispenserTask = dispenseAssetTasks.dispenseEtherTask(recipient, networkConfig.web3);
break;
case RequestedAssetType.WETH:
dispenserTask = dispenseAssetTasks.dispenseTokenTask(recipient, requestedAssetType, networkConfig.zeroEx);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be defaulted to the same case statement body?

case RequestedAssetType.WETH:
case RequestedAssetType.ZRX:
    dispenserTask = dispenseAssetTasks.dispenseTokenTask(recipient, requestedAssetType, networkConfig.zeroEx);
    break;

@BMillman19 BMillman19 requested a review from recmo as a code owner February 7, 2018 19:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants