Order Matching
Last updated
Last updated
In a decentralized system like Yamata, orders can be processed both off-chain (via a sequencer) and on-chain (directly recorded on the blockchain). The role of the Validating Nodes (VNs) is to ensure that all transactions are processed fairly and consistently across these two parallel paths.
The process of matching and verifying transactions involves several potential scenarios, which we’ll break down below.
In all cases, an order will be processed by the off-chain sequencer (Submission A) and will also appear on-chain (Submission B). The VNs are responsible for ensuring that these two versions of the transaction match. However, because there is no globally coordinated time between off-chain and on-chain transactions, we cannot rely on on-chain ordering for verification. Instead:
Handles the orders based on when they arrive at the API. It maintains the order of transactions as they are received and processes them accordingly.
Ensures that the transactions are included on the blockchain, but it cannot guarantee the same ordering as the off-chain sequencer. On-chain ordering can be influenced by gas fees and miner decisions, making it less reliable for verifying the exact sequence.
How it Works:
The sequencer is the authoritative source for order sequencing. The VNs verify that the on-chain orders match the off-chain orders, but they do not compare the exact order between the two systems since the blockchain does not offer an objective time ordering.
If there is a mismatch in the content (not the order) of the transaction between the sequencer and on-chain, the VNs can raise a challenge to investigate further.
In this scenario, we are not dealing with on-chain orders, but rather a discrepancy in how the sequencer itself has processed two or more off-chain orders. For example, two orders may arrive off-chain in a particular sequence, but the sequencer may process them out of order.
Example:
Order A: Sell 1 BTC for 1 ETH.
Order B: Sell 1 ETH for 1 BTC.
Order C: Sell 1 ETH for 1 BTC.
Order A could match either Order B or Order C, and the correct match depends on which order, B or C, arrived first at the sequencer. If Order B arrived first at the API, it should be processed before Order C. However, if the sequencer mistakenly processes Order C first, this is a discrepancy that the VNs must address.
How it Works:
The VNs monitor the off-chain sequencing of transactions. If they detect that the sequencer processed orders out of their correct order (e.g., processed Order C before Order B when B arrived first), they can raise a challenge.
The challenge process ensures that the sequencer cannot manipulate the order of transactions and that everything is processed fairly based on the time of arrival at the API.
Another role of the on-chain mechanism is to ensure that no valid orders are excluded by the sequencer. While the sequencer is trusted to process orders efficiently off-chain, the on-chain mechanism acts as a safeguard to make sure that no orders are left out of the system entirely.
Even if the order of transactions on-chain doesn’t match the sequencer’s order, as long as all orders are included, the system remains fair.
How it Works:
The primary goal of the on-chain system is to make sure that no order is excluded. If the sequencer fails to post an order on-chain, the VNs will detect this and raise a challenge.
This process ensures that the sequencer cannot simply ignore or exclude orders, while it is in control of the off-chain order processing.
As long as the orders from the sequencer and on-chain match, the VNs continue to validate each epoch in a circular fashion, simply ensuring that everything is correct and moving on to the next batch.
However, when the VNs detect a discrepancy, whether in the order, content, or exclusion of transactions, they immediately move into the challenge process to investigate and resolve the issue.