Skip to content

Commit

Permalink
Increase max order size and create separate max message size (#631)
Browse files Browse the repository at this point in the history
* Increase max order size and create separate max message size

* Update CHANGELOG

* Small wording changes
  • Loading branch information
albrow committed Jan 10, 2020
1 parent 75b53ac commit 2027ebb
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 24 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ This changelog is a work in progress and may contain notes for versions which ha

## v8.1.0

### Features ✅

- Reduced startup time for Mesh node by only waiting for a block to be processed if Mesh isn't already sync'ed up to the latest block. ([#622](https://github.com/0xProject/0x-mesh/pull/622))
- Increased the maximum size for encoded orders from ~8kB to 16kB ([#631](https://github.com/0xProject/0x-mesh/pull/631)).

### Bug fixes 🐞

- Fixed a typo ("rendervouz" --> "rendezvous") in GetStatsResponse. ([#611](https://github.com/0x-mesh/pull/611)).
- Fix bug where we attempted to update the same order multiple times in a single DB txn, causing the later update to noop. ([#623](https://github.com/0xProject/0x-mesh/pull/623))

### Features ✅
- Fixed a bug where we attempted to update the same order multiple times in a single DB txn, causing the later update to noop. ([#623](https://github.com/0xProject/0x-mesh/pull/623))

- Reduce startup time for Mesh node by only waiting for a block to be processed if Mesh isn't already sync'ed up to the latest block. ([#622](https://github.com/0xProject/0x-mesh/pull/622))

## v8.0.0-beta-0xv3

Expand Down
25 changes: 20 additions & 5 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,29 @@ func init() {
UnlimitedExpirationTime, _ = big.NewInt(0).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639935", 10)
}

// MaxOrderSizeInBytes is the maximum number of bytes allowed for encoded orders. It
// is more than 10x the size of a typical ERC20 order to account for multiAsset orders.
const MaxOrderSizeInBytes = 8192
const (
// MaxOrderSizeInBytes is the maximum number of bytes allowed for encoded
// orders. It allows for MultiAssetProxy orders with roughly 45 total ERC20
// assets or roughly 36 total ERC721 assets (combined between both maker and
// taker; depends on the other fields of the order).
MaxOrderSizeInBytes = 16000
messageOverhead = len(`{"messageType":"order","Order":}`)
// MaxMessageSizeInBytes is the maximum size for messages sent through
// GossipSub. It is the max order size plus some overhead for the message
// format.
MaxMessageSizeInBytes = MaxOrderSizeInBytes + messageOverhead
)

// MaxBlocksStoredInNonArchiveNode is the max number of historical blocks for which a regular Ethereum
// node stores archive-level state. One cannot make `eth_call` requests specifying blocks earlier than
// 128 blocks ago on non-archive nodes.
const MaxBlocksStoredInNonArchiveNode = 128

// ErrMaxMessageSize is the error emitted when a message exceeds it's max size
var ErrMaxMessageSize = fmt.Errorf("message exceeds maximum size of %d bytes", MaxOrderSizeInBytes)
var (
// ErrMaxMessageSize is returned or emitted when a GossipSub message exceeds
// the max size.
ErrMaxMessageSize = fmt.Errorf("message exceeds maximum size of %d bytes", MaxMessageSizeInBytes)
// ErrMaxOrderSize is returned or emitted when a signed order encoded as JSON
// exceeds the max size.
ErrMaxOrderSize = fmt.Errorf("order exceeds maximum size of %d bytes", MaxOrderSizeInBytes)
)
8 changes: 4 additions & 4 deletions core/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ func (app *App) HandleMessages(ctx context.Context, messages []*p2p.Message) err
for _, msg := range messages {
if err := validateMessageSize(msg); err != nil {
log.WithFields(map[string]interface{}{
"error": err,
"from": msg.From,
"maxOrderSizeInBytes": constants.MaxOrderSizeInBytes,
"actualSizeInBytes": len(msg.Data),
"error": err,
"from": msg.From,
"maxMessageSizeInBytes": constants.MaxMessageSizeInBytes,
"actualSizeInBytes": len(msg.Data),
}).Trace("received message that exceeds maximum size")
app.handlePeerScoreEvent(msg.From, psInvalidMessage)
continue
Expand Down
2 changes: 1 addition & 1 deletion core/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (app *App) schemaValidateMeshMessage(o []byte) (*gojsonschema.Result, error
}

func validateMessageSize(message *p2p.Message) error {
if len(message.Data) > constants.MaxOrderSizeInBytes {
if len(message.Data) > constants.MaxMessageSizeInBytes {
return constants.ErrMaxMessageSize
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion p2p/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func New(ctx context.Context, config Config) (*Node, error) {
GlobalBurst: config.GlobalPubSubMessageBurst,
PerPeerLimit: config.PerPeerPubSubMessageLimit,
PerPeerBurst: config.PerPeerPubSubMessageBurst,
MaxMessageSize: constants.MaxOrderSizeInBytes,
MaxMessageSize: constants.MaxMessageSizeInBytes,
})
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion p2p/ratevalidator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (v *Validator) Validate(ctx context.Context, peerID peer.ID, msg *pubsub.Me
return true
}

if msg.Size() > v.config.MaxMessageSize {
if data := msg.GetData(); data != nil && len(data) > v.config.MaxMessageSize {
return false
}

Expand Down
23 changes: 17 additions & 6 deletions p2p/ratevalidator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,21 @@ func TestValidatorMaxMessageSize(t *testing.T) {
})
require.NoError(t, err)

valid := validator.Validate(ctx, peerIDs[1], &pubsub.Message{
Message: &pb.Message{
Data: make([]byte, maxSize+1),
},
})
assert.False(t, valid, "message should be valid")
{
isValid := validator.Validate(ctx, peerIDs[1], &pubsub.Message{
Message: &pb.Message{
Data: make([]byte, maxSize),
},
})
assert.True(t, isValid, "message should be valid")
}

{
isValid := validator.Validate(ctx, peerIDs[1], &pubsub.Message{
Message: &pb.Message{
Data: make([]byte, maxSize+1),
},
})
assert.False(t, isValid, "message should be invalid")
}
}
4 changes: 2 additions & 2 deletions zeroex/orderwatch/order_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ func (w *Watcher) meshSpecificOrderValidation(orders []*zeroex.SignedOrder, chai
}
}
if err := validateOrderSize(order); err != nil {
if err == constants.ErrMaxMessageSize {
if err == constants.ErrMaxOrderSize {
results.Rejected = append(results.Rejected, &ordervalidator.RejectedOrderInfo{
OrderHash: orderHash,
SignedOrder: order,
Expand Down Expand Up @@ -1454,7 +1454,7 @@ func validateOrderSize(order *zeroex.SignedOrder) error {
return err
}
if len(encoded) > constants.MaxOrderSizeInBytes {
return constants.ErrMaxMessageSize
return constants.ErrMaxOrderSize
}
return nil
}
Expand Down

0 comments on commit 2027ebb

Please sign in to comment.