Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libp2p mesh testing #719

Closed
15 of 36 tasks
kumavis opened this issue Oct 10, 2016 · 38 comments
Closed
15 of 36 tasks

libp2p mesh testing #719

kumavis opened this issue Oct 10, 2016 · 38 comments
Assignees
Labels

Comments

@kumavis
Copy link
Member

kumavis commented Oct 10, 2016

In the name of facilitating libp2p-based Ethereum light client development, we're discussing running some libp2p mesh testing in the metamask extension.

Some Design Goals:

  • light: minimal overhead, gentle testing
  • safe: runs on a different domain than the extension (via iframe)
  • big: thousands of nodes

Progress Tracker:

  • Ethereum IPLD
    • RLP
      • eth-block-list
        • basic
        • resolve leaves (blocks)
      • dump ommers
    • Simple Objects
      • eth-tx
      • eth-tx-receipt
    • Eth Trie
      • eth-trie rewrite
      • eth-state-trie rewrite
      • eth-storage-trie
      • eth-tx-trie
      • eth-tx-receipt-trie
      • dump transactions
      • dump transactionReceipts
  • Networking
    • ipfs over webrtc
    • determine the current blockchain HEAD (infura or p2p)
    • new tx, new block global pubsub
  • libp2p test mesh
    • add option to disable ipfs discovery
    • manually setup discovery
    • update eth-ipld resolvers PR
    • transfer eth-ipld resolvers to ipld org
  • Other
    • blockchain - separate blockDb + detailsDb
    • block - update fromRpc
    • web3 ipfs-provider (RPC methods via IPFS lookups)
    • explore merkelization of external indexes
      • CHT (canonical hash tree)
      • index:txToBlock
      • index:logToTx
    • eth-*-trie correctly resolve keys not in trie
    • experiment with identity hash fn Add the "Identity" hash function multiformats/multihash#13 (comment)
@kumavis
Copy link
Member Author

kumavis commented Oct 10, 2016

node.js (non-browser) intensive test suite: https://github.com/gavinmcdermott/js-libp2p-pstn

this is a great start but has been built with a few different design goals (non-browser, short and intensive, fully connected mesh)

metamask mesh tests would need to be:

  • browser based, running on webrtc
  • setup for a topology with many nodes (1-3k)
  • tests more lightweight, intermittent
  • focus on long-running tests and long-term health of the mesh

@kumavis
Copy link
Member Author

kumavis commented Oct 10, 2016

cross-team interface/deployment will most likely happen in this way:
the extension runs a hidden iframe pointed at a domain (untrusted by the extension) controlled by the ipfs/libp2p team with some mesh test code that they can update at their will

@kumavis
Copy link
Member Author

kumavis commented Oct 10, 2016

ping @diasdavid @gavinmcdermott

@kumavis kumavis added this to the Public Release milestone Oct 10, 2016
@kumavis kumavis self-assigned this Oct 10, 2016
@kumavis
Copy link
Member Author

kumavis commented Oct 10, 2016

marking as blocked until I have some concrete action items ( happy to work on some libp2p-side stuff if needed )

@danfinlay danfinlay modified the milestones: Light Client Support, Public Release Oct 11, 2016
@kumavis
Copy link
Member Author

kumavis commented Oct 20, 2016

This is blocked by this big crypto PR libp2p/js-libp2p-crypto#12

@kumavis kumavis removed the ready label Nov 7, 2016
@kumavis
Copy link
Member Author

kumavis commented Nov 7, 2016

@kumavis
Copy link
Member Author

kumavis commented Dec 15, 2016

heres a new sketch of the explicit ethereum obj types ( 8 types in total )

[0x90] eth-block 
  ommers: eth-block-list
  txs: eth-tx-trie
  receipts: eth-tx-receipt-trie
  state: eth-state-trie

[0x91] eth-tx (local data only)
[0x92] eth-tx-receipt (local data only)
[0x93] eth-account-snapshot (local data only)

[0x94] eth-block-list (rlp array)
  [leaves]: eth-block

[0x95] eth-tx-trie (merkle trie)
  [leaves]: eth-tx

[0x96] eth-tx-receipt-trie (merkle trie)
  [leaves]: links to eth-tx-receipt

[0x97] eth-state-trie (secure merkle trie)
  [leaves]: links to eth-account-snapshot

[0x98] eth-storage-trie (secure merkle trie)
  [leaves]: links to raw binary

@kumavis
Copy link
Member Author

kumavis commented Dec 16, 2016

here is an attempt at a concise-yet-hacky set ( 6 types )

[0x90] eth-block  (rlp)
  ommers: eth-rlp:eth-block
  txs: eth-trie:eth-tx
  receipts: eth-trie:eth-tx-receipt
  state: eth-trie:eth-account-snapshot

[0x91] eth-tx  (rlp) (local data only)
[0x92] eth-tx-receipt  (rlp) (local data only)
[0x93] eth-account-snapshot  (rlp)
  storage: eth-trie

[0x94] eth-trie[:type] (merkle trie)
  [leaves]: buffer or <type>

[0x95] eth-rlp[:type] (rlp)
  [leaves]: buffer or <type>

