electrs icon indicating copy to clipboard operation
electrs copied to clipboard

Custom signet magic values are not supported

Open aitorjs opened this issue 4 years ago • 23 comments

Being inside a folder with the electrs code, I type:

cargo run --release --bin electrs -- -vvvv --daemon-dir ~/signet-custom --network signet --db-dir ~/.electrs/csignet/db --electrum-rpc-addr 127.0.0.1:60601

and I get this error: thread 'main' panicked at 'no indexed header found', src/bulk.rs:69:14.

I guess is because the path inside --daemon-dir has no blk*.dat in ~/signet-custom/signet/blocks/ but I has two blocks exactly:

user@domain:~/signet-custom/signet/blocks$ ls -las
16384 -rw------- 1 user user 16777216 Jun 30 17:15 blk00000.dat
    4 drwx------ 2 user user     4096 Jun 30 17:00 index
 1024 -rw------- 1 user user  1048576 Jun 30 17:15 rev00000.dat

If I try with --daemon-dir ~/signet-custom/signet, .cookie is not find it in ~/signet-custom/signet/signet/.cookie. My bitcoind signet data is on: ~/signet-custom/signet not on ~/signet-custom/signet/signet.

¿What I'm doing wrong?

Thanks! :)

aitorjs avatar Jun 30 '21 15:06 aitorjs

Thanks for reporting this issue! Could you please attach the full debug log?

romanz avatar Jun 30 '21 18:06 romanz

signet-custom/signet/debug.log

