GithubHelp home page GithubHelp logo

oasisdex / spock Goto Github PK

View Code? Open in Web Editor NEW
21.0 15.0 8.0 1.05 MB

Spock πŸ–– β€” Blockchain ETL

License: GNU Affero General Public License v3.0

Shell 0.14% JavaScript 1.10% TypeScript 98.77%

spock's Introduction

Spock

Centralized cache for blockchain data

Features

  • scrape any data available on blockchain (events, tx data, traces)
  • easily provide semantic layers on top
  • ensure data consistency

Packages πŸ“¦

Package Version Description
etl npm Core package - responsible for etl
graphql-api npm Exposes data as GraphQL API
test-utils npm Utils for integration tests
utils npm Common reusable extractors etc.
validation npm Scripts to validate spock data with Google Big Query

Installation

npm install @oasisdex/spock-etl

Usage

spock-etl yourconfig.js|ts

Commands

@oasisdex/spock-etl

  • dist/bin/migrate config β€”Β launches database migrations (core and defined in the config)
  • dist/bin/etl config β€” launches ETL process (long running process)

@oasisdex/graphql-api

  • dist/index.js config β€” run general GraphQL api exposing database schema api

Response caching

We can automatically cache slow graphql queries. To enable it add: VL_GRAPHQL_CACHING_ENABLED=true env variable or in your config:

  api: {
    responseCaching: {
      enabled: true,
      duration: "15 seconds" // default
    };
  };

Query whitelisting

Probably you don't want users to issue any query on GraphQL API. That's why we support query whitelisting.

Enable it by:

{
  // ...
  api: {
    whitelisting: {
      enabled: true,
      whitelistedQueriesDir: "./queries",
      bypassSecret: "SECRET VALUE 123",
    },
  }
}

We rely on special operationName (part of request's body) parameter to match requested query with a query that is defined in whitelistedQueriesDir.

You can bypass whole mechanism (for example to test new queries) by providing bypassSecret as devMode in request's body.

Ethereum node considerations

spock pulls all the data from ethereum node. Nodes can differ greatly between each other, and some are simply not reliable / consistent. Based on our tests:

  • Alchemy works
  • Infura DOESN'T WORK. Sometimes it can randomly return empty sets for getLogs calls
  • Self hosted nodes should work (not tested yet) but keep in mind that spock can generate quite a lot of network calls (around 500k daily)

Development

  • yarn build β€”Β build everything
  • yarn build:watch - build and watch
  • yarn test:fix - run tests, auto fix all errors

Tip: Use yarn link to link packages locally.

PostgreSQL for development

Start

docker-compose up -d

Stop (data preserved)

docker-compose stop

Down (data lost)

docker-compose down

Logging

We use consola for logging. By default it will log everything. To adjust logging levels set VL_LOGGING_LEVEL. env variable. Ex. use VL_LOGGING_LEVEL=4 to omit detailed db logs (most verbose).

Sentry integration

Configure sentry by providing environmental variables:

SENTRY_DSN=...
SENTRY_ENV=production

We will only report critical errors (ie. stopped jobs).

How to write transformers?

There are two main requirements for transformers in Spock, both of them are related to processing reorged blocks:

  1. Transformers should be written as a "pure" functions operating only on the arguments provided. There can be no internal caches placed in the closures etc.
  2. All data written to the database has to be linked via foreign keys to the processed block.

When reorg happens spock will cascade delete reorged blocks with all related data. Then it will resync new block.

spock's People

Contributors

halaprix avatar krzkaczor avatar paszkowskidamian avatar sashatechops avatar tyler17 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.