// 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
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))
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...)
)
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{
{
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),
},
}),
// 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")),
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),
},
}),
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),
},
}),
}
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"
}
// 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
}
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()
package mov
import (
+ "encoding/hex"
"math"
"os"
"testing"
}
func TestBeforeProposalBlock(t *testing.T) {
+ consensus.ActiveNetParams.MovRewardProgram = hex.EncodeToString(mock.RewardProgram)
+
cases := []struct {
desc string
initOrders []*common.Order
}
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)
}
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
}
func (b *blockBuilder) applyTransactionFromSubProtocol() error {
- cp, err := b.accountManager.GetCoinbaseControlProgram()
- if err != nil {
- return err
- }
-
isTimeout := func() bool {
return b.getTimeoutStatus() > timeoutOk
}
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
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
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