X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=test%2Fblock_test_util.go;h=94088f1c68107096c9437d9cffdcc44955158e9b;hb=0f580d4f320f32dc3735bf30e84a14cfd0506eb1;hp=0c839a8c9ee555d0e93da03d903b131c32b8b0a5;hpb=f8cb34f50c87af90336722603db99ea24ccd9442;p=bytom%2Fbytom.git diff --git a/test/block_test_util.go b/test/block_test_util.go index 0c839a8c..94088f1c 100644 --- a/test/block_test_util.go +++ b/test/block_test_util.go @@ -1,10 +1,7 @@ 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" @@ -21,9 +18,10 @@ func NewBlock(chain *protocol.Chain, txs []*types.Tx, controlProgram []byte) (*t txStatus.SetStatus(0, false) preBlockHeader := chain.BestBlockHeader() - var compareDiffBH *types.BlockHeader - if compareDiffBlock, err := chain.GetBlockByHeight(preBlockHeader.Height - consensus.BlocksPerRetarget); err == nil { - compareDiffBH = &compareDiffBlock.BlockHeader + preBlockHash := preBlockHeader.Hash() + nextBits, err := chain.CalcNextBits(&preBlockHash) + if err != nil { + return nil, err } b := &types.Block{ @@ -31,9 +29,9 @@ func NewBlock(chain *protocol.Chain, txs []*types.Tx, controlProgram []byte) (*t 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), + Bits: nextBits, }, Transactions: []*types.Tx{nil}, } @@ -43,7 +41,7 @@ func NewBlock(chain *protocol.Chain, txs []*types.Tx, controlProgram []byte) (*t gasOnlyTx := false gasStatus, err := validation.ValidateTx(tx.Tx, bcBlock) if err != nil { - if !gasStatus.GasVaild { + if !gasStatus.GasValid { continue } gasOnlyTx = true @@ -109,15 +107,8 @@ func SolveAndUpdate(chain *protocol.Chain, block *types.Block) error { 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{}) }