Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <[email protected]>
  • Loading branch information
joshua-kim committed Dec 2, 2024
1 parent fc37244 commit b12770b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
8 changes: 5 additions & 3 deletions x/dsmr/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ var (
ErrInvalidBlockHeight = errors.New("invalid block height")
ErrInvalidBlockTimestamp = errors.New("invalid block timestamp")
ErrInvalidWarpSignature = errors.New("invalid warp signature")
ErrInvalidSignatureType = errors.New("invalid signature type")
ErrFailedToReplicate = errors.New("failed to replicate to sufficient stake")
)

type Validator struct {
Expand Down Expand Up @@ -183,12 +185,12 @@ func (n *Node[T]) BuildChunk(
}

if !ok {
return Chunk[T]{}, ChunkCertificate{}, errors.New("failed to replicate to sufficient stake")
return Chunk[T]{}, ChunkCertificate{}, ErrFailedToReplicate
}

bitSetSignature, ok := aggregatedMsg.Signature.(*warp.BitSetSignature)
if !ok {
return Chunk[T]{}, ChunkCertificate{}, errors.New("invalid signature type")
return Chunk[T]{}, ChunkCertificate{}, ErrInvalidSignatureType
}

chunkCert := ChunkCertificate{
Expand Down Expand Up @@ -364,7 +366,7 @@ func (pChain) GetSubnetID(context.Context, ids.ID) (ids.ID, error) {
}

func (p pChain) GetValidatorSet(context.Context, uint64, ids.ID) (map[ids.NodeID]*snowValidators.GetValidatorOutput, error) {
result := make(map[ids.NodeID]*snowValidators.GetValidatorOutput)
result := make(map[ids.NodeID]*snowValidators.GetValidatorOutput, len(p.validators))
for _, v := range p.validators {
result[v.NodeID] = &snowValidators.GetValidatorOutput{
NodeID: v.NodeID,
Expand Down
18 changes: 9 additions & 9 deletions x/dsmr/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestNode_BuildChunk(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
r := require.New(t)

node := newNode(t)
node := newTestNode(t)
chunk, _, err := node.BuildChunk(
context.Background(),
tt.txs,
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestNode_GetChunk_AvailableChunk(t *testing.T) {
func TestNode_GetChunk_PendingChunk(t *testing.T) {
r := require.New(t)

node := newNode(t)
node := newTestNode(t)
chunk, _, err := node.BuildChunk(
context.Background(),
[]tx{{ID: ids.GenerateTestID(), Expiry: 123}},
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestNode_GetChunk_PendingChunk(t *testing.T) {
func TestNode_GetChunk_UnknownChunk(t *testing.T) {
r := require.New(t)

node := newNode(t)
node := newTestNode(t)
client := NewGetChunkClient[tx](p2ptest.NewClient(
t,
context.Background(),
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestNode_BuiltChunksAvailableOverGetChunk(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
r := require.New(t)

node := newNode(t)
node := newTestNode(t)

// Build some chunks
wantChunks := make([]Chunk[tx], 0)
Expand Down Expand Up @@ -647,7 +647,7 @@ func TestNode_GetChunkSignature_SignValidChunk(t *testing.T) {
func TestNode_GetChunkSignature_DuplicateChunk(t *testing.T) {
r := require.New(t)

node := newNode(t)
node := newTestNode(t)
chunk, _, err := node.BuildChunk(
context.Background(),
[]tx{{ID: ids.Empty, Expiry: 123}},
Expand Down Expand Up @@ -965,7 +965,7 @@ func TestNode_NewBlock_IncludesChunkCerts(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
r := require.New(t)

node := newNode(t)
node := newTestNode(t)
wantChunks := make([]Chunk[tx], 0)
for _, chunk := range tt.chunks {
chunk, _, err := node.BuildChunk(
Expand Down Expand Up @@ -1085,7 +1085,7 @@ func getSignerBitSet(t *testing.T, pChain snowValidators.State, nodeIDs ...ids.N
func Test_Verify(t *testing.T) {
r := require.New(t)

node := newNode(t)
node := newTestNode(t)
_, _, err := node.BuildChunk(
context.Background(),
[]tx{{ID: ids.GenerateTestID(), Expiry: 1}},
Expand Down Expand Up @@ -1240,7 +1240,7 @@ func Test_Verify_BadBlock(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
r := require.New(t)

node := newNode(t)
node := newTestNode(t)
_, chunkCert, err := node.BuildChunk(
context.Background(),
[]tx{{ID: ids.GenerateTestID(), Expiry: 2}},
Expand Down Expand Up @@ -1289,7 +1289,7 @@ type testNode struct {
Sk *bls.SecretKey
}

func newNode(t *testing.T) *Node[tx] {
func newTestNode(t *testing.T) *Node[tx] {
return newNodes(t, 1)[0]
}

Expand Down

0 comments on commit b12770b

Please sign in to comment.