Skip to content
Merged
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
6 changes: 2 additions & 4 deletions agreement/fuzzer/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package fuzzer
import (
"context"
"fmt"
"maps"
"math/rand"

"github.com/algorand/go-algorand/agreement"
Expand Down Expand Up @@ -152,11 +153,8 @@ func makeTestLedger(state map[basics.Address]basics.AccountData, sync testLedger
l.certs = make(map[basics.Round]agreement.Certificate)
l.nextRound = 1

// deep copy of state
l.state = make(map[basics.Address]basics.AccountData)
for k, v := range state {
l.state[k] = v
}
maps.Copy(l.state, state)

l.notifications = make(map[basics.Round]signal)
l.EnsuringDigestStartCh = make(chan struct{})
Expand Down
9 changes: 2 additions & 7 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package config

import (
"maps"
"time"

"github.com/algorand/go-algorand/config/bounds"
Expand Down Expand Up @@ -768,13 +769,7 @@ func (cp ConsensusProtocols) DeepCopy() ConsensusProtocols {
staticConsensus := make(ConsensusProtocols)
for consensusVersion, consensusParams := range cp {
// recreate the ApprovedUpgrades map since we don't want to modify the original one.
if consensusParams.ApprovedUpgrades != nil {
newApprovedUpgrades := make(map[protocol.ConsensusVersion]uint64)
for ver, when := range consensusParams.ApprovedUpgrades {
newApprovedUpgrades[ver] = when
}
consensusParams.ApprovedUpgrades = newApprovedUpgrades
}
consensusParams.ApprovedUpgrades = maps.Clone(consensusParams.ApprovedUpgrades)
staticConsensus[consensusVersion] = consensusParams
}
return staticConsensus
Expand Down
8 changes: 2 additions & 6 deletions crypto/merkletrie/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ func (mtc *merkleTrieCache) loadPage(page uint64) (err error) {
mtc.cachedNodeCount += len(mtc.pageToNIDsPtr[page])
} else {
mtc.cachedNodeCount -= len(mtc.pageToNIDsPtr[page])
for nodeID, pnode := range decodedNodes {
mtc.pageToNIDsPtr[page][nodeID] = pnode
}
maps.Copy(mtc.pageToNIDsPtr[page], decodedNodes)
mtc.cachedNodeCount += len(mtc.pageToNIDsPtr[page])
}

Expand Down Expand Up @@ -485,9 +483,7 @@ func (mtc *merkleTrieCache) reallocatePendingPages(stats *CommitStats) (pagesToC
delete(createdPages, page)
}

for pageID, page := range mtc.reallocatedPages {
createdPages[pageID] = page
}
maps.Copy(createdPages, mtc.reallocatedPages)

for _, nodeIDs := range createdPages {
for _, node := range nodeIDs {
Expand Down
5 changes: 2 additions & 3 deletions data/account/registeryDbOps.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"database/sql"
"errors"
"fmt"
"maps"
"strings"

"github.com/algorand/go-algorand/data/basics"
Expand Down Expand Up @@ -257,9 +258,7 @@ func (f *flushOp) apply(db *participationDB) error {
if err != nil {
// put back what we didn't finish with
db.mutex.Lock()
for id, v := range dirty {
db.dirty[id] = v
}
maps.Copy(db.dirty, dirty)
db.mutex.Unlock()
}

Expand Down
5 changes: 2 additions & 3 deletions data/basics/serr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package basics

import (
"errors"
"maps"
"strings"

"golang.org/x/exp/slog"
Expand Down Expand Up @@ -108,9 +109,7 @@ func Wrap(err error, msg string, field string, pairs ...any) error {
var inner *SError
if ok := errors.As(err, &inner); ok {
attributes := make(map[string]any, len(inner.Attrs))
for key, val := range inner.Attrs {
attributes[key] = val
}
maps.Copy(attributes, inner.Attrs)
serr.Attrs[field+"-attrs"] = attributes
}

Expand Down
5 changes: 2 additions & 3 deletions data/pools/transactionPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package pools
import (
"errors"
"fmt"
"maps"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -268,9 +269,7 @@ func (pool *TransactionPool) rememberCommit(flush bool) {
} else {
pool.pendingTxGroups = append(pool.pendingTxGroups, pool.rememberedTxGroups...)

for txid, txn := range pool.rememberedTxids {
pool.pendingTxids[txid] = txn
}
maps.Copy(pool.pendingTxids, pool.rememberedTxids)
}

pool.rememberedTxGroups = nil
Expand Down
5 changes: 2 additions & 3 deletions data/transactions/logic/mocktracer/scenarios.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package mocktracer
import (
"encoding/hex"
"fmt"
"maps"
"math"

"github.com/algorand/go-algorand/crypto"
Expand Down Expand Up @@ -836,9 +837,7 @@ func MergeStateDeltas(deltas ...ledgercore.StateDelta) ledgercore.StateDelta {
includedTx.Intra += txidBase
result.Txids[txid] = includedTx
}
for lease, round := range delta.Txleases {
result.Txleases[lease] = round
}
maps.Copy(result.Txleases, delta.Txleases)
}
return result
}
21 changes: 6 additions & 15 deletions ledger/acctdeltas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"maps"
"math"
"math/rand"
"os"
Expand Down Expand Up @@ -188,9 +189,7 @@ func creatablesFromUpdates(base map[basics.Address]basics.AccountData, updates l

func applyPartialDeltas(base map[basics.Address]basics.AccountData, deltas ledgercore.AccountDeltas) map[basics.Address]basics.AccountData {
result := make(map[basics.Address]basics.AccountData, len(base)+deltas.Len())
for addr, ad := range base {
result[addr] = ad
}
maps.Copy(result, base)

for i := 0; i < deltas.Len(); i++ {
addr, _ := deltas.GetByIdx(i)
Expand Down Expand Up @@ -1484,18 +1483,10 @@ func (m mockAccountWriter) clone() (m2 mockAccountWriter) {
m2.resources = make(map[mockResourcesKey]ledgercore.AccountResource, len(m.resources))
m2.addresses = make(map[basics.Address]trackerdb.AccountRef, len(m.resources))
m2.rowids = make(map[trackerdb.AccountRef]basics.Address, len(m.rowids))
for k, v := range m.accounts {
m2.accounts[k] = v
}
for k, v := range m.resources {
m2.resources[k] = v
}
for k, v := range m.addresses {
m2.addresses[k] = v
}
for k, v := range m.rowids {
m2.rowids[k] = v
}
maps.Copy(m2.accounts, m.accounts)
maps.Copy(m2.resources, m.resources)
maps.Copy(m2.addresses, m.addresses)
maps.Copy(m2.rowids, m.rowids)
m2.lastAcctRef = m.lastAcctRef
m2.availAcctRefs = m.availAcctRefs
return m2
Expand Down
5 changes: 2 additions & 3 deletions ledger/acctonline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ledger
import (
"context"
"fmt"
"maps"
"sort"
"strconv"
"testing"
Expand Down Expand Up @@ -871,9 +872,7 @@ func TestAcctOnlineCacheDBSync(t *testing.T) {
copyGenesisAccts := func() []map[basics.Address]basics.AccountData {
accounts := []map[basics.Address]basics.AccountData{{}}
accounts[0] = make(map[basics.Address]basics.AccountData, numAccts)
for addr, ad := range genesisAccts[0] {
accounts[0][addr] = ad
}
maps.Copy(accounts[0], genesisAccts[0])
return accounts
}

Expand Down
6 changes: 2 additions & 4 deletions ledger/acctupdates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"errors"
"fmt"
"maps"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -167,15 +168,12 @@ func (ml *mockLedgerForTracker) fork(t testing.TB) *mockLedgerForTracker {
log: dblogger,
blocks: make([]blockEntry, len(ml.blocks)),
deltas: make([]ledgercore.StateDelta, len(ml.deltas)),
accts: make(map[basics.Address]basics.AccountData),
accts: maps.Clone(ml.accts),
filename: fn,
consensusParams: ml.consensusParams,
consensusVersion: ml.consensusVersion,
trackers: trackerRegistry{log: dblogger},
}
for k, v := range ml.accts {
newLedgerTracker.accts[k] = v
}
copy(newLedgerTracker.blocks, ml.blocks)
copy(newLedgerTracker.deltas, ml.deltas)

Expand Down
5 changes: 2 additions & 3 deletions ledger/eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"errors"
"fmt"
"maps"
"math/rand"
"testing"

Expand Down Expand Up @@ -886,9 +887,7 @@ func (ledger *evalTestLedger) AddValidatedBlock(vb ledgercore.ValidatedBlock, ce
newBalances := make(map[basics.Address]basics.AccountData)

// copy the previous balances.
for k, v := range ledger.roundBalances[vb.Block().Round()-1] {
newBalances[k] = v
}
maps.Copy(newBalances, ledger.roundBalances[vb.Block().Round()-1])

// update
deltas := vb.Delta()
Expand Down
16 changes: 4 additions & 12 deletions ledger/ledgercore/statedelta.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,7 @@ func (ad AccountDeltas) ApplyToBasicsAccountData(addr basics.Address, prev basic

if acct.TotalAppParams > 0 || prev.AppParams != nil {
result.AppParams = make(map[basics.AppIndex]basics.AppParams)
for aidx, params := range prev.AppParams {
result.AppParams[aidx] = params
}
maps.Copy(result.AppParams, prev.AppParams)
for aapp, idx := range ad.appResourcesCache {
if aapp.Address == addr {
rec := ad.AppResources[idx]
Expand All @@ -784,9 +782,7 @@ func (ad AccountDeltas) ApplyToBasicsAccountData(addr basics.Address, prev basic

if acct.TotalAppLocalStates > 0 || prev.AppLocalStates != nil {
result.AppLocalStates = make(map[basics.AppIndex]basics.AppLocalState)
for aidx, state := range prev.AppLocalStates {
result.AppLocalStates[aidx] = state
}
maps.Copy(result.AppLocalStates, prev.AppLocalStates)
for aapp, idx := range ad.appResourcesCache {
if aapp.Address == addr {
rec := ad.AppResources[idx]
Expand All @@ -804,9 +800,7 @@ func (ad AccountDeltas) ApplyToBasicsAccountData(addr basics.Address, prev basic

if acct.TotalAssetParams > 0 || prev.AssetParams != nil {
result.AssetParams = make(map[basics.AssetIndex]basics.AssetParams)
for aidx, params := range prev.AssetParams {
result.AssetParams[aidx] = params
}
maps.Copy(result.AssetParams, prev.AssetParams)
for aapp, idx := range ad.assetResourcesCache {
if aapp.Address == addr {
rec := ad.AssetResources[idx]
Expand All @@ -824,9 +818,7 @@ func (ad AccountDeltas) ApplyToBasicsAccountData(addr basics.Address, prev basic

if acct.TotalAssets > 0 || prev.Assets != nil {
result.Assets = make(map[basics.AssetIndex]basics.AssetHolding)
for aidx, params := range prev.Assets {
result.Assets[aidx] = params
}
maps.Copy(result.Assets, prev.Assets)
for aapp, idx := range ad.assetResourcesCache {
if aapp.Address == addr {
rec := ad.AssetResources[idx]
Expand Down
8 changes: 3 additions & 5 deletions network/multiplexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package network

import (
"fmt"
"maps"
"sync/atomic"
)

Expand Down Expand Up @@ -83,11 +84,8 @@ func (m *Multiplexer) ValidateHandle(msg IncomingMessage) OutgoingMessage {

func registerMultiplexer[T any](target *atomic.Value, dispatch []taggedMessageDispatcher[T]) {
mp := make(map[Tag]T)
if existingMap := getMap[T](target); existingMap != nil {
for k, v := range existingMap {
mp[k] = v
}
}
existingMap := getMap[T](target)
maps.Copy(mp, existingMap)
for _, v := range dispatch {
if _, has := mp[v.Tag]; has {
panic(fmt.Sprintf("Already registered a handler for tag %v", v.Tag))
Expand Down
9 changes: 3 additions & 6 deletions network/wsNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"net"
"net/http"
"net/textproto"
Expand Down Expand Up @@ -2469,9 +2470,7 @@ func (wn *WebsocketNetwork) registerMessageInterest(t protocol.Tag) {

if wn.messagesOfInterest == nil {
wn.messagesOfInterest = make(map[protocol.Tag]bool)
for tag, flag := range defaultSendMessageTags {
wn.messagesOfInterest[tag] = flag
}
maps.Copy(wn.messagesOfInterest, defaultSendMessageTags)
}

wn.messagesOfInterest[t] = true
Expand All @@ -2485,9 +2484,7 @@ func (wn *WebsocketNetwork) DeregisterMessageInterest(t protocol.Tag) {

if wn.messagesOfInterest == nil {
wn.messagesOfInterest = make(map[protocol.Tag]bool)
for tag, flag := range defaultSendMessageTags {
wn.messagesOfInterest[tag] = flag
}
maps.Copy(wn.messagesOfInterest, defaultSendMessageTags)
}

delete(wn.messagesOfInterest, t)
Expand Down
5 changes: 2 additions & 3 deletions shared/pingpong/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/binary"
"fmt"
"log"
"maps"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -456,9 +457,7 @@ func (pps *WorkerState) makeNewAssets(client *libgoal.Client) (err error) {
break
}
}
for assetID, ap := range newAssets {
pps.cinfo.AssetParams[assetID] = ap
}
maps.Copy(pps.cinfo.AssetParams, newAssets)
return nil
}

Expand Down
Loading
Loading