GithubHelp home page GithubHelp logo

oslfmt / trin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ethereum/trin

0.0 0.0 0.0 520 KB

An Ethereum portal client: a json-rpc server with nearly instant sync, and low CPU & storage usage

Rust 99.78% Dockerfile 0.22%

trin's Introduction

trin

(a working name)

Trin is an Ethereum "portal": a json-rpc server with nearly instant sync, and low CPU & storage usage.

Trin does this by making these tradeoffs:

  • Trusts miners to include valid state transitions, to skip sync
  • Shards state across a (new) p2p network, to reduce local storage needs

This should sound similar to a light client. It is, but with a peer-to-peer philosophy rather than the LES client/server model, which has introduced challenges in an altruistic environment.

Repository Structure

The portal protocol is a collection of networks. Trin needs to connect to all of them.

The repository is structured as follows:

  • trin/: The main entry point to run a holistic Ethereum portal client
  • trin-history/: The chain history network
  • trin-state/: The state network

Ready for production?

LOL, not even a little bit. At the last readme update, this was simply a proxy to Infura for all inbound requests, and doesn't validate any answers against state roots.

Trin will proxy at least some requests to Infura for quite a while, but the plan is to incrementally reduce the reliance on Infura, as more trin functionality becomes available.

How to use

Install dependencies (on Ubuntu/Debian)

apt install libssl-dev librocksdb-dev libclang-dev 

Create an Infura account, getting a project ID. Check out the trin repository, then:

cd trin
TRIN_INFURA_PROJECT_ID="YoUr-Id-HeRe" cargo run -p trin

To run individual networks:

cargo run -p trin-state|trin-history

Optional: Custom data directory

TRIN_DATA_PATH="/your_path"

Note, default data paths are:
Linux/Unix - $HOME/.local/share/trin
MacOS - ~/Library/Application Support/Trin
Windows - C:\Users\Username\AppData\Roaming\Trin\data

Connect over IPC

In a python shell:

>>> from web3 import Web3
>>> w3 = Web3(Web3.IPCProvider("/tmp/trin-jsonrpc.ipc"))
>>> w3.clientVersion
'trin 0.0.1-alpha'
>>> w3.eth.blockNumber
11870768

Connect over HTTP

First launch trin using HTTP as the json-rpc transport protocol:

TRIN_INFURA_PROJECT_ID="YoUr-Id-HeRe" cargo run -- --web3-transport http

Then, in a python shell:

>>> from web3 import Web3
>>> w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545"))
>>> w3.clientVersion
'trin 0.0.1-alpha'
>>> w3.eth.blockNumber
11870768

The client version responds immediately, from the trin client. The block number is retrieved more slowly, by proxying to Infura.

To interact with trin at the lowest possible level, try netcat:

nc -U /tmp/trin-jsonrpc.ipc
{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}
{"jsonrpc":"2.0","id":83,"result":"0xb52258"}{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":84}
{"jsonrpc":"2.0","id":84,"result":"0xb52259"}{"jsonrpc":"2.0","id":85,"params":[],"method":"web3_clientVersion"}
{"jsonrpc":"2.0","id":"85","result":"trin 0.0.1-alpha"}
{"jsonrpc":"2.0","id":86,"params":[],"method":"discv5_nodeInfo"}
{"id":86,"jsonrpc":"2.0","result":"enr:-IS4QHK_CnCsQKT-mFTilJ5msHacIJtU91aYe8FhAd_K7G-ACO-FO2GPFOyM7kiphjXMwrNh8Y4mSbN3ufSdBQFzjikBgmlkgnY0gmlwhMCoAMKJc2VjcDI1NmsxoQNa58x56RRRcUeOegry5S4yQvLa6LKlDcbBPHL4H5Oy4oN1ZHCCIyg"}

CLI Options

trin 0.0.1
carver
Run an eth portal client

USAGE:
    trin [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --bootnodes <bootnodes>               One or more comma-delimited base64-encoded ENR's or multiaddr strings of
                                              peers to initially add to the local routing table [default: ]
        --discovery-port <discovery_port>     The UDP port to listen on. [default: 9000]
        --external-address <external_addr>    The public IP address and port under which this node is accessible
        --pool-size <pool_size>               max size of threadpool [default: 2]
        --unsafe-private-key <private_key>    Hex encoded 32 byte private key (considered unsafe to pass in pk as cli
                                              arg, as it's stored in terminal history - keyfile support coming soon)
        --web3-http-address <web3-http-address>    address to accept json-rpc http connections [default: 127.0.0.1:8545]
        --web3-ipc-path <web3_ipc_path>       path to json-rpc endpoint over IPC [default: /tmp/trin-jsonrpc.ipc]
        --web3-transport <web3_transport>     select transport protocol to serve json-rpc endpoint [default: ipc]
                                              [possible values: http, ipc]

Custom RPC Methods

  • discv5_nodeInfo Returns the ENR of the client
  • discv5_routingTableInfo Returns the list of discovery peers that have recently been available

See https://eth.wiki/json-rpc/API#json-rpc-methods for other standard methods that are implemented. Currently, most of them proxy to Infura.

Want to help?

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing, then check out issues that are labeled Good First Issue.

Gotchas

  • There is a limit on concurrent connections given by the threadpool. At last doc update, that number was 2, but will surely change. If you leave connections open, then new connections will block.
  • Error handling is pretty close to non-existent.

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.