Skip to content

net processing: Remove hash and fValidatedHeaders from QueuedBlock - #22141

Merged
laanwj merged 8 commits into
bitcoin:masterfrom
jnewbery:2021-06-blocks-in-flight
Jun 10, 2021
Merged

laanwj merged 8 commits into
bitcoin:masterfrom
jnewbery:2021-06-blocks-in-flight

Conversation

@jnewbery

@jnewbery jnewbery commented Jun 3, 2021

Copy link
Copy Markdown
Contributor

The QueuedBlock struct contains a fValidatedHeaders field that indicates whether we have already validated a header for the requested block. Since headers-first syncing, we only request blocks where the header is already validated, so fValidatedHeaders is always true. Remove it and clean up the logic that uses that field.

Likewise, QueuedBlock contains a hash field that is set to the block hash. Since headers-first syncing, we always have a CBlockIndex, which contains the block hash, so remove the redundant hash field.

Tidy up the logic and rename functions to better indicate what they're doing.

jnewbery added 8 commits June 3, 2021 12:39
MarkBlockAsInFlight is always called with a non-null pindex. Just get the block hash
from that pindex inside the function.
Since headers-first syncing, we only ever request a block if we've already validated its headers.
Therefore QueuedBlock.fValidatedHeaders is always set to true. Remove it.
nBlocksInFlightValidHeaders always has the same value as nBlocksInFlight, since we only download
blocks with valid headers.
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); }

ren nPeersWithValidatedDownloads  m_peers_downloading_from
-END VERIFY SCRIPT-
It's redundant with CBlockIndex::GetBlockHash()
MarkBlockAsReceived() should not be used for both removing the block
from mapBlocksInFlight and checking whether it was in the map.
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); }

ren  MarkBlockAsInFlight BlockRequested
ren  MarkBlockAsReceived RemoveBlockRequest
-END VERIFY SCRIPT-
@fanquake fanquake added the P2P label Jun 3, 2021
@DrahtBot

DrahtBot commented Jun 4, 2021 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@sipa sipa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

utACK 2f4ad6b

Very nice cleanup.

Comment thread src/net_processing.cpp Resolved
Comment thread src/net_processing.cpp Resolved
Comment thread src/net_processing.cpp Resolved
@practicalswift

Copy link
Copy Markdown
Contributor

Concept ACK

@mjdietzx

mjdietzx commented Jun 7, 2021

Copy link
Copy Markdown
Contributor

crACK 2f4ad6b

@jnewbery

jnewbery commented Jun 9, 2021

Copy link
Copy Markdown
Contributor Author

Thanks for the review @mjdietzx. I've answered your review questions. Feel free to ask more if there's anything that's still unclear about this PR.

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

review ACK 2f4ad6b 📊

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK 2f4ad6b7efa408b8a858e87499bf6cfcdf936d73 📊
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUhXzwv9HniRZ2DZea8vtfP9W0XCvKLSaLzohfoLcy8LV+kuq0kzasQQWYfqy6s+
9ZUkOV/pxBsrl55Pfk/MvhbHOMw2t4Y/2RP7foRm/GZVbF2W5eMkg58L3R0CIXsi
k4/dxINftIkNObRMtsYSjNWBwVaYiMHbAB8CHYH+B43/yE3otQ8QweT8IG7/r9VV
ZWSkw9P2Z7tUQw9FeiaOYxteDK/W+dxec0m3+iIvOJeloc/UHKXM+wI15E/KoSK/
S9ttkHCRzius/M3a54JqmgkA73vnDwcjQe7NLVphl2f/UbIgf2cE2PH/BIiL4k72
tNye+KKxMqknxsdMRjQXVs6biQp2crxu/pNSUS5kw6z6vvb0SQgF6zZtWzs2c77D
1r+Zo0eHhzxyLodbxwgtZzZmr5HvMzHMnAqhp/7aDWTqpeGRYeGC0Klqko9wXipB
dxs8nre5S/5XnJHt5DJ3DHiVLRGk0g7xldCDrv0A2KAJOI8whbHt8aEp1SojfM5I
0eVnuNvO
=itrW
-----END PGP SIGNATURE-----

Timestamp of file with hash f0a6a932acf4e1e73bf07c8f0433dd6b510a91f4061198f5afafddba6da52c6d -

Comment thread src/net_processing.cpp Resolved
@DrahtBot DrahtBot mentioned this pull request Jun 9, 2021
10 of 18 tasks
@laanwj
laanwj merged commit 1704bbf into bitcoin:master Jun 10, 2021
@jnewbery
jnewbery deleted the 2021-06-blocks-in-flight branch June 10, 2021 15:11
@Sjors Sjors mentioned this pull request Jun 10, 2021
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants