Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ブロックチェーンとIndexer
Search
yudetamago
January 24, 2020
Technology
980
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ブロックチェーンとIndexer
yudetamago
January 24, 2020
More Decks by yudetamago
See All by yudetamago
Unityでブロックチェーンアプリを作る
yudetamago
0
1.9k
DApps開発特有の_ハマりポイントご紹介.pdf
yudetamago
1
1.5k
スマートコントラクトの監査について
yudetamago
2
650
DApps開発事例 ~CryptoCrystal概要編~
yudetamago
3
340
Gasを誰が払うのか問題について
yudetamago
5
4.7k
Solidityの複数コントラク ト連携を色々試してる話
yudetamago
1
2.4k
Dapps開発におけるSoliidityのはまりどころ
yudetamago
3
2.4k
Other Decks in Technology
See All in Technology
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
4
1.6k
Claude Code本って、 読む必要あるの?
oikon48
2
430
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
12k
Screen Lens - 今見てる画面を翻訳する
komagata
0
260
Minecraft JavaのMODをSwiftで作る
1mash0
0
130
リージョンの壁を越える、 ちょっと変わったAWSサービスの話
falken
PRO
1
310
DEFCON_CHV_CTF_Write-up.pdf
bata_24
0
140
AI時代だからこそ、スケールしないことをやろう
yutashigemura
1
170
深夜のクラウド懺悔室 1:29:300 or 1:0:0
kazzpapa3
1
240
アプリログインとWeb認証基盤をつなぐ ASWebAuthenticationSession 作法
shimastripe
1
280
The Agent Builder Loop from Daily Work to OSS
minorun365
PRO
3
150
安心して変更できるWebフロントエンドの作り方
pirosikick
4
2k
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
410
Skip the Path - Find Your Career Trail
mkilby
1
230
Building Adaptive Systems
keathley
44
3.2k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
A better future with KSS
kneath
240
18k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
410
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
300
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
230
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.9k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
The Spectacular Lies of Maps
axbom
PRO
1
990
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