}
// NewBlockTemplate returns a new block template that is ready to be solved
-func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager *account.Manager) (b *types.Block, err error) {
+func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager *account.Manager, timestamp uint64) (b *types.Block, err error) {
view := state.NewUtxoViewpoint()
txStatus := bc.NewTransactionStatus()
if err := txStatus.SetStatus(0, false); err != nil {
Version: 1,
Height: nextBlockHeight,
PreviousBlockHash: preBlockHash,
- Timestamp: uint64(time.Now().UnixNano() / int64(time.Millisecond)),
+ Timestamp: timestamp,
BlockCommitment: types.BlockCommitment{},
+ BlockWitness: types.BlockWitness{Witness: make([][]byte, consensus.NumOfConsensusNode)},
},
}
bcBlock := &bc.Block{BlockHeader: &bc.BlockHeader{Height: nextBlockHeight}}
txs := txPool.GetTransactions()
sort.Sort(byTime(txs))
+
+ entriesTxs := []*bc.Tx{}
for _, txDesc := range txs {
+ entriesTxs = append(entriesTxs, txDesc.Tx.Tx)
+ }
+
+ validateResults := validation.ValidateTxs(entriesTxs, bcBlock)
+ for i, validateResult := range validateResults {
+ txDesc := txs[i]
tx := txDesc.Tx.Tx
gasOnlyTx := false
- if err := c.GetTransactionsUtxo(view, []*bc.Tx{tx}); err != nil {
- blkGenSkipTxForErr(txPool, &tx.ID, err)
- continue
- }
-
- gasStatus, err := validation.ValidateTx(tx, bcBlock)
- if err != nil {
+ gasStatus := validateResult.GetGasState()
+ if validateResult.GetError() != nil {
if !gasStatus.GasValid {
blkGenSkipTxForErr(txPool, &tx.ID, err)
continue
gasOnlyTx = true
}
+ if err := c.GetTransactionsUtxo(view, []*bc.Tx{tx}); err != nil {
+ blkGenSkipTxForErr(txPool, &tx.ID, err)
+ continue
+ }
+
if gasUsed+uint64(gasStatus.GasUsed) > consensus.MaxBlockGas {
break
}
if gasUsed == consensus.MaxBlockGas {
break
}
+
}
// creater coinbase transaction
b.BlockHeader.BlockCommitment.TransactionStatusHash, err = types.TxStatusMerkleRoot(txStatus.VerifyStatus)
- _, err = c.GetBBFT().SignBlock(b)
+ _, err = c.SignBlock(b)
return b, err
}