Ok after further thought and offline discussion, I retract my objection to leaving the VALID_SCRIPTS check in.
My original concern was that there were some race conditions where we might announce a block pre-validation, and then never test the block’s validity, resulting in stalling block download to a peer for a valid block. After the change to only do pre-validation announcements for a single block at a given height and only for blocks that build on our tip, I think this is no longer an issue.
A secondary concern was generally figuring out how to handle block requests for invalid blocks. In the typical case of a cmpctblock announcement being followed by a getblocktxn request, I believe everything works as intended (a node would provide the blocktxn, and the peer would not punish if the block turned out to be invalid). However if a peer somehow fell back to a getdata request for that block, then this code would cause us to stall the peer’s block download, likely resulting in them disconnecting us.
The alternative, however, of delivering the block when we know it is invalid is potentially even worse – they would ban us, absent more code changes to handle this situation (which #9026 overlooked), which is a lot more code complexity.
I haven’t been able to come up with realistic scenarios where someone could provoke these conditions (ie, produce an invalid block in such a way as to also cause nodes to fall back to getdata responses to the cmpctblock announcement), so I think this is an acceptable behavior to introduce for now. In the future, though it would be nice to add a protocol extension so that we could have the option of telling our peer that a block request is being ignored, so that the peer could do something smarter than just disconnect us for stalling download.
To remind us, I think it’d be nice to add a comment in ProcessGetData()
that mentions this issue, something like:
0// TODO: extend the protocol to allow us to tell our peer that we're not going to deliver a block that we've previously announced, eg because we don't think the block is valid.
1// This would give allow our peer to be make a better decision than just wait indefinitely or disconnect us for stalling block download.