OSDN Git Service

ts to ms (#71)
[bytom/vapor.git] / mining / mining.go
index e816bc4..82149b1 100644 (file)
@@ -19,11 +19,13 @@ import (
        "github.com/vapor/protocol/vm/vmutil"
 )
 
+const logModule = "mining"
+
 // createCoinbaseTx returns a coinbase transaction paying an appropriate subsidy
 // based on the passed block height to the provided address.  When the address
 // is nil, the coinbase transaction will instead be redeemable by anyone.
 func createCoinbaseTx(accountManager *account.Manager, amount uint64, blockHeight uint64) (tx *types.Tx, err error) {
-       //amount += consensus.BlockSubsidy(blockHeight)
+       amount += consensus.BlockSubsidy(blockHeight)
        arbitrary := append([]byte{0x00}, []byte(strconv.FormatUint(blockHeight, 10))...)
 
        var script []byte
@@ -45,7 +47,7 @@ func createCoinbaseTx(accountManager *account.Manager, amount uint64, blockHeigh
        if err = builder.AddInput(types.NewCoinbaseInput(arbitrary), &txbuilder.SigningInstruction{}); err != nil {
                return nil, err
        }
-       if err = builder.AddOutput(types.NewTxOutput(*consensus.BTMAssetID, amount, script)); err != nil {
+       if err = builder.AddOutput(types.NewIntraChainOutput(*consensus.BTMAssetID, amount, script)); err != nil {
                return nil, err
        }
        _, txData, err := builder.Build()
@@ -87,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{},
                },
        }
@@ -136,9 +138,7 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
                        break
                }
        }
-       if txFee == 0 {
-               return nil, err
-       }
+
        // creater coinbase transaction
        b.Transactions[0], err = createCoinbaseTx(accountManager, txFee, nextBlockHeight)
        if err != nil {
@@ -156,6 +156,6 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
 }
 
 func blkGenSkipTxForErr(txPool *protocol.TxPool, txHash *bc.Hash, err error) {
-       log.WithField("error", err).Error("mining block generation: skip tx due to")
+       log.WithFields(log.Fields{"module": logModule, "error": err}).Error("mining block generation: skip tx due to")
        txPool.RemoveTransaction(txHash)
 }