The hack works like this:
[ethBlock cid, 'state/<address>/balance']
would first resolve to
[<ethBlock.stateRoot cid>, '/<hash of address>:eth-account/balance']

since ethereum objects determine their leaf types from context, it doesnt fit neatly into a couple resolvers -- but if we cleverly use remainingPath we can specify the leaf type

@kumavis
Copy link
Member Author

kumavis commented Dec 16, 2016

here is an ultra-concise ( with only 2 types! ), by maximizing path fanciness

[0x90] eth-rlp[:type]
  [leaves]: buffer or <type>

[0x91] eth-trie[:type]
  [leaves]: buffer or <type>

how to lookup:

eth-block: `<cid for block as eth-rlp>/:block/`
  ommers(index): `<cid for ommersRoot as eth-rlp>/<index>/:block/`
  txs(index): `<cid for transactionsTrie as eth-trie>/<rlp.encode(index)>/:tx/`
  receipts(index): `<cid for receiptTrie as eth-trie>/<rlp.encode(index)>/:txr/`
  state(address): `<cid for stateRoot as eth-trie>/<hash(address)>/:account/`

eth-tx: `<cid for tx as eth-rlp>/:tx/`
  (local data only)

eth-tx-receipt: `<cid for txr as eth-rlp>/:txr/`
  (local data only)

eth-account-snapshot: `<cid for accountSnapshot as eth-rlp>/:account/`
  storage(key): `<cid for storageRoot as eth-trie>/<hash(key)>/`

@kumavis
Copy link
Member Author

kumavis commented Dec 16, 2016

theres one weird thing but i realize it would be true for the 6-type and 2-type version

resolving <cid for eth-block>/state/<address>
would not be the same as
resolving <cid for eth-block>/state/
then resolving <address>
bc <cid for eth-block>/state/<address> will hash the address after the first step, resolving to <cid for stateRoot as eth-trie>/<hash of address>

@kumavis
Copy link
Member Author

kumavis commented Dec 16, 2016

@wanderer what do you think of the 2-type solution?

@kumavis
Copy link
Member Author

kumavis commented Dec 16, 2016

zomg unified ethereum ipld proposal ( 1 type 😎 )

