From b12770bedb14ab8dce57c16a6ba4f1224934a11f Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:56:15 -0500 Subject: [PATCH] nit Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> --- x/dsmr/node.go | 8 +++++--- x/dsmr/node_test.go | 18 +++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/x/dsmr/node.go b/x/dsmr/node.go index 2553165653..59e5a0193b 100644 --- a/x/dsmr/node.go +++ b/x/dsmr/node.go @@ -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 { @@ -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{ @@ -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, diff --git a/x/dsmr/node_test.go b/x/dsmr/node_test.go index 056aeb5580..40682aac9a 100644 --- a/x/dsmr/node_test.go +++ b/x/dsmr/node_test.go @@ -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, @@ -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}}, @@ -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(), @@ -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) @@ -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}}, @@ -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( @@ -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}}, @@ -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}}, @@ -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] }