Skip to content
Draft
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
22 changes: 7 additions & 15 deletions test/e2e/evm_contract_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"
collpb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
Expand All @@ -44,6 +43,7 @@ import (
func BenchmarkEvmContractRoundtrip(b *testing.B) {
workDir := b.TempDir()
sequencerHome := filepath.Join(workDir, "evm-bench-sequencer")
const blockTime = 5 * time.Millisecond

// Start an in-process OTLP/HTTP receiver to collect traces from ev-node.
collector := newOTLPCollector(b)
Expand All @@ -55,6 +55,7 @@ func BenchmarkEvmContractRoundtrip(b *testing.B) {
"--evnode.instrumentation.tracing_endpoint", collector.endpoint(),
"--evnode.instrumentation.tracing_sample_rate", "1.0",
"--evnode.instrumentation.tracing_service_name", "ev-node-bench",
"--evnode.node.block_time="+blockTime.String(),
)
defer cleanup()

Expand Down Expand Up @@ -101,8 +102,11 @@ func BenchmarkEvmContractRoundtrip(b *testing.B) {
err = client.SendTransaction(ctx, signedTxs[i])
require.NoError(b, err)

// 2. Wait for inclusion.
waitForReceipt(b, ctx, client, signedTxs[i].Hash())
// 2. Wait for inclusion with fast polling to reduce variance while avoiding RPC overload.
require.Eventually(b, func() bool {
receipt, err := client.TransactionReceipt(ctx, signedTxs[i].Hash())
return err == nil && receipt != nil
}, 2*time.Second, blockTime/2, "transaction %s not included", signedTxs[i].Hash().Hex())

// 3. Retrieve and verify.
result, err := client.CallContract(ctx, callMsg, nil)
Expand Down Expand Up @@ -279,15 +283,3 @@ func printCollectedTraceReport(b testing.TB, collector *otlpCollector) {
b.Logf("%-40s %5.1f%% %s", name, pct, bar)
}
}

// waitForReceipt polls for a transaction receipt until it is available.
func waitForReceipt(t testing.TB, ctx context.Context, client *ethclient.Client, txHash common.Hash) *types.Receipt {
t.Helper()
var receipt *types.Receipt
var err error
require.Eventually(t, func() bool {
receipt, err = client.TransactionReceipt(ctx, txHash)
return err == nil && receipt != nil
}, 2*time.Second, 50*time.Millisecond, "transaction %s not included", txHash.Hex())
return receipt
}
Loading