OSDN Git Service

Added blockchain.
authorgguoss <1536310027@qq.com>
Wed, 9 Aug 2017 08:41:49 +0000 (16:41 +0800)
committergguoss <1536310027@qq.com>
Wed, 9 Aug 2017 08:41:49 +0000 (16:41 +0800)
blockchain/reactor.go
node/node.go

index 6cd64e2..45ffb53 100644 (file)
@@ -10,6 +10,7 @@ import (
        "github.com/blockchain/p2p"
        "github.com/blockchain/types"
     "github.com/blockchain/protocol/bc/legacy"
+    "github.com/blockchain/protocol"
        cmn "github.com/tendermint/tmlibs/common"
 )
 
@@ -46,6 +47,7 @@ type BlockchainReactor struct {
 //     state        *sm.State
 //     proxyAppConn proxy.AppConnConsensus // same as consensus.proxyAppConn
 //     store        *MemStore
+    chain        *protocol.Chain
        store        *BlockStore
        pool         *BlockPool
        fastSync     bool
@@ -56,7 +58,7 @@ type BlockchainReactor struct {
        evsw types.EventSwitch
 }
 
-func NewBlockchainReactor(store *BlockStore, fastSync bool) *BlockchainReactor {
+func NewBlockchainReactor(store *BlockStore, chain *protocol.Chain,fastSync bool) *BlockchainReactor {
     requestsCh    := make(chan BlockRequest, defaultChannelCapacity)
     timeoutsCh    := make(chan string, defaultChannelCapacity)
     pool := NewBlockPool(
@@ -65,6 +67,7 @@ func NewBlockchainReactor(store *BlockStore, fastSync bool) *BlockchainReactor {
         timeoutsCh,
     )
     bcR := &BlockchainReactor {
+        chain:         chain,
         fastSync:      fastSync,
         pool:          pool,
         store:         store,
index 0695a20..1255cd3 100644 (file)
@@ -21,6 +21,7 @@ import (
        //rpc "github.com/blockchain/rpc/lib"
        rpcserver "github.com/blockchain/rpc/lib/server"
     "github.com/blockchain/blockchain/account"
+    "github.com/blockchain/protocol"
 
        _ "net/http/pprof"
 )
@@ -83,7 +84,24 @@ func NewNode(config *cfg.Config, privValidator *types.PrivValidator, logger log.
        sw.SetLogger(p2pLogger)
 
     fastSync := config.FastSync
-    bcReactor := bc.NewBlockchainReactor(blockStore, fastSync)
+    genesisblock, err := protocol.NewInitialBlock()
+    if err != nil {
+      cmn.Exit(cmn.Fmt("initialize genesisblock failed: %v", err))
+    }
+
+    txdb := dbm.NewDB("txdb", config.DBBackend, config.DBDir())
+    store := txdb.NewStore(txdb)
+    chain, err := protocol.NewChain(ctx, genesisblock.Hash(), store, nil)
+    if err != nil {
+      cmn.Exit(cmn.Fmt("protocol new chain failed: %v", err)
+    }
+    err = chain.CommitAppliedBlock(ctx, block, state.Empty())
+    if err != nil {
+      cmn.Exit(cmn.Fmt("commit block failed: %v", err))
+    }
+    chain.MaxIssuanceWindow = bc.MillisDuration(c.MaxIssuanceWindowMs)
+
+    bcReactor := bc.NewBlockchainReactor(blockStore, chain, fastSync)
     bcReactor.SetLogger(logger.With("module", "blockchain"))
     sw.AddReactor("BLOCKCHAIN", bcReactor)