Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions pkg/signer/aws/signer_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package aws

import (
"bytes"
"os"
"testing"
"time"

"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

pb "github.com/evstack/ev-node/types/pb/evnode/v1"
)

// BenchmarkKmsSignerSign test kms round trip
// export EVNODE_E2E_GCP_KMS_KEY_NAME=projects/<project-id>/locations/<region>/keyRings/<keyring-name>/cryptoKeys/<key-name>/cryptoKeyVersions/1
// export EVNODE_E2E_GCP_KMS_CREDENTIALS_FILE=...
// go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/gcp
Comment on lines +15 to +18
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Copy-paste error: comments describe GCP instead of AWS.

The comment block references GCP environment variables and the GCP package path, but this is the AWS benchmark file. The actual code correctly uses AWS variables.

📝 Suggested fix
 // BenchmarkKmsSignerSign test kms round trip
-// export EVNODE_E2E_GCP_KMS_KEY_NAME=projects/<project-id>/locations/<region>/keyRings/<keyring-name>/cryptoKeys/<key-name>/cryptoKeyVersions/1
-// export EVNODE_E2E_GCP_KMS_CREDENTIALS_FILE=...
-// go test  -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/gcp
+// export EVNODE_E2E_AWS_KMS_KEY_ID="arn:aws:kms:...."
+// export EVNODE_E2E_AWS_KMS_REGION=eu-west-1
+// go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/aws
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// BenchmarkKmsSignerSign test kms round trip
// export EVNODE_E2E_GCP_KMS_KEY_NAME=projects/<project-id>/locations/<region>/keyRings/<keyring-name>/cryptoKeys/<key-name>/cryptoKeyVersions/1
// export EVNODE_E2E_GCP_KMS_CREDENTIALS_FILE=...
// go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/gcp
// BenchmarkKmsSignerSign test kms round trip
// export EVNODE_E2E_AWS_KMS_KEY_ID="arn:aws:kms:...."
// export EVNODE_E2E_AWS_KMS_REGION=eu-west-1
// go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/aws
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/signer/aws/signer_benchmark_test.go` around lines 15 - 18, The comment
block in signer_benchmark_test.go incorrectly references GCP (env vars and
package path) for the BenchmarkKmsSignerSign benchmark; update those comments to
show the AWS equivalents and package path (e.g., replace GCP env var examples
and "pkg/signer/gcp" with the AWS environment variables used by the test and
"pkg/signer/aws") so the doc comment matches the AWS test implementation (refer
to BenchmarkKmsSignerSign in this file to verify the correct AWS variable
names).

func BenchmarkKmsSignerSign(b *testing.B) {
keyID := os.Getenv("EVNODE_E2E_AWS_KMS_KEY_ID")
if keyID == "" {
b.Skip("set EVNODE_E2E_AWS_KMS_KEY_ID to run AWS KMS benchmark")
}

region := firstNonEmpty(
os.Getenv("EVNODE_E2E_AWS_KMS_REGION"),
os.Getenv("AWS_REGION"),
os.Getenv("AWS_DEFAULT_REGION"),
)
profile := os.Getenv("EVNODE_E2E_AWS_KMS_PROFILE")

signer, err := NewKmsSigner(b.Context(), region, profile, keyID, &Options{
Timeout: 10 * time.Second,
MaxRetries: 0,
})
require.NoError(b, err)

headerData := benchmarkHeaderData(b)

b.ReportAllocs()
b.SetBytes(int64(len(headerData)))
b.ResetTimer()

for b.Loop() {
_, err := signer.Sign(b.Context(), headerData)
require.NoError(b, err)
}
}

func firstNonEmpty(values ...string) string {
for _, value := range values {
if value != "" {
return value
}
}

return ""
}

func benchmarkHeaderData(b *testing.B) []byte {
b.Helper()

header := &pb.Header{
Version: &pb.Version{
Block: 11,
App: 1,
},
Height: 1,
Time: 1743091200000000000, // 2025-03-27T00:00:00Z
LastHeaderHash: bytes.Repeat([]byte{0x3b}, 32),
DataHash: bytes.Repeat([]byte{0x78}, 32),
AppHash: bytes.Repeat([]byte{0xf5}, 32),
ProposerAddress: bytes.Repeat([]byte{0x25}, 32),
ValidatorHash: bytes.Repeat([]byte{0x25}, 32),
ChainId: "benchmark-chain",
}

headerData, err := proto.Marshal(header)
require.NoError(b, err)
require.NotEmpty(b, headerData)

return headerData
}
69 changes: 69 additions & 0 deletions pkg/signer/gcp/signer_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package gcp

import (
"bytes"
"os"
"testing"
"time"

"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

pb "github.com/evstack/ev-node/types/pb/evnode/v1"
)

// BenchmarkKmsSignerSign test kms round trip
// export EVNODE_E2E_AWS_KMS_KEY_ID="arn:aws:kms:...."
// export EVNODE_E2E_AWS_KMS_REGION=eu-west-1
// go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/aws
Comment on lines +15 to +18
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Copy-paste error: comments describe AWS instead of GCP.

The comment block references AWS environment variables and the AWS package path, but this is the GCP benchmark file. The actual code correctly uses GCP variables.

📝 Suggested fix
 // BenchmarkKmsSignerSign test kms round trip
-// export EVNODE_E2E_AWS_KMS_KEY_ID="arn:aws:kms:...."
-// export EVNODE_E2E_AWS_KMS_REGION=eu-west-1
-// go test  -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/aws
+// export EVNODE_E2E_GCP_KMS_KEY_NAME=projects/<project-id>/locations/<region>/keyRings/<keyring-name>/cryptoKeys/<key-name>/cryptoKeyVersions/1
+// export EVNODE_E2E_GCP_KMS_CREDENTIALS_FILE=...
+// go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/gcp
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// BenchmarkKmsSignerSign test kms round trip
// export EVNODE_E2E_AWS_KMS_KEY_ID="arn:aws:kms:...."
// export EVNODE_E2E_AWS_KMS_REGION=eu-west-1
// go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/aws
// BenchmarkKmsSignerSign test kms round trip
// export EVNODE_E2E_GCP_KMS_KEY_NAME=projects/<project-id>/locations/<region>/keyRings/<keyring-name>/cryptoKeys/<key-name>/cryptoKeyVersions/1
// export EVNODE_E2E_GCP_KMS_CREDENTIALS_FILE=...
// go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/gcp
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/signer/gcp/signer_benchmark_test.go` around lines 15 - 18, The benchmark
comment block in signer_benchmark_test.go wrongly references AWS
(EVNODE_E2E_AWS_KMS_KEY_ID, EVNODE_E2E_AWS_KMS_REGION and ./pkg/signer/aws);
update that comment to GCP-specific environment variables and path used by the
GCP benchmark (e.g., replace AWS env var names with the GCP KMS equivalents your
test expects and change the package path to ./pkg/signer/gcp) so the comment
matches the actual BenchmarkKmsSignerSign implementation and required GCP setup.

