Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump to Go 1.21 #230

Merged
merged 3 commits into from
Aug 29, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
- name: Set up Go 1.21
uses: actions/setup-go@v2
with:
go-version: ^1.19
go-version: 1.21
id: go

- name: Check out code into the Go module directory
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Namespaced Merkle Tree (NMT)

![Go version](https://img.shields.io/badge/go-1.19-blue.svg)
![Go version](https://img.shields.io/badge/go-1.21-blue.svg)
[![API Reference](https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f676f6c616e672f6764646f3f7374617475732e737667)](https://pkg.go.dev/github.com/celestiaorg/nmt)
![golangci-lint](https://github.com/celestiaorg/nmt/workflows/golangci-lint/badge.svg?branch=master)
![Go](https://github.com/celestiaorg/nmt/workflows/Go/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/celestiaorg/nmt

go 1.19
go 1.21

require (
github.com/gogo/protobuf v1.3.2
Expand Down
22 changes: 15 additions & 7 deletions nmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package nmt
import (
"bytes"
"crypto"
"crypto/rand"
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"
"math"
"math/rand"
"reflect"
"sort"
"sync"
Expand Down Expand Up @@ -534,7 +534,8 @@ func TestNodeVisitor(t *testing.T) {
nodeHashes = append(nodeHashes, hash)
}

data := generateRandNamespacedRawData(numLeaves, nidSize, leafSize)
data, err := generateRandNamespacedRawData(numLeaves, nidSize, leafSize)
require.NoError(t, err)
n := New(sha256.New(), NamespaceIDSize(nidSize), NodeVisitor(collectNodeHashes))
for j := 0; j < numLeaves; j++ {
if err := n.Push(data[j]); err != nil {
Expand Down Expand Up @@ -706,7 +707,8 @@ func BenchmarkComputeRoot(b *testing.B) {
}

for _, tt := range tests {
data := generateRandNamespacedRawData(tt.numLeaves, tt.nidSize, tt.dataSize)
data, err := generateRandNamespacedRawData(tt.numLeaves, tt.nidSize, tt.dataSize)
require.NoError(b, err)
b.ResetTimer()
b.Run(tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -786,21 +788,27 @@ func repeat(data []namespaceDataPair, num int) []namespaceDataPair {
return res
}

func generateRandNamespacedRawData(total int, nidSize int, leafSize int) [][]byte {
func generateRandNamespacedRawData(total int, nidSize int, leafSize int) ([][]byte, error) {
data := make([][]byte, total)
for i := 0; i < total; i++ {
nid := make([]byte, nidSize)
rand.Read(nid)
_, err := rand.Read(nid)
if err != nil {
return nil, err
}
data[i] = nid
}
sortByteArrays(data)
for i := 0; i < total; i++ {
d := make([]byte, leafSize)
rand.Read(d)
_, err := rand.Read(d)
if err != nil {
return nil, err
}
data[i] = append(data[i], d...)
}

return data
return data, nil
}

func sortByteArrays(src [][]byte) {
Expand Down
Loading