2021-07-01T15:38:12Z Shutdown: done
2021-07-01T15:39:08Z Signet with challenge 512103b3b3721560a0d98a211a4bf38b910c4a0c97f435861e65e136c9993cd99fb34151ae
2021-07-01T15:39:08Z Bitcoin Core version v21.99.0-0ca8b7e7ecd5 (release build)
2021-07-01T15:39:08Z Signet derived magic (message start): 8de45da0
2021-07-01T15:39:08Z Validating signatures for all blocks.
2021-07-01T15:39:08Z Setting nMinimumChainWork=0000000000000000000000000000000000000000000000000000000000000000
2021-07-01T15:39:08Z Using the 'sse4(1way),sse41(4way)' SHA256 implementation
2021-07-01T15:39:08Z Using RdRand as an additional entropy source
2021-07-01T15:39:08Z Default data directory /home/user/.bitcoin
2021-07-01T15:39:08Z Using data directory /home/user/signet-custom/signet
2021-07-01T15:39:08Z Config file: /home/user/signet-custom/bitcoin.conf
2021-07-01T15:39:08Z Config file arg: signet="1"
2021-07-01T15:39:08Z Config file arg: [signet] addnode="XXX.XXX.XXX.XXX:38333"
2021-07-01T15:39:08Z Config file arg: [signet] daemon="1"
2021-07-01T15:39:08Z Config file arg: [signet] signetchallenge="512103b3b3721560a0d98a211a4bf38b910c4a0c97f435861e65e136c9993cd99fb34151ae"
2021-07-01T15:39:08Z Config file arg: [signet] wallet="test"
2021-07-01T15:39:08Z Command-line arg: datadir="/home/user/signet-custom"
2021-07-01T15:39:08Z Using at most 125 automatic connections (1024 file descriptors available)
2021-07-01T15:39:08Z Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements
2021-07-01T15:39:08Z Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements
2021-07-01T15:39:08Z Script verification uses 3 additional threads
2021-07-01T15:39:08Z scheduler thread start
2021-07-01T15:39:08Z HTTP: creating work queue of depth 16
2021-07-01T15:39:08Z Using random cookie authentication.
2021-07-01T15:39:08Z Generated RPC authentication cookie /home/user/signet-custom/signet/.cookie
2021-07-01T15:39:08Z HTTP: starting 4 worker threads
2021-07-01T15:39:08Z Using wallet directory /home/user/signet-custom/signet/wallets
2021-07-01T15:39:08Z init message: Verifying wallet(s)...
2021-07-01T15:39:08Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
2021-07-01T15:39:08Z Using wallet /home/user/signet-custom/signet/wallets/test/wallet.dat
2021-07-01T15:39:08Z BerkeleyEnvironment::Open: LogDir=/home/user/signet-custom/signet/wallets/test/database ErrorFile=/home/user/signet-custom/signet/wallets/test/db.log
2021-07-01T15:39:08Z init message: Loading banlist...
2021-07-01T15:39:08Z SetNetworkActive: true
2021-07-01T15:39:08Z Using /16 prefix for IP bucketing
2021-07-01T15:39:08Z Cache configuration:
2021-07-01T15:39:08Z * Using 2.0 MiB for block index database
2021-07-01T15:39:08Z * Using 8.0 MiB for chain state database
2021-07-01T15:39:08Z * Using 440.0 MiB for in-memory UTXO set (plus up to 286.1 MiB of unused mempool space)
2021-07-01T15:39:08Z init message: Loading block index...
2021-07-01T15:39:08Z Switching active chainstate to Chainstate [ibd] @ height -1 (null)
2021-07-01T15:39:08Z Opening LevelDB in /home/user/signet-custom/signet/blocks/index
2021-07-01T15:39:08Z Opened LevelDB successfully
2021-07-01T15:39:08Z Using obfuscation key for /home/user/signet-custom/signet/blocks/index: 0000000000000000
2021-07-01T15:39:08Z LoadBlockIndexDB: last block file = 0
2021-07-01T15:39:08Z LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=27, size=9055, heights=0...26, time=2020-09-01...2021-06-30)
2021-07-01T15:39:08Z Checking all blk files are present...
2021-07-01T15:39:08Z Opening LevelDB in /home/user/signet-custom/signet/chainstate
2021-07-01T15:39:08Z Opened LevelDB successfully
2021-07-01T15:39:08Z Using obfuscation key for /home/user/signet-custom/signet/chainstate: 442e821e31d0c462
2021-07-01T15:39:08Z Loaded best chain: hashBestChain=000000941fbabd0daa3cb1804bbe50cb4ae6cda9ebb87e8d1d6964668af26a1f height=26 date=2021-06-30T16:06:35Z progress=1.000000
2021-07-01T15:39:08Z init message: Verifying blocks...
2021-07-01T15:39:08Z Verifying last 6 blocks at level 3
2021-07-01T15:39:08Z [0%]...[16%]...[33%]...[50%]...[66%]...[83%]...[99%]...[DONE].
2021-07-01T15:39:08Z No coin database inconsistencies in last 6 blocks (6 transactions)
2021-07-01T15:39:08Z  block index              17ms
2021-07-01T15:39:08Z init message: Loading wallet...
2021-07-01T15:39:08Z BerkeleyEnvironment::Open: LogDir=/home/user/signet-custom/signet/wallets/test/database ErrorFile=/home/user/signet-custom/signet/wallets/test/db.log
2021-07-01T15:39:08Z [test] Wallet File Version = 169900
2021-07-01T15:39:08Z [test] Keys: 2024 plaintext, 0 encrypted, 2024 w/ metadata, 2024 total. Unknown wallet records: 0
2021-07-01T15:39:08Z [test] Wallet completed loading in             166ms
2021-07-01T15:39:08Z [test] keypool added 1 keys (0 internal), size=2000 (1000 internal)
2021-07-01T15:39:08Z [test] setKeyPool.size() = 2000
2021-07-01T15:39:08Z [test] mapWallet.size() = 1146
2021-07-01T15:39:08Z [test] m_address_book.size() = 26
2021-07-01T15:39:08Z block tree size = 27
2021-07-01T15:39:08Z nBestHeight = 26
2021-07-01T15:39:08Z loadblk thread start
2021-07-01T15:39:08Z AddLocal(11.0.0.201:38333,1)
2021-07-01T15:39:08Z Discover: IPv4 eth0: 11.0.0.201
2021-07-01T15:39:08Z Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there, 0 waiting for initial broadcast
2021-07-01T15:39:08Z Bound to [::]:38333
2021-07-01T15:39:08Z Bound to 0.0.0.0:38333
2021-07-01T15:39:08Z Bound to 127.0.0.1:38334
2021-07-01T15:39:08Z init message: Loading P2P addresses...
2021-07-01T15:39:08Z loadblk thread exit
2021-07-01T15:39:08Z Loaded 3 addresses from peers.dat  0ms
2021-07-01T15:39:08Z Loaded 0 addresses from "anchors.dat"
2021-07-01T15:39:08Z 0 block-relay-only anchors will be tried for connections.
2021-07-01T15:39:08Z init message: Starting network threads...
2021-07-01T15:39:08Z net thread start
2021-07-01T15:39:08Z init message: Done loading
2021-07-01T15:39:08Z msghand thread start
2021-07-01T15:39:08Z dnsseed thread start
2021-07-01T15:39:08Z 0 addresses found from DNS seeds
2021-07-01T15:39:08Z dnsseed thread exit
2021-07-01T15:39:08Z torcontrol thread start
2021-07-01T15:39:08Z [test] Submitting wtx 67025eec0f95ba03c9ad125a7cf5e3f65617df844cc0ae00e282da92e016d0d9 to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 058b4eb29baf53bff98d4c1e70d0dc46777cc6ba846611945bbcfd71c453c22f to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 1c3e2114444633def389e213c548bbdf006498285e2fb4d4372b8f1e7ee62664 to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 972fed1deb119dae9e28c4a637b370ddbbd4942234eebd5c89bd2846bc236c1e to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 9494a820084dd4ccd7e03d0344e9d6e5a2f064af69a5451b300285e096d977c0 to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx e6c2bfc23840e860be1124a8164ad9d7ef15149607cd3a2765a4d62c221b7063 to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx dbcdf048263167ad5d5ec52bab2660f8e397ab966d2011311ee6763fa8fe821d to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 9e1528a036a8391cb6036e06607975345df67b97cb104a94be60b73692001669 to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 55590fdb8b84149b25ed05dac9e7051f66f46c850b7558794c53303b73247dd7 to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 181089004b594d2d9982343c42f29bb904566fabdfbaf00a831548debff73051 to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 69a36ec483ea701636accc955f3d04bdddb70f68193faee1a455f3196b834b9e to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 5a5dff2b1e32792838b9a2106cb60b0f3c5806fa8a00cdbf6495823c0c713c15 to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx a5618a27f67dbd94f9b5a189da9653bc2d471dc9f77e9bfd498de5e5c4e226c3 to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 736111d0f739743f3af1b8000db64542dcad402b5b91211631bc1d885d81dd84 to mempool for relay
2021-07-01T15:39:08Z [test] Submitting wtx 9c0dfc72f8cb6c09c14f26592a2568d1f03149be326f7c470899a9b72b3911dc to mempool for relay
2021-07-01T15:39:08Z addcon thread start
2021-07-01T15:39:08Z opencon thread start
2021-07-01T15:39:09Z Leaving InitialBlockDownload (latching to false)

cargo run --release --bin electrs -- -vvvv --daemon-dir /home/user/signet-custom --network signet --db-dir /home/user/.electrs/csignet/db --electrum-rpc-addr 127.0.0.1:60601

    Finished release [optimized] target(s) in 1.10s
     Running `target/release/electrs -vvvv --daemon-dir /home/user/signet-custom --network signet --db-dir /home/user/.electrs/csignet/db --electrum-rpc-addr '127.0.0.1:60601'`
Config { log: StdErrLog { verbosity: Trace, quiet: false, show_level: true, timestamp: Off, modules: [], writer: "stderr", color_choice: Auto }, network_type: Signet, db_path: "/home/user/.electrs/csignet/db/signet", daemon_dir: "/home/user/signet-custom/signet", blocks_dir: "/home/user/signet-custom/signet/blocks", daemon_rpc_addr: 127.0.0.1:38332, electrum_rpc_addr: 127.0.0.1:60601, monitoring_addr: 127.0.0.1:34224, jsonrpc_import: false, index_batch_size: 10, bulk_index_threads: 4, tx_cache_size: 10485760, txid_limit: 100, server_banner: "Welcome to electrs 0.8.10 (Electrum Rust Server)!", blocktxids_cache_size: 10485760 }
DEBUG - Server listening on 127.0.0.1:34224
DEBUG - Running accept thread
INFO - NetworkInfo { version: 219900, subversion: "/Satoshi:21.99.0/", relayfee: 0.00001 }
INFO - BlockchainInfo { chain: "signet", blocks: 26, headers: 26, verificationprogress: 1.0, bestblockhash: "000000941fbabd0daa3cb1804bbe50cb4ae6cda9ebb87e8d1d6964668af26a1f", pruned: false, initialblockdownload: false }
DEBUG - opening DB at "/home/user/.electrs/csignet/db/signet"
TRACE - latest indexed blockhash: 0000000000000000000000000000000000000000000000000000000000000000
INFO - listing block files at "/home/user/signet-custom/signet/blocks/blk*.dat"
INFO - indexing 1 blk*.dat files
DEBUG - found 0 indexed blocks
TRACE - downloading 27 block headers
DEBUG - applying 27 new headers from height 0
DEBUG - no more blocks to index
DEBUG - no more blocks to index
DEBUG - no more blocks to index
DEBUG - no more blocks to index
TRACE - indexed "/home/user/signet-custom/signet/blocks/blk00000.dat": 0 rows
thread 'main' panicked at 'no indexed header found', src/bulk.rs:69:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
TRACE - closing DB at "/home/user/.electrs/csignet/db/signet"

cargo run --release --bin electrs -- -vvvv --daemon-dir /home/user/signet-custom/signet --network signet --db-dir /home/user/.electrs/csignet/db --electrum-rpc-addr 127.0.0.1:60601

Finished release [optimized] target(s) in 0.24s
     Running `target/release/electrs -vvvv --daemon-dir /home/user/signet-custom/signet --network signet --db-dir /home/user/.electrs/csignet/db --electrum-rpc-addr '127.0.0.1:60601'`
Config { log: StdErrLog { verbosity: Trace, quiet: false, show_level: true, timestamp: Off, modules: [], writer: "stderr", color_choice: Auto }, network_type: Signet, db_path: "/home/user/.electrs/csignet/db/signet", daemon_dir: "/home/user/signet-custom/signet/signet", blocks_dir: "/home/user/signet-custom/signet/signet/blocks", daemon_rpc_addr: 127.0.0.1:38332, electrum_rpc_addr: 127.0.0.1:60601, monitoring_addr: 127.0.0.1:34224, jsonrpc_import: false, index_batch_size: 10, bulk_index_threads: 4, tx_cache_size: 10485760, txid_limit: 100, server_banner: "Welcome to electrs 0.8.10 (Electrum Rust Server)!", blocktxids_cache_size: 10485760 }
DEBUG - Server listening on 127.0.0.1:34224
DEBUG - Running accept thread
WARN - reconnecting to bitcoind: failed to read cookie from /home/user/signet-custom/signet/signet/.cookie
WARN - reconnecting to bitcoind: failed to read cookie from /home/user/signet-custom/signet/signet/.cookie

aitorjs avatar Jul 01 '21 15:07 aitorjs

IIUC, you are running a signet with a custom "magic" (a 4-byte prefix for p2p messages, as well as the blocks stored on the disk):

2021-07-01T15:39:08Z Signet derived magic (message start): 8de45da0

Unfortunately, it is currently is not supported by the electrs blk*.dat parser, since it relies on the Network enum: https://github.com/rust-bitcoin/rust-bitcoin/blob/e99177c4fba9ece1eb219e7980981c099bc6f2d5/src/network/constants.rs#L110-L118

        match self {
            Network::Bitcoin => 0xD9B4BEF9,
            Network::Testnet => 0x0709110B,
            Network::Signet  => 0x40CF030A,
            Network::Regtest => 0xDAB5BFFA,
        }

I would suggest using --jsonrpc-import flag, which uses JSON RPC to get the blocks from bitcoind.

romanz avatar Jul 02 '21 08:07 romanz

Makes sense! :)

I try with --jsonrpc-import, 'no indexed header found' error disappear and start indexing old blocks.

When I create a new block, electrs on custom signet detects it and index it. So, it works! :)

Thanks for the help! Amazing job!

aitorjs avatar Jul 02 '21 12:07 aitorjs

Cool, happy it worked :)

romanz avatar Jul 02 '21 12:07 romanz

I see that --jsonrpc-import has been disappear. I try deleting it, like this:

cargo run --release --bin electrs -v -- --daemon-dir /home/user/signet-custom/ --network signet --db-dir /home/user/.electrs/csignet/db --electrum-rpc-addr 127.0.0.1:60601 --index-lookup-limit 20000

but I get this error:

**Error: electrs failed**

Caused by:
    receiving on an empty and disconnected channel

This curl request, response ok:

curl --user __cookie__ --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getblockcount", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:38332/

This is bitcoin.conf I have:

signet=1
daemon=1
[signet]
signetchallenge=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
addresstype=bech32
wallet=test

I think that electrs cant connect to bitcoind but bitcoind on custom signet is up and running.

¿What I'm missing? Thanks! :)

aitorjs avatar Nov 10 '21 16:11 aitorjs

Most likely you forgot to set p2p address or forgot to whitelist electrs in bitcoind. Please read the upgrade instructions.

Kixunil avatar Nov 10 '21 17:11 Kixunil

I use the default p2p address for bitcoind, so I guess is whitelist part.

I add "whitelist=127.0.0.1" to the end of bitcoin.conf, restart but the error continues.