func BenchmarkKmsSignerSign(b *testing.B) {
keyName := os.Getenv("EVNODE_E2E_GCP_KMS_KEY_NAME")
if keyName == "" {
b.Skip("set EVNODE_E2E_GCP_KMS_KEY_NAME to run GCP KMS benchmark")
}

credentialsFile := os.Getenv("EVNODE_E2E_GCP_KMS_CREDENTIALS_FILE")

signer, err := NewKmsSigner(b.Context(), keyName, &Options{
CredentialsFile: credentialsFile,
Timeout: 1 * time.Second,
MaxRetries: 0,
})
require.NoError(b, err)

headerData := benchmarkHeaderData(b)

b.ReportAllocs()
b.SetBytes(int64(len(headerData)))
b.ResetTimer()

for b.Loop() {
_, err := signer.Sign(b.Context(), headerData)
require.NoError(b, err)
}
}

func benchmarkHeaderData(b *testing.B) []byte {
b.Helper()

header := &pb.Header{
Version: &pb.Version{
Block: 11,
App: 1,
},
Height: 1,
Time: 1743091200000000000, // 2025-03-27T00:00:00Z
LastHeaderHash: bytes.Repeat([]byte{0x3b}, 32),
DataHash: bytes.Repeat([]byte{0x78}, 32),
AppHash: bytes.Repeat([]byte{0xf5}, 32),
ProposerAddress: bytes.Repeat([]byte{0x25}, 32),
ValidatorHash: bytes.Repeat([]byte{0x25}, 32),
ChainId: "benchmark-chain",
}

headerData, err := proto.Marshal(header)
require.NoError(b, err)
require.NotEmpty(b, headerData)

return headerData
}
Loading