Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hyperledger Fabric ハンズオン手順

Hyperledger Fabric ハンズオン手順

本資料は5月29日、6月12日、7月3日のIBM Developer Dojo用の資料です。

Taiji HAGINO

June 12, 2019
Tweet

More Decks by Taiji HAGINO

Other Decks in Technology

Transcript

  1. 2019/06/19 10(21 1 / 14 ϖʔδ about:blank 1.IBPͷωοτϫʔΫىಈ IBM CloudͷΧλϩά͔ΒBlockchain

    Platform v2.0Λબ୒ https:/ /cloud.ibm.com/catalog Standard PlanΛબ୒ͯ͠࡞੒ΛΫϦοΫ →IBPͷ࡞੒ϖʔδʹҠಈ͢Δɻ σϓϩΠϝϞ
  2. 2019/06/19 10(21 2 / 14 ϖʔδ about:blank DallasͷσʔληϯλʔͰIKSͷΫϥελʔΛ࡞੒͢Δඞཁ͕͋Δɻ طʹߏஙࡁΈͷΫϥελʔ΋ར༻Մೳɻ ͨͩ͠ɺKubernetesͷόʔδϣϯ͸v1.11Ҏ্ਪ঑ɻ

    IKSͷFreeϓϥϯΛબ୒͢Ε͹30೔ؒແྉͰར༻͢Δ͜ͱ͕Ͱ͖Δɻ IKSͷΫϥελʔબ୒ͷϓϧμ΢ϯͷ෦෼Ͱϒϥ΢βʹΑͬͯΫϥελ͕දࣔ͞Εͳ͍Մೳੑ͕͋ Δɻ ϒϥ΢βΛ࠷৽όʔδϣϯʹΞοϓσʔτ͢Δ͔ɺଞͷϒϥ΢βΛར༻͢Δ͔Ͱରॲ͢Δɻ IKSͰClusterΛ͍࣋ͬͯͳ͍৔߹͸create a new clusterΛΫϦοΫɻ IKSͷΫϥελ࡞੒ϖʔδͷλϒ͕৽͘͠։͘ɻ ແྉϓϥϯΛબ୒͠ɺϩέʔγϣϯ͕μϥεʹͳ͍ͬͯΔ͜ͱΛ֬ೝͷ্ɺ࡞੒ΛΫϦοΫɻ Ϋϥελ͕࡞੒͞ΕΔ·Ͱ໿30෼ɻ
  3. 2019/06/19 10(21 3 / 14 ϖʔδ about:blank Ϋϥελͷߏங͕׬ྃ͢ΔͱworkkerϊʔυͷKuberntesͷόʔδϣϯ͕දࣔ͞ΕΔɻ όʔδϣϯ͕1.11Ҏ্Ͱͳ͍ͱBlockchainͷϊʔυཱ͕ͯΒΕͨʹͨΊɺόʔδϣϯͷߋ৽͕ඞ ཁɻ

    ·ͣԼਤʹै͍ɺΫϥελͷόʔδϣϯͷߋ৽Λߦ͏ɻΞφ΢ϯεʹै͍ɺ1࣌ؒޙɺworkerϊʔ υͷϝχϡʔ͔Βόʔδϣϯߋ৽Λߦ͏ͱworkerϊʔυͷόʔδϣϯ΋1.11Ҏ্ʹΞοϓσʔτ ͢Δ͜ͱ͕Ͱ͖ΔɻσϑΥϧτͷىಈόʔδϣϯ͸2/25ݱࡏv1.11ͷͨΊɺόʔδϣϯΞοϓ͸ ෆཁɻ ΫϥελΛબ୒͠ɺDeploy to clusterΛΫϦοΫɻ ͦͷޙɺLaunch the IBM Blockchain PlatformΛΫϦοΫ
  4. 2019/06/19 10(21 4 / 14 ϖʔδ about:blank IBPͷ؅ཧίϯιʔϧը໘ 2.ϊʔυ࡞੒ ࢀߟ৘ใʢӳޠ൛ͷΈʣ

    https:/ /cloud.ibm.com/docs/services/blockchain/howto?topic=blockchain-ibp-console-build- network&locale=en#ibp-console-build-network (1)CAϊʔυͷ࡞੒ Blockchain ωοτϫʔΫʹࢀՃ͢Δ૊৫ͷCAΛىಈ͠ɺCAΛ࢖ͬͯɺൿີ伴΍ূ໌ॻΛൃߦ͠ ͯɺ ଞͷϊʔυΛىಈ͍ͯ͘͠ɻ ؅ཧίϯιʔϧͷࠨϝχϡʔͷNodesΛબ୒ɻ Add Certificate AuthorityΛΫϦοΫɻ Create a new Certificate AuthorityΛબ୒ͯ͠ɺNextΛΫϦοΫɻ Display NameΛ"Org1 CA"ͱهೖɻ
  5. 2019/06/19 10(21 5 / 14 ϖʔδ about:blank Enrollment IdΛadminɺsecretΛadminpwͱͯ͠NextΛΫϦοΫɻ ࠷ޙʹsubmitΛԡ͢ͱCAϊʔυ͕࡞੒͞ΕΔɻ

    ಉ༷ͷཁྖͰOrderer༻ͷCA΋࡞੒͓ͯ͘͠ɻ (2)adminϢʔβͷ࡞੒ɻ (1)Ͱ࡞੒ͨ͠CAϊadminϢʔβΛ࡞੒͢Δɻ(1)Ͱ࡞੒ͨ͠σϑΥϧτϢʔβΛͦͷ··ར༻͢Δ ͷ͸ɺ ɹηΩϡϦςΟ؍఺ͰΑΖ͘͠ͳ͍ɻ (1)Ͱ࡞੒ͨ͠Org1 CAΛબ୒ɻ Register UserΛΫϦοΫɻ Enrollment ID͸"org1admin"Secret͸"org1adminpw"Ͱ࡞੒͢Δɻ ϢʔβλΠϓ͸ClientΛબ୒ɻAffiliation͸αϯϓϧͰ͸ར༻ͳ͍ͨΊɺબ୒ࢶ͔Β೚ҙͷ஋ΛҒ Ϳɻ Φϓγϣϯཝ͸هೖͷ··SubmitΛΫϦοΫ͢ΔͱϢʔβ͕࡞੒͞ΕΔɻ ಉ༷ʹPeerߏங༻ͷϢʔβΛ࡞੒͢Δɻ Enrollment ID͸"peer1"Secret͸peer1pwͰϢʔβλΠϓ͸peerΛબ୒͢Δɻ Orderer΋ಉ༷ʹordereradminͱorderer1Ϣʔβͷ2ͭΛ࡞੒͢Δɻ (2)૊৫(MSP)ͷ࡞੒ɻ IBPͷ؅ཧίϯιʔϧͷOrganizationsλϒΛબ୒͢Δɻ Create MSP definitionΛબ୒͢Δɻ Display NameΛOrg1 MSPɺMSPIDΛorg1mspͰηοτ͢Δɻ
  6. 2019/06/19 10(21 6 / 14 ϖʔδ about:blank CAͷબ୒ཝͰ͸ઌ΄Ͳ࡞੒ͨ͠Org1 CAΛબ୒͢Δɻ Enrollment

    IDͱSecret͸org1adminͱorg1adminpwʹมߋ͠ɺGenerateϘλϯΛԡ͢ɻ IBPͷ؅ཧίϯιʔϧͷwalletଟ෼Ͱ࡞੒ͨ͠ϢʔβΛ֬ೝ͢Δ͜ͱ͕Ͱ͖Δɻ ൿີ伴ͱূ໌ॻ͸ΤΫεϙʔτͯ͠VSCodeͱͷ઀ଓʹ΋ར༻͢Δɻ ͜ͷwallet͸ϒϥ΢βͷϩʔΧϧετϨʔδ্ʹอଘ͞Ε͍ͯΔ͚ͩͰɺIKS্ʹอଘ͞Ε͍ͯͳ ͍ͨΊɺ Ϣʔβࣗ਎ͰΤΫεϙʔτͯ͠؅ཧ͢Δඞཁ͕͋Δɻ ϒϥ΢βͷཤྺΛ࡟আͨ͠ΓɺΩϟογϡΛ࡟আ͢Δͱwalletͷσʔλ͕ͳ͘ͳΓɺϊʔυʹΞ ΫηεͰ͖ͳ͘ͳͬͯ͠·͏ͷͰɺ࡞੒ͨ͠walletͷσʔλ͸ඞͣΤΫεϙʔτͯ͠όοΫΞοϓ Λऔಘ͓ͯ͘͠ඞཁ͕͋Δɻ ࠷ޙʹCreate MSPϘλϯΛԡ͢ɻ OrganizationsʹOrg1 MSP͕࡞੒͞ΕΔɻ ಉ༷ʹOrderer MSP΋࡞੒͓ͯ͘͠ɻ (4)PeerɺOrdererϊʔυͷ࡞੒ɻ IBPͷ؅ཧίϯιʔϧͷNodesλϒΛબ୒͠Add PeerΛબ୒͢Δɻ display Name͸Peer Org1ʹઃఆ͢Δɻ CA͸Org1 CAɺEnrollment IDͱSecret͸Peerͷ࡞੒༻ʹ࡞੒ͨ͠peer1ϢʔβΛࢦఆ͠NextΛબ ୒ɻ
  7. 2019/06/19 10(21 7 / 14 ϖʔδ about:blank TLSͷཝ͸Enrollment ID͸adminɺSecret͸adminpwΛબ୒͢ΔɻʢΦϓγϣϯػೳͷͨΊʣ ࠷ޙʹIdentityΛOrg1

    Adminʹͯ͠NextɺSubmitΛબ୒͢ΔɻPeer͕࡞੒͞ΕΔɻ ͜͜·ͰͰPeer1୆ɺOrderer1୆ɺCA͕2୆࡞੒Ͱ͖͍ͯΔ͜ͱΛNodesλϒͰ֬ೝ͢Δɻ (5)࡞੒ͨ͠૊৫ΛOrdererͷίϯιʔγΞϜϝϯόʔ΁௥Ճ͢Δɻ
  8. 2019/06/19 10(21 8 / 14 ϖʔδ about:blank IBPͷ؅ཧίϯιʔϧͷNodesλϒ͔Β࡞੒ͨ͠OrdererΛબ୒͢Δɻ Consortium MembersͷAdd

    OrganizationΛબ୒͢Δɻ Org1 MSPΛબ୒ͯ͠ɺSubmitΛΫϦοΫ͢Δɻ ࢀՃ༧ఆͷ૊৫ΛશͯConsortium Memberʹొ࿥ͯ͠ஔ͔ͳ͍ͱνϟωϧͷ࡞੒ͰΤϥʔ͕ൃੜ ͢Δɻ (6)νϟωϧͷ࡞੒ IBPͷίϯιʔϧͷࠨϝχϡʔը໘͔ΒChannelsΛબ୒͠ɺCreate channelΛબ୒͢Δɻ ҎԼͷΑ͏ʹ஋Λೖྗ͠ɺAddϘλϯΛԡ͢ɺOrg1MSPʹର͢Δݖݶͷઃఆཝ͕දࣔ͞ΕΔͷ Ͱɺ OperatorʹνΣοΫΛೖΕɺCreate ChannelϘλϯΛબ୒͢Δɻ
  9. 2019/06/19 10(21 10 / 14 ϖʔδ about:blank νϟωϧ͕࡞੒͞ΕΔ͕ɺ؅ཧը໘্ʹ͸·ͩදࣔ͞Εͳ͍ɻ ଓ͍ͯɺJoin channelϘλϯΛΫϦοΫ͢Δɻ

    OrdererΛબ୒͠ɺNext ઌ΄Ͳ࡞੒ͨ͠channel1Λهೖ͠ɺNextɺ ࠷ޙʹࢀՃͤ͞ΔPeerϊʔυΛબ୒͠ɺSubmitΛΫϦοΫ͢Δɻ νϟωϧ͕࡞੒͞ΕΔɻ 3.εϚʔτίϯτϥΫτσϓϩΠ IBPͷࠨϝχϡʔը໘͔ΒSmart contractλϒΛબ୒͠ɺInstall smart contractΛΫϦοΫɻ Πϯετʔϧ͢ΔνΣʔϯίʔυͷύοέʔδϑΝΠϧ(cds)ϑΝΠϧΛબ୒ͯ͠ɺΠϯετʔϧ ͢Δɻ ύοέʔδͷํ๏͸VSCodeΛར༻͢Δํ๏ͱɺpeerίϚϯυΛར༻͢Δํ๏ͷ2छྨ͕͋Δɻ VSCode͔Βύοέʔδͨ͠ϑΝΠϧ͸InstallͰ͖ͳ͍ 413 (Request Entity Too Large)͕javascriptίϯιʔϧͰฦͬͯདྷ͍ͯͨɻ ༰ྔ͕େ͖͔ͬͨͨΊɺࣦഊͨ͠ͱਪ࡯ ੒ޭͨ͠cdsϑΝΠϧ͸2KBɺࣦഊ͍ͯ͠ΔcdsϑΝΠϧ͸18.1MB →packaging͢Δࡍʹnode_module΋Ұॹʹpackage͞Ε͍ͯͨͨΊɺ༰ྔ͕ංେԽ͍ͯͨ͠ͱਪ ࡯ɻ ɹϓϩδΣΫτ಺ͷnode_moduleΛ࡟আͷ্ɺpackage͢Δͱ27KBʹݮΒ͢͜ͱ͕Ͱ͖ɺ ɹΠϯετʔϧ΋੒ޭͨ͠ɻ
  10. 2019/06/19 10(21 11 / 14 ϖʔδ about:blank νΣʔϯίʔυͷinstantiate IBPͷ؅ཧը໘ͷࠨϝχϡʔͷSmart contracts͔ΒΠϯετʔϧͨ͠εϚʔτίϯτϥΫτϦετ

    Λදࣔ͠ɺӈଆͷϝχϡʔ͔ΒInstantiateΛબ୒ɻ εϚʔτίϯτϥΫτΛσϓϩΠ͢ΔνϟωϧΛબ୒͠ɺEndorsement PolicyΛબ୒ͯ͠ɺ Instantiate͢Δࡍʹ࣮ߦ͢Δؔ਺໊ͱҾ਺Λೖྗͯ͠InstantiateΛΫϦοΫɻ Endorsement Policy͸γϯϓϧʹ૊৫Λબ୒͢ΔύλʔϯͱJSONϑΝΠϧͰࡉ͔͘ࢦఆ͢Δύλ ʔϯͷ2௨Γ͕͋Δɻ Instantiate͕׬ྃ͢ΔͱInstantiated smart contractͷϦετʹදࣔ͞ΕΔɻ 4.ωοτϫʔΫ΁ͷ઀ଓ IBPͷ؅ཧίϯιʔϧͷࠨϝχϡʔ͔ΒSmart contractsΛબ୒ɻ Instantiated smart contractsͷҰཡͷӈϝχϡʔ͔Βconnect with SDKΛબ୒͠ɺωοτϫʔΫͷ ConfigϑΝΠϧΛμ΢ϯϩʔυ͢Δɻ ϑϩϯτΞϓϦ͔ΒIBPͷωοτϫʔΫʹ઀ଓ͢Δͷʹඞཁͳ৘ใ͸ҎԼ4ͭ ɾConnection Profileʢ্هͰμ΢ϯϩʔυͨ͠configϑΝΠϧʣ ɾωοτϫʔΫʹࢀՃ͍ͯ͠Δ૊৫ͷCAͷadminϢʔβͱsecret(admin/adminpw) ɾ઀ଓ͢Δνϟωϧ໊ ɾ઀ଓ͢ΔνΣʔϯίʔυ໊ (1)ΞϓϦέʔγϣϯϢʔβͷ࡞੒
  11. 2019/06/19 10(21 12 / 14 ϖʔδ about:blank ɹτϥϯβΫγϣϯʹॺ໊͢ΔͨΊͷΞϓϦέʔγϣϯϢʔβΛ࡞੒͢Δɻ ɹɾConnection ProfileͷύεΛมߋ

    ɹɾCAͷURLΛϙʔτ෇Ͱࢦఆ ɹɾenrollment IDͱSecretɺOrg1ͷMSP IDΛهࡌɻ node enrollUser.jsͰϢʔβΛ࡞੒ɻ ผ్package.jsonΛ࡞੒ͯ͠ɺnpm install͢Δඞཁ͋Γɻ package.json͸fabcarͷαϯϓϧΛίϐʔͯ͠ར༻ɻ (2)τϥϯβΫγϣϯͷૹ৴ ɹ্ه4ͭͷ৘ใͱ(1)Ͱ࡞੒ͨ͠ϢʔβΛ࢖ͬͯɺτϥϯβΫγϣϯΛૹ৴͢Δɻ ɾconnection ProfileͷύεΛมߋ ɾνϟωϧ໊Λࢦఆ ɾνΣʔϯίʔυ໊Λࢦఆ node invoke.jsͰ࣮ߦ Channel not found....ͱ͍͏Τϥʔ͕ग़Δ͕ɺͦͷޙτϥϯβΫγϣϯ͸ਖ਼ৗʹૹ৴͞ΕΔͷͰ໰ ୊ͳ͠ɻ ʢdiscovery Serviceͷόάͱਪ࡯ʣ 5.VSCode(ධՁ൛)ͱͷ઀ଓ (1)network configϑΝΠϧͷμ΢ϯϩʔυɻ IBPͷ؅ཧը໘ͷsmart contractλϒΛબ୒ɻ Instantiated smart contractsͷҰཡ͔ΒσϓϩΠͨ͠εϚʔτίϯτϥΫτΛબ୒͠ɺӈͷϝχϡ ʔ͔Βconnect SDKΛΫϦοΫɻ
  12. 2019/06/19 10(21 13 / 14 ϖʔδ about:blank Download Connection ProfileΛΫϦοΫ͢ΔͱɺjsonܗࣜͰnetworkͷconfigϑΝΠϧ͕μ΢ϯϩ

    ʔυ͞ΕΔɻ (2)઀ଓ༻ͷൿີ伴ɺূ໌ॻͷ࡞੒ɻ IBPͷ؅ཧը໘ͷWalletλϒΛબ୒ɻ ࡞੒ͨ͠Identity(Org1Admin౳)Λબ୒͢Δɻ ը໘ӈଆʹূ໌ॻͱൿີ伴͕දࣔ͞ΕΔɻ VSCodeͰར༻͢Δʹ͸͜ΕΒͷσʔλΛPEMϑΥʔϚοτʹม׵͢Δඞཁ͕͋Δɻ ɹ ҎԼͷίϚϯυΛϩʔΧϧͰ࣮ߦ͢ΔͱPEMϑΝΠϧ͕ੜ੒Ͱ͖Δɻ #export FLAG=$(if [ "$(uname -s)" == "Linux" ]; then echo "-w 0"; else echo "-b 0"; fi) #echo <base64_string> | base64 --decode $FLAG > <key>.pem <base64_string>ʹ্ه؅ཧը໘ͷӈଆʹදࣔ͞ΕΔൿີ伴 or ূ໌ॻͷจࣈྻΛೖΕͯɺ <key>ʹ೚ҙͷϑΝΠϧ໊Λهࡌ͢Δɻ (3)VSCodeͱIBPͷωοτϫʔΫΛ઀ଓ͢Δɻ ͋Β͔͡ΊVSCodeʹIBM Blockchain PlatformͷΞυΦϯΛΠϯετʔϧ͓ͯ͘͠ɻ https:/ /marketplace.visualstudio.com/items?itemName=IBMBlockchain.ibm-blockchain- platform#overview VSCodeͷࠨϝχϡʔ͔ΒIBM Blockchain PlatformΛબ୒ɻ Blockchain Connectionsͷӈଆͷ+ϘλϯΛΫϦοΫɻ ઀ଓઌͷωοτϫʔΫ໊ʹ೚ҙͷωοτϫʔΫ໊Λબ୒͢Δɻ ࣍ʹ্هͰμ΢ϯϩʔυͨ͠networkͷconfigϑΝΠϧΛϑΝΠϧ͔Βબ୒͢Δɻ Create a new wallet for an identity with a certificate and private keyΛબ୒͠ɺwallet໊Λ
  13. 2019/06/19 10(21 14 / 14 ϖʔδ about:blank org1adminͱهࡌ͢ΔɻenrollIDͱಉ໊͡લʹࢦఆ͠ͳ͍ͱError͕ग़ྗ͞ΕΔɻ ࠷ޙʹ(2)Ͱ࡞੒ͨ͠ূ໌ॻͱൿີ伴ͷPEMϑΝΠϧΛબ୒͢Δͱɻ VSCode͔ΒIBP΁ͷ઀ଓ͕Ͱ͖Δɻ

    IBP্ͷεϚʔτίϯτϥΫτͷτϥϯβΫγϣϯͷૹ৴͕Ͱ͖Δɻ VSCode v0.3.0Ͱ͸ϩʔΧϧωοτϫʔΫͷΈεϚʔτίϯτϥΫτͷσϓϩΠ͕Ͱ͖ɺ֎෦ωο τϫʔΫ͸τϥϯβΫγϣϯͷૹ৴ͷΈͰ͖Δɻ ࣮ࡍ͸ҎԼͷΑ͏ͳΤϥʔ͕දࣔ͞ΕɺΠϯετʔϧ͸Ͱ͖Δ͕ɺInstantiationɺτϥϯβΫγϣ ϯͷૹ৴͸Ͱ͖ͳ͍ɻ※IBPଆͰInstantiation͸Ͱ͖ͨɻIBP for ExtensionͷόʔδϣϯΛ0.3.0ɺ VSCodeͷόʔδϣϯΛ1.31ʢIBP for Extensionͷਪ঑όʔδϣϯʣʹͨ͠ΒΤϥʔ͕දࣔ͞Εͳ ͘ͳͬͨɻʢVSCode͔Β͸IBPͷωοτϫʔΫʹରͯ͠ΠϯετʔϧͱInstantiation͸Ͱ͖ͣɺτ ϥϯβΫγϣϯͷૹ৴͚ͩͰ͖ΔΑ͏ʹͳͬͨʣ