Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ブロックチェーンとIndexer
Search
yudetamago
January 24, 2020
Technology
0
910
ブロックチェーンとIndexer
yudetamago
January 24, 2020
Tweet
Share
More Decks by yudetamago
See All by yudetamago
Unityでブロックチェーンアプリを作る
yudetamago
0
1.8k
DApps開発特有の_ハマりポイントご紹介.pdf
yudetamago
1
1.4k
スマートコントラクトの監査について
yudetamago
2
600
DApps開発事例 ~CryptoCrystal概要編~
yudetamago
3
310
Gasを誰が払うのか問題について
yudetamago
5
4.5k
Solidityの複数コントラク ト連携を色々試してる話
yudetamago
1
2.2k
Dapps開発におけるSoliidityのはまりどころ
yudetamago
3
2.3k
Other Decks in Technology
See All in Technology
Delegate authentication and a lot more to Keycloak with OpenID Connect
ahus1
0
240
生成AI活用のROI、どう測る? DMM.com 開発責任者から学ぶ「AI効果検証のノウハウ」 / ROI of AI
i35_267
3
110
[OCI Technical Deep Dive] OracleのAI戦略(2025年8月5日開催)
oracle4engineer
PRO
1
220
Autonomous Database Serverless 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
18
52k
僕たちが「開発しやすさ」を求め 模索し続けたアーキテクチャ #アーキテクチャ勉強会_findy
bengo4com
0
2.5k
JAWS AI/ML #30 AI コーディング IDE "Kiro" を触ってみよう
inariku
3
400
AIに目を奪われすぎて、周りの困っている人間が見えなくなっていませんか?
cap120
1
690
✨敗北解法コレクション✨〜Expertだった頃に足りなかった知識と技術〜
nanachi
1
760
Cloud WANの基礎から応用~少しだけDeep Dive~
masakiokuda
3
110
結局QUICで通信は速くなるの?
kota_yata
8
7.4k
マルチプロダクト×マルチテナントを支えるモジュラモノリスを中心としたアソビューのアーキテクチャ
disc99
1
630
Exadata Database Service on Dedicated Infrastructure セキュリティ、ネットワーク、および管理について
oracle4engineer
PRO
0
290
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.6k
Fireside Chat
paigeccino
39
3.6k
Building Applications with DynamoDB
mza
96
6.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Mobile First: as difficult as doing things right
swwweet
223
9.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
Making Projects Easy
brettharned
117
6.3k
A Tale of Four Properties
chriscoyier
160
23k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Why Our Code Smells
bkeepers
PRO
338
57k
We Have a Design System, Now What?
morganepeng
53
7.7k
Transcript
ブロックチェーンとIndexer 株式会社LayerX 神場 貴之 2019/1/24 blockchain.tokyo#24 supported by AWS 1
自己紹介 神場 貴之(じんば たかゆき) 株式会社LayerX Software Engineer Github: yudetamago Twitter:
takayukib 2
このスライドの前提 • ブロックチェーンとしてはQuorumを使います • 秘密鍵はサービス提供者が管理しています • (ブロックチェーンにある程度触れている方向けです) 3
indexerとは 4
シンプルなDAppsの構成 Quorum Frontend (+MetaMaskなど) tx送信 5
こんなときどうする? 6
デプロイ済みのERC20トークンを使って • 現在balanceが100以上で • 直近1週間のtransfer回数が100以上 のアドレスをリアルタイムに取得出来るよう にしたい 7
何が必要? • 過去1週間分のtransferのイベントログ ◦ 大量のイベント取得、どのブロック番号まで取得すればいい?? • (transferに関連する)アドレスのbalanceの一覧 ◦ アドレスそれぞれに対してERC20のbalanceOfを呼ぶ?? 8
RDBなら addresses address 0x…. balances address balance 0x…. 100 transfer_histories
from to amount block_timestamp 0x…. 0x…. 10 1579791600 joinとwhereで良い 9
indexerを使う理由 • コントラクト(Solidity)で柔軟な検索用メソッドを作るのは難しい • デプロイしてしまったコントラクトに後から検索用メソッドを追加することは出来な い ◦ イベントの定義に貼っているindexも後からは変えられない 10
ストレージのデータ、イベントをRDBに キャッシュ(インデクシング)しよう 11
indexer全体像 12
全体像 Quorum indexer RDB ログ取得 保存 API 取得 13
Indexer全体の流れ1 indexing_status not_indexing block_height 123 RDB ①現在indexing中でないことを確認 ②indexing中状態に変更 ③indexing済みの次のブロック(124)からログを取得する •
現在のindexing状態を記録(二重 実行防止) • indexing済みのブロック番号を記録 14
Indexer全体の流れ2 a 10 block_height 124 b 20 block_height 124 RDB
Quorum name data A a=10 B b=20 ④取得したイベントのログの数だけループ ⑤indexing対象のログならblock_heightと共にDBに保存 • イベントと RDB上のテー ブルのマッピングを作っ ておく 15
Indexer全体の流れ3 indexing_status not_indexing block_height 124 RDB ⑥block_heightを最新のものに更新 16
Indexingの仕方 1. Push型(WebSocketで常時接続) 2. Pull型(HTTPでPolling) 17
Push型 WebSocketでQuorumと常時接続しておき、イベントまたはブロックをsubscribeする • Pros ◦ リアルタイムにindexingすることが出来る • Cons ◦ 受け取る側でエラーになったときに備えてリトライ機構が必要
18
Pull型 HTTPでPollingを行い、Quorumに定期的にブロックを取りに行く • Pros ◦ 失敗しても(ブロック番号を調整して)再実行することが出来る • Cons ◦ Push型よりもリアルタイム性は多少下がる
19
その他 • 一度に取得するブロック数を制限してデータ量・処理時間が長くなりすぎないよ うにする • 中途半端に保存されないように(RDBの)トランザクションで実行する • uint256など通常の数値型では収まらない値に注意する 20
フロントエンドのUX 21
ブロック取り込み前, 未indexingの状態 Quorum API DB 最新のデータ 古いデータ 古いデータ ??? 22
API側でのレスポンスのタイミング 1. トランザクションの送信終了時 2. Quorumのブロック取り込み終了時 3. Indexing終了時 23
24
(ユーザーから見たときの) • レスポンスの待ち時間 • 状態が不整合となる時間 のトレードオフ 25