Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix sigops handling pre nov upgrade #51

Merged
merged 3 commits into from
Oct 12, 2018
Merged

[Fix] Fix sigops handling pre nov upgrade #51

merged 3 commits into from
Oct 12, 2018

Conversation

zquestz
Copy link
Contributor

@zquestz zquestz commented Oct 11, 2018

So I believe this should fix the sigops counts pre anomaly. I am not 100% sure this is right, and I had to pass around the flag a lot. Maybe I missed something.

Hopefully this is useful, if so we can write some tests. =)

Also if anyone wants to make changes, feel free to push to this branch.

Start of fix for #47

@cpacia
Copy link
Contributor

cpacia commented Oct 11, 2018

My node is syncing past the offending block with this patch

@tyler-smith
Copy link
Member

It seems pretty hacky to have to pass the boolean around for just this one fork. If/when other forks change behaviors in these functions we'll need to add booleans for them as well.

The txscript.Engine has a set of txscript.ScriptFlags which define which rules to enforce. It would great if we could leverage these here instead, but that would require the callers to know the current state of flags based on which fork criteria have been activated, or potentially reorged away, etc.

I haven't had a chance yet to go in further and estimate the feasibility of doing that. Obviously the current active flag set is known somewhere because the txscript.Engine uses them. But I don't know how accessible that is to all the callers of CheckTransactionSanity, CountSigOps, etc.

@@ -419,21 +419,21 @@ func CheckProofOfWork(block *bchutil.Block, powLimit *big.Int) error {
// input and output scripts in the provided transaction. This uses the
// quicker, but imprecise, signature operation counting mechanism from
// txscript.
func CountSigOps(tx *bchutil.Tx) int {
func CountSigOps(tx *bchutil.Tx, magneticAnomalyActive bool) int {
msgTx := tx.MsgTx()

// Accumulate the number of signature operations in all transaction
// inputs.
totalSigOps := 0
for _, txIn := range msgTx.TxIn {

Choose a reason for hiding this comment

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

Had a chat with Josh during the hackathon. I'm not sure if this is the right place, but sigops should not be counted for coinbase inputs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@zquestz zquestz Oct 12, 2018

Choose a reason for hiding this comment

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

I think the correct thing to do is only check the coinbase outputs. The input can be garbage. I think we hit an unlikely byte sequence and it randomly broke on this block. I want to try syncing with just coinbase input validation removed and see if that fixes the issue. Then we don't need to pass around booleans everywhere. The code for that would be MUCH cleaner if that worked.

https://bitcoin.stackexchange.com/questions/4990/what-is-the-format-of-coinbase-input-scripts

Copy link
Contributor Author

@zquestz zquestz Oct 12, 2018

Choose a reason for hiding this comment

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

Actually I take that back. We need the mining interface to be accurate, and if ABC is counting those sigops even when the coinbase input has garbage data then we need to be consistent. I can investigate the txScript.Engine suggestion as I agree passing a boolean is a bit dirty.

That being said, my node is now stuck, so if we merge this change set then it unblocks people to start syncing, and we can refactor it to use the flags approach which will be a much better solution long term.

What do you think @tyler-smith ?

@zquestz
Copy link
Contributor Author

zquestz commented Oct 12, 2018

It seems pretty hacky to have to pass the boolean around for just this one fork. If/when other forks change behaviors in these functions we'll need to add booleans for them as well.

The txscript.Engine has a set of txscript.ScriptFlags which define which rules to enforce. It would great if we could leverage these here instead, but that would require the callers to know the current state of flags based on which fork criteria have been activated, or potentially reorged away, etc.

I haven't had a chance yet to go in further and estimate the feasibility of doing that. Obviously the current active flag set is known somewhere because the txscript.Engine uses them. But I don't know how accessible that is to all the callers of CheckTransactionSanity, CountSigOps, etc.

I think that can happen when we need it. Looks like the coinbase input was the culprit and if we fix that then these changes won't be necessary yet. If we do need to adjust the counting logic later then we can investigate txscript.Engine. =)

@tyler-smith
Copy link
Member

@zquestz That sounds alright. It seems like we need to get some clarity from ABC on how exactly they're intending to handle coinbase tx sigop counts.

Copy link
Member

@tyler-smith tyler-smith left a comment

Choose a reason for hiding this comment

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

This looks correct and is tested.

Issue to track refactoring of the boolean flag for the fork is here: #52

@zquestz zquestz merged commit 8f5010a into master Oct 12, 2018
@zquestz zquestz deleted the sigops branch October 12, 2018 16:50
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.

None yet

4 participants