OSDN Git Service

Peer add announces new block message num limit
[bytom/vapor.git] / test / bench_blockchain_test.go
index 207696d..092811d 100644 (file)
@@ -11,14 +11,14 @@ import (
        "github.com/vapor/blockchain/pseudohsm"
        "github.com/vapor/blockchain/signers"
        "github.com/vapor/blockchain/txbuilder"
+       "github.com/vapor/config"
        "github.com/vapor/consensus"
-       "github.com/vapor/consensus/difficulty"
        "github.com/vapor/crypto/ed25519/chainkd"
        "github.com/vapor/database"
        dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/database/storage"
        "github.com/vapor/event"
-       "github.com/vapor/mining"
+       "github.com/vapor/proposal"
        "github.com/vapor/protocol"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -127,7 +127,7 @@ func GenerateChainData(dirPath string, testDB dbm.DB, txNumber, otherAssetNum in
 
        // init UtxoViewpoint
        utxoView := state.NewUtxoViewpoint()
-       utxoEntry := storage.NewUtxoEntry(false, 1, false)
+       utxoEntry := storage.NewUtxoEntry(storage.NormalUTXOType, 1, false)
        for _, tx := range txs {
                for _, id := range tx.SpentOutputIDs {
                        utxoView.Entries[id] = utxoEntry
@@ -138,10 +138,11 @@ func GenerateChainData(dirPath string, testDB dbm.DB, txNumber, otherAssetNum in
                return nil, nil, nil, err
        }
 
+       config.CommonConfig = config.DefaultConfig()
        store := database.NewStore(testDB)
        dispatcher := event.NewDispatcher()
        txPool := protocol.NewTxPool(store, dispatcher)
-       chain, err := protocol.NewChain(store, txPool)
+       chain, err := protocol.NewChain(store, txPool, dispatcher)
        if err != nil {
                return nil, nil, nil, err
        }
@@ -158,7 +159,7 @@ func InsertChain(chain *protocol.Chain, txPool *protocol.TxPool, txs []*types.Tx
                }
        }
 
-       block, err := mining.NewBlockTemplate(chain, txPool, nil)
+       block, err := proposal.NewBlockTemplate(chain, txPool, nil, uint64(time.Now().UnixNano()/1e6))
        if err != nil {
                return err
        }
@@ -175,15 +176,6 @@ func InsertChain(chain *protocol.Chain, txPool *protocol.TxPool, txs []*types.Tx
                fmt.Println("txsize:", uint64(block.Transactions[1].SerializedSize))
        }
 
-       seed, err := chain.CalcNextSeed(&block.PreviousBlockHash)
-       if err != nil {
-               return err
-       }
-
-       if err := SolveBlock(seed, block); err != nil {
-               return err
-       }
-
        if _, err := chain.ProcessBlock(block); err != nil {
                return err
        }
@@ -194,19 +186,6 @@ func InsertChain(chain *protocol.Chain, txPool *protocol.TxPool, txs []*types.Tx
 func processNewTxch(txPool *protocol.TxPool) {
 }
 
-func SolveBlock(seed *bc.Hash, block *types.Block) error {
-       maxNonce := ^uint64(0) // 2^64 - 1
-       header := &block.BlockHeader
-       for i := uint64(0); i < maxNonce; i++ {
-               header.Nonce = i
-               headerHash := header.Hash()
-               if difficulty.CheckProofOfWork(&headerHash, seed, header.Bits) {
-                       return nil
-               }
-       }
-       return nil
-}
-
 func MockSimpleUtxo(index uint64, assetID *bc.AssetID, amount uint64, ctrlProg *account.CtrlProgram) *account.UTXO {
        if ctrlProg == nil {
                ctrlProg = &account.CtrlProgram{
@@ -272,7 +251,7 @@ func AddTxInputFromUtxo(utxo *account.UTXO, singer *signers.Signer) (*types.TxIn
 }
 
 func AddTxOutput(assetID bc.AssetID, amount uint64, controlProgram []byte) *types.TxOutput {
-       out := types.NewTxOutput(assetID, amount, controlProgram)
+       out := types.NewIntraChainOutput(assetID, amount, controlProgram)
        return out
 }
 
@@ -389,7 +368,8 @@ func SetUtxoView(db dbm.DB, view *state.UtxoViewpoint) error {
 
 //-------------------------Mock actual transaction----------------------------------
 func MockTxsP2PKH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
-       accountManager := account.NewManager(testDB, nil)
+       accountStore := database.NewAccountStore(testDB)
+       accountManager := account.NewManager(accountStore, nil)
        hsm, err := pseudohsm.New(keyDirPath)
        if err != nil {
                return nil, err
@@ -431,7 +411,8 @@ func MockTxsP2PKH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int)
 }
 
 func MockTxsP2SH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
-       accountManager := account.NewManager(testDB, nil)
+       accountStore := database.NewAccountStore(testDB)
+       accountManager := account.NewManager(accountStore, nil)
        hsm, err := pseudohsm.New(keyDirPath)
        if err != nil {
                return nil, err
@@ -478,7 +459,8 @@ func MockTxsP2SH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int)
 }
 
 func MockTxsMultiSign(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
-       accountManager := account.NewManager(testDB, nil)
+       accountStore := database.NewAccountStore(testDB)
+       accountManager := account.NewManager(accountStore, nil)
        hsm, err := pseudohsm.New(keyDirPath)
        if err != nil {
                return nil, err