GithubHelp home page GithubHelp logo

joincolony / block-ingestor Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 2.93 MB

Microservice that ingests ERC20 transactions for Colony Network Contracts

License: GNU General Public License v3.0

JavaScript 0.19% Shell 0.07% TypeScript 99.71% Dockerfile 0.03%

block-ingestor's People

Contributors

armandograterol avatar bogdan-1337 avatar chmanie avatar iamsamgibbs avatar jakubcolony avatar julianahlk avatar rdig avatar willm30 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

joincolony

block-ingestor's Issues

Write extension data to the db on block-ingestor start

Upon start, block-ingestor should go over all the past events and write the following to the database:

  • Extension version information (by traversing through ExtensionAddedToNetwork events)
  • Extension installation information (by traversing through ExtensionInstalled/ExtensionUninstalled events)
  • Extension initialisation sstatus (by traversing through ExtensionInitialised events)

Implement retry strategy for failed get block calls

Currently a failed get block call will result in ingestor throwing an error and restarting which takes about 2 minutes. During that time no data will be processed and stored in the database, potentially resulting in a considerable delay in the UI. This issue is to implement a retry strategy so that it retries the get block call a number of times before throwing an error.

[Verified Members] Update the isVerified flag for contributors when verifying / unverifying members

Specification

Story

In the UI, we display verified checkmarks for users which are added as verified.
We need to realign this according to the verified members rework.

Description

This should be done by changing the isVerified flag on the ColonyContributor model.

Implementation

This issue is complete when...

  • The isVerified flag and checkmarks reflect the state of verified members after realign

New Colony network version and extensions are not being picked up

Description

New Colony network contract releases and extension releases are not being picked up by the block-ingestor.

This has been noticed in the past, but has most recently been noticed again as there was a new Colony Network deployment this morning to version 14.

The versions for each are as follows:

  • ColonyNetwork:
    • Version in db: 13
    • Latest version: 14
  • VotingReputation Extension:
    • Version in db: 9
    • Latest version: 10
  • OneTxPayment Extension:
    • Version in db: 5
    • Latest version: 6

image

Note: The Colony network version has been manually updated in the database now to version 14.

[Verified members] Feature: Block ingestor can parse and handle the Add verified members event - Permissions

Specification

Story

The block ingestor must be able to parse the new event which corresponds to adding verified members via permissions.
Then it needs to call the graphql mutation for adding verified members.

Description

The client will send out a Metadata delta event where they will pass through the operation object and the block ingestor needs to parse it and handle it.

Implementation

Create a new handler in the event handlers folder and handle it in eventProcessor.
We need to parse the passed in string, so we know which users are being added to which colony.

This issue is complete when...

  • Block ingestor can successfully handle the event and discern it being an Add event not anything else
  • The gql mutation is called and the database table is updated

Write colony data to the db

Currently we don't write the colony data to the database, meaning we don't have access to all the colonies created before block-ingestor has started and we have to rely on frontend mutating the db directly (which we want to go away from).

This issue can be split in two parts:

  • The trackColonies function should be extended to not only set up the colony specific listeners but also write the colony to the database. This is to ensure we store info on all previously created colonies
  • Writing colony info to the db when handling ColonyAdded event

Handle Reorgs

What is a reorg?

https://river.com/learn/terms/r/reorganization
https://cointelegraph.com/explained/what-is-chain-reorganization-in-blockchain-technology
https://www.alchemy.com/overviews/what-is-a-reorg

How to handle

Here are my notes from a call I had with Jakub, Raul and Alex:

when listening to blocks, for each block that comes in, we need to confirm that it's parent hash is the previous block we processed, else it's a reorg.

If it's a reorg, we need to go back the last block we saw that is consistent with the reorg, and re-sync from that block

We need to keep a list of the last 500 blocks we have processed, each block containing:

  • block number
  • block hash

-- We also need to think about undoing state changes in the db for blocks that got reorged (and which may, thus, no longer exist on chain)

Recommendations

Speak to Alex to remind yourself of the details before starting work on this.

Add GraphQL codegen

Investigate and setup GraphQL codegen solution, preferably similar to the one in CDapp.

Investigate caching colony clients optimisation opportunity

I wonder if we could optimize the ingestor somewhat if we were to store all known instances of the colony client.

I see us re-instantiating the client for a lot of tracked events.

But I actually don't know what this impact would be real-life.

Originally posted by @rdig in #22 (comment)

This issue is to investigate and work on or close the ticket.

Gracefully handle loss of API connection

Currently, if the ingestor looses connection to the GraphQL api, more specifically the stats entry, it will reset from the first chain block, and more problematic, overwrite the stats entry.

