OSDN Git Service

fixed reward address (#504)
authorPoseidon <shenao.78@163.com>
Tue, 3 Mar 2020 06:59:55 +0000 (14:59 +0800)
committerGitHub <noreply@github.com>
Tue, 3 Mar 2020 06:59:55 +0000 (14:59 +0800)
application/mov/match/match.go
application/mov/match/match_test.go
application/mov/mock/mock.go
application/mov/mov_core.go
application/mov/mov_core_test.go
consensus/general.go
proposal/proposal.go
protocol/bbft.go
protocol/protocol.go

index a66f7d4..bfc3943 100644 (file)
@@ -18,14 +18,14 @@ import (
 
 // Engine is used to generate math transactions
 type Engine struct {
-       orderBook   *OrderBook
-       maxFeeRate  float64
-       nodeProgram []byte
+       orderBook     *OrderBook
+       maxFeeRate    float64
+       rewardProgram []byte
 }
 
 // NewEngine return a new Engine
-func NewEngine(orderBook *OrderBook, maxFeeRate float64, nodeProgram []byte) *Engine {
-       return &Engine{orderBook: orderBook, maxFeeRate: maxFeeRate, nodeProgram: nodeProgram}
+func NewEngine(orderBook *OrderBook, maxFeeRate float64, rewardProgram []byte) *Engine {
+       return &Engine{orderBook: orderBook, maxFeeRate: maxFeeRate, rewardProgram: rewardProgram}
 }
 
 // HasMatchedTx check does the input trade pair can generate a match deal
@@ -77,7 +77,7 @@ func (e *Engine) addMatchTxFeeOutput(txData *types.TxData) error {
                        feeAmount = matchTxFee.MaxFeeAmount
                        reminder = matchTxFee.FeeAmount - matchTxFee.MaxFeeAmount
                }
-               txData.Outputs = append(txData.Outputs, types.NewIntraChainOutput(assetID, uint64(feeAmount), e.nodeProgram))
+               txData.Outputs = append(txData.Outputs, types.NewIntraChainOutput(assetID, uint64(feeAmount), e.rewardProgram))
 
                // There is the remaining amount after paying the handling fee, assign it evenly to participants in the transaction
                averageAmount := reminder / int64(len(txData.Inputs))
index 7d013ec..70fda39 100644 (file)
@@ -80,7 +80,7 @@ func TestGenerateMatchedTxs(t *testing.T) {
 
        for i, c := range cases {
                movStore := mock.NewMovStore([]*common.TradePair{btc2eth, eth2btc}, c.initStoreOrders)
-               matchEngine := NewEngine(NewOrderBook(movStore, nil, nil), 0.05, mock.NodeProgram)
+               matchEngine := NewEngine(NewOrderBook(movStore, nil, nil), 0.05, mock.RewardProgram)
                var gotMatchedTxs []*types.Tx
                for matchEngine.HasMatchedTx(c.tradePairs...) {
                        matchedTx, err := matchEngine.NextMatchedTx(c.tradePairs...)
index 8dbd921..f351e64 100644 (file)
@@ -10,11 +10,11 @@ import (
 )
 
 var (
-       BTC         = bc.NewAssetID([32]byte{1})
-       ETH         = bc.NewAssetID([32]byte{2})
-       EOS         = bc.NewAssetID([32]byte{3})
-       ETC         = bc.NewAssetID([32]byte{4})
-       NodeProgram = []byte{0x58}
+       BTC           = bc.NewAssetID([32]byte{1})
+       ETH           = bc.NewAssetID([32]byte{2})
+       EOS           = bc.NewAssetID([32]byte{3})
+       ETC           = bc.NewAssetID([32]byte{4})
+       RewardProgram = []byte{0x58}
 
        Btc2EthOrders = []*common.Order{
                {
@@ -269,7 +269,7 @@ var (
                        Outputs: []*types.TxOutput{
                                types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 500, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19251")),
                                types.NewIntraChainOutput(*Eth2BtcOrders[0].ToAssetID, 10, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19253")),
-                               types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 10, NodeProgram),
+                               types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 10, RewardProgram),
                        },
                }),
 
@@ -285,7 +285,7 @@ var (
                                // re-order
                                types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, 270, Eth2BtcOrders[2].Utxo.ControlProgram),
                                // fee
-                               types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, 27, NodeProgram),
+                               types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, 27, RewardProgram),
                                // refund
                                types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, 6, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19251")),
                                types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, 7, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19255")),
@@ -370,7 +370,7 @@ var (
                                types.NewIntraChainOutput(*Btc2EthOrders[3].FromAssetID, 1, Btc2EthOrders[3].Utxo.ControlProgram),
                                types.NewIntraChainOutput(*Eth2BtcOrders[2].ToAssetID, 15, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19255")),
                                // fee
-                               types.NewIntraChainOutput(*Btc2EthOrders[3].FromAssetID, 1, NodeProgram),
+                               types.NewIntraChainOutput(*Btc2EthOrders[3].FromAssetID, 1, RewardProgram),
                        },
                }),
 
@@ -395,7 +395,7 @@ var (
                        Outputs: []*types.TxOutput{
                                types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 500, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19251")),
                                types.NewIntraChainOutput(*Eth2BtcOrders[0].ToAssetID, 10, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19253")),
-                               types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 10, NodeProgram),
+                               types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 10, RewardProgram),
                        },
                }),
        }
index 376f9f2..dcf17ad 100644 (file)
@@ -1,10 +1,13 @@
 package mov
 
 import (
+       "encoding/hex"
+
        "github.com/bytom/vapor/application/mov/common"
        "github.com/bytom/vapor/application/mov/contract"
        "github.com/bytom/vapor/application/mov/database"
        "github.com/bytom/vapor/application/mov/match"
+       "github.com/bytom/vapor/consensus"
        "github.com/bytom/vapor/consensus/segwit"
        dbm "github.com/bytom/vapor/database/leveldb"
        "github.com/bytom/vapor/errors"
@@ -71,7 +74,7 @@ func (m *MovCore) ApplyBlock(block *types.Block) error {
 }
 
 // BeforeProposalBlock return all transactions than can be matched, and the number of transactions cannot exceed the given capacity.
-func (m *MovCore) BeforeProposalBlock(txs []*types.Tx, nodeProgram []byte, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error) {
+func (m *MovCore) BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error) {
        if blockHeight <= m.startBlockHeight {
                return nil, nil
        }
@@ -81,7 +84,12 @@ func (m *MovCore) BeforeProposalBlock(txs []*types.Tx, nodeProgram []byte, block
                return nil, err
        }
 
-       matchEngine := match.NewEngine(orderBook, maxFeeRate, nodeProgram)
+       rewardProgram, err := hex.DecodeString(consensus.ActiveNetParams.MovRewardProgram)
+       if err != nil {
+               return nil, err
+       }
+
+       matchEngine := match.NewEngine(orderBook, maxFeeRate, rewardProgram)
        tradePairIterator := database.NewTradePairIterator(m.movStore)
        matchCollector := newMatchTxCollector(matchEngine, tradePairIterator, gasLeft, isTimeout)
        return matchCollector.result()
index 78898ef..28a0bd9 100644 (file)
@@ -1,6 +1,7 @@
 package mov
 
 import (
+       "encoding/hex"
        "math"
        "os"
        "testing"
@@ -508,6 +509,8 @@ func TestValidateBlock(t *testing.T) {
 }
 
 func TestBeforeProposalBlock(t *testing.T) {
+       consensus.ActiveNetParams.MovRewardProgram = hex.EncodeToString(mock.RewardProgram)
+
        cases := []struct {
                desc           string
                initOrders     []*common.Order
@@ -572,7 +575,7 @@ func TestBeforeProposalBlock(t *testing.T) {
                }
 
                movCore := &MovCore{movStore: store}
-               gotMatchedTxs, err := movCore.BeforeProposalBlock(nil, []byte{0x51}, 2, c.gasLeft, func() bool { return false })
+               gotMatchedTxs, err := movCore.BeforeProposalBlock(nil, 2, c.gasLeft, func() bool { return false })
                if err != nil {
                        t.Fatal(err)
                }
index 11bff3c..20392b1 100644 (file)
@@ -103,7 +103,12 @@ type Params struct {
        ProducerSubsidys []ProducerSubsidy
 
        SoftForkPoint map[uint64]uint64
+
+       // Mov will only start when the block height is greater than this value
        MovStartHeight uint64
+
+       // Used to receive rewards for matching transactions
+       MovRewardProgram string
 }
 
 // ActiveNetParams is the active NetParams
index 4a8273f..7ab48ce 100644 (file)
@@ -139,11 +139,6 @@ func (b *blockBuilder) applyTransactionFromPool() error {
 }
 
 func (b *blockBuilder) applyTransactionFromSubProtocol() error {
-       cp, err := b.accountManager.GetCoinbaseControlProgram()
-       if err != nil {
-               return err
-       }
-
        isTimeout := func() bool {
                return b.getTimeoutStatus() > timeoutOk
        }
@@ -153,7 +148,7 @@ func (b *blockBuilder) applyTransactionFromSubProtocol() error {
                        break
                }
 
-               subTxs, err := p.BeforeProposalBlock(b.block.Transactions, cp, b.block.Height, b.gasLeft, isTimeout)
+               subTxs, err := p.BeforeProposalBlock(b.block.Transactions, b.block.Height, b.gasLeft, isTimeout)
                if err != nil {
                        log.WithFields(log.Fields{"module": logModule, "index": i, "error": err}).Error("failed on sub protocol txs package")
                        continue
index c1b63a2..b727b1f 100644 (file)
@@ -227,16 +227,16 @@ func (c *Chain) signBlockHeader(blockHeader *types.BlockHeader) ([]byte, error)
        xprv := config.CommonConfig.PrivateKey()
        xpub := xprv.XPub()
        node, err := c.getConsensusNode(&blockHeader.PreviousBlockHash, xpub.String())
-       blockHash := blockHeader.Hash().String()
+       blockHash := blockHeader.Hash()
        if err == errNotFoundConsensusNode {
-               log.WithFields(log.Fields{"module": logModule, "blockHash": blockHash}).Warn("can't find consensus node of current node")
+               log.WithFields(log.Fields{"module": logModule, "blockHash": blockHash.String()}).Warn("can't find consensus node of current node")
                return nil, nil
        } else if err != nil {
                return nil, err
        }
 
        if err := c.checkDoubleSign(blockHeader, node.XPub.String()); err == errDoubleSignBlock {
-               log.WithFields(log.Fields{"module": logModule, "blockHash": blockHash}).Warn("current node has double sign the block")
+               log.WithFields(log.Fields{"module": logModule, "blockHash": blockHash.String()}).Warn("current node has double sign the block")
                return nil, nil
        } else if err != nil {
                return nil, err
index 40888aa..48b11b1 100644 (file)
@@ -22,7 +22,7 @@ const (
 type Protocoler interface {
        Name() string
        StartHeight() uint64
-       BeforeProposalBlock(txs []*types.Tx, nodeProgram []byte, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error)
+       BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error)
        ChainStatus() (uint64, *bc.Hash, error)
        ValidateBlock(block *types.Block, verifyResults []*bc.TxVerifyResult) error
        ValidateTxs(txs []*types.Tx, verifyResults []*bc.TxVerifyResult) error