• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: 提交

Golang implemented sidechain for Bytom


Commit MetaInfo

修订版9d13f32318300cac93fe20f966442a5fde9f676d (tree)
时间2019-10-28 11:16:51
作者shenao78 <shenao.78@163....>
Commitershenao78

Log Message

Merge branch 'mov' into fix_mov_store

更改概述

差异

--- a/account/builder.go
+++ b/account/builder.go
@@ -20,7 +20,7 @@ var (
2020 //chainTxUtxoNum maximum utxo quantity in a tx
2121 chainTxUtxoNum = 20
2222 //chainTxMergeGas chain tx gas
23- chainTxMergeGas = uint64(10000000)
23+ chainTxMergeGas = uint64(0)
2424 )
2525
2626 //DecodeSpendAction unmarshal JSON-encoded data of spend action
--- a/account/builder_test.go
+++ b/account/builder_test.go
@@ -354,56 +354,10 @@ func TestMergeSpendAction(t *testing.T) {
354354 }
355355 }
356356
357-func TestCalcMergeGas(t *testing.T) {
358- chainTxUtxoNum = 10
359- cases := []struct {
360- utxoNum int
361- gas uint64
362- }{
363- {
364- utxoNum: 0,
365- gas: 0,
366- },
367- {
368- utxoNum: 1,
369- gas: 0,
370- },
371- {
372- utxoNum: 9,
373- gas: chainTxMergeGas,
374- },
375- {
376- utxoNum: 10,
377- gas: chainTxMergeGas,
378- },
379- {
380- utxoNum: 11,
381- gas: chainTxMergeGas * 2,
382- },
383- {
384- utxoNum: 20,
385- gas: chainTxMergeGas * 3,
386- },
387- {
388- utxoNum: 21,
389- gas: chainTxMergeGas * 3,
390- },
391- {
392- utxoNum: 74,
393- gas: chainTxMergeGas * 9,
394- },
395- }
396-
397- for i, c := range cases {
398- gas := calcMergeGas(c.utxoNum)
399- if gas != c.gas {
400- t.Fatalf("case %d got %d want %d", i, gas, c.gas)
401- }
402- }
403-}
404-
405357 func TestReserveBtmUtxoChain(t *testing.T) {
406358 chainTxUtxoNum = 3
359+ chainTxMergeGas = uint64(10000000)
360+
407361 utxos := []*UTXO{}
408362 m := mockAccountManager(t)
409363 for i := uint64(1); i <= 20; i++ {
--- a/consensus/general.go
+++ b/consensus/general.go
@@ -103,6 +103,7 @@ type Params struct {
103103 ProducerSubsidys []ProducerSubsidy
104104
105105 SoftForkPoint map[uint64]uint64
106+ MovStartPoint Checkpoint
106107 }
107108
108109 // ActiveNetParams is the active NetParams
--- a/netsync/chainmgr/handle.go
+++ b/netsync/chainmgr/handle.go
@@ -50,6 +50,7 @@ type Switch interface {
5050 // Mempool is the interface for Bytom mempool
5151 type Mempool interface {
5252 GetTransactions() []*core.TxDesc
53+ IsDust(tx *types.Tx) bool
5354 }
5455
5556 //Manager is responsible for the business layer information synchronization
@@ -254,6 +255,11 @@ func (m *Manager) handleTransactionMsg(peer *peers.Peer, msg *msgs.TransactionMe
254255 return
255256 }
256257
258+ if m.mempool.IsDust(tx) {
259+ m.peers.ProcessIllegal(peer.ID(), security.LevelMsgIllegal, "receive dust tx msg")
260+ return
261+ }
262+
257263 m.peers.MarkTx(peer.ID(), tx.ID)
258264 if isOrphan, err := m.chain.ValidateTx(tx); err != nil && err != core.ErrDustTx && !isOrphan {
259265 m.peers.ProcessIllegal(peer.ID(), security.LevelMsgIllegal, "fail on validate tx transaction")
@@ -273,6 +279,11 @@ func (m *Manager) handleTransactionsMsg(peer *peers.Peer, msg *msgs.Transactions
273279 }
274280
275281 for _, tx := range txs {
282+ if m.mempool.IsDust(tx) {
283+ m.peers.ProcessIllegal(peer.ID(), security.LevelMsgIllegal, "receive dust txs msg")
284+ continue
285+ }
286+
276287 m.peers.MarkTx(peer.ID(), tx.ID)
277288 if isOrphan, err := m.chain.ValidateTx(tx); err != nil && !isOrphan {
278289 m.peers.ProcessIllegal(peer.ID(), security.LevelMsgIllegal, "fail on validate tx transaction")
--- a/node/node.go
+++ b/node/node.go
@@ -83,7 +83,11 @@ func NewNode(config *cfg.Config) *Node {
8383 }
8484
8585 initCommonConfig(config)
86-
86+ movDB := dbm.NewDB("mov", config.DBBackend, config.DBDir())
87+ mov, err := protocol.NewMOV(movDB, consensus.ActiveNetParams.MovStartPoint)
88+ if err != nil {
89+ log.Fatalf("Failed to create Mov protocol", err.Error())
90+ }
8791 // Get store
8892 if config.DBBackend != "memdb" && config.DBBackend != "leveldb" {
8993 cmn.Exit(cmn.Fmt("Param db_backend [%v] is invalid, use leveldb or memdb", config.DBBackend))
@@ -95,8 +99,8 @@ func NewNode(config *cfg.Config) *Node {
9599 accessTokens := accesstoken.NewStore(tokenDB)
96100
97101 dispatcher := event.NewDispatcher()
98- txPool := protocol.NewTxPool(store, dispatcher)
99- chain, err := protocol.NewChain(store, txPool, dispatcher)
102+ txPool := protocol.NewTxPool(store, []protocol.DustFilterer{mov}, dispatcher)
103+ chain, err := protocol.NewChain(store, txPool, []protocol.Protocoler{mov}, dispatcher)
100104 if err != nil {
101105 cmn.Exit(cmn.Fmt("Failed to create chain structure: %v", err))
102106 }
@@ -162,7 +166,7 @@ func NewNode(config *cfg.Config) *Node {
162166 notificationMgr: notificationMgr,
163167 }
164168
165- node.cpuMiner = blockproposer.NewBlockProposer(chain, accounts, txPool, dispatcher)
169+ node.cpuMiner = blockproposer.NewBlockProposer(chain, accounts, txPool, []blockproposer.Preprocessor{mov}, dispatcher)
166170 node.BaseService = *cmn.NewBaseService(nil, "Node", node)
167171 return node
168172 }
--- a/proposal/blockproposer/blockproposer.go
+++ b/proposal/blockproposer/blockproposer.go
@@ -2,6 +2,7 @@ package blockproposer
22
33 import (
44 "encoding/hex"
5+ "sort"
56 "sync"
67 "time"
78
@@ -13,18 +14,25 @@ import (
1314 "github.com/vapor/event"
1415 "github.com/vapor/proposal"
1516 "github.com/vapor/protocol"
17+ "github.com/vapor/protocol/bc/types"
1618 )
1719
1820 const (
19- logModule = "blockproposer"
21+ logModule = "blockproposer"
22+ maxBlockTxNum = 3000
2023 )
2124
25+type Preprocessor interface {
26+ BeforeProposalBlock(capacity int) ([]*types.Tx, error)
27+}
28+
2229 // BlockProposer propose several block in specified time range
2330 type BlockProposer struct {
2431 sync.Mutex
2532 chain *protocol.Chain
2633 accountManager *account.Manager
2734 txPool *protocol.TxPool
35+ preprocessors []Preprocessor
2836 started bool
2937 quit chan struct{}
3038 eventDispatcher *event.Dispatcher
@@ -74,7 +82,28 @@ func (b *BlockProposer) generateBlocks() {
7482 continue
7583 }
7684
77- block, err := proposal.NewBlockTemplate(b.chain, b.txPool, b.accountManager, nextBlockTime)
85+ var packageTxs []*types.Tx
86+ txs := b.txPool.GetTransactions()
87+ sort.Sort(byTime(txs))
88+ for _, txDesc := range txs {
89+ packageTxs = append(packageTxs, txDesc.Tx)
90+ }
91+ capacity := maxBlockTxNum - len(txs)
92+ for i, p := range b.preprocessors {
93+ if capacity <= 0 {
94+ break
95+ }
96+
97+ txs, err := p.BeforeProposalBlock(capacity)
98+ if err != nil {
99+ log.WithFields(log.Fields{"module": logModule, "index": i, "error": err}).Error("failed on sub protocol txs package")
100+ continue
101+ }
102+ packageTxs = append(packageTxs, txs...)
103+ capacity = capacity - len(txs)
104+ }
105+
106+ block, err := proposal.NewBlockTemplate(b.chain, b.txPool, b.accountManager, packageTxs, nextBlockTime)
78107 if err != nil {
79108 log.WithFields(log.Fields{"module": logModule, "error": err}).Error("failed on create NewBlockTemplate")
80109 continue
@@ -147,11 +176,12 @@ func (b *BlockProposer) IsProposing() bool {
147176 // NewBlockProposer returns a new instance of a block proposer for the provided configuration.
148177 // Use Start to begin the proposal process. See the documentation for BlockProposer
149178 // type for more details.
150-func NewBlockProposer(c *protocol.Chain, accountManager *account.Manager, txPool *protocol.TxPool, dispatcher *event.Dispatcher) *BlockProposer {
179+func NewBlockProposer(c *protocol.Chain, accountManager *account.Manager, txPool *protocol.TxPool, preprocessors []Preprocessor, dispatcher *event.Dispatcher) *BlockProposer {
151180 return &BlockProposer{
152181 chain: c,
153182 accountManager: accountManager,
154183 txPool: txPool,
184+ preprocessors: preprocessors,
155185 eventDispatcher: dispatcher,
156186 }
157187 }
--- a/proposal/sort.go
+++ b/proposal/blockproposer/sort.go
@@ -1,4 +1,4 @@
1-package proposal
1+package blockproposer
22
33 import "github.com/vapor/protocol"
44
--- a/proposal/proposal.go
+++ b/proposal/proposal.go
@@ -1,7 +1,6 @@
11 package proposal
22
33 import (
4- "sort"
54 "strconv"
65 "time"
76
@@ -74,7 +73,7 @@ func createCoinbaseTx(accountManager *account.Manager, blockHeight uint64, rewar
7473 }
7574
7675 // NewBlockTemplate returns a new block template that is ready to be solved
77-func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager *account.Manager, timestamp uint64) (b *types.Block, err error) {
76+func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager *account.Manager, txs []*types.Tx, timestamp uint64) (b *types.Block, err error) {
7877 view := state.NewUtxoViewpoint()
7978 txStatus := bc.NewTransactionStatus()
8079 if err := txStatus.SetStatus(0, false); err != nil {
@@ -101,18 +100,14 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
101100 bcBlock := &bc.Block{BlockHeader: &bc.BlockHeader{Height: nextBlockHeight}}
102101 b.Transactions = []*types.Tx{nil}
103102
104- txs := txPool.GetTransactions()
105- sort.Sort(byTime(txs))
106-
107103 entriesTxs := []*bc.Tx{}
108- for _, txDesc := range txs {
109- entriesTxs = append(entriesTxs, txDesc.Tx.Tx)
104+ for _, tx := range txs {
105+ entriesTxs = append(entriesTxs, tx.Tx)
110106 }
111107
112108 validateResults := validation.ValidateTxs(entriesTxs, bcBlock)
113109 for i, validateResult := range validateResults {
114- txDesc := txs[i]
115- tx := txDesc.Tx.Tx
110+ tx := txs[i].Tx
116111 gasOnlyTx := false
117112
118113 gasStatus := validateResult.GetGasState()
@@ -142,7 +137,7 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
142137 return nil, err
143138 }
144139
145- b.Transactions = append(b.Transactions, txDesc.Tx)
140+ b.Transactions = append(b.Transactions, txs[i])
146141 txEntries = append(txEntries, tx)
147142 gasUsed += uint64(gasStatus.GasUsed)
148143 if gasUsed == consensus.ActiveNetParams.MaxBlockGas {
--- a/protocol/block.go
+++ b/protocol/block.go
@@ -110,6 +110,12 @@ func (c *Chain) connectBlock(block *types.Block) (err error) {
110110 return err
111111 }
112112
113+ for _, p := range c.subProtocols {
114+ if err := p.ApplyBlock(block); err != nil {
115+ return errors.Wrap(err, p.Name(), "sub protocol connect block")
116+ }
117+ }
118+
113119 irrBlockHeader := c.lastIrrBlockHeader
114120 if c.isIrreversible(&block.BlockHeader) && block.Height > irrBlockHeader.Height {
115121 irrBlockHeader = &block.BlockHeader
@@ -164,6 +170,12 @@ func (c *Chain) reorganizeChain(blockHeader *types.BlockHeader) error {
164170 return err
165171 }
166172
173+ for _, p := range c.subProtocols {
174+ if err := p.DetachBlock(b); err != nil {
175+ return errors.Wrap(err, p.Name(), "sub protocol detach block")
176+ }
177+ }
178+
167179 for _, tx := range b.Transactions {
168180 txsToRestore[tx.ID] = tx
169181 }
@@ -199,6 +211,12 @@ func (c *Chain) reorganizeChain(blockHeader *types.BlockHeader) error {
199211 return err
200212 }
201213
214+ for _, p := range c.subProtocols {
215+ if err := p.ApplyBlock(b); err != nil {
216+ return errors.Wrap(err, p.Name(), "sub protocol attach block")
217+ }
218+ }
219+
202220 if consensusResult.IsFinalize() {
203221 consensusResults = append(consensusResults, consensusResult.Fork())
204222 }
@@ -280,6 +298,12 @@ func (c *Chain) saveBlock(block *types.Block) error {
280298 return errors.Sub(ErrBadBlock, err)
281299 }
282300
301+ for _, p := range c.subProtocols {
302+ if err := p.ValidateBlock(block); err != nil {
303+ return errors.Wrap(err, "sub protocol save block")
304+ }
305+ }
306+
283307 if err := c.store.SaveBlock(block, bcBlock.TransactionStatus); err != nil {
284308 return err
285309 }
--- /dev/null
+++ b/protocol/mov.go
@@ -0,0 +1,76 @@
1+package protocol
2+
3+import (
4+ "github.com/vapor/application/mov"
5+ "github.com/vapor/config"
6+ "github.com/vapor/consensus"
7+ dbm "github.com/vapor/database/leveldb"
8+ "github.com/vapor/errors"
9+ "github.com/vapor/protocol/bc"
10+ "github.com/vapor/protocol/bc/types"
11+)
12+
13+const (
14+ protocolName = "MOV"
15+)
16+
17+type movCore interface {
18+ ApplyBlock(block *types.Block) error
19+ BeforeProposalBlock(capacity int) ([]*types.Tx, error)
20+ ChainStatus() (uint64, *bc.Hash, error)
21+ DetachBlock(block *types.Block) error
22+ IsDust(tx *types.Tx) bool
23+ ValidateBlock(block *types.Block) error
24+ ValidateTxs(txs []*types.Tx) error
25+}
26+
27+type MOV struct {
28+ core movCore
29+}
30+
31+func NewMOV(db dbm.DB, startPoint consensus.Checkpoint) (*MOV, error) {
32+ if startPoint.Height == 0 {
33+ startPoint.Hash = config.GenesisBlock().Hash()
34+ }
35+
36+ movCore, err := mov.NewMovCore(db, startPoint.Height, &startPoint.Hash)
37+ if err != nil {
38+ return nil, errors.Wrap(err, "failed on create mov core")
39+ }
40+
41+ return &MOV{
42+ core: movCore,
43+ }, nil
44+}
45+
46+func (m MOV) ApplyBlock(block *types.Block) error {
47+ return m.core.ApplyBlock(block)
48+}
49+
50+func (m MOV) BeforeProposalBlock(capacity int) ([]*types.Tx, error) {
51+ return m.core.BeforeProposalBlock(capacity)
52+}
53+
54+func (m MOV) ChainStatus() (uint64, *bc.Hash, error) {
55+ return m.core.ChainStatus()
56+}
57+
58+func (m MOV) DetachBlock(block *types.Block) error {
59+ return m.core.DetachBlock(block)
60+}
61+
62+func (m MOV) IsDust(tx *types.Tx) bool {
63+ return m.core.IsDust(tx)
64+}
65+
66+func (m MOV) Name() string {
67+ return protocolName
68+}
69+
70+func (m MOV) ValidateBlock(block *types.Block) error {
71+ return m.core.ValidateBlock(block)
72+}
73+
74+func (m MOV) ValidateTxs(txs []*types.Tx) error {
75+ return m.core.ValidateTxs(txs)
76+}
--- a/protocol/protocol.go
+++ b/protocol/protocol.go
@@ -7,6 +7,7 @@ import (
77
88 "github.com/vapor/common"
99 "github.com/vapor/config"
10+ "github.com/vapor/errors"
1011 "github.com/vapor/event"
1112 "github.com/vapor/protocol/bc"
1213 "github.com/vapor/protocol/bc/types"
@@ -18,12 +19,22 @@ const (
1819 maxKnownTxs = 32768 // Maximum transactions hashes to keep in the known list (prevent DOS)
1920 )
2021
22+type Protocoler interface {
23+ Name() string
24+ ChainStatus() (uint64, *bc.Hash, error)
25+ ValidateBlock(block *types.Block) error
26+ ValidateTxs(txs []*types.Tx) error
27+ ApplyBlock(block *types.Block) error
28+ DetachBlock(block *types.Block) error
29+}
30+
2131 // Chain provides functions for working with the Bytom block chain.
2232 type Chain struct {
2333 orphanManage *OrphanManage
2434 txPool *TxPool
2535 store Store
2636 processBlockCh chan *processBlockMsg
37+ subProtocols []Protocoler
2738
2839 signatureCache *common.Cache
2940 eventDispatcher *event.Dispatcher
@@ -36,12 +47,13 @@ type Chain struct {
3647 }
3748
3849 // NewChain returns a new Chain using store as the underlying storage.
39-func NewChain(store Store, txPool *TxPool, eventDispatcher *event.Dispatcher) (*Chain, error) {
50+func NewChain(store Store, txPool *TxPool, subProtocols []Protocoler, eventDispatcher *event.Dispatcher) (*Chain, error) {
4051 knownTxs, _ := common.NewOrderedSet(maxKnownTxs)
4152 c := &Chain{
4253 orphanManage: NewOrphanManage(),
4354 txPool: txPool,
4455 store: store,
56+ subProtocols: subProtocols,
4557 signatureCache: common.NewCache(maxSignatureCacheSize),
4658 eventDispatcher: eventDispatcher,
4759 processBlockCh: make(chan *processBlockMsg, maxProcessBlockChSize),
@@ -67,6 +79,13 @@ func NewChain(store Store, txPool *TxPool, eventDispatcher *event.Dispatcher) (*
6779 if err != nil {
6880 return nil, err
6981 }
82+
83+ for _, p := range c.subProtocols {
84+ if err := c.syncProtocolStatus(p); err != nil {
85+ return nil, errors.Wrap(err, p.Name(), "sync sub protocol status")
86+ }
87+ }
88+
7089 go c.blockProcesser()
7190 return c, nil
7291 }
@@ -182,6 +201,55 @@ func (c *Chain) markTransactions(txs ...*types.Tx) {
182201 }
183202 }
184203
204+func (c *Chain) syncProtocolStatus(subProtocol Protocoler) error {
205+ protocolHeight, protocolHash, err := subProtocol.ChainStatus()
206+ if err != nil {
207+ return errors.Wrap(err, "failed on get sub protocol status")
208+ }
209+
210+ if protocolHeight == c.BestBlockHeight() && protocolHash == c.BestBlockHash() {
211+ return nil
212+ }
213+
214+ for !c.InMainChain(*protocolHash) {
215+ block, err := c.GetBlockByHash(protocolHash)
216+ if err != nil {
217+ return errors.Wrap(err, subProtocol.Name(), "can't get block by hash in chain")
218+ }
219+
220+ if err := subProtocol.DetachBlock(block); err != nil {
221+ return errors.Wrap(err, subProtocol.Name(), "sub protocol detach block err")
222+ }
223+
224+ protocolHeight, protocolHash, err = subProtocol.ChainStatus()
225+ if err != nil {
226+ return errors.Wrap(err, "failed on get sub protocol status")
227+ }
228+ }
229+
230+ for height := protocolHeight + 1; height <= c.BestBlockHeight(); height++ {
231+ block, err := c.GetBlockByHeight(height)
232+ if err != nil {
233+ return errors.Wrap(err, subProtocol.Name(), "can't get block by height in chain")
234+ }
235+
236+ if err := subProtocol.ApplyBlock(block); err != nil {
237+ return errors.Wrap(err, subProtocol.Name(), "sub protocol apply block err")
238+ }
239+
240+ protocolHeight, protocolHash, err = subProtocol.ChainStatus()
241+ if err != nil {
242+ return errors.Wrap(err, "failed on get sub protocol status")
243+ }
244+
245+ if *protocolHash != block.Hash() {
246+ return errors.Wrap(errors.New("sub protocol status sync err"), subProtocol.Name())
247+ }
248+ }
249+
250+ return nil
251+}
252+
185253 // This function must be called with mu lock in above level
186254 func (c *Chain) setState(blockHeader, irrBlockHeader *types.BlockHeader, mainBlockHeaders []*types.BlockHeader, view *state.UtxoViewpoint, consensusResults []*state.ConsensusResult) error {
187255 if err := c.store.SaveChainStatus(blockHeader, irrBlockHeader, mainBlockHeaders, view, consensusResults); err != nil {
--- a/protocol/txpool.go
+++ b/protocol/txpool.go
@@ -43,6 +43,10 @@ var (
4343 ErrDustTx = errors.New("transaction is dust tx")
4444 )
4545
46+type DustFilterer interface {
47+ IsDust(tx *types.Tx) bool
48+}
49+
4650 type TxMsgEvent struct{ TxMsg *TxPoolMsg }
4751
4852 // TxDesc store tx and related info for mining strategy
@@ -76,11 +80,12 @@ type TxPool struct {
7680 orphans map[bc.Hash]*orphanTx
7781 orphansByPrev map[bc.Hash]map[bc.Hash]*orphanTx
7882 errCache *lru.Cache
83+ filters []DustFilterer
7984 eventDispatcher *event.Dispatcher
8085 }
8186
8287 // NewTxPool init a new TxPool
83-func NewTxPool(store Store, dispatcher *event.Dispatcher) *TxPool {
88+func NewTxPool(store Store, filters []DustFilterer, dispatcher *event.Dispatcher) *TxPool {
8489 tp := &TxPool{
8590 lastUpdated: time.Now().Unix(),
8691 store: store,
@@ -89,6 +94,7 @@ func NewTxPool(store Store, dispatcher *event.Dispatcher) *TxPool {
8994 orphans: make(map[bc.Hash]*orphanTx),
9095 orphansByPrev: make(map[bc.Hash]map[bc.Hash]*orphanTx),
9196 errCache: lru.New(maxCachedErrTxs),
97+ filters: filters,
9298 eventDispatcher: dispatcher,
9399 }
94100 go tp.orphanExpireWorker()
@@ -212,7 +218,16 @@ func isTransactionZeroOutput(tx *types.Tx) bool {
212218
213219 //IsDust checks if a tx has zero output
214220 func (tp *TxPool) IsDust(tx *types.Tx) bool {
215- return isTransactionZeroOutput(tx)
221+ if ok := isTransactionZeroOutput(tx); ok {
222+ return ok
223+ }
224+
225+ for _, filter := range tp.filters {
226+ if ok := filter.IsDust(tx); ok {
227+ return ok
228+ }
229+ }
230+ return false
216231 }
217232
218233 func (tp *TxPool) processTransaction(tx *types.Tx, statusFail bool, height, fee uint64) (bool, error) {
--- a/test/builder_test.go
+++ b/test/builder_test.go
@@ -13,8 +13,6 @@ import (
1313 var (
1414 //chainTxUtxoNum maximum utxo quantity in a tx
1515 chainTxUtxoNum = 5
16- //chainTxMergeGas chain tx gas
17- chainTxMergeGas = uint64(10000000)
1816 )
1917
2018 func TestBuildBtmTxChain(t *testing.T) {
@@ -30,7 +28,7 @@ func TestBuildBtmTxChain(t *testing.T) {
3028 inputUtxo: []uint64{5},
3129 wantInput: [][]uint64{},
3230 wantOutput: [][]uint64{},
33- wantUtxo: 5 * chainTxMergeGas,
31+ wantUtxo: 5,
3432 },
3533 {
3634 inputUtxo: []uint64{5, 4},
@@ -38,9 +36,9 @@ func TestBuildBtmTxChain(t *testing.T) {
3836 []uint64{5, 4},
3937 },
4038 wantOutput: [][]uint64{
41- []uint64{8},
39+ []uint64{9},
4240 },
43- wantUtxo: 8 * chainTxMergeGas,
41+ wantUtxo: 9,
4442 },
4543 {
4644 inputUtxo: []uint64{5, 4, 1, 1},
@@ -49,22 +47,22 @@ func TestBuildBtmTxChain(t *testing.T) {
4947 []uint64{1, 9},
5048 },
5149 wantOutput: [][]uint64{
50+ []uint64{11},
5251 []uint64{10},
53- []uint64{9},
5452 },
55- wantUtxo: 10 * chainTxMergeGas,
53+ wantUtxo: 11,
5654 },
5755 {
5856 inputUtxo: []uint64{22, 123, 53, 234, 23, 4, 2423, 24, 23, 43, 34, 234, 234, 24, 11, 16, 33, 59, 73, 89, 66},
5957 wantInput: [][]uint64{
6058 []uint64{22, 123, 53, 234, 23, 4, 2423, 24, 23, 43, 34, 234, 234, 24, 11, 16, 33, 59, 73, 89},
61- []uint64{66, 3778},
59+ []uint64{66, 3779},
6260 },
6361 wantOutput: [][]uint64{
64- []uint64{3778},
65- []uint64{3843},
62+ []uint64{3779},
63+ []uint64{3845},
6664 },
67- wantUtxo: 3843 * chainTxMergeGas,
65+ wantUtxo: 3845,
6866 },
6967 }
7068
@@ -82,7 +80,7 @@ func TestBuildBtmTxChain(t *testing.T) {
8280 utxos := []*acc.UTXO{}
8381 for _, amount := range c.inputUtxo {
8482 utxos = append(utxos, &acc.UTXO{
85- Amount: amount * chainTxMergeGas,
83+ Amount: amount,
8684 AssetID: *consensus.BTMAssetID,
8785 Address: acp.Address,
8886 ControlProgram: acp.ControlProgram,
@@ -97,12 +95,12 @@ func TestBuildBtmTxChain(t *testing.T) {
9795 for i, tpl := range tpls {
9896 gotInput := []uint64{}
9997 for _, input := range tpl.Transaction.Inputs {
100- gotInput = append(gotInput, input.Amount()/chainTxMergeGas)
98+ gotInput = append(gotInput, input.Amount())
10199 }
102100
103101 gotOutput := []uint64{}
104102 for _, output := range tpl.Transaction.Outputs {
105- gotOutput = append(gotOutput, output.AssetAmount().Amount/chainTxMergeGas)
103+ gotOutput = append(gotOutput, output.AssetAmount().Amount)
106104 }
107105
108106 if !testutil.DeepEqual(c.wantInput[i], gotInput) {
Show on old repository browser