From bc102aec839b2003893d6d9dd60936ce576ec81b Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Tue, 3 Jan 2023 14:21:13 -0600 Subject: [PATCH 1/5] Fix misspellings --- blake3_regression_test.go | 2 +- circlehash64_regression_test.go | 2 +- cmd/stress/main.go | 2 +- errors.go | 4 ++-- map.go | 2 +- storage.go | 2 +- storage_test.go | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/blake3_regression_test.go b/blake3_regression_test.go index 9a6474ca..0d5707bb 100644 --- a/blake3_regression_test.go +++ b/blake3_regression_test.go @@ -110,7 +110,7 @@ func TestBLAKE3Regression(t *testing.T) { data := nonUniformBytes64KiB() // Verify BLAKE3 digests produced from hashing portions of - // data. Input sizes vary from 1 to 64KiB bytes by varing + // data. Input sizes vary from 1 to 64KiB bytes by varying // starting pos and ending pos. // We use 64KiB because BLAKE3 implementations can have // special optimizations for large data sizes and we diff --git a/circlehash64_regression_test.go b/circlehash64_regression_test.go index 0757ff60..ddd2991e 100644 --- a/circlehash64_regression_test.go +++ b/circlehash64_regression_test.go @@ -72,7 +72,7 @@ func TestCircleHash64Regression(t *testing.T) { // Verify CircleHash64 digests produced from hashing portions of // data using different seed values. Input sizes vary from - // 1 to 16384 bytes by varing starting pos and ending pos. + // 1 to 16384 bytes by varying starting pos and ending pos. testCases := []struct { name string diff --git a/cmd/stress/main.go b/cmd/stress/main.go index 8c02c367..8e59a9ce 100644 --- a/cmd/stress/main.go +++ b/cmd/stress/main.go @@ -98,7 +98,7 @@ func main() { typ = strings.ToLower(typ) if typ != "array" && typ != "map" { - fmt.Fprintf(os.Stderr, "Please specifiy type as either \"array\" or \"map\"") + fmt.Fprintf(os.Stderr, "Please specify type as either \"array\" or \"map\"") return } diff --git a/errors.go b/errors.go index 961ab788..80acccc6 100644 --- a/errors.go +++ b/errors.go @@ -246,7 +246,7 @@ func (e *SlabNotFoundError) Error() string { // Unwrap returns the wrapped err func (e *SlabNotFoundError) Unwrap() error { return e.err } -// SlabSplitError is alwyas a fatal error returned when splitting an slab has failed +// SlabSplitError is always a fatal error returned when splitting an slab has failed type SlabSplitError struct { err error } @@ -288,7 +288,7 @@ func (e *SlabMergeError) Error() string { func (e *SlabMergeError) Unwrap() error { return e.err } -// SlabRebalanceError is alwyas a fatal error returned when rebalancing a slab has failed +// SlabRebalanceError is always a fatal error returned when rebalancing a slab has failed type SlabRebalanceError struct { err error } diff --git a/map.go b/map.go index 9e314158..4f34b873 100644 --- a/map.go +++ b/map.go @@ -715,7 +715,7 @@ func (e *inlineCollisionGroup) Set(storage SlabStorage, address Address, b Diges } if level == 1 { - // Export oversized inline collision group to separete slab (external collision group) + // Export oversized inline collision group to separate slab (external collision group) // for first level collision. if e.Size() > uint32(maxInlineMapElementSize) { diff --git a/storage.go b/storage.go index 9e28b6f5..7370bb93 100644 --- a/storage.go +++ b/storage.go @@ -914,7 +914,7 @@ func (s *PersistentSlabStorage) Remove(id StorageID) error { return nil } -// Warning Counts doesn't consider new segments in the deltas and only returns commited values +// Warning Counts doesn't consider new segments in the deltas and only returns committed values func (s *PersistentSlabStorage) Count() int { return s.baseStorage.SegmentCounts() } diff --git a/storage_test.go b/storage_test.go index f81c1548..ac8dfc16 100644 --- a/storage_test.go +++ b/storage_test.go @@ -675,7 +675,7 @@ func TestPersistentStorage(t *testing.T) { storageWithFastCommit := NewPersistentSlabStorage(baseStorage2, encMode, decMode, nil, nil) simpleMap := make(map[StorageID][]byte) - // test random updates apply commit and check the order of commited values + // test random updates apply commit and check the order of committed values for i := 0; i < numberOfAccounts; i++ { for j := 0; j < numberOfSlabsPerAccount; j++ { addr := generateRandomAddress(r) From 2d9fcaba279d3f755c5850727a011168f8668b73 Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Tue, 3 Jan 2023 14:34:40 -0600 Subject: [PATCH 2/5] Remove unnecessary conversions --- array.go | 2 +- cmd/stress/utils.go | 2 +- map.go | 2 +- map_debug.go | 2 +- settings.go | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/array.go b/array.go index 0530df53..8d293006 100644 --- a/array.go +++ b/array.go @@ -892,7 +892,7 @@ func newArrayMetaDataSlabFromData( totalCount += count childrenHeaders[i] = ArraySlabHeader{ - id: StorageID(storageID), + id: storageID, count: count, size: size, } diff --git a/cmd/stress/utils.go b/cmd/stress/utils.go index 1af28886..6aa9621a 100644 --- a/cmd/stress/utils.go +++ b/cmd/stress/utils.go @@ -53,7 +53,7 @@ var ( func newRand(seed int64) *rand.Rand { if seed == 0 { - seed = int64(time.Now().UnixNano()) + seed = time.Now().UnixNano() } fmt.Printf("rand seed 0x%x\n", seed) diff --git a/map.go b/map.go index 4f34b873..06291903 100644 --- a/map.go +++ b/map.go @@ -2503,7 +2503,7 @@ func newMapMetaDataSlabFromData( size := binary.BigEndian.Uint32(data[sizeOffset:]) childrenHeaders[i] = MapSlabHeader{ - id: StorageID(storageID), + id: storageID, size: size, firstKey: Digest(firstKey), } diff --git a/map_debug.go b/map_debug.go index 7c4bccbf..66e13ac4 100644 --- a/map_debug.go +++ b/map_debug.go @@ -581,7 +581,7 @@ func validMapHkeyElements( elementSize += e.Size() - elementCount += uint64(count) + elementCount += count } else { diff --git a/settings.go b/settings.go index d472e1cd..bc48dccb 100644 --- a/settings.go +++ b/settings.go @@ -49,12 +49,12 @@ func SetThreshold(threshold uint64) (uint64, uint64, uint64, uint64) { } targetThreshold = threshold - minThreshold = uint64(targetThreshold / 2) + minThreshold = targetThreshold / 2 maxThreshold = uint64(float64(targetThreshold) * 1.5) // Total slab size available for array elements, excluding slab encoding overhead availableArrayElementsSize := targetThreshold - arrayDataSlabPrefixSize - MaxInlineArrayElementSize = uint64(availableArrayElementsSize / minElementCountInSlab) + MaxInlineArrayElementSize = availableArrayElementsSize / minElementCountInSlab // Total slab size available for map elements, excluding slab encoding overhead availableMapElementsSize := targetThreshold - mapDataSlabPrefixSize - hkeyElementsPrefixSize @@ -63,10 +63,10 @@ func SetThreshold(threshold uint64) (uint64, uint64, uint64, uint64) { mapElementOverheadSize := uint64(digestSize) // Max inline size for a map's element - maxInlineMapElementSize = uint64(availableMapElementsSize/minElementCountInSlab) - mapElementOverheadSize + maxInlineMapElementSize = availableMapElementsSize/minElementCountInSlab - mapElementOverheadSize // Max inline size for a map's key or value, excluding element encoding overhead - MaxInlineMapKeyOrValueSize = uint64((maxInlineMapElementSize - singleElementPrefixSize) / 2) + MaxInlineMapKeyOrValueSize = (maxInlineMapElementSize - singleElementPrefixSize) / 2 return minThreshold, maxThreshold, MaxInlineArrayElementSize, MaxInlineMapKeyOrValueSize } From 4bdfa618799f2f1a428e003c1a05d760189214d3 Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Tue, 3 Jan 2023 15:22:37 -0600 Subject: [PATCH 3/5] Fix linter errors --- cmd/stress/main.go | 2 +- map_test.go | 6 ------ storage_test.go | 7 +++---- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/cmd/stress/main.go b/cmd/stress/main.go index 8e59a9ce..7ba3ac8c 100644 --- a/cmd/stress/main.go +++ b/cmd/stress/main.go @@ -87,7 +87,7 @@ func main() { var seed int64 if len(seedHex) != 0 { var err error - seed, err = strconv.ParseInt(strings.Replace(seedHex, "0x", "", -1), 16, 64) + seed, err = strconv.ParseInt(strings.ReplaceAll(seedHex, "0x", ""), 16, 64) if err != nil { panic("Failed to parse seed flag (hex string)") } diff --git a/map_test.go b/map_test.go index 7a809ff9..f61f18e8 100644 --- a/map_test.go +++ b/map_test.go @@ -1734,7 +1734,6 @@ func TestMapEncodeDecode(t *testing.T) { // extra data (CBOR encoded array of 3 elements) 0x83, // type info: "map" - //0x63, 0x6d, 0x61, 0x70, 0x18, 0x2A, // count: 8 0x08, @@ -1951,7 +1950,6 @@ func TestMapEncodeDecode(t *testing.T) { // extra data (CBOR encoded array of 3 elements) 0x83, // type info: "map" - //0x63, 0x6d, 0x61, 0x70, 0x18, 0x2A, // count: 8 0x08, @@ -2145,7 +2143,6 @@ func TestMapEncodeDecode(t *testing.T) { // extra data (CBOR encoded array of 3 elements) 0x83, // type info: "map" - //0x63, 0x6d, 0x61, 0x70, 0x18, 0x2A, // count: 8 0x08, @@ -2391,7 +2388,6 @@ func TestMapEncodeDecode(t *testing.T) { // extra data (CBOR encoded array of 3 elements) 0x83, // type info: "map" - //0x63, 0x6d, 0x61, 0x70, 0x18, 0x2A, // count: 10 0x14, @@ -2616,7 +2612,6 @@ func TestMapEncodeDecode(t *testing.T) { // extra data (CBOR encoded array of 3 elements) 0x83, // type info: "map" - //0x63, 0x6d, 0x61, 0x70, 0x18, 0x2A, // count: 10 0x01, @@ -2672,7 +2667,6 @@ func TestMapEncodeDecode(t *testing.T) { // extra data (CBOR encoded array of 3 elements) 0x83, // type info: "map" - //0x63, 0x6d, 0x61, 0x70, 0x18, 0x2A, // count: 10 0x01, diff --git a/storage_test.go b/storage_test.go index ac8dfc16..c4f71f14 100644 --- a/storage_test.go +++ b/storage_test.go @@ -226,10 +226,9 @@ func TestLedgerBaseStorageStore(t *testing.T) { // Overwrite stored values for id := range values { - value := append(values[id], []byte{1, 2, 3}...) - values[id] = value - bytesStored += len(value) - err := baseStorage.Store(id, value) + values[id] = append(values[id], []byte{1, 2, 3}...) + bytesStored += len(values[id]) + err := baseStorage.Store(id, values[id]) require.NoError(t, err) } From 41b6a81098f8f5092fb5f4056b0e12b7af07c9d2 Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Tue, 3 Jan 2023 15:25:12 -0600 Subject: [PATCH 4/5] Fix goimports linting --- cmd/main/main.go | 3 ++- cmd/stress/main.go | 3 ++- cmd/stress/storable.go | 3 ++- cmd/stress/typeinfo.go | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/main/main.go b/cmd/main/main.go index 814bb6c3..66d60e5b 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -22,8 +22,9 @@ import ( "flag" "fmt" - "github.com/fxamacker/cbor/v2" "github.com/onflow/atree" + + "github.com/fxamacker/cbor/v2" ) const cborTagUInt64Value = 164 diff --git a/cmd/stress/main.go b/cmd/stress/main.go index 7ba3ac8c..c74e677a 100644 --- a/cmd/stress/main.go +++ b/cmd/stress/main.go @@ -29,8 +29,9 @@ import ( "syscall" "time" - "github.com/fxamacker/cbor/v2" "github.com/onflow/atree" + + "github.com/fxamacker/cbor/v2" ) const maxStatusLength = 128 diff --git a/cmd/stress/storable.go b/cmd/stress/storable.go index 3d808acb..213bd1a4 100644 --- a/cmd/stress/storable.go +++ b/cmd/stress/storable.go @@ -23,8 +23,9 @@ import ( "fmt" "math" - "github.com/fxamacker/cbor/v2" "github.com/onflow/atree" + + "github.com/fxamacker/cbor/v2" ) // This file is mostly from github.com/onflow/atree/storable_test.go diff --git a/cmd/stress/typeinfo.go b/cmd/stress/typeinfo.go index 531bfaef..4618dc12 100644 --- a/cmd/stress/typeinfo.go +++ b/cmd/stress/typeinfo.go @@ -19,8 +19,9 @@ package main import ( - "github.com/fxamacker/cbor/v2" "github.com/onflow/atree" + + "github.com/fxamacker/cbor/v2" ) type testTypeInfo struct { From 132dfb3813457a653bd06b5d61a1190f077e8e60 Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Tue, 3 Jan 2023 15:30:36 -0600 Subject: [PATCH 5/5] Add .golangci.yml --- .golangci.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..3a72ce82 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,38 @@ +# .golangci.yml for github.com/onflow/atree + +linters: + disable-all: true + enable: + # enable default linters + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - typecheck + - unused + + # enable extra linters + - exportloopref + - gocritic + - gofmt + - goimports + - misspell + - nilerr + - unconvert + +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + +linters-settings: + gocritic: + disabled-checks: + - ifElseChain # style + - singleCaseSwitch # style + - unslice # false positives + - commentFormatting # does not detect commented out code + - exitAfterDefer + + goimports: + local-prefixes: github.com/onflow/atree