Skip to content

Commit

Permalink
refactor: replace experimental maps and slices with stdlib (algor…
Browse files Browse the repository at this point in the history
…and#6179)

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee authored Nov 25, 2024
1 parent 0bc3d7e commit 92e0e00
Show file tree
Hide file tree
Showing 37 changed files with 69 additions and 74 deletions.
2 changes: 1 addition & 1 deletion agreement/agreementtest/simulate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package agreementtest
import (
"context"
"fmt"
"maps"
"math/rand"
"os"
"strconv"
Expand All @@ -27,7 +28,6 @@ import (

"github.com/algorand/go-deadlock"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"

"github.com/algorand/go-algorand/agreement"
"github.com/algorand/go-algorand/config"
Expand Down
2 changes: 1 addition & 1 deletion agreement/autopsy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"fmt"
"io"
"os"
"slices"

"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
"golang.org/x/exp/slices"
)

// An Autopsy is a trace of the ordered input events and output
Expand Down
2 changes: 1 addition & 1 deletion agreement/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package agreement
import (
"context"
"fmt"
"maps"
"math/rand"
"testing"

"github.com/algorand/go-deadlock"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
Expand Down
5 changes: 3 additions & 2 deletions cmd/algokey/keyreg.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"encoding/base64"
"errors"
"fmt"
"maps"
"os"
"slices"
"strings"

"github.com/spf13/cobra"
"golang.org/x/exp/maps"

"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/account"
Expand Down Expand Up @@ -95,7 +96,7 @@ func init() {
"betanet": mustConvertB64ToDigest("mFgazF+2uRS1tMiL9dsj01hJGySEmPN28B/TjjvpVW0="),
"devnet": mustConvertB64ToDigest("sC3P7e2SdbqKJK0tbiCdK9tdSpbe6XeCGKdoNzmlj0E="),
}
validNetworkList = maps.Keys(validNetworks)
validNetworkList = slices.Collect(maps.Keys(validNetworks))
}

func mustConvertB64ToDigest(b64 string) (digest crypto.Digest) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/goal/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"net/http"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"time"

"github.com/spf13/cobra"
"golang.org/x/exp/slices"

"github.com/algorand/go-algorand/cmd/util/datadir"
"github.com/algorand/go-algorand/config"
Expand Down
2 changes: 1 addition & 1 deletion cmd/tealdbg/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"log"
"slices"
"time"

"github.com/algorand/go-algorand/config"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/algorand/go-algorand/data/transactions/logic"
"github.com/algorand/go-algorand/ledger/apply"
"github.com/algorand/go-algorand/protocol"
"golang.org/x/exp/slices"
)

func protoFromString(protoString string) (name string, proto config.ConsensusParams, err error) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/merklearray/merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"errors"
"fmt"
"hash"
"slices"
"sort"

"github.com/algorand/go-algorand/crypto"
"golang.org/x/exp/slices"
)

