Skip to content

Instantly share code, notes, and snippets.

@bonedaddy
Forked from Schwartz10/filecoin-network-stats-bug.md
Last active November 14, 2019 04:23
Show Gist options
  • Save bonedaddy/720c327488bddfe0179ea4773520c6a7 to your computer and use it in GitHub Desktop.
Save bonedaddy/720c327488bddfe0179ea4773520c6a7 to your computer and use it in GitHub Desktop.
Bug in filecoin-network-stats description

Chainsaw fetches a block with tipset bafy2bzaceaxd64ic4e36kbkn3apxdbjkknrdar7kozc552pd55aurowy5kocs and block height 4684. One of the messages in this block represents an addAsk method. The param passed to this method chokes up when it gets decoded https://github.com/openworklabs/filecoin-network-stats/blob/master/backend/src/client/ABI.ts#L68.

Essentially the param passed in the message gets “chunked” into 2 buffers, the second of which appears to be an empty buffer, which goes on to get decoded by the BigIntDecoder https://github.com/openworklabs/filecoin-network-stats/blob/master/backend/src/client/ABI.ts#L22. The BigIntDecoder attempts to decode the empty buffer, but returns “NaN” instead. This causes the message to become malformed, it looks like this:

  { 
    height: 4684,
    tipsetHash:
     'bafy2bzaceaxd64ic4e36kbkn3apxdbjkknrdar7kozc552pd55aurowy5kocs',
    index: 2,
    gasPrice: 0.001,
    gasLimit: 1000,
    from: 't1of6xshaylxaldawngixtzicuc52qi7ddy4rvxyi',
    to: 't2tb4ascwjtmvgvykfw3riy6iec4ejy5o337yf34i',
    value: 0,
    method: 'addAsk',
    params: [ '100000000', 'NaN' ], 
    nonce: 1 
  }

Chainsaw passes this poorly formed message along, which eventually attempts to get stored and cached in Postgres. Once that happens, Postgres complains about the params field having ‘NaN’, which rolls back the entire database operation. At that point, nothing passed block height 4683 gets stored in Postgres, and chainsaw continues to choke attempting to store this poorly formed information.

You can see this malformed message yourself by curling http://api.temporal.cloud:3453/api/show/block/bafy2bzaceaxd64ic4e36kbkn3apxdbjkknrdar7kozc552pd55aurowy5kocs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment