This repository was archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
Improve algorithm for sharing old orders #692
Merged
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
3dc71ba
Remove old algorithm for order sharing via GossipSub
albrow 12e94a5
WIP initial implementation
albrow 835fec3
Improve test for p2p/ordersync
albrow 1b4218b
Implement ordersync.Provider in core package
albrow ba6591e
Make new core tests serial
albrow 43fbeb6
Wait for nodes to exit in core_test
albrow cc1dc49
Try running new core tests without the race detector
albrow 20b230b
Only run core serial tests in CI
albrow b95db9d
Add more log spam
albrow 4743c61
Log spam about number of orders requested/provided
albrow 20d7fa7
More logging
albrow 7c57e00
log when orders are invalid
albrow 2dd98d5
Add additional sleep statement
albrow 1004272
Change timing for test
albrow 616de9d
Remove some logs
albrow 52e22d3
Increase ETH RPC rate limiting limits for tests
albrow 5663d67
Re-enable all tests
albrow e5611ec
Remove more old logs
albrow f799e3d
Move ordersync to core package; create subprotocols
albrow 48c90f9
Use BlockchainLifecycle in new core tests
albrow 1569ba3
Update core.go with new ordersync logic
albrow ab315c1
Fix some bugs and get integration tests passing
albrow 76cb7a2
make core_test more robust
albrow 7d29d5f
Add timeout for ordersync requests and responses
albrow 46d0e20
Fix failing tests
albrow ef1a6a7
Wait for event to be sent before returning from ValidateAndStoreValid…
albrow 4ce1cf6
Increase test timeouts
albrow e9c23d3
Add manual delay in browser integraiton tests
albrow d2fd249
Add note about timing hack in browser integration tests
albrow ca01b9a
Remove old files
albrow fa3c492
Add a lot more comments
albrow 05165cd
Break out of for loop in GetOrders when minPeers reached
albrow e356d86
Add appropriate peer score events
albrow bce828b
Add rate limiting
albrow 1bdd00a
Remove old constants
albrow 57fce7d
Update core/ordersync/ordersync.go
albrow 9f575b3
Update core/ordersync_subprotocols.go
albrow 51f9477
Update core/ordersync_subprotocols.go
albrow 748c7bd
Add missing newline
albrow c7c36a0
Merge branch 'feature/better-old-order-sharing' of github.com:0xProje…
albrow 91b334b
Fix assertion in core_test.go
albrow 06a6d2f
Rename some methods of ordersync.Subprotocol
albrow 1c73f2d
Increase minPeers to 5
albrow fdfa934
Take filters into account in ordersync protocol
albrow b743b5d
Update some comments
albrow 067e94b
Add log message when receiving valid orders via ordersync
albrow 4c8b0b6
Update core/ordersync_subprotocols.go
albrow 1b3f820
Use same log message for receiving new order from peer
albrow ab2ba8a
Update core/ordersync_subprotocols.go
albrow ae4b65b
Return errors in waitForResponse and waitForRequest
albrow bc38f92
Merge branch 'feature/better-old-order-sharing' of github.com:0xProje…
albrow 5f77523
Add note to changelog
albrow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |||||
| "fmt" | ||||||
|
|
||||||
| "github.com/0xProject/0x-mesh/core/ordersync" | ||||||
| "github.com/0xProject/0x-mesh/orderfilter" | ||||||
| "github.com/0xProject/0x-mesh/zeroex" | ||||||
| ) | ||||||
|
|
||||||
|
|
@@ -17,16 +18,18 @@ var _ ordersync.Subprotocol = (*FilteredPaginationSubProtocol)(nil) | |||||
| // paginating through them. It involves sending multiple requests until pagination is | ||||||
| // finished and all orders have been returned. | ||||||
| type FilteredPaginationSubProtocol struct { | ||||||
| app *App | ||||||
| perPage int | ||||||
| app *App | ||||||
| orderFilter *orderfilter.Filter | ||||||
| perPage int | ||||||
| } | ||||||
|
|
||||||
| // NewFilteredPaginationSubprotocol creates and returns a new FilteredPaginationSubprotocol | ||||||
| // which will respond with perPage orders for each individual request/response. | ||||||
| func NewFilteredPaginationSubprotocol(app *App, perPage int) *FilteredPaginationSubProtocol { | ||||||
| return &FilteredPaginationSubProtocol{ | ||||||
| app: app, | ||||||
| perPage: perPage, | ||||||
| app: app, | ||||||
| orderFilter: app.orderFilter, | ||||||
| perPage: perPage, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -68,22 +71,40 @@ func (p *FilteredPaginationSubProtocol) HandleOrderSyncRequest(ctx context.Conte | |||||
| return nil, fmt.Errorf("FilteredPaginationSubProtocol received request with wrong metadata type (got %T)", req.Metadata) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| ordersResp, err := p.app.GetOrders(metadata.Page, p.perPage, metadata.SnapshotID) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| orders := make([]*zeroex.SignedOrder, len(ordersResp.OrdersInfos)) | ||||||
| for i, orderInfo := range ordersResp.OrdersInfos { | ||||||
| orders[i] = orderInfo.SignedOrder | ||||||
| // It's possible that none of the orders in the current page match the filter. | ||||||
| // We don't want to respond with zero orders, so keep iterating until we find | ||||||
| // at least some orders that match the filter. | ||||||
| filteredOrders := []*zeroex.SignedOrder{} | ||||||
| var snapshotID string | ||||||
| var currentPage int | ||||||
| for currentPage = metadata.Page; len(filteredOrders) == 0; currentPage += 1 { | ||||||
| // Get the orders for this page. | ||||||
| ordersResp, err := p.app.GetOrders(currentPage, p.perPage, metadata.SnapshotID) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| snapshotID = ordersResp.SnapshotID | ||||||
| if len(ordersResp.OrdersInfos) == 0 { | ||||||
| // No more orders left. | ||||||
| break | ||||||
| } | ||||||
| // Filter the orders for this page. If none of them match the filter, we continue | ||||||
| // on to the next page. | ||||||
| for _, orderInfo := range ordersResp.OrdersInfos { | ||||||
| if matches, err := p.orderFilter.MatchOrder(orderInfo.SignedOrder); err != nil { | ||||||
| return nil, err | ||||||
| } else if matches { | ||||||
| filteredOrders = append(filteredOrders, orderInfo.SignedOrder) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| // TODO(albrow): Filter orders | ||||||
|
|
||||||
| return &ordersync.Response{ | ||||||
| Orders: orders, | ||||||
| Complete: len(orders) == 0, | ||||||
| Orders: filteredOrders, | ||||||
| Complete: len(filteredOrders) == 0, | ||||||
| Metadata: &FilteredPaginationResponseMetadata{ | ||||||
| Page: metadata.Page, | ||||||
| SnapshotID: ordersResp.SnapshotID, | ||||||
| Page: currentPage, | ||||||
| SnapshotID: snapshotID, | ||||||
| }, | ||||||
| }, nil | ||||||
| } | ||||||
|
|
@@ -99,7 +120,16 @@ func (p *FilteredPaginationSubProtocol) HandleOrderSyncResponse(ctx context.Cont | |||||
| if !ok { | ||||||
| return nil, fmt.Errorf("FilteredPaginationSubProtocol received response with wrong metadata type (got %T)", res.Metadata) | ||||||
| } | ||||||
| // TODO(albrow): Check that this order matches our current filter/topic | ||||||
| filteredOrders := []*zeroex.SignedOrder{} | ||||||
| for _, order := range res.Orders { | ||||||
| if matches, err := p.orderFilter.MatchOrder(order); err != nil { | ||||||
| return nil, err | ||||||
| } else if matches { | ||||||
| filteredOrders = append(filteredOrders, order) | ||||||
| } else if !matches { | ||||||
| p.app.handlePeerScoreEvent(res.ProviderID, psReceivedOrderDoesNotMatchFilter) | ||||||
| } | ||||||
| } | ||||||
| _, err := p.app.orderWatcher.ValidateAndStoreValidOrders(ctx, res.Orders, false, p.app.chainID) | ||||||
|
||||||
| _, err := p.app.orderWatcher.ValidateAndStoreValidOrders(ctx, res.Orders, false, p.app.chainID) | |
| _, err := p.app.orderWatcher.ValidateAndStoreValidOrders(ctx, filteredOrders, false, p.app.chainID) |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.