On the same machine, electrs on testnet and regtest runs ok.

aitorjs avatar Nov 10 '21 17:11 aitorjs

Could you please attach the verbose log by running the latest electrs with:

$ RUST_LOG=debug electrs <args>

romanz avatar Nov 10 '21 21:11 romanz

~/electrs$ RUST_LOG=debug cargo run --release --bin electrs -v -- --daemon-dir /home/user/signet-custom --network signet --db-dir /home/user/.electrs/csignet/db --electrum-rpc-addr 127.0.0.1:60601 --index-lookup-limit 20000
    Finished release [optimized] target(s) in 0.17s
     Running `target/release/electrs --daemon-dir /home/user/signet-custom --network signet --db-dir /home/user/.electrs/csignet/db --electrum-rpc-addr '127.0.0.1:60601' --index-lookup-limit 20000`
Starting electrs 0.9.2 on x86_64 linux with Config { network: Signet, db_path: "/home/user/.electrs/csignet/db/signet", daemon_dir: "/home/user/signet-custom/signet", daemon_auth: CookieFile("/home/user/signet-custom/signet/.cookie"), daemon_rpc_addr: 127.0.0.1:38332, daemon_p2p_addr: 127.0.0.1:38333, electrum_rpc_addr: 127.0.0.1:60601, monitoring_addr: 127.0.0.1:34224, wait_duration: 10s, jsonrpc_timeout: 15s, index_batch_size: 10, index_lookup_limit: Some(20000), reindex_last_blocks: 0, auto_reindex: true, ignore_mempool: false, sync_once: false, disable_electrum_rpc: false, server_banner: "Welcome to electrs 0.9.2 (Electrum Rust Server)!", args: [] }
[2021-11-10T22:33:22.404Z INFO  electrs::metrics::metrics_impl] serving Prometheus metrics on 127.0.0.1:34224
[2021-11-10T22:33:22.405Z INFO  electrs::server] serving Electrum RPC on 127.0.0.1:60601
[2021-11-10T22:33:22.405Z DEBUG tiny_http] Server listening on 127.0.0.1:34224
[2021-11-10T22:33:22.405Z DEBUG tiny_http] Running accept thread
[2021-11-10T22:33:22.448Z INFO  electrs::db] "/home/user/.electrs/csignet/db/signet": 285 SST files, 0.000229425 GB, 0.000000021 Grows
[2021-11-10T22:33:22.448Z DEBUG electrs::db] DB Some(Config { compacted: false, format: 0 })
[2021-11-10T22:33:22.508Z DEBUG bitcoincore_rpc] JSON-RPC request: getblockchaininfo []
[2021-11-10T22:33:22.510Z DEBUG bitcoincore_rpc] JSON-RPC request: getnetworkinfo []
[2021-11-10T22:33:22.511Z DEBUG bitcoincore_rpc] JSON-RPC request: getblockchaininfo []
[2021-11-10T22:33:22.513Z DEBUG electrs::p2p] closing p2p_recv thread: connection closed
[2021-11-10T22:33:22.513Z DEBUG electrs::p2p] closing p2p_loop thread: peer has disconnected
[2021-11-10T22:33:22.513Z DEBUG electrs::p2p] closing p2p_send thread: no more messages to send
[2021-11-10T22:33:22.513Z INFO  electrs::db] closing DB at /home/user/.electrs/csignet/db/signet
Error: electrs failed

Caused by:
    receiving on an empty and disconnected channel

aitorjs avatar Nov 10 '21 22:11 aitorjs

Could you please run bitcoind with -debug=net flag and set electrs logging verbosity to:

$ export RUST_LOG=electrs=debug,electrs::p2p=trace

It should (hopefully) help us understand why electrs disconnects from bitcoind.

romanz avatar Nov 11 '21 07:11 romanz

When I call to electrs, those new lines are seen on bitcoind's debug.log

2021-11-11T11:53:41Z Added connection peer=1
2021-11-11T11:53:41Z connection from 127.0.0.1:57544 accepted
2021-11-11T11:53:41Z Header error: Wrong MessageStart 0a03cf40 received, peer=1
2021-11-11T11:53:41Z disconnecting peer=1
2021-11-11T11:53:41Z Cleared nodestate for peer=1

So, the problem is the custom "magic" of the custom signet ¿right? My custom signet starts with "8de45da0" ¿Is there a way to change this "magic" data?

aitorjs avatar Nov 11 '21 11:11 aitorjs

