Skip to content

Commit

Permalink
Fix new G115 lints in golangci-lint v1.61.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Sep 9, 2024
1 parent 8bdb5ee commit 01e1c4a
Show file tree
Hide file tree
Showing 71 changed files with 207 additions and 75 deletions.
13 changes: 9 additions & 4 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ type BatchPosterConfig struct {
L1BlockBound string `koanf:"l1-block-bound" reload:"hot"`
L1BlockBoundBypass time.Duration `koanf:"l1-block-bound-bypass" reload:"hot"`
UseAccessLists bool `koanf:"use-access-lists" reload:"hot"`
GasEstimateBaseFeeMultipleBips arbmath.Bips `koanf:"gas-estimate-base-fee-multiple-bips"`
GasEstimateBaseFeeMultipleBips arbmath.UBips `koanf:"gas-estimate-base-fee-multiple-bips"`
Dangerous BatchPosterDangerousConfig `koanf:"dangerous"`
ReorgResistanceMargin time.Duration `koanf:"reorg-resistance-margin" reload:"hot"`
CheckBatchCorrectness bool `koanf:"check-batch-correctness"`
Expand Down Expand Up @@ -253,7 +253,7 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
L1BlockBoundBypass: time.Hour,
UseAccessLists: true,
RedisLock: redislock.DefaultCfg,
GasEstimateBaseFeeMultipleBips: arbmath.OneInBips * 3 / 2,
GasEstimateBaseFeeMultipleBips: arbmath.OneInUBips * 3 / 2,
ReorgResistanceMargin: 10 * time.Minute,
CheckBatchCorrectness: true,
}
Expand Down Expand Up @@ -285,7 +285,7 @@ var TestBatchPosterConfig = BatchPosterConfig{
L1BlockBound: "",
L1BlockBoundBypass: time.Hour,
UseAccessLists: true,
GasEstimateBaseFeeMultipleBips: arbmath.OneInBips * 3 / 2,
GasEstimateBaseFeeMultipleBips: arbmath.OneInUBips * 3 / 2,
CheckBatchCorrectness: true,
}

