GithubHelp home page GithubHelp logo

bitcoin-net's People

Contributors

greenkeeperio-bot avatar head avatar mappum 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitcoin-net's Issues

Only connects to self

When I run the sample I'm getting flooded with

connected to peer 192.168.1.140

Does this even work anymore?

Several peers created for one webSeed

Issue: when only one webSeed url and only one p2p peer is set several peer objects are created sending over one websockets object resulting in repeated request rejects from the p2p peer.

The situation shows itself as several 'version' messages are sent by each peer over the same single websocket connection so the chain node accepts only first version and rejects subsequent and the client prints bitcoin-net:peergroup peer connection error: Peer handshake timed out messages in console.

In the browser debug I could see that WebSocketStream() function, creating the ws object, is called only once but PeerGroup _OnConnection(), creating peers, is called three times. It looks like we have 3 peers but only one ws object resulting in mixing up exchanges with the chain node

Test coverage

The tests are not yet very thorough, and live tests which connect to real nodes should be used sparingly (should be using mock connections).

BlockStream peer timeouts

It seems that very many peers are timing out when responding with blocks messages when we request many of them via BlockStream. I'm not sure if we're hitting some Bitcoin Core rate limiting, or if a bug is preventing us from seeing the response.

A convenient way to persist a transaction stream?

I'm interested in caching the results of a particular transaction stream. This will let me read the transactions off disk, and then start looking at new transactions at the point where my disk cache stops. I'm currently doing this in a pretty simple way, by just caching each transaction that comes out of the transaction stream. What I'd like to do is to also cache that a particular block doesn't contain any matching transactions. Right now this seems a little tricky because the transaction stream doesn't tell us when it sees a block without transactions. I can think of a few ways to do this, but do you have any recommendations for the "right" way to approach this?

One thing I was thinking about is that the transaction stream could have an option where it can output an object indicating that it has finished looking at a particular block. This may be a bit too closely tailored to my use case, though.

Another idea is to have a stream that reads from both the block stream and the transaction stream and kind of zips their outputs together into a single stream. This might be a little bit more work but it could be better-factored.

Not working for Bitcoin testnet

When I run the tests w/ the Bitcoin testnet params, I get the error below.

It looks like some values in the test are hardcoded for the Bitcoin mainnet. However, I think that there might be actual functionality issues as well, because burnie seems to not work with bitcoin-net@4.

✓ PeerGroup constructor
✓ invalid params
✓ valid params, no options
✓ valid params, with options
✓ connect
✓ peer methods
✓ randomPeer
⨯ getBlocks
  not ok 19 no error
    ---
      operator: error
      expected: |-
        undefined
      actual: |-
        { [Error: Request timed out] timeout: true }
      at: Timeout._onTimeout (/Users/paul/repos/bitcoin-net/lib/peer.js:9:23770)
      stack: |-
        Error: Request timed out
            at Timeout._onTimeout (/Users/paul/repos/bitcoin-net/lib/peer.js:9:23640)
            at tryOnTimeout (timers.js:224:11)
            at Timer.listOnTimeout (timers.js:198:5)
    ...
  not ok 20 result is array
    ---
      operator: ok
      expected: true
      actual:   false
      at: Timeout._onTimeout (/Users/paul/repos/bitcoin-net/lib/peer.js:9:23770)
    ...
/Users/paul/repos/bitcoin-net/test/build/peerGroup.js:101
        t.equal(res.length, 1, 'result is correct length');
                   ^

TypeError: Cannot read property 'length' of undefined
    at /Users/paul/repos/bitcoin-net/test/build/peerGroup.js:101:20
    at Timeout._onTimeout (/Users/paul/repos/bitcoin-net/lib/peer.js:9:23770)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)
  ------------------------|----------|----------|----------|----------|----------------|
  File                    |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
  ------------------------|----------|----------|----------|----------|----------------|
   bitcoin-net/           |      100 |      100 |      100 |      100 |                |
    index.js              |      100 |      100 |      100 |      100 |                |
   bitcoin-net/lib/       |    52.11 |    34.26 |     46.9 |    52.29 |                |
    bridge.js             |    43.94 |    33.33 |    33.33 |    29.27 |... 56,59,60,67 |
    peer.js               |    59.38 |    42.07 |    63.27 |    60.36 |... 462,463,464 |
    peerGroup.js          |       50 |    30.81 |    41.94 |     51.6 |... 537,538,540 |
    protocolTransforms.js |    32.86 |     4.17 |       25 |    32.86 |... 103,115,116 |
    utils.js              |    72.73 |    71.43 |    66.67 |       80 |          11,12 |
  ------------------------|----------|----------|----------|----------|----------------|
  All files               |    52.17 |    34.26 |     46.9 |    52.36 |                |
  ------------------------|----------|----------|----------|----------|----------------|

not ok 21 no plan found
⨯ fail  3
npm ERR! Test failed.  See above for more details.

TypeError: block.header.getHash is not a function

block argument is object with data fields, but without any specific methods

this.emit(`block:${block.header.getHash().toString('base64')}`, block)

example.js

let { Peer } = require('bitcoin-net')
const net = require("net")

const socket = net.connect({ port: 8333, host: 'vilha.info' }, () => {
  const peer = new Peer({ magic: 0xd9b4bef9, defaultPort: 8333 }, { socket })

  peer.once('ready', () => {
    peer.getBlocks([Buffer.from('0000000000000000002b0fcdc0bdedcc71fcce092633885628c3b50d43200002', 'hex').reverse()],
      (err, headers) => {
        console.log(headers)
      })
  })
})

package.json

  "dependencies": {
    "bitcoin-inventory": "^1.0.2",
    "bitcoin-merkle-proof": "0.0.6",
    "bitcoin-net": "^5.0.0",
    "bitcoin-protocol": "^3.0.1",
    "blockchain-spv": "^3.1.6",
    "crypto": "^1.0.1",
    "debug": "^2.2.0",
    "event-cleanup": "^1.0.3",
    "object-assign": "^4.1.0",
    "through2": "^2.0.1",
    "webcoin-bitcoin": "^3.1.4"
  }

How can I listen to transactions?

Now since I'm getting connections and figured out how to use the debug command I see a lot of pingpongs and the blocks.

Shouldn't I also get the "inv" for all transactions? How can I listen to (and send back raw) transactions?

Bloom filtering

We'll need an API for setting Bloom filters on our peers. However, this module is getting pretty large, so it might make sense to put that in its own module which is enabled on a PeerGroup by setting the filter for each peer.

not connecting anymore

See screenshot. After the latest npm install the bridge/everything is not working anymore:

unbenannt

Documentation

The README docs are still missing some info:

  • HeaderStream
  • BlockStream
  • PeerGroup events
  • Peer events

PeerGroup close callback is called before all sockets are closed

As far as I can tell, the close method of PeerGroup does successfully close it, but the callback is called before it's really closed. Specifically, it looks like TCP connections can still be opened after close is called. Maybe we could count the number of open TCP connections and only call the callback after count goes to zero?

  simple-block-stream closing... +31ms
  bitcoin-net:peergroup close called: peers.length = 0 +1ms
// At this point, PeerGroup calls the callback
  simple-block-stream closed +0ms
  simple-block-stream streaming from 278336 73a362d87ddf3cd111a53532dc711d2869054064fd38032a0000000000000000 +8ms
  simple-block-stream starting txs... +1ms
  bitcoin-net:peergroup _connectTCP: tcp://96.2.103.25:8333 +5ms
  bitcoin-net:peergroup _connectTCP: tcp://108.44.238.26:8333 +3ms
  bitcoin-net:peergroup _connectTCP: tcp://122.133.113.149:8333 +1ms
  bitcoin-net:peergroup _connectTCP: tcp://169.255.57.31:8333 +0ms
  bitcoin-net:peergroup _connectTCP: tcp://124.82.29.181:8333 +1ms
  bitcoin-net:peergroup _connectTCP: tcp://46.17.103.64:8333 +29ms
  bitcoin-net:peergroup _connectTCP: tcp://37.146.53.88:8333 +25ms
  bitcoin-net:peergroup _connectTCP: tcp://103.255.25.89:8333 +9ms
  bitcoin-net:peergroup discovery connection error: Connection timed out +8s

Documentation outdated

In the sample it should be
new PeerGroup.PeerGroup(params)
and
peer.ping(() => console.log('received pong response'))
and
peer.socket._sockname.address

Flood of peer connections

The browser debug is flooding (and crashing the browser) with

bitcoin-net:peergroup discovery connection error: Peer does not have any peers to exchange

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.