Skip to content

Commit

Permalink
les: use nicer constants
Browse files Browse the repository at this point in the history
  • Loading branch information
zsfelfoldi committed Sep 27, 2019
1 parent bb71fc5 commit 7eb5f2d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions les/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"math"
"sync"
"time"

Expand All @@ -38,7 +39,7 @@ var (
errNoPriority = errors.New("not enough priority")
)

const maxBalance = 9000000000000000000
const maxBalance = math.MaxInt64

type clientApiFields struct {
balanceUpdatePeriod uint64
Expand Down Expand Up @@ -154,12 +155,12 @@ func (api *PrivateLightServerAPI) setParams(params map[string]interface{}, clien
loop:
for name, value := range params {
errValue := func() error {
return errors.New(fmt.Sprintf("invalid value for parameter '%s'", name))
return fmt.Errorf("invalid value for parameter '%s'", name)
}
setFactor := func(v *float64) {
if posFactors != nil {
if val, ok := value.(float64); ok && val >= 0 {
*v = val / 1000000000
*v = val / float64(time.Second)
updateFactors = true
} else {
err = errValue()
Expand All @@ -186,7 +187,7 @@ loop:
default:
processed = false
if defParams {
err = errors.New(fmt.Sprintf("invalid default parameter '%s'", name))
err = fmt.Errorf("invalid default parameter '%s'", name)
continue loop
}
}
Expand Down Expand Up @@ -226,7 +227,7 @@ loop:
err = errClientNotConnected
}
default:
err = errors.New(fmt.Sprintf("invalid client parameter '%s'", name))
err = fmt.Errorf("invalid client parameter '%s'", name)
}
}
return updateFactors, err
Expand Down
2 changes: 1 addition & 1 deletion les/clientpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ func (f *clientPool) getPosBalance(id enode.ID) *posBalance {
return balance
}

// getPosBalanceIDs returns a lexicographically ordered list of IDs of accounts
// getPosBalanceIDs returns a lexicographically ordered list of IDs from accounts
// with a positive balance
func (f *clientPool) getPosBalanceIDs(start, stop enode.ID, maxCount int) (result []enode.ID) {
if maxCount <= 0 {
Expand Down
2 changes: 1 addition & 1 deletion les/clientpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func testClientPool(t *testing.T, connLimit, clientCount, paidCount int, randomD

if tickCounter == testClientPoolTicks/4 {
// give a positive balance to some of the peers
amount := int64(testClientPoolTicks / 2 * 1000000000) // enough for half of the simulation period
amount := testClientPoolTicks / 2 * int64(time.Second) // enough for half of the simulation period
for i := 0; i < paidCount; i++ {
pool.forClients([]enode.ID{poolTestPeer(i).ID()}, func(client *clientInfo, id enode.ID) {
pool.updateBalance(id, amount, true, "")
Expand Down

0 comments on commit 7eb5f2d

Please sign in to comment.