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

Rosetta API, Klaytn도 지원한다!

kakao
PRO
December 09, 2022

Rosetta API, Klaytn도 지원한다!

#Rosetta

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

발표자 : jamie.1222

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

kakao
PRO

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

    View Slide

  2. ߊ಴੗ ࣗѐ
    - Jimin (Jamie) Kim
    - Ӓۄ਍٘X (2019-2022)
    - Klaytn/KAS SDK ѐߊ
    - Kaikas ߔূ٘ ѐߊ
    - ࠶۾୓ੋ ௏য ѐߊ
    - ௼۞झ౟ ਬפߡझ (2022~)
    - rosetta-klaytn ѐߊ
    - ࠶۾୓ੋ ௏য ѐߊ
    - Klaytn SDK ѐߊ

    View Slide

  3. Rosetta API
    rosetta-klaytn
    Performance Improvement
    ೱറߊ੹ࢎ೦

    View Slide

  4. Rosetta API

    View Slide

  5. Rosetta API

    View Slide

  6. Why?
    “࠶۾୓ੋ ಴ળ APIо ৵ ೙ਃೠоਃ?”

    View Slide

  7. ࠶۾୓ੋ ಴ળ API੄ ೙ਃࢿ

    View Slide

  8. rosetta-klaytn

    View Slide

  9. Ethereum Equivalence

    View Slide

  10. rosetta-klaytn

    View Slide

  11. Reward
    Gas
    Dynamic Gas Fee Distribution
    TxType
    Fee Delegation

    View Slide

  12. Reward
    Gas
    Dynamic Gas Fee Distribution
    TxType
    Fee Delegation

    View Slide

  13. Reward
    Gas
    Dynamic Gas Fee Distribution
    TxType
    Fee Delegation

    View Slide

  14. Reward
    Gas
    Dynamic Gas Fee Distribution
    TxType
    Fee Delegation

    View Slide

  15. 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

    View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. ?
    “API ҳഅ੉ ੜ غ঻ա?”

    View Slide

  21. rosetta-klaytn
    check:data

    check:construction

    View Slide

  22. Performance Improvement

    View Slide

  23. 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

    View Slide

  24. 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

    View Slide

  25. 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

    View Slide

  26. 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

    View Slide

  27. 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

    View Slide

  28. 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

    View Slide

  29. 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

    View Slide

  30. 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

    View Slide

  31. 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

    View Slide

  32. 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

    View Slide

  33. 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

    View Slide

  34. 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

    View Slide

  35. 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

    View Slide

  36. 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

    View Slide

  37. 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

    View Slide

  38. 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

    View Slide

  39. 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

    View Slide

  40. Function
    Call
    Stack
    Blocking Time
    Pro
    fi
    ling with pprof

    View Slide

  41. Function
    Call
    Stack
    Blocking Time
    Pro
    fi
    ling with pprof

    View Slide

  42. 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

    View Slide

  43. 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

    View Slide

  44. 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

    View Slide

  45. Upgrade aws instance
    c5a.4xlarge (8 core / 32GB Memory) c5a.8xlarge (16 core / 64GB Memory)
    2.77 Blocks/sec 3.18 Blocks/sec

    View Slide

  46. 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

    View Slide

  47. 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

    View Slide

  48. 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

    View Slide

  49. 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

    View Slide

  50. 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 )

    View Slide

  51. 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

    View Slide

  52. 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

    View Slide

  53. ೱറߊ੹ࢎ೦

    View Slide

  54. ೱറߊ੹ࢎ೦
    - 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
    - …

    View Slide

  55. ௿ۨ੉ౡী ؀೧ ؊ ੜ ঌҊ र׮ݶ? ௼۞झ౟ ਬפߡझח ૑Ә ଻ਊ ઺!

    View Slide