OSDN Git Service

MOV add startpoint subprotocol
authorYahtoo Ma <yahtoo.ma@gmail.com>
Tue, 22 Oct 2019 03:03:11 +0000 (11:03 +0800)
committerYahtoo Ma <yahtoo.ma@gmail.com>
Tue, 22 Oct 2019 03:26:47 +0000 (11:26 +0800)
consensus/general.go
node/node.go
protocol/mov.go

index b34f19d..279b4ad 100644 (file)
@@ -103,6 +103,7 @@ type Params struct {
        ProducerSubsidys []ProducerSubsidy
 
        SoftForkPoint map[uint64]uint64
+       MovStartPoint Checkpoint
 }
 
 // ActiveNetParams is the active NetParams
index b305e37..a6ee74e 100644 (file)
@@ -83,8 +83,11 @@ func NewNode(config *cfg.Config) *Node {
        }
 
        initCommonConfig(config)
-
-       mov := protocol.NewMOV()
+       movDB := dbm.NewDB("mov", config.DBBackend, config.DBDir())
+       mov, err := protocol.NewMOV(movDB, consensus.ActiveNetParams.MovStartPoint)
+       if err != nil {
+               log.Fatalf("Failed to create Mov protocol", err.Error())
+       }
        // Get store
        if config.DBBackend != "memdb" && config.DBBackend != "leveldb" {
                cmn.Exit(cmn.Fmt("Param db_backend [%v] is invalid, use leveldb or memdb", config.DBBackend))
index 03d02f8..af09b61 100644 (file)
@@ -1,6 +1,11 @@
 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"
 )
@@ -9,7 +14,7 @@ const (
        protocolName = "MOV"
 )
 
-type matchEnginer interface {
+type movCore interface {
        ApplyBlock(block *types.Block) error
        BeforeProposalBlock(capacity int) ([]*types.Tx, error)
        ChainStatus() (uint64, *bc.Hash, error)
@@ -20,31 +25,42 @@ type matchEnginer interface {
 }
 
 type MOV struct {
-       engine matchEnginer
+       core movCore
 }
 
-func NewMOV() *MOV {
-       return &MOV{}
+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.engine.ApplyBlock(block)
+       return m.core.ApplyBlock(block)
 }
 
 func (m MOV) BeforeProposalBlock(capacity int) ([]*types.Tx, error) {
-       return m.engine.BeforeProposalBlock(capacity)
+       return m.core.BeforeProposalBlock(capacity)
 }
 
 func (m MOV) ChainStatus() (uint64, *bc.Hash, error) {
-       return m.engine.ChainStatus()
+       return m.core.ChainStatus()
 }
 
 func (m MOV) DetachBlock(block *types.Block) error {
-       return m.engine.DetachBlock(block)
+       return m.core.DetachBlock(block)
 }
 
 func (m MOV) IsDust(tx *types.Tx) bool {
-       return m.engine.IsDust(tx)
+       return m.core.IsDust(tx)
 }
 
 func (m MOV) Name() string {
@@ -52,9 +68,9 @@ func (m MOV) Name() string {
 }
 
 func (m MOV) ValidateBlock(block *types.Block) error {
-       return m.engine.ValidateBlock(block)
+       return m.core.ValidateBlock(block)
 }
 
 func (m MOV) ValidateTxs(txs []*types.Tx) error {
-       return m.engine.ValidateTxs(txs)
+       return m.core.ValidateTxs(txs)
 }