vegaprotocol / vega

A Go implementation of the Vega Protocol, a protocol for creating and trading derivatives on a fully decentralised network.
https://vega.xyz
GNU Affero General Public License v3.0
37 stars 22 forks source link

Regression - Integer divide by 0 when placing Pegged order #2900

Closed ponthief closed 3 years ago

ponthief commented 3 years ago

Problem encountered

Core crashes on submitting Pegged orders

System response

2021-02-03T13:10:20.118Z    ERROR   tm.abci.socket-server   server/socket_server.go:142 Connection error [err recovered from panic: runtime error: integer divide by zero
goroutine 216 [running]:
github.com/tendermint/tendermint/abci/server.(*SocketServer).handleRequests.func1(0xc00123e6e0, 0xc02d9d91a0)
    /home/djordje/go/src/vega/vendor/github.com/tendermint/tendermint/abci/server/socket_server.go:165 +0xb5
panic(0x18b4aa0, 0x2c28260)
    /usr/local/go/src/runtime/panic.go:969 +0x166
code.vegaprotocol.io/vega/positions.(*Engine).RegisterOrder(0xc01dbd9200, 0xc01ecb45b0, 0xc01ef62360)
    /home/djordje/go/src/vega/positions/engine.go:161 +0x356
code.vegaprotocol.io/vega/execution.(*Market).submitValidatedOrder(0xc0010da420, 0x1f8f380, 0xc01ef62360, 0xc01ecb45b0, 0x0, 0x0, 0x0)
    /home/djordje/go/src/vega/execution/market.go:1110 +0x132
code.vegaprotocol.io/vega/execution.(*Market).submitOrder(0xc0010da420, 0x1f8f380, 0xc01ef62360, 0xc01ecb45b0, 0x71406c91dac8501, 0x0, 0x0, 0x0)
    /home/djordje/go/src/vega/execution/market.go:1067 +0x2f7
code.vegaprotocol.io/vega/execution.(*Market).SubmitOrder(0xc0010da420, 0x1f8f380, 0xc01ef62360, 0xc01ecb45b0, 0xc01e112940, 0x1, 0x0)
    /home/djordje/go/src/vega/execution/market.go:1026 +0x65
code.vegaprotocol.io/vega/execution.(*Engine).SubmitOrder(0xc000200cc0, 0x1f8f380, 0xc01ef62360, 0xc01ecb45b0, 0x0, 0xc01dac8838, 0x49d906)
    /home/djordje/go/src/vega/execution/engine.go:310 +0x1c6
code.vegaprotocol.io/vega/processor.(*App).DeliverSubmitOrder(0xc0000f5040, 0x1f8f380, 0xc01ef62360, 0x1f9d140, 0xc01ebe7f20, 0x0, 0xc00123e5d8)
    /home/djordje/go/src/vega/processor/abci.go:347 +0x250
code.vegaprotocol.io/vega/blockchain/abci.(*App).DeliverTx(0xc0003761c0, 0xc01ecc0180, 0x16d, 0x180, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /home/djordje/go/src/vega/blockchain/abci/abci.go:111 +0x249
github.com/tendermint/tendermint/abci/server.(*SocketServer).handleRequest(0xc00123e6e0, 0xc01ef63650, 0xc02d9d9200)
    /home/djordje/go/src/vega/vendor/github.com/tendermint/tendermint/abci/server/socket_server.go:207 +0x105b
github.com/tendermint/tendermint/abci/server.(*SocketServer).handleRequests(0xc00123e6e0, 0xc02d9d91a0, 0x1f60800, 0xc000011888, 0xc02d9d9200)
    /home/djordje/go/src/vega/vendor/github.com/tendermint/tendermint/abci/server/socket_server.go:189 +0x173
created by github.com/tendermint/tendermint/abci/server.(*SocketServer).acceptConnectionsRoutine
    /home/djordje/go/src/vega/vendor/github.com/tendermint/tendermint/abci/server/socket_server.go:127 +0x2b3

The market is in the following state just before the crash:

"orders": [
        {
          "id": "V0000000121-0000000001",
          "party": {
            "id": "376c3ae97bcecba084265d745cb86fa9ebe6b66db4e71c73bcab515aeee3570b"
          },
          "type": "LIMIT",
          "status": "Active",
          "side": "Buy",
          "price": "985",
          "size": "20",
          "reference": "dc17eb17-aca9-4e0e-abe7-6993b792469f",
          "createdAt": "2021-02-03T13:16:22.316667178Z",
          "expiresAt": null,
          "timeInForce": "GTC",
          "remaining": "20",
          "version": "1",
          "peggedOrder": null,
          "rejectionReason": null,
          "trades": null
        },
        {
          "id": "V0000000121-0000000002",
          "party": {
            "id": "bb29c7170dcc95c3ba70b5e998732d338cbd524d6bbf4cb3aaa0e3a2feb8d7cc"
          },
          "type": "LIMIT",
          "status": "Active",
          "side": "Sell",
          "price": "1015",
          "size": "20",
          "reference": "f364a5f2-28a2-4b61-ba8a-bc435e52e3ff",
          "createdAt": "2021-02-03T13:16:22.316667178Z",
          "expiresAt": null,
          "timeInForce": "GTC",
          "remaining": "20",
          "version": "1",
          "peggedOrder": null,
          "rejectionReason": null,
          "trades": null
        },
        {
          "id": "V0000000124-0000000003",
          "party": {
            "id": "bb29c7170dcc95c3ba70b5e998732d338cbd524d6bbf4cb3aaa0e3a2feb8d7cc"
          },
          "type": "LIMIT",
          "status": "Expired",
          "side": "Buy",
          "price": "985",
          "size": "100",
          "reference": "87f56cab-3038-4759-b14d-d2b4f143e81c",
          "createdAt": "2021-02-03T13:16:26.237542756Z",
          "expiresAt": "2021-02-03T13:16:30.028077652Z",
          "timeInForce": "GTT",
          "remaining": "100",
          "version": "2",
          "peggedOrder": {
            "reference": "Mid",
            "offset": "-15"
          },
          "rejectionReason": null,
          "trades": null
        },
        {
          "id": "V0000000132-0000000004",
          "party": {
            "id": "376c3ae97bcecba084265d745cb86fa9ebe6b66db4e71c73bcab515aeee3570b"
          },
          "type": "LIMIT",
          "status": "Expired",
          "side": "Sell",
          "price": "1025",
          "size": "100",
          "reference": "91df0341-1047-4fb6-90af-6b69d6a33e90",
          "createdAt": "2021-02-03T13:16:36.311597421Z",
          "expiresAt": "2021-02-03T13:16:40.456653912Z",
          "timeInForce": "GTT",
          "remaining": "100",
          "version": "2",
          "peggedOrder": {
            "reference": "BestAsk",
            "offset": "10"
          },
          "rejectionReason": null,
          "trades": null
        }
],
      "trades": null,
      "state": "PROPOSED",
      "data": {
        "markPrice": "1",
        "bestBidPrice": "985",
        "bestBidVolume": "20",
        "bestOfferPrice": "1015",
        "bestStaticBidPrice": "985",
        "bestStaticBidVolume": "20",
        "bestStaticOfferPrice": "1015",
        "bestStaticOfferVolume": "20",
        "midPrice": "1000",
        "suppliedStake": "0",
        "marketValueProxy": "0",
        "staticMidPrice": "1000",
        "marketTradingMode": "CONTINUOUS",
        "openInterest": "0",
        "liquidityProviderFeeShare": [],
        "priceMonitoringBounds": []
      }

2 Expired Pegged orders have been expired via Amend functionality

user places Pegged order:

Core crashes... System version: Specify the system version (0.30) Protocol: Specify the protocol

Component: Specify the components that might be related

Steps to reproduce

Automation

these 2 tests combined crash Core https://github.com/vegaprotocol/system-tests/blob/develop/CoreTesting/orders/orderExceptions_test.py#L1434

https://github.com/vegaprotocol/system-tests/blob/develop/CoreTesting/orders/orderExceptions_test.py#L1560

ponthief commented 3 years ago

retested on the hotfix/2900-division-by-0-regression branch and it's no longer crashing Core