Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit c163356

Browse files
authored
Merge pull request #886 from 0xProject/release/9.4.1
Release 9.4.1
2 parents ee19434 + f1fb6f1 commit c163356

21 files changed

+815
-704
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
This changelog is a work in progress and may contain notes for versions which have not actually been released. Check the [Releases](https://github.com/0xProject/0x-mesh/releases) page to see full release notes and more information about the latest released versions.
44

5+
## v9.4.1
6+
7+
### Bug fixes 🐞
8+
9+
- Fixed a problem in the filtered pagination subprotocols of ordersync that caused the nodes to use the wrong orderfilter [#882](https://github.com/0xProject/0x-mesh/pull/882)
10+
11+
512
## v9.4.0
613

714
### Features ✅

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Version](https://img.shields.io/badge/version-9.4.0-orange.svg)](https://github.com/0xProject/0x-mesh/releases)
1+
[![Version](https://img.shields.io/badge/version-9.4.1-orange.svg)](https://github.com/0xProject/0x-mesh/releases)
22
[![Docs](https://img.shields.io/badge/docs-website-yellow.svg)](https://0x-org.gitbook.io/mesh)
33
[![Chat with us on Discord](https://img.shields.io/badge/chat-Discord-blueViolet.svg)](https://discord.gg/HF7fHwk)
44
[![Circle CI](https://img.shields.io/circleci/project/0xProject/0x-mesh/master.svg)](https://circleci.com/gh/0xProject/0x-mesh/tree/master)

RELEASE_CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
- [Docker image](https://hub.docker.com/r/0xorg/mesh/tags)
2-
- [README](https://github.com/0xProject/0x-mesh/blob/v9.4.0/README.md)
2+
- [README](https://github.com/0xProject/0x-mesh/blob/v9.4.1/README.md)
33

44
## Summary
55

6-
### Features ✅
6+
### Bug fixes 🐞
77

8-
- Improved the performance of validating order filters in the browser [#809](https://github.com/0xProject/0x-mesh/pull/809).
8+
- Fixed a problem in the filtered pagination subprotocols of ordersync that caused the nodes to use the wrong orderfilter [#882](https://github.com/0xProject/0x-mesh/pull/882)
99

1010

1111

core/core.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const (
6060
estimatedNonPollingEthereumRPCRequestsPer24Hrs = 50000
6161
// logStatsInterval is how often to log stats for this node.
6262
logStatsInterval = 5 * time.Minute
63-
version = "9.4.0"
63+
version = "9.4.1"
6464
// ordersyncMinPeers is the minimum amount of peers to receive orders from
6565
// before considering the ordersync process finished.
6666
ordersyncMinPeers = 5

core/ordersync/ordersync.go

+50-9
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ type Subprotocol interface {
148148
// ParseResponseMetadata converts raw response metadata into a concrete type
149149
// that the subprotocol expects.
150150
ParseResponseMetadata(metadata json.RawMessage) (interface{}, error)
151+
// GenerateFirstRequestMetadata generates the metadata for the first request
152+
// that should be made with this subprotocol.
153+
GenerateFirstRequestMetadata() (json.RawMessage, error)
151154
}
152155

153156
// New creates and returns a new ordersync service, which is used for both
@@ -172,19 +175,19 @@ func New(ctx context.Context, node *p2p.Node, subprotocols []Subprotocol) *Servi
172175

173176
// GetMatchingSubprotocol returns the most preferred subprotocol to use
174177
// based on the given request.
175-
func (s *Service) GetMatchingSubprotocol(rawReq *rawRequest) (Subprotocol, error) {
176-
for _, protoID := range rawReq.Subprotocols {
178+
func (s *Service) GetMatchingSubprotocol(rawReq *rawRequest) (Subprotocol, int, error) {
179+
for i, protoID := range rawReq.Subprotocols {
177180
subprotocol, found := s.subprotocols[protoID]
178181
if found {
179-
return subprotocol, nil
182+
return subprotocol, i, nil
180183
}
181184
}
182185

183186
err := NoMatchingSubprotocolsError{
184187
Requested: rawReq.Subprotocols,
185188
Supported: s.SupportedSubprotocols(),
186189
}
187-
return nil, err
190+
return nil, 0, err
188191
}
189192

190193
// HandleStream is a stream handler that is used to handle incoming ordersync requests.
@@ -225,12 +228,19 @@ func (s *Service) HandleStream(stream network.Stream) {
225228
s.handlePeerScoreEvent(requesterID, psInvalidMessage)
226229
return
227230
}
228-
subprotocol, err := s.GetMatchingSubprotocol(rawReq)
231+
subprotocol, i, err := s.GetMatchingSubprotocol(rawReq)
229232
if err != nil {
230233
log.WithError(err).Warn("GetMatchingSubprotocol returned error")
231234
s.handlePeerScoreEvent(requesterID, psSubprotocolNegotiationFailed)
232235
return
233236
}
237+
if len(rawReq.Subprotocols) > 1 {
238+
firstRequests := FirstRequestsForSubprotocols{}
239+
err := json.Unmarshal(rawReq.Metadata, &firstRequests)
240+
if err == nil {
241+
rawReq.Metadata = firstRequests.MetadataForSubprotocol[i]
242+
}
243+
}
234244
res, err := handleRequestWithSubprotocol(s.ctx, subprotocol, requesterID, rawReq)
235245
if err != nil {
236246
log.WithError(err).Warn("subprotocol returned error")
@@ -406,6 +416,38 @@ func parseResponseWithSubprotocol(subprotocol Subprotocol, providerID peer.ID, r
406416
}, nil
407417
}
408418

419+
type FirstRequestsForSubprotocols struct {
420+
MetadataForSubprotocol []json.RawMessage `json:"metadata"`
421+
}
422+
423+
// createFirstRequestForAllSubprotocols creates an initial ordersync request that
424+
// contains metadata for all of the ordersync subprotocols.
425+
func (s *Service) createFirstRequestForAllSubprotocols() (*rawRequest, error) {
426+
metadata := []json.RawMessage{}
427+
for _, subprotocolString := range s.SupportedSubprotocols() {
428+
subprotocol, found := s.subprotocols[subprotocolString]
429+
if !found {
430+
return nil, fmt.Errorf("cannot generate first request metadata for subprotocol %s", subprotocolString)
431+
}
432+
m, err := subprotocol.GenerateFirstRequestMetadata()
433+
if err != nil {
434+
return nil, err
435+
}
436+
metadata = append(metadata, m)
437+
}
438+
encodedMetadata, err := json.Marshal(FirstRequestsForSubprotocols{
439+
MetadataForSubprotocol: metadata,
440+
})
441+
if err != nil {
442+
return nil, err
443+
}
444+
return &rawRequest{
445+
Type: TypeRequest,
446+
Subprotocols: s.SupportedSubprotocols(),
447+
Metadata: encodedMetadata,
448+
}, nil
449+
}
450+
409451
func (s *Service) getOrdersFromPeer(ctx context.Context, providerID peer.ID) error {
410452
stream, err := s.node.NewStream(ctx, providerID, ID)
411453
if err != nil {
@@ -428,10 +470,9 @@ func (s *Service) getOrdersFromPeer(ctx context.Context, providerID peer.ID) err
428470
var rawReq *rawRequest
429471
if nextReq == nil {
430472
// First request
431-
rawReq = &rawRequest{
432-
Type: TypeRequest,
433-
Subprotocols: s.SupportedSubprotocols(),
434-
Metadata: nil,
473+
rawReq, err = s.createFirstRequestForAllSubprotocols()
474+
if err != nil {
475+
return err
435476
}
436477
} else {
437478
encodedMetadata, err := json.Marshal(nextReq.Metadata)

core/ordersync_subprotocols.go

+24-8
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ func NewFilteredPaginationSubprotocol(app *App, perPage int) *FilteredPagination
3838
// FilteredPaginationSubProtocol. It keeps track of the current page and SnapshotID,
3939
// which is expected to be an empty string on the first request.
4040
type FilteredPaginationRequestMetadata struct {
41-
Page int `json:"page"`
42-
SnapshotID string `json:"snapshotID"`
41+
Page int `json:"page"`
42+
SnapshotID string `json:"snapshotID"`
43+
OrderFilter *orderfilter.Filter `json:"orderfilter"`
4344
}
4445

4546
// FilteredPaginationResponseMetadata is the response metadata for the
@@ -96,10 +97,16 @@ func (p *FilteredPaginationSubProtocol) HandleOrderSyncRequest(ctx context.Conte
9697
break
9798
}
9899
// Filter the orders for this page.
99-
for _, orderInfo := range ordersResp.OrdersInfos {
100-
if matches, err := p.orderFilter.MatchOrder(orderInfo.SignedOrder); err != nil {
101-
return nil, err
102-
} else if matches {
100+
if metadata.OrderFilter != nil {
101+
for _, orderInfo := range ordersResp.OrdersInfos {
102+
if matches, err := metadata.OrderFilter.MatchOrder(orderInfo.SignedOrder); err != nil {
103+
return nil, err
104+
} else if matches {
105+
filteredOrders = append(filteredOrders, orderInfo.SignedOrder)
106+
}
107+
}
108+
} else {
109+
for _, orderInfo := range ordersResp.OrdersInfos {
103110
filteredOrders = append(filteredOrders, orderInfo.SignedOrder)
104111
}
105112
}
@@ -166,8 +173,9 @@ func (p *FilteredPaginationSubProtocol) HandleOrderSyncResponse(ctx context.Cont
166173

167174
return &ordersync.Request{
168175
Metadata: &FilteredPaginationRequestMetadata{
169-
Page: metadata.Page + 1,
170-
SnapshotID: metadata.SnapshotID,
176+
OrderFilter: p.orderFilter,
177+
Page: metadata.Page + 1,
178+
SnapshotID: metadata.SnapshotID,
171179
},
172180
}, nil
173181
}
@@ -187,3 +195,11 @@ func (p *FilteredPaginationSubProtocol) ParseResponseMetadata(metadata json.RawM
187195
}
188196
return &parsed, nil
189197
}
198+
199+
func (p *FilteredPaginationSubProtocol) GenerateFirstRequestMetadata() (json.RawMessage, error) {
200+
return json.Marshal(FilteredPaginationRequestMetadata{
201+
OrderFilter: p.orderFilter,
202+
Page: 0,
203+
SnapshotID: "",
204+
})
205+
}

docs/browser-bindings/browser-lite/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @0x/mesh-browser-lite - v9.4.0
1+
# @0x/mesh-browser-lite - v9.4.1
22

33
## @0x/mesh-browser-lite
44

0 commit comments

Comments
 (0)