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

Bring getblock up to date #52

Closed
roylee17 opened this issue Jun 7, 2022 · 4 comments · Fixed by #73
Closed

Bring getblock up to date #52

roylee17 opened this issue Jun 7, 2022 · 4 comments · Fixed by #73
Assignees
Labels
rpc RPC related issues

Comments

@roylee17
Copy link
Collaborator

roylee17 commented Jun 7, 2022

Missing chainwork and mediantime

On lbcd:

lbcctl getblock ac280c2a68c57707cc1fedbd025782c76cc2679550aa18cc5bd6e3f64c2a2769
{
  "hash": "ac280c2a68c57707cc1fedbd025782c76cc2679550aa18cc5bd6e3f64c2a2769",
  "confirmations": 1,
  "strippedsize": 16191,
  "size": 16227,
  "weight": 64800,
  "height": 1172332,
  "version": 536870912,
  "versionHex": "20000000",
  "merkleroot": "b3717572eb82f625a1de2735fbb119802032d07b59a2c84d25c5d5bcb4a69128",
  "time": 1654577506,
  "nonce": 3245888345,
  "bits": "1a009cca",
  "difficulty": 1795218858097.069,
  "previousblockhash": "9ee97ed1dbaf34fbf40d755ccb9a23b3074e61b1572a8135397a9f6514d741ca",
  "nameclaimroot": "1c6a4517e9254d0becdfc1dd5257b8c66b58899618e9305f1fab57a7054c12cd",
  "nTx": 33,
  "tx": [
    "07c8b6aa16d59f184e6aea71e613b08be52182869b9fdeba422a0dbf47411383",
    "1f0eeaa0480639805849724e835be04f1e041f73ed1f10caceb4db70c7403876",
    "0a999db30bfa1116646347dc8a6c1baf62ae1998c63640f48c33b02117fc1412",
    ...
  ]
}

On lbrycrd:

lbcctl --notls -s $LBRYCRD_NODE getblock ac280c2a68c57707cc1fedbd025782c76cc2679550aa18cc5bd6e3f64c2a2769
{
  "hash": "ac280c2a68c57707cc1fedbd025782c76cc2679550aa18cc5bd6e3f64c2a2769",
  "confirmations": 1,
  "strippedsize": 16191,
  "size": 16227,
  "weight": 64800,
  "height": 1172332,
  "version": 536870912,
  "versionHex": "20000000",
  "merkleroot": "b3717572eb82f625a1de2735fbb119802032d07b59a2c84d25c5d5bcb4a69128",
  "time": 1654577506,
  "nonce": 3245888345,
  "bits": "1a009cca",
  "difficulty": 1795218858097.069,
  "previousblockhash": "9ee97ed1dbaf34fbf40d755ccb9a23b3074e61b1572a8135397a9f6514d741ca",
  "nameclaimroot": "1c6a4517e9254d0becdfc1dd5257b8c66b58899618e9305f1fab57a7054c12cd",
  "nTx": 33,
  "tx": [
    "07c8b6aa16d59f184e6aea71e613b08be52182869b9fdeba422a0dbf47411383",
    "1f0eeaa0480639805849724e835be04f1e041f73ed1f10caceb4db70c7403876",
    "0a999db30bfa1116646347dc8a6c1baf62ae1998c63640f48c33b02117fc1412",
    ...

  ],
  "mediantime": 1654577056,
  "chainwork": "000000000000000000000000000000000000000000000964a8366f9822316ea1"
}
@roylee17 roylee17 added the rpc RPC related issues label Jun 7, 2022
@roylee17 roylee17 changed the title getblock RPC missing chainwork and meantime fields Bring getblock up to date Jun 15, 2022
@moodyjon moodyjon self-assigned this Jul 19, 2022
@moodyjon
Copy link
Collaborator

moodyjon commented Jul 20, 2022

I was getting worried that chainwork/mediantime had no implementation in "lbcd", but found what I needed here:

func (node *blockNode) CalcPastMedianTime() time.Time {

workSum *big.Int

@roylee17
Copy link
Collaborator Author

Yeah, the mediantime is part of consensus, so it must be existing somewhere.

The chainwork, however, in lbcd currently has different semantics - accounting works since each restart of lbcd, instead of historically accumulated numbers. It works for the chain as it only cares about the relative work between branches, if any, for choosing the one with most work.

Currently, the only known external users of that field is block explorers for displaying information. While it probably won't block any functional integration, still very nice to have if we can reconstruct/calculated the accumulated work at start-up.

@moodyjon
Copy link
Collaborator

moodyjon commented Jul 20, 2022

All the code I investigate indicates chainwork (workSum) is predictable, and is initialized during the "Loading block index" phase:

func (b *BlockChain) initChainState() error {

initBlockNode() is where the parent workSum is added. This seems consistent across bcd, lbrycrd, and C++ bitcoin. It's "in memory only" but gets recomputed during startup.

Maybe there is some separate concept with a similar purpose/name that you are thinking of?

@roylee17
Copy link
Collaborator Author

I didn't dig too deep into that last time, so you maybe right, which would be a good news.

You can test against a public lbrycrd instance I setup for validation when you export it to the rpcserver.

lbcctl --notls -s 18.221.146.233 -u rpcuser -P rpcpass getblock ac280c2a68c57707cc1fedbd025782c76cc2679550aa18cc5bd6e3f64c2a2769

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rpc RPC related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants