Skip to content

RPC: Introduce getblockstats to plot things#1913

Merged
gandrewstone merged 5 commits into
BitcoinUnlimited:devfrom
dagurval:getblockstats
Sep 12, 2019
Merged

RPC: Introduce getblockstats to plot things#1913
gandrewstone merged 5 commits into
BitcoinUnlimited:devfrom
dagurval:getblockstats

Conversation

@dagurval

Copy link
Copy Markdown
Collaborator

jtimon and others added 5 commits September 11, 2019 11:27
Cherry-picker notes:

The following stats have been removed, as we don't have the added
complexities of segwit:

swtotal_size, swtotal_weight, swtxs, total_weight

In addition, fee rate is calculated as sat/bytes and not "virtual
bytes".
Includes commit from Anthony Towns @ajtowns:

Tests: Save and load block and corresponding expected statistics
Generated with `rpc_getblockstats.py --gen-test-data`
Comment thread src/rpc/blockchain.cpp
}

LOCK(cs_main);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we need cs_main here. Getting the tip height does not need it in BU because it's atomic, and neither chainActive[height] nor chainActive.contains() need it because the data is immutable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right about that, but if cs_main is not taken, the chain could be reorged between 1677 and 1689 causing an out of bounds error. Its basically impossible IRL because the user would have to call InvalidateBlock to reorg to a shorter chain. But let's merge and then worry about narrowing cs_main.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where an out of bounds could be caused but I don't want to hold up the PR for this either.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There a 80x speedup PR for getblockstats in the pipeline, we could postpone discussing this for that one

Comment thread src/rpc/blockchain.cpp
}
}

DbgAssert(pindex != nullptr, throw std::runtime_error(__func__));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not throw JSONRPCError? What is the behavior of throwing runtime_error here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly for brevity, these are converted into RPC_MISC_ERROR here

Comment thread src/rpc/blockchain.cpp

#include <univalue.h>

#include <boost/algorithm/string.hpp>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey -- I was just browsing around the extant PRs -- quick question: why include this header? I don't see any new lines using it.. does it fix a compile error that was already there or something?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're right, it is not needed. It was in the original PR. Maybe the original author used it in an earlier revision and forgot to take it out.

I will remove it if I do a revision on this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this happens to me a lot -- include some header for something -- take that something out -- leave header in. So I am vigilant always to detect that since it's a bane.. :)

@gandrewstone
gandrewstone merged commit 35c77aa into BitcoinUnlimited:dev Sep 12, 2019
@dagurval
dagurval deleted the getblockstats branch September 12, 2019 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants