Norman Meyer
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Indexer missing events report The teritori indexer has various chances to miss events since it's inception, here's the explaination of what it does, what happens and what are the ideas for fixing it ## The goal The teritori indexer is an event sourced system that sequentially reads all transactions of the teritori chain from genesis in order to populate a database with aggregated data that can't be properly queried from the chain and smart contracts directly ## The naive flow - 1) Choose a `chunk_size` (max number of blocks queried and processed in one database transaction) - 2) Read or initialize a field in the database that keeps track of the height of the next block to process (`height_cursor`) - 3) Declare `chunk_end = height_cursor + chunk_size` - 3) Query the `latest_height` from a teritori node, if this height is lower than `chunk_end` set `chunk_end = latest_height + 1` - 4) Start a database transaction - 5) Use the tendermint `tx_search` rpc to query a page of transactions contained in blocks in the range `[height_cursor, chunk_end[`. See https://docs.tendermint.com/v0.34/rpc/#/Info/tx_search and https://docs.tendermint.com/v0.34/app-dev/indexing-transactions.html - 6) Process transactions in the page - 7) Go back to 5) until there is no transaction left in the chunk - 8) Upate the height cursor - 8) Commit the database transaction - 10) Go back to 3) until killed We use tendermint `tx_search` because cosmos' `GetTxsEvent` (`tx_search` wrapper) is broken in our version of cosmos-sdk. See https://github.com/cosmos/cosmos-sdk/issues/11538 ## Problems ### Too much txs If we were to query all transactions in the chain the indexer would be too slow to replay the whole chain Fortunately, the `tx_search` rpc allows to filter on events so we can request only cosmwasm related transactions and thus greatly reduce the number of transaction to process ### Limited queries While the `tx_search` call allows some filterting of transaction, it's query language is very poor and does not allow to set multiple filter, so we can't ask for cosmwasm AND aidrop messages, thus we could not implemented the `Claim aidrop` quest ### Load balanced nodes desync With the naive implementation, if the teritori endpoint is load balanced, nodes behind the load balancer might not all be at the same height Due to this, there is a race condition between the height query and the tx_search queries when: - the indexer queries a first node that is ahead for the latest_height - then queries another node for the txs until that height but this node doesn't have these txs yet and will return an empty chunk - the height_cursor will be updated to the latest_height and txs will be lost We fixed this by using a websocket client that ensures we connect to the same node for all queries. A side benefit of using a websocket client is that we reuse the connection ### Tendermint tx indexer race condition There is a race condition if we query the height and txs between the moment that the node has processed a block and the moment that the tendermint tx indexer has finished to index transactions. See https://docs.tendermint.com/v0.34/app-dev/indexing-transactions.html for details about the tendermint tx indexer. We did not found a proper way to fix this for now, so we decided to wait one block until we query transactions to decrease the chances to fall in the race condition ## Ideas ### Use the psql tx indexer Tendermint provides another implementation of the tx indexer that populate a postgresql database so we can do advanced SQL queries instead of using `tx_search` This would be the optimal solution as it would grant us a lot more freedom on how we query transactions (and thus implement the `Claim airdrop` quest for example) We started a node that uses the psql indexer but it's very slow and is estimated to finish replaying the chain in more than a month ### Patch tendermint to be able to query the tx indexer height This would fix the tendermint tx indexer race condition but not the limited filter problem ### Keep a tx hash cursor We could - keep the height and hash of the last transaction processed by the teritori indexer - query transactions from this height - ignore transactions until the one after the last processed transaction hash This would fix the tendermint tx indexer race condition but not the limited filter problem

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully