2021/12/02

[22.0]Local環境でbitcoind@Regtestを動かしてみる

bitcoindocker

概要

開発時に使うbitcoinのノードにはRegtestが便利です。
ローカルで動くプライベートネットワークで、ネットワークに参加するノードを自由に付け替えたりできます。

ちゃんとした、開発環境では、testnetなどを指定しますが
ローカルでの開発時には、ローカルマシン上のDiskspace/Memory/CPUなどがかなり使われてしまうばかりか、
同期に時間がかかってしまうので、Regtestで動くbitoindを立てて、その動作確認を行いました。

bitcoinの実行環境はdockerで行い、ruimarinho/docker-bitcoin-coreのリポジトリのものがとても便利です。

実施事項

bitcoindの起動

  • 22.0 のバージョンをDockerを使って起動します。
  • bitcoind -fallbackfee=0.0002 で起動します。
  • bitcoin.conf は以下のようなものを含んでいます。
rpcuser=kumanote
rpcpassword=123456
server=1
testnet=0
regtest=1
printtoconsole=1
disablewallet=0

[regtest]
rpcport=18332
rpcbind=0.0.0.0
rpcallowip=0.0.0.0/0

bitcoin-cliで確認

bitcoindのノードにログインして、以下を実行します。

# 最初にwalletを作ってあげる必要があります。
$ bitcoin-cli createwallet "testwallet"

# mining用のアドレスを作成(systemというlabelをつけておく)
$ bitcoin-cli getnewaddress system
bcrt1qp3kdafp9tll9622ettknmw9kp3nvpx4h2upv0h

# 101block生成
$ bitcoin-cli generatetoaddress 101 bcrt1qp3kdafp9tll9622ettknmw9kp3nvpx4h2upv0h
[
  "4c32d0f957bcda932d2faa0bd22c878c0e2c58b0bed2937f60cb1ff0589e2168",
  "05e47f2a9e8c9da9a19a176bfabd3d30cab6546eed0f1ce3ad4c98f1b5a32b93",
  "0c8152438b1e52b90a073045407a0d0ec42b747cbefb0a2f87ea9b9f3a31d373",
  "5de300c7b12e6a37dfc9a54e7f0ff70284e99f19f98c443c5c36fbc0a30aee05",
  "4490cbe976430827511c5dae3d29b36be2dfc90c890fca751e52dfc9721e4f60",
  "0e3d2fecf0bd728ac9016e396d990aa0632b0de4a86426438d68c66b1180f393",
  "191647f32ed951d3249dab067859a365c0bc13e31776de6dc83154bcb6f01db7",
  "0e92eae0b78ac8e4fa651eba57dc7f805d164a0ed99540135d7e1351a439f8a6",
  "7557021bc1b783bcd3d00e62b7bba8d4c5060cdfc0331e416e39b1cd3f3ecad5",
  "68237872b91a4ec8e53c1c37bb8cface2e321a48b60230173ddae1e08fc94d07",
  "1c79e1cb8a262233ff5382a9c518c510776e4c206a3283f4510d2c3a24e9816c",
  "4768b663e5680e53a8f3d5d40bdaaf6bc3cf5a13ee954f13fb104d467ac45e4c",
  "50cbf3febc397f38c787f23c12df7bb91b64228e0a80c9e014a4ce06e23586c6",
  "34908b0f0513b5c493f9dae3b70a51ec225e3ab935607da85bec0f423d842208",
  "6ca2986b58760f5dcd8ad50eabc0fd458ea32ce8034c6c92e79c9c41f648ca9e",
  "79fd04022e742e0f5f1d14002fedfdaff2e52654d1d3e317b73bfde5aa2ae681",
  "7cdc15b7651b2c48706717361dcc54e90a5758926db4084be736a746c709e360",
  "1ceb27812d5e44f0a580354e0d4d99a3afd1f6873d8c4e154bd2770bd2132872",
  "127f8bbe730df894805552ff9ccf7a17eff286f3d9ee31977bf974f6d90e7e55",
  "447240043460ff5f8fb67a77f8a9ca880437fead59d248cb17ab32913dacefea",
  "60e2b063bf9b08cc848dd36532a24375433e51f7a49f2b50602b527e313ef84a",
  "235c6496b4d6137ae2a6add0f17b4dc739c6c0df1ae5ddcd4d983136e95a72e4",
  "0fc3538957b014ff0f49dcb11c7610c7bf13b71e0f5586fe887e370397980387",
  "0780a36d2c6b7584eca139437400cdfa6382e3eb096214f2fe2140466d4e5ae6",
  "1749e8b5ca16ca1a649a8e4586ca1c2906fef14205f92e6205819e2bf6fc98ce",
  "53600b799cd55d68dad8b7ea88ff39e842d93b20dbe047dd7324eb635b7c1b57",
  "266a533566185a48d7c24529cb25204ac185aab8919c6ddb196abdbfad6d5ef8",
  "7f8a053a12622556e71d55c0b26d0329837b281d26ca24a95b02648dfcf06b85",
  "555674b8bd84ecb3a552032e7688143307079f2c2c9ee9dd093e4d07d4527b0b",
  "23a7040b9866b855421524788166f1b8b9dc00883ecdddc53131ddf229a410d7",
  "71dc8cd4613a7558b093def534472b827ef1662f1fa744a6d7f5660132720038",
  "5fa0c88f9ecc2fef5f5cb4622f2c05f7d2f8e83ba1b659776e807923fd769d57",
  "57cada26020fb5e843b4f5e80250654954f52a9dc1dd428614514233e2b5f744",
  "5974b9a1a101fcd14ea5fdcb6ed0aa92fdc24216de62935bb4b0b85c1ab0931d",
  "2b518c9156501d18fda1f6a281584895d6511e8b222249e4c48777d065d589b3",
  "6e52f5df16361a61ef27c2bfcc5ff08131105b750faada72b92bb3cf83945565",
  "46cfd600653e0114829dac2b370aebc2e211ad18fdd40e380af76b943c30383e",
  "7d8b96bee1c68e386348869831ffd4f5cab91b5512685cf43fe023383c6ff75c",
  "3b3dd6a9958f0fae848244e0f5466f4d233b6381e1b2219b3fcb72576f5b6329",
  "4dc286e0ba0d3e1ffcee52401ed75d40e89d2fa9db15f5bf07a72cdddc1f4a89",
  "195efed48290a3c3ba3e0cf3c6e7ade5f6b8b5df297dd2fdaad373741235a490",
  "17511b90cfd25ef516add4df99ea12f0277617b9ed79d76ec98412c65da9e37a",
  "410d6061c91720d220e6e725574bc1158994dec723b17808bebc5d2045e68f18",
  "2d264eedfa8a3a0bf9bdd1fa78d665ec612f1332a092c95fb82d1b323a70f53e",
  "6c473321d6548e4ec08866638e382c909226760ba66ce800750e5c2e92b375cf",
  "46ea16d7c57f11c366ac3edbcb4be972451ac3c0ec1f118d076dfa787ba13cb6",
  "67eee13d5e99b6f4cd0fac984e677bcb6faf7f7d50238318861ed7e8c612dd74",
  "2b15a5ad654a01331a1fa19504c3d64f1f20d5962bc338991c54094be7b5b0be",
  "3feb1e8ae96b15d76ea58775a458c2055281883734df510bb833ff5db2b42ef4",
  "4731765c748219c7724a721d09c74f352615fbe81e07eb61ffda57b57a3bbf84",
  "2164d5c605cb9addee74a35c350a70065cf52fd402a9e4122585259f642da33c",
  "1f1547b185d47a37399ab1004448e5f4e78af74e6f1f41f01abb39a7fbb0aa5d",
  "7dd41f633273c6c2dd1392ac0f5504262bf03dbd63e2a71a61df97269018e82c",
  "075f9d22e8c056e720cd009cf9bf23e3c7b0949a0f7ab9bc3089e2473fc66b0a",
  "158c76142d690464c65fbcaab87782bd98630b83b03e3137057bf80a7f566bae",
  "1e86f629037ff33a9c0d218732faa765f7c6c431ebe2e2aa11d835f43673d83a",
  "3b941ae4dc7a31c8bbec7e34715b02eacc63673f44774d683a36f3f9073939e2",
  "2fe0f89b4d276f8df8e934305b90f2615de39fc3bab5b522c8500c9b2061ae5d",
  "0922bfc3e3d1ecc5b59d61e0fd83b4cd947ddddb60a814d3d39362240365f20f",
  "2f03a14283c9061e9276ecd8391f42cc2b9fc86a88cccbb353fe9cbcbdfc154a",
  "276b72859b166f258a9ca1c1a2f1ab1762c1c470682b7379abedc551bd3d5869",
  "43945b947099b158ca759816e56c671cde4d2140a4908029f9131884f5427e16",
  "3c8cdaa92646ef79590292bc1932e34923d02e5aa7458a7d7f4823c44a37334e",
  "209ead1e0cc914dfd5c66e093ad8592b350f754e99ed13a50cf67d910baeb935",
  "3a8f560d16ba0fa6fb38d2a1369d9149586f34ac46e988f74d23757b78c58a56",
  "36cbcbe1e06b8de7e7af7f94c304ca21e104da16cb655573ef5480a8768d3eb2",
  "79729bc253ede2d86fe40dd6f61c2fe231d37c665f370eb4bbd1648e87ce944a",
  "739d5e8ea593e10cb1725395ba4abbf56943e334d59391591170b3959a98b6d0",
  "4e6c86db3e1978ba6c5b26754d6f8bbd79f8027b3d2a341939d1a86de420ca93",
  "415ec03a2bf6821f3a78af90981db11c39338d06d768c7cc06a66eaa9534d1bf",
  "454ac2edc8ccfc93fb5e96a2305540bd7a94d304eb9ae4ddb3ef01566b299b44",
  "33a54633329283b05539a694a7088a33512e2f0834f1f2414e4479f452bb913d",
  "0754164a8f2c5fb17471621fa150d055685210721db6c7223367ebb52ee92852",
  "4da647d219ed631c834c5f1b406e88b8e226508e7bfd8a493495e5e498b88d94",
  "2b4d7e41bb81e898b3b7aeba3176b4f3d7929243462bd9257d825514b13de818",
  "4f959fbc0699e29622c75ed0918c9b85e90f55491715772f850648afa95aba5b",
  "686a7cdcd448c339ec7a5a655a43eb4008b291d053978cfbd656f8c06b2b3b52",
  "092651e340fe28a98ed52a26799f9b253cd2f3482cff564bd0061502a2d158ab",
  "2a30b708c31f82316832fdd1cc35131dedfc223e3820267cc467e3d5d81f1d58",
  "53aa988d6023c5746482e0c94c64e8c6528ac5bc74d141f725ee6e7eaf003c7b",
  "245471d211fdd893f8f69e577f2f5857e0468cda05755451b01ecc81e7a27764",
  "560c3043b1a65e61db3a24bd82024f3e9e1b6027ea6546ac3fdfe04d0775ef88",
  "05e7bd1e6f562012e44ccf59dd62aa68fdf66e43a9f1f563a123d124d81fecbb",
  "4c40c46f0812e9cff233669de512c0b5e46b0d6a30e17b83f4a3fe0e15c82cd9",
  "4b541226c68e72528de938b6aad3bbab14b34c9e211fa5c2e4a8aa1c41474b30",
  "7ff7f595032d05e81d837d09f46f55d2378360fbd969fdee2a8dd2ffa18efac5",
  "0dee91f87fa9d15f2fa3934effef07c89fc46b7dee123df850af69d1cb6c5450",
  "2bd5aae9a969fda6231406005e3c0eb96a30e3f47382b90e9e66de0da7b155f4",
  "7011ceccf7173d29a1142a254045c2ef0bedc0f3b1ae29c7abe938ca2256e5a1",
  "7a970459007b747cd24df50eeb0f09809ce8e116aeaca963d2968af0941b6dc7",
  "1fd319db5a713c63bef4d685c2bae86a03172be10f02d8621ffc97801c31abd3",
  "22258b441a6b1b647365d52cda03a7442bc2f8fa5d6145c521e72ecb4efc06c6",
  "5910ebb22a80d74c2af134749a8a2a64c62ca2e438e8a645ebd0be8a55ee86f6",
  "7b0ea1d600deb87e1ef85ed8ac889c5bbb995b142663c6f57d168e2b2ffbcadd",
  "5b8f7a57bb824362c985e5e60dcef81832175ec6ba268311a430b5a0df163a58",
  "5c9d8290094fb7752594c131fbb03389ff0034fc41740589ff540e3bbec1f26b",
  "0ca2f5b5771c4162b87e594d80e7015b0808ced74d6e71f3bb2bd470b6f974f6",
  "328eb8e01da6c16724d5050bf75a282279ebd1ca0c56309a641b54ac37711ab1",
  "3889e90189f97bfcb32c8cce1f998abb53235361d82dd319f5f9bcfb752d95a1",
  "1363c8f2a6f1749e6ab344c4b2b313b2f61630fa0347d7d6ae22f628cacb78ac",
  "0d8e2038a012b4634b2db04d3222e76bae41a5afa75bd82f54b28658881249b7"
]

# blockchainの状態を確認
$ bitcoin-cli getblockchaininfo
{
  "chain": "regtest",
  "blocks": 101,
  "headers": 101,
  "bestblockhash": "0d8e2038a012b4634b2db04d3222e76bae41a5afa75bd82f54b28658881249b7",
  "difficulty": 4.656542373906925e-10,
  "mediantime": 1638417486,
  "verificationprogress": 1,
  "initialblockdownload": false,
  "chainwork": "00000000000000000000000000000000000000000000000000000000000000cc",
  "size_on_disk": 30476,
  "pruned": false,
  "softforks": {
    "bip34": {
      "type": "buried",
      "active": false,
      "height": 500
    },
    "bip66": {
      "type": "buried",
      "active": false,
      "height": 1251
    },
    "bip65": {
      "type": "buried",
      "active": false,
      "height": 1351
    },
    "csv": {
      "type": "buried",
      "active": false,
      "height": 432
    },
    "segwit": {
      "type": "buried",
      "active": true,
      "height": 0
    },
    "testdummy": {
      "type": "bip9",
      "bip9": {
        "status": "defined",
        "start_time": 0,
        "timeout": 9223372036854775807,
        "since": 0,
        "min_activation_height": 0
      },
      "active": false
    },
    "taproot": {
      "type": "bip9",
      "bip9": {
        "status": "active",
        "start_time": -1,
        "timeout": 9223372036854775807,
        "since": 0,
        "min_activation_height": 0
      },
      "height": 0,
      "active": true
    }
  },
  "warnings": ""
}

