Skip to content

Commit

Permalink
Merge PR :fix rpc monitor error (#892)
Browse files Browse the repository at this point in the history
* fix rpc monitor error

* fix rpc monitor elapse time

Co-authored-by: KamiD <[email protected]>
  • Loading branch information
ilovers and KamiD authored Jun 1, 2021
1 parent 4b67a15 commit b87806e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/rpc/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ func (m *Monitor) OnBegin(metrics map[string]metrics.Counter) {

func (m *Monitor) OnEnd(args ...interface{}) {
now := time.Now().UnixNano()
m.logger.Debug(fmt.Sprintf("RPC: Method<%s>, Interval<%dms>, Params<%v>", m.method, (now-m.lastTimestamp)/1000, args))
unit := int64(1e6)
m.logger.Debug(fmt.Sprintf("RPC: Method<%s>, Interval<%dms>, Params<%v>", m.method, (now-m.lastTimestamp)/unit, args))
}
6 changes: 5 additions & 1 deletion app/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ func (api *PublicEthereumAPI) Accounts() ([]common.Address, error) {
monitor := monitor.GetMonitor("eth_accounts", api.logger)
monitor.OnBegin(api.Metrics)
defer monitor.OnEnd()
return api.accounts()
}

func (api *PublicEthereumAPI) accounts() ([]common.Address, error) {
api.keyringLock.Lock()
defer api.keyringLock.Unlock()

Expand Down Expand Up @@ -687,7 +691,7 @@ func (api *PublicEthereumAPI) doCall(
var addr common.Address

if args.From == nil {
addrs, err := api.Accounts()
addrs, err := api.accounts()
if err == nil && len(addrs) > 0 {
addr = addrs[0]
}
Expand Down
2 changes: 1 addition & 1 deletion app/rpc/namespaces/eth/filters/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (api *PublicFilterAPI) NewFilter(criteria filters.FilterCriteria) (rpc.ID,
//
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getLogs
func (api *PublicFilterAPI) GetLogs(ctx context.Context, criteria filters.FilterCriteria) ([]*ethtypes.Log, error) {
monitor := monitor.GetMonitor("eth_getBalance", api.logger)
monitor := monitor.GetMonitor("eth_getLogs", api.logger)
monitor.OnBegin(api.Metrics)
defer monitor.OnEnd("args", criteria)
rateLimiter := api.backend.GetRateLimiter("eth_getLogs")
Expand Down

0 comments on commit b87806e

Please sign in to comment.