Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a chart for history of knowledge size #797

Closed
Keith-CY opened this issue Nov 29, 2024 · 3 comments
Closed

Add a chart for history of knowledge size #797

Keith-CY opened this issue Nov 29, 2024 · 3 comments
Assignees
Labels

Comments

@Keith-CY
Copy link
Member

Is your feature request related to a problem? Please describe.

The knowledge size is the size occupied by on-chain data, not the declared size of cells. It reveals how many resources are used to share common knowledge, which is an important index for users.

Describe the solution you'd like
The current knowledge size can be calculated as described in https://talk.nervos.org/t/how-to-get-the-average-occupied-bytes-per-live-cell-in-ckb/7138/2?u=keith

And here is the code

const EXCLUDE = BigNumber('504000000000000000')
const getKnowledgeSize = async (nodeUrl: string) => {
  const header = await fetch(nodeUrl, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      id: 1,
      jsonrpc: '2.0',
      method: 'get_tip_header',
      params: [],
    }),
  })
    .then(res => res.json())
    .then(res => res.result)
  const { dao } = header

  const [, , , u] = dao
    .slice(2)
    .match(/\w{16}/g)
    .map((i: string) => i.match(/\w{2}/g)?.reverse().join('') ?? '')
  const total = BigNumber(`0x${u}`).minus(EXCLUDE).toFormat()
  return total
}

A chart of its history can be added in the explorer so we can see how it grew in the past.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

@rabbitz
Copy link

rabbitz commented Dec 2, 2024

PR: nervosnetwork/ckb-explorer@de6f7d4

curl 'https://ckb-explorer-api-staging.magickbase.com/api/v1/daily_statistics/knowledge_size' \
  -H 'accept: application/vnd.api+json' \
  -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8,sa;q=0.7' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/vnd.api+json' 

@FrederLu
Copy link

image image image image

Screenshot 1336491 This data is obtained through the dao of this block on 2020/05/23 00:00:42.
If you want to display the knowledge_size on May 23, it is best to use the dao data of this block on 2020/05/23 23:59:38.
Please confirm. @rabbitz

@FrederLu
Copy link

Verified.

@FrederLu FrederLu moved this from 👀 Testing to ✅ Done in CKB Explorer Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

No branches or pull requests

5 participants