-
Notifications
You must be signed in to change notification settings - Fork 111
Improve algorithm for sharing old orders #692
Conversation
01e7a82
to
8ccc8c4
Compare
b6564e8
to
0a3f365
Compare
@fabioberger @jalextowle I believe I addressed all your feedback and any remaining TODOs on my end. I want to leave some optimizations and improvements for future PRs. This one is ready for final review. I'll create new GitHub issues for any important tasks that are remaining. |
core/ordersync_subprotocols.go
Outdated
log.WithFields(map[string]interface{}{ | ||
"orderHash": acceptedOrderInfo.OrderHash.Hex(), | ||
"from": res.ProviderID.Pretty(), | ||
}).Info("received new valid order from peer via ordersync") |
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.
}).Info("received new valid order from peer via ordersync") | |
}).Info("received new valid order from peer") |
Let's not modify the log message since the data pipeline is querying for it exactly. If we want to distinguish between those discovered via ordersync
and gossipsub
, let's add a source
field to the log.
core/ordersync_subprotocols.go
Outdated
} else if !matches { | ||
p.app.handlePeerScoreEvent(res.ProviderID, psReceivedOrderDoesNotMatchFilter) | ||
} | ||
} | ||
_, err := p.app.orderWatcher.ValidateAndStoreValidOrders(ctx, res.Orders, false, p.app.chainID) |
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.
_, err := p.app.orderWatcher.ValidateAndStoreValidOrders(ctx, res.Orders, false, p.app.chainID) | |
_, err := p.app.orderWatcher.ValidateAndStoreValidOrders(ctx, filteredOrders, false, p.app.chainID) |
Co-Authored-By: Fabio B <me@fabioberger.com>
// SupportedSubprotocols returns the subprotocols that are supported by the service. | ||
func (s *Service) SupportedSubprotocols() []string { | ||
sids := []string{} | ||
for sid := range s.subprotocols { |
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 snippet suggests that this array can have a random order (unless I'm missing something): https://play.golang.org/p/s3WTo2LVuyl. With this in mind, we aren't actually enforcing a preference on these subprotocols. What do you think about keeping the original subprotocols array in the Service
object?
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.
Arrays and slices do not have randomized order. Maps have randomized order. When we implement more subprotocols we just need to add an additional field to Service
to keep track of the original order for the subprotocols that were passed in.
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.
Your last sentence was the point of my comment. Is there a reason not to fix this now though?
if err != nil { | ||
return err | ||
} | ||
s.handlePeerScoreEvent(providerID, psValidMessage) |
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.
I see that we parse the response below with the subprotocol, but I still question whether we should give a peer a psValidMessage
peer score when we cannot decode their response as a valid rawResponse
. This relates to the two other comments about not propagating the error.
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 addressed by the other changes. We only add the psValidMessage
score when receiving a valid message.
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.
Yep, I just wanted to mention this in case not returning the err was intentional.
Co-Authored-By: Fabio B <me@fabioberger.com>
…ct/0x-mesh into feature/better-old-order-sharing
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 looks good to me once my outstanding comment is addressed
Fixes #638.
This PR introduces a new protocol for sharing existing orders between two peers, called the "ordersync" protocol. At a high-level, ordersync is a pull-based protocol rather than a push-based one. Upon initialization, a Mesh node will simply request orders from its peers. This PR also removes our old push-based strategy for sharing existing orders. GossipSub is now only used for sharing new orders.
The ordersync protocol is designed with forward-compatibility in mind and supports multiple "subprotocols" which define the details for what each request and response should look like. This PR includes only one subprotocol, in which all orders are returned using pagination. We can expand on this in the future to implement more efficient protocols (e.g. using cuckoo filters, a gossip layer, or prioritizing sharing orders with the best price).
Remaining TODOs: