Skip to content

Commit

Permalink
fixing caching issue and more (#315)
Browse files Browse the repository at this point in the history
* fixing caching issue and more

* clear chain hangup timeout

* timeout fixed

* Update lib/block-listeners/cosmos-node-subscription.js

Co-authored-by: Jordan Bibla <[email protected]>
  • Loading branch information
iambeone and jbibla authored Feb 13, 2020
1 parent 40f7c9c commit 259caa2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/block-listeners/cosmos-node-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class CosmosNodeSubscription {
async pollForNewBlock() {
this.pollingTimeout = setTimeout(async () => {
const block = await this.cosmosAPI.getBlockByHeight()

if (this.height !== block.height) {
// apparently the cosmos db takes a while to serve the content after a block has been updated
// if we don't do this, we run into errors as the data is not yet available
setTimeout(() => this.newBlockHandler(block), COSMOS_DB_DELAY)
this.height = block.height // this needs to be set somewhere

// we are safe, that the chain produced a block so it didn't hang up
if (this.chainHangup) clearTimeout(this.chainHangup)
Expand All @@ -47,6 +47,8 @@ class CosmosNodeSubscription {

// if there are no new blocks for some time, trigger an error
// TODO: show this error automatically in the UI
// clearing previous timeout, otherwise it will execute
if (this.chainHangup) clearTimeout(this.chainHangup)
this.chainHangup = setTimeout(() => {
console.error(`Chain ${this.network.id} seems to have halted.`)
Sentry.captureException(
Expand Down
4 changes: 3 additions & 1 deletion lib/source/cosmosV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class CosmosV0API extends RESTDataSource {
}

async getRetry(url, intent = 0) {
// cleareing memoizedResults
this.memoizedResults.clear()
try {
return await this.get(url)
return await this.get(url, null, { cacheOptions: { ttl: 1 } }) // normally setting cacheOptions should be enought, but...
} catch (error) {
// give up
if (intent >= 3) {
Expand Down

0 comments on commit 259caa2

Please sign in to comment.