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(linter): enable go-critic #28

Merged
merged 2 commits into from
Jan 24, 2024
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ linters:
- revive
- prealloc
- stylecheck
- gocritic

linters-settings:
nakedret:
Expand Down
6 changes: 3 additions & 3 deletions inclusion/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func CreateCommitment(blob *blob.Blob, merkleRootFn MerkleRootFn, subtreeRootThr
cursor := uint64(0)
for i, treeSize := range treeSizes {
leafSets[i] = sh.ToBytes(shares[cursor : cursor+treeSize])
cursor = cursor + treeSize
cursor += treeSize
}

// create the commitments by pushing each leaf set onto an nmt
Expand Down Expand Up @@ -99,14 +99,14 @@ func MerkleMountainRangeSizes(totalSize, maxTreeSize uint64) ([]uint64, error) {
switch {
case totalSize >= maxTreeSize:
treeSizes = append(treeSizes, maxTreeSize)
totalSize = totalSize - maxTreeSize
totalSize -= maxTreeSize
case totalSize < maxTreeSize:
treeSize, err := sh.RoundDownPowerOfTwo(totalSize)
if err != nil {
return treeSizes, err
}
treeSizes = append(treeSizes, treeSize)
totalSize = totalSize - treeSize
totalSize -= treeSize
}
}

Expand Down
2 changes: 1 addition & 1 deletion shares/powers_of_two.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func RoundUpPowerOfTwo[I constraints.Integer](input I) I {
var result I = 1
for result < input {
result = result << 1
result <<= 1
}
return result
}
Expand Down
2 changes: 1 addition & 1 deletion shares/share_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (b *Builder) FlipSequenceStart() {

// the sequence start indicator is the last bit of the info byte so flip the
// last bit
b.rawShareData[infoByteIndex] = b.rawShareData[infoByteIndex] ^ 0x01
b.rawShareData[infoByteIndex] ^= 0x01
}

func (b *Builder) prepareCompactShare() error {
Expand Down
7 changes: 3 additions & 4 deletions shares/shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ func TestSequenceLen(t *testing.T) {
wantLen uint32
wantErr bool
}
sparseNamespaceID := bytes.Repeat([]byte{1}, namespace.NamespaceSize)
firstShare := append(sparseNamespaceID,
firstShare := append(bytes.Repeat([]byte{1}, namespace.NamespaceSize),
[]byte{
1, // info byte
0, 0, 0, 10, // sequence len
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // data
}...)
firstShareWithLongSequence := append(sparseNamespaceID,
firstShareWithLongSequence := append(bytes.Repeat([]byte{1}, namespace.NamespaceSize),
[]byte{
1, // info byte
0, 0, 1, 67, // sequence len
}...)
continuationShare := append(sparseNamespaceID,
continuationShare := append(bytes.Repeat([]byte{1}, namespace.NamespaceSize),
[]byte{
0, // info byte
}...)
Expand Down
2 changes: 1 addition & 1 deletion square/square.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func WriteSquare(
}

square := make([]shares.Share, totalShares)
copy(square[:], txShares)
copy(square, txShares)
copy(square[pfbStartIndex:], pfbShares)
if blobWriter.Count() > 0 {
copy(square[paddingStartIndex:], padding)
Expand Down
3 changes: 2 additions & 1 deletion square/square_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func TestSquareConstruction(t *testing.T) {
sendTxs := test.GenerateTxs(250, 250, 250)
pfbTxs := test.GenerateBlobTxs(10_000, 1, 1024)
t.Run("normal transactions after PFB transactions", func(t *testing.T) {
txs := append(sendTxs[:5], append(pfbTxs, sendTxs[5:]...)...)
txs := sendTxs[:5]
txs = append(txs, append(pfbTxs, txs...)...)
_, err := square.Construct(txs, defaultMaxSquareSize, defaultSubtreeRootThreshold)
require.Error(t, err)
})
Expand Down
Loading