Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 965443c

Browse files
Merge branch 'master' into lint-enable-gosec
Signed-off-by: Jonathan Oppenheimer <jonathan.oppenheimer@avalabs.org>
2 parents ff54299 + 33016b5 commit 965443c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+741
-2347
lines changed

.avalanche-golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ linters:
8282
- unparam
8383
- unused
8484
- usestdlibvars
85+
- usetesting
8586
- whitespace
8687
settings:
8788
depguard:
@@ -228,6 +229,14 @@ linters:
228229
# Mark all local variables as used.
229230
# default: true
230231
local-variables-are-used: false
232+
usetesting:
233+
os-create-temp: true # Disallow `os.CreateTemp("", ...)`
234+
os-mkdir-temp: true # Disallow `os.MkdirTemp()`
235+
os-setenv: true # Disallow `os.Setenv()`
236+
os-temp-dir: true # Disallow `os.TempDir()`
237+
os-chdir: true # Disallow `os.Chdir()`
238+
context-background: true # Disallow `context.Background()`
239+
context-todo: true # Disallow `context.TODO()`
231240
exclusions:
232241
generated: lax
233242
presets:

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jobs:
3636
cache-dependency-path: |
3737
go.sum
3838
tools/go.sum
39-
tools/legacy-golangci-lint.sum
4039
- name: change avalanchego dep
4140
if: ${{ github.event_name == 'workflow_dispatch' }}
4241
run: |

.golangci.yml

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,77 @@
1-
# This file configures github.com/golangci/golangci-lint.
2-
1+
version: "2"
32
run:
4-
timeout: 10m
53
tests: true
64

75
linters:
8-
disable-all: true
6+
default: none
97
enable:
10-
- goimports
11-
- gosimple
8+
- bidichk
9+
- copyloopvar
10+
- durationcheck
11+
- gocheckcompilerdirectives
1212
- govet
1313
- ineffassign
14+
- mirror
1415
- misspell
16+
- reassign
17+
# - revive # only certain checks enabled
18+
- staticcheck
1519
- unconvert
16-
- typecheck
1720
- unused
18-
# - staticcheck
19-
- bidichk
20-
- durationcheck
21-
- copyloopvar
2221
- whitespace
23-
# - revive # only certain checks enabled
24-
- durationcheck
25-
- gocheckcompilerdirectives
26-
- reassign
27-
- mirror
28-
- tenv
22+
settings:
23+
goconst:
24+
min-len: 3 # minimum length of string constant
25+
min-occurrences: 6 # minimum number of occurrences
26+
staticcheck:
27+
checks:
28+
- all
29+
30+
# There's a lot of legacy code that triggers these warnings after upgrading golangci-lint.
31+
# These checks are removed.
32+
- -QF1001 # Apply De Morgan’s law
33+
- -QF1002 # Convert an untagged switch comparing the same variable into a “tagged” switch
34+
- -QF1003 # Convert if / else-if chains comparing the same variable into a tagged switch
35+
- -QF1006 # Lift if + break into loop condition
36+
- -QF1008 # Omit embedded fields from selector expression
37+
- -QF1010 # Convert slice of bytes to string when printing it
38+
- -SA1019 # Use of deprecated identifiers: triggers when you import or use something marked deprecated.
39+
- -SA4009 # A function argument is overwritten before its first use.
40+
- -SA9003 # Empty body in an if or else branch.
41+
- -ST1003 # Poorly chosen identifier.
42+
- -ST1008 # A function’s error value should be its last return value.
43+
- -ST1016 # Use consistent method receiver names (e.g. avoid mixing `s *S`, `s S`, `t *T` in same type).
2944

30-
linters-settings:
31-
gofmt:
32-
simplify: true
33-
goconst:
34-
min-len: 3 # minimum length of string constant
35-
min-occurrences: 6 # minimum number of occurrences
36-
ignore-tests: true
45+
exclusions:
46+
generated: lax
47+
presets:
48+
- comments
49+
- common-false-positives
50+
- legacy
51+
- std-error-handling
52+
rules:
53+
- linters:
54+
- unused
55+
# Exclude unused geth symbols from ethclient/ethclient.go to simplify upgrading Geth to a newer version.
56+
path: ethclient\/ethclient\.go
57+
text: (type `rpcProgress`|func `\(\*rpcProgress\)\.toSyncProgress`) is unused
58+
- linters:
59+
- goconst
60+
path: (.+)_test\.go
61+
paths:
62+
- third_party$
63+
- builtin$
64+
- examples$
3765

38-
issues:
39-
exclude-rules:
40-
# Exclude unused geth symbols from ethclient/ethclient.go to simplify upgrading Geth to a newer version.
41-
- path: "ethclient\\/ethclient\\.go"
42-
text: "(type `rpcProgress`|func `\\(\\*rpcProgress\\)\\.toSyncProgress`) is unused"
43-
linters:
44-
- unused
66+
formatters:
67+
enable:
68+
- goimports
69+
settings:
70+
gofmt:
71+
simplify: true
72+
exclusions:
73+
generated: lax
74+
paths:
75+
- third_party$
76+
- builtin$
77+
- examples$

RELEASES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
- Add minimum block building delays to conform the block builder to ACP-226 requirements.
1313
- Add minimum delay verification.
1414
- Update go version to 1.24.9
15+
- Updated gas price estimation to use median of transactions in the last 20 seconds/40 blocks instead of estimation with block gas cost:
16+
- Changed default percentile from 60 to 40
17+
- This impacts `eth_suggestGasPrice` and `eth_suggestGasTipCap` , `eth_suggestPriceOptions`, `eth_maxPriorityFeePerGas`, `eth_gasPrice` APIs
18+
1519

1620
## [v0.15.3](https://github.com/ava-labs/coreth/releases/tag/v0.15.3)
1721

Taskfile.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ tasks:
6565
- task: check-clean-branch
6666
- cmd: cd tools && go mod tidy
6767
- task: check-clean-branch
68-
- cmd: cd tools && go mod tidy -modfile=legacy-golangci-lint.mod
69-
- task: check-clean-branch
7068

7169
coverage:
7270
desc: Display test coverage statistics from coverage.out file
@@ -113,6 +111,12 @@ tasks:
113111
- task: check-generate-codec
114112
- task: check-generate-mocks
115113
- task: check-generate-rlp
114+
115+
lint-fix:
116+
desc: Run golangci-lint with auto-fix where possible
117+
# TODO(alarso16): Create a script to run the avalanchego linter as well.
118+
# See https://github.com/ava-labs/coreth/issues/1374
119+
cmd: go tool -modfile=tools/go.mod golangci-lint run --config .golangci.yml --fix
116120

117121
shellcheck:
118122
desc: Run shellcheck static analysis on all shell scripts with version management

cmd/simulator/load/funder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func DistributeFunds(ctx context.Context, client *ethclient.Client, keys []*key.
7373
if err != nil {
7474
return nil, fmt.Errorf("failed to fetch chainID: %w", err)
7575
}
76-
gasFeeCap, err := client.EstimateBaseFee(ctx)
76+
baseFee, err := client.EstimateBaseFee(ctx)
7777
if err != nil {
7878
return nil, fmt.Errorf("failed to fetch estimated base fee: %w", err)
7979
}
@@ -91,7 +91,7 @@ func DistributeFunds(ctx context.Context, client *ethclient.Client, keys []*key.
9191
ChainID: chainID,
9292
Nonce: nonce,
9393
GasTipCap: gasTipCap,
94-
GasFeeCap: gasFeeCap,
94+
GasFeeCap: new(big.Int).Add(baseFee, gasTipCap),
9595
Gas: ethparams.TxGas,
9696
To: &needFundsAddrs[i],
9797
Data: nil,

eth/api_backend.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"github.com/ava-labs/coreth/eth/tracers"
4242
"github.com/ava-labs/coreth/internal/ethapi"
4343
"github.com/ava-labs/coreth/params"
44-
"github.com/ava-labs/coreth/plugin/evm/customheader"
4544
"github.com/ava-labs/coreth/rpc"
4645
"github.com/ava-labs/libevm/accounts"
4746
"github.com/ava-labs/libevm/common"
@@ -527,11 +526,6 @@ func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Blo
527526
return b.eth.stateAtTransaction(ctx, block, txIndex, reexec)
528527
}
529528

530-
func (b *EthAPIBackend) MinRequiredTip(ctx context.Context, header *types.Header) (*big.Int, error) {
531-
config := params.GetExtra(b.ChainConfig())
532-
return customheader.EstimateRequiredTip(config, header)
533-
}
534-
535529
func (b *EthAPIBackend) isLatestAndAllowed(number rpc.BlockNumber) bool {
536530
return number.IsLatest() && b.IsAllowUnfinalizedQueries()
537531
}

eth/ethconfig/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343
// DefaultFullGPOConfig contains default gasprice oracle settings for full node.
4444
var DefaultFullGPOConfig = gasprice.Config{
4545
Blocks: 40,
46-
Percentile: 60,
46+
Percentile: 40,
4747
MaxLookbackSeconds: gasprice.DefaultMaxLookbackSeconds,
4848
MaxCallBlockHistory: gasprice.DefaultMaxCallBlockHistory,
4949
MaxBlockHistory: gasprice.DefaultMaxBlockHistory,

eth/gasprice/fee_info_provider.go

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"math/big"
3333

3434
"github.com/ava-labs/coreth/core"
35-
"github.com/ava-labs/coreth/plugin/evm/customtypes"
3635
"github.com/ava-labs/coreth/rpc"
3736
"github.com/ava-labs/libevm/core/types"
3837
lru "github.com/hashicorp/golang-lru"
@@ -44,26 +43,23 @@ import (
4443
const feeCacheExtraSlots = 5
4544

4645
type feeInfoProvider struct {
47-
cache *lru.Cache
48-
backend OracleBackend
49-
// [minGasUsed] ensures we don't recommend users pay non-zero tips when other
50-
// users are paying a tip to unnecessarily expedite block production.
51-
minGasUsed uint64
46+
cache *lru.Cache
47+
backend OracleBackend
5248
newHeaderAdded func() // callback used in tests
5349
}
5450

5551
// feeInfo is the type of data stored in feeInfoProvider's cache.
5652
type feeInfo struct {
57-
baseFee, tip *big.Int // baseFee and min. suggested tip for tx to be included in the block
58-
timestamp uint64 // timestamp of the block header
53+
baseFee *big.Int // base fee of the block
54+
tips []*big.Int // tips for txs to be included in the block
55+
timestamp uint64 // timestamp of the block header
5956
}
6057

6158
// newFeeInfoProvider returns a bounded buffer with [size] slots to
6259
// store [*feeInfo] for the most recently accepted blocks.
63-
func newFeeInfoProvider(backend OracleBackend, minGasUsed uint64, size int) (*feeInfoProvider, error) {
60+
func newFeeInfoProvider(backend OracleBackend, size int) (*feeInfoProvider, error) {
6461
fc := &feeInfoProvider{
65-
backend: backend,
66-
minGasUsed: minGasUsed,
62+
backend: backend,
6763
}
6864
if size == 0 {
6965
// if size is zero, we return early as there is no
@@ -79,7 +75,7 @@ func newFeeInfoProvider(backend OracleBackend, minGasUsed uint64, size int) (*fe
7975
backend.SubscribeChainAcceptedEvent(acceptedEvent)
8076
go func() {
8177
for ev := range acceptedEvent {
82-
fc.addHeader(context.Background(), ev.Block.Header())
78+
fc.addHeader(context.Background(), ev.Block.Header(), ev.Block.Transactions())
8379
if fc.newHeaderAdded != nil {
8480
fc.newHeaderAdded()
8581
}
@@ -89,35 +85,23 @@ func newFeeInfoProvider(backend OracleBackend, minGasUsed uint64, size int) (*fe
8985
}
9086

9187
// addHeader processes header into a feeInfo struct and caches the result.
92-
func (f *feeInfoProvider) addHeader(ctx context.Context, header *types.Header) (*feeInfo, error) {
88+
func (f *feeInfoProvider) addHeader(ctx context.Context, header *types.Header, txs []*types.Transaction) (*feeInfo, error) {
89+
tips := make([]*big.Int, 0, len(txs))
90+
for _, tx := range txs {
91+
tip, err := tx.EffectiveGasTip(header.BaseFee)
92+
if err != nil {
93+
return nil, err
94+
}
95+
tips = append(tips, tip)
96+
}
97+
9398
feeInfo := &feeInfo{
9499
timestamp: header.Time,
95100
baseFee: header.BaseFee,
101+
tips: tips,
96102
}
97-
98-
totalGasUsed := new(big.Int).SetUint64(header.GasUsed)
99-
if used := customtypes.GetHeaderExtra(header).ExtDataGasUsed; used != nil {
100-
totalGasUsed.Add(totalGasUsed, used)
101-
}
102-
minGasUsed := new(big.Int).SetUint64(f.minGasUsed)
103-
104-
// Don't bias the estimate with blocks containing a limited number of transactions paying to
105-
// expedite block production.
106-
var err error
107-
if minGasUsed.Cmp(totalGasUsed) <= 0 {
108-
// Compute minimum required tip to be included in previous block
109-
//
110-
// NOTE: Using this approach, we will never recommend that the caller
111-
// provides a non-zero tip unless some block is produced faster than the
112-
// target rate (which could only occur if some set of callers manually override the
113-
// suggested tip). In the future, we may wish to start suggesting a non-zero
114-
// tip when most blocks are full otherwise callers may observe an unexpected
115-
// delay in transaction inclusion.
116-
feeInfo.tip, err = f.backend.MinRequiredTip(ctx, header)
117-
}
118-
119103
f.cache.Add(header.Number.Uint64(), feeInfo)
120-
return feeInfo, err
104+
return feeInfo, nil
121105
}
122106

123107
// get returns the feeInfo for block with [number] if present in the cache
@@ -141,11 +125,11 @@ func (f *feeInfoProvider) populateCache(size int) error {
141125
}
142126

143127
for i := lowerBlockNumber; i <= lastAccepted; i++ {
144-
header, err := f.backend.HeaderByNumber(context.Background(), rpc.BlockNumber(i))
128+
block, err := f.backend.BlockByNumber(context.Background(), rpc.BlockNumber(i))
145129
if err != nil {
146130
return err
147131
}
148-
_, err = f.addHeader(context.Background(), header)
132+
_, err = f.addHeader(context.Background(), block.Header(), block.Transactions())
149133
if err != nil {
150134
return err
151135
}

eth/gasprice/fee_info_provider_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44
package gasprice
55

66
import (
7-
"context"
87
"math/big"
98
"sync"
109
"testing"
1110

12-
"github.com/ava-labs/libevm/common"
1311
"github.com/ava-labs/libevm/core/types"
1412
"github.com/stretchr/testify/require"
1513

1614
"github.com/ava-labs/coreth/core"
17-
"github.com/ava-labs/coreth/params"
1815
)
1916

2017
func TestFeeInfoProvider(t *testing.T) {
21-
backend := newTestBackend(t, params.TestChainConfig, 2, common.Big0, testGenBlock(t, 55, 80))
22-
f, err := newFeeInfoProvider(backend, 1, 2)
18+
backend := newTestBackend(t, 2, testGenBlock(t, 55, 80))
19+
f, err := newFeeInfoProvider(backend, 2)
2320
require.NoError(t, err)
2421

2522
// check that accepted event was subscribed
@@ -46,15 +43,15 @@ func TestFeeInfoProvider(t *testing.T) {
4643
func TestFeeInfoProviderCacheSize(t *testing.T) {
4744
size := 5
4845
overflow := 3
49-
backend := newTestBackend(t, params.TestChainConfig, 0, common.Big0, testGenBlock(t, 55, 370))
50-
f, err := newFeeInfoProvider(backend, 1, size)
46+
backend := newTestBackend(t, 0, testGenBlock(t, 55, 370))
47+
f, err := newFeeInfoProvider(backend, size)
5148
require.NoError(t, err)
5249

5350
// add [overflow] more elements than what will fit in the cache
5451
// to test eviction behavior.
5552
for i := 0; i < size+feeCacheExtraSlots+overflow; i++ {
5653
header := &types.Header{Number: big.NewInt(int64(i))}
57-
_, err := f.addHeader(context.Background(), header)
54+
_, err := f.addHeader(t.Context(), header, []*types.Transaction{})
5855
require.NoError(t, err)
5956
}
6057

0 commit comments

Comments
 (0)