Skip to content

Instantly share code, notes, and snippets.

@Schwartz10
Last active November 14, 2019 05:01
Show Gist options
  • Save Schwartz10/3b93ff897e2a492c9281de80a7dfa628 to your computer and use it in GitHub Desktop.
Save Schwartz10/3b93ff897e2a492c9281de80a7dfa628 to your computer and use it in GitHub Desktop.
Bug in filecoin-network-stats description

It's possible this isn't the only problem causing the stats dashboard to get stuck at height 4683, but we're nearly certain it's one of them. You can replicate the logging by pulling this commit.

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 (gkSAwtcvQA==) 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.

Here are some examples of other messages that get decoded properly:

~~~~~~~~~~~~~~~~~~~~~~~
DATA gkSAwtcvQhIt
~~~~~~~~~~~~~~~~~~~~~~~
DECODING CHUNKS [ <Buffer 80 c2 d7 2f>, <Buffer 12 2d> ]
DECODE { decode: [Function: decode] } <Buffer 80 c2 d7 2f>
DECODE { decode: [Function: decode] } <Buffer 12 2d>
OUT [ '100000000', '4653' ]
~~~~~~~~~~~~~~~~~~~~~~~
DATA gkWAlOvcA0ILQA==
~~~~~~~~~~~~~~~~~~~~~~~
DECODING CHUNKS [ <Buffer 80 94 eb dc 03>, <Buffer 0b 40> ]
DECODE { decode: [Function: decode] } <Buffer 80 94 eb dc 03>
DECODE { decode: [Function: decode] } <Buffer 0b 40>
OUT [ '1000000000', '2880' ]
~~~~~~~~~~~~~~~~~~~~~~~

And here's the message that gets improperly decoded:

DATA gkSAwtcvQA==
~~~~~~~~~~~~~~~~~~~~~~~
DECODING CHUNKS [ <Buffer 80 c2 d7 2f>, <Buffer > ]
DECODE { decode: [Function: decode] } <Buffer 80 c2 d7 2f>
DECODE { decode: [Function: decode] } <Buffer >
OUT [ '100000000', 'NaN' ]
~~~~~~~~~~~~~~~~~~~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment