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
800
ブロックチェーンとIndexer
yudetamago
January 24, 2020
Tweet
Share
More Decks by yudetamago
See All by yudetamago
Unityでブロックチェーンアプリを作る
yudetamago
0
1.7k
DApps開発特有の_ハマりポイントご紹介.pdf
yudetamago
1
1.3k
スマートコントラクトの監査について
yudetamago
2
570
DApps開発事例 ~CryptoCrystal概要編~
yudetamago
3
280
Gasを誰が払うのか問題について
yudetamago
5
4.3k
Solidityの複数コントラク ト連携を色々試してる話
yudetamago
1
2.1k
Dapps開発におけるSoliidityのはまりどころ
yudetamago
3
2.1k
Other Decks in Technology
See All in Technology
LLVM/ASMを使った有限体の高速実装
herumi
0
120
言葉は感情の近似値である。その感情と言葉の誤差を最小化しよう ~コミュニケーションにおけるアナログ/デジタル変換の課題に立ち向かう~
nktamago
0
240
スタッフエンジニアの道: The Staff Engineer’s Path
snoozer05
PRO
44
14k
Mocking in Rust Applications
taiki45
2
420
フルカイテン株式会社 採用資料
fullkaiten
0
32k
不動産tech Product Night#2_AIことはじめ_GA橋本
takehikohashimoto
0
190
DevRelの始め方
moongift
PRO
2
400
あなたの知らないiOS開発の世界
recruitengineers
PRO
3
190
『GRANBLUE FANTASY Relink』ソフトウェアラスタライザによる実践的なオクルージョンカリング
cygames
0
180
『GRANBLUE FANTASY: Relink』最高の「没入感」を実現するカットシーン制作手法とそれを支える技術
cygames
1
150
「認証認可」という体験をデザインする ~Nekko Cloud認証認可基盤計画
logica0419
2
450
やってやろうじゃないかメカアジャイル! / Let's do it, mechanical agile!
psj59129
1
690
Featured
See All Featured
RailsConf 2023
tenderlove
28
810
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.3k
The Mythical Team-Month
searls
218
43k
We Have a Design System, Now What?
morganepeng
48
7.1k
Designing on Purpose - Digital PM Summit 2013
jponch
114
6.8k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
Thoughts on Productivity
jonyablonski
66
4.2k
How To Stay Up To Date on Web Technology
chriscoyier
786
250k
The World Runs on Bad Software
bkeepers
PRO
64
11k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
230
17k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Git: the NoSQL Database
bkeepers
PRO
425
64k
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