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

Rosetta API, Klaytn도 지원한다!

kakao
December 09, 2022

Rosetta API, Klaytn도 지원한다!

#Rosetta

Klaytn은 Rosetta API를 지원합니다. Rosetta 표준은 Coinbase가 만든 표준으로 서로 다른 블록체인 플랫폼에 대해 동일한 API 사용성을 제공하고자 만들어졌습니다.
본 세션에서는 Rosetta 표준을 구현체인 rosetta-klaytn에 대한 이해와 이를 구현하면서 해결했던 이슈에 대해 공유드리고자 합니다.

발표자 : jamie.1222

크러스트유니버스 코어 데브팀 제이미입니다. 블록체인 기술이 대중화되고 많은 사용자들이 쉽고 편리한 클레이튼을 사용하는 그날을 위해 열심히 노력하겠습니다.

kakao

December 09, 2022
Tweet

More Decks by kakao

Other Decks in Programming

Transcript

  1. Rosetta API, Klaytnب ૑ਗೠ׮! ӣ૑޹ Jamie.1222 ௼۞झ౟ ਬפߡझ Copyright 2022.

    Kakao Corp. All rights reserved. Redistribution or public display is not permitted without written permission from Kakao. if(kakao)2022
  2. ߊ಴੗ ࣗѐ - Jimin (Jamie) Kim - Ӓۄ਍٘X (2019-2022) -

    Klaytn/KAS SDK ѐߊ - Kaikas ߔূ٘ ѐߊ - ࠶۾୓ੋ ௏য ѐߊ - ௼۞झ౟ ਬפߡझ (2022~) - rosetta-klaytn ѐߊ - ࠶۾୓ੋ ௏য ѐߊ - Klaytn SDK ѐߊ
  3. Endpoint Category rosetta-klaytn /account/balance Data O /account/coins Data X /block

    Data O /block/transaction Data O /call Data O /mempool Data O /mempool/transaction Data X /network/list Data O /netwokr/options Data O /network/status Data O Endpoint Category rosetta-klaytn /construction/combine Construction O /construction/derive Construction O /construction/hash Construction O /construction/metadata Construction O /construction/parse Construction O /construction/payloads Construction O /construction/preprocess Construction O /construction/submit Construction O Construction API endpoints Data API endpoints rosetta-klaytn
  4. rosetta-cli rosetta-klaytn Cypress Mainnet 0 1 2 3 4 …

    How to run check:data testing with rosetta-cli tester Syncer Reconciler BlockStorage BalanceStorage N-3 N-1 N 5 6 7 N-2 How check:data works
  5. rosetta-cli rosetta-klaytn Cypress Mainnet 0 1 2 3 4 …

    How to run check:data testing with rosetta-cli tester Syncer Reconciler BlockStorage BalanceStorage N-3 N-1 N 5 6 7 N-2 How check:data works
  6. rosetta-cli rosetta-klaytn Cypress Mainnet 0 1 2 3 4 …

    How to run check:data testing with rosetta-cli tester Syncer Reconciler BlockStorage BalanceStorage N-3 N-1 N 5 6 7 N-2 How check:data works
  7. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works
  8. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Call APIs Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works
  9. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Call APIs Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works API return
  10. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Return parsed blocks Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works Call APIs API return
  11. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Return parsed blocks Store processed blocks Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works Call APIs API return
  12. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Return parsed blocks Update balance Store processed blocks from parsed data Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works Call APIs API return
  13. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Return parsed blocks Update balance Calls QueueChanges Store processed blocks from parsed data Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works Call APIs API return
  14. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Return parsed blocks Update balance Calls QueueChanges Fetch Balance (/account/balance endpoint) Store processed blocks from parsed data Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works Call APIs API return
  15. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Return parsed blocks Update balance Calls QueueChanges Fetch Balance (/account/balance endpoint) Store processed blocks from parsed data Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works Call APIs API return Call APIs
  16. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Return parsed blocks Update balance Calls QueueChanges Fetch Balance (/account/balance endpoint) Store processed blocks from parsed data Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works Call APIs API return API return Call APIs
  17. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Return parsed blocks Update balance Calls QueueChanges Fetch Balance (/account/balance endpoint) Return balance info
 at speci fi c block number Store processed blocks from parsed data Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works Call APIs API return API return Call APIs
  18. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Return parsed blocks Update balance Calls QueueChanges Fetch Balance (/account/balance endpoint) Return balance info
 at speci fi c block number Compare with balance in the network Store processed blocks from parsed data Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works Call APIs API return API return Call APIs
  19. Performance issue with check:data testing Cypress Mainnet (22/06/21) 0 1

    93,192,251 2 3 … Baobab Testnet (22/06/10) 0 1 2 3 93,074,057 … 0.97 blocks/sec 3,492 blocks/hour 83,808 blocks/day 81,000,000 ~ 81,010,000 block range 1,112 Days for Cypress 1,111 Days for Baobab
  20. Adjusting rosetta-cli concurrency parameters { … "max_online_connections": 120, "max_sync_concurrency": 64,

    … "data": { "active_reconciliation_concurrency": 16, "inactive_reconciliation_concurrency": 4, … } 0.97 Blocks/sec - 0.87 Blocks/sec { … "max_online_connections": 256, "max_sync_concurrency": 256, … "data": { "active_reconciliation_concurrency": 128, "inactive_reconciliation_concurrency": 64, … } 1.10 Blocks/sec { … "max_online_connections": 1024, "max_sync_concurrency": 1024, … "data": { "active_reconciliation_concurrency": 512, "inactive_reconciliation_concurrency": 256, … } { … "max_online_connections": 512, "max_sync_concurrency": 512, … "data": { "active_reconciliation_concurrency": 256, "inactive_reconciliation_concurrency": 128, … } { … "max_online_connections": 128, "max_sync_concurrency": 128, … "data": { "active_reconciliation_concurrency": 64, "inactive_reconciliation_concurrency": 32, … } 1.14 Blocks/sec 946 Days for Cypress 944 Days for Baobab
  21. rosetta-cli rosetta-klaytn How to run check:data testing with rosetta-cli tester

    Syncer Reconciler BlockStorage BalanceStorage Fetch Blocks (/block endpoint) Return parsed blocks Update balance Calls QueueChanges Fetch Balance (/account/balance endpoint) Return balance info
 at speci fi c block number Compare with balance in the network Store processed blocks from parsed data Cypress Mainnet 0 1 2 3 4 … N-3 N-1 N 5 6 7 N-2 How check:data works Call APIs API return API return Call APIs
  22. func (ec *Client) getBlockReceipts( ctx context.Context, blockHash common.Hash, txs []rpcTransaction,

    ) ([]*types.Receipt, error) { receipts := make([]*types.Receipt, len(txs)) if len(txs) == 0 { return receipts, nil } reqs := make([]rpc.BatchElem, len(txs)) for i := range reqs { reqs[i] = rpc.BatchElem{ Method: “klay_getTransactionReceipt", Args: []interface{}{txs[i].tx.Hash().Hex()}, Result: &receipts[i], } } func (kc *Client) getBlockReceipts( ctx context.Context, blockHash common.Hash, txsLen int, ) ([]*types.Receipt, error) { receipts := make([]*types.Receipt, txsLen) if txsLen == 0 { return receipts, nil } err := kc.c.CallContext(ctx, &receipts, "klay_getBlockReceipts", blockHash) return receipts, err } 1.10 Blocks/sec 2.77 Blocks/sec
  23. func (ec *Client) getBlockReceipts( ctx context.Context, blockHash common.Hash, txs []rpcTransaction,

    ) ([]*types.Receipt, error) { receipts := make([]*types.Receipt, len(txs)) if len(txs) == 0 { return receipts, nil } reqs := make([]rpc.BatchElem, len(txs)) for i := range reqs { reqs[i] = rpc.BatchElem{ Method: “klay_getTransactionReceipt", Args: []interface{}{txs[i].tx.Hash().Hex()}, Result: &receipts[i], } } func (kc *Client) getBlockReceipts( ctx context.Context, blockHash common.Hash, txsLen int, ) ([]*types.Receipt, error) { receipts := make([]*types.Receipt, txsLen) if txsLen == 0 { return receipts, nil } err := kc.c.CallContext(ctx, &receipts, "klay_getBlockReceipts", blockHash) return receipts, err } 1.10 Blocks/sec 2.77 Blocks/sec 388 Days for Cypress 389 Days for Baobab
  24. Upgrade aws instance c5a.4xlarge (8 core / 32GB Memory) c5a.8xlarge

    (16 core / 64GB Memory) 2.77 Blocks/sec 3.18 Blocks/sec
  25. Adjust kernel params for rosetta-klaytn $ sysctl -a net.ipv4.tcp_max_syn_backlog: 4,096

    net.core.rmem_max: 212,992 net.core.wmem_max: 212,992 net.ipv4.tcp_tw_reuse: 2 net.core.somaxconn: 4096 ulimit: 65,535 $ sysctl -a net.ipv4.tcp_max_syn_backlog: 10,000 net.core.rmem_max: 16,777,216 net.core.wmem_max: 16,777,216 net.ipv4.tcp_tw_reuse: 1 net.core.somaxconn: 10,000 ulimit: 100,000 3.18 Blocks/sec 6.18 Blocks/sec
  26. Adjust kernel params for rosetta-klaytn $ sysctl -a net.ipv4.tcp_max_syn_backlog: 4,096

    net.core.rmem_max: 212,992 net.core.wmem_max: 212,992 net.ipv4.tcp_tw_reuse: 2 net.core.somaxconn: 4096 ulimit: 65,535 $ sysctl -a net.ipv4.tcp_max_syn_backlog: 10,000 net.core.rmem_max: 16,777,216 net.core.wmem_max: 16,777,216 net.ipv4.tcp_tw_reuse: 1 net.core.somaxconn: 10,000 ulimit: 100,000 3.18 Blocks/sec 6.18 Blocks/sec 174 Days for Cypress 174 Days for Baobab
  27. Run check:data tests in parallel Run check:data tests in parallel

    … 81,000,000 81,000,001 81,005,000 81,005,001 … 81,009,999 81,010,000 cli tester
  28. Run check:data tests in parallel Run check:data tests in parallel

    … 81,000,000 81,000,001 81,005,000 81,005,001 … 81,009,999 81,010,000 cli tester … 81,000,000 81,000,001 81,005,000 81,005,001 … 81,009,999 81,010,000 cli tester 1 cli tester 2 { … "data": { “start_index": 81000000, "end_conditions": { "index": 81005000 } … } cli tester 1 con fi g { … "data": { “start_index": 81005001, "end_conditions": { "index": 81010000 } … } cli tester 2 con fi g
  29. Run check:data tests in parallel Run check:data tests in parallel

    … 81,000,000 81,000,001 81,005,000 81,005,001 … 81,009,999 81,010,000 cli tester … 81,000,000 81,000,001 81,005,000 81,005,001 … 81,009,999 81,010,000 cli tester 1 cli tester 2 { … "data": { “start_index": 81000000, "end_conditions": { "index": 81005000 } … } cli tester 1 con fi g { … "data": { “start_index": 81005001, "end_conditions": { "index": 81010000 } … } cli tester 2 con fi g 6.18 Blocks/sec 9.25 Blocks/sec ( 116 Days for Cypress / 116 Days for Baobab )
  30. Performance Improvement with check:data testing 0.97 blocks/sec 1,112 Days for

    Cypress 1,111 Days for Baobab 81,000,000 ~ 81,010,000 block range Improve performance
  31. Performance Improvement with check:data testing 9.25+ blocks/sec 116 Days for

    Cypress 116 Days for Baobab Improve performance 81,000,000 ~ 81,010,000 block range 81,000,000 ~ 81,010,000 block range 0.97 blocks/sec 1,112 Days for Cypress 1,111 Days for Baobab
  32. ೱറߊ੹ࢎ೦ - Parse the native token (KLAY) transfer transactions with

    fastCallTracer in better way - API that re fl ects Klaytn's unique features - Apply governance policy modi fi cation - Modify governance API output key name - Restructuring for easy maintenance - …