Skip to content

Commit

Permalink
chore: rename max var name to avoid collision with predeclared iden…
Browse files Browse the repository at this point in the history
…tifier

Signed-off-by: gfanton <[email protected]>
  • Loading branch information
gfanton committed Dec 5, 2024
1 parent 5427f26 commit cc52b62
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 96 deletions.
26 changes: 13 additions & 13 deletions gnovm/pkg/gnolang/op_expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ func (m *Machine) doOpSelector() {

func (m *Machine) doOpSlice() {
sx := m.PopExpr().(*SliceExpr)
var low, high, max int = -1, -1, -1
var lowVal, highVal, maxVal int = -1, -1, -1
// max
if sx.Max != nil {
max = m.PopValue().ConvertGetInt()
maxVal = m.PopValue().ConvertGetInt()
}
// high
if sx.High != nil {
high = m.PopValue().ConvertGetInt()
highVal = m.PopValue().ConvertGetInt()
}
// low
if sx.Low != nil {
low = m.PopValue().ConvertGetInt()
lowVal = m.PopValue().ConvertGetInt()
} else {
low = 0
lowVal = 0
}
// slice base x
xv := m.PopValue()
Expand All @@ -114,14 +114,14 @@ func (m *Machine) doOpSlice() {
}
// fill default based on xv
if sx.High == nil {
high = xv.GetLength()
highVal = xv.GetLength()
}
// all low:high:max cases
if max == -1 {
sv := xv.GetSlice(m.Alloc, low, high)
if maxVal == -1 {
sv := xv.GetSlice(m.Alloc, lowVal, highVal)
m.PushValue(sv)
} else {
sv := xv.GetSlice2(m.Alloc, low, high, max)
sv := xv.GetSlice2(m.Alloc, lowVal, highVal, maxVal)
m.PushValue(sv)
}
}
Expand Down Expand Up @@ -593,16 +593,16 @@ func (m *Machine) doOpSliceLit2() {
// peek slice type.
st := m.PeekValue(1).V.(TypeValue).Type
// calculate maximum index.
max := 0
maxVal := 0
for i := 0; i < el; i++ {
itv := tvs[i*2+0]
idx := itv.ConvertGetInt()
if idx > max {
max = idx
if idx > maxVal {
maxVal = idx
}
}
// construct element buf slice.
es := make([]TypedValue, max+1)
es := make([]TypedValue, maxVal+1)
for i := 0; i < el; i++ {
itv := tvs[i*2+0]
vtv := tvs[i*2+1]
Expand Down
48 changes: 24 additions & 24 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -2248,41 +2248,41 @@ func (tv *TypedValue) GetSlice(alloc *Allocator, low, high int) TypedValue {
}
}

func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue {
if low < 0 {
func (tv *TypedValue) GetSlice2(alloc *Allocator, lowVal, highVal, maxVal int) TypedValue {
if lowVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
low))
lowVal))

Check warning on line 2255 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2255

Added line #L2255 was not covered by tests
}
if high < 0 {
if highVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
high))
highVal))

Check warning on line 2260 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2260

Added line #L2260 was not covered by tests
}
if max < 0 {
if maxVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
max))
maxVal))

Check warning on line 2265 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2265

Added line #L2265 was not covered by tests
}
if low > high {
if lowVal > highVal {
panic(fmt.Sprintf(
"invalid slice index %d > %d",
low, high))
lowVal, highVal))

Check warning on line 2270 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2270

Added line #L2270 was not covered by tests
}
if high > max {
if highVal > maxVal {
panic(fmt.Sprintf(
"invalid slice index %d > %d",
high, max))
highVal, maxVal))

Check warning on line 2275 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2275

Added line #L2275 was not covered by tests
}
if tv.GetCapacity() < high {
if tv.GetCapacity() < highVal {
panic(fmt.Sprintf(
"slice bounds out of range [%d:%d:%d] with capacity %d",
low, high, max, tv.GetCapacity()))
lowVal, highVal, maxVal, tv.GetCapacity()))

Check warning on line 2280 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2280

Added line #L2280 was not covered by tests
}
if tv.GetCapacity() < max {
if tv.GetCapacity() < maxVal {
panic(fmt.Sprintf(
"slice bounds out of range [%d:%d:%d] with capacity %d",
low, high, max, tv.GetCapacity()))
lowVal, highVal, maxVal, tv.GetCapacity()))

Check warning on line 2285 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2285

