• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版cdf7e7a5604300477dbd2132bca15e7bdab947bb (tree)
时间2020-03-09 16:08:38
作者shenao78 <shenao.78@163....>
Commitershenao78

Log Message

fee strategy

更改概述

差异

--- a/application/mov/mov_core.go
+++ b/application/mov/mov_core.go
@@ -75,7 +75,7 @@ func (m *MovCore) ApplyBlock(block *types.Block) error {
7575 }
7676
7777 // BeforeProposalBlock return all transactions than can be matched, and the number of transactions cannot exceed the given capacity.
78-func (m *MovCore) BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error) {
78+func (m *MovCore) BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, nodeProgram []byte, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error) {
7979 if blockHeight <= m.startBlockHeight {
8080 return nil, nil
8181 }
@@ -85,13 +85,7 @@ func (m *MovCore) BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, gasLe
8585 return nil, err
8686 }
8787
88- program, _ := getRewardProgram(blockHeight)
89- rewardProgram, err := hex.DecodeString(program)
90- if err != nil {
91- return nil, errNotConfiguredRewardProgram
92- }
93-
94- matchEngine := match.NewEngine(orderBook, match.NewDefaultFeeStrategy(maxFeeRate), rewardProgram)
88+ matchEngine := match.NewEngine(orderBook, match.NewDefaultFeeStrategy(maxFeeRate), nodeProgram)
9589 tradePairIterator := database.NewTradePairIterator(m.movStore)
9690 matchCollector := newMatchTxCollector(matchEngine, tradePairIterator, gasLeft, isTimeout)
9791 return matchCollector.result()
@@ -290,12 +284,6 @@ func validateMatchedTxFee(tx *types.Tx, blockHeight uint64) error {
290284 return err
291285 }
292286
293- for _, fee := range matchedTxFees {
294- if err := validateRewardProgram(blockHeight, hex.EncodeToString(fee.rewardProgram)); err != nil {
295- return err
296- }
297- }
298-
299287 orders, err := getDeleteOrdersFromTx(tx)
300288 if err != nil {
301289 return err
@@ -509,11 +497,3 @@ func getRewardProgram(height uint64) (string, bool) {
509497 }
510498 return program, false
511499 }
512-
513-func validateRewardProgram(height uint64, program string) error {
514- rewardProgram, exact := getRewardProgram(height)
515- if exact && rewardProgram != program {
516- return errRewardProgramIsWrong
517- }
518- return nil
519-}
--- a/application/mov/mov_core_test.go
+++ b/application/mov/mov_core_test.go
@@ -629,7 +629,7 @@ func TestBeforeProposalBlock(t *testing.T) {
629629 }
630630
631631 movCore := &MovCore{movStore: store}
632- gotMatchedTxs, err := movCore.BeforeProposalBlock(nil, 2, c.gasLeft, func() bool { return false })
632+ gotMatchedTxs, err := movCore.BeforeProposalBlock(nil, 2, mock.RewardProgram, c.gasLeft, func() bool { return false })
633633 if err != nil {
634634 t.Fatal(err)
635635 }
--- a/proposal/proposal.go
+++ b/proposal/proposal.go
@@ -143,12 +143,17 @@ func (b *blockBuilder) applyTransactionFromSubProtocol() error {
143143 return b.getTimeoutStatus() > timeoutOk
144144 }
145145
146+ cp, err := b.accountManager.GetCoinbaseControlProgram()
147+ if err != nil {
148+ return err
149+ }
150+
146151 for i, p := range b.chain.SubProtocols() {
147152 if b.gasLeft <= 0 || isTimeout() {
148153 break
149154 }
150155
151- subTxs, err := p.BeforeProposalBlock(b.block.Transactions, b.block.Height, b.gasLeft, isTimeout)
156+ subTxs, err := p.BeforeProposalBlock(b.block.Transactions, b.block.Height, cp, b.gasLeft, isTimeout)
152157 if err != nil {
153158 log.WithFields(log.Fields{"module": logModule, "index": i, "error": err}).Error("failed on sub protocol txs package")
154159 continue
--- a/protocol/protocol.go
+++ b/protocol/protocol.go
@@ -22,7 +22,7 @@ const (
2222 type Protocoler interface {
2323 Name() string
2424 StartHeight() uint64
25- BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error)
25+ BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, nodeProgram []byte, gasLeft int64, isTimeout func() bool) ([]*types.Tx, error)
2626 ChainStatus() (uint64, *bc.Hash, error)
2727 ValidateBlock(block *types.Block, verifyResults []*bc.TxVerifyResult) error
2828 ValidateTx(tx *types.Tx, verifyResult *bc.TxVerifyResult, blockHeight uint64) error
Show on old repository browser