[0x90] eth-star[:type] ( basically rlp but we look for `trie@` prefix and `/:<type>` postfixes
  {leaves}: buffer
  {leaves}/:type: <type>

how to lookup:

eth-block: `<cid for block as eth-star>/:block/`
  ommers(index): `<cid for ommersRoot as eth-star>/<index>/:block/`
  txs(index): `<cid for transactionsTrie as eth-star>/trie@<rlp.encode(index)>/:tx/`
  receipts(index): `<cid for receiptTrie as eth-star>/trie@<rlp.encode(index)>/:txr/`
  state(address): `<cid for stateRoot as eth-star>/<hash(address)>/:account/`

eth-tx: `<cid for tx as eth-star>/:tx/`
  (local data only)

eth-tx-receipt: `<cid for txr as eth-star>/:txr/`
  (local data only)

eth-account-snapshot: `<cid for accountSnapshot as eth-star>/:account/`
  storage(key): `<cid for storageRoot as eth-star>/trie@<hash(key)>/`

note: special chars can be changed to maintain compliance with ipld-query spec. paths are ether pre-defined by the type or specified as hex, so avoiding collision is not a hard problem.

@kumavis
Copy link
Member Author

kumavis commented Dec 16, 2016

that said, we have room for 16384 codes before we hit the 3 byte range, which is currently reserved for apps
so maybe we dont need to be so concise
so maybe taking up 8 types and having the prettiest paths is reasonable 😸

@kumavis
Copy link
Member Author

kumavis commented Dec 16, 2016

tho im sure in the future ill be interested in adding this fancy type casting for some other reason, like converting eth contract storage values into cids or other formats

@kumavis
Copy link
Member Author

kumavis commented Dec 16, 2016

@wanderer btw jbenet and daviddias said dont hack the paths, better to have more formats

kumavis added a commit to kumavis/multicodec that referenced this issue Dec 23, 2016
Here are the Ethereum objects as I have mapped them so far. While there are only two underlying structures (RLP and Eth-(Secure-)Trie), they interpret the format of the leaf values based on context, which is lost when resolving at the IPLD level. I sketched out some versions that used fewer IPLD formats by employing some cleverness in the path naming conventions. (see here MetaMask/metamask-extension#719 (comment)). The consensus was to be explicit instead of clever, thusly the list of objects as I've proposed.

I'd additionally like to reserve 0x99-0x9f for additional Ethereum objects I may have missed or may be introduced when Ethereum milestone Metropolis is released.
@kumavis
Copy link
Member Author

kumavis commented Dec 23, 2016

Major TODOS:
( moved to top )

@kumavis
Copy link
Member Author

kumavis commented Jan 2, 2017

who likes todo lists? you do!
( moved to top )

@kumavis
Copy link
Member Author

kumavis commented Jan 2, 2017

TIL "identity hash fn" multiformats/multihash#13 (comment)

@kumavis
Copy link
Member Author

kumavis commented Jan 13, 2017

consider using rlpx over libp2p transport

@kumavis
Copy link
Member Author

kumavis commented Jan 13, 2017

proposal: blocks via ipfs-http-api on parity openethereum/parity-ethereum#4172
@wanderer @cdetrio this would be a nice way to skip syncing all together:

  • run parity client
  • wrap parity ipfs-http-api as block service
  • run public ipfs gateway on top of parity-backed block service

@kumavis
Copy link
Member Author

kumavis commented Feb 16, 2017

identifying RPC method data/index requirements

clientConfig
  eth_protocolVersion
  eth_syncing
  eth_coinbase
  eth_mining
  eth_hashrate
  eth_gasPrice
  eth_accounts
  eth_sign
  eth_sendTransaction
  eth_sendRawTransaction
  eth_newFilter
  eth_newBlockFilter
  eth_newPendingTransactionFilter
  eth_uninstallFilter
  eth_getFilterChanges
  eth_getFilterLogs

ipfs
  eth_getBlockByHash
  eth_getUncleByBlockHashAndIndex

ipfs:selectors (selectors/transforms)
  eth_getBlockTransactionCountByHash
  eth_getUncleCountByBlockHash

index:txToBlock
  eth_getTransactionReceipt
  eth_getTransactionByHash
  eth_getTransactionByBlockHashAndIndex

blockTracker (head tracking)
  eth_blockNumber

index:CHT
  eth_call
  eth_estimateGas
  eth_getBalance
  eth_getStorageAt
  eth_getTransactionCount
  eth_getCode
  eth_getBlockByNumber
  eth_getTransactionByBlockNumberAndIndex (+index:txToBlock)
  eth_getBlockTransactionCountByNumber (+ipfs:selectors)
  eth_getUncleCountByBlockNumber (+ipfs:selectors)
  eth_getUncleByBlockNumberAndIndex
  eth_getLogs (+index:logToTx)


HEX String - an integer block number
String "earliest" for the earliest/genesis block
String "latest" - for the latest mined block
String "pending" - for the pending state/transactions

transaction
├─ blockHash { txToBlock }
├─ blockNumber { txToBlock }
├─ creates { txToBlock, compute, ... }
├─ from { ecrecover }
├─ gas {}
├─ gasPrice {}
├─ hash {}
├─ input {}
├─ nonce {}
├─ publicKey { ecrecover }
├─ r {}
├─ raw {}
├─ s {}
├─ to {}
├─ transactionIndex { txToBlock, blockToTxs }
├─ v {}
└─ value {}

@kumavis
Copy link
Member Author

kumavis commented Feb 16, 2017

for those playing along at home, i made a thing: https://kumavis.github.io/metamask-mesh

@kumavis
Copy link
Member Author

kumavis commented Feb 28, 2017

@kumavis
Copy link
Member Author

kumavis commented Mar 22, 2017

migrated js-ipld-eth-* modules to ipld org

@kumavis
Copy link
Member Author

kumavis commented Mar 22, 2017

(a few weeks back) friends at Parity added an http server that serves parity data from CIDs. it got merged into master : )

@kumavis
Copy link
Member Author

kumavis commented May 6, 2017

tracking parity integration here ipfs/js-ipfs#763

@kumavis
Copy link
Member Author

kumavis commented May 9, 2017

ipfs routing improvements ipfs/js-ipfs#833

@kumavis
Copy link
Member Author

kumavis commented May 9, 2017

here is the current custom rolled parity->ipfs server https://github.com/kumavis/ipfs-eth-bridge
it works if you can connect to it

@kumavis
Copy link
Member Author

kumavis commented Jul 3, 2017

currently eth-ipfs bridge only serves blocks, transactions (no tries), state and storage tries, no tx receipts or no tx receipt tries. These are missing b/c parity does not index them by hash (tx receipt) or doesn't store them at all (tx trie, tx receipt tree).

the bridge is available over http as https://ipfs.lab.metamask.io

@kumavis
Copy link
Member Author

kumavis commented Jul 4, 2017

what if: generic ipfs merkle tree heat map could show us what is happening on ethereum

@kumavis
Copy link
Member Author

kumavis commented Jul 4, 2017

we will need to: create a special index for { tx tries, tx rxs, tx rx tries }

@ghost
Copy link

ghost commented Jul 4, 2017

what if: (in the long run): a box that users can just "download and run". Will be like this https://github.com/kumavis/ipfs-eth-bridge

With the idea "Contribute to the light clients mesh, making it stronger and resilient by downloading this application".

@kumavis
Copy link
Member Author

kumavis commented Jul 4, 2017

merkelize and serve the Canonical Hash Table over ipfs

@ghost
Copy link

ghost commented Jul 4, 2017

serverless block explorer

To make it more sexy, people gets it from IPNS.

Pros: We get more people pulling IPLD links, making them available faster.

@ghost
Copy link

ghost commented Jul 4, 2017

This thread is the sequel to this effort MetaMask/eth-ipfs-browser-client#1

@kumavis
Copy link
Member Author

kumavis commented Jul 4, 2017

closing this thread in favor of the new repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants