2020/07/09

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

bitcoin

概要

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

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

実施事項

bitcoindの起動

  • 0.20.0 のバージョンをDockerを使って起動します。
  • bitcoind -fallbackfee=0.0002 で起動します。
  • bitcoin.conf は以下のようなものを含んでいます。
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のノードにログインして、以下を実行します。

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

# 101block生成
bitcoin-cli generatetoaddress 101 bcrt1qx25sk4wgdrcraph5g533en7x2zc7kexlrskhe7
[
  "025adb4bc0c2604dac938466c19c9ab21005f943420122e8be1ab1172ecc0a10",
  "06b46eab97a9204a31c369993ccf434cc480a3d9f56374b8f556c5ec6f706634",
  "10bab83b211b9b8fc952be3956fd014f2890eef1ad45e425fea7cfd59602549b",
  "7fa32bf41aa8ca9a6ef3594cf4cf6b0ece5d1b0f95a4a36daf5b87f460a0d843",
  "46b0f8984eb18923048ac9c2ef33da6b55c0135bfbe7c8268a9d4b48b5d04db6",
  "0dda84c9c3cf772df55d67092c52d697e7040ffc125f862def8835c5bfa979c7",
  "09c89a9b32f0b24cf20e3e0b380b9cdccd1e4fd66b402647f9c2024c2679e135",
  "66c0610df4bbe56490924e7c3d195d141b72570616874cba3e0627885907fcd9",
  "0fc0e80d97941601b87a79283bb4f260995949270b04c9f8a45f64664a9257d2",
  "5585c6c601083c4997f92d803ade1581df34ee4e8626874fc279ac6d72f8ae50",
  "3088eca754ded1ed8ae0d32e423249cc2790b45fe7157228d3dedd1e0e2c3b56",
  "1eb2ca4e90c5109d612932d001ce0483700754f2c792ab8744e649c754095a10",
  "55b4a10b15d078f312cd8cd2b632892afd29b531b00b46b81fe3aeb0b11adcc9",
  "4a55296b93d84e743e211a2690e3a1ab7ffceb7f3210d6b86285cbd57a0dc3fd",
  "6573dd3abf81fdadc550e74b5e3dcd9cb7bea197d775c0f7abc158dac0a8521c",
  "58ef089dfd8729d99f5a122df03200584974be2cb928e5daad0f881c6fe4eadc",
  "5aa40964a2810f02c762ce31e36b31ec01ac3cd3cc4fe2c5c7883c4511df75e9",
  "0c401d34a2187c61f2c27cf4eed8e54c6eedc462c8fc7209b198e95f1c4a42a3",
  "33d386f701325d6f0bb22814af7354c8362851a7892e4c28c34f8d98aaf2e3fc",
  "770953be8edd8236b0128e63ccdc904debbea65ddb7b3ad751df43979d6fc4a9",
  "261d37d307d0d14bb83b296c689c274ed23d4892fc22853b4c49e3712a41da0c",
  "2f85fad2cb110392e910b80c59a519d17f010824979011c5657aaa48e883fa15",
  "4429d891387656963fc9d5a12dcacbc14d9cfbce102c0ea9a0091c84fdfa5a77",
  "5e89f785ced856e2265c34b832a4adaaf481a883203f31c9485627df332d9dae",
  "330a663ad49ead0ced11a30a36c9ac6c00c0f11308d66028cf7c48e06ec8c449",
  "3b2ff80764cd3fd0b93f6e30c762fc2bcdb59cb1c68281f219978e4bbb44a899",
  "4885ed1b9adb7c59b13216b96c0d2e3440a280259462e74499fd4df749062f60",
  "74342f7a8a8004f39ef02851972e79c1df490d8f6fa9184f75b0b7a57aaf7463",
  "4b4b10f12388ba538c2cc5d6f1153b4c1dc18b9f0ecd911282abf7d7ec4752aa",
  "37bce17b807b0cbcbd658ba3c79a8cb19dff8da85a8ba9a9af181d279aa2f81a",
  "680cbeae901cc363fda0ffa43924c8d61479e192d1c8e3f8c0ce2c8350807c01",
  "5b60de92938ba913f89f51b2cf8c5623dd6d2c2acb1fb74358164b13b0a3567c",
  "0c94d669b43e76d0fc5d30eecbaef0f119dd8c681eef09149b0c9c8bbbec5822",
  "6fc3edb995d4e9a92beb192b7954be2772d393e1049f2fe279370ed788883595",
  "6fe05bc38a8fb85991197b87a0251d81a8ee01dca3d166de095643c4e8e9e26e",
  "6ab38e4156f4dadb7d9bdf7623096b353a46721ae80d291d90373a94bacf75fd",
  "723f13f09754877ba6fe19d13136c4b559e311d5d2405010d09003a4f1f9aed4",
  "7741a7a3db341685c98eb75e3a12a5ccd10a28db895939f9aa0e908a13c663ed",
  "42c00dd686bbdb2c2ada4946e7edb45b014a5df0095b79455f543a768ea5c9d0",
  "1b854e36df01eb0f216107200c9b7427df2af4dd4dc44623ae4dc20638eae339",
  "428efd78893e8ee980ec6b2e135d1415dfb30a600eb03c438c138f736b9b6ce1",
  "17f26ef0433b761c0ffa73767b166b18a46076071916ac89a06def4abb27b97d",
  "439812399b613357e685d0b64abd8b91147b49cdf231dc51e0a49f393e857262",
  "7154aee3dac90f815380e93cb078d096fae602563f2e8fd223d12b5cc8e3c823",
  "51b13fd67a4f861c7428b9da239aa6ae6e8f2c10765bb5e300cee97756cbd553",
  "6c5378573110ea4f56c7c7be47d3105e958e925a8c78cfe2a7d284746cbe03ba",
  "03309adb47a78969c9bf6208d986207e8c2ccec65cbb9ecd26d2716cb419a638",
  "7a02799e843a974ed3072bd1baae6db2b4f8da238c445e0a6075f01d436ac0bf",
  "509ff44d61e909c7e74c61d0c7fa8606de365a607b9097550ab465a5e0c1e3fa",
  "4ef143eef365276f307416aee91c614ab52abddc7ce8bab416182956c4f87e9c",
  "7c1633cb7a2cde8790a74e161beb924e6e7629bfda560f87a87a2d6b3be63fc1",
  "6d47ba314a0f3e2fca647efed9edf0bb72a30e650bb07507e07e063edfd5c4f4",
  "4e075cf48b39a97fdf844d7f6cb841588f37d9e8deff494e75c49c19ee2d1639",
  "34b03e8616f24bae70a2753044a405518f89fc6426ba5fabba45edd39c23b185",
  "715b9148c69b99d734edf09b7cb3913b8c71caff001d711f72ff6d9d89bc15e5",
  "792522527c1c9caa604c584e47945769adbab052912cfe9768d05146e06ce4fb",
  "591f55f96f01aa44adf1808af25ea29789936f28137e16907aec55caee7b9b6b",
  "5d406773cc6834c9f7d17f475a763a3fb18f979718ea1c0d5cda45dfd53d0fc4",
  "702bfaddab0e798686542e39880eb6226e6408611e071a28572d6e344b036066",
  "49a9ba8e708e156e030d46dc1e90a74be963aa08f6e211f7259c2c2e6fb88cb1",
  "3b0ab2a9805a201766ccb24fcf3b43ed00acd4e62ba8cf49ba94085064fb7410",
  "44e67b03d2fc44dd4082082ea727467eac9e1c9a83c2d8dc8380183df14f6388",
  "53436b155aa5100caa1ed10de9beb5f8705e3c9708faec4ba3bc1bb433bfe81b",
  "4170f7df8b5b139449eb68b505672ca0fff063e7f071fec457fb46a719e7a5fc",
  "0be82aa2dc697db34c6993f5258421cbe3390e0bfb08ca057ff8d50735ffa3eb",
  "657195fbe9b1e3c472b9ed105889ac92c331475ca2a031436fc8096df4b5de5c",
  "2202a44d1752ddcaca9711e840a4959351999218176ac6c5b65886bf484db6e1",
  "74c21de5e3ba73f50903cbb0620f909c39b051d0c5639cf43be9e736b2d0e215",
  "3692ee813158ada6386e8ff6b565b238e9e8fcff6454d2dd5f14fc9499bd211b",
  "5bc2737c0056ce97646a14956341c2364e7b5635e9d5d416cb41051723d12214",
  "7ef6ff333e316d4450fbbfa6efe113be051f306220ae2b1f46e506f97627c002",
  "1343268470df4b6162871b2917be9154e39a851b1bda8a361c1c198f88bf4ef1",
  "391a5af204b4d23744c4ab5fd8ab529a7d2e423ee4e935595039471fbc69f64c",
  "7a985525197681e736edbacadfd18559ab3f2fd2c081f23a71abec47f69c2b10",
  "67a78a66baa5e402509962cc381ea320fab1469e47326c258bb0bd76f62878d8",
  "2280561cf1ca2c5a319c8520d9ea2d1d385878ad25f69f904cb0e14a7f048b54",
  "05246dfb3cb9746fc20b973c3e1704b70936c600b8c31033ea0c3f40d419271e",
  "4551f71e28ff24956eab00d502eeb185ba8abf9b7a591c6c9e1195b2337d2f65",
  "1ccca3ea6f82ff86c2457729f39d92c65620703f7fec063c75bdbbbbaa4c5419",
  "2da6eb9e5d3b8920b1c8572d0a9e94a7f2ae1923c6ca83ca0ebab98f6a34aa8b",
  "0560441349b6493026dec8b30ebd6329370d0e1b2b06031c2c4ec5ceb641af13",
  "0e5cfbac03ec8493553111a9709243788213682e1bccc0ae5dc7758979d8c389",
  "71b6f27683e45912e5ef5ab72313b8b4a6c5b36ec49407121e57fba785a7a97b",
  "25811d3e50a022a49282fcd2da42d1e5802840fd3963a05fafb7806c158d24b2",
  "789fa97a83e0a982d20722e5dd4dd4e20cc85d7efd817e8201696b61ffe66198",
  "510516c7cc1237773aec71f75559d0eab0b5034bc6a67aa40b0a3f454fd5b158",
  "24241157d3ad82d708152e8233ea81b62a3affc15b62fbf7a78160bb3af11873",
  "67a0f8d905ad0cd72b9f2258087dc4411cebccad60068a7870b8722dfcfd5501",
  "036eb99f812b6ec554da01ffa943cc40d6c200cb00022d692f363ca4349586eb",
  "60a35f8494e20071044cad532349e26a8c3a4aafaf907535c3d8098991f2db63",
  "39d55b9f6c9c4bc30e32db26b87e419a39c7ae26f65c3dde4537d9ddd1d15c96",
  "2005ccc988d34b7569c2777848c68ba9414aa60fc2366f35a265873ee90eaddb",
  "460adec41e0a7235ca377f42265b690f19fad155c006ad3d18c44697a9e286b8",
  "296494d2dc7be54fe031af646677db83da5c9c8bc1c1459f879842879a24c8b4",
  "7c874e47f975588bc0bcd06c36ac74a3a27dafdaefd21a4c9aa647e5a4ad158e",
  "00256da5fb1dc86010a69333ec32f89111e8107443adf9924a6864e55a26ffbe",
  "2443946abc1a7a6853eb2dbc0cb2008188ca5087d7c7eb0950736b49c25dcb9a",
  "745eefea5febbceb9b9fec50c6c276e7b6820a1afa53f876f44afd6418aeda93",
  "455d1614a26ede316c019aa0b963a49950edc521fedf7360fe8ccac1e3ff440c",
  "13c55b4a9befb46edeeaeb592d11647fa08c465af1c581c907e8b19af2e6e08a",
  "33ac56d611342e4c982df4e5455e56050000f7eb75fda928ccc39a5563a671af"
]

# blockchainの状態を確認
bitcoin-cli getblockchaininfo
{
  "chain": "regtest",
  "blocks": 101,
  "headers": 101,
  "bestblockhash": "33ac56d611342e4c982df4e5455e56050000f7eb75fda928ccc39a5563a671af",
  "difficulty": 4.656542373906925e-10,
  "mediantime": 1594274908,
  "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
      },
      "active": false
    }
  },
  "warnings": ""
}

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

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

# 送金をチェック
bitcoin-cli listaddressgroupings
[
  [
    [
      "2N62m4SvgHHTFm5Bo34exQusmSNGgw7VpAD",
      1.00000000,
      "wallet-system"
    ]
  ],
  [
    [
      "bcrt1qx25sk4wgdrcraph5g533en7x2zc7kexlrskhe7",
      0.00000000,
      "system"
    ],
    [
      "bcrt1qngg0l4hhr4t2hdtwustm5u3lvzfkzafjdhszd5",
      48.99997160
    ]
  ]
]

# もう1block生成
bitcoin-cli generatetoaddress 1 bcrt1qx25sk4wgdrcraph5g533en7x2zc7kexlrskhe7
[
  "4d94148a7a2e0ad75538fa824038f60b8fa6e50ef192e594d1c77e1cd8799ec6"
]

# block生成をチェック
bitcoin-cli listaddressgroupings
[
  [
    [
      "2N62m4SvgHHTFm5Bo34exQusmSNGgw7VpAD",
      1.00000000,
      "wallet-system"
    ]
  ],
  [
    [
      "bcrt1qx25sk4wgdrcraph5g533en7x2zc7kexlrskhe7",
      50.00000000,
      "system"
    ],
    [
      "bcrt1qngg0l4hhr4t2hdtwustm5u3lvzfkzafjdhszd5",
      48.99997160
    ]
  ]
]

bitcoin-cli getblock 4d94148a7a2e0ad75538fa824038f60b8fa6e50ef192e594d1c77e1cd8799ec6
{
  "hash": "4d94148a7a2e0ad75538fa824038f60b8fa6e50ef192e594d1c77e1cd8799ec6",
  "confirmations": 1,
  "strippedsize": 328,
  "size": 473,
  "weight": 1457,
  "height": 102,
  "version": 536870912,
  "versionHex": "20000000",
  "merkleroot": "caf6fea14827433d156f30f4983d7cfd7c1d40f4592406cac57a5b0be24ce042",
  "tx": [
    "6b14ad52e593362b12377f3439b50c427d1ac65e87b96fe14ba556c44ee33e49",
    "910fe4cbfc6ce215e11fd4075083d5326e94252fc215531b41b0ea2aa348ebb4"
  ],
  "time": 1594275663,
  "mediantime": 1594274908,
  "nonce": 2,
  "bits": "207fffff",
  "difficulty": 4.656542373906925e-10,
  "chainwork": "00000000000000000000000000000000000000000000000000000000000000ce",
  "nTx": 2,
  "previousblockhash": "33ac56d611342e4c982df4e5455e56050000f7eb75fda928ccc39a5563a671af"
}

# transactionの確認
bitcoin-cli gettransaction 910fe4cbfc6ce215e11fd4075083d5326e94252fc215531b41b0ea2aa348ebb4
{
  "amount": 0.00000000,
  "fee": -0.00002840,
  "confirmations": 1,
  "blockhash": "4d94148a7a2e0ad75538fa824038f60b8fa6e50ef192e594d1c77e1cd8799ec6",
  "blockheight": 102,
  "blockindex": 1,
  "blocktime": 1594275663,
  "txid": "910fe4cbfc6ce215e11fd4075083d5326e94252fc215531b41b0ea2aa348ebb4",
  "walletconflicts": [
  ],
  "time": 1594275501,
  "timereceived": 1594275501,
  "bip125-replaceable": "no",
  "details": [
    {
      "address": "2N62m4SvgHHTFm5Bo34exQusmSNGgw7VpAD",
      "category": "send",
      "amount": -1.00000000,
      "label": "wallet-system",
      "vout": 0,
      "fee": -0.00002840,
      "abandoned": false
    },
    {
      "address": "2N62m4SvgHHTFm5Bo34exQusmSNGgw7VpAD",
      "category": "receive",
      "amount": 1.00000000,
      "label": "wallet-system",
      "vout": 0
    }
  ],
  "hex": "0200000000010152c1c63b39c905d9b81a934e8618972770ddd120b75c046d9a88c3d8003449540000000000feffffff0200e1f5050000000017a9148c3e2a44ada5ffc7ac8505a55d35dc192648379987e8051024010000001600149a10ffd6f71d56abb56ee417ba723f609361753202473044022024bc95946bdce6d9959e145866393f4846540c9ad199eb52f99fc366d26ec496022037d71dbdb665d484875b305fb84897fcf24a2ee12bfc679aabce6aa3f0aea86d012103daaf558ade9ab9916b51e1edad367a303b69465907429bbda92d7e3d11fddfae65000000"
}

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