• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版e443154b503e35d6f66cbe3a4463ffdd31b6b52a (tree)
时间2020-03-06 16:55:36
作者shenao78 <shenao.78@163....>
Commitershenao78

Log Message

opt code

更改概述

差异

--- a/application/mov/mov_core.go
+++ b/application/mov/mov_core.go
@@ -28,7 +28,7 @@ var (
2828 errSpendOutputIDIsIncorrect = errors.New("spend output id of matched tx is not equals to actual matched tx")
2929 errRequestAmountMath = errors.New("request amount of order less than one or big than max of int64")
3030 errNotMatchedOrder = errors.New("order in matched tx is not matched")
31- errNoRewardProgramConfigured = errors.New("no reward program configured")
31+ errNotConfiguredRewardProgram = errors.New("reward program is not configured properly")
3232 errRewardProgramIsWrong = errors.New("the reward program is not correct")
3333 )
3434
@@ -85,9 +85,10 @@ func (m *MovCore) BeforeProposalBlock(txs []*types.Tx, blockHeight uint64, gasLe
8585 return nil, err
8686 }
8787
88- rewardProgram, err := getRewardProgram(blockHeight)
88+ program, _ := getRewardProgram(blockHeight)
89+ rewardProgram, err := hex.DecodeString(program)
8990 if err != nil {
90- return nil, err
91+ return nil, errNotConfiguredRewardProgram
9192 }
9293
9394 matchEngine := match.NewEngine(orderBook, match.NewDefaultFeeStrategy(maxFeeRate), rewardProgram)
@@ -489,30 +490,30 @@ func mergeOrders(addOrderMap, deleteOrderMap map[string]*common.Order) ([]*commo
489490 return addOrders, deleteOrders
490491 }
491492
492-func getRewardProgram(height uint64) ([]byte, error) {
493+// getRewardProgram return the reward program by specified block height
494+// if no reward program configured, then will return empty string
495+// if reward program of 0-100 height is configured, but the specified height is 200, then will return 0-100's reward program
496+// the second return value represent whether to find exactly
497+func getRewardProgram(height uint64) (string, bool) {
493498 rewardPrograms := consensus.ActiveNetParams.MovRewardPrograms
494499 if len(rewardPrograms) == 0 {
495- return nil, errNoRewardProgramConfigured
500+ return "", false
496501 }
497502
498503 var program string
499504 for _, rewardProgram := range rewardPrograms {
500505 program = rewardProgram.Program
501506 if height >= rewardProgram.BeginBlock && height <= rewardProgram.EndBlock {
502- break
507+ return program, true
503508 }
504509 }
505- return hex.DecodeString(program)
510+ return program, false
506511 }
507512
508513 func validateRewardProgram(height uint64, program string) error {
509- for _, rewardProgram := range consensus.ActiveNetParams.MovRewardPrograms {
510- if height >= rewardProgram.BeginBlock && height <= rewardProgram.EndBlock {
511- if rewardProgram.Program != program {
512- return errRewardProgramIsWrong
513- }
514- return nil
515- }
514+ rewardProgram, exact := getRewardProgram(height)
515+ if exact && rewardProgram != program {
516+ return errRewardProgramIsWrong
516517 }
517518 return nil
518519 }
Show on old repository browser