Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): add command line support for RPC-related parameters #2189

Open
wants to merge 2 commits into
base: feature_bpos
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func GetDefaultParams() *Configuration {
HttpRestPort: 20334,
HttpWsPort: 20335,
HttpJsonPort: 20336,
EnableRPC: true,
PowConfiguration: PowConfiguration{
PowLimit: powLimit,
PowLimitBits: 0x1f0008ff,
Expand Down Expand Up @@ -821,9 +822,9 @@ type PowConfiguration struct {

// RpcConfiguration defines the JSON-RPC authenticate parameters.
type RpcConfiguration struct {
User string `json:"User"`
Pass string `json:"Pass"`
WhiteIPList []string `json:"WhiteIPList"`
User string `screw:"--rpcuser" usage:"username for JSON-RPC connections"`
Pass string `screw:"--rpcpassword" usage:"password for JSON-RPC connections"`
WhiteIPList []string `screw:"--rpcips" usage:"white IP list allowed to access RPC server"`
}

// InstantBlock returns the network parameters for generate instant block.
Expand Down
7 changes: 7 additions & 0 deletions common/config/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ func (s *Settings) SetupConfig(withScrew bool, about string, version string) *co
}
conf.Configuration = conf.Sterilize()
config.Parameters = conf.Configuration

if len(conf.RpcConfiguration.WhiteIPList) > 1 {
ips := strings.Split(conf.RpcConfiguration.WhiteIPList[0], ",")
for i, ip := range ips {
conf.RpcConfiguration.WhiteIPList[i] = ip
}
}
return conf.Configuration
}

Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ func startNode(cfg *config.Configuration) {

log.Info("Start services")
if cfg.EnableRPC {
log.Info("Start rpc server, user:", chain.GetParams().RpcConfiguration.User,
"whit ip list:", chain.GetParams().RpcConfiguration.WhiteIPList)
go httpjsonrpc.StartRPCServer()
}
if cfg.HttpRestStart {
Expand Down
9 changes: 9 additions & 0 deletions pow/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ func (pow *Service) DiscreteMining(n uint32) ([]*common.Uint256, error) {
Block: msgBlock,
})
if err != nil {
pow.mutex.Lock()
pow.started = false
pow.discreteMining = false
pow.mutex.Unlock()
return blockHashes, nil
}

Expand All @@ -455,6 +459,11 @@ func (pow *Service) DiscreteMining(n uint32) ([]*common.Uint256, error) {
}
}
}

pow.mutex.Lock()
pow.started = false
pow.discreteMining = false
pow.mutex.Unlock()
return blockHashes, nil
}
}
Expand Down