This will render the block ingestor effectively useless until it catches up to the current block, which, starting from block 1 will take a while (order of weeks, multiple)

A common scenario where this can happen is during the short lived window when an API expire, and before the renew lambda process gets triggered.

The proposed solution for this is to prevent the above behavior by having the ingestor stop it's block fallback on API connection loss and just keep retrying until the connection is restored. That way, we avoid overwriting valid production data will fallbacks

[Verified members] Feature: Block ingestor can parse and handle the Remove verified members event - Permissions

Specification

Story

The block ingestor must be able to parse the new event which corresponds to removing verified members via permissions.
Then it needs to call the graphql mutation for removing verified members.

Description

The client will send out a Metadata delta event where they will pass through the pseudocode language a la REMOVE {userAddress} VERIFIED {colonyAddress} and the block ingestor needs to parse it and handle it.

Implementation

Create a new handler in the event handlers folder and handle it in eventProcessor.
We need to parse the passed in string, so we know which users are being removed from which colony's verified members.
After that, call the removeVerifiedMembers mutation.

This issue is complete when...

  • Block ingestor can successfully handle the event and discern it being a Remove event not anything else
  • The gql mutation is called and the database entry is modified

Add extensions client caching

Similarly to #38, we want to cache extension clients (Voting Reputation is the only one for now) in a bid to improve performance. This needs to be branched off Will's motion work.

Refactor colonyFundsClaimed query

Using the list version of ColonyFundsClaimed query could be improved here. This will list all ColonyFundsClaims in the db, and only apply filtering for colony and token once the query returns. If we have more than 100 items in the db (the default limit), we may not receive the results we're expecting.

We should be able to query the colony directly and get claims from there, since they're connected in the schema.

listCol

[Verified members] Feature: Block ingestor can parse and handle the Remove verified members motion

Specification

Story

The block ingestor must be able to parse the new event which corresponds to removing verified members via motions.
When it's finalized it needs to apply the result (or not apply it if it failed).

Description

The client will send out a Metadata delta motion event where they will pass through the pseudocode language a la REMOVE {userAddress} VERIFIED {colonyAddress} and the block ingestor needs to parse it and handle it.

Implementation

Create a new handler in the motions/motionCreated folder and handle it in motionCreated.ts file.
We need to parse the passed in string, so we know which user is being removed from which colony's verified members.

This issue is complete when...

  • Block ingestor can successfully handle the motion event and discern it being Remove event not anything else
  • Block ingestor successfully creates a motion
  • If the motion passes, we remove the verified members via the gql mutation
  • If the motion fails the members don't get removed

Handle Permissions Events

Handle the following events to extract required permissions:

  • ColonyRoleSet(indexed address,indexed uint256,indexed uint8,bool) -- old version of event
  • ColonyRoleSet(address,indexed address,indexed uint256,indexed uint8,bool) -- current version of event
  • RecoveryRoleSet(indexed address,bool) -- recovery role

Note to extract domain, and block at which point this permission was set.

A good idea is to look up the way we used to fetch permissions in colonyJS: https://github.com/JoinColony/colonyJS/blob/deprecated/4.x.x-branch-still-in-use/src/helpers.ts#L194-L255

Image

Refactor block-ingestor events queueing and processing

Several issues with potential solutions were raised during the ingestor call on Friday, May 2nd, including:

  • Changing the order of setting up listeners
  • Using 2 queues to ensure no events are missed during the tracking stage
  • Retrieving known colonies from the DB instead of the chain

Investigate and introduce automatic linting

The current setup relies on the developer having a linting extension enabled to highlight any issues during development. There are no pre-commit/pre-push hooks that would run linting automatically.

The issue is to investigate the existing CDapp linting setup and port the relevant parts to block-ingestor.

[Verified members] Feature: Block ingestor can parse and handle the Add verified members motion

Specification

Story

The block ingestor must be able to parse the new event which corresponds to adding verified members via motions.
When it's finalized it needs to apply the result (or not apply it if it failed).

Description

The client will send out a Metadata delta motion event where they will pass through the pseudocode language a la ADD {userAddress} VERIFIED {colonyAddress} and the block ingestor needs to parse it and handle it.

Implementation

Create a new handler in the motions/motionCreated folder and handle it in motionCreated.ts file.
We need to parse the passed in string, so we know which user is being added to which colony.

This issue is complete when...

  • Block ingestor can successfully handle the motion event and discern it being an Add event not anything else
  • Block ingestor successfully creates a motion
  • If the motion passes, we add the verified members via the gql mutation
  • If the motion fails the members don't get added

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.