Skip to content
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
5 changes: 1 addition & 4 deletions cmd/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,10 +932,7 @@ func setTxResendConfig(ctx *cli.Context, cfg *cn.Config) {
cfg.TxResendInterval = cn.DefaultTxResendInterval
}

cfg.TxResendCount = ctx.Int(TxResendCountFlag.Name)
if cfg.TxResendCount < cn.DefaultMaxResendTxCount {
cfg.TxResendCount = cn.DefaultMaxResendTxCount
}
cfg.TxResendCount = max(ctx.Int(TxResendCountFlag.Name), cn.DefaultMaxResendTxCount)
cfg.TxResendUseLegacy = ctx.Bool(TxResendUseLegacyFlag.Name)
logger.Debug("TxResend config", "Interval", cfg.TxResendInterval, "TxResendCount", cfg.TxResendCount, "UseLegacy", cfg.TxResendUseLegacy)
}
Expand Down
5 changes: 1 addition & 4 deletions datasync/dbsyncer/query_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ func (qe *QueryEngine) executeBulkInsert(bulkInserts []*BulkInsertQuery, result
}

// Ensure we have meaningful task sizes and schedule the recoveries
tasks := qe.insertQueue
if len(bulkInserts) < tasks {
tasks = len(bulkInserts)
}
tasks := min(len(bulkInserts), qe.insertQueue)
for i := 0; i < tasks; i++ {
qe.inserts <- &BulkInsertRequest{
bulkInserts: bulkInserts[i:],
Expand Down
22 changes: 4 additions & 18 deletions datasync/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
p.logger.Debug("Looking for common ancestor", "local", ceil, "remote", height)

// Request the topmost blocks to short circuit binary ancestor lookup
head := ceil
if head > height {
head = height
}
head := min(ceil, height)
from := int64(head) - int64(MaxHeaderFetch)
if from < 0 {
if head < 16 {
Expand All @@ -843,10 +840,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
}
// Span out with 15 block gaps into the future to catch bad head reports
limit := 2 * MaxHeaderFetch / 16
count := 1 + int((int64(ceil)-from)/16)
if count > limit {
count = limit
}
count := min(1+int((int64(ceil)-from)/16), limit)
go p.peer.RequestHeadersByNumber(uint64(from), count, 15, false)

// Wait for the remote response to the head fetch
Expand Down Expand Up @@ -1592,10 +1586,7 @@ func (d *Downloader) processHeaders(origin uint64, td *big.Int) error {
default:
}
// Select the next chunk of headers to import
limit := maxHeadersProcess
if limit > len(headers) {
limit = len(headers)
}
limit := min(maxHeadersProcess, len(headers))
chunk := headers[:limit]

// In case of header only syncing, validate the chunk immediately
Expand Down Expand Up @@ -1977,7 +1968,6 @@ func (d *Downloader) DeliverSnapPacket(peer *snap.Peer, packet snap.Packet) erro
}
}


// deliver injects a new batch of data received from a remote node.
func (d *Downloader) deliver(id string, destCh chan dataPack, packet dataPack, inMeter, dropMeter metrics.Meter) (err error) {
// Update the delivery metrics for both good and failed deliveries
Expand Down Expand Up @@ -2070,11 +2060,7 @@ func (d *Downloader) requestTTL() time.Duration {
rtt = time.Duration(atomic.LoadUint64(&d.rttEstimate))
conf = float64(atomic.LoadUint64(&d.rttConfidence)) / 1000000.0
)
ttl := time.Duration(ttlScaling) * time.Duration(float64(rtt)/conf)
if ttl > ttlLimit {
ttl = ttlLimit
}
return ttl
return min(time.Duration(ttlScaling)*time.Duration(float64(rtt)/conf), ttlLimit)
}

func calcStakingBlockNumber(blockNum uint64, stakingUpdateInterval uint64) uint64 {
Expand Down
7 changes: 1 addition & 6 deletions kaiax/auction/impl/bid_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,5 @@ func (bp *BidPool) getBidTxGasLimit(bid *auction.Bid) (uint64, error) {
}
}

gasLimit := intrinsicGas + bid.CallGasLimit + buffer
if gasLimit < floorDataGas {
gasLimit = floorDataGas
}

return gasLimit, nil
return max(intrinsicGas+bid.CallGasLimit+buffer, floorDataGas), nil
}
10 changes: 2 additions & 8 deletions kaiax/valset/impl/getter_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,12 @@ func (v *ValsetModule) getProposer(c *blockContext, round uint64) (common.Addres
}

func selectRoundRobinProposer(qualified *valset.AddressSet, prevProposer common.Address, round uint64) common.Address {
prevIdx := qualified.IndexOf(prevProposer)
if prevIdx < 0 {
prevIdx = 0
}
prevIdx := max(qualified.IndexOf(prevProposer), 0)
return qualified.At((prevIdx + int(round) + 1) % qualified.Len())
}

func selectStickyProposer(qualified *valset.AddressSet, prevProposer common.Address, round uint64) common.Address {
prevIdx := qualified.IndexOf(prevProposer)
if prevIdx < 0 {
prevIdx = 0
}
prevIdx := max(qualified.IndexOf(prevProposer), 0)
return qualified.At((prevIdx + int(round)) % qualified.Len())
}

Expand Down
5 changes: 1 addition & 4 deletions networks/p2p/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ func (r *eofSignal) Read(buf []byte) (int, error) {
return 0, io.EOF
}

max := len(buf)
if int(r.count) < len(buf) {
max = int(r.count)
}
max := min(int(r.count), len(buf))
n, err := r.wrapped.Read(buf[:max])
r.count -= uint32(n)
if (err != nil || r.count == 0) && r.eof != nil {
Expand Down
5 changes: 1 addition & 4 deletions networks/p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1183,10 +1183,7 @@ func (s *sharedUDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err err
if !ok {
return 0, nil, fmt.Errorf("Connection was closed")
}
l := len(packet.Data)
if l > len(b) {
l = len(b)
}
l := min(len(packet.Data), len(b))
copy(b[:l], packet.Data[:l])
return l, packet.Addr, nil
}
Expand Down
10 changes: 2 additions & 8 deletions node/cn/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,8 @@ type Oracle struct {

// NewOracle returns a new oracle.
func NewOracle(backend OracleBackend, config Config, txPool TxPool, govModule gov.GovModule) *Oracle {
blocks := config.Blocks
if blocks < 1 {
blocks = 1
}
percent := config.Percentile
if percent < 0 {
percent = 0
}
blocks := max(config.Blocks, 1)
percent := max(config.Percentile, 0)
if percent > 100 {
percent = 100
}
Expand Down
10 changes: 2 additions & 8 deletions node/cn/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,7 @@ func (api *CommonAPI) traceChain(start, end *types.Block, config *TraceConfig, n
}
// Execute all the transaction contained within the chain concurrently for each block
blocks := int(end.NumberU64() - start.NumberU64())
threads := runtime.NumCPU()
if threads > blocks {
threads = blocks
}
threads := min(runtime.NumCPU(), blocks)
var (
pend = new(sync.WaitGroup)
tasks = make(chan *blockTraceTask, threads)
Expand Down Expand Up @@ -700,10 +697,7 @@ func (api *CommonAPI) traceBlock(ctx context.Context, block *types.Block, config
blockCtx = blockchain.NewEVMBlockContext(header, newChainContext(ctx, api.backend), nil)
)

threads := runtime.NumCPU()
if threads > len(txs) {
threads = len(txs)
}
threads := min(runtime.NumCPU(), len(txs))
for th := 0; th < threads; th++ {
pend.Go(func() {

Expand Down
5 changes: 1 addition & 4 deletions tests/pregenerated_data_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,7 @@ func dataExecutionTest(b *testing.B, tc *preGeneratedTC) {
// there is no transaction left.
func executeTxs(bcData *BCData, txPool *blockchain.TxPool, txs types.Transactions) error {
for i := 0; i < len(txs); i += txPoolSize {
end := i + txPoolSize
if end > len(txs) {
end = len(txs)
}
end := min(i+txPoolSize, len(txs))
txPool.AddRemotes(txs[i:end])
for {
if err := bcData.GenABlockWithTxPoolWithoutAccountMap(txPool); err != nil {
Expand Down