diff --git a/commit/merkleroot/rmn/controller_test.go b/commit/merkleroot/rmn/controller_test.go index 827d317ac..7731e1ce9 100644 --- a/commit/merkleroot/rmn/controller_test.go +++ b/commit/merkleroot/rmn/controller_test.go @@ -6,6 +6,7 @@ import ( "crypto/sha256" "errors" "fmt" + "maps" "sort" "strconv" "strings" @@ -1053,9 +1054,7 @@ func (m *mockPeerClient) getReceivedRequests() map[rmntypes.NodeID][]*rmnpb.Requ cp := make(map[rmntypes.NodeID][]*rmnpb.Request) m.mu.RLock() defer m.mu.RUnlock() - for k, v := range m.receivedRequests { - cp[k] = v - } + maps.Copy(cp, m.receivedRequests) return cp } diff --git a/commit/merkleroot/transmission_checks_test.go b/commit/merkleroot/transmission_checks_test.go index f96b9256e..415cc17dc 100644 --- a/commit/merkleroot/transmission_checks_test.go +++ b/commit/merkleroot/transmission_checks_test.go @@ -1,6 +1,7 @@ package merkleroot import ( + "maps" "testing" "github.com/stretchr/testify/mock" @@ -28,9 +29,7 @@ func TestValidateRootBlessings(t *testing.T) { copyConfigWithOverride := func(chain cciptypes.ChainSelector, override reader2.StaticSourceChainConfig) map[cciptypes.ChainSelector]reader2.StaticSourceChainConfig { config := make(map[cciptypes.ChainSelector]reader2.StaticSourceChainConfig) - for k, v := range sourceChainConfig { - config[k] = v - } + maps.Copy(config, sourceChainConfig) config[chain] = override return config } diff --git a/pkg/addressbook/book.go b/pkg/addressbook/book.go index 4c505bd77..82e71e511 100644 --- a/pkg/addressbook/book.go +++ b/pkg/addressbook/book.go @@ -2,6 +2,7 @@ package addressbook import ( "errors" + "maps" "sync" "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" @@ -73,9 +74,7 @@ func (b *Book) InsertOrUpdate(addresses ContractAddresses) error { } // if contract exists, set or replace any existing address for each chain - for chain, addr := range chains { - b.mem[name][chain] = addr - } + maps.Copy(b.mem[name], chains) } return nil diff --git a/pkg/ocrtypecodec/v1/translate.go b/pkg/ocrtypecodec/v1/translate.go index 157a85312..65b8bea69 100644 --- a/pkg/ocrtypecodec/v1/translate.go +++ b/pkg/ocrtypecodec/v1/translate.go @@ -1,6 +1,7 @@ package v1 import ( + "maps" "math/big" "google.golang.org/protobuf/types/known/timestamppb" @@ -854,9 +855,7 @@ func (t *protoTranslator) nonceObservationsToProto( for chainSel, nonceMap := range observations { addrToNonce := make(map[string]uint64, len(nonceMap)) - for addr, nonce := range nonceMap { - addrToNonce[addr] = nonce - } + maps.Copy(addrToNonce, nonceMap) nonceObservations[uint64(chainSel)] = &ocrtypecodecpb.StringAddrToNonce{Nonces: addrToNonce} } @@ -873,9 +872,7 @@ func (t *protoTranslator) nonceObservationsFromProto( for chainSel, nonceMap := range pbObservations { innerMap := make(map[string]uint64, len(nonceMap.Nonces)) - for addr, nonce := range nonceMap.Nonces { - innerMap[addr] = nonce - } + maps.Copy(innerMap, nonceMap.Nonces) nonces[cciptypes.ChainSelector(chainSel)] = innerMap } diff --git a/pkg/reader/config_poller.go b/pkg/reader/config_poller.go index 4d59b605b..44273858c 100644 --- a/pkg/reader/config_poller.go +++ b/pkg/reader/config_poller.go @@ -3,6 +3,7 @@ package reader import ( "context" "fmt" + "maps" "sync" "sync/atomic" "time" @@ -591,9 +592,7 @@ func (c *configPoller) GetOfframpSourceChainConfigs( } // Merge the new configs with existing cached results - for chain, config := range newCachedConfigs { - cachedSourceConfigs[chain] = config - } + maps.Copy(cachedSourceConfigs, newCachedConfigs) return cachedSourceConfigs, nil } diff --git a/pkg/reader/config_poller_v2_test.go b/pkg/reader/config_poller_v2_test.go index 6b344fd1d..fe13b4a95 100644 --- a/pkg/reader/config_poller_v2_test.go +++ b/pkg/reader/config_poller_v2_test.go @@ -3,6 +3,7 @@ package reader import ( "context" "errors" + "maps" "sync" "sync/atomic" "testing" @@ -314,9 +315,7 @@ func TestConfigPollerV2_BatchRefreshChainAndSourceConfigs_Error(t *testing.T) { cache.sourceChainMu.RLock() initialSourceRefreshTime := cache.sourceChainRefresh initialSourceConfigData := make(map[cciptypes.ChainSelector]StaticSourceChainConfig) - for k, v := range cache.staticSourceChainConfigs { - initialSourceConfigData[k] = v - } + maps.Copy(initialSourceConfigData, cache.staticSourceChainConfigs) cache.sourceChainMu.RUnlock() // Verify cache was populated diff --git a/pkg/reader/usdc_reader.go b/pkg/reader/usdc_reader.go index 3334f9a7e..557e03f75 100644 --- a/pkg/reader/usdc_reader.go +++ b/pkg/reader/usdc_reader.go @@ -4,6 +4,7 @@ import ( "context" "encoding/binary" "fmt" + "maps" sel "github.com/smartcontractkit/chain-selectors" @@ -231,9 +232,7 @@ func AllAvailableDomains() map[uint64]uint32 { } destDomains := make(map[uint64]uint32) - for k, v := range CCTPDestDomains { - destDomains[k] = v - } + maps.Copy(destDomains, CCTPDestDomains) for i, chainID := range chainIDs { chainSelector, _ := sel.SelectorFromChainId(chainID)