OSDN Git Service

ts to ms (#71)
authorPaladz <yzhu101@uottawa.ca>
Mon, 20 May 2019 03:10:59 +0000 (11:10 +0800)
committerGitHub <noreply@github.com>
Mon, 20 May 2019 03:10:59 +0000 (11:10 +0800)
12 files changed:
config/genesis.go
consensus/general.go
mining/mining.go
netsync/message_test.go
protocol/bc/types/block_header.go
protocol/bc/types/block_header_test.go
protocol/validation/block.go
protocol/validation/block_test.go
protocol/validation/tx_test.go
test/block_test.go
test/utxo_view/utxo_view_test_util.go
wallet/unconfirmed.go

index 021f14d..5f643a0 100644 (file)
@@ -48,7 +48,7 @@ func mainNetGenesisBlock() *types.Block {
                BlockHeader: types.BlockHeader{
                        Version:   1,
                        Height:    0,
-                       Timestamp: 1524549600,
+                       Timestamp: 1524549600000,
                        BlockCommitment: types.BlockCommitment{
                                TransactionsMerkleRoot: merkleRoot,
                                TransactionStatusHash:  txStatusHash,
@@ -79,7 +79,7 @@ func testNetGenesisBlock() *types.Block {
                BlockHeader: types.BlockHeader{
                        Version:   1,
                        Height:    0,
-                       Timestamp: 1528945000,
+                       Timestamp: 1528945000000,
                        BlockCommitment: types.BlockCommitment{
                                TransactionsMerkleRoot: merkleRoot,
                                TransactionStatusHash:  txStatusHash,
@@ -110,7 +110,7 @@ func soloNetGenesisBlock() *types.Block {
                BlockHeader: types.BlockHeader{
                        Version:   1,
                        Height:    0,
-                       Timestamp: 1528945000,
+                       Timestamp: 1528945000000,
                        BlockCommitment: types.BlockCommitment{
                                TransactionsMerkleRoot: merkleRoot,
                                TransactionStatusHash:  txStatusHash,
index 6b67870..868fc5b 100644 (file)
@@ -27,9 +27,9 @@ const (
        TargetSecondsPerBlock = uint64(150)
        SeedPerRetarget       = uint64(256)
 
-       // MaxTimeOffsetSeconds is the maximum number of seconds a block time is allowed to be ahead of the current time
-       MaxTimeOffsetSeconds = uint64(60 * 60)
-       MedianTimeBlocks     = 11
+       // MaxTimeOffsetMs is the maximum number of seconds a block time is allowed to be ahead of the current time
+       MaxTimeOffsetMs  = uint64(60 * 60 * 1000)
+       MedianTimeBlocks = 11
 
        PayToWitnessPubKeyHashDataSize = 20
        PayToWitnessScriptHashDataSize = 32
index 9f9dece..82149b1 100644 (file)
@@ -89,7 +89,7 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
                        Version:           1,
                        Height:            nextBlockHeight,
                        PreviousBlockHash: preBlockHash,
-                       Timestamp:         uint64(time.Now().Unix()),
+                       Timestamp:         uint64(time.Now().UnixNano() / int64(time.Millisecond)),
                        BlockCommitment:   types.BlockCommitment{},
                },
        }
index 8743df7..5c40a68 100644 (file)
@@ -14,7 +14,7 @@ var testBlock = &types.Block{
        BlockHeader: types.BlockHeader{
                Version:   1,
                Height:    0,
-               Timestamp: 1528945000,
+               Timestamp: 1528945000000,
                BlockCommitment: types.BlockCommitment{
                        TransactionsMerkleRoot: bc.Hash{V0: uint64(0x11)},
                        TransactionStatusHash:  bc.Hash{V0: uint64(0x55)},
@@ -48,7 +48,7 @@ var testHeaders = []*types.BlockHeader{
        {
                Version:   1,
                Height:    0,
-               Timestamp: 1528945000,
+               Timestamp: 1528945000000,
                BlockCommitment: types.BlockCommitment{
                        TransactionsMerkleRoot: bc.Hash{V0: uint64(0x11)},
                        TransactionStatusHash:  bc.Hash{V0: uint64(0x55)},
@@ -57,7 +57,7 @@ var testHeaders = []*types.BlockHeader{
        {
                Version:   1,
                Height:    1,
-               Timestamp: 1528945000,
+               Timestamp: 1528945000000,
                BlockCommitment: types.BlockCommitment{
                        TransactionsMerkleRoot: bc.Hash{V0: uint64(0x11)},
                        TransactionStatusHash:  bc.Hash{V0: uint64(0x55)},
@@ -66,7 +66,7 @@ var testHeaders = []*types.BlockHeader{
        {
                Version:   1,
                Height:    3,
-               Timestamp: 1528945000,
+               Timestamp: 1528945000000,
                BlockCommitment: types.BlockCommitment{
                        TransactionsMerkleRoot: bc.Hash{V0: uint64(0x11)},
                        TransactionStatusHash:  bc.Hash{V0: uint64(0x55)},
@@ -127,7 +127,7 @@ var testBlocks = []*types.Block{
                BlockHeader: types.BlockHeader{
                        Version:   1,
                        Height:    0,
-                       Timestamp: 1528945000,
+                       Timestamp: 1528945000000,
                        BlockCommitment: types.BlockCommitment{
                                TransactionsMerkleRoot: bc.Hash{V0: uint64(0x11)},
                                TransactionStatusHash:  bc.Hash{V0: uint64(0x55)},
@@ -138,7 +138,7 @@ var testBlocks = []*types.Block{
                BlockHeader: types.BlockHeader{
                        Version:   1,
                        Height:    0,
-                       Timestamp: 1528945000,
+                       Timestamp: 1528945000000,
                        BlockCommitment: types.BlockCommitment{
                                TransactionsMerkleRoot: bc.Hash{V0: uint64(0x11)},
                                TransactionStatusHash:  bc.Hash{V0: uint64(0x55)},
index 7df4c37..88bdddb 100644 (file)
@@ -17,14 +17,14 @@ type BlockHeader struct {
        Version           uint64  // The version of the block.
        Height            uint64  // The height of the block.
        PreviousBlockHash bc.Hash // The hash of the previous block.
-       Timestamp         uint64  // The time of the block in seconds.
+       Timestamp         uint64  // The time of the block in milliseconds.
        BlockCommitment
        BlockWitness
 }
 
 // Time returns the time represented by the Timestamp in block header.
 func (bh *BlockHeader) Time() time.Time {
-       return time.Unix(int64(bh.Timestamp), 0).UTC()
+       return time.Unix(0, int64(bh.Timestamp)*int64(time.Millisecond)).UTC()
 }
 
 // Hash returns complete hash of the block header.
index 4a9237a..2ea6e01 100644 (file)
@@ -19,7 +19,7 @@ func TestBlockHeader(t *testing.T) {
                Version:           1,
                Height:            432234,
                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-               Timestamp:         1522908275,
+               Timestamp:         1522908275000,
                BlockCommitment: BlockCommitment{
                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
@@ -32,8 +32,8 @@ func TestBlockHeader(t *testing.T) {
                "01",     // version
                "eab01a", // block height
                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-               "f3f896d605", // timestamp
-               "40",         // commitment extensible field length
+               "b8c2a0a3a92c", // timestamp
+               "40",           // commitment extensible field length
                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
                "040102beef", //BlockWitness
@@ -70,7 +70,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                Version:           1,
                                Height:            10000,
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-                               Timestamp:         1528945000,
+                               Timestamp:         1528945000000,
                                BlockCommitment: BlockCommitment{
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
@@ -82,8 +82,8 @@ func TestMarshalBlockHeader(t *testing.T) {
                                "01",   // version
                                "904e", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
                                "040102beef", //BlockWitness
@@ -94,7 +94,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                Version:           1,
                                Height:            9223372036854775808, // Height > MaxInt64(9223372036854775807)
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-                               Timestamp:         1528945000,
+                               Timestamp:         1528945000000,
                                BlockCommitment: BlockCommitment{
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
@@ -122,7 +122,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                Version:           1,
                                Height:            9223372036854775807, // MaxInt64(9223372036854775807)
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-                               Timestamp:         1528945000,
+                               Timestamp:         1528945000000,
                                BlockWitness:      BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}},
                        },
                        wantHex: strings.Join([]string{
@@ -130,8 +130,8 @@ func TestMarshalBlockHeader(t *testing.T) {
                                "01",                 // version
                                "ffffffffffffffff7f", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
                                "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
                                "040102beef", //BlockWitness
@@ -142,7 +142,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                Version:           1,
                                Height:            9223372036854775807, // MaxInt64(9223372036854775807)
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-                               Timestamp:         1528945000,
+                               Timestamp:         1528945000000,
                                BlockWitness:      BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, []byte{0xab, 0xcd}, []byte{0xcd, 0x68}}},
                        },
                        wantHex: strings.Join([]string{
@@ -150,8 +150,8 @@ func TestMarshalBlockHeader(t *testing.T) {
                                "01",                 // version
                                "ffffffffffffffff7f", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
                                "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
                                "0a0302beef02abcd02cd68", //BlockWitness
@@ -162,7 +162,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                Version:           1,
                                Height:            9223372036854775807, // MaxInt64(9223372036854775807)
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-                               Timestamp:         1528945000,
+                               Timestamp:         1528945000000,
                                BlockWitness:      BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, nil, []byte{0xcd, 0x68}}},
                        },
                        wantHex: strings.Join([]string{
@@ -170,8 +170,8 @@ func TestMarshalBlockHeader(t *testing.T) {
                                "01",                 // version
                                "ffffffffffffffff7f", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
                                "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
                                "080302beef0002cd68", //BlockWitness
@@ -182,7 +182,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                Version:           1,
                                Height:            9223372036854775807, // MaxInt64(9223372036854775807)
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-                               Timestamp:         1528945000,
+                               Timestamp:         1528945000000,
                                BlockWitness:      BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, []byte{}, []byte{0xcd, 0x68}}},
                        },
                        wantHex: strings.Join([]string{
@@ -190,8 +190,8 @@ func TestMarshalBlockHeader(t *testing.T) {
                                "01",                 // version
                                "ffffffffffffffff7f", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
                                "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
                                "080302beef0002cd68", //BlockWitness
@@ -202,7 +202,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                Version:           1,
                                Height:            9223372036854775807, // MaxInt64(9223372036854775807)
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-                               Timestamp:         1528945000,
+                               Timestamp:         1528945000000,
                                BlockWitness:      BlockWitness{Witness: [][]byte{}},
                        },
                        wantHex: strings.Join([]string{
@@ -210,8 +210,8 @@ func TestMarshalBlockHeader(t *testing.T) {
                                "01",                 // version
                                "ffffffffffffffff7f", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
                                "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
                                "0100", //BlockWitness
@@ -254,8 +254,8 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "01",   // version
                                "904e", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
                                "040102beef", //BlockWitness
@@ -264,7 +264,7 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                Version:           1,
                                Height:            10000,
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-                               Timestamp:         1528945000,
+                               Timestamp:         1528945000000,
                                BlockCommitment: BlockCommitment{
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
@@ -278,8 +278,8 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "01",   // version
                                "904e", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
                                "040102beef", //BlockWitness
@@ -288,7 +288,7 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                Version:           1,
                                Height:            10000,
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-                               Timestamp:         1528945000,
+                               Timestamp:         1528945000000,
                                BlockCommitment: BlockCommitment{
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
@@ -302,8 +302,8 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "01",   // version
                                "904e", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
                        }, ""),
@@ -315,8 +315,8 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "01",  // version
                                "908", // block height (error with odd length)
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
                        }, ""),
@@ -328,8 +328,8 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "01",                 // version
                                "ffffffffffffffffff", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
                                "040102beef", //BlockWitness
@@ -342,8 +342,8 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "01",                 // version
                                "ffffffffffffffff7f", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a14",   // tx status hash
                        }, ""),
@@ -355,8 +355,8 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "01",                 // version
                                "ffffffffffffffff7f", // block height
                                "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
-                               "e8b287d905", // timestamp
-                               "40",         // commitment extensible field length
+                               "c0fce4e1bf2c", // timestamp
+                               "40",           // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
                                "040102beef", //BlockWitness
@@ -365,7 +365,7 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                Version:           1,
                                Height:            9223372036854775807, // MaxInt64(9223372036854775807)
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
-                               Timestamp:         1528945000,
+                               Timestamp:         1528945000000,
                                BlockCommitment: BlockCommitment{
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
index 827750d..3ded430 100644 (file)
@@ -26,7 +26,7 @@ var (
 )
 
 func checkBlockTime(b *bc.Block, parent *state.BlockNode) error {
-       if b.Timestamp > uint64(time.Now().Unix())+consensus.MaxTimeOffsetSeconds {
+       if b.Timestamp > uint64(time.Now().UnixNano()/int64(time.Millisecond))+consensus.MaxTimeOffsetMs {
                return errBadTimestamp
        }
 
index 83a5baa..a6fcfeb 100644 (file)
@@ -33,14 +33,14 @@ func TestCheckBlockTime(t *testing.T) {
                },
                {
                        desc:       "timestamp greater than max limit (blocktest#1006)",
-                       blockTime:  9999999999,
-                       parentTime: []uint64{1520000000},
+                       blockTime:  99999999990000,
+                       parentTime: []uint64{15200000000000},
                        err:        errBadTimestamp,
                },
                {
                        desc:       "timestamp of the block and the parent block are both greater than max limit (blocktest#1007)",
-                       blockTime:  uint64(time.Now().Unix()) + consensus.MaxTimeOffsetSeconds + 2,
-                       parentTime: []uint64{uint64(time.Now().Unix()) + consensus.MaxTimeOffsetSeconds + 1},
+                       blockTime:  uint64(time.Now().UnixNano()/int64(time.Millisecond)) + consensus.MaxTimeOffsetMs + 2000,
+                       parentTime: []uint64{uint64(time.Now().UnixNano()/int64(time.Millisecond)) + consensus.MaxTimeOffsetMs + 1000},
                        err:        errBadTimestamp,
                },
        }
@@ -154,14 +154,14 @@ func TestValidateBlockHeader(t *testing.T) {
                                BlockHeader: &bc.BlockHeader{
                                        Version:         1,
                                        Height:          1,
-                                       Timestamp:       1523352601,
+                                       Timestamp:       1523352601000,
                                        PreviousBlockId: &bc.Hash{V0: 0},
                                },
                        },
                        parent: &state.BlockNode{
                                Version:   1,
                                Height:    0,
-                               Timestamp: 1523352600,
+                               Timestamp: 1523352600000,
                                Hash:      bc.Hash{V0: 0},
                        },
                        err: nil,
@@ -230,7 +230,7 @@ func TestValidateBlock(t *testing.T) {
                                BlockHeader: &bc.BlockHeader{
                                        Version:          1,
                                        Height:           1,
-                                       Timestamp:        1523352601,
+                                       Timestamp:        1523352601000,
                                        PreviousBlockId:  &bc.Hash{V0: 0},
                                        TransactionsRoot: &bc.Hash{V0: 1},
                                },
@@ -246,7 +246,7 @@ func TestValidateBlock(t *testing.T) {
                        parent: &state.BlockNode{
                                Version:   1,
                                Height:    0,
-                               Timestamp: 1523352600,
+                               Timestamp: 1523352600000,
                                Hash:      bc.Hash{V0: 0},
                        },
                        err: errMismatchedMerkleRoot,
@@ -258,7 +258,7 @@ func TestValidateBlock(t *testing.T) {
                                BlockHeader: &bc.BlockHeader{
                                        Version:               1,
                                        Height:                1,
-                                       Timestamp:             1523352601,
+                                       Timestamp:             1523352601000,
                                        PreviousBlockId:       &bc.Hash{V0: 0},
                                        TransactionsRoot:      &bc.Hash{V0: 6294987741126419124, V1: 12520373106916389157, V2: 5040806596198303681, V3: 1151748423853876189},
                                        TransactionStatusHash: &bc.Hash{V0: 1},
@@ -275,7 +275,7 @@ func TestValidateBlock(t *testing.T) {
                        parent: &state.BlockNode{
                                Version:   1,
                                Height:    0,
-                               Timestamp: 1523352600,
+                               Timestamp: 1523352600000,
                                Hash:      bc.Hash{V0: 0},
                        },
                        err: errMismatchedMerkleRoot,
@@ -287,7 +287,7 @@ func TestValidateBlock(t *testing.T) {
                                BlockHeader: &bc.BlockHeader{
                                        Version:         1,
                                        Height:          1,
-                                       Timestamp:       1523352601,
+                                       Timestamp:       1523352601000,
                                        PreviousBlockId: &bc.Hash{V0: 0},
                                },
                                Transactions: []*bc.Tx{
@@ -308,7 +308,7 @@ func TestValidateBlock(t *testing.T) {
                        parent: &state.BlockNode{
                                Version:   1,
                                Height:    0,
-                               Timestamp: 1523352600,
+                               Timestamp: 1523352600000,
                                Hash:      bc.Hash{V0: 0},
                        },
                        err: ErrWrongCoinbaseTransaction,
@@ -329,7 +329,7 @@ func TestGasOverBlockLimit(t *testing.T) {
        parent := &state.BlockNode{
                Version:   1,
                Height:    0,
-               Timestamp: 1523352600,
+               Timestamp: 1523352600000,
                Hash:      bc.Hash{V0: 0},
        }
        block := &bc.Block{
@@ -337,7 +337,7 @@ func TestGasOverBlockLimit(t *testing.T) {
                BlockHeader: &bc.BlockHeader{
                        Version:          1,
                        Height:           1,
-                       Timestamp:        1523352601,
+                       Timestamp:        1523352601000,
                        PreviousBlockId:  &bc.Hash{V0: 0},
                        TransactionsRoot: &bc.Hash{V0: 1},
                },
@@ -375,7 +375,7 @@ func TestSetTransactionStatus(t *testing.T) {
        parent := &state.BlockNode{
                Version:   1,
                Height:    0,
-               Timestamp: 1523352600,
+               Timestamp: 1523352600000,
                Hash:      bc.Hash{V0: 0},
        }
        block := &bc.Block{
@@ -383,7 +383,7 @@ func TestSetTransactionStatus(t *testing.T) {
                BlockHeader: &bc.BlockHeader{
                        Version:               1,
                        Height:                1,
-                       Timestamp:             1523352601,
+                       Timestamp:             1523352601000,
                        PreviousBlockId:       &bc.Hash{V0: 0},
                        TransactionsRoot:      &bc.Hash{V0: 10011341401654852692, V1: 8144266100226420640, V2: 18332298251154128538, V3: 7663092454615786384},
                        TransactionStatusHash: &bc.Hash{V0: 8682965660674182538, V1: 8424137560837623409, V2: 6979974817894224946, V3: 4673809519342015041},
index ed0f06e..a9a2f3d 100644 (file)
@@ -809,7 +809,7 @@ func TestTimeRange(t *testing.T) {
        block := &bc.Block{
                BlockHeader: &bc.BlockHeader{
                        Height:    333,
-                       Timestamp: 1521625823,
+                       Timestamp: 1521625823000,
                },
        }
 
index deb5474..1aca282 100644 (file)
@@ -60,10 +60,10 @@ func TestBlockHeader(t *testing.T) {
                        valid:      false,
                },
                {
-                       desc:       "invalid timestamp, greater than MaxTimeOffsetSeconds from system time",
+                       desc:       "invalid timestamp, greater than MaxTimeOffsetMs  from system time",
                        version:    func() uint64 { return chain.BestBlockHeader().Version },
                        prevHeight: chain.BestBlockHeight,
-                       timestamp:  func() uint64 { return uint64(time.Now().Unix()) + consensus.MaxTimeOffsetSeconds + 60 },
+                       timestamp:  func() uint64 { return uint64(time.Now().Unix()) + consensus.MaxTimeOffsetMs + 60 },
                        prevHash:   chain.BestBlockHash,
                        valid:      false,
                },
index 8110b39..3948f7e 100644 (file)
@@ -365,7 +365,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            100,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block0"),
@@ -377,7 +377,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            101,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block1"),
@@ -392,7 +392,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            102,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block2"),
@@ -404,7 +404,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            102,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block3"),
@@ -416,7 +416,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            103,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block4"),
@@ -429,7 +429,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            104,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block5"),
@@ -440,7 +440,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            105,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block6"),
@@ -452,7 +452,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            106,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block7"),
@@ -463,7 +463,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            107,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block8"),
@@ -476,7 +476,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            108,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block9"),
@@ -489,7 +489,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            105,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block10"),
@@ -505,7 +505,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            105,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block11"),
@@ -520,7 +520,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            106,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block12"),
@@ -534,7 +534,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            107,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block13"),
@@ -547,7 +547,7 @@ func init() {
                        BlockHeader: types.BlockHeader{
                                Height:            106,
                                PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
-                               Timestamp:         1522908275,
+                               Timestamp:         1522908275000,
                        },
                        Transactions: []*types.Tx{
                                coinBaseTx(41250000000, "arbitrary block14"),
index d634d81..4eec6a2 100644 (file)
@@ -94,7 +94,7 @@ func (w *Wallet) RemoveUnconfirmedTx(txD *protocol.TxDesc) {
 func (w *Wallet) buildAnnotatedUnconfirmedTx(tx *types.Tx) *query.AnnotatedTx {
        annotatedTx := &query.AnnotatedTx{
                ID:        tx.ID,
-               Timestamp: uint64(time.Now().Unix()),
+               Timestamp: uint64(time.Now().UnixNano() / int64(time.Millisecond)),
                Inputs:    make([]*query.AnnotatedInput, 0, len(tx.Inputs)),
                Outputs:   make([]*query.AnnotatedOutput, 0, len(tx.Outputs)),
                Size:      tx.SerializedSize,