1

I have my blockchain running locally . I was using node-json-rpc module to make rpc calls . I was able to make few calls like erisdb.getBlockchainInfo. I tried the erisdb.eventSubscribe call :

client.call(
  {
    "jsonrpc": "2.0", "method": "erisdb.eventSubscribe", "params": {
      "event_id": "NewBlock"
    }, "id": "0"
  },

and it successfully returned a sub_id to me :

{ result: { sub_id: '7878EB2ECC668AEE19D958B89C4ED6E145D9298E91366D67F93CD2A20E995829' },
      error: null,
      id: '0',
      jsonrpc: '2.0' }

I used that sub_id to invoke erisdb.eventPoll call :

client.call(
  {
    "jsonrpc": "2.0", "method": "erisdb.eventPoll", "params": {
      "sub_id":"7878EB2ECC668AEE19D958B89C4ED6E145D9298E91366D67F93CD2A20E995829"
    }, "id": "1"
  },

but it is giving the following error :

{ result: null,
  error:
   { code: -32603,
     message: 'Subscription not active. ID: 7878EB2ECC668AEE19D958B89C4ED6E145D9298E91366D67F93CD2A20E995829' },
  id: '1',
  jsonrpc: '2.0' }

My eris-db version is 0.12.1.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
GeekyGags
  • 59
  • 5

1 Answers1

0

We have two different APIs at the moment. The one you are using we call the 'v0' API. It is optimised for long-polling Javascript clients. My guess is that your subscription is getting reaped before a certain hard-coded timeout that happens to be 10 seconds. Have you tried making the eventPoll call in quick sucession after the eventSubscribe call?

This is the 'v0' reaping function: https://github.com/eris-ltd/eris-db/blob/master/event/event_cache.go#L72. It runs in a loop clearing out old subscriptions that have not been polled recently. If you have waited longer than 10 seconds before polling then your subscription has probably been reaped (deleted).

We have another API optimised for chain administration called the 'tendermint' API (because of its heritage from the Tendermint consensus engine). It is something of a parallel API and it is used by the eris-pm tool. It also has a subscribe method accessible by a websocket endpoint. This might be useful for you because its subscriptions are never reaped.

You could try it out like this:

Start your chain:

$ eris chains start testchain

Get a simple websocket client:

$ go get github.com/raphael/wsc

Connect to the websocket endpoint:

$ wsc ws://0.0.0.0:46657/websocket
2017/01/21 01:03:51 connecting to ws://0.0.0.0:46657/websocket...
2017/01/21 01:03:51 ready, exit with CTRL+C.

Subscribe to the NewBlock event by pasting { "jsonrpc": "2.0", "method": "subscribe", "params": ["NewBlock"] } into the terminal as a single line:

>> { "jsonrpc": "2.0", "method": "subscribe", "params": ["NewBlock"] }

Then you should receive a stream of new block events (about 1 per second) like:

<< {"jsonrpc":"2.0","id":"#event","result":[19 {"event":"NewBlock","data":[1,{"block":{"header":{"chain_id":"testchain","height":206320,"time":"2017-01-21T01:04:01.095Z","num_txs":0,"last_block_hash":"2DB0D0AE6D92DA6DA07F8E7D1605AAB6CB96D8D2","last_block_parts":{"total":1,"hash":"A4AD1708714CF0BE3E5125B65F495DDDFA1ED8D9"},"last_commit_hash":"4C301C0367B7CECDD4E00C955D2F155802B2377E","data_hash":"","validators_hash":"46E43215C6C332446114BF7320D2D007114C5EEB","app_hash":"9A72DE9AAD6BD820A64DB98462CD706594217E1
<< 1"},"data":{"txs":[]},"last_commit":{"precommits":[{"height":206319,"round":0,"type":2,"block_hash":"2DB0D0AE6D92DA6DA07F8E7D1605AAB6CB96D8D2","block_parts_header":{"total":1,"hash":"A4AD1708714CF0BE3E5125B65F495DDDFA1ED8D9"},"signature":"45A6C3D0B0BD380A239F014681A29FD6217B52653CC7FC189FF5B7DC840A61062CF12FC652687A30A5CBBF0270937F32542D6075BA94A12180568560B322EC07"}]}}}]}],"error":""}

You could use a programmatic websocket client of your choice to interact with the chain using this websocket API and your subscriptions will never get reaped.

There is a grand unification of these APIs planned soon that should make them easier to use and better documented.

If you need help debugging, join us on: https://monax.slack.com/

Silas Davis
  • 712
  • 1
  • 9
  • 15