question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite loop on events due to inacurracy between seconds and miliseconds ?

See original GitHub issue

My bot has been stuck reposting the same event over and over. From my investigation, I’m surprised the problem didn’t seem to emerge earlier and I don’t totally get it.

curl 'https://api.opensea.io/api/v1/events?collection_slug=cryptocubes&occurred_after=1645787316' -H 'Accept: application/json' -H "X-API-KEY: $API_KEY" | jq '.asset_events[-1]'

Result

{
  "approved_account": null,
  "asset": {
    "id": 17168260,
    "num_sales": 3,
    "background_color": null,
    "image_url": "https://lh3.googleusercontent.com/1juN1Mbi52rVbspQtDG9-Ichs8_WdCH2L6gwx3yFlpv-PKfETMZ8haemFX8veXul31wwLb_ScwxIN0RkDUPF8gMmKQ",
    "image_preview_url": "https://lh3.googleusercontent.com/1juN1Mbi52rVbspQtDG9-Ichs8_WdCH2L6gwx3yFlpv-PKfETMZ8haemFX8veXul31wwLb_ScwxIN0RkDUPF8gMmKQ=s250",
    "image_thumbnail_url": "https://lh3.googleusercontent.com/1juN1Mbi52rVbspQtDG9-Ichs8_WdCH2L6gwx3yFlpv-PKfETMZ8haemFX8veXul31wwLb_ScwxIN0RkDUPF8gMmKQ=s128",
    "image_original_url": "https://ipfs.io/ipfs/QmQQPBFQ221xKcMo31k4pKbEwQwHAZugV2qHjWhdGZ47c8/image.gif",
    "animation_url": null,
    "animation_original_url": null,
    "name": "CryptoCube#136",
    "description": "Join the punk movement.  \n\nExhibit your CryptoCube in 3d platforms.",
    "external_link": "https://app.rarible.com/token/0xdbb163b22e839a26d2a5011841cb4430019020f9:152",
    "asset_contract": {
      "address": "0xdbb163b22e839a26d2a5011841cb4430019020f9",
      "asset_contract_type": "non-fungible",
      "created_date": "2020-10-04T16:51:37.658205",
      "name": "CryptoCubes",
      "nft_version": "3.0",
      "opensea_version": null,
      "owner": 12077606,
      "schema_name": "ERC721",
      "symbol": "CC",
      "total_supply": "0",
      "description": "CryptoCubes are algorithmically generated metaverse-native 3d NFT collectibles.\r\n\r\nLimited to 256\r\n\r\nCreated by Han.",
      "external_link": "https://app.rarible.com/collection/0xdbb163b22e839a26d2a5011841cb4430019020f9",
      "image_url": "https://lh3.googleusercontent.com/X_V_EbYK5XpjO_j1AETDTUkolFCx-HJzcpM5TtMbI3bVN1ny4wVvXcX_BYzcAkzbTHjtW0mgGNmqOSRiejhr3tPt=s120",
      "default_to_fiat": false,
      "dev_buyer_fee_basis_points": 0,
      "dev_seller_fee_basis_points": 1000,
      "only_proxied_transfers": false,
      "opensea_buyer_fee_basis_points": 0,
      "opensea_seller_fee_basis_points": 250,
      "buyer_fee_basis_points": 0,
      "seller_fee_basis_points": 1250,
      "payout_address": "0xbf28421a82186bf50f496ab937c3368b55adbf19"
    },
    "permalink": "https://opensea.io/assets/0xdbb163b22e839a26d2a5011841cb4430019020f9/152",
    "collection": {
      "banner_image_url": "https://lh3.googleusercontent.com/eMwxxLlB7W8Psnr61OLliEFQlA8Bt5Y4tz1KXiEZaDD83t4IxIJcQMIZfm9ClVr5ATBOZxSLKcuGhtV_kdl4dVcs=s2500",
      "chat_url": null,
      "created_date": "2020-10-20T19:31:14.007197",
      "default_to_fiat": false,
      "description": "CryptoCubes are algorithmically generated metaverse-native 3d NFT collectibles.\r\n\r\nLimited to 256\r\n\r\nCreated by Han.",
      "dev_buyer_fee_basis_points": "0",
      "dev_seller_fee_basis_points": "1000",
      "discord_url": "https://discord.gg/cryptocubes",
      "display_data": {
        "card_display_style": "contain"
      },
      "external_url": "https://app.rarible.com/collection/0xdbb163b22e839a26d2a5011841cb4430019020f9",
      "featured": false,
      "featured_image_url": null,
      "hidden": false,
      "safelist_request_status": "verified",
      "image_url": "https://lh3.googleusercontent.com/X_V_EbYK5XpjO_j1AETDTUkolFCx-HJzcpM5TtMbI3bVN1ny4wVvXcX_BYzcAkzbTHjtW0mgGNmqOSRiejhr3tPt=s120",
      "is_subject_to_whitelist": false,
      "large_image_url": "https://lh3.googleusercontent.com/X_V_EbYK5XpjO_j1AETDTUkolFCx-HJzcpM5TtMbI3bVN1ny4wVvXcX_BYzcAkzbTHjtW0mgGNmqOSRiejhr3tPt",
      "medium_username": null,
      "name": "CryptoCubes",
      "only_proxied_transfers": false,
      "opensea_buyer_fee_basis_points": "0",
      "opensea_seller_fee_basis_points": "250",
      "payout_address": "0xbf28421a82186bf50f496ab937c3368b55adbf19",
      "require_email": false,
      "short_description": null,
      "slug": "cryptocubes",
      "telegram_url": null,
      "twitter_username": "CubesCrypto",
      "instagram_username": null,
      "wiki_url": null
    },
    "decimals": 0,
    "token_metadata": "https://ipfs.io/ipfs/QmaMDuYvnNU9HcLKXm419Lu3KafRPt56kccj7xmtHJiRtU",
    "owner": {
      "user": {
        "username": "Futureis"
      },
      "profile_img_url": "https://storage.googleapis.com/opensea-static/opensea-profile/23.png",
      "address": "0x1fdc7ec0a099dadf4643faea7cd0fcee23075932",
      "config": ""
    },
    "token_id": "152"
  },
  "asset_bundle": null,
  "auction_type": null,
  "bid_amount": "10000000000000000000",
  "collection_slug": "cryptocubes",
  "contract_address": "0x7f268357a8c2552623316e2562d90e642bb538e5",
  "created_date": "2022-02-25T11:08:36.706701",
  "custom_event_name": null,
  "dev_fee_payment_event": null,
  "dev_seller_fee_basis_points": 1000,
  "duration": null,
  "ending_price": null,
  "event_type": "offer_entered",
  "from_account": {
    "user": {
      "username": "M4T"
    },
    "profile_img_url": "https://storage.googleapis.com/opensea-static/opensea-profile/15.png",
    "address": "0x6bf97f2534be2242ddb3a29bfb24d498212dcded",
    "config": ""
  },
  "id": 3676682692,
  "is_private": null,
  "owner_account": null,
  "payment_token": {
    "id": 2,
    "symbol": "WETH",
    "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
    "image_url": "https://storage.opensea.io/files/accae6b6fb3888cbff27a013729c22dc.svg",
    "name": "Wrapped Ether",
    "decimals": 18,
    "eth_price": "1.000000000000000",
    "usd_price": "2630.679999999999836000"
  },
  "quantity": "1",
  "seller": null,
  "starting_price": null,
  "to_account": null,
  "total_price": null,
  "transaction": null,
  "winner_account": null,
  "listing_time": null
}

