Don't waste resources updating hashFinalSproutRoot in src/main.cpp when loading block index #248

Closed
opened 2 years ago by duke · 8 comments
duke commented 2 years ago
Owner

Hush nor any Hush Smart Chain has ever had any sprout history in their blockchains, so there is no sense in spending any resources updating hashFinalSproutRoot when loading the block index. From src/main.cpp LoadBlockIndexDB function :

    // Fill in-memory data
    BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
    {
        CBlockIndex* pindex = item.second;
        // - This relationship will always be true even if pprev has multiple
        //   children, because hashSproutAnchor is technically a property of pprev,
        //   not its children.
        // - This will miss chain tips; we handle the best tip below, and other
        //   tips will be handled by ConnectTip during a re-org.
        if (pindex->pprev) {
            pindex->pprev->hashFinalSproutRoot = pindex->hashSproutAnchor;
        }
    }

This iterates over every single block in the history of the chain and then updates a value that is never used. It's the only operation in this loop. This makes full node startup times slower and slower as more blocks are in the chain. We can likely comment out the above code with no ill effect and make full node startup times faster.

Hush nor any Hush Smart Chain has ever had any sprout history in their blockchains, so there is no sense in spending any resources updating hashFinalSproutRoot when loading the block index. From src/main.cpp `LoadBlockIndexDB` function : ``` // Fill in-memory data BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex) { CBlockIndex* pindex = item.second; // - This relationship will always be true even if pprev has multiple // children, because hashSproutAnchor is technically a property of pprev, // not its children. // - This will miss chain tips; we handle the best tip below, and other // tips will be handled by ConnectTip during a re-org. if (pindex->pprev) { pindex->pprev->hashFinalSproutRoot = pindex->hashSproutAnchor; } } ``` This iterates over every single block in the history of the chain and then updates a value that is never used. It's the only operation in this loop. This makes full node startup times slower and slower as more blocks are in the chain. We can likely comment out the above code with no ill effect and make full node startup times faster.
Poster
Owner

To test this change :

  • Verify a full sync can be done
  • Verify a node can be stopped, restarted and do a partial sync
  • Create an HSC with default equihash PoW and verify a block can be mined
  • Verify you can do a full sync with the HSC
  • Verify you can do a partial sync with the HSC
To test this change : * [x] Verify a full sync can be done * [x] Verify a node can be stopped, restarted and do a partial sync * [x] Create an HSC with default equihash PoW and verify a block can be mined * [x] Verify you can do a full sync with the HSC * [x] Verify you can do a partial sync with the HSC
onryo self-assigned this 2 years ago
Poster
Owner

For extra credit, you can look at the difference in how long it takes the message finished loading blocks to be printed to STDERR on master vs this code change, to see what kind of performance boost we get.

For extra credit, you can look at the difference in how long it takes the message `finished loading blocks` to be printed to STDERR on master vs this code change, to see what kind of performance boost we get.

To test this change :

  • Verify a full sync can be done
  • Verify a node can be stopped, restarted and do a partial sync
  • Create an HSC with default equihash PoW and verify a block can be mined
  • Verify you can do a full sync with the HSC
  • Verify you can do a partial sync with the HSC

All checks passed.

> To test this change : > > * [x] Verify a full sync can be done > * [x] Verify a node can be stopped, restarted and do a partial sync > * [x] Create an HSC with default equihash PoW and verify a block can be mined > * [x] Verify you can do a full sync with the HSC > * [x] Verify you can do a partial sync with the HSC All checks passed.

For extra credit, you can look at the difference in how long it takes the message finished loading blocks to be printed to STDERR on master vs this code change, to see what kind of performance boost we get.

It is nearly instant to begin with, I got a finished loading blocks message within a second on master and I am not sure what performance boost I can test here, could you clarify?

> For extra credit, you can look at the difference in how long it takes the message `finished loading blocks` to be printed to STDERR on master vs this code change, to see what kind of performance boost we get. It is nearly instant to begin with, I got a `finished loading blocks` message within a second on `master` and I am not sure what performance boost I can test here, could you clarify?
Poster
Owner

@onryo are you talking about loading blocks on HUSH mainnet or an HSC? For an HSC wih just a few blocks, it's going to be instant. For HUSH mainnet, which currently has over 1.1 million blocks, it often takes at least 1 or 2 minutes, depending on CPU speed, in my experience.

@onryo are you talking about loading blocks on HUSH mainnet or an HSC? For an HSC wih just a few blocks, it's going to be instant. For HUSH mainnet, which currently has over 1.1 million blocks, it often takes at least 1 or 2 minutes, depending on CPU speed, in my experience.
Poster
Owner

@onryo if things work for you without that code, please send a PR to the dev branch with that code deleted. I am not sure what performance change it will give, but at least we are getting rid of sprout code we don't need.

@onryo if things work for you without that code, please send a PR to the `dev` branch with that code deleted. I am not sure what performance change it will give, but at least we are getting rid of sprout code we don't need.
onryo referenced this issue from a commit 2 years ago
onryo referenced this issue from a commit 2 years ago

@onryo are you talking about loading blocks on HUSH mainnet or an HSC? For an HSC wih just a few blocks, it's going to be instant. For HUSH mainnet, which currently has over 1.1 million blocks, it often takes at least 1 or 2 minutes, depending on CPU speed, in my experience.

To be honest I was talking about HUSH, not HSC. Takes me 1-2 seconds. 😶

> @onryo are you talking about loading blocks on HUSH mainnet or an HSC? For an HSC wih just a few blocks, it's going to be instant. For HUSH mainnet, which currently has over 1.1 million blocks, it often takes at least 1 or 2 minutes, depending on CPU speed, in my experience. To be honest I was talking about HUSH, not HSC. Takes me 1-2 seconds. 😶
duke commented 1 year ago
Poster
Owner

done, closing

done, closing
duke closed this issue 1 year ago
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.