Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-batcher: Fix intermittency in TestChannelBuilder_PendingFrames_TotalFrames #5989

Merged
merged 3 commits into from
Jun 12, 2023
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
8 changes: 3 additions & 5 deletions op-batcher/batcher/channel_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (
"math/big"
"math/rand"
"testing"
"time"

"github.com/ethereum-optimism/optimism/op-batcher/compressor"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
dtest "github.com/ethereum-optimism/optimism/op-node/rollup/derive/test"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie"
Expand Down Expand Up @@ -686,7 +684,7 @@ func TestFramePublished(t *testing.T) {

func TestChannelBuilder_PendingFrames_TotalFrames(t *testing.T) {
const tnf = 8
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
rng := rand.New(rand.NewSource(94572314))
require := require.New(t)
cfg := defaultTestChannelConfig
cfg.CompressorConfig.TargetFrameSize = 1000
Expand Down Expand Up @@ -729,7 +727,7 @@ func TestChannelBuilder_PendingFrames_TotalFrames(t *testing.T) {

func TestChannelBuilder_InputBytes(t *testing.T) {
require := require.New(t)
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
rng := rand.New(rand.NewSource(4982432))
cb, _ := defaultChannelBuilderSetup(t)

require.Zero(cb.InputBytes())
Expand All @@ -747,7 +745,7 @@ func TestChannelBuilder_InputBytes(t *testing.T) {

func TestChannelBuilder_OutputBytes(t *testing.T) {
require := require.New(t)
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
rng := rand.New(rand.NewSource(9860372))
cfg := defaultTestChannelConfig
cfg.CompressorConfig.TargetFrameSize = 1000
cfg.MaxFrameSize = 1000
Expand Down
16 changes: 10 additions & 6 deletions op-node/testutils/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package testutils

import (
"crypto/ecdsa"
"fmt"
"math/big"
"math/rand"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"

"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
)

func RandomBool(rng *rand.Rand) bool {
Expand Down Expand Up @@ -102,10 +102,14 @@ func NextRandomL2Ref(rng *rand.Rand, l2BlockTime uint64, parent eth.L2BlockRef,
}
}

// InsecureRandomKey returns a random private key from a limited set of keys.
// Output is deterministic when the supplied rng generates the same random sequence.
func InsecureRandomKey(rng *rand.Rand) *ecdsa.PrivateKey {
key, err := ecdsa.GenerateKey(crypto.S256(), rng)
idx := rng.Intn(len(randomEcdsaKeys))
key, err := crypto.ToECDSA(common.Hex2Bytes(randomEcdsaKeys[idx]))
if err != nil {
panic(err)
// Should never happen because the list of keys is hard coded and known to be valid.
panic(fmt.Errorf("invalid pre-generated ecdsa key at index %v: %w", idx, err))
}
return key
}
Expand Down
Loading