ordinals / ord

👁‍🗨 Rare and exotic sats
https://ordinals.com
Creative Commons Zero v1.0 Universal
3.84k stars 1.37k forks source link

Use default RPC port for chain if port is not passed with rpc URL #2093

Open robinsdan opened 1 year ago

robinsdan commented 1 year ago
ERROR [ord::index::updater] src\index\updater.rs:311: Couldn't receive txs error trying to connect: tcp connect error: No connection could be made because the target machine actively refused it.
WARN [ord::subcommand::server] src\subcommand\server.rs:138: failed to get transaction for a2df039d22ce84803de677328efe3a2fe82b0102d66c32f899715608babd1214

It always failed at this transaction, but I can get the transaction data using bitcoin console:

> getrawtransaction "a2df039d22ce84803de677328efe3a2fe82b0102d66c32f899715608babd1214"

< 010000000001018c27fa2db6d393176d10e8cfe75fe0e05dcddce651e3d47daf7d33fae42b69ae0000000000ffffffff021ec02b00000000001976a91419537f699522039153319200019e327a4fb09bc888ac22081b0100000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d0400473044022028dc2de37300325408577563173c383cbbe1410caae57f88ed6d551e7560e5da02203a839e34ff865fd998c63d395a587a56fc594c6ff457b5d58edbe4e0bea5b0710147304402202b1c0a9df34049c288ac2b8c077700071bce1b43dd5bd89ef87b00452dbca945022077aba9d2024183bbc4edfa831eaf2917e860d38168f520f8a3bab876dffb5bc8016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000

my bitcoin.conf:

txindex=1
server=1
rpcthreads=20
rpcallowip=127.0.0.1
maxconnection=1000
robinsdan commented 1 year ago

I have create a testcase, and it works fine. do not known why the bitcoind reject the ord's connection.

#[test]
fn test_fetcher() {
  let rt = tokio::runtime::Builder::new_multi_thread()
    .enable_all()
    .build()
    .unwrap();
  rt.block_on(async move {
    let mut handles =Vec::new();
    for i in 0..100 {
      handles.push(tokio::spawn(
        async move {
          let mut options = Options::default();
          options.bitcoin_rpc_user = Some("user".to_string());
          options.bitcoin_rpc_pass = Some("pass".to_string());
          options.rpc_url = Some("http://localhost:8332".to_string());

          let fetcher = Fetcher::new(&options).unwrap();
          let txid = Txid::from_hex("a2df039d22ce84803de677328efe3a2fe82b0102d66c32f899715608babd1214").unwrap();
          let txids = iter::repeat(txid).take(10).collect();
          let result = fetcher.get_transactions(txids).await.unwrap();

          println!("transactions: {}", serde_json::to_string(&result).unwrap());
        }));
    }

    for h in handles {
      h.await;
    }
  });
}
transactions: [{"version":1,"lock_time":0,"input":[{"previous_output":"ae692be4fa337daf7dd4e351e6dccd5de0e05fe7cfe8106d1793d3b62dfa278c:0","script_sig":"","sequence":4294967295,"witness":["","3044022028dc2de37300325408577563173c383cbbe1410caae57f88ed6d551e7560e5da02203a839e34ff865fd998c63d395a587a56fc594c6ff457b5d58edbe4e0bea5b07101","304402202b1c0a9df34049c288ac2b8c077700071bce1b43dd5bd89ef87b00452dbca945022077aba9d2024183bbc4edfa831eaf2917e860d38168f520f8a3bab876dffb5bc801","52210375e00eb72e29da82b89369ef87b00452...
robinsdan commented 1 year ago

Ok, I found out the reason, I use --rpc-url=127.0.0.1, the jsonrpc crate will take it as http://127.0.0.1:8332, but hyper crate used to get transaction will take it as http://127.0.0.1:80. I think the ord crate need more check to make them behave consistent.

xiaok commented 1 year ago

@robinsdan Hi, I have the same problem, even the tx hash is the same, how do you solve this problem?

[2023-07-25T02:34:22Z ERROR ord::index::updater] Couldn't receive txs Failed to fetch raw transaction: code -5 message No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries. Use gettransaction for wallet transactions. error: failed to get transaction for a2df039d22ce84803de677328efe3a2fe82b0102d66c32f899715608babd1214

solaasan commented 1 year ago

@xiaok a bit delayed but specify the port of your RPC ie --rpc-url=127.0.0.1:8332 if you are running locally

casey commented 1 year ago

I'm not opposed to defaulting to the default port of the chain, instead of using port 80, which is almost always wrong.

solaasan commented 1 year ago

I'm not opposed to defaulting to the default port of the chain, instead of using port 80, which is almost always wrong.

Assuming that doesnt cause some sort of breaking change for others, sounds to me at least like that'd do the trick. Either that or some kind of more verbose heads up/warning when no rpc-url is specified of it's behavior defaulting to :80 . Took me longer than I'd like to admit to realize this had been the headache my docker ord setup was running into 😅

zangshenccc commented 10 months ago

But I specified port 8332 and still reported this error. Why is it

raphjaph commented 10 months ago

how did you specify it?

donnlee commented 10 months ago

I get the same error with SAME HASH. Could a chain reorg have caused this?

donn@nas:~/workspace/bitcoin/ord$ ./ord --cookie-file ./cookie --rpc-url http://zotac:8332/wallet/ord --data-dir . wallet balance
[indexing blocks] ████████████████████████████████████████████░░░░ 767427/821421
[2023-12-16T05:07:59Z ERROR ord::index::updater] Couldn't receive txs failed to fetch raw transaction: code -5 message No such mempool or blockchain transaction. Use gettransaction for wallet transactions.
error: failed to get transaction for a2df039d22ce84803de677328efe3a2fe82b0102d66c32f899715608babd1214

ord 0.13.1

donnlee commented 10 months ago

My bitcoin node's console outputs this when I do bitcoin-cli getrawtransaction a2df039d22ce84803de677328efe3a2fe82b0102d66c32f899715608babd1214:

2023-12-16T05:17:24Z ERROR: FindTx: Deserialize or I/O error - ReadCompactSize(): size too large: iostream error
donnlee commented 9 months ago

Here's how I resolved the failed to get transaction for a2df039d22ce84803de677328efe3a2fe82b0102d66c32f899715608babd1214 blocker: Use the sledgehammer approach. On my bitcoin node, deleted all block, chainstate, and index files. Resync'd bitcoin node from the beginning. After bitcoin node was fully sync'd, I ran ord 0.13.1 sync from the beginning. After a few days, ord fully sync'd.

xiaok commented 9 months ago

you should use txindex=1 as a bitcoind configuration