Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify trades based on their UUID #117

Merged
merged 4 commits into from
Apr 12, 2018
Merged

Identify trades based on their UUID #117

merged 4 commits into from
Apr 12, 2018

Conversation

lukechilds
Copy link
Member

@lukechilds lukechilds commented Apr 11, 2018

This requires a custom build of mm with UUID support. We shouldn't merge this until there's an official build with the UUID update.

This has simplified a lot of the swap tracking code and swapDB code. I stopped storing all the pseudo ids (tradeid,aliceid, requestid, quoteid) in our DB as we didn't actually use them for anything apart from the crazy tracking logic. Now all we need is the UUID. All socket messages should have this and it should be unique.

api.subscribeToSwap() now only requires a UUID as an argument as apposed to an object containing a tradeid/aliceid or requestid/quoteid combo.

It's important we always check if uuid is set before we start tracking a swap, otherwise it'll check for message.uuid === undefined on every message, which will be true for every non swap message (there are a huge amount of those) and it'll jsut fill the database with random messages. Learned that the hard way.

https://github.com/lukechilds/hyperdex/pull/117/files#diff-ec72782f2b90873687d6bfdd5f291908R45

We now have a much simpler index as we don't need to index all those different ids and create multiple indexes to make sorting work because of bugs in PouchDB.

We still don't properly detect unmatched trades, they will display as pending forever. UUIDs don't help with that, we need to implement our own logic to catch this that works the same was as marketmaker. More info here: jl777/SuperNET#745

There is also a tiny memory leak:

https://github.com/lukechilds/hyperdex/pull/117/files#diff-ec72782f2b90873687d6bfdd5f291908R64

We only remove the event listened on completed swaps, not on failed swaps. This will be very easy to add, we just need to check for both events. However I ran into a very strange situation in my tests where one swap was failed and the a few seconds later completed. Reported here: jl777/SuperNET#756. In that case if I removed the listener on the failed event we wouldn't of ever got the complete event. So I'm aware of this but leaving it as is for now until that issue is resolved. The memory implications of the memory leak should be miniscule.

@lukechilds lukechilds changed the title UUID Identify trades based on their UUID Apr 11, 2018
await swapEmitter.once('finished');
stopNetworkListener();
})();
swapEmitter.once('completed').then(removeListener);
Copy link
Contributor

Choose a reason for hiding this comment

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

You are the one emitting this event, so couldn't you just call removeListener() on line 60?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently yes, but this will be updated in the future to support other events such as 'failed' so I think it makes more sense to have it here.

@sindresorhus
Copy link
Contributor

I really like how much simpler the code is. 👌✨

@sindresorhus
Copy link
Contributor

I've done many successful trades with this branch, so seems to work well.

@lukechilds
Copy link
Member Author

Brilliant!

@lukechilds lukechilds merged commit ea77360 into master Apr 12, 2018
@lukechilds lukechilds deleted the uuid branch April 12, 2018 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants