Skip to content

Commit

Permalink
Reduce the ECChain API surface by removing unused capability (#832)
Browse files Browse the repository at this point in the history
The `ECChain` API offers a few functions that seem to only have been
used in unit testing the functions themselves.

Remove them to reduce LOC, in favor of adding back later if ever anyone
asked for it.
  • Loading branch information
masih authored Jan 16, 2025
1 parent 79a7008 commit 7e86edb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 66 deletions.
42 changes: 0 additions & 42 deletions gpbft/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,55 +288,13 @@ func (c ECChain) Eq(other ECChain) bool {
return true
}

// Checks whether two chains have the same base.
//
// Always false for a zero value.
func (c ECChain) SameBase(other ECChain) bool {
if c.IsZero() || other.IsZero() {
return false
}
return c.Base().Equal(other.Base())
}

// Check whether a chain has a specific base tipset.
//
// Always false for a zero value.
func (c ECChain) HasBase(t *TipSet) bool {
return t != nil && !c.IsZero() && c.Base().Equal(t)
}

// Checks whether a chain has some prefix (including the base).
//
// Always false for a zero value.
func (c ECChain) HasPrefix(other ECChain) bool {
if c.IsZero() || other.IsZero() {
return false
}
if len(other) > len(c) {
return false
}
for i := range other {
if !c[i].Equal(&other[i]) {
return false
}
}
return true
}

// Checks whether a chain has some tipset (including as its base).
func (c ECChain) HasTipset(t *TipSet) bool {
if t == nil {
// Chain can never contain zero-valued TipSet.
return false
}
for i := range c {
if c[i].Equal(t) {
return true
}
}
return false
}

// Validates a chain value, returning an error if it finds any issues.
// A chain is valid if it meets the following criteria:
// 1) All contained tipsets are non-empty.
Expand Down
24 changes: 0 additions & 24 deletions gpbft/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ func TestECChain(t *testing.T) {
var subject gpbft.ECChain
require.True(t, subject.IsZero())
require.False(t, subject.HasBase(&zeroTipSet))
require.False(t, subject.HasPrefix(subject))
require.False(t, subject.HasTipset(&zeroTipSet))
require.False(t, subject.SameBase(subject))
require.True(t, subject.Eq(subject))
require.True(t, subject.Eq(*new(gpbft.ECChain)))
require.Nil(t, subject.Suffix())
Expand Down Expand Up @@ -56,27 +53,6 @@ func TestECChain(t *testing.T) {
require.Equal(t, &wantNext, subjectExtended.Head())
require.True(t, subjectExtended.HasSuffix())
require.Equal(t, &wantNext, subjectExtended.Prefix(1).Head())
require.True(t, subjectExtended.HasTipset(&wantBase))
require.False(t, subject.HasPrefix(subjectExtended))
require.True(t, subjectExtended.HasPrefix(subject))

require.False(t, subject.Extend(wantBase.Key).HasPrefix(subjectExtended.Extend(wantNext.Key)))
})
t.Run("SameBase is false when either chain is zero", func(t *testing.T) {
var zeroChain gpbft.ECChain
nonZeroChain, err := gpbft.NewChain(oneTipSet)
require.NoError(t, err)
require.False(t, nonZeroChain.SameBase(zeroChain))
require.False(t, zeroChain.SameBase(nonZeroChain))
require.False(t, zeroChain.SameBase(zeroChain))
})
t.Run("HasPrefix is false when either chain is zero", func(t *testing.T) {
var zeroChain gpbft.ECChain
nonZeroChain, err := gpbft.NewChain(oneTipSet)
require.NoError(t, err)
require.False(t, nonZeroChain.HasPrefix(zeroChain))
require.False(t, zeroChain.HasPrefix(nonZeroChain))
require.False(t, zeroChain.HasPrefix(zeroChain))
})
t.Run("zero-valued chain is valid", func(t *testing.T) {
var zeroChain gpbft.ECChain
Expand Down

0 comments on commit 7e86edb

Please sign in to comment.