From d9a81b2a84b1e82374c0aa82425e578b0b0404c0 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Mon, 8 Oct 2018 12:14:18 +0300 Subject: [PATCH] [DEV-193] Invert previous blocks order to be from low hash to high hash (#84) * [DEV-189] invert arguments order or daghash.Less * [DEV-189] invert arguments order of daghash.Less in blockset.highest * [DEV-189] change to equivalent condition in Hash.Less to make it prettier * [DEV-194] change prevblocks order to be from low hash to high hash --- blockdag/dag_test.go | 2 +- blockdag/validate_test.go | 50 ++++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/blockdag/dag_test.go b/blockdag/dag_test.go index 191818cb6..177a3941e 100644 --- a/blockdag/dag_test.go +++ b/blockdag/dag_test.go @@ -117,7 +117,7 @@ func TestHaveBlock(t *testing.T) { {hash: "00000093c8f2ab3444502da0754fc8149d738701aef9b2e0f32f32c078039295", want: true}, // Block 100000 should be present (as an orphan). - {hash: "000000a805b083e0ef1f516b1153828724c235d6e6f0fabb47b869f6d054ac3f", want: true}, + {hash: "000000e46b5f4f7bfecff77f2f30f2ab90d08e3c5a55784080f97689bcd92786", want: true}, // Random hashes should not be available. {hash: "123", want: false}, diff --git a/blockdag/validate_test.go b/blockdag/validate_test.go index 0bbeb6bb2..bb980ec1d 100644 --- a/blockdag/validate_test.go +++ b/blockdag/validate_test.go @@ -172,26 +172,27 @@ func TestCheckBlockSanity(t *testing.T) { NumPrevBlocks: 2, PrevBlocks: []daghash.Hash{ [32]byte{ // Make go vet happy. - 0x0f, 0xea, 0x33, 0x21, 0x67, 0xd0, 0x25, 0x05, - 0x89, 0x83, 0x19, 0x9f, 0x47, 0x50, 0x3a, 0x3b, - 0x91, 0xd2, 0x0a, 0xec, 0x57, 0x7a, 0x10, 0x89, - 0xd6, 0x36, 0xf8, 0x6d, 0x29, 0x00, 0x00, 0x00, - }, // MainNet genesis + 0x4b, 0xb0, 0x75, 0x35, 0xdf, 0xd5, 0x8e, 0x0b, + 0x3c, 0xd6, 0x4f, 0xd7, 0x15, 0x52, 0x80, 0x87, + 0x2a, 0x04, 0x71, 0xbc, 0xf8, 0x30, 0x95, 0x52, + 0x6a, 0xce, 0x0e, 0x38, 0xc6, 0x00, 0x00, 0x00, + }, // SimNet genesis [32]byte{ // Make go vet happy. - 0x42, 0xeb, 0x66, 0x1f, 0x71, 0xb2, 0xb9, 0x26, - 0x05, 0xae, 0xe7, 0xf4, 0x8a, 0x6b, 0x7c, 0x86, - 0x33, 0x54, 0x0a, 0x27, 0xe5, 0x47, 0xb9, 0xb5, - 0xee, 0x13, 0x18, 0x83, 0x46, 0x00, 0x00, 0x00, - }}, // SimNet genesis + 0x16, 0x5e, 0x38, 0xe8, 0xb3, 0x91, 0x45, 0x95, + 0xd9, 0xc6, 0x41, 0xf3, 0xb8, 0xee, 0xc2, 0xf3, + 0x46, 0x11, 0x89, 0x6b, 0x82, 0x1a, 0x68, 0x3b, + 0x7a, 0x4e, 0xde, 0xfe, 0x2c, 0x00, 0x00, 0x00, + }, // MainNet genesis + }, MerkleRoot: daghash.Hash([32]byte{ // Make go vet happy. 0xc0, 0x92, 0x53, 0x8f, 0x6f, 0xf7, 0xf5, 0x24, 0xd5, 0x33, 0xd4, 0x8b, 0xf3, 0xc0, 0xf8, 0xf9, 0x6f, 0xff, 0xfb, 0xb7, 0xdc, 0x39, 0x9d, 0x76, 0x8d, 0xb0, 0xe1, 0x9c, 0x2e, 0x6d, 0x22, 0xd9, }), // f3e94742aca4b5ef85488dc37c06c3282295ffec960994b2c0d5ac2a25a95766 - Timestamp: time.Unix(0x5b50aa0e, 0), // 2018-07-19 15:11:10 +0000 UTC + Timestamp: time.Unix(0x5b7142b4, 0), // 2018-07-19 15:11:10 +0000 UTC Bits: 0x1e00ffff, // 503382015 - Nonce: 0x800c2a77, // 2148280951 + Nonce: 0xa05433ab, // 2148280951 }, Transactions: []*wire.MsgTx{ { @@ -423,6 +424,7 @@ func TestCheckBlockSanity(t *testing.T) { }, }, } + btcutilInvalidBlock := util.NewBlock(&invalidParentsOrderBlock) err = CheckBlockSanity(btcutilInvalidBlock, powLimit, timeSource) if err == nil { @@ -549,17 +551,17 @@ var Block100000 = wire.MsgBlock{ NumPrevBlocks: 2, PrevBlocks: []daghash.Hash{ [32]byte{ // Make go vet happy. - 0x4b, 0xb0, 0x75, 0x35, 0xdf, 0xd5, 0x8e, 0x0b, - 0x3c, 0xd6, 0x4f, 0xd7, 0x15, 0x52, 0x80, 0x87, - 0x2a, 0x04, 0x71, 0xbc, 0xf8, 0x30, 0x95, 0x52, - 0x6a, 0xce, 0x0e, 0x38, 0xc6, 0x00, 0x00, 0x00, - }, // SimNet genesis - [32]byte{ // Make go vet happy. - 0x16, 0x5e, 0x38, 0xe8, 0xb3, 0x91, 0x45, 0x95, - 0xd9, 0xc6, 0x41, 0xf3, 0xb8, 0xee, 0xc2, 0xf3, - 0x46, 0x11, 0x89, 0x6b, 0x82, 0x1a, 0x68, 0x3b, - 0x7a, 0x4e, 0xde, 0xfe, 0x2c, 0x00, 0x00, 0x00, + 0xa5, 0x60, 0xe4, 0x59, 0x61, 0x5d, 0xbb, 0x4e, + 0xae, 0x33, 0x40, 0x2a, 0xc0, 0xb8, 0x8a, 0xb6, + 0x53, 0xc5, 0x11, 0xe3, 0x35, 0xd0, 0xa6, 0x1e, + 0x0a, 0xc4, 0x06, 0x96, 0x97, 0x00, 0x00, 0x00, }, // MainNet genesis + [32]byte{ // Make go vet happy. + 0x2a, 0x9a, 0x2a, 0xe4, 0x3b, 0xc1, 0x6b, 0x55, + 0x06, 0x39, 0xc2, 0xe6, 0xbb, 0x4a, 0xec, 0xeb, + 0x7a, 0x49, 0x7c, 0xe9, 0xf3, 0x60, 0x20, 0x7d, + 0x63, 0xc7, 0x26, 0x89, 0xf6, 0x00, 0x00, 0x00, + }, // SimNet genesis }, MerkleRoot: daghash.Hash([32]byte{ // Make go vet happy. 0xc0, 0x92, 0x53, 0x8f, 0x6f, 0xf7, 0xf5, 0x24, @@ -567,9 +569,9 @@ var Block100000 = wire.MsgBlock{ 0x6f, 0xff, 0xfb, 0xb7, 0xdc, 0x39, 0x9d, 0x76, 0x8d, 0xb0, 0xe1, 0x9c, 0x2e, 0x6d, 0x22, 0xd9, }), // f3e94742aca4b5ef85488dc37c06c3282295ffec960994b2c0d5ac2a25a95766 - Timestamp: time.Unix(0x5b7142b4, 0), // 2018-07-19 15:11:10 +0000 UTC + Timestamp: time.Unix(0x5bb9f3b4, 0), // 2018-07-19 15:11:10 +0000 UTC Bits: 0x1e00ffff, // 503382015 - Nonce: 0xa05433ab, // 2148280951 + Nonce: 0x203602e3, // 2148280951 }, Transactions: []*wire.MsgTx{ {