Giter VIP home page Giter VIP logo

chainlink-polkadot's Introduction

Chainlink-polkadot

This repository contains the Chainlink feed pallet as well as an example node showing how to integrate it in Substrate-based chains.

It also includes the pallet-chainlink for interacting with the Chainlink job-based oracle system.

How to integrate the Chainlink feed pallet into a runtime?

The pallet is added to the runtime like any regular pallet (see tutorial). It then needs to be configured. See the pallet readme for details.

The usage is simple:

let feed = T::Oracle::feed(0.into()).ok_or(Error::<T>::FeedMissing)?;
let RoundData { answer, .. } = feed.latest_data();
do_something_with_answer(answer);

See the template pallet for a full example showing how to access a price feed.

Run the example

substrate-node-example demonstrates how to use pallet-chainlink-feed end-to-end. To test:

  • start the chain using make run-temp (for a temporary node which cleans up after itself)
  • connect to the chain by pointing https://polkadot.js.org/apps/ (or a locally hosted version) to the local dev node
  • specify the types by copying substrate-node-example/types.json into the input at Settings > Developer

You are now ready to send extrinsics to the pallet.

chainlink-polkadot's People

Contributors

apopiak avatar boxhock avatar clearloop avatar dependabot[bot] avatar ebarakos avatar j16r avatar jeluard avatar laurenttrk avatar mattsse avatar patrickalphac avatar se3000 avatar thodges-gh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chainlink-polkadot's Issues

Support free submissions every X blocks

To remove fees for submitters the submit extrinsic's weight function should return Pays::No if:

  • the submitted value is valid
  • if the last submitted value of the caller was X blocks ago. This should be configured with a new config type: FreeSubmissionFrequency: T::BlockNumber. The block number of the last submission should be cached in a new storage page (submitter, Feed) -> BlockNumber

Add support for canceling ownership transfers

There are no dispatchables that allow cancelation of a initiated ownership transfer.

Additional cancel_transfer_* functions that remove the Pending entry entirely and issue a cancelation event would fix this.

Missing JS Dependencies

The instructions in the readme only say to run make run-front-end to start the frontend. But first time users will fail here because they need to first install the js dependencies. Somewhere they need to run

cd substrate-node-example/front-end
yarn install

Enforce a maximum delay for Requesters

There is currently no check in set_requester on the given delay, so that an account can be added as requester but with such a high delay (measured in rounds: u32), that the account never has permission to request a new round.
This could be fixed either by a adding a new type to the pallet config and/or use the restart_delay of the feed

Harden create_feed input validation

The current checks within create_feed should be improved to validate that:

  • A feed can not be created without any oracles
  • submission value bounds should never be mutually exclusive

In a further step it should be evaluated whether the 'payment' or the 'timeout' should be restricted by the palette, or whether this should be continued to be left to the creator alone.

Also additional documentation should be added to explain all parameters

Add time limits for ownership transfers

Currently the transfer_* functions don't enforce a limit in which the pending owner must accept the transfer.

Expected behavior
A triggered transfer is only valid for x amount of blocks. The pending owner has x amount of blocks time to accept ownership otherwise the pending transfer is revoked.

An additional Timeout as config type makes sense here probably.

Cannot start chainlink nodes

When I run the substrate-chainlink/setup script, I get a docker compose error.

joshy@pop-os:~/ProgrammingProjects/chainlink-polkadot$ cd substrate-chainlink/
joshy@pop-os:~/ProgrammingProjects/chainlink-polkadot/substrate-chainlink$ ./setup
yarn install v1.22.4
warning package.json: No license field
info No lockfile found.
warning [email protected]: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 7.47s.
Endpoint: ws://host.docker.internal:9944/
Starting Chainlink Docker containers
ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
Waiting for http://localhost:6691/.
Timed out waiting for 'curl -s "http://localhost:6691/"' (waited 60s).
joshy@pop-os:~/ProgrammingProjects/chainlink-polkadot/substrate-chainlink$ 

Add pallet admin access control to reduce debt

The check for pallet admin origin within reduce_debt was removed in 62c4638 this made sense then since feed balances where tracked for the whole pallet and not on a per feed basis, so allowing any account to reduce debt made sense in this setting.
Now that endowment and debt is tracked on a per feed basis, the reduce_debt call should be limited again to the pallet admin to remove the exploit scenario where a malicious oracle calls reduce_debt and causes the pallet admin to pay out more funds than intended.

Use checked add when incrementing the round id

The RoundId is configured as u32, and u32::MAX is 4_294_967_295 which should be enough of rounds, considering that there is a round delay, and block times are 6s, A feed can run of rounds at the earliest after:
u::MAX * 6s * delay / 3600 hours. Even with 1 block delay this is still >800 years

Substrate node should include Cargo.lock

I'm trying to reproduce the demo from the video at https://www.youtube.com/watch?v=0rZghy0TIOQ. Following the instructions in the readme, I run make run-chain and get this compile error:

error[E0599]: no method named `sign` found for type `ed25519_dalek::keypair::Keypair` in the current scope
  --> /home/joshy/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-core-0.13.2/src/identity/ed25519.rs:56:16
   |
56 |         self.0.sign(msg).to_bytes().to_vec()
   |                ^^^^ method not found in `ed25519_dalek::keypair::Keypair`
   |
   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope; perhaps add a `use` for it:
           `use signature::signer::Signer;`

error[E0599]: no function or associated item named `from_bytes` found for type `ed25519::Signature` in the current scope
   --> /home/joshy/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-core-0.13.2/src/identity/ed25519.rs:111:29
    |
111 |         ed25519::Signature::from_bytes(sig).and_then(|s| self.0.verify(msg, &s)).is_ok()
    |                             ^^^^^^^^^^
    |                             |
    |                             function or associated item not found in `ed25519::Signature`
    |                             help: there is a method with a similar name: `to_bytes`
    |
    = help: items from traits can only be used if the trait is in scope
    = note: the following trait is implemented but not in scope; perhaps add a `use` for it:
            `use signature::signature::Signature;`

error[E0599]: no method named `verify` found for type `ed25519_dalek::public::PublicKey` in the current scope
   --> /home/joshy/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-core-0.13.2/src/identity/ed25519.rs:111:65
    |
111 |         ed25519::Signature::from_bytes(sig).and_then(|s| self.0.verify(msg, &s)).is_ok()
    |                                                                 ^^^^^^ method not found in `ed25519_dalek::public::PublicKey`
    |
    = help: items from traits can only be used if the trait is in scope
    = note: the following trait is implemented but not in scope; perhaps add a `use` for it:
            `use signature::verifier::Verifier;`

An extrinsic failed when initiate request

When practicing this demo with this commit, and do it as this steps:

  • clone the code
  • make run-chain
  • make run-front-end (yarn the front directory before)
  • cd chanlink-substrate; ./setup

Then go to the substrate front end, copy/paste the jobId and to(node address) to the initiate request parameter and click the initiate request button
it tells Completed at block hash #0xce66d394fedbf2aabd27ffc92873a3f7aa3ed219319edb5f75377e87c0832af3 below the button and an error in the events column

system:ExtrinsicFailed:: (phase={"ApplyExtrinsic":1})-3
DispatchError: {"module":8,"error":0}, DispatchInfo: {"weight":10000,"class":0,"paysFee":true}
An extrinsic failed.

Creating new jobs with external initiator throws a 401

Running the individual steps of the setup scripts, I supposedly get a successful run, but no job is ever created (and jobids.txt contains null 3 times).

