Starcoin Offchain 服务文档

该目录下为2023年整理的Swap的相关信息备份


简介

SwapInfo 显示 starswap 统计的一些相关的数据,主站为 https://info.starswap.xyz ,一共包含了以下几个部分:

  1. Starswap Overview,TVL的趋势

  2. All Tokens,所有的Token的排名

  3. Top Pools,排名前几位的交易对

  4. Transactions,池子的相关交易

结构

背景:这里当时锁元老师在构建新的stcscan,将老账户的数据迁移到新账户,由于一些原因中断了开发,当时迁移了一半的数据又迁移回了旧账户,造成维护了两套数据库的现状

 

Starswap Info Service & StcScan Service

 

可以看到前端主要访问统计API进行显示,该部分与 https://stcscan.io 存在一个物理数据库中,具体相关文档参考 stcscan 整理(TODO)

图中主要有以下几个服务:

  1. stc-scan-api,区块链浏览器API,主要用于stcscan.io查询STC相关交易、账户等信息

  2. starcoin-indexer,负责维护定时更新统计信息等到数据库,除了Swap相关之外,还有Token价格统计,交易信息,TVL统计等,其中Swap相关的后台任务主要有以下几种:

    1. SwapEventHandler,负责保存链上每次交易费的信息;

    2. SwapHandler,负责记录每日的swap交易信息与LiquidityPool的TVL信息

    3. SwapPoolFeeStatIndexer,定时将数据库中池子的交易费统计到统计表中;

    4. 当数据出现问题时,可以使用kube/indexer中的repair后缀的配置文件进行数据修复

  3. StarcoinPriceReporter, 主要负责定时维护币价的Oracle服务,方便SwapInfo等统计相关信息,其信息主要从Chainlink中获取

上述具体细节请参考代码。

 

部署

基于k8s工具部署,需要先配置k8s相关的本地环境

Pods

 

老账户:arn:aws:eks:ap-northeast-1:576184071779:cluster/starcoin2

NAMESPACE               NAME                                                              READY   STATUS      RESTARTS   AGE default                 scan-api-deployment-6fcb97d6-rrrtx                                1/1     Running     0          312d default                 starcoin-db                                                       0/1     Completed   0          284d default                 swap-stat-api-deployment-7d7577c885-8l6nf                         1/1     Running     0          7d starcoin-barnard        starcoin-indexer-deployment-6bc988bb9c-tv987                      1/1     Running     0          276d starcoin-halley         starcoin-indexer-deployment-6f5d6c79b7-zhthn                      1/1     Running     0          283d starcoin-main           starcoin-indexer-deployment-5ddbbd7899-npbtw                      1/1     Running     0          284d starcoin-main           starcoin-indexer-swap-deployment-7fdc4f88c9-26gmj                 1/1     Running     0          284d

可见老账户中有scan-api-deployment,swap-stat-api 几个服务

 

新账户:arn:aws:eks:ap-northeast-1:370341518942:cluster/starcoin3

NAMESPACE NAME READY STATUS RESTARTS AGE ... default airdrop-api-deployment-6bbdb6d596-b5qtp 1/1 Running 0 321d default airdrop-java-deployment-77d879c9db-7ffhl 0/1 CreateContainerConfigError 0 236d default dao-api-deployment-786fd994b4-jhfn7 1/1 Running 1 (318d ago) 319d default dao-api-deployment-barnard-5855485f88-chqkq 0/1 CrashLoopBackOff 88643 (3m52s ago) 318d default faucet-api-deployment-54ff75ff58-8jjx5 1/1 Running 0 317d default faucet-worker-deployment-78b7b5679b-zdnmm 1/1 Running 0 317d default mainnet-poly-to-starcoin-relayer-deployment-bf54968b7-jh8xd 1/1 Running 0 318d default poll-api-deployment-6c449c78c7-csgmc 1/1 Running 0 318d default poll-api-deployment-6c449c78c7-lnqtl 1/1 Running 1 (318d ago) 326d default starcoin-airdrop-service-deployment-f687fdd4-4lw9t 1/1 Running 0 318d default starcoin-bot-go-deployment-67dcf64947-zt55r 1/1 Running 0 35d default starcoin-db 0/1 Completed 0 6d3h default starcoin-pricereporter-deployment-6755449b4d-p4tsb 1/1 Running 0 6d2h default starcoin-pricereporter-deployment-barnard-7c4d4b667-6q669 1/1 Running 0 6d2h default starfly-backend-deployment-674949dd7-t2pkq 1/1 Running 0 318d default starfly-front-deployment-7c68654687-vcshx 1/1 Running 0 35d default starswap-api-deployment-5b6f4d4d8d-h9ngx 1/1 Running 0 321d default starswap-api-deployment-aptos-devnet-f8cc96f-vswd4 1/1 Running 3 (318d ago) 326d default starswap-api-deployment-aptos-mainnet-54f9cb9b79-sb5mf 1/1 Running 0 278d default starswap-api-deployment-aptos-testnet-7b777b4956-vqps5 1/1 Running 0 255d default starswap-api-deployment-barnard-5d9ff7686f-9nwnb 1/1 Running 0 317d default testnet-poly-to-starcoin-relayer-deployment-78b84b6b5f-cbgwv 1/1 Running 0 318d ... starcoin-barnard starcoin-0 1/1 Running 0 26d starcoin-barnard starcoin-1 1/1 Running 0 26d starcoin-barnard starcoin-2 1/1 Running 0 26d starcoin-halley starcoin-0 1/1 Running 0 26d starcoin-main starcoin-0 1/1 Running 0 35d starcoin-main starcoin-1 1/1 Running 0 74d starcoin-main starcoin-2 1/1 Running 0 74d starcoin-main starcoin-3 1/1 Running 0 74d starcoin-main starcoin-4 1/1 Running 0 35d starcoin-main starcoin-5 1/1 Running 0 35d starcoin-main starcoin-6 1/1 Running 0 74d starcoin-main starcoin-7 1/1 Running 0 74d starcoin-main starcoin-8 1/1 Running 0 74d starcoin-proxima starcoin-0 1/1 Running 0 49d

新账户中包含了所有的seed节点,pricereporterstarswap-api

 

数据库对应的服务

根据代码配置整理出两个数据库分别支持的服务

新账户

数据库地址:starcoin-db-2.czftx6muneg7.ap-northeast-1.rds.amazonaws.com

支持的服务:

  1. Price Reporter

  2. Swap Info

  3. api-airdrop

 

老账户

数据库地址:
1. database-1: database-1.c0bz9kehdvnb.ap-northeast-1.rds.amazonaws.com:5432 支持 scan-stat-api
2. scan-db: scan-db.c0bz9kehdvnb.ap-northeast-1.rds.amazonaws.com:5432 支持 stc-scan

 

数据库维护

连接跳板机:

# Run starcoin db pods $ kubectl exec starcoin-db --stdin --tty -- sh # if prompt error: cannot exec into a container in a completed pod; current phase is Succeeded # Then replace pod $ kubectl get pod starcoin-db -n default -o yaml | kubectl replace --force -f - # Run starcoin-db $ kubectl run starcoin-db --image=alpine --restart=Never -- sleep 1d # Reenter starcoin-db pods $ kubectl exec starcoin-db --stdin --tty -- sh # Add mysql client / apk add mysql-client

 

连接数据库。

 

错误

1.报错为

com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException: Network exception: Connection timed out (Connection timed out)

 一般是jsonrpc失败了

2.或者查看

GET barnard.0727.blocks/_mapping 这值太小不行

 

把值调大