Added line #L2285 was not covered by tests
}
switch bt := baseOf(tv.T).(type) {
case *ArrayType:
Expand All @@ -2294,15 +2294,15 @@ func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue
return TypedValue{
T: st,
V: alloc.NewSlice(
av, // base
low, // low
high-low, // length
max-low, // maxcap
av, // base
lowVal, // low
highVal-lowVal, // length
maxVal-lowVal, // maxcap
),
}
case *SliceType:
if tv.V == nil {
if low != 0 || high != 0 || max != 0 {
if lowVal != 0 || highVal != 0 || maxVal != 0 {

Check warning on line 2305 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2305

Added line #L2305 was not covered by tests
panic("nil slice index out of range")
}
return TypedValue{
Expand All @@ -2314,10 +2314,10 @@ func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue
return TypedValue{
T: tv.T,
V: alloc.NewSlice(
sv.Base, // base
sv.Offset+low, // offset
high-low, // length
max-low, // maxcap
sv.Base, // base
sv.Offset+lowVal, // offset
highVal-lowVal, // length
maxVal-lowVal, // maxcap
),
}
default:
Expand Down
8 changes: 4 additions & 4 deletions tm2/pkg/bft/blockchain/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,13 @@ func (pool *BlockPool) removePeer(peerID p2p.ID) {

// If no peers are left, maxPeerHeight is set to 0.
func (pool *BlockPool) updateMaxPeerHeight() {
var max int64
var maxVal int64
for _, peer := range pool.peers {
if peer.height > max {
max = peer.height
if peer.height > maxVal {
maxVal = peer.height
}
}
pool.maxPeerHeight = max
pool.maxPeerHeight = maxVal
}

// Pick an available peer with at least the given minHeight.
Expand Down
10 changes: 5 additions & 5 deletions tm2/pkg/bft/mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,21 +505,21 @@ func (mem *CListMempool) ReapMaxBytesMaxGas(maxDataBytes, maxGas int64) types.Tx
return txs
}

func (mem *CListMempool) ReapMaxTxs(max int) types.Txs {
func (mem *CListMempool) ReapMaxTxs(maxVal int) types.Txs {
mem.mtx.Lock()
defer mem.mtx.Unlock()

if max < 0 {
max = mem.txs.Len()
if maxVal < 0 {
maxVal = mem.txs.Len()

Check warning on line 513 in tm2/pkg/bft/mempool/clist_mempool.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/mempool/clist_mempool.go#L513

Added line #L513 was not covered by tests
}

for atomic.LoadInt32(&mem.rechecking) > 0 {
// TODO: Something better?
time.Sleep(time.Millisecond * 10)
}

txs := make([]types.Tx, 0, min(mem.txs.Len(), max))
for e := mem.txs.Front(); e != nil && len(txs) <= max; e = e.Next() {
txs := make([]types.Tx, 0, min(mem.txs.Len(), maxVal))
for e := mem.txs.Front(); e != nil && len(txs) <= maxVal; e = e.Next() {
memTx := e.Value.(*mempoolTx)
txs = append(txs, memTx.tx)
}
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/bft/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Mempool interface {
// ReapMaxTxs reaps up to max transactions from the mempool.
// If max is negative, there is no cap on the size of all returned
// transactions (~ all available transactions).
ReapMaxTxs(max int) types.Txs
ReapMaxTxs(maxVal int) types.Txs

// Lock locks the mempool. The consensus must be able to hold lock to safely update.
Lock()
Expand Down
6 changes: 3 additions & 3 deletions tm2/pkg/bft/rpc/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,11 @@ func getHeight(currentHeight int64, heightPtr *int64) (int64, error) {
return getHeightWithMin(currentHeight, heightPtr, 1)
}

func getHeightWithMin(currentHeight int64, heightPtr *int64, min int64) (int64, error) {
func getHeightWithMin(currentHeight int64, heightPtr *int64, minVal int64) (int64, error) {
if heightPtr != nil {
height := *heightPtr
if height < min {
return 0, fmt.Errorf("height must be greater than or equal to %d", min)
if height < minVal {
return 0, fmt.Errorf("height must be greater than or equal to %d", minVal)
}
if height > currentHeight {
return 0, fmt.Errorf("height must be less than or equal to the current blockchain height")
Expand Down
18 changes: 9 additions & 9 deletions tm2/pkg/bft/rpc/core/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ func TestBlockchainInfo(t *testing.T) {
t.Parallel()

cases := []struct {
min, max int64
height int64
limit int64
resultLength int64
wantErr bool
minVal, maxVal int64
height int64
limit int64
resultLength int64
wantErr bool
}{
// min > max
{0, 0, 0, 10, 0, true}, // min set to 1
Expand Down Expand Up @@ -46,12 +46,12 @@ func TestBlockchainInfo(t *testing.T) {

for i, c := range cases {
caseString := fmt.Sprintf("test %d failed", i)
min, max, err := filterMinMax(c.height, c.min, c.max, c.limit)
minVal, maxVal, err := filterMinMax(c.height, c.minVal, c.maxVal, c.limit)
if c.wantErr {
require.Error(t, err, caseString)
} else {
require.NoError(t, err, caseString)
require.Equal(t, 1+max-min, c.resultLength, caseString)
require.Equal(t, 1+maxVal-minVal, c.resultLength, caseString)
}
}
}
Expand All @@ -62,7 +62,7 @@ func TestGetHeight(t *testing.T) {
cases := []struct {
currentHeight int64
heightPtr *int64
min int64
minVal int64
res int64
wantErr bool
}{
Expand All @@ -79,7 +79,7 @@ func TestGetHeight(t *testing.T) {

for i, c := range cases {
caseString := fmt.Sprintf("test %d failed", i)
res, err := getHeightWithMin(c.currentHeight, c.heightPtr, c.min)
res, err := getHeightWithMin(c.currentHeight, c.heightPtr, c.minVal)
if c.wantErr {
require.Error(t, err, caseString)
} else {
Expand Down
10 changes: 5 additions & 5 deletions tm2/pkg/bft/rpc/lib/server/http_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ import (
func TestMaxOpenConnections(t *testing.T) {
t.Parallel()

const max = 5 // max simultaneous connections
const maxVal = 5 // max simultaneous connections

// Start the server.
var open int32
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if n := atomic.AddInt32(&open, 1); n > int32(max) {
t.Errorf("%d open connections, want <= %d", n, max)
if n := atomic.AddInt32(&open, 1); n > int32(maxVal) {
t.Errorf("%d open connections, want <= %d", n, maxVal)
}
defer atomic.AddInt32(&open, -1)
time.Sleep(10 * time.Millisecond)
fmt.Fprint(w, "some body")
})
config := DefaultConfig()
config.MaxOpenConnections = max
config.MaxOpenConnections = maxVal
l, err := Listen("tcp://127.0.0.1:0", config)
require.NoError(t, err)
defer l.Close()
go StartHTTPServer(l, mux, log.NewTestingLogger(t), config)

// Make N GET calls to the server.
attempts := max * 2
attempts := maxVal * 2
var wg sync.WaitGroup
var failed int32
for i := 0; i < attempts; i++ {
Expand Down
4 changes: 2 additions & 2 deletions tm2/pkg/bft/types/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type EvidenceOverflowError struct {
}

// NewErrEvidenceOverflow returns a new EvidenceOverflowError where got > max.
func NewErrEvidenceOverflow(max, got int64) *EvidenceOverflowError {
return &EvidenceOverflowError{max, got}
func NewErrEvidenceOverflow(maxVal, got int64) *EvidenceOverflowError {
return &EvidenceOverflowError{maxVal, got}

Check warning on line 42 in tm2/pkg/bft/types/evidence.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/types/evidence.go#L41-L42

Added lines #L41 - L42 were not covered by tests
}

// Error returns a string representation of the error.
Expand Down
14 changes: 7 additions & 7 deletions tm2/pkg/bft/types/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ func computeMaxMinPriorityDiff(vals *ValidatorSet) int64 {
if vals.IsNilOrEmpty() {
panic("empty validator set")
}
max := int64(math.MinInt64)
min := int64(math.MaxInt64)
maxVal := int64(math.MinInt64)
minVal := int64(math.MaxInt64)
for _, v := range vals.Validators {
if v.ProposerPriority < min {
min = v.ProposerPriority
if v.ProposerPriority < minVal {
minVal = v.ProposerPriority
}
if v.ProposerPriority > max {
max = v.ProposerPriority
if v.ProposerPriority > maxVal {
maxVal = v.ProposerPriority
}
}
diff := max - min
diff := maxVal - minVal
if diff < 0 {
return -1 * diff
} else {
Expand Down
Loading

0 comments on commit cc52b62

Please sign in to comment.