bee icon indicating copy to clipboard operation
bee copied to clipboard

chore: bump go version to 1.22 (#4590)

Open martinconic opened this issue 1 year ago • 4 comments

Checklist

  • [x] I have read the coding guide.
  • [ ] My change requires a documentation update, and I have done it.
  • [ ] I have added tests to cover my changes.
  • [ ] I have filled out the description and linked the related issues.

Description

Upgrading Go version to 1.22

martinconic avatar May 20 '24 14:05 martinconic

There might be 2 solutions here: https://github.com/github/codeql/issues/15647

  1. Add toolchain
  2. Add a more specific Go version 1.22.0 or 1.22.1

martinconic avatar May 20 '24 16:05 martinconic

The biggest change in go 1.22 is the variable scoping in for loops. While the code should work as expected, whenever the variable is deliberately not scoped inside the iteration, should be adjusted, as with go 1.22 that variable will have the scope in iteration. I do not know of such case in the bee codebase, but it should be good to validate by other reviewers, as well. Have in mind that for loop variable scoping in 1.22 have a lot of strange consequences that may not be obvious and are very indirect.

It appears that CodeQL analyzer is a blocker for this change https://github.com/ethersphere/bee/actions/runs/9160600677/job/25183926395?pr=4687#step:4:103 as it does not support go 1.22, which is unfortunate.

There is tooling support we should look into. https://tip.golang.org/wiki/LoopvarExperiment After running go build -gcflags=all=-d=loopvar=2 ./cmd/bee, this is what I got:

# runtime
/usr/local/go/src/runtime/proc.go:1907:7: loop variable freem now per-iteration, stack-allocated
/usr/local/go/src/runtime/proc.go:3269:7: loop variable enum now per-iteration, stack-allocated
/usr/local/go/src/runtime/mgcmark.go:810:6: loop variable d now per-iteration, stack-allocated
/usr/local/go/src/runtime/traceback.go:633:7: loop variable iu now per-iteration, stack-allocated
/usr/local/go/src/runtime/traceback.go:990:7: loop variable iu now per-iteration, stack-allocated
# vendor/golang.org/x/net/dns/dnsmessage
/usr/local/go/src/vendor/golang.org/x/net/dns/dnsmessage/message.go:1161:10: loop variable q now per-iteration, stack-allocated
/usr/local/go/src/vendor/golang.org/x/net/dns/dnsmessage/message.go:1168:10: loop variable a now per-iteration, stack-allocated
/usr/local/go/src/vendor/golang.org/x/net/dns/dnsmessage/message.go:1175:10: loop variable a now per-iteration, stack-allocated
/usr/local/go/src/vendor/golang.org/x/net/dns/dnsmessage/message.go:1182:10: loop variable a now per-iteration, stack-allocated
/usr/local/go/src/vendor/golang.org/x/net/dns/dnsmessage/message.go:2633:9: loop variable o now per-iteration, stack-allocated
# runtime/pprof
/usr/local/go/src/runtime/pprof/pprof.go:386:9: loop variable r now per-iteration, heap-allocated
/usr/local/go/src/runtime/pprof/proto.go:363:6: loop variable e now per-iteration, stack-allocated
/usr/local/go/src/runtime/pprof/proto.go:612:9: loop variable frame now per-iteration, stack-allocated
/usr/local/go/src/runtime/pprof/protomem.go:29:9: loop variable r now per-iteration, heap-allocated
# github.com/ethereum/go-ethereum/rlp
../../go/pkg/mod/github.com/ethereum/[email protected]/rlp/encbuffer.go:68:9: loop variable head now per-iteration, stack-allocated
../../go/pkg/mod/github.com/ethereum/[email protected]/rlp/encbuffer.go:84:9: loop variable head now per-iteration, stack-allocated
# net
/usr/local/go/src/net/cgo_unix.go:74:9: loop variable addr now per-iteration, stack-allocated
/usr/local/go/src/net/dnsclient_unix.go:567:9: loop variable ip now per-iteration, stack-allocated
/usr/local/go/src/net/interface_linux.go:27:9: loop variable m now per-iteration, stack-allocated
/usr/local/go/src/net/interface_linux.go:150:9: loop variable m now per-iteration, stack-allocated
/usr/local/go/src/net/sockopt_posix.go:28:9: loop variable ifi now per-iteration, heap-allocated
/usr/local/go/src/net/interface.go:147:9: loop variable ifi now per-iteration, heap-allocated (loop inlined into /usr/local/go/src/net/interface.go:139)
/usr/local/go/src/net/interface.go:147:9: loop variable ifi now per-iteration, heap-allocated (loop inlined into /usr/local/go/src/net/interface_linux.go:159)
# github.com/ethereum/go-ethereum/p2p/netutil
../../go/pkg/mod/github.com/ethereum/[email protected]/p2p/netutil/net.go:93:9: loop variable net now per-iteration, stack-allocated
../../go/pkg/mod/github.com/ethereum/[email protected]/p2p/netutil/net.go:130:9: loop variable net now per-iteration, stack-allocated
../../go/pkg/mod/github.com/ethereum/[email protected]/p2p/netutil/net.go:130:9: loop variable net now per-iteration, stack-allocated (loop inlined into ../../go/pkg/mod/github.com/ethereum/[email protected]/p2p/netutil/net.go:144)
../../go/pkg/mod/github.com/ethereum/[email protected]/p2p/netutil/net.go:130:9: loop variable net now per-iteration, stack-allocated (loop inlined into ../../go/pkg/mod/github.com/ethereum/[email protected]/p2p/netutil/net.go:146)
../../go/pkg/mod/github.com/ethereum/[email protected]/p2p/netutil/net.go:130:9: loop variable net now per-iteration, stack-allocated (loop inlined into ../../go/pkg/mod/github.com/ethereum/[email protected]/p2p/netutil/net.go:156)
../../go/pkg/mod/github.com/ethereum/[email protected]/p2p/netutil/net.go:130:9: loop variable net now per-iteration, stack-allocated (loop inlined into ../../go/pkg/mod/github.com/ethereum/[email protected]/p2p/netutil/net.go:158)
# crypto/x509
/usr/local/go/src/crypto/x509/x509.go:1208:11: loop variable name now per-iteration, stack-allocated
/usr/local/go/src/crypto/x509/x509.go:1220:11: loop variable ipNet now per-iteration, stack-allocated
/usr/local/go/src/crypto/x509/x509.go:1228:11: loop variable email now per-iteration, stack-allocated
/usr/local/go/src/crypto/x509/x509.go:1240:11: loop variable uriDomain now per-iteration, stack-allocated
/usr/local/go/src/crypto/x509/verify.go:856:9: loop variable ext now per-iteration, heap-allocated
/usr/local/go/src/crypto/x509/verify.go:871:10: loop variable ext now per-iteration, heap-allocated
# github.com/casbin/casbin/v2/rbac/default-role-manager
../../go/pkg/mod/github.com/casbin/casbin/[email protected]/rbac/default-role-manager/role_manager.go:103:10: loop variable domain now per-iteration, stack-allocated
../../go/pkg/mod/github.com/casbin/casbin/[email protected]/rbac/default-role-manager/role_manager.go:195:10: loop variable domain now per-iteration, stack-allocated
# github.com/gogo/protobuf/proto
../../go/pkg/mod/github.com/gogo/[email protected]/proto/extensions_gogo.go:163:9: loop variable e now per-iteration, stack-allocated
../../go/pkg/mod/github.com/gogo/[email protected]/proto/extensions_gogo.go:179:9: loop variable e now per-iteration, stack-allocated
# github.com/ethereum/go-ethereum/accounts/abi
../../go/pkg/mod/github.com/ethereum/[email protected]/accounts/abi/abi.go:229:9: loop variable errABI now per-iteration, heap-allocated
# github.com/casbin/casbin/v2/model
../../go/pkg/mod/github.com/casbin/casbin/[email protected]/model/model.go:306:13: loop variable assertion now per-iteration, stack-allocated
# crypto/tls
/usr/local/go/src/crypto/tls/common.go:1146:9: loop variable cert now per-iteration, heap-allocated
/usr/local/go/src/crypto/tls/ticket.go:121:10: loop variable extra now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/ticket.go:143:10: loop variable chain now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/ticket.go:150:12: loop variable cert now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/ticket.go:374:9: loop variable key now per-iteration, heap-allocated
/usr/local/go/src/crypto/tls/handshake_messages.go:195:12: loop variable proto now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/handshake_messages.go:233:12: loop variable ks now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/handshake_messages.go:268:12: loop variable psk now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/handshake_messages.go:276:12: loop variable binder now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/handshake_messages.go:355:11: loop variable binder now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/handshake_messages.go:693:12: loop variable sct now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/handshake_messages.go:1186:14: loop variable ca now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/handshake_messages.go:1389:7: loop variable i now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/handshake_messages.go:1389:10: loop variable cert now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/handshake_messages.go:1411:15: loop variable sct now per-iteration, stack-allocated
/usr/local/go/src/crypto/tls/handshake_client.go:1099:9: loop variable chain now per-iteration, heap-allocated
/usr/local/go/src/crypto/tls/handshake_server_tls13.go:186:10: loop variable ks now per-iteration, heap-allocated
# internal/profile
/usr/local/go/src/internal/profile/encode.go:251:10: loop variable l now per-iteration, stack-allocated
/usr/local/go/src/internal/profile/encode.go:285:9: loop variable i now per-iteration, stack-allocated
# go.opencensus.io/trace/tracestate
../../go/pkg/mod/[email protected]/trace/tracestate/tracestate.go:67:13: loop variable entry now per-iteration, heap-allocated (loop inlined into ../../go/pkg/mod/[email protected]/trace/tracestate/tracestate.go:78)
../../go/pkg/mod/[email protected]/trace/tracestate/tracestate.go:105:9: loop variable entry now per-iteration, heap-allocated (loop inlined into ../../go/pkg/mod/[email protected]/trace/tracestate/tracestate.go:128)
# google.golang.org/protobuf/internal/impl
../../go/pkg/mod/google.golang.org/[email protected]/internal/impl/message_reflect.go:238:10: loop variable x now per-iteration, stack-allocated
../../go/pkg/mod/google.golang.org/[email protected]/internal/impl/encode.go:156:9: loop variable x now per-iteration, stack-allocated
../../go/pkg/mod/google.golang.org/[email protected]/internal/impl/encode.go:177:10: loop variable x now per-iteration, stack-allocated
../../go/pkg/mod/google.golang.org/[email protected]/internal/impl/merge.go:60:12: loop variable sx now per-iteration, stack-allocated
../../go/pkg/mod/google.golang.org/[email protected]/internal/impl/checkinit.go:69:9: loop variable x now per-iteration, stack-allocated
# gopkg.in/yaml.v2
../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:81:6: loop variable i now per-iteration, stack-allocated
../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:1265:6: loop variable i now per-iteration, stack-allocated
../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:1322:6: loop variable i now per-iteration, stack-allocated
../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:1378:6: loop variable i now per-iteration, stack-allocated
../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:1435:6: loop variable i now per-iteration, stack-allocated
../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:1605:6: loop variable i now per-iteration, stack-allocated
../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:1645:6: loop variable i now per-iteration, stack-allocated
../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:81:6: loop variable i now per-iteration, stack-allocated (loop inlined into ../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:1227)
../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:81:6: loop variable i now per-iteration, stack-allocated (loop inlined into ../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:1237)
../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:81:6: loop variable i now per-iteration, stack-allocated (loop inlined into ../../go/pkg/mod/gopkg.in/[email protected]/emitterc.go:1251)
# golang.org/x/text/language
../../go/pkg/mod/golang.org/x/[email protected]/language/coverage.go:126:10: loop variable t now per-iteration, stack-allocated
../../go/pkg/mod/golang.org/x/[email protected]/language/match.go:382:9: loop variable tag now per-iteration, stack-allocated
../../go/pkg/mod/golang.org/x/[email protected]/language/match.go:391:9: loop variable tag now per-iteration, stack-allocated
../../go/pkg/mod/golang.org/x/[email protected]/language/match.go:455:9: loop variable ww now per-iteration, stack-allocated
../../go/pkg/mod/golang.org/x/[email protected]/language/match.go:495:10: loop variable t now per-iteration, stack-allocated
# encoding/xml
/usr/local/go/src/encoding/xml/typeinfo.go:81:13: loop variable finfo now per-iteration, stack-allocated
# go.opencensus.io/trace
../../go/pkg/mod/[email protected]/trace/spanstore.go:130:10: loop variable b now per-iteration, stack-allocated
# resenje.org/web
../../go/pkg/mod/resenje.org/[email protected]/auth.go:127:10: loop variable network now per-iteration, stack-allocated
../../go/pkg/mod/resenje.org/[email protected]/auth.go:136:10: loop variable network now per-iteration, stack-allocated
# github.com/uber/jaeger-client-go/utils
../../go/pkg/mod/github.com/uber/[email protected]+incompatible/utils/localip.go:63:9: loop variable iface now per-iteration, stack-allocated
# github.com/koron/go-ssdp/internal/multicast
../../go/pkg/mod/github.com/koron/[email protected]/internal/multicast/interface.go:30:9: loop variable ifi now per-iteration, stack-allocated
../../go/pkg/mod/github.com/koron/[email protected]/internal/multicast/multicast.go:70:9: loop variable ifi now per-iteration, stack-allocated
../../go/pkg/mod/github.com/koron/[email protected]/internal/multicast/multicast.go:116:9: loop variable ifi now per-iteration, heap-allocated
# github.com/google/gopacket/routing
../../go/pkg/mod/github.com/google/[email protected]/routing/routing.go:166:9: loop variable m now per-iteration, stack-allocated
../../go/pkg/mod/github.com/google/[email protected]/routing/routing.go:217:9: loop variable iface now per-iteration, stack-allocated
# github.com/huin/goupnp
../../go/pkg/mod/github.com/huin/[email protected]/network.go:50:9: loop variable iface now per-iteration, stack-allocated
# github.com/libp2p/go-netroute
../../go/pkg/mod/github.com/libp2p/[email protected]/netroute_linux.go:52:9: loop variable m now per-iteration, stack-allocated
../../go/pkg/mod/github.com/libp2p/[email protected]/netroute_linux.go:103:9: loop variable iface now per-iteration, stack-allocated
# github.com/miekg/dns
../../go/pkg/mod/github.com/miekg/[email protected]/types.go:1513:9: loop variable p now per-iteration, stack-allocated
../../go/pkg/mod/github.com/miekg/[email protected]/msg.go:797:9: loop variable r now per-iteration, stack-allocated
../../go/pkg/mod/github.com/miekg/[email protected]/msg.go:919:10: loop variable r now per-iteration, stack-allocated
../../go/pkg/mod/github.com/miekg/[email protected]/msg.go:983:9: loop variable r now per-iteration, stack-allocated
../../go/pkg/mod/github.com/miekg/[email protected]/ztypes.go:308:9: loop variable x now per-iteration, stack-allocated
../../go/pkg/mod/github.com/miekg/[email protected]/ztypes.go:841:9: loop variable e now per-iteration, stack-allocated
../../go/pkg/mod/github.com/miekg/[email protected]/msg_truncate.go:66:9: loop variable r now per-iteration, stack-allocated
# github.com/uber/jaeger-client-go
../../go/pkg/mod/github.com/uber/[email protected]+incompatible/span.go:349:11: loop variable ld now per-iteration, stack-allocated
../../go/pkg/mod/github.com/uber/[email protected]+incompatible/jaeger_thrift_span.go:70:9: loop variable tag now per-iteration, stack-allocated
# github.com/libp2p/go-libp2p/p2p/net/upgrader
../../go/pkg/mod/github.com/libp2p/[email protected]/p2p/net/upgrader/upgrader.go:247:9: loop variable m now per-iteration, heap-allocated (loop inlined into ../../go/pkg/mod/github.com/libp2p/[email protected]/p2p/net/upgrader/upgrader.go:240)
../../go/pkg/mod/github.com/libp2p/[email protected]/p2p/net/upgrader/upgrader.go:247:9: loop variable m now per-iteration, heap-allocated (loop inlined into ../../go/pkg/mod/github.com/libp2p/[email protected]/p2p/net/upgrader/upgrader.go:259)
# github.com/prometheus/client_golang/prometheus
../../go/pkg/mod/github.com/prometheus/[email protected]/prometheus/metric.go:181:10: loop variable e now per-iteration, stack-allocated
../../go/pkg/mod/github.com/prometheus/[email protected]/prometheus/expvar_collector.go:44:12: loop variable desc now per-iteration, stack-allocated
../../go/pkg/mod/github.com/prometheus/[email protected]/prometheus/go_collector_latest.go:198:9: loop variable d now per-iteration, stack-allocated
# github.com/klauspost/compress/huff0
../../go/pkg/mod/github.com/klauspost/[email protected]/huff0/compress.go:538:9: loop variable v now per-iteration, stack-allocated
../../go/pkg/mod/github.com/klauspost/[email protected]/huff0/compress.go:553:9: loop variable v now per-iteration, stack-allocated
# github.com/libp2p/go-nat
../../go/pkg/mod/github.com/libp2p/[email protected]/natpmp.go:69:9: loop variable iface now per-iteration, stack-allocated
../../go/pkg/mod/github.com/libp2p/[email protected]/upnp.go:30:10: loop variable dev now per-iteration, stack-allocated
../../go/pkg/mod/github.com/libp2p/[email protected]/upnp.go:87:10: loop variable dev now per-iteration, stack-allocated
../../go/pkg/mod/github.com/libp2p/[email protected]/upnp.go:306:9: loop variable iface now per-iteration, stack-allocated
# github.com/prometheus/statsd_exporter/pkg/mapper
../../go/pkg/mod/github.com/prometheus/[email protected]/pkg/mapper/mapper.go:334:9: loop variable mapping now per-iteration, heap-allocated
# github.com/libp2p/go-libp2p/p2p/host/eventbus
../../go/pkg/mod/github.com/libp2p/[email protected]/p2p/host/eventbus/basic.go:245:6: loop variable i now per-iteration, stack-allocated
# github.com/libp2p/go-libp2p/p2p/host/resource-manager
../../go/pkg/mod/github.com/libp2p/[email protected]/p2p/host/resource-manager/limit_defaults.go:428:9: loop variable l now per-iteration, stack-allocated
../../go/pkg/mod/github.com/libp2p/[email protected]/p2p/host/resource-manager/limit_defaults.go:500:9: loop variable l now per-iteration, stack-allocated
# github.com/libp2p/go-libp2p/p2p/net/swarm
../../go/pkg/mod/github.com/libp2p/[email protected]/p2p/net/swarm/swarm_dial.go:435:9: loop variable addr now per-iteration, stack-allocated
# github.com/klauspost/compress/zstd
../../go/pkg/mod/github.com/klauspost/[email protected]/zstd/fse_decoder.go:277:9: loop variable v now per-iteration, stack-allocated
# github.com/ethereum/go-ethereum/core/types
../../go/pkg/mod/github.com/ethereum/[email protected]/core/types/bloom9.go:110:11: loop variable b now per-iteration, heap-allocated
../../go/pkg/mod/github.com/ethereum/[email protected]/core/types/bloom9.go:124:10: loop variable b now per-iteration, heap-allocated
../../go/pkg/mod/github.com/ethereum/[email protected]/core/types/gen_log_rlp.go:13:9: loop variable _tmp2 now per-iteration, stack-allocated
# github.com/quic-go/quic-go
../../go/pkg/mod/github.com/quic-go/[email protected]/server.go:511:10: loop variable p now per-iteration, stack-allocated
# github.com/ethereum/go-ethereum/accounts
../../go/pkg/mod/github.com/ethereum/[email protected]/accounts/manager.go:249:9: loop variable wallet now per-iteration, stack-allocated
../../go/pkg/mod/github.com/ethereum/[email protected]/accounts/manager.go:263:9: loop variable wallet now per-iteration, stack-allocated
# github.com/ethereum/go-ethereum/signer/core/apitypes
../../go/pkg/mod/github.com/ethereum/[email protected]/signer/core/apitypes/types.go:629:9: loop variable field now per-iteration, stack-allocated
../../go/pkg/mod/github.com/ethereum/[email protected]/signer/core/apitypes/types.go:713:10: loop variable typeObj now per-iteration, stack-allocated
# github.com/ethersphere/bee/v2/pkg/bzz
pkg/bzz/utilities.go:9:9: loop variable v now per-iteration, stack-allocated
# github.com/libp2p/go-libp2p/p2p/transport/webtransport
../../go/pkg/mod/github.com/libp2p/[email protected]/p2p/transport/webtransport/cert_manager.go:183:9: loop variable certHash now per-iteration, stack-allocated
# github.com/ethersphere/bee/v2/pkg/transaction
pkg/transaction/transaction.go:621:9: loop variable abiError now per-iteration, stack-allocated
# github.com/ethersphere/bee/v2/pkg/storer/internal/cache
pkg/storer/internal/cache/cache.go:271:9: loop variable addr now per-iteration, stack-allocated
pkg/storer/internal/cache/cache.go:289:10: loop variable addr now per-iteration, stack-allocated
# github.com/ethersphere/bee/v2/pkg/file/joiner
pkg/file/joiner/joiner.go:383:6: loop variable i now per-iteration, stack-allocated
pkg/file/joiner/joiner.go:383:9: loop variable addr now per-iteration, heap-allocated
# github.com/ethersphere/bee/v2/pkg/storer/migration
pkg/storer/migration/reserveRepair.go:111:7: loop variable i now per-iteration, stack-allocated
pkg/storer/migration/step_05.go:27:8: loop variable item now per-iteration, stack-allocated
# github.com/ethersphere/bee/v2/pkg/storer
pkg/storer/reserve.go:183:9: loop variable batchID now per-iteration, stack-allocated
pkg/storer/compact.go:54:6: loop variable shard now per-iteration, stack-allocated
# github.com/ethersphere/bee/v2/pkg/puller
pkg/puller/puller.go:457:6: loop variable bin now per-iteration, stack-allocated
# github.com/ethersphere/bee/v2/cmd/bee/cmd
cmd/bee/cmd/db.go:521:11: loop variable root now per-iteration, stack-allocated
./pkg/storer/migration/reserveRepair.go:111:7: loop variable migration.i now per-iteration, stack-allocated

istae avatar May 20 '24 18:05 istae

I do not know how to interepet the above yet but it's a start

istae avatar May 20 '24 18:05 istae

I do not know how to interepet the above yet but it's a start

That is indeed a nice start, especially as there are not so many reported for loops under pkg/. It is nice that every module as dependency declares the supported go version and the for loop scoping will be used according to it, so we do not have to care about the dependencies when we are upgrading go version in our own module (bee).

janos avatar May 20 '24 21:05 janos