Skip to content

Conversation

TheBlueMatt
Copy link
Contributor

Based on #8930, the only thing left to do after this to split main.cpp into main and net_processing is a single move-only commit.

After #8930, the only remaining changes are tweaks to pull header-processing-logic out of net code and into a function exposed through main.h.

@instagibbs
Copy link
Member

utACK c53fc42

@jonasschnelli
Copy link
Contributor

Core Review ACK c53fc42cd7c57c75940e6ec593973e3f0ad69374.
Maybe Squash.

}

CValidationState state;
if (!ProcessNewBlockHeaders(headers, state, chainparams, &pindexLast)) { // We should call this without cs_main
Copy link
Member

Choose a reason for hiding this comment

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

Seems if one fails we don't actually know which? Or is there some async event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats true, though I dont think any code actually needs to know which currently? If its needed at some point its easy to add an async event and/or additional return value.

Copy link
Member

Choose a reason for hiding this comment

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

Stale comment? As far as I can tell, cs_main is not locked here.

Not sure if this means "TODO: Don't call without cs_main" or "make sure not to call this with cs_main"

{
LOCK(cs_main);
for (const CBlockHeader& header : headers) {
if (!AcceptBlockHeader(header, state, chainparams, ppindex)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this is probably fine now, but reusing state and assuming that it's only interesting if AcceptBlockHeader fails seems like it's asking for future bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm...I'm sure this isnt the only place we do this. Would definitely need an audit to figure out all the places this is true if we ever want to change state meaning.

This will allow NotifyHeaderTip to be called from an
AcceptBlockHeader wrapper function without holding cs_main.
@TheBlueMatt
Copy link
Contributor Author

Rebased after merge of #8930.

@sipa
Copy link
Member

sipa commented Nov 25, 2016

utACK 711fb0bb192e6b9a6ac8c53c35f12be6d7216df7

@morcos
Copy link
Contributor

morcos commented Nov 28, 2016

cautious ACK

This looks good to me, I code reviewed, and did some light testing. I was a bit hesitant about moving NotifyHeaderTip before the rest of the header processing, but that seems to be mostly async behavior.

@sdaftuar
Copy link
Member

utACK 711fb0b

@sipa
Copy link
Member

sipa commented Dec 1, 2016

@theuni Comments?


CBlockIndex *pindex = NULL;
CValidationState state;
if (!AcceptBlockHeader(cmpctblock.header, state, chainparams, &pindex)) {
if (!ProcessNewBlockHeaders({cmpctblock.header}, state, chainparams, &pindex)) { // We should call this without cs_main
Copy link
Member

Choose a reason for hiding this comment

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

same

@theuni
Copy link
Member

theuni commented Dec 1, 2016

utACK 711fb0bb192e6b9a6ac8c53c35f12be6d7216df7. The comment nits can be fixed later.

@TheBlueMatt
Copy link
Contributor Author

Fixed @theuni's documentation comments.

}
return error("invalid header received");
Copy link
Contributor

@jtimon jtimon Dec 1, 2016

Choose a reason for hiding this comment

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

maybe print the state here (ie use FormatStateMessage(state), maybe func too) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AcceptBlockHeader already does a bunch of printing. And while this could maybe be cleaned up, probably a topic for another PR, I think.


CBlockIndex *pindex = NULL;
CValidationState state;
if (!AcceptBlockHeader(cmpctblock.header, state, chainparams, &pindex)) {
if (!ProcessNewBlockHeaders({cmpctblock.header}, state, chainparams, &pindex)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why {} around cmpctblock.header ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the {} creates the vector that ProcessNewBlockHeaders takes, instead of a single header as AcceptBlockHeader does (note that it makes a copy of the header, but nbd, I think).

@jtimon
Copy link
Contributor

jtimon commented Dec 1, 2016

utACK 2c8c57e besides my little nits.

@sipa
Copy link
Member

sipa commented Dec 1, 2016

utACK 2c8c57e

@sipa sipa merged commit 2c8c57e into bitcoin:master Dec 2, 2016
sipa added a commit that referenced this pull request Dec 2, 2016
2c8c57e Document cs_main status when calling into PNB or PNBH (Matt Corallo)
58a215c Use ProcessNewBlockHeaders in CMPCTBLOCK processing (Matt Corallo)
a8b936d Use exposed ProcessNewBlockHeaders from ProcessMessages (Matt Corallo)
63fd101 Split ::HEADERS processing into two separate cs_main locks (Matt Corallo)
4a6b1f3 Expose AcceptBlockHeader through main.h (Matt Corallo)
}

CValidationState state;
if (!ProcessNewBlockHeaders(headers, state, chainparams, &pindexLast)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why name it such when the headers won't necessarily be new?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To mirror the naming of ProcessNewBlock.

codablock added a commit to codablock/dash that referenced this pull request Jan 17, 2018
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Feb 25, 2019
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants