aboutsummaryrefslogtreecommitdiffstats
path: root/dex/backend.go
diff options
context:
space:
mode:
authorSonic <sonic@cobinhood.com>2018-10-12 15:02:33 +0800
committerWei-Ning Huang <w@dexon.org>2019-03-12 12:19:09 +0800
commit961231f91fc4c7edc122ccdf337d804a885b1f6b (patch)
tree4de8ac71927a013dedb65a7be91770c1a3fc97bb /dex/backend.go
parentf4936aa1eb7fa01f56c28f081af266c2a4924a61 (diff)
downloaddexon-961231f91fc4c7edc122ccdf337d804a885b1f6b.tar.gz
dexon-961231f91fc4c7edc122ccdf337d804a885b1f6b.tar.zst
dexon-961231f91fc4c7edc122ccdf337d804a885b1f6b.zip
dex: network: implement the network interface
Diffstat (limited to 'dex/backend.go')
-rw-r--r--dex/backend.go35
1 files changed, 30 insertions, 5 deletions
diff --git a/dex/backend.go b/dex/backend.go
index d01ab8040..caac0fe21 100644
--- a/dex/backend.go
+++ b/dex/backend.go
@@ -85,7 +85,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) {
if err != nil {
panic(err)
}
- network := NewDexconNetwork()
chainDb, err := CreateDB(ctx, config, "chaindata")
if err != nil {
@@ -116,7 +115,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) {
networkID: config.NetworkId,
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
- network: network,
blockdb: db,
engine: dexcon.New(&params.DexconConfig{}),
}
@@ -154,9 +152,18 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) {
dex.governance = NewDexconGovernance(dex.APIBackend, dex.chainConfig, config.PrivateKey)
dex.app = NewDexconApp(dex.txPool, dex.blockchain, dex.governance, chainDb, config, vmConfig)
- privKey := coreEcdsa.NewPrivateKeyFromECDSA(config.PrivateKey)
- dex.consensus = dexCore.NewConsensus(dex.app, dex.governance, db, network, privKey)
+ pm, err := NewProtocolManager(dex.chainConfig, config.SyncMode,
+ config.NetworkId, dex.eventMux, dex.txPool, dex.engine, dex.blockchain,
+ chainDb, dex.governance)
+ if err != nil {
+ return nil, err
+ }
+
+ dex.protocolManager = pm
+ dex.network = NewDexconNetwork(pm)
+ privKey := coreEcdsa.NewPrivateKeyFromECDSA(config.PrivateKey)
+ dex.consensus = dexCore.NewConsensus(dex.app, dex.governance, db, dex.network, privKey)
return dex, nil
}
@@ -168,7 +175,24 @@ func (s *Dexon) APIs() []rpc.API {
return nil
}
-func (s *Dexon) Start(server *p2p.Server) error {
+func (s *Dexon) Start(srvr *p2p.Server) error {
+ // Start the bloom bits servicing goroutines
+ s.startBloomHandlers(params.BloomBitsBlocks)
+
+ // Start the RPC service
+ s.netRPCService = ethapi.NewPublicNetAPI(srvr, s.NetVersion())
+
+ // Figure out a max peers count based on the server limits
+ maxPeers := srvr.MaxPeers
+ if s.config.LightServ > 0 {
+ if s.config.LightPeers >= srvr.MaxPeers {
+ return fmt.Errorf("invalid peer config: light peer count (%d) >= total peer count (%d)", s.config.LightPeers, srvr.MaxPeers)
+ }
+ maxPeers -= s.config.LightPeers
+ }
+ // Start the networking layer and the light server if requested
+ s.protocolManager.Start(srvr, maxPeers)
+
return nil
}
@@ -196,3 +220,4 @@ func (d *Dexon) EventMux() *event.TypeMux { return d.eventMux }
func (d *Dexon) Engine() consensus.Engine { return d.engine }
func (d *Dexon) ChainDb() ethdb.Database { return d.chainDb }
func (d *Dexon) Downloader() *downloader.Downloader { return d.protocolManager.downloader }
+func (d *Dexon) NetVersion() uint64 { return d.networkID }