From 82fa8e6831349dc2230c67e2d71e11a016794008 Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Tue, 8 Dec 2020 17:17:30 +0200 Subject: [PATCH] Abstract CheckProofOfWork as a public function and change PoW structure (#1198) * Expose CheckProofOfWork from model/pow * Update blockvalidator to call the new CheckProofOfWork * Update genesis blocks * Update tools to use the new CheckProofOfWork * Update tests with new PoW --- cmd/kaspaminer/mineloop.go | 6 +- domain/consensus/model/pow/pow.go | 57 +++++++++++++++ .../processes/blockvalidator/proof_of_work.go | 16 ++--- .../dagtraversalmanager/window_test.go | 72 +++++++++---------- domain/consensus/utils/mining/solve.go | 6 +- domain/dagconfig/genesis.go | 46 ++++++------ testing/integration/mining_test.go | 7 +- 7 files changed, 127 insertions(+), 83 deletions(-) create mode 100644 domain/consensus/model/pow/pow.go diff --git a/cmd/kaspaminer/mineloop.go b/cmd/kaspaminer/mineloop.go index 26b38dd42..ffe554c78 100644 --- a/cmd/kaspaminer/mineloop.go +++ b/cmd/kaspaminer/mineloop.go @@ -2,13 +2,12 @@ package main import ( nativeerrors "errors" + "github.com/kaspanet/kaspad/domain/consensus/model/pow" "math/rand" "sync" "sync/atomic" "time" - "github.com/kaspanet/kaspad/domain/consensus/utils/hashes" - "github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing" "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" @@ -114,9 +113,8 @@ func solveBlock(block *externalapi.DomainBlock, stopChan chan struct{}, foundBlo return default: block.Header.Nonce = i - hash := consensushashing.BlockHash(block) atomic.AddUint64(&hashesTried, 1) - if hashes.ToBig(hash).Cmp(targetDifficulty) <= 0 { + if pow.CheckProofOfWorkWithTarget(block.Header, targetDifficulty) { foundBlock <- block return } diff --git a/domain/consensus/model/pow/pow.go b/domain/consensus/model/pow/pow.go new file mode 100644 index 000000000..7ac8b668a --- /dev/null +++ b/domain/consensus/model/pow/pow.go @@ -0,0 +1,57 @@ +package pow + +import ( + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + "github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing" + "github.com/kaspanet/kaspad/domain/consensus/utils/hashes" + "github.com/kaspanet/kaspad/domain/consensus/utils/serialization" + "github.com/kaspanet/kaspad/util" + "github.com/pkg/errors" + "math/big" +) + +// CheckProofOfWorkWithTarget check's if the block has a valid PoW according to the provided target +// it does not check if the difficulty itself is valid or less than the maximum for the appropriate network +func CheckProofOfWorkWithTarget(header *externalapi.DomainBlockHeader, target *big.Int) bool { + // The block pow must be less than the claimed target + powNum := calcPowValue(header) + + // The block hash must be less or equal than the claimed target. + return powNum.Cmp(target) <= 0 +} + +// CheckProofOfWorkByBits check's if the block has a valid PoW according to its Bits field +// it does not check if the difficulty itself is valid or less than the maximum for the appropriate network +func CheckProofOfWorkByBits(header *externalapi.DomainBlockHeader) bool { + return CheckProofOfWorkWithTarget(header, util.CompactToBig(header.Bits)) +} + +func calcPowValue(header *externalapi.DomainBlockHeader) *big.Int { + // Zero out the time and nonce. + timestamp, nonce := header.TimeInMilliseconds, header.Nonce + header.TimeInMilliseconds, header.Nonce = 0, 0 + + prePowHash := consensushashing.HeaderHash(header) + header.TimeInMilliseconds, header.Nonce = timestamp, nonce + + // PRE_POW_HASH || TIME || 32 zero byte padding || NONCE + writer := hashes.NewHashWriter() + _, err := writer.Write(prePowHash[:]) + if err != nil { + panic(errors.Wrap(err, "this should never happen. SHA256's digest should never return an error")) + } + err = serialization.WriteElement(writer, timestamp) + if err != nil { + panic(errors.Wrap(err, "this should never happen. SHA256's digest should never return an error")) + } + zeroes := [32]byte{} + _, err = writer.Write(zeroes[:]) + if err != nil { + panic(errors.Wrap(err, "this should never happen. SHA256's digest should never return an error")) + } + err = serialization.WriteElement(writer, nonce) + if err != nil { + panic(errors.Wrap(err, "this should never happen. SHA256's digest should never return an error")) + } + return hashes.ToBig(writer.Finalize()) +} diff --git a/domain/consensus/processes/blockvalidator/proof_of_work.go b/domain/consensus/processes/blockvalidator/proof_of_work.go index 896818159..8b29c7445 100644 --- a/domain/consensus/processes/blockvalidator/proof_of_work.go +++ b/domain/consensus/processes/blockvalidator/proof_of_work.go @@ -2,9 +2,8 @@ package blockvalidator import ( "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + "github.com/kaspanet/kaspad/domain/consensus/model/pow" "github.com/kaspanet/kaspad/domain/consensus/ruleerrors" - "github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing" - "github.com/kaspanet/kaspad/domain/consensus/utils/hashes" "github.com/kaspanet/kaspad/util" "github.com/pkg/errors" ) @@ -89,18 +88,13 @@ func (v *blockValidator) checkProofOfWork(header *externalapi.DomainBlockHeader) "higher than max of %064x", target, v.powMax) } - // The block hash must be less than the claimed target unless the flag - // to avoid proof of work checks is set. + // The block pow must be valid unless the flag to avoid proof of work checks is set. if !v.skipPoW { - // The block hash must be less than the claimed target. - hash := consensushashing.HeaderHash(header) - hashNum := hashes.ToBig(hash) - if hashNum.Cmp(target) > 0 { - return errors.Wrapf(ruleerrors.ErrUnexpectedDifficulty, "block hash of %064x is higher than "+ - "expected max of %064x", hashNum, target) + valid := pow.CheckProofOfWorkWithTarget(header, target) + if !valid { + return errors.Wrap(ruleerrors.ErrUnexpectedDifficulty, "block has invalid difficulty") } } - return nil } diff --git a/domain/consensus/processes/dagtraversalmanager/window_test.go b/domain/consensus/processes/dagtraversalmanager/window_test.go index f22af38dd..2f878ceef 100644 --- a/domain/consensus/processes/dagtraversalmanager/window_test.go +++ b/domain/consensus/processes/dagtraversalmanager/window_test.go @@ -36,12 +36,12 @@ func TestBlueBlockWindow(t *testing.T) { { parents: []string{"D", "C"}, id: "E", - expectedWindowWithGenesisPadding: []string{"D", "C", "B", "A", "A", "A", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"C", "D", "B", "A", "A", "A", "A", "A", "A", "A"}, }, { parents: []string{"D", "C"}, id: "F", - expectedWindowWithGenesisPadding: []string{"D", "C", "B", "A", "A", "A", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"C", "D", "B", "A", "A", "A", "A", "A", "A", "A"}, }, { parents: []string{"A"}, @@ -56,37 +56,37 @@ func TestBlueBlockWindow(t *testing.T) { { parents: []string{"H", "F"}, id: "I", - expectedWindowWithGenesisPadding: []string{"F", "D", "H", "C", "B", "G", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"F", "C", "H", "D", "B", "G", "A", "A", "A", "A"}, }, { parents: []string{"I"}, id: "J", - expectedWindowWithGenesisPadding: []string{"I", "F", "D", "H", "C", "B", "G", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"I", "F", "C", "H", "D", "B", "G", "A", "A", "A"}, }, { parents: []string{"J"}, id: "K", - expectedWindowWithGenesisPadding: []string{"J", "I", "F", "D", "H", "C", "B", "G", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"J", "I", "F", "C", "H", "D", "B", "G", "A", "A"}, }, { parents: []string{"K"}, id: "L", - expectedWindowWithGenesisPadding: []string{"K", "J", "I", "F", "D", "H", "C", "B", "G", "A"}, + expectedWindowWithGenesisPadding: []string{"K", "J", "I", "F", "C", "H", "D", "B", "G", "A"}, }, { parents: []string{"L"}, id: "M", - expectedWindowWithGenesisPadding: []string{"L", "K", "J", "I", "F", "D", "H", "C", "B", "G"}, + expectedWindowWithGenesisPadding: []string{"L", "K", "J", "I", "F", "C", "H", "D", "B", "G"}, }, { parents: []string{"M"}, id: "N", - expectedWindowWithGenesisPadding: []string{"M", "L", "K", "J", "I", "F", "D", "H", "C", "B"}, + expectedWindowWithGenesisPadding: []string{"M", "L", "K", "J", "I", "F", "C", "H", "D", "B"}, }, { parents: []string{"N"}, id: "O", - expectedWindowWithGenesisPadding: []string{"N", "M", "L", "K", "J", "I", "F", "D", "H", "C"}, + expectedWindowWithGenesisPadding: []string{"N", "M", "L", "K", "J", "I", "F", "C", "H", "D"}, }, }, "kaspa-testnet": { @@ -108,12 +108,12 @@ func TestBlueBlockWindow(t *testing.T) { { parents: []string{"D", "C"}, id: "E", - expectedWindowWithGenesisPadding: []string{"C", "D", "B", "A", "A", "A", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"D", "C", "B", "A", "A", "A", "A", "A", "A", "A"}, }, { parents: []string{"D", "C"}, id: "F", - expectedWindowWithGenesisPadding: []string{"C", "D", "B", "A", "A", "A", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"D", "C", "B", "A", "A", "A", "A", "A", "A", "A"}, }, { parents: []string{"A"}, @@ -128,37 +128,37 @@ func TestBlueBlockWindow(t *testing.T) { { parents: []string{"H", "F"}, id: "I", - expectedWindowWithGenesisPadding: []string{"F", "C", "H", "D", "B", "G", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"F", "D", "C", "H", "G", "B", "A", "A", "A", "A"}, }, { parents: []string{"I"}, id: "J", - expectedWindowWithGenesisPadding: []string{"I", "F", "C", "H", "D", "B", "G", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"I", "F", "D", "C", "H", "G", "B", "A", "A", "A"}, }, { parents: []string{"J"}, id: "K", - expectedWindowWithGenesisPadding: []string{"J", "I", "F", "C", "H", "D", "B", "G", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"J", "I", "F", "D", "C", "H", "G", "B", "A", "A"}, }, { parents: []string{"K"}, id: "L", - expectedWindowWithGenesisPadding: []string{"K", "J", "I", "F", "C", "H", "D", "B", "G", "A"}, + expectedWindowWithGenesisPadding: []string{"K", "J", "I", "F", "D", "C", "H", "G", "B", "A"}, }, { parents: []string{"L"}, id: "M", - expectedWindowWithGenesisPadding: []string{"L", "K", "J", "I", "F", "C", "H", "D", "B", "G"}, + expectedWindowWithGenesisPadding: []string{"L", "K", "J", "I", "F", "D", "C", "H", "G", "B"}, }, { parents: []string{"M"}, id: "N", - expectedWindowWithGenesisPadding: []string{"M", "L", "K", "J", "I", "F", "C", "H", "D", "B"}, + expectedWindowWithGenesisPadding: []string{"M", "L", "K", "J", "I", "F", "D", "C", "H", "G"}, }, { parents: []string{"N"}, id: "O", - expectedWindowWithGenesisPadding: []string{"N", "M", "L", "K", "J", "I", "F", "C", "H", "D"}, + expectedWindowWithGenesisPadding: []string{"N", "M", "L", "K", "J", "I", "F", "D", "C", "H"}, }, }, "kaspa-devnet": { @@ -180,12 +180,12 @@ func TestBlueBlockWindow(t *testing.T) { { parents: []string{"C", "D"}, id: "E", - expectedWindowWithGenesisPadding: []string{"C", "D", "B", "A", "A", "A", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"D", "C", "B", "A", "A", "A", "A", "A", "A", "A"}, }, { parents: []string{"C", "D"}, id: "F", - expectedWindowWithGenesisPadding: []string{"C", "D", "B", "A", "A", "A", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"D", "C", "B", "A", "A", "A", "A", "A", "A", "A"}, }, { parents: []string{"A"}, @@ -200,37 +200,37 @@ func TestBlueBlockWindow(t *testing.T) { { parents: []string{"H", "F"}, id: "I", - expectedWindowWithGenesisPadding: []string{"F", "C", "H", "D", "B", "G", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"F", "D", "H", "C", "G", "B", "A", "A", "A", "A"}, }, { parents: []string{"I"}, id: "J", - expectedWindowWithGenesisPadding: []string{"I", "F", "C", "H", "D", "B", "G", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"I", "F", "D", "H", "C", "G", "B", "A", "A", "A"}, }, { parents: []string{"J"}, id: "K", - expectedWindowWithGenesisPadding: []string{"J", "I", "F", "C", "H", "D", "B", "G", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"J", "I", "F", "D", "H", "C", "G", "B", "A", "A"}, }, { parents: []string{"K"}, id: "L", - expectedWindowWithGenesisPadding: []string{"K", "J", "I", "F", "C", "H", "D", "B", "G", "A"}, + expectedWindowWithGenesisPadding: []string{"K", "J", "I", "F", "D", "H", "C", "G", "B", "A"}, }, { parents: []string{"L"}, id: "M", - expectedWindowWithGenesisPadding: []string{"L", "K", "J", "I", "F", "C", "H", "D", "B", "G"}, + expectedWindowWithGenesisPadding: []string{"L", "K", "J", "I", "F", "D", "H", "C", "G", "B"}, }, { parents: []string{"M"}, id: "N", - expectedWindowWithGenesisPadding: []string{"M", "L", "K", "J", "I", "F", "C", "H", "D", "B"}, + expectedWindowWithGenesisPadding: []string{"M", "L", "K", "J", "I", "F", "D", "H", "C", "G"}, }, { parents: []string{"N"}, id: "O", - expectedWindowWithGenesisPadding: []string{"N", "M", "L", "K", "J", "I", "F", "C", "H", "D"}, + expectedWindowWithGenesisPadding: []string{"N", "M", "L", "K", "J", "I", "F", "D", "H", "C"}, }, }, "kaspa-simnet": { @@ -252,12 +252,12 @@ func TestBlueBlockWindow(t *testing.T) { { parents: []string{"C", "D"}, id: "E", - expectedWindowWithGenesisPadding: []string{"D", "C", "B", "A", "A", "A", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"C", "D", "B", "A", "A", "A", "A", "A", "A", "A"}, }, { parents: []string{"C", "D"}, id: "F", - expectedWindowWithGenesisPadding: []string{"D", "C", "B", "A", "A", "A", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"C", "D", "B", "A", "A", "A", "A", "A", "A", "A"}, }, { parents: []string{"A"}, @@ -272,37 +272,37 @@ func TestBlueBlockWindow(t *testing.T) { { parents: []string{"H", "F"}, id: "I", - expectedWindowWithGenesisPadding: []string{"F", "D", "C", "H", "B", "G", "A", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"F", "C", "D", "H", "B", "G", "A", "A", "A", "A"}, }, { parents: []string{"I"}, id: "J", - expectedWindowWithGenesisPadding: []string{"I", "F", "D", "C", "H", "B", "G", "A", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"I", "F", "C", "D", "H", "B", "G", "A", "A", "A"}, }, { parents: []string{"J"}, id: "K", - expectedWindowWithGenesisPadding: []string{"J", "I", "F", "D", "C", "H", "B", "G", "A", "A"}, + expectedWindowWithGenesisPadding: []string{"J", "I", "F", "C", "D", "H", "B", "G", "A", "A"}, }, { parents: []string{"K"}, id: "L", - expectedWindowWithGenesisPadding: []string{"K", "J", "I", "F", "D", "C", "H", "B", "G", "A"}, + expectedWindowWithGenesisPadding: []string{"K", "J", "I", "F", "C", "D", "H", "B", "G", "A"}, }, { parents: []string{"L"}, id: "M", - expectedWindowWithGenesisPadding: []string{"L", "K", "J", "I", "F", "D", "C", "H", "B", "G"}, + expectedWindowWithGenesisPadding: []string{"L", "K", "J", "I", "F", "C", "D", "H", "B", "G"}, }, { parents: []string{"M"}, id: "N", - expectedWindowWithGenesisPadding: []string{"M", "L", "K", "J", "I", "F", "D", "C", "H", "B"}, + expectedWindowWithGenesisPadding: []string{"M", "L", "K", "J", "I", "F", "C", "D", "H", "B"}, }, { parents: []string{"N"}, id: "O", - expectedWindowWithGenesisPadding: []string{"N", "M", "L", "K", "J", "I", "F", "D", "C", "H"}, + expectedWindowWithGenesisPadding: []string{"N", "M", "L", "K", "J", "I", "F", "C", "D", "H"}, }, }, } diff --git a/domain/consensus/utils/mining/solve.go b/domain/consensus/utils/mining/solve.go index 39b969d2f..f5274f7b0 100644 --- a/domain/consensus/utils/mining/solve.go +++ b/domain/consensus/utils/mining/solve.go @@ -1,12 +1,11 @@ package mining import ( + "github.com/kaspanet/kaspad/domain/consensus/model/pow" "math" "math/rand" "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" - "github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing" - "github.com/kaspanet/kaspad/domain/consensus/utils/hashes" utilsMath "github.com/kaspanet/kaspad/domain/consensus/utils/math" "github.com/pkg/errors" ) @@ -17,8 +16,7 @@ func SolveBlock(block *externalapi.DomainBlock, rd *rand.Rand) { for i := rd.Uint64(); i < math.MaxUint64; i++ { block.Header.Nonce = i - hash := consensushashing.BlockHash(block) - if hashes.ToBig(hash).Cmp(targetDifficulty) <= 0 { + if pow.CheckProofOfWorkWithTarget(block.Header, targetDifficulty) { return } } diff --git a/domain/dagconfig/genesis.go b/domain/dagconfig/genesis.go index 577e37b49..2b3b1c604 100644 --- a/domain/dagconfig/genesis.go +++ b/domain/dagconfig/genesis.go @@ -28,10 +28,10 @@ var genesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(1, []*externa // genesisHash is the hash of the first block in the block DAG for the main // network (genesis block). var genesisHash = externalapi.DomainHash{ - 0xbb, 0xc1, 0x88, 0xdd, 0x56, 0x9d, 0x46, 0xbd, - 0x36, 0xb0, 0x31, 0x52, 0x49, 0x93, 0xac, 0x70, - 0x1d, 0x36, 0xf1, 0xb3, 0xd2, 0x2f, 0xe5, 0x51, - 0x7c, 0x8b, 0x1a, 0xaf, 0x3c, 0x82, 0x6f, 0x18, + 0xfe, 0x18, 0xeb, 0xc3, 0x20, 0xe2, 0xdf, 0x7b, + 0xf5, 0x62, 0x27, 0xe4, 0x8c, 0x32, 0xdd, 0x06, + 0x19, 0xe2, 0xf9, 0xb1, 0xef, 0xf4, 0x96, 0x38, + 0x6b, 0x1f, 0x11, 0xba, 0x0b, 0x9f, 0x92, 0xa8, } // genesisMerkleRoot is the hash of the first transaction in the genesis block @@ -52,7 +52,7 @@ var genesisBlock = externalapi.DomainBlock{ HashMerkleRoot: genesisMerkleRoot, AcceptedIDMerkleRoot: externalapi.DomainHash{}, UTXOCommitment: externalapi.DomainHash{}, - TimeInMilliseconds: 0x175bc9e305a, + TimeInMilliseconds: 0x1763db5c4a9, Bits: 0x207fffff, Nonce: 0x0, }, @@ -79,10 +79,10 @@ var devnetGenesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(1, // devGenesisHash is the hash of the first block in the block DAG for the development // network (genesis block). var devnetGenesisHash = externalapi.DomainHash{ - 0x92, 0xb5, 0x28, 0xd3, 0xaa, 0x6d, 0x8b, 0x30, - 0x49, 0x19, 0x53, 0x6f, 0x62, 0xce, 0x9a, 0x82, - 0x2f, 0x91, 0xd4, 0x33, 0x24, 0xbc, 0x39, 0xe6, - 0xad, 0x53, 0xe3, 0x97, 0x5f, 0x03, 0x00, 0x00, + 0x13, 0x2d, 0xfc, 0xf3, 0xcf, 0x03, 0xfb, 0x21, + 0x30, 0xb8, 0x67, 0x79, 0xbc, 0x2e, 0x18, 0x4e, + 0x08, 0xd7, 0xeb, 0xf7, 0xb6, 0x86, 0x3c, 0x3e, + 0xe0, 0x8c, 0x8d, 0x02, 0x3c, 0xfd, 0xfe, 0x66, } // devnetGenesisMerkleRoot is the hash of the first transaction in the genesis block @@ -103,9 +103,9 @@ var devnetGenesisBlock = externalapi.DomainBlock{ HashMerkleRoot: devnetGenesisMerkleRoot, AcceptedIDMerkleRoot: externalapi.DomainHash{}, UTXOCommitment: externalapi.DomainHash{}, - TimeInMilliseconds: 0x175bca27b7f, + TimeInMilliseconds: 0x1763db5c4a9, Bits: 0x1e7fffff, - Nonce: 0x1a9ba, + Nonce: 0x281ad, }, Transactions: []*externalapi.DomainTransaction{devnetGenesisCoinbaseTx}, } @@ -129,10 +129,10 @@ var simnetGenesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(1, // simnetGenesisHash is the hash of the first block in the block DAG for // the simnet (genesis block). var simnetGenesisHash = externalapi.DomainHash{ - 0x84, 0x96, 0x38, 0xb6, 0x5c, 0x44, 0xc0, 0xb9, - 0x3c, 0x48, 0x03, 0x7c, 0x2e, 0xee, 0x0a, 0xbf, - 0xfb, 0x54, 0xc8, 0x5f, 0x99, 0xd6, 0x21, 0x3d, - 0x3f, 0xdd, 0xac, 0xb1, 0xe7, 0x30, 0x7e, 0x05, + 0xda, 0xcc, 0x82, 0xd2, 0xf2, 0x53, 0x49, 0x48, + 0x18, 0x9e, 0x08, 0x8f, 0xd3, 0xe1, 0xbc, 0xce, + 0xb6, 0x0d, 0x48, 0xa6, 0x51, 0x53, 0xe1, 0xc1, + 0xa7, 0xa7, 0x10, 0x8a, 0xde, 0x96, 0xa3, 0x4d, } // simnetGenesisMerkleRoot is the hash of the first transaction in the genesis block @@ -153,9 +153,9 @@ var simnetGenesisBlock = externalapi.DomainBlock{ HashMerkleRoot: simnetGenesisMerkleRoot, AcceptedIDMerkleRoot: externalapi.DomainHash{}, UTXOCommitment: externalapi.DomainHash{}, - TimeInMilliseconds: 0x175bca27c39, + TimeInMilliseconds: 0x1763db5c5de, Bits: 0x207fffff, - Nonce: 0x1, + Nonce: 0x0, }, Transactions: []*externalapi.DomainTransaction{simnetGenesisCoinbaseTx}, } @@ -177,10 +177,10 @@ var testnetGenesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(1, // testnetGenesisHash is the hash of the first block in the block DAG for the test // network (genesis block). var testnetGenesisHash = externalapi.DomainHash{ - 0xa9, 0xbe, 0xa7, 0xd9, 0x0f, 0xd2, 0xbd, 0xfb, - 0xd8, 0x09, 0x4d, 0x6a, 0x49, 0xa7, 0x59, 0x93, - 0xd1, 0x35, 0xce, 0x61, 0x18, 0x07, 0x0b, 0xe6, - 0xb9, 0xec, 0xad, 0x68, 0xe4, 0x2d, 0x00, 0x00, + 0x97, 0xb5, 0xd5, 0xf6, 0x0d, 0xfe, 0x77, 0x83, + 0x87, 0xe8, 0x06, 0x52, 0xd5, 0xbe, 0xd2, 0x5e, + 0x92, 0x5a, 0x70, 0x03, 0x2b, 0x7a, 0x75, 0x5c, + 0xc5, 0xe4, 0x73, 0xa0, 0x23, 0x47, 0x25, 0x2f, } // testnetGenesisMerkleRoot is the hash of the first transaction in the genesis block @@ -201,9 +201,9 @@ var testnetGenesisBlock = externalapi.DomainBlock{ HashMerkleRoot: testnetGenesisMerkleRoot, AcceptedIDMerkleRoot: externalapi.DomainHash{}, UTXOCommitment: externalapi.DomainHash{}, - TimeInMilliseconds: 0x175bcac06ec, + TimeInMilliseconds: 0x1763db5c5de, Bits: 0x1e7fffff, - Nonce: 0x568f, + Nonce: 0xec6f, }, Transactions: []*externalapi.DomainTransaction{testnetGenesisCoinbaseTx}, } diff --git a/testing/integration/mining_test.go b/testing/integration/mining_test.go index 6b6fa77b1..1fecb839c 100644 --- a/testing/integration/mining_test.go +++ b/testing/integration/mining_test.go @@ -1,15 +1,13 @@ package integration import ( + "github.com/kaspanet/kaspad/domain/consensus/model/pow" "math/rand" "testing" "github.com/kaspanet/kaspad/app/appmessage" "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" - "github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing" - "github.com/kaspanet/kaspad/domain/consensus/utils/hashes" - "github.com/kaspanet/kaspad/util" ) @@ -18,8 +16,7 @@ func solveBlock(block *externalapi.DomainBlock) *externalapi.DomainBlock { initialNonce := rand.Uint64() for i := initialNonce; i != initialNonce-1; i++ { block.Header.Nonce = i - hash := consensushashing.BlockHash(block) - if hashes.ToBig(hash).Cmp(targetDifficulty) <= 0 { + if pow.CheckProofOfWorkWithTarget(block.Header, targetDifficulty) { return block } }