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

FullNode Object cannot connect to the Bitcoin Core in regtest network #1109

Closed
f5i23q999d opened this issue Nov 20, 2022 · 1 comment
Closed

Comments

@f5i23q999d
Copy link

const FullNode = require('./lib/node/fullnode');

async function test() {

    const ports = {
        p2p: 49331,
        node: 49332,
        wallet: 49333
      };


    const node1 = new FullNode({
        network: 'regtest',
        apiKey: 'bar',
        walletAuth: true,
        memory: true,
        workers: true,
        workersSize: 2,
        indexTX: true,
        indexAddress: true,
        plugins: [require('./lib/wallet/plugin')],
        port: ports.p2p,
        httpPort: ports.node,
        env: {
          'BCOIN_WALLET_HTTP_PORT': ports.wallet.toString()
        }
      });

    
    node1.pool.on('packet', (packet) => {
        if (!nodePackets[packet.cmd])
            nodePackets[packet.cmd] = [packet];
        else
            nodePackets[packet.cmd].push(packet);
    });

    await node1.open();
    await node1.connect();
    node1.startSync();
}


test();

Here's the js code , and i ran the Bitcoin core V23.0 with command
./bitcoin-qt -regtest -server -connect=127.0.0.1:49331

They cannot communicate with each other , and i find the peers in Bitoin-qt and there is no peer.

But,

when i ran the bcoin command , which in the bin folder,
./bin/bcoin --network=regtest

with bconf.conf below

# Sample bcoin config file (~/.bcoin/bcoin.conf)

#
# Options
#

# network: main

#
# Node
#

prefix: ~/.bcoin
db: leveldb
max-files: 64
cache-size: 100

#
# Workers
#

workers: true
# workers-size: 4
# workers-timeout: 5000

#
# Logger
#

log-level: debug
log-console: true
log-file: true

#
# Chain
#

prune: false
checkpoints: true
entry-cache: 5000
index-tx: true
index-address: true
index-filter: true

#
# Mempool
#

mempool-size: 100
limit-free: true
limit-free-relay: 15
reject-absurd-fees: true
replace-by-fee: false
persistent-mempool: false

#
# Pool
#

selfish: false
compact: true
bip37: false
listen: true
max-outbound: 8
max-inbound: 30

# Proxy Server (browser=websockets, node=socks)
# proxy: foo:bar@127.0.0.1:9050
# onion: true
# upnp: true

# Custom list of DNS seeds
# seeds: seed.bitcoin.sipa.be

# Local Host & Port (to listen on)
host: 127.0.0.1
port: 28444

# Public Host & Port (to advertise to peers)
public-host: 127.0.0.1
public-port: 48444

# Always try to connect to these nodes.
# nodes: 127.0.0.1,127.0.0.2

# Only try to connect to these nodes.
# only: 127.0.0.1,127.0.0.2

#
# Miner
#

coinbase-flags: mined by bcoin
# coinbase-address: 1111111111111111111114oLvT2,1111111111111111111114oLvT2
preverify: false
max-block-weight: 4000000
reserved-block-weight: 4000
reserved-block-sigops: 400

#
# HTTP
#

http-host: 127.0.0.1
http-port: 8332
# ssl: true
# ssl-cert: @/ssl/cert.crt
# ssl-key: @/ssl/priv.key
api-key: bikeshed
# no-auth: false
# cors: false

and with the
./bitcoin-qt -regtest -server -connect=127.0.0.1:28444

they can connect with each other.

So i wonder if there is something wrong with my js code.

@theanmolsharma
Copy link
Collaborator

theanmolsharma commented Nov 24, 2022

I think you need to add a peer using node1.pool.hosts.addNode('127.0.0.1:18445')
I'm able to connect using this script

const {FullNode} = require("bcoin");

async function test() {
    const ports = {
        p2p: 49331,
        node: 49332,
        wallet: 49333
    };

    const node1 = new FullNode({
        network: 'regtest',
        memory: true,
        workers: true,
        workersSize: 2,
        port: ports.p2p,
        httpPort: ports.node
    });

    node1.pool.hosts.addNode('127.0.0.1:18445')

    node1.on('connect', (entry, block) => {
        console.log('%s (%d) added to chain.', entry.rhash(), entry.height);
    });

    await node1.open();
    await node1.connect();
    node1.startSync();
}

test();

I can also see peer info using bitcoin-cli -regtest getpeerinfo which shows an inbound connection.

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

No branches or pull requests

2 participants