Expand Down Expand Up @@ -1035,7 +1035,7 @@ func (b *BatchPoster) estimateGas(ctx context.Context, sequencerMessage []byte,
if err != nil {
return 0, err
}
maxFeePerGas := arbmath.BigMulByBips(latestHeader.BaseFee, config.GasEstimateBaseFeeMultipleBips)
maxFeePerGas := arbmath.BigMulByUBips(latestHeader.BaseFee, config.GasEstimateBaseFeeMultipleBips)
if useNormalEstimation {
_, realBlobHashes, err := blobs.ComputeCommitmentsAndHashes(realBlobs)
if err != nil {
Expand Down Expand Up @@ -1250,7 +1250,9 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
l1BoundMinTimestamp = arbmath.SaturatingUSub(latestHeader.Time, arbmath.BigToUintSaturating(maxTimeVariationDelaySeconds))

if config.L1BlockBoundBypass > 0 {
// #nosec G115
blockNumberWithPadding := arbmath.SaturatingUAdd(latestBlockNumber, uint64(config.L1BlockBoundBypass/ethPosBlockTime))
// #nosec G115
timestampWithPadding := arbmath.SaturatingUAdd(latestHeader.Time, uint64(config.L1BlockBoundBypass/time.Second))
l1BoundMinBlockNumberWithBypass = arbmath.SaturatingUSub(blockNumberWithPadding, arbmath.BigToUintSaturating(maxTimeVariationDelayBlocks))
l1BoundMinTimestampWithBypass = arbmath.SaturatingUSub(timestampWithPadding, arbmath.BigToUintSaturating(maxTimeVariationDelaySeconds))
Expand Down Expand Up @@ -1316,7 +1318,9 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
if hasL1Bound && config.ReorgResistanceMargin > 0 {
firstMsgBlockNumber := firstMsg.Message.Header.BlockNumber
firstMsgTimeStamp := firstMsg.Message.Header.Timestamp
// #nosec G115
batchNearL1BoundMinBlockNumber := firstMsgBlockNumber <= arbmath.SaturatingUAdd(l1BoundMinBlockNumber, uint64(config.ReorgResistanceMargin/ethPosBlockTime))
// #nosec G115
batchNearL1BoundMinTimestamp := firstMsgTimeStamp <= arbmath.SaturatingUAdd(l1BoundMinTimestamp, uint64(config.ReorgResistanceMargin/time.Second))
if batchNearL1BoundMinTimestamp || batchNearL1BoundMinBlockNumber {
log.Error(
Expand Down Expand Up @@ -1361,6 +1365,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
batchPosterDAFailureCounter.Inc(1)
return false, fmt.Errorf("%w: nonce changed from %d to %d while creating batch", storage.ErrStorageRace, nonce, gotNonce)
}
// #nosec G115
sequencerMsg, err = b.dapWriter.Store(ctx, sequencerMsg, uint64(time.Now().Add(config.DASRetentionPeriod).Unix()), config.DisableDapFallbackStoreDataOnChain)
if err != nil {
batchPosterDAFailureCounter.Inc(1)
Expand Down
10 changes: 5 additions & 5 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,11 @@ func (p *DataPoster) feeAndTipCaps(ctx context.Context, nonce uint64, gasLimit u

if config.MaxFeeBidMultipleBips > 0 {
// Limit the fee caps to be no greater than max(MaxFeeBidMultipleBips, minRbf)
maxNonBlobFee := arbmath.BigMulByBips(currentNonBlobFee, config.MaxFeeBidMultipleBips)
maxNonBlobFee := arbmath.BigMulByUBips(currentNonBlobFee, config.MaxFeeBidMultipleBips)
if lastTx != nil {
maxNonBlobFee = arbmath.BigMax(maxNonBlobFee, arbmath.BigMulByBips(lastTx.GasFeeCap(), minRbfIncrease))
}
maxBlobFee := arbmath.BigMulByBips(currentBlobFee, config.MaxFeeBidMultipleBips)
maxBlobFee := arbmath.BigMulByUBips(currentBlobFee, config.MaxFeeBidMultipleBips)
if lastTx != nil && lastTx.BlobGasFeeCap() != nil {
maxBlobFee = arbmath.BigMax(maxBlobFee, arbmath.BigMulByBips(lastTx.BlobGasFeeCap(), minRbfIncrease))
}
Expand Down Expand Up @@ -1241,7 +1241,7 @@ type DataPosterConfig struct {
MinBlobTxTipCapGwei float64 `koanf:"min-blob-tx-tip-cap-gwei" reload:"hot"`
MaxTipCapGwei float64 `koanf:"max-tip-cap-gwei" reload:"hot"`
MaxBlobTxTipCapGwei float64 `koanf:"max-blob-tx-tip-cap-gwei" reload:"hot"`
MaxFeeBidMultipleBips arbmath.Bips `koanf:"max-fee-bid-multiple-bips" reload:"hot"`
MaxFeeBidMultipleBips arbmath.UBips `koanf:"max-fee-bid-multiple-bips" reload:"hot"`
NonceRbfSoftConfs uint64 `koanf:"nonce-rbf-soft-confs" reload:"hot"`
AllocateMempoolBalance bool `koanf:"allocate-mempool-balance" reload:"hot"`
UseDBStorage bool `koanf:"use-db-storage"`
Expand Down Expand Up @@ -1345,7 +1345,7 @@ var DefaultDataPosterConfig = DataPosterConfig{
MinBlobTxTipCapGwei: 1, // default geth minimum, and relays aren't likely to accept lower values given propagation time
MaxTipCapGwei: 1.2,
MaxBlobTxTipCapGwei: 1, // lower than normal because 4844 rbf is a minimum of a 2x
MaxFeeBidMultipleBips: arbmath.OneInBips * 10,
MaxFeeBidMultipleBips: arbmath.OneInUBips * 10,
NonceRbfSoftConfs: 1,
AllocateMempoolBalance: true,
UseDBStorage: true,
Expand Down Expand Up @@ -1380,7 +1380,7 @@ var TestDataPosterConfig = DataPosterConfig{
MinBlobTxTipCapGwei: 1,
MaxTipCapGwei: 5,
MaxBlobTxTipCapGwei: 1,
MaxFeeBidMultipleBips: arbmath.OneInBips * 10,
MaxFeeBidMultipleBips: arbmath.OneInUBips * 10,
NonceRbfSoftConfs: 1,
AllocateMempoolBalance: true,
UseDBStorage: false,
Expand Down
4 changes: 2 additions & 2 deletions arbnode/dataposter/dataposter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestFeeAndTipCaps_EnoughBalance_NoBacklog_NoUnconfirmed_BlobTx(t *testing.T
MinBlobTxTipCapGwei: 1,
MaxTipCapGwei: 5,
MaxBlobTxTipCapGwei: 10,
MaxFeeBidMultipleBips: arbmath.OneInBips * 10,
MaxFeeBidMultipleBips: arbmath.OneInUBips * 10,
AllocateMempoolBalance: true,

UrgencyGwei: 2.,
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestFeeAndTipCaps_RBF_RisingBlobFee_FallingBaseFee(t *testing.T) {
MinBlobTxTipCapGwei: 1,
MaxTipCapGwei: 5,
MaxBlobTxTipCapGwei: 10,
MaxFeeBidMultipleBips: arbmath.OneInBips * 10,
MaxFeeBidMultipleBips: arbmath.OneInUBips * 10,
AllocateMempoolBalance: true,

UrgencyGwei: 2.,
Expand Down
4 changes: 2 additions & 2 deletions arbnode/dataposter/dbstorage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ func (s *Storage) PruneAll(ctx context.Context) error {
if err != nil {
return fmt.Errorf("pruning all keys: %w", err)
}
until, err := strconv.Atoi(string(idx))
until, err := strconv.ParseUint(string(idx), 10, 64)
if err != nil {
return fmt.Errorf("converting last item index bytes to integer: %w", err)
}
return s.Prune(ctx, uint64(until+1))
return s.Prune(ctx, until+1)
}

func (s *Storage) Prune(ctx context.Context, until uint64) error {
Expand Down
17 changes: 13 additions & 4 deletions arbnode/dataposter/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,29 @@ func newRedisStorage(ctx context.Context, t *testing.T, encF storage.EncoderDeco

func valueOf(t *testing.T, i int) *storage.QueuedTransaction {
t.Helper()
// #nosec G115
meta, err := rlp.EncodeToBytes(storage.BatchPosterPosition{DelayedMessageCount: uint64(i)})
if err != nil {
t.Fatalf("Encoding batch poster position, error: %v", err)
}
return &storage.QueuedTransaction{
FullTx: types.NewTransaction(
// #nosec G115
uint64(i),
common.Address{},
big.NewInt(int64(i)),
// #nosec G115
uint64(i),
big.NewInt(int64(i)),
[]byte{byte(i)}),
Meta: meta,
DeprecatedData: types.DynamicFeeTx{
ChainID: big.NewInt(int64(i)),
Nonce: uint64(i),
GasTipCap: big.NewInt(int64(i)),
GasFeeCap: big.NewInt(int64(i)),
ChainID: big.NewInt(int64(i)),
// #nosec G115
Nonce: uint64(i),
GasTipCap: big.NewInt(int64(i)),
GasFeeCap: big.NewInt(int64(i)),
// #nosec G115
Gas: uint64(i),
Value: big.NewInt(int64(i)),
Data: []byte{byte(i % 8)},
Expand All @@ -113,6 +118,7 @@ func values(t *testing.T, from, to int) []*storage.QueuedTransaction {
func initStorage(ctx context.Context, t *testing.T, s QueueStorage) QueueStorage {
t.Helper()
for i := 0; i < 20; i++ {
// #nosec G115
if err := s.Put(ctx, uint64(i), nil, valueOf(t, i)); err != nil {
t.Fatalf("Error putting a key/value: %v", err)
}
Expand Down Expand Up @@ -153,6 +159,7 @@ func TestPruneAll(t *testing.T) {
s := newLevelDBStorage(t, func() storage.EncoderDecoderInterface { return &storage.EncoderDecoder{} })
ctx := context.Background()
for i := 0; i < 20; i++ {
// #nosec G115
if err := s.Put(ctx, uint64(i), nil, valueOf(t, i)); err != nil {
t.Fatalf("Error putting a key/value: %v", err)
}
Expand Down Expand Up @@ -236,6 +243,7 @@ func TestLast(t *testing.T) {
ctx := context.Background()
for i := 0; i < cnt; i++ {
val := valueOf(t, i)
// #nosec G115
if err := s.Put(ctx, uint64(i), nil, val); err != nil {
t.Fatalf("Error putting a key/value: %v", err)
}
Expand All @@ -255,6 +263,7 @@ func TestLast(t *testing.T) {
for i := 0; i < cnt-1; i++ {
prev := valueOf(t, i)
newVal := valueOf(t, cnt+i)
// #nosec G115
if err := s.Put(ctx, uint64(i), prev, newVal); err != nil {
t.Fatalf("Error putting a key/value: %v, prev: %v, new: %v", err, prev, newVal)
}
Expand Down
2 changes: 2 additions & 0 deletions arbnode/delayed_sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (d *DelayedSequencer) sequenceWithoutLockout(ctx context.Context, lastBlock
if currentNum < config.FinalizeDistance {
return nil
}
// #nosec G115
finalized = uint64(currentNum - config.FinalizeDistance)
}

Expand Down Expand Up @@ -189,6 +190,7 @@ func (d *DelayedSequencer) sequenceWithoutLockout(ctx context.Context, lastBlock
return fmt.Errorf("inbox reader at delayed message %v db accumulator %v doesn't match delayed bridge accumulator %v at L1 block %v", pos-1, lastDelayedAcc, delayedBridgeAcc, finalized)
}
for i, msg := range messages {
// #nosec G115
err = d.exec.SequenceDelayedMessage(msg, startPos+uint64(i))
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions arbnode/inbox_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ func (r *InboxReader) run(ctx context.Context, hadError bool) error {
} else {
from = arbmath.BigAddByUint(to, 1)
}
// #nosec G115
haveMessages := uint64(len(delayedMessages) + len(sequencerBatches))
if haveMessages <= (config.TargetMessagesRead / 2) {
blocksToFetch += (blocksToFetch + 4) / 5
Expand Down
17 changes: 11 additions & 6 deletions arbnode/transaction_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func (s *TransactionStreamer) reorg(batch ethdb.Batch, count arbutil.MessageInde
return err
}
config := s.config()
// #nosec G115
maxResequenceMsgCount := count + arbutil.MessageIndex(config.MaxReorgResequenceDepth)
if config.MaxReorgResequenceDepth >= 0 && maxResequenceMsgCount < targetMsgCount {
log.Error(
Expand Down Expand Up @@ -388,6 +389,7 @@ func (s *TransactionStreamer) reorg(batch ethdb.Batch, count arbutil.MessageInde
}

for i := 0; i < len(messagesResults); i++ {
// #nosec G115
pos := count + arbutil.MessageIndex(i)
err = s.storeResult(pos, *messagesResults[i], batch)
if err != nil {
Expand Down Expand Up @@ -680,7 +682,7 @@ func (s *TransactionStreamer) AddMessagesAndEndBatch(pos arbutil.MessageIndex, m
if err != nil {
return err
}
if dups == len(messages) {
if dups == uint64(len(messages)) {
return endBatch(batch)
}
// cant keep reorg lock when catching insertionMutex.
Expand Down Expand Up @@ -715,10 +717,10 @@ func (s *TransactionStreamer) countDuplicateMessages(
pos arbutil.MessageIndex,
messages []arbostypes.MessageWithMetadataAndBlockHash,
batch *ethdb.Batch,
) (int, bool, *arbostypes.MessageWithMetadata, error) {
curMsg := 0
) (uint64, bool, *arbostypes.MessageWithMetadata, error) {
var curMsg uint64
for {
if len(messages) == curMsg {
if uint64(len(messages)) == curMsg {
break
}
key := dbKey(messagePrefix, uint64(pos))
Expand Down Expand Up @@ -818,7 +820,7 @@ func (s *TransactionStreamer) addMessagesAndEndBatchImpl(messageStartPos arbutil
broadcastStartPos := arbutil.MessageIndex(s.broadcasterQueuedMessagesPos.Load())

if messagesAreConfirmed {
var duplicates int
var duplicates uint64
var err error
duplicates, confirmedReorg, oldMsg, err = s.countDuplicateMessages(messageStartPos, messages, &batch)
if err != nil {
Expand Down Expand Up @@ -857,7 +859,7 @@ func (s *TransactionStreamer) addMessagesAndEndBatchImpl(messageStartPos arbutil

var feedReorg bool
if !hasNewConfirmedMessages {
var duplicates int
var duplicates uint64
var err error
duplicates, feedReorg, oldMsg, err = s.countDuplicateMessages(messageStartPos, messages, nil)
if err != nil {
Expand Down Expand Up @@ -889,6 +891,7 @@ func (s *TransactionStreamer) addMessagesAndEndBatchImpl(messageStartPos arbutil

// Validate delayed message counts of remaining messages
for i, msg := range messages {
// #nosec G115
msgPos := messageStartPos + arbutil.MessageIndex(i)
diff := msg.MessageWithMeta.DelayedMessagesRead - lastDelayedRead
if diff != 0 && diff != 1 {
Expand Down Expand Up @@ -924,6 +927,7 @@ func (s *TransactionStreamer) addMessagesAndEndBatchImpl(messageStartPos arbutil
// Check if new messages were added at the end of cache, if they were, then dont remove those particular messages
if len(s.broadcasterQueuedMessages) > cacheClearLen {
s.broadcasterQueuedMessages = s.broadcasterQueuedMessages[cacheClearLen:]
// #nosec G115
s.broadcasterQueuedMessagesPos.Store(uint64(broadcastStartPos) + uint64(cacheClearLen))
} else {
s.broadcasterQueuedMessages = s.broadcasterQueuedMessages[:0]
Expand Down Expand Up @@ -1044,6 +1048,7 @@ func (s *TransactionStreamer) writeMessages(pos arbutil.MessageIndex, messages [
batch = s.db.NewBatch()
}
for i, msg := range messages {
// #nosec G115
err := s.writeMessage(pos+arbutil.MessageIndex(i), msg, batch)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions arbos/activate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestActivationDataFee(t *testing.T) {
rand.Seed(time.Now().UTC().UnixNano())
state, _ := arbosState.NewArbosMemoryBackedArbOSState()
pricer := state.Programs().DataPricer()
// #nosec G115
time := uint64(time.Now().Unix())

assert := func(cond bool) {
Expand Down
1 change: 1 addition & 0 deletions arbos/addressSet/addressSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (as *AddressSet) AllMembers(maxNumToReturn uint64) ([]common.Address, error
}
ret := make([]common.Address, size)
for i := range ret {
// #nosec G115
sba := as.backingStorage.OpenStorageBackedAddress(uint64(i + 1))
ret[i], err = sba.Get()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions arbos/addressTable/addressTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (atab *AddressTable) Decompress(buf []byte) (common.Address, uint64, error)
return common.Address{}, 0, err
}
if len(input) == 20 {
// #nosec G115
numBytesRead := uint64(rd.Size() - int64(rd.Len()))
return common.BytesToAddress(input), numBytesRead, nil
} else {
Expand Down
1 change: 1 addition & 0 deletions arbos/arbosState/initialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func checkAddressTable(arbState *ArbosState, addrTable []common.Address, t *test
Fail(t)
}
for i, addr := range addrTable {
// #nosec G115
res, exists, err := atab.LookupIndex(uint64(i))
Require(t, err)
if !exists {
Expand Down
4 changes: 2 additions & 2 deletions arbos/arbosState/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig,
if err != nil {
return common.Hash{}, err
}
for i := 0; addressReader.More(); i++ {
for i := uint64(0); addressReader.More(); i++ {
addr, err := addressReader.GetNext()
if err != nil {
return common.Hash{}, err
Expand All @@ -117,7 +117,7 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig,
if err != nil {
return common.Hash{}, err
}
if uint64(i) != slot {
if i != slot {
return common.Hash{}, errors.New("address table slot mismatch")
}
}
Expand Down
2 changes: 2 additions & 0 deletions arbos/l1pricing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ func _testL1PriceEquilibration(t *testing.T, initialL1BasefeeEstimate *big.Int,
evm.StateDB,
evm,
3,
// #nosec G115
uint64(10*(i+1)),
// #nosec G115
uint64(10*(i+1)+5),
bpAddr,
arbmath.BigMulByUint(equilibriumL1BasefeeEstimate, unitsToAdd),
Expand Down
1 change: 1 addition & 0 deletions arbos/merkleAccumulator/merkleAccumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (acc *MerkleAccumulator) GetPartials() ([]*common.Hash, error) {
}
partials := make([]*common.Hash, CalcNumPartials(size))
for i := range partials {
// #nosec G115
p, err := acc.getPartial(uint64(i))
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions arbos/programs/data_pricer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (p *DataPricer) UpdateModel(tempBytes uint32, time uint64) (*big.Int, error
}

exponent := arbmath.OneInBips * arbmath.Bips(demand) / arbmath.Bips(inertia)
multiplier := arbmath.ApproxExpBasisPoints(exponent, 12).Uint64()
costPerByte := arbmath.SaturatingUMul(uint64(minPrice), multiplier) / 10000
multiplier := arbmath.ApproxExpBasisPoints(exponent, 12)
costPerByte := arbmath.UintSaturatingMulByBips(uint64(minPrice), multiplier)
costInWei := arbmath.SaturatingUMul(costPerByte, uint64(tempBytes))
return arbmath.UintToBig(costInWei), nil
}
Loading

0 comments on commit 01e1c4a

Please sign in to comment.