refactors

geth Node api change

sd ctor refactor
This commit is contained in:
Roy Crihfield 2020-11-16 17:49:59 +08:00
parent ca8b3066d1
commit abff9bf045
3 changed files with 14 additions and 9 deletions

View File

@ -71,7 +71,7 @@ func serve() {
// create statediff service
logWithCommand.Info("creating statediff service")
db, err := postgres.NewDB(GetDBParams(), GetDBConfig(), nodeInfo)
db, err := postgres.NewDB(postgres.DbConnectionString(GetDBParams()), GetDBConfig(), nodeInfo)
if err != nil {
logWithCommand.Fatal(err)
}
@ -127,9 +127,11 @@ func startServers(serv sd.IService) error {
}
if httpPath != "" {
logWithCommand.Info("starting up HTTP server")
if _, _, err := rpc.StartHTTPEndpoint(httpPath, serv.APIs(), []string{sd.APIName}, nil, nil, rpc.HTTPTimeouts{}); err != nil {
return err
}
// XXX broken https://github.com/ethereum/go-ethereum/pull/21105
// if _, _, err := node.StartHTTPEndpoint(httpPath, rpc.HTTPTimeouts{}, handler); err != nil {
// return err
// }
// or node.RegisterHandler ?
}
return nil
}
@ -139,7 +141,7 @@ func chainConfig(chainID uint64) (*params.ChainConfig, error) {
case 1:
return params.MainnetChainConfig, nil
case 3:
return params.TestnetChainConfig, nil // Ropsten
return params.RopstenChainConfig, nil // Ropsten
case 4:
return params.RinkebyChainConfig, nil
case 5:

View File

@ -68,7 +68,7 @@ func write() {
// create statediff service
logWithCommand.Info("creating statediff service")
db, err := postgres.NewDB(GetDBParams(), GetDBConfig(), nodeInfo)
db, err := postgres.NewDB(postgres.DbConnectionString(GetDBParams()), GetDBConfig(), nodeInfo)
if err != nil {
logWithCommand.Fatal(err)
}

View File

@ -45,8 +45,11 @@ type lvlDBReader interface {
// IService is the state-diffing service interface
type IService interface {
// APIs(), Protocols(), Start() and Stop()
node.Service
// Start() and Stop()
node.Lifecycle
// For node service registration
APIs() []rpc.API
Protocols() []p2p.Protocol
// Main event loop for processing state diffs
Loop(wg *sync.WaitGroup)
// Method to get state diff object at specific block
@ -207,7 +210,7 @@ func (sds *Service) processStateTrie(block *types.Block, params sd.Params) (*sd.
}
// Start is used to begin the service
func (sds *Service) Start(*p2p.Server) error {
func (sds *Service) Start() error {
logrus.Info("starting statediff service")
go sds.Loop(new(sync.WaitGroup))
return nil