# walletの中身を確認
$ bitcoin-cli listaddressgroupings
[
  [
    [
      "bcrt1qp3kdafp9tll9622ettknmw9kp3nvpx4h2upv0h",
      50.00000000,
      "system"
    ]
  ]
]

# 事前に生成しておいたアドレスに送金(bitcoind -fallbackfee=0.0002 のようにfallbackfeeを指定しないとエラーになる場合がある)
$ bitcoin-cli sendtoaddress 2N62m4SvgHHTFm5Bo34exQusmSNGgw7VpAD 1.0
376405b82fba8966261fc4747333ebd95dc93e1d41e4d3388cf5012b7d49c76a

# 送金をチェック
$ bitcoin-cli listaddressgroupings
[
  [
    [
      "bcrt1qqxh6xetdt95dfsnta028v05tsdulmdqsrln70y",
      48.99997160
    ],
    [
      "bcrt1qp3kdafp9tll9622ettknmw9kp3nvpx4h2upv0h",
      0.00000000,
      "system"
    ]
  ]
]


# もう1block生成
$ bitcoin-cli generatetoaddress 1 bcrt1qx25sk4wgdrcraph5g533en7x2zc7kexlrskhe7
[
  "755f89e6fbc8a6fd94ae99e146f20e486bbb909d7c4411a150cea73065356f28"
]

