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

Commit 9e86d4d

Browse files
authored
Merge pull request #464 from 0xProject/v5.1.0-beta
Version 5.1.0-beta
2 parents 90c3d03 + 0b7e791 commit 9e86d4d

34 files changed

+3350
-521
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
- image: circleci/golang:1.12.9-browsers
88
- image: 0xorg/ganache-cli:latest
99
environment:
10-
VERSION: 4.3.0
10+
VERSION: 4.3.3
1111
working_directory: /go/src/github.com/0xProject/0x-mesh
1212
steps:
1313
- checkout

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
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+
## v5.1.0-beta
6+
7+
### Features ✅
8+
9+
- The `getStats` RPC endpoint now includes a new field which accounts for the number of orders that have been marked as "removed" but not yet permanently deleted ([#461](https://github.com/0xProject/0x-mesh/pull/461)).
10+
- Improved historical order sharing using round-robin algorithm instead of random selection ([#454](https://github.com/0xProject/0x-mesh/pull/454)). This will reduce the warm-up time for receiving existing orders when first joining the network.
11+
- Added ERC1155 assetData support ([#453](https://github.com/0xProject/0x-mesh/pull/453)). This includes order watching and order events for orders involving ERC1155 tokens.
12+
- Added Ability to specify custom contract addresses via the `CUSTOM_ADDRESSES` environment variable or the `customAddresses` field in the TypeScript bindings ([#451](https://github.com/0xProject/0x-mesh/pull/451)).
13+
14+
### Bug fixes 🐞
15+
16+
- Temporarily disabled bandwidth-based peer banning ([#448](https://github.com/0xProject/0x-mesh/pull/448)). A [bug in libp2p](https://github.com/libp2p/go-libp2p-core/issues/65) was occasionally causing observed bandwidth usage to spike to unrealistic levels, which can result in peers being erroneously banned. We decided to temporarily stop banning peers while we're working with the libp2p team to resolve the issue.
17+
518
## v5.0.0-beta
619

720
### Breaking changes 🛠

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Version](https://img.shields.io/badge/version-5.0.0--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases)
1+
[![Version](https://img.shields.io/badge/version-5.1.0--beta-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)

browser/go/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func convertConfig(jsConfig js.Value) (core.Config, error) {
120120
if ethereumRPCMaxContentLength := jsConfig.Get("ethereumRPCMaxContentLength"); !isNullOrUndefined(ethereumRPCMaxContentLength) {
121121
config.EthereumRPCMaxContentLength = ethereumRPCMaxContentLength.Int()
122122
}
123+
if customContractAddresses := jsConfig.Get("customContractAddresses"); !isNullOrUndefined(customContractAddresses) {
124+
config.CustomContractAddresses = customContractAddresses.String()
125+
}
123126

124127
return config, nil
125128
}

browser/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@0x/mesh-browser",
3-
"version": "5.0.0-beta",
3+
"version": "5.1.0-beta",
44
"description": "TypeScript and JavaScript bindings for running Mesh directly in the browser.",
55
"main": "./lib/index.js",
66
"license": "Apache-2.0",

browser/ts/index.ts

+238-100
Large diffs are not rendered by default.

cmd/cut-release/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ func updateHardCodedVersions(version string) {
8989
regex = `version(.*)= "(.*)"`
9090
updateFileWithRegex(corePath, regex, newVersionString)
9191

92+
// Update `docs/deployment_with_telemetry.md`
93+
newVersionString = fmt.Sprintf(`image: 0xorg/mesh:%s`, version)
94+
regex = `image: 0xorg/mesh:latest`
95+
updateFileWithRegex("docs/deployment_with_telemetry.md", regex, newVersionString)
96+
9297
// Update `CHANGELOG.md`
9398
changelog := "CHANGELOG.md"
9499
newChangelogSection := fmt.Sprintf(`## v%s`, version)

constants/constants.go

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ var GanacheAccountToPrivateKey = map[common.Address][]byte{
5252
// GanacheDummyERC721TokenAddress is the dummy ERC721 token address in the Ganache snapshot
5353
var GanacheDummyERC721TokenAddress = common.HexToAddress("0x07f96aa816c1f244cbc6ef114bb2b023ba54a2eb")
5454

55+
// GanacheDummyERC1155MintableAddress is the dummy ERC1155 token address in the Ganache snapshot
56+
var GanacheDummyERC1155MintableAddress = common.HexToAddress("0xc4df27466183c0fe2a5924d6ea56e334deff146a")
57+
5558
// ErrInternal is used whenever we don't wish to expose internal errors to a client
5659
var ErrInternal = errors.New("internal error")
5760

core/core.go

+68-19
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const (
4848
expirationPollingInterval = 50 * time.Millisecond
4949
// logStatsInterval is how often to log stats for this node.
5050
logStatsInterval = 5 * time.Minute
51-
version = "5.0.0-beta"
51+
version = "5.1.0-beta"
5252
)
5353

5454
// Note(albrow): The Config type is currently copied to browser/ts/index.ts. We
@@ -97,6 +97,23 @@ type Config struct {
9797
// or Infura. If using Alchemy or Parity, feel free to double the default max in order to reduce the
9898
// number of RPC calls made by Mesh.
9999
EthereumRPCMaxContentLength int `envvar:"ETHEREUM_RPC_MAX_CONTENT_LENGTH" default:"524288"`
100+
// CustomContractAddresses is a JSON-encoded string representing a set of
101+
// custom addresses to use for the configured network ID. The contract
102+
// addresses for most common networks are already included by default, so this
103+
// is typically only needed for testing on custom networks. The given
104+
// addresses are added to the default list of addresses for known networks and
105+
// overriding any contract addresses for known networks is not allowed. The
106+
// addresses for exchange, devUtils, erc20Proxy, and erc721Proxy are required
107+
// for each network. For example:
108+
//
109+
// {
110+
// "exchange":"0x48bacb9266a570d521063ef5dd96e61686dbe788",
111+
// "devUtils": "0x38ef19fdf8e8415f18c307ed71967e19aac28ba1",
112+
// "erc20Proxy": "0x1dc4c1cefef38a777b15aa20260a54e584b16c48",
113+
// "erc721Proxy": "0x1d7022f5b17d2f8b695918fb48fa1089c9f85401"
114+
// }
115+
//
116+
CustomContractAddresses string `envvar:"CUSTOM_CONTRACT_ADDRESSES" default:""`
100117
}
101118

102119
type snapshotInfo struct {
@@ -120,6 +137,7 @@ type App struct {
120137
snapshotExpirationWatcher *expirationwatch.Watcher
121138
muIdToSnapshotInfo sync.Mutex
122139
idToSnapshotInfo map[string]snapshotInfo
140+
messageHandler *MessageHandler
123141
}
124142

125143
func New(config Config) (*App, error) {
@@ -129,6 +147,13 @@ func New(config Config) (*App, error) {
129147
log.SetLevel(log.Level(config.Verbosity))
130148
log.AddHook(loghooks.NewKeySuffixHook())
131149

150+
// Add custom contract addresses if needed.
151+
if config.CustomContractAddresses != "" {
152+
if err := parseAndAddCustomContractAddresses(config.EthereumNetworkID, config.CustomContractAddresses); err != nil {
153+
return nil, err
154+
}
155+
}
156+
132157
// Load private key and add peer ID hook.
133158
privKeyPath := filepath.Join(config.DataDir, "keys", "privkey")
134159
privKey, err := initPrivateKey(privKeyPath)
@@ -210,6 +235,9 @@ func New(config Config) (*App, error) {
210235
if err != nil {
211236
return nil, err
212237
}
238+
messageHandler := &MessageHandler{
239+
nextOffset: 0,
240+
}
213241

214242
app := &App{
215243
config: config,
@@ -225,6 +253,7 @@ func New(config Config) (*App, error) {
225253
meshMessageJSONSchema: meshMessageJSONSchema,
226254
snapshotExpirationWatcher: snapshotExpirationWatcher,
227255
idToSnapshotInfo: map[string]snapshotInfo{},
256+
messageHandler: messageHandler,
228257
}
229258

230259
log.WithFields(map[string]interface{}{
@@ -659,25 +688,33 @@ func (app *App) GetStats() (*rpc.GetStatsResponse, error) {
659688
if err != nil {
660689
return nil, err
661690
}
662-
latestBlock := rpc.LatestBlock{
663-
Number: int(latestBlockHeader.Number.Int64()),
664-
Hash: latestBlockHeader.Hash,
691+
var latestBlock rpc.LatestBlock
692+
if latestBlockHeader != nil {
693+
latestBlock = rpc.LatestBlock{
694+
Number: int(latestBlockHeader.Number.Int64()),
695+
Hash: latestBlockHeader.Hash,
696+
}
665697
}
666698
notRemovedFilter := app.db.Orders.IsRemovedIndex.ValueFilter([]byte{0})
667699
numOrders, err := app.db.Orders.NewQuery(notRemovedFilter).Count()
668700
if err != nil {
669701
return nil, err
670702
}
703+
numOrdersIncludingRemoved, err := app.db.Orders.Count()
704+
if err != nil {
705+
return nil, err
706+
}
671707

672708
response := &rpc.GetStatsResponse{
673-
Version: version,
674-
PubSubTopic: getPubSubTopic(app.config.EthereumNetworkID),
675-
Rendezvous: getRendezvous(app.config.EthereumNetworkID),
676-
PeerID: app.peerID.String(),
677-
EthereumNetworkID: app.config.EthereumNetworkID,
678-
LatestBlock: latestBlock,
679-
NumOrders: numOrders,
680-
NumPeers: app.node.GetNumPeers(),
709+
Version: version,
710+
PubSubTopic: getPubSubTopic(app.config.EthereumNetworkID),
711+
Rendezvous: getRendezvous(app.config.EthereumNetworkID),
712+
PeerID: app.peerID.String(),
713+
EthereumNetworkID: app.config.EthereumNetworkID,
714+
LatestBlock: latestBlock,
715+
NumOrders: numOrders,
716+
NumPeers: app.node.GetNumPeers(),
717+
NumOrdersIncludingRemoved: numOrdersIncludingRemoved,
681718
}
682719
return response, nil
683720
}
@@ -698,13 +735,14 @@ func (app *App) periodicallyLogStats(ctx context.Context) {
698735
continue
699736
}
700737
log.WithFields(log.Fields{
701-
"version": stats.Version,
702-
"pubSubTopic": stats.PubSubTopic,
703-
"rendezvous": stats.Rendezvous,
704-
"ethereumNetworkID": stats.EthereumNetworkID,
705-
"latestBlock": stats.LatestBlock,
706-
"numOrders": stats.NumOrders,
707-
"numPeers": stats.NumPeers,
738+
"version": stats.Version,
739+
"pubSubTopic": stats.PubSubTopic,
740+
"rendezvous": stats.Rendezvous,
741+
"ethereumNetworkID": stats.EthereumNetworkID,
742+
"latestBlock": stats.LatestBlock,
743+
"numOrders": stats.NumOrders,
744+
"numOrdersIncludingRemoved": stats.NumOrdersIncludingRemoved,
745+
"numPeers": stats.NumPeers,
708746
}).Info("current stats")
709747
}
710748
}
@@ -714,3 +752,14 @@ func (app *App) SubscribeToOrderEvents(sink chan<- []*zeroex.OrderEvent) event.S
714752
subscription := app.orderWatcher.Subscribe(sink)
715753
return subscription
716754
}
755+
756+
func parseAndAddCustomContractAddresses(networkID int, encodedContractAddresses string) error {
757+
customAddresses := ethereum.ContractAddresses{}
758+
if err := json.Unmarshal([]byte(encodedContractAddresses), &customAddresses); err != nil {
759+
return fmt.Errorf("config.CustomContractAddresses is invalid: %s", err.Error())
760+
}
761+
if err := ethereum.AddContractAddressesForNetworkID(networkID, customAddresses); err != nil {
762+
return fmt.Errorf("config.CustomContractAddresses is invalid: %s", err.Error())
763+
}
764+
return nil
765+
}

core/message_handler.go

+42-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package core
22

33
import (
4-
"math/rand"
5-
64
"github.com/0xProject/0x-mesh/meshdb"
75
"github.com/0xProject/0x-mesh/p2p"
86
"github.com/0xProject/0x-mesh/zeroex"
@@ -14,8 +12,19 @@ import (
1412
// Ensure that App implements p2p.MessageHandler.
1513
var _ p2p.MessageHandler = &App{}
1614

15+
type MessageHandler struct {
16+
nextOffset int
17+
}
18+
19+
func min(a int, b int) int {
20+
if a < b {
21+
return a
22+
}
23+
return b
24+
}
25+
1726
func (app *App) GetMessagesToShare(max int) ([][]byte, error) {
18-
// For now, we just select a random set of orders from those we have stored.
27+
// For now, we use a round robin strategy to select a set of orders to share.
1928
// We might return less than max even if there are max or greater orders
2029
// currently stored.
2130
// Use a snapshot to make sure state doesn't change between our two queries.
@@ -32,18 +41,37 @@ func (app *App) GetMessagesToShare(max int) ([][]byte, error) {
3241
if count == 0 {
3342
return nil, nil
3443
}
35-
// If count is less than max, we use an offset of 0 to simply return all
36-
// orders we have stored.
37-
offset := 0
38-
if count > max {
39-
// If count is greater than max, choose an offset such that we always return
40-
// at least max orders.
41-
offset = rand.Intn(count - max)
42-
}
44+
45+
// Select up to the maximum number of orders starting at the offset that was
46+
// calculated the last time this was called with `app`.
47+
offset := min(app.messageHandler.nextOffset, count)
4348
var selectedOrders []*meshdb.Order
44-
err = ordersSnapshot.NewQuery(notRemovedFilter).Offset(offset).Max(max).Run(&selectedOrders)
45-
if err != nil {
46-
return nil, err
49+
if offset != count {
50+
err = ordersSnapshot.NewQuery(notRemovedFilter).Offset(offset).Max(max).Run(&selectedOrders)
51+
if err != nil {
52+
return nil, err
53+
}
54+
}
55+
56+
// If more orders can be shared than were selected, append the maximum amount of
57+
// unique (in this round) orders that can be added to the selected orders without
58+
// exceeding the maximum number to share.
59+
overflow := min(max-len(selectedOrders), offset)
60+
if overflow > 0 {
61+
var overflowSelectedOrders []*meshdb.Order
62+
err = ordersSnapshot.NewQuery(notRemovedFilter).Offset(0).Max(overflow).Run(&overflowSelectedOrders)
63+
if err != nil {
64+
return nil, err
65+
}
66+
selectedOrders = append(selectedOrders, overflowSelectedOrders...)
67+
app.messageHandler.nextOffset = overflow
68+
} else {
69+
// Calculate the next offset and wrap back to 0 if the next offset is larger
70+
// than or equal to count.
71+
app.messageHandler.nextOffset += max
72+
if app.messageHandler.nextOffset >= count {
73+
app.messageHandler.nextOffset = 0
74+
}
4775
}
4876

4977
log.WithFields(map[string]interface{}{

0 commit comments

Comments
 (0)