When I try to create the job from UI with the following parameters - (see attached file I get:

notify 'test-ei' (http://substrate-chainlink_external-initiator-node1_1:8080/jobs) received bad response '401 Unauthorized'

Where the job parameters are from add-jobspec.sh, filling in the account from setup script.

I'm not sure where I'd provide the auth credentials. Could you offer any help please? I guess that since this tutorial has been released, the API of both the chainlink node as well as external initiator have changed significantly.

Many thanks!!! I'm almost there ๐Ÿ‘ Once I get it all working, I'll make a PR which brings this repo up to date with latest substrate & chainlink versions.

No jobs after starting chainlink nodes

When I run the substrate-chainlink/setup script, the chainlink nodes start, but they do not have any jobs included.

Looking back at the script output, I see three instances of:

Adding Jobspec #2 to Chainlink node...
./internal-scripts/add-jobspec.sh: line 50: jq: command not found
(23) Failed writing body
Jobspec has been added to Chainlink node
Done adding jobspec #2

The script failed because I did not have the jq command installed locally. I got past this error by running sudo apt install jq.

Allow Root to set pallet admin

Currently the only way to set the admin is via genesis. This is a limitation for already launched chains.
Therefore another call will be required to allow Root to set or overwrite the pallet admin.

Can't get jobIDs

I am following the demo from here

  1. Run make run-chain (successful)
  2. Run make run-front-end (successful)
  3. Run cd substrate-chainlink && ./setup (says it's successful but job IDs are null, confirmed by entering the GUI)

However, after I run ./setup I am getting null for all the jobs in my jobids.txt

null
null
null

After running ./setup I am coming across this message as well, maybe it has something to do with it:

Unknown types found, no types for Callback
Imported operator with address 5EsiCstpHTxarfafS3tvG7WDwbrp9Bv6BbyRvpwt3fY8PCtN
Operator already registered
Unknown types found, no types for Callback
Imported operator with address 5CDogos4Dy2tSCvShBHkeFeMscwx9Wi2vFRijjTRRFau3vkJ
Operator already registered
Unknown types found, no types for Callback
Imported operator with address 5HjLHE3A9L6zxUEn6uy8mcx3tqyVxZvVXu7okovfWzemadzs
Operator already registered

Any thoughts?

OnAnswer Callback

Currently the feed pallet is pull-based, meaning that new data needs to be requested.
In order to integrate with e.g. the ORML oracle pallet it would be useful (and potentially necessary) to add a callback that allows reacting to new answers.

docker container keeps restarting

When running ./setup.sh, the containers are all started, but the ones for chainlink nodes keep restarting.
To check the logs I run docker-compose up, where I see two possible culprits:

chainlink-node1_1           | error starting app: websocket: bad handshake (HTTP status 403 Forbidden)
substrate-chainlink_chainlink-node1_1 exited with code 1

&

external-initiator-node3_1  | 2020-09-12T16:20:13Z [ERROR] ic_accesskey flag or EI_IC_ACCESSKEY env must be set client/client.go:108             stacktrace=github.com/smartcontractkit/chainlink/core/logger.Error

Any clues on how to proceed?

Thanks!

Chainlink Keeper Support

I have 2 questions regarding the integration of chainlink keepers with these pallets.

  1. Are chainlink keepers supported in combination with these pallets? I guess the pallets don't care whether the chainlink contracts are fed by chainlink keepers. Hence, it shouldn't be an issue to access oracle data that is fed by chainlink keepers, correct?
  2. However, what if we want to trigger some extrinsic on a custom substrate pallet whenever the performUpkeep method in the KeeperCompatibleInterface contract is executed? This is currently not possible, correct? Are there any plans to integrate this in the future or are there already any existing workarounds?

Got `Errored` in Recent Job Runs

I integrate pallet-chainlink and example modules into my own runtime, then run all necessary steps.
But when I click Initiate Request button, I got the following json messages inChainlink Operator page:

{
  "id": "e3bdf73af31844b5a2d63b9f46a3ee68",
  "jobId": "a71760d093ce4daf8fbac6babb2dafc4",
  "result": {
    "data": {
      "result": "2.3188e+10"
    },
    "error": "ExternalBridge post to external adapter: POST response: 500 {"jobRunID":"e3bdf73af31844b5a2d63b9f46a3ee68","status_code":500,"status":"errored","data":null,"error":""} "
  },
  "status": "errored",
  "taskRuns": [
    {
      "id": "b608ee6b814b448891fc3c407e13129c",
      "result": {
        "data": {
          "result": "{"RAW":{"ETH":{"USD":{"TYPE":"5","MARKET":"CCCAGG","FROMSYMBOL":"ETH","TOSYMBOL":"USD","FLAGS":"2052","PRICE":231.88,"LASTUPDATE":1583638106,"MEDIAN":231.78,"LASTVOLUME":0.0601555,"LASTVOLUMETO":13.919381145,"LASTTRADEID":"56102311","VOLUMEDAY":97946.58387871957,"VOLUMEDAYTO":22828845.026123006,"VOLUME24HOUR":431047.7686566701,"VOLUME24HOURTO":103942413.16648632,"OPENDAY":237.78,"HIGHDAY":237.81,"LOWDAY":229.58,"OPEN24HOUR":244.61,"HIGH24HOUR":252.8,"LOW24HOUR":229.37,"LASTMARKET":"BTCAlpha","VOLUMEHOUR":11410.756630029984,"VOLUMEHOURTO":2633799.5719559174,"OPENHOUR":230.46,"HIGHHOUR":232.1,"LOWHOUR":229.79,"TOPTIERVOLUME24HOUR":409203.7313784001,"TOPTIERVOLUME24HOURTO":98673049.1756815,"CHANGE24HOUR":-12.730000000000018,"CHANGEPCT24HOUR":-5.204202608233522,"CHANGEDAY":-5.900000000000006,"CHANGEPCTDAY":-2.481285221633445,"CHANGEHOUR":1.4199999999999875,"CHANGEPCTHOUR":0.6161589863750705,"CONVERSIONTYPE":"direct","CONVERSIONSYMBOL":"","SUPPLY":110004301.624,"MKTCAP":25507797460.57312,"TOTALVOLUME24H":12448797.188920468,"TOTALVOLUME24HTO":2890618148.7372556,"TOTALTOPTIERVOLUME24H":5760424.948928239,"TOTALTOPTIERVOLUME24HTO":1339514225.1011384,"IMAGEURL":"/media/20646/eth_logo.png"}}},"DISPLAY":{"ETH":{"USD":{"FROMSYMBOL":"ฮž","TOSYMBOL":"$","MARKET":"CryptoCompare Index","PRICE":"$ 231.88","LASTUPDATE":"Just now","LASTVOLUME":"ฮž 0.06016","LASTVOLUMETO":"$ 13.92","LASTTRADEID":"56102311","VOLUMEDAY":"ฮž 97,946.6","VOLUMEDAYTO":"$ 22,828,845.0","VOLUME24HOUR":"ฮž 431,047.8","VOLUME24HOURTO":"$ 103,942,413.2","OPENDAY":"$ 237.78","HIGHDAY":"$ 237.81","LOWDAY":"$ 229.58","OPEN24HOUR":"$ 244.61","HIGH24HOUR":"$ 252.80","LOW24HOUR":"$ 229.37","LASTMARKET":"BTCAlpha","VOLUMEHOUR":"ฮž 11,410.8","VOLUMEHOURTO":"$ 2,633,799.6","OPENHOUR":"$ 230.46","HIGHHOUR":"$ 232.10","LOWHOUR":"$ 229.79","TOPTIERVOLUME24HOUR":"ฮž 409,203.7","TOPTIERVOLUME24HOURTO":"$ 98,673,049.2","CHANGE24HOUR":"$ -12.73","CHANGEPCT24HOUR":"-5.20","CHANGEDAY":"$ -5.90","CHANGEPCTDAY":"-2.48","CHANGEHOUR":"$ 1.42","CHANGEPCTHOUR":"0.62","CONVERSIONTYPE":"direct","CONVERSIONSYMBOL":"","SUPPLY":"ฮž 110,004,301.6","MKTCAP":"$ 25.51 B","TOTALVOLUME24H":"ฮž 12.45 M","TOTALVOLUME24HTO":"$ 2.89 B","TOTALTOPTIERVOLUME24H":"ฮž 5.76 M","TOTALTOPTIERVOLUME24HTO":"$ 1.34 B","IMAGEURL":"/media/20646/eth_logo.png"}}}}"
        },
        "error": null
      },
      "status": "completed",
      "task": {
        "ID": 1,
        "CreatedAt": "2020-03-08T03:25:59.728984Z",
        "UpdatedAt": "2020-03-08T03:25:59.728984Z",
        "DeletedAt": null,
        "type": "httpget",
        "confirmations": null,
        "params": {
        }
      },
      "minimumConfirmations": null,
      "confirmations": null
    },
    {
      "id": "b72f017bf96246a4bb2e21c4ba7109ce",
      "result": {
        "data": {
          "result": 231.88
        },
        "error": null
      },
      "status": "completed",
      "task": {
        "ID": 2,
        "CreatedAt": "2020-03-08T03:25:59.731116Z",
        "UpdatedAt": "2020-03-08T03:25:59.731116Z",
        "DeletedAt": null,
        "type": "jsonparse",
        "confirmations": null,
        "params": {
        }
      },
      "minimumConfirmations": null,
      "confirmations": null
    },
    {
      "id": "15e004a5d9ef43188751919fdfd81fb6",
      "result": {
        "data": {
          "result": "2.3188e+10"
        },
        "error": null
      },
      "status": "completed",
      "task": {
        "ID": 3,
        "CreatedAt": "2020-03-08T03:25:59.733623Z",
        "UpdatedAt": "2020-03-08T03:25:59.733623Z",
        "DeletedAt": null,
        "type": "multiply",
        "confirmations": null,
        "params": {
        }
      },
      "minimumConfirmations": null,
      "confirmations": null
    },
    {
      "id": "9583850daebd46e58b3cf0f181b3187e",
      "result": {
        "data": {
        },
        "error": "ExternalBridge post to external adapter: POST response: 500 {"jobRunID":"e3bdf73af31844b5a2d63b9f46a3ee68","status_code":500,"status":"errored","data":null,"error":""} "
      },
      "status": "errored",
      "task": {
        "ID": 4,
        "CreatedAt": "2020-03-08T03:25:59.734905Z",
        "UpdatedAt": "2020-03-08T03:25:59.734905Z",
        "DeletedAt": null,
        "type": "substrate",
        "confirmations": null,
        "params": {
          "type": "uint128"
        }
      },
      "minimumConfirmations": null,
      "confirmations": null
    }
  ],
  "createdAt": "2020-03-08T03:28:39.231742Z",
  "finishedAt": "2020-03-08T03:28:41.919743Z",
  "updatedAt": "2020-03-08T03:28:41.925807Z",
  "creationHeight": null,
  "observedHeight": null,
  "initiator": {
    "type": "external",
    "params": {
      "name": "test-ei"
    }
  }
}

How can I fix this error?

Upgrade to Substrate v3

Parachains are using a recent Substrate version to be compatible with Polkadot.
The Chainlink feed pallet will need to be upgraded (from the current v2.0.1) if it is meant to be integrated with these chains.

Blocking issue on this front is the (SCALE) support of the go client libraries.

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.