# block生成をチェック
$ bitcoin-cli listaddressgroupings
[
  [
    [
      "bcrt1qqxh6xetdt95dfsnta028v05tsdulmdqsrln70y",
      48.99997160
    ],
    [
      "bcrt1qp3kdafp9tll9622ettknmw9kp3nvpx4h2upv0h",
      50.00000000,
      "system"
    ]
  ]
]

# 送信時のブロックを確認
$ bitcoin-cli getblock 755f89e6fbc8a6fd94ae99e146f20e486bbb909d7c4411a150cea73065356f28
{
  "hash": "755f89e6fbc8a6fd94ae99e146f20e486bbb909d7c4411a150cea73065356f28",
  "confirmations": 1,
  "height": 102,
  "version": 536870912,
  "versionHex": "20000000",
  "merkleroot": "3f2cc3b61a7ddcd03503ba1c97ca8ad6fcd4a2512ff09abdcc925e4d6cd901aa",
  "time": 1638417620,
  "mediantime": 1638417486,
  "nonce": 0,
  "bits": "207fffff",
  "difficulty": 4.656542373906925e-10,
  "chainwork": "00000000000000000000000000000000000000000000000000000000000000ce",
  "nTx": 2,
  "previousblockhash": "0d8e2038a012b4634b2db04d3222e76bae41a5afa75bd82f54b28658881249b7",
  "strippedsize": 328,
  "size": 473,
  "weight": 1457,
  "tx": [
    "8980c9565b531f7b080e2390a5fafbacf058693837e7d8bddac7f65510bc297b",
    "376405b82fba8966261fc4747333ebd95dc93e1d41e4d3388cf5012b7d49c76a"
  ]
}


# transactionの確認
$ bitcoin-cli gettransaction 376405b82fba8966261fc4747333ebd95dc93e1d41e4d3388cf5012b7d49c76a
{
  "amount": -1.00000000,
  "fee": -0.00002840,
  "confirmations": 1,
  "blockhash": "755f89e6fbc8a6fd94ae99e146f20e486bbb909d7c4411a150cea73065356f28",
  "blockheight": 102,
  "blockindex": 1,
  "blocktime": 1638417620,
  "txid": "376405b82fba8966261fc4747333ebd95dc93e1d41e4d3388cf5012b7d49c76a",
  "walletconflicts": [
  ],
  "time": 1638417571,
  "timereceived": 1638417571,
  "bip125-replaceable": "no",
  "details": [
    {
      "address": "2N62m4SvgHHTFm5Bo34exQusmSNGgw7VpAD",
      "category": "send",
      "amount": -1.00000000,
      "vout": 1,
      "fee": -0.00002840,
      "abandoned": false
    }
  ],
  "hex": "02000000000101cd3a73c0bf2181c32214741f9bf181fa9652d243b23136e339e8834581ffa5060000000000feffffff02e80510240100000016001401afa3656d5968d4c26bebd4763e8b8379fdb41000e1f5050000000017a9148c3e2a44ada5ffc7ac8505a55d35dc19264837998702473044022033d6bf63032b4275963648be41d612c5eaf815a8a4a3fd6ae6100680a7f3093002201866495c486b4307b5c528f5aac9aecab67c63da59a6cc244ce34b80e004f2f8012103c3f88026de903c7d4eaf922d085d38d07807f0874e3f4cdd7546ffda48cf09e765000000"
}

このような流れで一通り確認ができました。