desc: "block version is 0",
version: func() uint64 { return 0 },
prevHeight: chain.BestBlockHeight,
- timestamp: func() uint64 { return uint64(time.Now().Unix()) },
+ timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
prevHash: chain.BestBlockHash,
bits: func() uint64 { return chain.BestBlockHeader().Bits },
solve: true,
desc: "block version grater than prevBlock.Version",
version: func() uint64 { return chain.BestBlockHeader().Version + 10 },
prevHeight: chain.BestBlockHeight,
- timestamp: func() uint64 { return uint64(time.Now().Unix()) },
+ timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
prevHash: chain.BestBlockHash,
bits: func() uint64 { return chain.BestBlockHeader().Bits },
solve: true,
desc: "invalid block, misorder block height",
version: func() uint64 { return chain.BestBlockHeader().Version },
prevHeight: func() uint64 { return chain.BestBlockHeight() + 1 },
- timestamp: func() uint64 { return uint64(time.Now().Unix()) },
+ timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
prevHash: chain.BestBlockHash,
bits: func() uint64 { return chain.BestBlockHeader().Bits },
solve: true,
desc: "invalid prev hash, prev hash dismatch",
version: func() uint64 { return chain.BestBlockHeader().Version },
prevHeight: chain.BestBlockHeight,
- timestamp: func() uint64 { return uint64(time.Now().Unix()) },
+ timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
prevHash: func() *bc.Hash { hash := genesisHeader.Hash(); return &hash },
bits: func() uint64 { return chain.BestBlockHeader().Bits },
solve: true,
desc: "invalid bits",
version: func() uint64 { return chain.BestBlockHeader().Version },
prevHeight: chain.BestBlockHeight,
- timestamp: func() uint64 { return uint64(time.Now().Unix()) },
+ timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
prevHash: chain.BestBlockHash,
bits: func() uint64 { return chain.BestBlockHeader().Bits + 100 },
solve: true,
package test
import (
- "time"
-
"github.com/bytom/consensus"
"github.com/bytom/consensus/difficulty"
+ "github.com/bytom/mining/tensority"
"github.com/bytom/protocol"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/bc/types"
Version: 1,
Height: preBlockHeader.Height + 1,
PreviousBlockHash: preBlockHeader.Hash(),
- Timestamp: uint64(time.Now().Unix()),
+ Timestamp: preBlockHeader.Timestamp + 1,
BlockCommitment: types.BlockCommitment{},
Bits: difficulty.CalcNextRequiredDifficulty(preBlockHeader, compareDiffBH),
},
return err
}
-// Solve solve difficulty
-func Solve(seed *bc.Hash, block *types.Block) error {
- header := &block.BlockHeader
- for i := uint64(0); i < maxNonce; i++ {
- header.Nonce = i
- headerHash := header.Hash()
- if difficulty.CheckProofOfWork(&headerHash, seed, header.Bits) {
- return nil
- }
- }
- return nil
+// Solve simulate solve difficulty by add result to cache
+func Solve(seed *bc.Hash, block *types.Block) {
+ hash := block.BlockHeader.Hash()
+ tensority.AIHash.AddCache(&hash, seed, &bc.Hash{})
}