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

Validate that blocks satisfy either V1 or V2 PoW #2240

Merged
merged 1 commit into from Jun 8, 2023
Merged

Conversation

jrick
Copy link
Member

@jrick jrick commented Jun 6, 2023

This includes a port of dcrd's positional difficulty check. This check replaces
the check that difficulty bits match the expected difficulty when always
calculated using the original difficulty algorithm used since Decred launch.

The vote version has been bumped to enable voting on the new agendas.

This requires dependency updates in wire and blockchain/standalone in order to
create Blake3 PoW hashes and calculate the ASERT difficulty.

@jrick jrick marked this pull request as draft June 6, 2023 20:34
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

I haven't tested this yet, but it reads correctly.

wallet/difficulty.go Show resolved Hide resolved
wallet/difficulty.go Outdated Show resolved Hide resolved
@jrick jrick marked this pull request as ready for review June 7, 2023 18:00
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

I've tested this including both when simnet/testnet are forced active and by voting the agenda in on simnet. For the test involving voting the agenda in, I also tested for potential off by ones around the activation point.

Details:

I used the following dcrd and dcrwallet diffs in order to achieve the voting in the agenda on simnet:

dcrd:

diff --git a/chaincfg/simnetparams.go b/chaincfg/simnetparams.go
index cbd785d12..380ac11e1 100644
--- a/chaincfg/simnetparams.go
+++ b/chaincfg/simnetparams.go
@@ -460,7 +460,7 @@ func SimNetParams() *Params {
                                                IsNo:        false,
                                        }},
                                },
-                               ForcedChoiceID: "yes",
+                               // ForcedChoiceID: "yes",         // TODO(davec): Don't commit
                                StartTime:      0,             // Always available for vote
                                ExpireTime:     math.MaxInt64, // Never expires
                        }, {
diff --git a/internal/mining/mining.go b/internal/mining/mining.go
index 8e313938e..f473fcbb3 100644
--- a/internal/mining/mining.go
+++ b/internal/mining/mining.go
@@ -268,7 +268,7 @@ const (

        // generatedBlockVersionTest is the version of the block being generated
        // for networks other than the main network.
-       generatedBlockVersionTest = 10
+       generatedBlockVersionTest = 11 // TODO(davec): Don't commit

        // blockHeaderOverhead is the max number of bytes it takes to serialize
        // a block header and max possible transaction count.

dcrwallet:

diff --git a/go.mod b/go.mod
index e5ca79a7..363cd225 100644
--- a/go.mod
+++ b/go.mod
@@ -44,6 +44,7 @@ require (

 replace (
        github.com/decred/dcrd/blockchain/stake/v5 => github.com/decred/dcrd/blockchain/stake/v5 v5.0.0-20221022042529-0a0cc3b3bf92
+       github.com/decred/dcrd/chaincfg/v3 => ../dcrd/chaincfg
        github.com/decred/dcrd/gcs/v4 => github.com/decred/dcrd/gcs/v4 v4.0.0-20221022042529-0a0cc3b3bf92
 )
  • From within the simnet harness, configure wallet1 to vote yes for the agenda:
wallet1$ ./ctl setvotechoice blake3pow yes
  • Mine enough blocks via dcrd1 to reach just one block prior to the agenda activating and confirm the agenda isn't active yet:
dcrd1$ ./mine 1071
dcrd1$ ./ctl getblockchaininfo | jq -c '.deployments.blake3pow | {status,since}'
{"status":"lockedin","since":784}
  • Nuke the existing wallet2 and create it fresh to test wallet syncing from scratch:
...
[INF] SYNC: Fetched 1103 new header(s) ending at height 1103 from wss://127.0.0.1:19566/ws
[INF] SYNC: Connected 1103 blocks, new tip block 41bac38323dab68493ae624b6d665fea7d70b7902b5426dc50a6c4fae1bd1978, height 1103, date 2023-06-07 15:19:46 -0500 CDT
...
[INF] WLLT: Rescanning block range [1, 1103]...
...
WLLT: Rescan complete
SYNC: Blockchain sync completed, wallet ready for general usage.
  • Mine another block via dcrd1 to activate the agenda and confirm it's now active:
dcrd1$ ./mine
dcrd1$ ./ctl getblockchaininfo | jq -c '.deployments.blake3pow | {status,since}'
{"status":"active","since":1104}
  • Confirm wallet1 and wallet2 are both at the activated tip:
wallet1$ ./ctl getinfo | jq .blocks
1104
wallet2$ ./ctl getinfo | jq .blocks
1104
  • Mine another block via dcrd1 to activate the agenda and confirm it's now active:
dcrd1$ ./mine
dcrd1$ ./ctl getblockchaininfo | jq -c '.deployments.blake3pow | {status,since}'
{"status":"active","since":1104}
  • Mine a couple more blocks via dcrd1 and ensure the wallets continue to vote and track the tip:
dcrd1$ ./mine 2
walllet1$ ./ctl getinfo | jq .blocks
1106
walllet2$ ./ctl getinfo | jq .blocks
1106

This includes a port of dcrd's positional difficulty check.  This check replaces
the check that difficulty bits match the expected difficulty when always
calculated using the original difficulty algorithm used since Decred launch.

The vote version has been bumped to enable voting on the new agendas.

This requires dependency updates in wire and blockchain/standalone in order to
create Blake3 PoW hashes and calculate the ASERT difficulty.
@jrick jrick merged commit 3a52f00 into decred:master Jun 8, 2023
2 checks passed
@jrick jrick deleted the dcp0011 branch June 8, 2023 16:32
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

2 participants