Skip to content

Commit

Permalink
chore(trees): removed TreeConfiguration interface
Browse files Browse the repository at this point in the history
We don't need an interface (yet), since there is only one
implementation. A client (user) of the package can easily add its
own interface as necessary.
  • Loading branch information
meling committed Dec 22, 2024
1 parent 0131823 commit 5fe6e96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
13 changes: 2 additions & 11 deletions trees/treeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ import (
"github.com/relab/hotstuff"
)

// TreeConfiguration is an abstraction for a tree communication model.
type TreeConfiguration interface {
InitializeWithPIDs(treePositions []hotstuff.ID) error
GetTreeHeight() int
GetChildren() []hotstuff.ID
GetSubTreeNodes() []hotstuff.ID
GetParent() (hotstuff.ID, bool)
}

// Tree implements a fault free tree configuration.
type Tree struct {
id hotstuff.ID
Expand All @@ -26,8 +17,8 @@ type Tree struct {
branchFactor int
}

// CreateTree Creates the tree configuration, currently only fault free tree configuration is supported.
func CreateTree(configurationSize int, myID hotstuff.ID, bf int) TreeConfiguration {
// CreateTree creates the tree configuration, currently only fault free tree configuration is supported.
func CreateTree(configurationSize int, myID hotstuff.ID, bf int) *Tree {
if configurationSize <= 0 {
return nil
}
Expand Down
13 changes: 6 additions & 7 deletions trees/treeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,16 @@ func TestTreeAPIWithInitializeWithPIDs(t *testing.T) {
t.Errorf("Expected %d, got %d", test.parent, parent)
}
}
treeConfig := tree.(*Tree)
if treeConfig.IsRoot(test.id) != test.isRoot {
t.Errorf("Expected %t, got %t", test.isRoot, treeConfig.IsRoot(test.id))
if tree.IsRoot(test.id) != test.isRoot {
t.Errorf("Expected %t, got %t", test.isRoot, tree.IsRoot(test.id))
}
if treeConfig.GetHeight() != test.replicaHeight {
t.Errorf("Expected %d, got %d", test.replicaHeight, treeConfig.GetHeight())
if tree.GetHeight() != test.replicaHeight {
t.Errorf("Expected %d, got %d", test.replicaHeight, tree.GetHeight())
}
gotPeers := treeConfig.GetPeers(test.id)
gotPeers := tree.GetPeers(test.id)
sort.Slice(gotPeers, func(i, j int) bool { return gotPeers[i] < gotPeers[j] })
if len(gotPeers) != len(test.peers) || !slices.Equal(gotPeers, test.peers) {
t.Errorf("Expected %v, got %v", test.peers, treeConfig.GetPeers(test.id))
t.Errorf("Expected %v, got %v", test.peers, tree.GetPeers(test.id))
}
}
}

0 comments on commit 5fe6e96

Please sign in to comment.