The returned event created_date is 2022-02-25T11:08:36.706701 Now if we make a moment out of it, we get

> const moment = require('moment');
> moment("2022-02-25T11:08:36.706701").unix()
1645787316

The resulting request will be https://api.opensea.io/api/v1/events?collection_slug=cryptocubes&occurred_after=1645787316 again, and that will fetch and post the same event again. Just incrementing the timestamp by 1 will prevent the problem to happen (but we might miss some events !)

Am I the only one experiencing the problem ? Was occured_after exclusive of timestamp and became inclusive ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
AstralsCodingcommented, Mar 13, 2022

@skiisinjeans Cheers, I’ll look into it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

The event loop - JavaScript - MDN Web Docs - Mozilla
JavaScript has a runtime model based on an event loop, which is responsible for executing the code, collecting and processing events, ...
Read more >
JS timing events within infinite loop / interval - Stack Overflow
Tried self building the infinite loop and logic with while(true) and ... "seconds" when setTimeout() takes delay parameter in milliseconds.
Read more >
Thrown for a loop: understanding for loops and timeouts in ...
function has about 998 milliseconds remaining before the code it contains goes into the event queue and then finally into the call stack....
Read more >
Understanding the Event Loop, Callbacks, Promises, and ...
Whether you set the timeout to zero seconds or five minutes will make no difference—the console.log called by asynchronous code will execute ...
Read more >
Routine Access to Millisecond Time Scale Events with ...
In this work, we critically assess the ability of the all-atom enhanced sampling method accelerated molecular dynamics (aMD) to investigate ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found