Skip to content
Merged
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
25 changes: 5 additions & 20 deletions agreement/fuzzer/tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,7 @@ func TestNetworkBandwidth(t *testing.T) {

deadlock.Opts.Disable = true
rnd := rand.New(rand.NewSource(0))
k := 4 // outgoing connections
if k > relayCounts {
k = relayCounts
}
k := min(4, relayCounts) // outgoing connections
statConf := &TrafficStatisticsFilterConfig{
OutputFormat: 2,
}
Expand Down Expand Up @@ -563,10 +560,7 @@ func TestUnstakedNetworkLinearGrowth(t *testing.T) {

relayMaxBandwidth := []int{}

k := 4 // outgoing connections
if k > relayCount {
k = relayCount
}
k := min(4, relayCount) // outgoing connections
statConf := &TrafficStatisticsFilterConfig{
OutputFormat: 0,
}
Expand Down Expand Up @@ -674,10 +668,7 @@ func TestStakedNetworkQuadricGrowth(t *testing.T) {
totalRelayedMessages := []int{}
deadlock.Opts.Disable = true

k := 2 // outgoing connections
if k > relayCount {
k = relayCount
}
k := min(2, relayCount) // outgoing connections
statConf := &TrafficStatisticsFilterConfig{
OutputFormat: 0,
}
Expand Down Expand Up @@ -784,10 +775,7 @@ func TestRegossipinngElimination(t *testing.T) {
nodeCount := 20
deadlock.Opts.Disable = true
rnd := rand.New(rand.NewSource(0))
k := 4 // outgoing connections
if k > relayCounts {
k = relayCounts
}
k := min(4, relayCounts) // outgoing connections
statConf := &TrafficStatisticsFilterConfig{
OutputFormat: 2,
}
Expand Down Expand Up @@ -880,10 +868,7 @@ func BenchmarkNetworkPerformance(b *testing.B) {
// disable deadlock checking code
deadlock.Opts.Disable = true

k := 4 // outgoing connections
if k > relayCount {
k = relayCount
}
k := min(4, relayCount) // outgoing connections
statConf := &TrafficStatisticsFilterConfig{
OutputFormat: 0,
}
Expand Down
5 changes: 1 addition & 4 deletions agreement/gossip/networkFull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,7 @@ func testNetworkImplRebroadcast(t *testing.T, nodesCount int, cfg config.Local)
nets, counters := spinNetwork(t, nodesCount, cfg)
defer shutdownNetwork(nets, counters)

rebroadcastNodes := nodesCount
if rebroadcastNodes > 3 {
rebroadcastNodes = 3
}
rebroadcastNodes := min(nodesCount, 3)
for i := byte(0); i < byte(rebroadcastNodes); i++ {
ok := nets[i].Broadcast(protocol.AgreementVoteTag, []byte{i, i + 1})
assert.NoError(t, ok)
Expand Down
8 changes: 1 addition & 7 deletions agreement/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,7 @@ func (p *player) calculateFilterTimeout(ver protocol.ConsensusVersion, tracer *t
dynamicTimeout := p.lowestCredentialArrivals.orderStatistics(dynamicFilterTimeoutCredentialArrivalHistoryIdx) + dynamicFilterTimeoutGraceInterval

// Make sure the dynamic filter timeout is not too small nor too large
clampedTimeout := dynamicTimeout
if clampedTimeout < dynamicFilterTimeoutLowerBound {
clampedTimeout = dynamicFilterTimeoutLowerBound
}
if clampedTimeout > defaultTimeout {
clampedTimeout = defaultTimeout
}
clampedTimeout := min(max(dynamicTimeout, dynamicFilterTimeoutLowerBound), defaultTimeout)
tracer.log.Debugf("round %d, period %d: dynamicTimeout = %d, clamped timeout = %d", p.Round, p.Period, dynamicTimeout, clampedTimeout)
// store dynamicFilterTimeout on the player for debugging & reporting
p.dynamicFilterTimeout = dynamicTimeout
Expand Down
6 changes: 1 addition & 5 deletions agreement/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ func init() {
// for consistency in analytics we are setting the minimum to be 8 rounds
// (equivalent to a dynamicFilterTimeoutLowerBound of 500 ms).
minCredentialRoundLag := round(8) // round 2*2000ms / 500ms
credentialRoundLag = round(2 * config.Protocol.SmallLambda / dynamicFilterTimeoutLowerBound)

if credentialRoundLag < minCredentialRoundLag {
credentialRoundLag = minCredentialRoundLag
}
credentialRoundLag = max(round(2*config.Protocol.SmallLambda/dynamicFilterTimeoutLowerBound), minCredentialRoundLag)
if credentialRoundLag*round(dynamicFilterTimeoutLowerBound) < round(2*config.Protocol.SmallLambda) {
credentialRoundLag++
}
Expand Down
5 changes: 1 addition & 4 deletions catchup/catchpointService.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,7 @@ func (cs *CatchpointCatchupService) processStageBlocksDownload() (err error) {
// 2. replay starts from X-CatchpointLookback+1
// 3. transaction evaluation at Y requires block up to MaxTxnLife+DeeperBlockHeaderHistory back from Y
proto := config.Consensus[topBlock.CurrentProtocol]
lookback := proto.MaxTxnLife + proto.DeeperBlockHeaderHistory + proto.CatchpointLookback
if lookback < proto.MaxBalLookback {
lookback = proto.MaxBalLookback
}
lookback := max(proto.MaxTxnLife+proto.DeeperBlockHeaderHistory+proto.CatchpointLookback, proto.MaxBalLookback)

lookbackForStateProofSupport := lookbackForStateproofsSupport(&topBlock)
if lookback < lookbackForStateProofSupport {
Expand Down
10 changes: 2 additions & 8 deletions catchup/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,17 +476,11 @@ func (s *Service) fetchAndWrite(ctx context.Context, r basics.Round, prevFetchCo

// TODO the following code does not handle the following case: seedLookback upgrades during fetch
func (s *Service) pipelinedFetch(seedLookback uint64) {
maxParallelRequests := s.parallelBlocks
if maxParallelRequests < seedLookback {
maxParallelRequests = seedLookback
}
maxParallelRequests := max(s.parallelBlocks, seedLookback)
minParallelRequests := seedLookback

// Start the limited requests at max(1, 'seedLookback')
limitedParallelRequests := uint64(1)
if limitedParallelRequests < seedLookback {
limitedParallelRequests = seedLookback
}
limitedParallelRequests := max(1, seedLookback)

completed := make(map[basics.Round]chan bool)
var wg sync.WaitGroup
Expand Down
5 changes: 1 addition & 4 deletions cmd/catchpointdump/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,7 @@ func loadCatchpointIntoDatabase(ctx context.Context, catchupAccessor ledger.Catc
}
if time.Since(lastProgressUpdate) > 50*time.Millisecond && catchpointFileSize > 0 {
lastProgressUpdate = time.Now()
progressRatio := int(float64(progress) * barLength / float64(catchpointFileSize))
if progressRatio > barLength {
progressRatio = barLength
}
progressRatio := min(int(float64(progress)*barLength/float64(catchpointFileSize)), barLength)
printLoadCatchpointProgressLine(progressRatio, barLength, int64(progress))
}
}
Expand Down
5 changes: 1 addition & 4 deletions crypto/onetimesig.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,7 @@ func (s *OneTimeSignatureSecrets) DeleteBeforeFineGrained(current OneTimeSignatu
// subkeys.
if current.Batch+1 == s.FirstBatch {
if current.Offset > s.FirstOffset {
jump := current.Offset - s.FirstOffset
if jump > uint64(len(s.Offsets)) {
jump = uint64(len(s.Offsets))
}
jump := min(current.Offset-s.FirstOffset, uint64(len(s.Offsets)))

s.FirstOffset += jump
s.Offsets = s.Offsets[jump:]
Expand Down
5 changes: 1 addition & 4 deletions daemon/algod/api/server/v2/test/handlers_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,7 @@ func accountAssetInformationResourceLimitsTest(t *testing.T, handlers v2.Handler
assert.Equal(t, maxResults, len(*ret.AssetHoldings))

// Asset holdings should match the first limit assets from the account data
minForResults := 0
if inputNextToken > 0 {
minForResults = inputNextToken
}
minForResults := max(inputNextToken, 0)
for i := minForResults; i < minForResults+maxResults; i++ {
expectedIndex := basics.AssetIndex(i + 1)

Expand Down
26 changes: 7 additions & 19 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,10 @@ func feeCredit(txgroup []transactions.SignedTxnWithAD, minFee uint64) uint64 {

// NewInnerEvalParams creates an EvalParams to be used while evaluating an inner group txgroup
func NewInnerEvalParams(txg []transactions.SignedTxnWithAD, caller *EvalContext) *EvalParams {
minAvmVersion := computeMinAvmVersion(txg)
// Can't happen currently, since earliest inner callable version is higher
// than any minimum imposed otherwise. But is correct to inherit a stronger
// restriction from above, in case of future restriction.
if minAvmVersion < caller.minAvmVersion {
minAvmVersion = caller.minAvmVersion
}
minAvmVersion := max(computeMinAvmVersion(txg), caller.minAvmVersion)
// caller.AvmVersion can't exceed the computed value currently, since earliest
// inner callable version is higher than any minimum imposed otherwise. But is
// correct to inherit a stronger restriction from above, in case of future restriction.

// Unlike NewEvalParams, do not add fee credit here. opTxSubmit has already done so.

Expand Down Expand Up @@ -1638,10 +1635,7 @@ func (cx *EvalContext) step() error {
if len(cx.Stack) == 0 {
stackString = "<empty stack>"
} else {
num := 1
if len(spec.Return.Types) > 1 {
num = len(spec.Return.Types)
}
num := max(len(spec.Return.Types), 1)
// check for nil error here, because we might not return
// values if we encounter an error in the opcode
if err == nil {
Expand Down Expand Up @@ -3238,10 +3232,7 @@ func (cx *EvalContext) txnFieldToStack(stxn *transactions.SignedTxnWithAD, fs *t
return sv, fmt.Errorf("invalid ApprovalProgramPages index %d", arrayFieldIdx)
}
first := arrayFieldIdx * maxStringSize
last := first + maxStringSize
if last > uint64(len(txn.ApprovalProgram)) {
last = uint64(len(txn.ApprovalProgram))
}
last := min(first+maxStringSize, uint64(len(txn.ApprovalProgram)))
sv.Bytes = txn.ApprovalProgram[first:last]
case NumClearStateProgramPages:
sv.Uint = uint64(basics.DivCeil(len(txn.ClearStateProgram), maxStringSize))
Expand All @@ -3251,10 +3242,7 @@ func (cx *EvalContext) txnFieldToStack(stxn *transactions.SignedTxnWithAD, fs *t
return sv, fmt.Errorf("invalid ClearStateProgramPages index %d", arrayFieldIdx)
}
first := arrayFieldIdx * maxStringSize
last := first + maxStringSize
if last > uint64(len(txn.ClearStateProgram)) {
last = uint64(len(txn.ClearStateProgram))
}
last := min(first+maxStringSize, uint64(len(txn.ClearStateProgram)))
sv.Bytes = txn.ClearStateProgram[first:last]
case RekeyTo:
sv.Bytes = txn.RekeyTo[:]
Expand Down
5 changes: 1 addition & 4 deletions data/transactions/verify/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,7 @@ func generateTransactionGroups(maxGroupSize int, signedTxns []transactions.Signe

txnGroups := make([][]transactions.SignedTxn, 0, len(signedTxns))
for i := 0; i < len(signedTxns); {
txnsInGroup := rand.Intn(protoMaxGroupSize-1) + 1
if txnsInGroup > maxGroupSize {
txnsInGroup = maxGroupSize
}
txnsInGroup := min(rand.Intn(protoMaxGroupSize-1)+1, maxGroupSize)
if i+txnsInGroup > len(signedTxns) {
txnsInGroup = len(signedTxns) - i
}
Expand Down
10 changes: 2 additions & 8 deletions data/txHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,10 +1361,7 @@ func getTransactionGroups(N, numUsers, maxGroupSize int, addresses []basics.Addr
txnGrps := make([][]transactions.Transaction, N)
protoMaxGrpSize := proto.MaxTxGroupSize
for u := 0; u < N; u++ {
grpSize := rand.Intn(protoMaxGrpSize-1) + 1
if grpSize > maxGroupSize {
grpSize = maxGroupSize
}
grpSize := min(rand.Intn(protoMaxGrpSize-1)+1, maxGroupSize)
var txGroup transactions.TxGroup
txns := make([]transactions.Transaction, 0, grpSize)
for g := 0; g < grpSize; g++ {
Expand Down Expand Up @@ -1794,10 +1791,7 @@ func runHandlerBenchmarkWithBacklog(b *testing.B, txGen txGenIf, tps int, useBac
}

// Prepare 1000 transactions
genTCount := 1000
if b.N < genTCount {
genTCount = b.N
}
genTCount := min(b.N, 1000)
signedTransactionGroups, badTxnGroups := txGen.createSignedTxGroups(b, genTCount)
var encStxns []network.IncomingMessage
if useBacklogWorker {
Expand Down
10 changes: 2 additions & 8 deletions ledger/acctdeltas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,7 @@ func randomCreatableSampling(iteration int, crtbsList []basics.CreatableIndex,
iteration-- // 0-based here

delSegmentEnd := iteration * numElementsPerSegement
delSegmentStart := delSegmentEnd - numElementsPerSegement
if delSegmentStart < 0 {
delSegmentStart = 0
}
delSegmentStart := max(delSegmentEnd-numElementsPerSegement, 0)

newSample := make(map[basics.CreatableIndex]ledgercore.ModifiedCreatable)
stop := delSegmentEnd + numElementsPerSegement
Expand Down Expand Up @@ -707,10 +704,7 @@ func benchmarkWriteCatchpointStagingBalancesSub(b *testing.B, ascendingOrder boo
b.StopTimer()
balancesLoopStart := time.Now()
// generate a chunk;
chunkSize := targetAccountsCount - accountsLoaded
if chunkSize > BalancesPerCatchpointFileChunk {
chunkSize = BalancesPerCatchpointFileChunk
}
chunkSize := min(targetAccountsCount-accountsLoaded, BalancesPerCatchpointFileChunk)
last64KSize += chunkSize
if accountsLoaded >= targetAccountsCount-64*1024 && last64KStart.IsZero() {
last64KStart = time.Now()
Expand Down
5 changes: 1 addition & 4 deletions ledger/catchpointtracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ func (ct *catchpointTracker) initialize(cfg config.Local, paths DirsAndPrefix) {
ct.enableGeneratingCatchpointFiles = true
}

ct.catchpointFileHistoryLength = cfg.CatchpointFileHistoryLength
if cfg.CatchpointFileHistoryLength < -1 {
ct.catchpointFileHistoryLength = -1
}
ct.catchpointFileHistoryLength = max(cfg.CatchpointFileHistoryLength, -1)
}

// GetLastCatchpointLabel retrieves the last catchpoint label that was stored to the database.
Expand Down
5 changes: 1 addition & 4 deletions ledger/catchpointtracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2030,10 +2030,7 @@ func TestCatchpointLargeAccountCountCatchpointGeneration(t *testing.T) {
}

start := basics.Round(initialBlocksCount)
min := conf.CatchpointInterval
if min < protoParams.CatchpointLookback {
min = protoParams.CatchpointLookback
}
min := max(conf.CatchpointInterval, protoParams.CatchpointLookback)
end := basics.Round(min + conf.MaxAcctLookback + 3) // few more rounds to commit and generate the second stage
for i := start; i < end; i++ {
rewardLevelDelta := crypto.RandUint64() % 5
Expand Down
5 changes: 1 addition & 4 deletions ledger/catchupaccessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ func createTestingEncodedChunks(accountsCount uint64) (encodedAccountChunks [][]
last64KIndex = -1
for accounts < accountsCount {
// generate a chunk;
chunkSize := accountsCount - accounts
if chunkSize > BalancesPerCatchpointFileChunk {
chunkSize = BalancesPerCatchpointFileChunk
}
chunkSize := min(accountsCount-accounts, BalancesPerCatchpointFileChunk)
if accounts >= accountsCount-64*1024 && last64KIndex == -1 {
last64KIndex = len(encodedAccountChunks)
}
Expand Down
5 changes: 1 addition & 4 deletions ledger/store/trackerdb/pebbledbdriver/pebbledriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ func Open(dbdir string, inMem bool, proto config.ConsensusParams, log logging.Lo
maxMemTableSize := 4<<30 - 1 // Capped by 4 GB

memTableLimit := 2 // default: 2
memTableSize := cache * 1024 * 1024 / 2 / memTableLimit
if memTableSize > maxMemTableSize {
memTableSize = maxMemTableSize
}
memTableSize := min(cache*1024*1024/2/memTableLimit, maxMemTableSize)

// configure pebbledb
opts := &pebble.Options{
Expand Down
6 changes: 2 additions & 4 deletions ledger/txtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,8 @@ func (t *txTail) recentTailHash(offset uint64, retainSize uint64) (crypto.Digest
buffer := make([]byte, (retainSize)*crypto.DigestSize)
bufIdx := 0
t.tailMu.RLock()
lastOffset := offset + retainSize // size of interval [offset, lastOffset) is retainSize
if lastOffset > uint64(len(t.roundTailHashes)) {
lastOffset = uint64(len(t.roundTailHashes))
}
// size of interval [offset, lastOffset) is retainSize
lastOffset := min(offset+retainSize, uint64(len(t.roundTailHashes)))
for i := offset; i < lastOffset; i++ {
copy(buffer[bufIdx:], t.roundTailHashes[i][:])
bufIdx += crypto.DigestSize
Expand Down
6 changes: 1 addition & 5 deletions netdeploy/remote/deployedNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,7 @@ func (cfg DeployedNetwork) GenerateDatabaseFiles(fileCfgs BootstrappedNetwork, g

minAccounts := accountsNeeded(fileCfgs.GeneratedApplicationCount, fileCfgs.GeneratedAssetsCount, params)
nAccounts := fileCfgs.GeneratedAccountsCount
if minAccounts > nAccounts {
bootstrappedNet.nAccounts = minAccounts
} else {
bootstrappedNet.nAccounts = nAccounts
}
bootstrappedNet.nAccounts = max(minAccounts, nAccounts)

//fund src account with enough funding
rand.Seed(time.Now().UnixNano())
Expand Down
5 changes: 1 addition & 4 deletions network/limited_reader_slurper.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ func (s *LimitedReaderSlurper) Bytes() []byte {
// allocateNextBuffer allocates the next buffer and places it in the buffers array.
func (s *LimitedReaderSlurper) allocateNextBuffer() {
s.lastBuffer++
allocationSize := allocationStep
if allocationSize > s.remainedUnallocatedSpace {
allocationSize = s.remainedUnallocatedSpace
}
allocationSize := min(allocationStep, s.remainedUnallocatedSpace)
s.buffers[s.lastBuffer] = make([]byte, 0, allocationSize)
s.remainedUnallocatedSpace -= allocationSize
}
5 changes: 1 addition & 4 deletions network/limited_reader_slurper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ type fuzzReader struct {
}

func (f *fuzzReader) Read(b []byte) (n int, err error) {
s := int(crypto.RandUint64() % 19)
if s > len(b) {
s = len(b)
}
s := min(int(crypto.RandUint64()%19), len(b))
if f.pos >= len(f.buf) {
return 0, io.EOF
}
Expand Down
6 changes: 2 additions & 4 deletions network/msgCompressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ const zstdCompressionLevel = zstd.BestSpeed

// zstdCompressMsg returns a concatenation of a tag and compressed data
func zstdCompressMsg(tbytes []byte, d []byte) ([]byte, string) {
bound := zstd.CompressBound(len(d))
if bound < len(d) {
bound := max(zstd.CompressBound(len(d)),
// although CompressBound allocated more than the src size, this is an implementation detail.
// increase the buffer size to always have enough space for the raw data if compression fails.
bound = len(d)
}
len(d))
mbytesComp := make([]byte, len(tbytes)+bound)
copy(mbytesComp, tbytes)
comp, err := zstd.CompressLevel(mbytesComp[len(tbytes):], d, zstdCompressionLevel)
Expand Down
Loading
Loading