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

Avoid unnecessary uint -> int casting on big.Int construction #10916

Merged
merged 1 commit into from
Jun 26, 2024
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
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestNewSimulatedBackend(t *testing.T) {
t.Fatal(err)
}

statedb := sim.stateByBlockNumber(tx, big.NewInt(int64(num+1)))
statedb := sim.stateByBlockNumber(tx, new(big.Int).SetUint64(num+1))
bal := statedb.GetBalance(testAddr)
if !bal.Eq(expectedBal) {
t.Errorf("expected balance for test address not received. expected: %v actual: %v", expectedBal, bal)
Expand Down
2 changes: 1 addition & 1 deletion cl/cltypes/eth1_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (b *Eth1Block) RlpHeader(parentRoot *libcommon.Hash) (*types.Header, error)
ReceiptHash: b.ReceiptsRoot,
Bloom: b.LogsBloom,
Difficulty: merge.ProofOfStakeDifficulty,
Number: big.NewInt(int64(b.BlockNumber)),
Number: new(big.Int).SetUint64(b.BlockNumber),
GasLimit: b.GasLimit,
GasUsed: b.GasUsed,
Time: b.Time,
Expand Down
2 changes: 1 addition & 1 deletion cmd/devnet/contracts/steps/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func DeployAndCallLogSubscriber(ctx context.Context, deployer string) (*libcommo

logs, err := node.FilterLogs(ctx, ethereum.FilterQuery{
FromBlock: big.NewInt(0),
ToBlock: big.NewInt(int64(blockNum)),
ToBlock: new(big.Int).SetUint64(blockNum),
Addresses: []libcommon.Address{address}})

if err != nil || len(logs) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/devnet/services/polygon/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func (h *Heimdall) handleChildHeader(ctx context.Context, header *types.Header)
h.pendingCheckpoint = &heimdall.Checkpoint{
Fields: heimdall.WaypointFields{
Timestamp: timeStamp,
StartBlock: big.NewInt(int64(expectedCheckpointState.newStart)),
EndBlock: big.NewInt(int64(expectedCheckpointState.newEnd)),
StartBlock: new(big.Int).SetUint64(expectedCheckpointState.newStart),
EndBlock: new(big.Int).SetUint64(expectedCheckpointState.newEnd),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/devnet/services/polygon/proofgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func (pg *ProofGenerator) getRootBlockInfo(txBlockNumber uint64) (rootBlockNumbe
return 0, 0, 0, err
}

headerBlock, err := pg.heimdall.rootChainBinding.HeaderBlocks(&bind.CallOpts{}, big.NewInt(int64(rootBlockNumber)))
headerBlock, err := pg.heimdall.rootChainBinding.HeaderBlocks(&bind.CallOpts{}, new(big.Int).SetUint64(rootBlockNumber))

if err != nil {
return 0, 0, 0, err
Expand Down Expand Up @@ -560,7 +560,7 @@ func (pg *ProofGenerator) findRootBlockFromChild(childBlockNumber uint64) (uint6
}

mid := (start + end) / 2
headerBlock, err := pg.heimdall.rootChainBinding.HeaderBlocks(&bind.CallOpts{}, big.NewInt(int64(mid*checkPointInterval)))
headerBlock, err := pg.heimdall.rootChainBinding.HeaderBlocks(&bind.CallOpts{}, new(big.Int).SetUint64(mid*checkPointInterval))

if err != nil {
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func NewHeader(env stEnv) *types.Header {
header.Coinbase = env.Coinbase
header.Difficulty = env.Difficulty
header.GasLimit = env.GasLimit
header.Number = big.NewInt(int64(env.Number))
header.Number = new(big.Int).SetUint64(env.Number)
header.Time = env.Timestamp
header.BaseFee = env.BaseFee
header.MixDigest = env.MixDigest
Expand Down
16 changes: 8 additions & 8 deletions core/vm/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func BenchmarkEVM_CREATE2_1200(bench *testing.B) {
func fakeHeader(n uint64, parentHash libcommon.Hash) *types.Header {
header := types.Header{
Coinbase: libcommon.HexToAddress("0x00000000000000000000000000000000deadbeef"),
Number: big.NewInt(int64(n)),
Number: new(big.Int).SetUint64(n),
ParentHash: parentHash,
Time: n,
Nonce: types.BlockNonce{0x1},
Expand All @@ -329,7 +329,7 @@ func (cr *FakeChainHeaderReader) GetHeaderByHash(hash libcommon.Hash) *types.Hea
return nil
}
func (cr *FakeChainHeaderReader) GetHeaderByNumber(number uint64) *types.Header {
return cr.GetHeaderByHash(libcommon.BigToHash(big.NewInt(int64(number))))
return cr.GetHeaderByHash(libcommon.BigToHash(new(big.Int).SetUint64(number)))
}
func (cr *FakeChainHeaderReader) Config() *chain.Config { return nil }
func (cr *FakeChainHeaderReader) CurrentHeader() *types.Header { return nil }
Expand All @@ -340,8 +340,8 @@ func (cr *FakeChainHeaderReader) CurrentSafeHeader() *types.Header { return
func (cr *FakeChainHeaderReader) GetHeader(hash libcommon.Hash, number uint64) *types.Header {
return &types.Header{
Coinbase: libcommon.HexToAddress("0x00000000000000000000000000000000deadbeef"),
Number: big.NewInt(int64(number)),
ParentHash: libcommon.BigToHash(big.NewInt(int64(number - 1))),
Number: new(big.Int).SetUint64(number),
ParentHash: libcommon.BigToHash(new(big.Int).SetUint64(number - 1)),
Time: number,
Nonce: types.BlockNonce{0x1},
Extra: []byte{},
Expand Down Expand Up @@ -377,7 +377,7 @@ func (d *dummyChain) Engine() consensus.Engine {
func (d *dummyChain) GetHeader(h libcommon.Hash, n uint64) *types.Header {
d.counter++
parentHash := libcommon.Hash{}
s := common.LeftPadBytes(big.NewInt(int64(n-1)).Bytes(), 32)
s := common.LeftPadBytes(new(big.Int).SetUint64(n-1).Bytes(), 32)
copy(parentHash[:], s)

//parentHash := libcommon.Hash{byte(n - 1)}
Expand All @@ -392,7 +392,7 @@ func TestBlockhash(t *testing.T) {
// Current head
n := uint64(1000)
parentHash := libcommon.Hash{}
s := common.LeftPadBytes(big.NewInt(int64(n-1)).Bytes(), 32)
s := common.LeftPadBytes(new(big.Int).SetUint64(n-1).Bytes(), 32)
copy(parentHash[:], s)
header := fakeHeader(n, parentHash)

Expand Down Expand Up @@ -491,10 +491,10 @@ func TestBlockHashEip2935(t *testing.T) {
// Current head
n := uint64(10000)
parentHash := libcommon.Hash{}
s := common.LeftPadBytes(big.NewInt(int64(n-1)).Bytes(), 32)
s := common.LeftPadBytes(new(big.Int).SetUint64(n-1).Bytes(), 32)
copy(parentHash[:], s)
fakeHeaderReader := &FakeChainHeaderReader{}
header := fakeHeaderReader.GetHeader(libcommon.BigToHash(big.NewInt(int64(n))), n)
header := fakeHeaderReader.GetHeader(libcommon.BigToHash(new(big.Int).SetUint64(n)), n)

chain := &dummyChain{}
cfg := &Config{
Expand Down
4 changes: 2 additions & 2 deletions eth/stagedsync/stage_bodies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestBodiesCanonical(t *testing.T) {
err = bw.MakeBodiesCanonical(tx, 1)
require.NoError(err)
}
h.Number = big.NewInt(int64(i))
h.Number = new(big.Int).SetUint64(i)
hash := h.Hash()
err = rawdb.WriteHeader(tx, h)
require.NoError(err)
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestBodiesUnwind(t *testing.T) {
defer logEvery.Stop()

for i := uint64(1); i <= 10; i++ {
h.Number = big.NewInt(int64(i))
h.Number = new(big.Int).SetUint64(i)
hash := h.Hash()
err = rawdb.WriteHeader(tx, h)
require.NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions eth/stagedsync/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func generateBlocks2(t *testing.T, from uint64, numberOfBlocks uint64, blockWrit
var oldValue, newValue uint256.Int
newValue.SetOne()
var location libcommon.Hash
location.SetBytes(big.NewInt(int64(blockNumber)).Bytes())
location.SetBytes(new(big.Int).SetUint64(blockNumber).Bytes())
if blockNumber >= from {
if err := blockWriter.WriteAccountStorage(addr, newAcc.Incarnation, &location, &oldValue, &newValue); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -245,7 +245,7 @@ func generateBlocks(t *testing.T, from uint64, numberOfBlocks uint64, stateWrite
var oldValue, newValue uint256.Int
newValue.SetOne()
var location libcommon.Hash
location.SetBytes(big.NewInt(int64(blockNumber)).Bytes())
location.SetBytes(new(big.Int).SetUint64(blockNumber).Bytes())
if blockNumber >= from {
if err := blockWriter.WriteAccountStorage(addr, newAcc.Incarnation, &location, &oldValue, &newValue); err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion polygon/bor/finality/whitelist/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ func createMockChain(start, end uint64) []*types.Header {

for i = start; i <= end; i++ {
header := &types.Header{
Number: big.NewInt(int64(i)),
Number: new(big.Int).SetUint64(i),
Time: uint64(time.Now().UnixMicro()) + i,
}
chain[idx] = header
Expand Down
2 changes: 1 addition & 1 deletion polygon/sync/canonical_chain_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (test *connectCCBTest) makeHeader(parent *types.Header, difficulty uint64)
test.currentHeaderTime++
return &types.Header{
ParentHash: parent.Hash(),
Difficulty: big.NewInt(int64(difficulty)),
Difficulty: new(big.Int).SetUint64(difficulty),
Number: big.NewInt(parent.Number.Int64() + 1),
Time: test.currentHeaderTime,
Extra: bytes.Repeat([]byte{0x00}, types.ExtraVanityLength+types.ExtraSealLength),
Expand Down
2 changes: 1 addition & 1 deletion tests/difficulty_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type difficultyTestMarshaling struct {
}

func (test *DifficultyTest) Run(config *chain.Config) error {
parentNumber := big.NewInt(int64(test.CurrentBlockNumber - 1))
parentNumber := new(big.Int).SetUint64(test.CurrentBlockNumber - 1)
parent := &types.Header{
Difficulty: test.ParentDifficulty,
Time: test.ParentTimestamp,
Expand Down
2 changes: 1 addition & 1 deletion tests/state_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func rlpHash(x interface{}) (h libcommon.Hash) {
}

func vmTestBlockHash(n uint64) libcommon.Hash {
return libcommon.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(n)).String())))
return libcommon.BytesToHash(crypto.Keccak256([]byte(new(big.Int).SetUint64(n).String())))
}

func toMessage(tx stTransaction, ps stPostState, baseFee *big.Int) (core.Message, error) {
Expand Down
2 changes: 1 addition & 1 deletion turbo/execution/eth1/eth1_utils/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func HeaderRpcToHeader(header *execution.Header) (*types.Header, error) {
ReceiptHash: gointerfaces.ConvertH256ToHash(header.ReceiptRoot),
Bloom: gointerfaces.ConvertH2048ToBloom(header.LogsBloom),
Difficulty: gointerfaces.ConvertH256ToUint256Int(header.Difficulty).ToBig(),
Number: big.NewInt(int64(header.BlockNumber)),
Number: new(big.Int).SetUint64(header.BlockNumber),
GasLimit: header.GasLimit,
GasUsed: header.GasUsed,
Time: header.Timestamp,
Expand Down
2 changes: 1 addition & 1 deletion turbo/jsonrpc/eth_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat
coinbase := parent.Coinbase
header := &types.Header{
ParentHash: parent.Hash(),
Number: big.NewInt(int64(blockNumber)),
Number: new(big.Int).SetUint64(blockNumber),
GasLimit: parent.GasLimit,
Time: timestamp,
Difficulty: parent.Difficulty,
Expand Down
4 changes: 2 additions & 2 deletions turbo/jsonrpc/eth_callMany.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func blockHeaderOverride(blockCtx *evmtypes.BlockContext, blockOverride BlockOve
blockCtx.Coinbase = *blockOverride.Coinbase
}
if blockOverride.Difficulty != nil {
blockCtx.Difficulty = big.NewInt(int64(*blockOverride.Difficulty))
blockCtx.Difficulty = new(big.Int).SetUint64(uint64(*blockOverride.Difficulty))
}
if blockOverride.Timestamp != nil {
blockCtx.Time = uint64(*blockOverride.Timestamp)
Expand Down Expand Up @@ -237,7 +237,7 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont
blockCtx.Coinbase = *bundle.BlockOverride.Coinbase
}
if bundle.BlockOverride.Difficulty != nil {
blockCtx.Difficulty = big.NewInt(int64(*bundle.BlockOverride.Difficulty))
blockCtx.Difficulty = new(big.Int).SetUint64(uint64(*bundle.BlockOverride.Difficulty))
}
if bundle.BlockOverride.Timestamp != nil {
blockCtx.Time = uint64(*bundle.BlockOverride.Timestamp)
Expand Down
2 changes: 1 addition & 1 deletion turbo/jsonrpc/eth_mining_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestPendingBlock(t *testing.T) {
api := NewEthAPI(NewBaseApi(ff, stateCache, m.BlockReader, nil, false, rpccfg.DefaultEvmCallTimeout, engine,
m.Dirs), nil, nil, nil, mining, 5000000, 1e18, 100_000, false, 100_000, 128, log.New())
expect := uint64(12345)
b, err := rlp.EncodeToBytes(types.NewBlockWithHeader(&types.Header{Number: big.NewInt(int64(expect))}))
b, err := rlp.EncodeToBytes(types.NewBlockWithHeader(&types.Header{Number: new(big.Int).SetUint64(expect)}))
require.NoError(t, err)
ch, id := ff.SubscribePendingBlock(1)
defer ff.UnsubscribePendingBlock(id)
Expand Down
Loading