OSDN Git Service

mov merge
authorshenao78 <shenao.78@163.com>
Tue, 29 Oct 2019 08:16:21 +0000 (16:16 +0800)
committershenao78 <shenao.78@163.com>
Tue, 29 Oct 2019 08:16:21 +0000 (16:16 +0800)
node/node.go
proposal/blockproposer/blockproposer.go
protocol/block.go
protocol/mov.go [deleted file]
protocol/protocol.go

index a6ee74e..1407a59 100644 (file)
@@ -17,6 +17,7 @@ import (
        "github.com/vapor/accesstoken"
        "github.com/vapor/account"
        "github.com/vapor/api"
+       "github.com/vapor/application/mov"
        "github.com/vapor/asset"
        "github.com/vapor/blockchain/pseudohsm"
        cfg "github.com/vapor/config"
@@ -83,9 +84,12 @@ func NewNode(config *cfg.Config) *Node {
        }
 
        initCommonConfig(config)
-       movDB := dbm.NewDB("mov", config.DBBackend, config.DBDir())
-       mov, err := protocol.NewMOV(movDB, consensus.ActiveNetParams.MovStartPoint)
-       if err != nil {
+       movCore := mov.NewMovCore(config.DBBackend, config.DBDir())
+       startPoint := consensus.ActiveNetParams.MovStartPoint
+       if startPoint.Height == 0 {
+               startPoint.Hash = cfg.GenesisBlock().Hash()
+       }
+       if err := movCore.InitChainStatus(startPoint.Height, &startPoint.Hash); err != nil {
                log.Fatalf("Failed to create Mov protocol", err.Error())
        }
        // Get store
@@ -99,8 +103,8 @@ func NewNode(config *cfg.Config) *Node {
        accessTokens := accesstoken.NewStore(tokenDB)
 
        dispatcher := event.NewDispatcher()
-       txPool := protocol.NewTxPool(store, []protocol.DustFilterer{mov}, dispatcher)
-       chain, err := protocol.NewChain(store, txPool, []protocol.Protocoler{mov}, dispatcher)
+       txPool := protocol.NewTxPool(store, []protocol.DustFilterer{movCore}, dispatcher)
+       chain, err := protocol.NewChain(store, txPool, []protocol.Protocoler{movCore}, dispatcher)
        if err != nil {
                cmn.Exit(cmn.Fmt("Failed to create chain structure: %v", err))
        }
@@ -166,7 +170,7 @@ func NewNode(config *cfg.Config) *Node {
                notificationMgr: notificationMgr,
        }
 
-       node.cpuMiner = blockproposer.NewBlockProposer(chain, accounts, txPool, []blockproposer.Preprocessor{mov}, dispatcher)
+       node.cpuMiner = blockproposer.NewBlockProposer(chain, accounts, txPool, []blockproposer.Preprocessor{movCore}, dispatcher)
        node.BaseService = *cmn.NewBaseService(nil, "Node", node)
        return node
 }
index b3d6983..2b3edc2 100644 (file)
@@ -23,7 +23,7 @@ const (
 )
 
 type Preprocessor interface {
-       BeforeProposalBlock(capacity int) ([]*types.Tx, error)
+       BeforeProposalBlock(capacity int, nodeProgram []byte) ([]*types.Tx, error)
 }
 
 // BlockProposer propose several block in specified time range
@@ -94,7 +94,7 @@ func (b *BlockProposer) generateBlocks() {
                                break
                        }
 
-                       txs, err := p.BeforeProposalBlock(capacity)
+                       txs, err := p.BeforeProposalBlock(capacity, []byte{0x51})
                        if err != nil {
                                log.WithFields(log.Fields{"module": logModule, "index": i, "error": err}).Error("failed on sub protocol txs package")
                                continue
index 05eb702..eb19ef3 100644 (file)
@@ -299,7 +299,7 @@ func (c *Chain) saveBlock(block *types.Block) error {
        }
 
        for _, p := range c.subProtocols {
-               if err := p.ValidateBlock(block); err != nil {
+               if err := p.ValidateBlock(block, bcBlock.TransactionStatus.GetVerifyStatus()); err != nil {
                        return errors.Wrap(err, "sub protocol save block")
                }
        }
diff --git a/protocol/mov.go b/protocol/mov.go
deleted file mode 100644 (file)
index af09b61..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-package protocol
-
-import (
-       "github.com/vapor/application/mov"
-       "github.com/vapor/config"
-       "github.com/vapor/consensus"
-       dbm "github.com/vapor/database/leveldb"
-       "github.com/vapor/errors"
-       "github.com/vapor/protocol/bc"
-       "github.com/vapor/protocol/bc/types"
-)
-
-const (
-       protocolName = "MOV"
-)
-
-type movCore interface {
-       ApplyBlock(block *types.Block) error
-       BeforeProposalBlock(capacity int) ([]*types.Tx, error)
-       ChainStatus() (uint64, *bc.Hash, error)
-       DetachBlock(block *types.Block) error
-       IsDust(tx *types.Tx) bool
-       ValidateBlock(block *types.Block) error
-       ValidateTxs(txs []*types.Tx) error
-}
-
-type MOV struct {
-       core movCore
-}
-
-func NewMOV(db dbm.DB, startPoint consensus.Checkpoint) (*MOV, error) {
-       if startPoint.Height == 0 {
-               startPoint.Hash = config.GenesisBlock().Hash()
-       }
-
-       movCore, err := mov.NewMovCore(db, startPoint.Height, &startPoint.Hash)
-       if err != nil {
-               return nil, errors.Wrap(err, "failed on create mov core")
-       }
-
-       return &MOV{
-               core: movCore,
-       }, nil
-}
-
-func (m MOV) ApplyBlock(block *types.Block) error {
-       return m.core.ApplyBlock(block)
-}
-
-func (m MOV) BeforeProposalBlock(capacity int) ([]*types.Tx, error) {
-       return m.core.BeforeProposalBlock(capacity)
-}
-
-func (m MOV) ChainStatus() (uint64, *bc.Hash, error) {
-       return m.core.ChainStatus()
-}
-
-func (m MOV) DetachBlock(block *types.Block) error {
-       return m.core.DetachBlock(block)
-}
-
-func (m MOV) IsDust(tx *types.Tx) bool {
-       return m.core.IsDust(tx)
-}
-
-func (m MOV) Name() string {
-       return protocolName
-}
-
-func (m MOV) ValidateBlock(block *types.Block) error {
-       return m.core.ValidateBlock(block)
-}
-
-func (m MOV) ValidateTxs(txs []*types.Tx) error {
-       return m.core.ValidateTxs(txs)
-}
index fa75c3b..2730358 100644 (file)
@@ -22,8 +22,8 @@ const (
 type Protocoler interface {
        Name() string
        ChainStatus() (uint64, *bc.Hash, error)
-       ValidateBlock(block *types.Block) error
-       ValidateTxs(txs []*types.Tx) error
+       ValidateBlock(block *types.Block, verifyResults []*bc.TxVerifyResult) error
+       ValidateTxs(txs []*types.Tx, verifyResults []*bc.TxVerifyResult) error
        ApplyBlock(block *types.Block) error
        DetachBlock(block *types.Block) error
 }