Currently no - we only support the following magic values: https://docs.rs/bitcoin/0.27.1/src/bitcoin/network/constants.rs.html#110-118

    pub fn magic(self) -> u32 {
        // Note: any new entries here must be added to `from_magic` above
        match self {
            Network::Bitcoin => 0xD9B4BEF9,
            Network::Testnet => 0x0709110B,
            Network::Signet  => 0x40CF030A,
            Network::Regtest => 0xDAB5BFFA,
        }
    }

romanz avatar Nov 11 '21 15:11 romanz

It would be definitely possible to add such feature though :)

romanz avatar Nov 11 '21 15:11 romanz

So I suppose the solution is something like:

  • add signet_magic configuration option
  • if signet_magic is Some(_) and network is not Signet return error
  • if signet_magic is None set it to default
  • test that hex value can be used and document the syntax (I guess it'll need 0x prefix but not sure)

This looks easy, maybe "good first issue"?

Kixunil avatar Nov 11 '21 16:11 Kixunil

This looks easy, maybe "good first issue"?

:+1:

romanz avatar Nov 11 '21 17:11 romanz

I started learning rust a month ago, more or less with "The rust programming language".

I will try it! Sure I will have questions or problems. :)

aitorjs avatar Nov 11 '21 18:11 aitorjs

I add --signet-custom param and with those lines on _src/config.rs'_s from_args() method:

let signet_magic = match config.signet_magic {
    None => None,
    Some(string) => {
        if config.network != Network::Signet {
            eprintln!("Error: signet_magic is only available on signet");
            std::process::exit(1);
        } 
                
        println!("! SIGNET MAGIC es signet: {:?}", string);
        Some(string)
    }
};

--signet-custom param is more or less under control.

Next, I try to figure it out how can I add a new network to bitcoin::network::constants::Network. This enum is public (https://docs.rs/bitcoin/0.27.1/bitcoin/network/constants/enum.Network.html), so I can re-export it on electrs. I try it but dont get the code for a new enum with Network::Bitcoin, Network::Testsnet... and the new variant for custom signet.

I'm stuck trying to add the new variant for Network enum. ¿Could I get some help here?

¿is this a possible way to solve the issue? ¿Do you see an easier way to do it?

Thanks! :)

aitorjs avatar Nov 12 '21 14:11 aitorjs

how can I add a new network to bitcoin::network::constants::Network

You can't - it's an external library. But that's OK, just pass config.signet_magic as a separate argument to fn magic(self) and do the computation there.

Kixunil avatar Nov 12 '21 14:11 Kixunil

I started reading about rust one month ago. First thing I do with rust... so, be patient please!

just pass config.signet_magic as a separate argument to fn magic(self) and do the computation there.

I dont understant it, sorry. magic() is a method from an external crate so I dont know where to pass config.signet_magic because magic()'s signature has no params and where is the method to do the computation.

aitorjs avatar Nov 12 '21 14:11 aitorjs

Ah, sorry, for some reason I thought it's in electrs (in retrospect I could have noticed trivially, lol).

So I think the best approach is to write something like this in the caller of magic:

let magic = match (config.network, config.signet_magic) {
    (Network::Signet, Some(magic)) => magic,
    (network, None) => network.magic(),
    (_, Some(_)) => {
        eprintln!("Error: signet_magic is only available on signet");
        std::process::exit(1);
    },
}

First thing I do with rust... so, be patient please!

No worries, always love to see new Rust Bitcoin developers! :)

Kixunil avatar Nov 12 '21 14:11 Kixunil

I customize the match because --signet-custom param is an hexadecimal string value and network.magic() returns an u32.

let magic = match (config.network, config.signet_magic) {
            (Network::Signet, Some(magic)) => u32::from_str_radix(&magic.as_str(), 16).unwrap(),
            (network, None) => network.magic(),
            (_, Some(_)) => {
                eprintln!("Error: signet_magic is only available on signet");
                std::process::exit(1);
            },
        };

As later, on config.magic is the magic for the selected network.

just pass config.signet_magic as a separate argument to fn magic(self) and do the computation there.

So, if this is not a possible solution ¿which one could be?

So, still I dont see how can config.magic be used with bitcoin crater.

aitorjs avatar Nov 12 '21 16:11 aitorjs

i have the same problem, i have a custom signet and electrs wont start on it, --jsonrpc-import doesnt work (i use 0.9.3). how can i get this working? or do i just have to wait til this is implemented?

antonilol avatar May 03 '22 22:05 antonilol