// check if we should switch to consensus reactor
switchToConsensusIntervalSeconds = 1
maxBlockchainResponseSize = 22020096 + 2
- crosscoreRPCPrefix = "/rpc/"
+ crosscoreRPCPrefix = "/rpc/"
)
- /*
- type consensusReactor interface {
- // for when we switch from blockchain reactor and fast sync to
- // the consensus machine
- SwitchToConsensus(*sm.State)
- }
- */
-
// BlockchainReactor handles long-term catchup syncing.
type BlockchainReactor struct {
p2p.BaseReactor
- // state *sm.State
- // proxyAppConn proxy.AppConnConsensus // same as consensus.proxyAppConn
- // store *MemStore
- chain *protocol.Chain
- store *txdb.Store
- accounts *account.Manager
- assets *asset.Registry
- txFeeds *txfeed.TxFeed
- indexer *query.Indexer
- pool *BlockPool
- mux *http.ServeMux
- handler http.Handler
- fastSync bool
- requestsCh chan BlockRequest
- timeoutsCh chan string
- submitter txbuilder.Submitter
+ chain *protocol.Chain
+ store *txdb.Store
+ accounts *account.Manager
+ assets *asset.Registry
+ txFeeds *txfeed.TxFeed
+ pool *BlockPool
+ txPool *protocol.TxPool
+ mining *cpuminer.CPUMiner
+ mux *http.ServeMux
+ handler http.Handler
+ fastSync bool
+ requestsCh chan BlockRequest
+ timeoutsCh chan string
+ submitter txbuilder.Submitter
- // lastBlock *types.Block
evsw types.EventSwitch
}
m.Handle("/get-transaction-feed", jsonHandler(bcr.getTxFeed))
m.Handle("/update-transaction-feed", jsonHandler(bcr.updateTxFeed))
m.Handle("/delete-transaction-feed", jsonHandler(bcr.deleteTxFeed))
- m.Handle("/list-assets", jsonHandler(bcr.listAssets))
- m.Handle("/list-transaction-feeds", jsonHandler(bcr.listTxFeeds))
- m.Handle("/list-transactions", jsonHandler(bcr.listTransactions))
- m.Handle("/list-balances", jsonHandler(bcr.listBalances))
- m.Handle("/list-unspent-outputs", jsonHandler(bcr.listUnspentOutputs))
+ m.Handle("/list-accounts", jsonHandler(bcr.listAccounts))
++ m.Handle("/list-assets", jsonHandler(bcr.listAssets))
++ m.Handle("/list-transaction-feeds", jsonHandler(bcr.listTxFeeds))
++ m.Handle("/list-transactions", jsonHandler(bcr.listTransactions))
++ m.Handle("/list-balances", jsonHandler(bcr.listBalances))
++ m.Handle("/list-unspent-outputs", jsonHandler(bcr.listUnspentOutputs))
m.Handle("/", alwaysError(errors.New("not Found")))
m.Handle("/info", jsonHandler(bcr.info))
m.Handle("/create-block-key", jsonHandler(bcr.createblockkey))
+ m.Handle("/submit-transaction", jsonHandler(bcr.submit))
- latencyHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+ latencyHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if l := latency(m, req); l != nil {
defer l.RecordSince(time.Now())
}
LastPage bool `json:"last_page"`
}
- func NewBlockchainReactor(store *txdb.Store, chain *protocol.Chain, txPool *protocol.TxPool, accounts *account.Manager, fastSync bool) *BlockchainReactor {
-func NewBlockchainReactor(store *txdb.Store, chain *protocol.Chain, accounts *account.Manager, assets *asset.Registry, fastSync bool) *BlockchainReactor {
- requestsCh := make(chan BlockRequest, defaultChannelCapacity)
- timeoutsCh := make(chan string, defaultChannelCapacity)
- pool := NewBlockPool(
- store.Height()+1,
- requestsCh,
- timeoutsCh,
- )
- bcR := &BlockchainReactor {
- chain: chain,
- store: store,
- accounts: accounts,
- assets: assets,
- pool: pool,
- mux: http.NewServeMux(),
- fastSync: fastSync,
- requestsCh: requestsCh,
- timeoutsCh: timeoutsCh,
- }
- bcR.BaseReactor = *p2p.NewBaseReactor("BlockchainReactor", bcR)
- return bcR
++func NewBlockchainReactor(store *txdb.Store, chain *protocol.Chain, txPool *protocol.TxPool, accounts *account.Manager, assets *asset.Registry, fastSync bool) *BlockchainReactor {
+ requestsCh := make(chan BlockRequest, defaultChannelCapacity)
+ timeoutsCh := make(chan string, defaultChannelCapacity)
+ pool := NewBlockPool(
+ store.Height()+1,
+ requestsCh,
+ timeoutsCh,
+ )
+ mining := cpuminer.NewCPUMiner(chain, txPool)
+ bcR := &BlockchainReactor{
+ chain: chain,
+ store: store,
+ accounts: accounts,
++ assets: assets,
+ pool: pool,
+ txPool: txPool,
+ mining: mining,
+ mux: http.NewServeMux(),
+ fastSync: fastSync,
+ requestsCh: requestsCh,
+ timeoutsCh: timeoutsCh,
+ }
+ bcR.BaseReactor = *p2p.NewBaseReactor("BlockchainReactor", bcR)
+ return bcR
}
// OnStart implements BaseService
"github.com/tendermint/tmlibs/log"
//rpc "github.com/blockchain/rpc/lib"
"github.com/bytom/blockchain/account"
++ "github.com/bytom/blockchain/asset"
"github.com/bytom/blockchain/txdb"
"github.com/bytom/net/http/reqid"
"github.com/bytom/protocol"
accounts_db := dbm.NewDB("account", config.DBBackend, config.DBDir())
accounts := account.NewManager(accounts_db, chain)
- bcReactor := bc.NewBlockchainReactor(store, chain, txPool, accounts, fastSync)
+ assets_db := dbm.NewDB("asset", config.DBBackend, config.DBDir())
+ assets := asset.NewRegistry(assets_db, chain)
- bcReactor := bc.NewBlockchainReactor(store, chain, accounts, assets, fastSync)
++ bcReactor := bc.NewBlockchainReactor(store, chain, txPool, accounts, assets, fastSync)
++
bcReactor.SetLogger(logger.With("module", "blockchain"))
sw.AddReactor("BLOCKCHAIN", bcReactor)