This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
albrow
force-pushed
the
feature/custom-order-filters-rebase
branch
from
January 8, 2020 22:22
898614b
to
8d77bbe
Compare
albrow
force-pushed
the
feature/custom-order-filters-rebase
branch
from
January 9, 2020 20:54
630e6c5
to
62ab355
Compare
albrow
commented
Jan 9, 2020
integration-tests/browser/yarn.lock
Outdated
@@ -63,7 +63,7 @@ | |||
lodash.values "^4.3.0" | |||
|
|||
"@0x/mesh-browser@./../../browser/": | |||
version "8.0.0-beta-0xv3" | |||
version "3.0.1-beta" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an auto-generated file and yarn is grabbing the version number from the package.json for the @0x/mesh-browser
package locally. I know this looks weird but it's a side-effect of using a relative import in our package.json instead of importing from npm. I say we leave it be.
albrow
force-pushed
the
feature/custom-order-filters-rebase
branch
from
January 13, 2020 20:59
bf9de3a
to
fff1e91
Compare
This PR is ready for review. In the interest of not making this PR even bigger than it already is, the following will be added in separate PRs:
|
albrow
changed the title
WIP: Implement custom order filtering
Implement custom order filtering
Jan 13, 2020
albrow
force-pushed
the
feature/custom-order-filters-rebase
branch
from
January 14, 2020 22:29
41169c4
to
9555451
Compare
fabioberger
suggested changes
Jan 14, 2020
fabioberger
approved these changes
Jan 15, 2020
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR simply rebases #563 on the new
development
branch. I'm keeping the old PR around just in case anything was forgotten/lost during the messy rebase.Fixes #336 and #337.
Overview
This PR implements custom order filtering and custom topics. A custom filter may be passed into Mesh as a JSON Schema via the new
CUSTOM_ORDER_FILTER
environment variable. Messages that contain orders that don't match this schema will be dropped. As a limitation, filtering is only possible by looking at the static fields of an order. So for example, it is not possible to filter orders by doing an on-chain check or sending an HTTP request to a third-party API. We don't expect that this limitation is going to be a problem in practice and it comes with the huge benefit of enabling cross-topic forwarding in the future (more on that later).This PR also changes the way that pubsub topics work in Mesh. Previously, there was only one topic and it was hard-coded based on the chain ID. Now, there is a one-to-one correspondence between custom filters and topics. You can convert from custom order schema to a topic and vice versa. This is a breaking change and the old topic names are not compatible with this PR. (However, with this change we can potentially implement cross-version forwarding for forward compatibility from now on).
New order and message schemas.
All orders must match the following JSON Schema:
/signedOrder
is the same JSON Schema as before and will match only valid 0x orders./customOrder
is the custom schema passed in through theCUSTOM_ORDER_FILTER
environment variable.Organizing the JSON Schema for orders like this means that
CUSTOM_ORDER_FILTER
can be relatively small. It doesn't need to contain all the required fields for a signed 0x order. It just needs to contain any additional requirements on top of the default ones.The new schema for order messages sent through pubsub looks like this:
Notably this adds the
topics
field which is a list of topics that the message was sent on. This is critical for cross-topic forwarding.Example custom order schemas
The following
CUSTOM_ORDER_FILTER
doesn't add any additional requirements. All valid signed 0x orders will be accepted. This is the default value if no custom filter is passed in.The following
CUSTOM_ORDER_FILTER
matches any valid signed 0x orders with a specific sender address:This can easily be tweaked to filter orders by asset type, maker/taker address, or fee recipient.
New topic strings
The new topic format looks like this:
`/0x-orders/version/${versionNumber}/chain/${chainID}/schema/${encodedSchema}`
versionNumber
is the version for the topic string. This PR changes the default version from 2 to 3.chainID
is the chain ID that Mesh is configured to use.encodedSchema
is the base64-encoded custom order schema. This trick allows us to extract the custom order schema from the topic string.Future improvements
Cross-topic forwarding
Part of the reason this PR is implemented in a particular way is to enable "cross-topic forwarding" in the future. What this means is that a Mesh node that is subscribed on the default topic (all 0x orders) can receive orders on any topic and forward them to nodes that are only subscribed to that topic without subscribing to or even knowing about the topic ahead of time. This PR does not implement cross-topic forwarding but it does add everything we need to do so in the future without breaking backwards-compatibility.
Here's a rough overview of how it will work:
allOf
, we know that any order which is valid for a custom topic would also be considered valid on the default topic.A similar approach can be used to forward messages between topic versions. In other words a message that was originally sent on topic version 3 could be modified and forwarded to topic version 4. This means we could potentially break backwards compatibility at the pubsub layer without completely fragmenting liquidity (although this approach would add additional latency).