Skip to content

Commit

Permalink
fix!: remove incorrect and extra delimlen func (celestiaorg#809)
Browse files Browse the repository at this point in the history
as noticed in
celestiaorg#804 (comment),
I forgot to delete the old `DelimLen` function after fixing a bug in
celestiaorg#747.
  • Loading branch information
evan-forbes authored and rach-id committed Nov 16, 2022
1 parent 2214d30 commit 497feaf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
6 changes: 0 additions & 6 deletions x/payment/types/payfordata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"crypto/sha256"
"fmt"
"math/bits"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/nmt"
Expand Down Expand Up @@ -232,8 +231,3 @@ func powerOf2(v uint64) bool {
}
return false
}

// DelimLen calculates the length of the delimiter for a given message size
func DelimLen(x uint64) int {
return 8 - bits.LeadingZeros64(x)%8
}
3 changes: 2 additions & 1 deletion x/payment/types/payfordata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

sdkerrors "cosmossdk.io/errors"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
shares "github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/nmt/namespace"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -421,7 +422,7 @@ func TestValidateBasic(t *testing.T) {
// totalMsgSize subtracts the delimiter size from the desired total size. this
// is useful for testing for messages that occupy exactly so many shares.
func totalMsgSize(size int) int {
return size - DelimLen(uint64(size))
return size - shares.DelimLen(uint64(size))
}

func validWirePayForData(t *testing.T) *MsgWirePayForData {
Expand Down
3 changes: 2 additions & 1 deletion x/payment/types/square_sizes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"github.com/celestiaorg/celestia-app/pkg/appconsts"
shares "github.com/celestiaorg/celestia-app/pkg/shares"
)

// https://github.com/celestiaorg/celestia-app/issues/236
Expand Down Expand Up @@ -45,7 +46,7 @@ func AllSquareSizes(msgSize int) []uint64 {
// It accounts for the necessary delimiter and potential padding.
func MsgSharesUsed(msgSize int) int {
// add the delimiter to the message size
msgSize = DelimLen(uint64(msgSize)) + msgSize
msgSize = shares.DelimLen(uint64(msgSize)) + msgSize
shareCount := msgSize / appconsts.SparseShareContentSize
// increment the share count if the message overflows the last counted share
if msgSize%appconsts.SparseShareContentSize != 0 {
Expand Down

0 comments on commit 497feaf

Please sign in to comment.