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

multi: Enforce testnet difficulty throttling. #2978

Merged

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Aug 2, 2022

Currently, version 3 of the test network implements a minimum difficulty reduction rule that was inherited from btcsuite which intends to act as mechanism to deal with major difficulty spikes due to ASICs which are typically not running testnet and since it's not reasonable to require high-powered hardware to keep the test network running smoothly.

Unfortunately, this existing rule is not a particularly good solution in general as it is not very deterministic and introduces additional complications around difficulty selection. It is an even worse solution in the the case of Decred due to its hybrid model.

Rather than the aforementioned reactive approach, this introduces more deterministic proactive testnet rules in order limit the type of games that ASICs can play on testnet.

In particular, two new rules are introduced that are only imposed starting with block height 962928:

  • A maximum allowed difficulty is now imposed on testnet such that CPU mining will still be feasible without resorting to any type of reactive and more complicated difficulty dropping
  • Once the maximum allowed difficulty is reached on testnet, blocks must be at least 1 minute apart

The combination of these rules will prevent the difficulty on testnet from ever rising to levels that are out of reach for CPUs to continue mining blocks and throttle production in the case of higher-powered hardware such as GPUs and ASICs.

It should be noted that this solution is only suitable on a test network where no real monetary value is in play and thus the typical game theory mechanics do not apply.

Code to invalidate the existing extremely high work testnet chain which has stalled testnet after that point is added to allow the test network to be recovered without needing to fire up a bunch of ASICs.

Finally, this includes several other commits which improve the handling of mining and syncing when the new rules are enforced.

@davecgh davecgh added this to the 1.8.0 milestone Aug 2, 2022
@davecgh davecgh force-pushed the multi_enforce_testnet_diff_throttling branch 3 times, most recently from c292121 to 3a06a22 Compare August 2, 2022 11:49
internal/rpcserver/rpcserver.go Show resolved Hide resolved
internal/netsync/manager.go Show resolved Hide resolved
internal/blockchain/difficulty.go Show resolved Hide resolved

// block962928Hash is the hash of the checkpoint used to activate maximum
// difficulty semantics on the version 3 test network.
block962928Hash = mustParseHash("0000004fd1b267fd39111d456ff557137824538e6f6776168600e56002e23b93")
Copy link
Member

Choose a reason for hiding this comment

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

Confirmed.

internal/blockchain/validate.go Outdated Show resolved Hide resolved
@davecgh davecgh force-pushed the multi_enforce_testnet_diff_throttling branch 6 times, most recently from 0a52504 to b8c99fc Compare August 3, 2022 01:28
Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

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

Tested fairly thoroughly. (the 1.7 backport however)

This makes the calcNextRequiredDifficulty method a little more
consistent with the code in terms of the name of the parameter and using
a shorter local convenience var to avoid overly long lines.
This modifies the template generation code in the case an alterative
block building on the parent of the current tip is needed due to lack of
votes to also copy the regular transactions from the current tip in
addition to the stake transactions.

This is useful because it helps make it the template creation logic more
robust in the case of duplicate spends and also helps ensure all of the
same transactions, such as split transactions make it into the new
alternative block templates.
This modifies the RPC server getwork method to return an error in the
case of a failed background template.  Callers generally expect an error
as opposed to long blocking behavior in the case there is a temporary
reason block templates are unable to be generated.

Also, correct the offsets in the comments regarding the serialized
locations of the fields while here.
This modifies the behavior that notifies RPC clients about winning
tickets when blocks are connected to send the notification even when the
chain is not considered current in the case the --allowunsyncedmining
CLI option is set.
This modifies the sync manager to update the sync height in the
following additional cases to improve its accuracy:

- When a block that is higher than the current known sync height is
  processed and connected to the main chain
- When a header fails to connect during the initial header sync process
Currently, version 3 of the test network implements a minimum difficulty
reduction rule that was inherited from btcsuite which intends to act as
mechanism to deal with major difficulty spikes due to ASICs which are
typically not running testnet and since it's not reasonable to require
high-powered hardware to keep the test network running smoothly.

Unfortunately, this existing rule is not a particularly good solution in
general as it is not very deterministic and introduces additional
complications around difficulty selection.  It is an even worse solution
in the the case of Decred due to its hybrid model.

Rather than the aforementioned reactive approach, this introduces more
deterministic proactive testnet rules in order limit the type of games
that ASICs can play on testnet.

In particular, two new rules are introduced that are only imposed
started with block height 962928:

- A maximum allowed difficulty is now imposed on testnet such that
  CPU mining will still be feasible without resorting to any type of
  reactive and more complicated difficulty dropping
- Once the maximum allowed difficulty is reached on testnet, blocks must
  be at least 1 minute apart

The combination of these rules will prevent the difficulty on testnet
from ever rising to levels that are out of reach for CPUs to continue
mining blocks and throttle production in the case of higher-powered
hardware such as GPUs and ASICs.

It should be noted that this solution is only suitable on a test network
where no real monetary value is in play and thus the typical game theory
mechanics do not apply.

Finally, code to invalidate the existing extremely high work testnet
chain which has stalled testnet after that point is added to allow
the test network to be recovered without needing to fire up a bunch of
ASICs.
This deprecates the ReduceMinDifficulty and MinDiffReductionTime
parameters since they will no longer apply to testnet version 3 after
activation of the maximum difficulty rules nor any future versions of
testnet.
@davecgh davecgh force-pushed the multi_enforce_testnet_diff_throttling branch from b8c99fc to 46ab52d Compare August 3, 2022 16:56
@davecgh davecgh merged commit 46ab52d into decred:master Aug 3, 2022
@davecgh davecgh deleted the multi_enforce_testnet_diff_throttling branch August 3, 2022 17:15
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

3 participants