const (
Expand Down
8 changes: 3 additions & 5 deletions crypto/merkletrie/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import (
"encoding/binary"
"errors"
"fmt"

"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"maps"
"slices"
)

// storedNodeIdentifier is the "equivalent" of a node-ptr, but oriented around persisting the
Expand Down Expand Up @@ -448,8 +447,7 @@ func (mtc *merkleTrieCache) reallocatePendingPages(stats *CommitStats) (pagesToC
}

// create a sorted list of created pages
sortedCreatedPages := maps.Keys(createdPages)
slices.Sort(sortedCreatedPages)
sortedCreatedPages := slices.Sorted(maps.Keys(createdPages))

mtc.reallocatedPages = make(map[uint64]map[storedNodeIdentifier]*node)

Expand Down
2 changes: 1 addition & 1 deletion crypto/merkletrie/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package merkletrie

import "golang.org/x/exp/slices"
import "slices"

// Committer is the interface supporting serializing tries into persistent storage.
type Committer interface {
Expand Down
2 changes: 1 addition & 1 deletion crypto/merkletrie/committer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package merkletrie

import (
"encoding/binary"
"slices"
"testing"

"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/test/partitiontest"
Expand Down
2 changes: 1 addition & 1 deletion crypto/merkletrie/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package merkletrie
import (
"bytes"
"encoding/binary"
"slices"
"sort"
"unsafe"

"github.com/algorand/go-algorand/crypto"
"golang.org/x/exp/slices"
)

type childEntry struct {
Expand Down
2 changes: 1 addition & 1 deletion daemon/algod/api/server/v2/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"encoding/base64"
"errors"
"math"
"slices"
"sort"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/merklesignature"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
"github.com/algorand/go-algorand/data/basics"
"golang.org/x/exp/slices"
)

// AssetHolding converts between basics.AssetHolding and model.AssetHolding
Expand Down
2 changes: 1 addition & 1 deletion daemon/algod/api/server/v2/test/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"net/http"
"net/http/httptest"
"reflect"
"slices"
"strings"
"testing"
"time"
Expand All @@ -37,7 +38,6 @@ import (
"github.com/algorand/go-algorand/daemon/algod/api/server"
"github.com/algorand/go-algorand/ledger/eval"
"github.com/algorand/go-algorand/ledger/ledgercore"
"golang.org/x/exp/slices"

"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
Expand Down
16 changes: 8 additions & 8 deletions daemon/algod/api/server/v2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import (
"encoding/base64"
"errors"
"fmt"
"maps"
"net/http"
"slices"
"strings"
"unicode"
"unicode/utf8"

"github.com/algorand/go-codec/codec"
"github.com/labstack/echo/v4"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"

"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model"
Expand Down Expand Up @@ -494,23 +494,23 @@ func convertUnnamedResourcesAccessed(resources *simulation.ResourceTracker) *mod
return nil
}
return &model.SimulateUnnamedResourcesAccessed{
Accounts: sliceOrNil(stringSlice(maps.Keys(resources.Accounts))),
Assets: sliceOrNil(uint64Slice(maps.Keys(resources.Assets))),
Apps: sliceOrNil(uint64Slice(maps.Keys(resources.Apps))),
Boxes: sliceOrNil(convertSlice(maps.Keys(resources.Boxes), func(box logic.BoxRef) model.BoxReference {
Accounts: sliceOrNil(stringSlice(slices.Collect(maps.Keys(resources.Accounts)))),
Assets: sliceOrNil(uint64Slice(slices.Collect(maps.Keys(resources.Assets)))),
Apps: sliceOrNil(uint64Slice(slices.Collect(maps.Keys(resources.Apps)))),
Boxes: sliceOrNil(convertSlice(slices.Collect(maps.Keys(resources.Boxes)), func(box logic.BoxRef) model.BoxReference {
return model.BoxReference{
App: uint64(box.App),
Name: []byte(box.Name),
}
})),
ExtraBoxRefs: omitEmpty(uint64(resources.NumEmptyBoxRefs)),
AssetHoldings: sliceOrNil(convertSlice(maps.Keys(resources.AssetHoldings), func(holding ledgercore.AccountAsset) model.AssetHoldingReference {
AssetHoldings: sliceOrNil(convertSlice(slices.Collect(maps.Keys(resources.AssetHoldings)), func(holding ledgercore.AccountAsset) model.AssetHoldingReference {
return model.AssetHoldingReference{
Account: holding.Address.String(),
Asset: uint64(holding.Asset),
}
})),
AppLocals: sliceOrNil(convertSlice(maps.Keys(resources.AppLocals), func(local ledgercore.AccountApp) model.ApplicationLocalReference {
AppLocals: sliceOrNil(convertSlice(slices.Collect(maps.Keys(resources.AppLocals)), func(local ledgercore.AccountApp) model.ApplicationLocalReference {
return model.ApplicationLocalReference{
Account: local.Address.String(),
App: uint64(local.App),
Expand Down
2 changes: 1 addition & 1 deletion data/basics/teal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package basics
import (
"encoding/hex"
"fmt"
"maps"

"github.com/algorand/go-algorand/config"
"golang.org/x/exp/maps"
)

// DeltaAction is an enum of actions that may be performed when applying a
Expand Down
2 changes: 1 addition & 1 deletion data/basics/userBalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"encoding/binary"
"fmt"
"reflect"
"slices"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/merklesignature"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
"golang.org/x/exp/slices"
)

// Status is the delegation status of an account's MicroAlgos
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package transactions

import (
"fmt"
"slices"

"github.com/algorand/go-algorand/data/basics"
"golang.org/x/exp/slices"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"encoding/hex"
"fmt"
"math/big"
"slices"
"strconv"
"testing"

"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/secp256k1"
Expand Down
3 changes: 1 addition & 2 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ import (
"math/big"
"math/bits"
"runtime"
"slices"
"strconv"
"strings"

"golang.org/x/exp/slices"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
Expand Down
9 changes: 4 additions & 5 deletions data/transactions/logic/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package logic
import (
"cmp"
"fmt"
"maps"
"slices"
"strconv"
"strings"

"github.com/algorand/go-algorand/data/basics"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

// LogicVersion defines default assembler and max eval versions
Expand Down Expand Up @@ -838,11 +838,10 @@ func OpcodesByVersion(version uint64) []OpSpec {
}
}
}
result := maps.Values(subv)
slices.SortFunc(result, func(a, b OpSpec) int {
values := maps.Values(subv)
return slices.SortedFunc(values, func(a, b OpSpec) int {
return cmp.Compare(a.Opcode, b.Opcode)
})
return result
}

// direct opcode bytes
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/opcodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package logic
import (
"fmt"
"reflect"
"slices"
"testing"

"github.com/algorand/go-algorand/test/partitiontest"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

func TestOpSpecs(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions data/transactions/teal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package transactions

import (
"bytes"
"maps"
"slices"

"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/protocol"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

// EvalDelta stores StateDeltas for an application's global key/value store, as
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
"encoding/binary"
"errors"
"fmt"
"slices"
"sync"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/protocol"
"golang.org/x/exp/slices"
)

// Txid is a hash used to uniquely identify individual transactions
Expand Down
2 changes: 1 addition & 1 deletion ledger/apply/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package apply

import (
"fmt"
"maps"
"math/rand"
"testing"

"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
Expand Down
Loading

0 comments on commit 92e0e00

Please sign in to comment.