"github.com/bytom/blockchain/accesstoken"
"github.com/bytom/blockchain/account"
"github.com/bytom/blockchain/asset"
+ "github.com/bytom/blockchain/pseudohsm"
"github.com/bytom/blockchain/txdb"
"github.com/bytom/blockchain/txfeed"
- "github.com/bytom/blockchain/pseudohsm"
"github.com/bytom/encoding/json"
"github.com/bytom/log"
"github.com/bytom/mining/cpuminer"
"github.com/bytom/p2p"
"github.com/bytom/protocol"
"github.com/bytom/protocol/bc/legacy"
- "github.com/bytom/protocol/validation"
"github.com/bytom/types"
wire "github.com/tendermint/go-wire"
cmn "github.com/tendermint/tmlibs/common"
crosscoreRPCPrefix = "/rpc/"
)
-
// BlockchainReactor handles long-term catchup syncing.
type BlockchainReactor struct {
p2p.BaseReactor
- chain *protocol.Chain
- store *txdb.Store
- accounts *account.Manager
- assets *asset.Registry
+ chain *protocol.Chain
+ store *txdb.Store
+ accounts *account.Manager
+ assets *asset.Registry
accesstoken *accesstoken.Token
- txFeeds *txfeed.TxFeed
- pool *BlockPool
- txPool *protocol.TxPool
- hsm *pseudohsm.HSM
- mining *cpuminer.CPUMiner
- mux *http.ServeMux
- handler http.Handler
- fastSync bool
- requestsCh chan BlockRequest
- timeoutsCh chan string
- submitter txbuilder.Submitter
+ txFeeds *txfeed.TxFeed
+ pool *BlockPool
+ txPool *protocol.TxPool
+ hsm *pseudohsm.HSM
+ mining *cpuminer.CPUMiner
+ mux *http.ServeMux
+ handler http.Handler
+ fastSync bool
+ requestsCh chan BlockRequest
+ timeoutsCh chan string
+ submitter txbuilder.Submitter
evsw types.EventSwitch
}
}
}
-
-
func jsonHandler(f interface{}) http.Handler {
h, err := httpjson.Handler(f, errorFormatter.Write)
if err != nil {
return jsonHandler(func() error { return err })
}
-
func (bcr *BlockchainReactor) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
bcr.handler.ServeHTTP(rw, req)
}
//m.Handle("/hsm/reset-password", jsonHandler(bcr.pseudohsmResetPassword))
//m.Handle("/hsm/update-alias", jsonHandler(bcr.pseudohsmUpdateAlias))
-
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, assets *asset.Registry, hsm *pseudohsm.HSM, fastSync bool) *BlockchainReactor {
requestsCh := make(chan BlockRequest, defaultChannelCapacity)
timeoutsCh := make(chan string, defaultChannelCapacity)
pool := NewBlockPool(
- store.Height()+1,
- requestsCh,
- timeoutsCh,
+ store.Height()+1,
+ requestsCh,
+ timeoutsCh,
)
mining := cpuminer.NewCPUMiner(chain, txPool)
bcR := &BlockchainReactor{
txPool: txPool,
mining: mining,
mux: http.NewServeMux(),
- hsm: hsm,
+ hsm: hsm,
fastSync: fastSync,
requestsCh: requestsCh,
timeoutsCh: timeoutsCh,
return bcR
}
-
// OnStart implements BaseService
func (bcR *BlockchainReactor) OnStart() error {
bcR.BaseReactor.OnStart()
//fmt.Printf("reveive peer high is %d \n", msg.Height)
bcR.pool.SetPeerHeight(src.Key, msg.Height)
case *bcTransactionMessage:
- block, _ := bcR.chain.State()
tx := msg.GetTransaction()
- if bcR.txPool.HaveTransaction(&tx.Tx.ID) {
- return
- }
- gas, err := validation.ValidateTx(tx.Tx, legacy.MapBlock(block))
- if err != nil {
+ if err := bcR.chain.ValidateTx(tx); err != nil {
return
}
- bcR.txPool.AddTransaction(tx, block.BlockHeader.Height, gas)
+
go bcR.BroadcastTransaction(tx)
default:
bcR.Logger.Error(cmn.Fmt("Unknown message type %v", reflect.TypeOf(msg)))