修訂 | dc43c45b0f6f0e0eda023465ff98d90e745abc58 (tree) |
---|---|
時間 | 2020-03-03 15:15:34 |
作者 | shenao78 <shenao.78@163....> |
Commiter | shenao78 |
fixed reward address
@@ -18,14 +18,14 @@ import ( | ||
18 | 18 | |
19 | 19 | // Engine is used to generate math transactions |
20 | 20 | type Engine struct { |
21 | - orderBook *OrderBook | |
22 | - maxFeeRate float64 | |
23 | - nodeProgram []byte | |
21 | + orderBook *OrderBook | |
22 | + maxFeeRate float64 | |
23 | + rewardProgram []byte | |
24 | 24 | } |
25 | 25 | |
26 | 26 | // NewEngine return a new Engine |
27 | -func NewEngine(orderBook *OrderBook, maxFeeRate float64, nodeProgram []byte) *Engine { | |
28 | - return &Engine{orderBook: orderBook, maxFeeRate: maxFeeRate, nodeProgram: nodeProgram} | |
27 | +func NewEngine(orderBook *OrderBook, maxFeeRate float64, rewardProgram []byte) *Engine { | |
28 | + return &Engine{orderBook: orderBook, maxFeeRate: maxFeeRate, rewardProgram: rewardProgram} | |
29 | 29 | } |
30 | 30 | |
31 | 31 | // HasMatchedTx check does the input trade pair can generate a match deal |
@@ -77,7 +77,7 @@ func (e *Engine) addMatchTxFeeOutput(txData *types.TxData) error { | ||
77 | 77 | feeAmount = matchTxFee.MaxFeeAmount |
78 | 78 | reminder = matchTxFee.FeeAmount - matchTxFee.MaxFeeAmount |
79 | 79 | } |
80 | - txData.Outputs = append(txData.Outputs, types.NewIntraChainOutput(assetID, uint64(feeAmount), e.nodeProgram)) | |
80 | + txData.Outputs = append(txData.Outputs, types.NewIntraChainOutput(assetID, uint64(feeAmount), e.rewardProgram)) | |
81 | 81 | |
82 | 82 | // There is the remaining amount after paying the handling fee, assign it evenly to participants in the transaction |
83 | 83 | averageAmount := reminder / int64(len(txData.Inputs)) |
@@ -80,7 +80,7 @@ func TestGenerateMatchedTxs(t *testing.T) { | ||
80 | 80 | |
81 | 81 | for i, c := range cases { |
82 | 82 | movStore := mock.NewMovStore([]*common.TradePair{btc2eth, eth2btc}, c.initStoreOrders) |
83 | - matchEngine := NewEngine(NewOrderBook(movStore, nil, nil), 0.05, mock.NodeProgram) | |
83 | + matchEngine := NewEngine(NewOrderBook(movStore, nil, nil), 0.05, mock.RewardProgram) | |
84 | 84 | var gotMatchedTxs []*types.Tx |
85 | 85 | for matchEngine.HasMatchedTx(c.tradePairs...) { |
86 | 86 | matchedTx, err := matchEngine.NextMatchedTx(c.tradePairs...) |
@@ -10,11 +10,11 @@ import ( | ||
10 | 10 | ) |
11 | 11 | |
12 | 12 | var ( |
13 | - BTC = bc.NewAssetID([32]byte{1}) | |
14 | - ETH = bc.NewAssetID([32]byte{2}) | |
15 | - EOS = bc.NewAssetID([32]byte{3}) | |
16 | - ETC = bc.NewAssetID([32]byte{4}) | |
17 | - NodeProgram = []byte{0x58} | |
13 | + BTC = bc.NewAssetID([32]byte{1}) | |
14 | + ETH = bc.NewAssetID([32]byte{2}) | |
15 | + EOS = bc.NewAssetID([32]byte{3}) | |
16 | + ETC = bc.NewAssetID([32]byte{4}) | |
17 | + RewardProgram = []byte{0x58} | |
18 | 18 | |
19 | 19 | Btc2EthOrders = []*common.Order{ |
20 | 20 | { |
@@ -269,7 +269,7 @@ var ( | ||
269 | 269 | Outputs: []*types.TxOutput{ |
270 | 270 | types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 500, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19251")), |
271 | 271 | types.NewIntraChainOutput(*Eth2BtcOrders[0].ToAssetID, 10, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19253")), |
272 | - types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 10, NodeProgram), | |
272 | + types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 10, RewardProgram), | |
273 | 273 | }, |
274 | 274 | }), |
275 | 275 |
@@ -285,7 +285,7 @@ var ( | ||
285 | 285 | // re-order |
286 | 286 | types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, 270, Eth2BtcOrders[2].Utxo.ControlProgram), |
287 | 287 | // fee |
288 | - types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, 27, NodeProgram), | |
288 | + types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, 27, RewardProgram), | |
289 | 289 | // refund |
290 | 290 | types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, 6, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19251")), |
291 | 291 | types.NewIntraChainOutput(*Eth2BtcOrders[2].FromAssetID, 7, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19255")), |
@@ -370,7 +370,7 @@ var ( | ||
370 | 370 | types.NewIntraChainOutput(*Btc2EthOrders[3].FromAssetID, 1, Btc2EthOrders[3].Utxo.ControlProgram), |
371 | 371 | types.NewIntraChainOutput(*Eth2BtcOrders[2].ToAssetID, 15, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19255")), |
372 | 372 | // fee |
373 | - types.NewIntraChainOutput(*Btc2EthOrders[3].FromAssetID, 1, NodeProgram), | |
373 | + types.NewIntraChainOutput(*Btc2EthOrders[3].FromAssetID, 1, RewardProgram), | |
374 | 374 | }, |
375 | 375 | }), |
376 | 376 |
@@ -395,7 +395,7 @@ var ( | ||
395 | 395 | Outputs: []*types.TxOutput{ |
396 | 396 | types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 500, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19251")), |
397 | 397 | types.NewIntraChainOutput(*Eth2BtcOrders[0].ToAssetID, 10, testutil.MustDecodeHexString("0014f928b723999312df4ed51cb275a2644336c19253")), |
398 | - types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 10, NodeProgram), | |
398 | + types.NewIntraChainOutput(*Btc2EthOrders[0].ToAssetID, 10, RewardProgram), | |
399 | 399 | }, |
400 | 400 | }), |
401 | 401 | } |
@@ -1,10 +1,13 @@ | ||
1 | 1 | package mov |
2 | 2 | |
3 | 3 | import ( |
4 | + "encoding/hex" | |
5 | + | |
4 | 6 | "github.com/bytom/vapor/application/mov/common" |
5 | 7 | "github.com/bytom/vapor/application/mov/contract" |
6 | 8 | "github.com/bytom/vapor/application/mov/database" |
7 | 9 | "github.com/bytom/vapor/application/mov/match" |
10 | + "github.com/bytom/vapor/consensus" | |
8 | 11 | "github.com/bytom/vapor/consensus/segwit" |
9 | 12 | dbm "github.com/bytom/vapor/database/leveldb" |
10 | 13 | "github.com/bytom/vapor/errors" |
@@ -71,7 +74,7 @@ func (m *MovCore) ApplyBlock(block *types.Block) error { | ||
71 | 74 | } |
72 | 75 | |
73 | 76 | // BeforeProposalBlock return all transactions than can be matched, and the number of transactions cannot exceed the given capacity. |
74 | -func (m *MovCore) BeforeProposalBlock(txs []*types.Tx, nodeProgram []byte, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error) { | |
77 | +func (m *MovCore) BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error) { | |
75 | 78 | if blockHeight <= m.startBlockHeight { |
76 | 79 | return nil, nil |
77 | 80 | } |
@@ -81,7 +84,12 @@ func (m *MovCore) BeforeProposalBlock(txs []*types.Tx, nodeProgram []byte, block | ||
81 | 84 | return nil, err |
82 | 85 | } |
83 | 86 | |
84 | - matchEngine := match.NewEngine(orderBook, maxFeeRate, nodeProgram) | |
87 | + rewardProgram, err := hex.DecodeString(consensus.ActiveNetParams.MovRewardProgram) | |
88 | + if err != nil { | |
89 | + return nil, err | |
90 | + } | |
91 | + | |
92 | + matchEngine := match.NewEngine(orderBook, maxFeeRate, rewardProgram) | |
85 | 93 | tradePairIterator := database.NewTradePairIterator(m.movStore) |
86 | 94 | matchCollector := newMatchTxCollector(matchEngine, tradePairIterator, gasLeft, isTimeout) |
87 | 95 | return matchCollector.result() |
@@ -1,6 +1,7 @@ | ||
1 | 1 | package mov |
2 | 2 | |
3 | 3 | import ( |
4 | + "encoding/hex" | |
4 | 5 | "math" |
5 | 6 | "os" |
6 | 7 | "testing" |
@@ -508,6 +509,8 @@ func TestValidateBlock(t *testing.T) { | ||
508 | 509 | } |
509 | 510 | |
510 | 511 | func TestBeforeProposalBlock(t *testing.T) { |
512 | + consensus.ActiveNetParams.MovRewardProgram = hex.EncodeToString(mock.RewardProgram) | |
513 | + | |
511 | 514 | cases := []struct { |
512 | 515 | desc string |
513 | 516 | initOrders []*common.Order |
@@ -572,7 +575,7 @@ func TestBeforeProposalBlock(t *testing.T) { | ||
572 | 575 | } |
573 | 576 | |
574 | 577 | movCore := &MovCore{movStore: store} |
575 | - gotMatchedTxs, err := movCore.BeforeProposalBlock(nil, []byte{0x51}, 2, c.gasLeft, func() bool { return false }) | |
578 | + gotMatchedTxs, err := movCore.BeforeProposalBlock(nil, 2, c.gasLeft, func() bool { return false }) | |
576 | 579 | if err != nil { |
577 | 580 | t.Fatal(err) |
578 | 581 | } |
@@ -103,7 +103,12 @@ type Params struct { | ||
103 | 103 | ProducerSubsidys []ProducerSubsidy |
104 | 104 | |
105 | 105 | SoftForkPoint map[uint64]uint64 |
106 | + | |
107 | + // Mov will only start when the block height is greater than this value | |
106 | 108 | MovStartHeight uint64 |
109 | + | |
110 | + // Used to receive rewards for matching transactions | |
111 | + MovRewardProgram string | |
107 | 112 | } |
108 | 113 | |
109 | 114 | // ActiveNetParams is the active NetParams |
@@ -139,11 +139,6 @@ func (b *blockBuilder) applyTransactionFromPool() error { | ||
139 | 139 | } |
140 | 140 | |
141 | 141 | func (b *blockBuilder) applyTransactionFromSubProtocol() error { |
142 | - cp, err := b.accountManager.GetCoinbaseControlProgram() | |
143 | - if err != nil { | |
144 | - return err | |
145 | - } | |
146 | - | |
147 | 142 | isTimeout := func() bool { |
148 | 143 | return b.getTimeoutStatus() > timeoutOk |
149 | 144 | } |
@@ -153,7 +148,7 @@ func (b *blockBuilder) applyTransactionFromSubProtocol() error { | ||
153 | 148 | break |
154 | 149 | } |
155 | 150 | |
156 | - subTxs, err := p.BeforeProposalBlock(b.block.Transactions, cp, b.block.Height, b.gasLeft, isTimeout) | |
151 | + subTxs, err := p.BeforeProposalBlock(b.block.Transactions, b.block.Height, b.gasLeft, isTimeout) | |
157 | 152 | if err != nil { |
158 | 153 | log.WithFields(log.Fields{"module": logModule, "index": i, "error": err}).Error("failed on sub protocol txs package") |
159 | 154 | continue |
@@ -227,16 +227,16 @@ func (c *Chain) signBlockHeader(blockHeader *types.BlockHeader) ([]byte, error) | ||
227 | 227 | xprv := config.CommonConfig.PrivateKey() |
228 | 228 | xpub := xprv.XPub() |
229 | 229 | node, err := c.getConsensusNode(&blockHeader.PreviousBlockHash, xpub.String()) |
230 | - blockHash := blockHeader.Hash().String() | |
230 | + blockHash := blockHeader.Hash() | |
231 | 231 | if err == errNotFoundConsensusNode { |
232 | - log.WithFields(log.Fields{"module": logModule, "blockHash": blockHash}).Warn("can't find consensus node of current node") | |
232 | + log.WithFields(log.Fields{"module": logModule, "blockHash": blockHash.String()}).Warn("can't find consensus node of current node") | |
233 | 233 | return nil, nil |
234 | 234 | } else if err != nil { |
235 | 235 | return nil, err |
236 | 236 | } |
237 | 237 | |
238 | 238 | if err := c.checkDoubleSign(blockHeader, node.XPub.String()); err == errDoubleSignBlock { |
239 | - log.WithFields(log.Fields{"module": logModule, "blockHash": blockHash}).Warn("current node has double sign the block") | |
239 | + log.WithFields(log.Fields{"module": logModule, "blockHash": blockHash.String()}).Warn("current node has double sign the block") | |
240 | 240 | return nil, nil |
241 | 241 | } else if err != nil { |
242 | 242 | return nil, err |
@@ -22,7 +22,7 @@ const ( | ||
22 | 22 | type Protocoler interface { |
23 | 23 | Name() string |
24 | 24 | StartHeight() uint64 |
25 | - BeforeProposalBlock(txs []*types.Tx, nodeProgram []byte, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error) | |
25 | + BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error) | |
26 | 26 | ChainStatus() (uint64, *bc.Hash, error) |
27 | 27 | ValidateBlock(block *types.Block, verifyResults []*bc.TxVerifyResult) error |
28 | 28 | ValidateTxs(txs []*types.Tx, verifyResults []*bc.TxVerifyResult) error |