Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Wazzymandias committed Jul 26, 2023
1 parent 5ddc19b commit 6ccec93
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 38 deletions.
3 changes: 2 additions & 1 deletion core/state/multi_tx_snapshot.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package state

import (
"github.com/ethereum/go-ethereum/common"
"math/big"

"github.com/ethereum/go-ethereum/common"
)

// MultiTxSnapshot retains StateDB changes for multiple transactions.
Expand Down
54 changes: 30 additions & 24 deletions core/state/multi_tx_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ package state
import (
"bytes"
"fmt"
"github.com/ethereum/go-ethereum/common"
"math/big"
"math/rand"
"testing"

"github.com/ethereum/go-ethereum/common"
)

var (
addrs []common.Address
keys []common.Hash

rng *rand.Rand
)

func init() {
rng = rand.New(rand.NewSource(0))

for i := 0; i < 20; i++ {
addrs = append(addrs, common.HexToAddress(fmt.Sprintf("0x%02x", i)))
}
Expand Down Expand Up @@ -69,7 +74,7 @@ func verifyObservableAccountState(s *StateDB, state *observableAccountState) err
if s.GetNonce(state.address) != state.nonce {
return fmt.Errorf("nonce mismatch %v != %v", s.GetNonce(state.address), state.nonce)
}
if bytes.Compare(s.GetCode(state.address), state.code) != 0 {
if !bytes.Equal(s.GetCode(state.address), state.code) {
return fmt.Errorf("code mismatch %v != %v", s.GetCode(state.address), state.code)
}
if s.GetCodeHash(state.address) != state.codeHash {
Expand Down Expand Up @@ -102,7 +107,10 @@ func verifyObservableAccountState(s *StateDB, state *observableAccountState) err

func randomBytes(n int) []byte {
b := make([]byte, n)
rand.Read(b)
_, err := rng.Read(b)
if err != nil {
panic(err)
}
return b
}

Expand All @@ -122,9 +130,9 @@ func randFillAccountState(addr common.Address, s *StateDB) {
}

func randFillAccount(addr common.Address, s *StateDB) {
s.SetNonce(addr, rand.Uint64())
s.SetBalance(addr, big.NewInt(rand.Int63()))
s.SetCode(addr, randomBytes(rand.Intn(100)))
s.SetNonce(addr, rng.Uint64())
s.SetBalance(addr, big.NewInt(rng.Int63()))
s.SetCode(addr, randomBytes(rng.Intn(100)))
randFillAccountState(addr, s)
}

Expand All @@ -139,49 +147,47 @@ func prepareInitialState(s *StateDB) {
afterCommitHooks = append(afterCommitHooks, afterCommit)
}

rand.Seed(0)

addAccount(func(addr common.Address, s *StateDB) {
s.SetNonce(addr, rand.Uint64())
s.SetNonce(addr, rng.Uint64())
}, nil)
addAccount(nil, func(addr common.Address, s *StateDB) {
s.SetNonce(addr, rand.Uint64())
s.SetNonce(addr, rng.Uint64())
})
addAccount(func(addr common.Address, s *StateDB) {
s.SetNonce(addr, rand.Uint64())
s.SetNonce(addr, rng.Uint64())
}, func(addr common.Address, s *StateDB) {
s.SetNonce(addr, rand.Uint64())
s.SetNonce(addr, rng.Uint64())
})

addAccount(func(addr common.Address, s *StateDB) {
s.SetBalance(addr, big.NewInt(rand.Int63()))
s.SetBalance(addr, big.NewInt(rng.Int63()))
}, nil)
addAccount(nil, func(addr common.Address, s *StateDB) {
s.SetBalance(addr, big.NewInt(rand.Int63()))
s.SetBalance(addr, big.NewInt(rng.Int63()))
})
addAccount(func(addr common.Address, s *StateDB) {
s.SetBalance(addr, big.NewInt(rand.Int63()))
s.SetBalance(addr, big.NewInt(rng.Int63()))
}, func(addr common.Address, s *StateDB) {
s.SetBalance(addr, big.NewInt(rand.Int63()))
s.SetBalance(addr, big.NewInt(rng.Int63()))
})

addAccount(func(addr common.Address, s *StateDB) {
s.SetCode(addr, randomBytes(rand.Intn(100)))
s.SetCode(addr, randomBytes(rng.Intn(100)))
}, nil)
addAccount(nil, func(addr common.Address, s *StateDB) {
s.SetCode(addr, randomBytes(rand.Intn(100)))
s.SetCode(addr, randomBytes(rng.Intn(100)))
})
addAccount(func(addr common.Address, s *StateDB) {
s.SetCode(addr, randomBytes(rand.Intn(100)))
s.SetCode(addr, randomBytes(rng.Intn(100)))
s.SetCode(addr, nil)
}, func(addr common.Address, s *StateDB) {
s.SetCode(addr, randomBytes(rand.Intn(100)))
s.SetCode(addr, randomBytes(rng.Intn(100)))
})
addAccount(func(addr common.Address, s *StateDB) {
s.SetCode(addr, randomBytes(rand.Intn(100)))
s.SetCode(addr, randomBytes(rng.Intn(100)))
s.Suicide(addr)
}, func(addr common.Address, s *StateDB) {
s.SetCode(addr, randomBytes(rand.Intn(100)))
s.SetCode(addr, randomBytes(rng.Intn(100)))
})

addAccount(func(addr common.Address, s *StateDB) {
Expand Down Expand Up @@ -277,15 +283,15 @@ func testMutliTxSnapshot(t *testing.T, actions func(s *StateDB)) {
if len(s.state.stateObjectsPending) != len(pendingAddressesBefore) {
t.Error("pending state objects count mismatch", "got", len(s.state.stateObjectsPending), "expected", len(pendingAddressesBefore))
}
for k, _ := range s.state.stateObjectsPending {
for k := range s.state.stateObjectsPending {
if _, ok := pendingAddressesBefore[k]; !ok {
t.Error("stateObjectsPending mismatch, before was nil", "address", k)
}
}
if len(s.state.stateObjectsDirty) != len(dirtyAddressesBefore) {
t.Error("dirty state objects count mismatch", "got", len(s.state.stateObjectsDirty), "expected", len(dirtyAddressesBefore))
}
for k, _ := range s.state.stateObjectsDirty {
for k := range s.state.stateObjectsDirty {
if _, ok := dirtyAddressesBefore[k]; !ok {
t.Error("stateObjectsDirty mismatch, before was nil", "address", k)
}
Expand Down
3 changes: 1 addition & 2 deletions miner/algo_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,10 @@ func BuildMultiTxSnapBlock(
chData chainData,
algoConf algorithmConfig,
orders *types.TransactionsByPriceAndNonce) ([]types.SimulatedBundle, []types.UsedSBundle, error) {

var (
usedBundles []types.SimulatedBundle
usedSbundles []types.UsedSBundle
orderFailed = false
orderFailed bool
buildBlockErrors []error
)

Expand Down
1 change: 0 additions & 1 deletion miner/algo_greedy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func newGreedyBuilder(
chain *core.BlockChain, chainConfig *params.ChainConfig, algoConf *algorithmConfig,
blacklist map[common.Address]struct{}, env *environment, key *ecdsa.PrivateKey, interrupt *int32,
) (*greedyBuilder, error) {

if algoConf == nil {
return nil, errNoAlgorithmConfig
}
Expand Down
4 changes: 0 additions & 4 deletions miner/algo_greedy_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func newGreedyBucketsBuilder(
if algoConf.EnableMultiTxSnap {
buildBlockFunc = func(simBundles []types.SimulatedBundle, simSBundles []*types.SimSBundle,
transactions map[common.Address]types.Transactions) (*environment, []types.SimulatedBundle, []types.UsedSBundle) {

orders := types.NewTransactionsByPriceAndNonce(builder.inputEnvironment.signer, transactions,
simBundles, simSBundles, builder.inputEnvironment.header.BaseFee)

Expand All @@ -69,7 +68,6 @@ func newGreedyBucketsBuilder(
} else {
buildBlockFunc = func(simBundles []types.SimulatedBundle, simSBundles []*types.SimSBundle,
transactions map[common.Address]types.Transactions) (*environment, []types.SimulatedBundle, []types.UsedSBundle) {

orders := types.NewTransactionsByPriceAndNonce(builder.inputEnvironment.signer, transactions,
simBundles, simSBundles, builder.inputEnvironment.header.BaseFee)

Expand All @@ -88,7 +86,6 @@ func newGreedyBucketsBuilder(
func CheckRetryOrderAndReinsert(
order *types.TxWithMinerFee, orders *types.TransactionsByPriceAndNonce,
retryMap map[*types.TxWithMinerFee]int, retryLimit int) bool {

var isRetryable bool = false
if retryCount, exists := retryMap[order]; exists {
if retryCount != retryLimit {
Expand Down Expand Up @@ -281,6 +278,5 @@ func (b *greedyBucketsBuilder) mergeOrdersIntoEnvDiff(

func (b *greedyBucketsBuilder) buildBlock(simBundles []types.SimulatedBundle, simSBundles []*types.SimSBundle,
transactions map[common.Address]types.Transactions) (*environment, []types.SimulatedBundle, []types.UsedSBundle) {

return b.buildBlockFunc(simBundles, simSBundles, transactions)
}
5 changes: 2 additions & 3 deletions miner/env_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"crypto/ecdsa"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/log"
"math/big"
)

// envChanges is a helper struct to apply and revert changes to the environment
Expand Down Expand Up @@ -283,7 +284,6 @@ func (c *envChanges) CommitSBundle(sbundle *types.SimSBundle, chData chainData,
}

func (c *envChanges) commitSBundle(sbundle *types.SBundle, chData chainData, key *ecdsa.PrivateKey, algoConf algorithmConfig) error {

var (
// check inclusion
minBlock = sbundle.Inclusion.BlockNumber
Expand Down Expand Up @@ -396,7 +396,6 @@ func (c *envChanges) revert() error {
func (c *envChanges) rollback(
gasUsedBefore uint64, gasPoolBefore *core.GasPool, profitBefore *big.Int,
txsBefore []*types.Transaction, receiptsBefore []*types.Receipt) {

c.usedGas = gasUsedBefore
c.gasPool = gasPoolBefore
c.txs = txsBefore
Expand Down
5 changes: 3 additions & 2 deletions miner/env_changes_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package miner

import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
"math/big"
"testing"
)

func TestTxCommitSnaps(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion miner/environment_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"crypto/ecdsa"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"math/big"
)

// environmentDiff is a helper struct used to apply transactions to a block using a copy of the state at that block
Expand Down

0 comments on commit 6ccec93

Please sign in to comment.