-
Notifications
You must be signed in to change notification settings - Fork 114
Improve algorithm for sharing old orders #692
Changes from 51 commits
3dc71ba
12e94a5
835fec3
1b4218b
ba6591e
43fbeb6
cc1dc49
20b230b
b95db9d
4743c61
20d7fa7
7c57e00
2dd98d5
1004272
616de9d
52e22d3
5663d67
e5611ec
f799e3d
48c90f9
1569ba3
ab315c1
76cb7a2
7d29d5f
46d0e20
ef1a6a7
4ce1cf6
e9c23d3
d2fd249
ca01b9a
fa3c492
05165cd
e356d86
bce828b
1bdd00a
57fce7d
9f575b3
51f9477
748c7bd
c7c36a0
91b334b
06a6d2f
1c73f2d
fdfa934
b743b5d
067e94b
4c8b0b6
1b3f820
ab2ba8a
ae4b65b
bc38f92
5f77523
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import ( | |
|
|
||
| "github.com/0xProject/0x-mesh/common/types" | ||
| "github.com/0xProject/0x-mesh/constants" | ||
| "github.com/0xProject/0x-mesh/core/ordersync" | ||
| "github.com/0xProject/0x-mesh/db" | ||
| "github.com/0xProject/0x-mesh/encoding" | ||
| "github.com/0xProject/0x-mesh/ethereum" | ||
|
|
@@ -61,6 +62,10 @@ const ( | |
| // logStatsInterval is how often to log stats for this node. | ||
| logStatsInterval = 5 * time.Minute | ||
| version = "development" | ||
| // ordersyncMinPeers is the minimum amount of peers to receive orders from | ||
| // before considering the ordersync process finished. | ||
| ordersyncMinPeers = 5 | ||
| paginationSubprotocolPerPage = 500 | ||
| ) | ||
|
|
||
| // Note(albrow): The Config type is currently copied to browser/ts/index.ts. We | ||
|
|
@@ -193,8 +198,8 @@ type App struct { | |
| idToSnapshotInfo map[string]snapshotInfo | ||
| ethRPCRateLimiter ratelimit.RateLimiter | ||
| ethRPCClient ethrpcclient.Client | ||
| orderSelector *orderSelector | ||
| db *meshdb.MeshDB | ||
| ordersyncService *ordersync.Service | ||
|
|
||
| // started is closed to signal that the App has been started. Some methods | ||
| // will block until after the App is started. | ||
|
|
@@ -348,11 +353,6 @@ func New(config Config) (*App, error) { | |
|
|
||
| // Initialize remaining fields. | ||
| snapshotExpirationWatcher := expirationwatch.New() | ||
| orderSelector := &orderSelector{ | ||
| topic: orderFilter.Topic(), | ||
| nextOffset: 0, | ||
| db: meshDB, | ||
| } | ||
|
|
||
| app := &App{ | ||
| started: make(chan struct{}), | ||
|
|
@@ -366,7 +366,6 @@ func New(config Config) (*App, error) { | |
| orderFilter: orderFilter, | ||
| snapshotExpirationWatcher: snapshotExpirationWatcher, | ||
| idToSnapshotInfo: map[string]snapshotInfo{}, | ||
| orderSelector: orderSelector, | ||
| ethRPCRateLimiter: ethRPCRateLimiter, | ||
| ethRPCClient: ethClient, | ||
| db: meshDB, | ||
|
|
@@ -476,6 +475,9 @@ func (app *App) Start(ctx context.Context) error { | |
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| defer func() { | ||
| log.Debug("closing app.db") | ||
| }() | ||
| <-innerCtx.Done() | ||
| app.db.Close() | ||
| }() | ||
|
|
@@ -485,13 +487,19 @@ func (app *App) Start(ctx context.Context) error { | |
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| defer func() { | ||
| log.Debug("closing eth RPC rate limiter") | ||
| }() | ||
| ethRPCRateLimiterErrChan <- app.ethRPCRateLimiter.Start(innerCtx, rateLimiterCheckpointInterval) | ||
| }() | ||
|
|
||
| // Set up the snapshot expiration watcher pruning logic | ||
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| defer func() { | ||
| log.Debug("closing snapshot expiration watcher") | ||
| }() | ||
| ticker := time.NewTicker(expirationPollingInterval) | ||
| for { | ||
| select { | ||
|
|
@@ -513,6 +521,9 @@ func (app *App) Start(ctx context.Context) error { | |
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| defer func() { | ||
| log.Debug("closing order watcher") | ||
| }() | ||
| log.Info("starting order watcher") | ||
| orderWatcherErrChan <- app.orderWatcher.Watch(innerCtx) | ||
| }() | ||
|
|
@@ -528,6 +539,9 @@ func (app *App) Start(ctx context.Context) error { | |
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| defer func() { | ||
| log.Debug("closing block watcher") | ||
| }() | ||
| log.Info("starting block watcher") | ||
| blockWatcherErrChan <- app.blockWatcher.Watch(innerCtx) | ||
| }() | ||
|
|
@@ -580,11 +594,31 @@ func (app *App) Start(ctx context.Context) error { | |
| return err | ||
| } | ||
|
|
||
| // Register and start ordersync service. | ||
| ordersyncSubprotocols := []ordersync.Subprotocol{ | ||
| NewFilteredPaginationSubprotocol(app, paginationSubprotocolPerPage), | ||
| } | ||
| app.ordersyncService = ordersync.New(innerCtx, app.node, ordersyncSubprotocols) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the fact that we are calling I think that an even more impactful change than the heuristic I described would be for Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The downside to this approach is that for networks or topics that don't have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. I'm still somewhat concerned about a future in which there are a lot of browser nodes that are spinning up and down quickly and are being used as |
||
| orderSyncErrChan := make(chan error, 1) | ||
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| defer func() { | ||
| log.Debug("closing ordersync service") | ||
| }() | ||
| if err := app.ordersyncService.GetOrders(innerCtx, ordersyncMinPeers); err != nil { | ||
| orderSyncErrChan <- err | ||
| } | ||
| }() | ||
|
|
||
| // Start the p2p node. | ||
| p2pErrChan := make(chan error, 1) | ||
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| defer func() { | ||
| log.Debug("closing p2p node") | ||
| }() | ||
| addrs := app.node.Multiaddrs() | ||
| log.WithFields(map[string]interface{}{ | ||
| "addresses": addrs, | ||
|
|
@@ -594,6 +628,9 @@ func (app *App) Start(ctx context.Context) error { | |
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| defer func() { | ||
| log.Debug("closing new addrs checker") | ||
| }() | ||
| app.periodicallyCheckForNewAddrs(innerCtx, addrs) | ||
| }() | ||
|
|
||
|
|
@@ -604,6 +641,9 @@ func (app *App) Start(ctx context.Context) error { | |
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| defer func() { | ||
| log.Debug("closing periodic stats logger") | ||
| }() | ||
| app.periodicallyLogStats(innerCtx) | ||
| }() | ||
|
|
||
|
|
@@ -628,14 +668,20 @@ func (app *App) Start(ctx context.Context) error { | |
| return err | ||
| } | ||
| case err := <-blockWatcherErrChan: | ||
| log.WithError(err).Error("block watcher exited with error") | ||
| if err != nil { | ||
| log.WithError(err).Error("block watcher exited with error") | ||
| cancel() | ||
| return err | ||
| } | ||
| case err := <-ethRPCRateLimiterErrChan: | ||
| log.WithError(err).Error("ETH JSON-RPC ratelimiter exited with error") | ||
| if err != nil { | ||
| log.WithError(err).Error("ETH JSON-RPC ratelimiter exited with error") | ||
| cancel() | ||
| return err | ||
| } | ||
| case err := <-orderSyncErrChan: | ||
| if err != nil { | ||
| log.WithError(err).Error("ordersync service exited with error") | ||
| cancel() | ||
| return err | ||
| } | ||
|
|
@@ -644,6 +690,7 @@ func (app *App) Start(ctx context.Context) error { | |
| // Wait for all goroutines to exit. If we reached here it means we are done | ||
| // and there are no errors. | ||
| wg.Wait() | ||
| log.Debug("app successfully closed") | ||
| return nil | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Is this purely a stylistic change? Just wondering if this is one of those weird make syntax elements that actually matter a lot.
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.
Yeah this is a carryover from conventions we used at a previous job. I like to put two spaces between Make tasks. It's subjective and probably not worth enforcing. Do you think I should just undo this commit and not make any formatting-only changes to the Makefile?
Uh oh!
There was an error while loading. Please reload this page.
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.
Nope, I'm totally fine with this change and am actually a fan of the style. I just wanted to make sure that I understood it properly. I think that some formatting-only changes are bad because they mess up
git --blame, but a blank line isn't going to cause a bug.