From b07c8febdc02328a13644595b1661a3d1482383a Mon Sep 17 00:00:00 2001 From: Cara Wang Date: Tue, 21 Mar 2023 13:32:45 +0800 Subject: [PATCH 1/7] metrics, core: fix G601 and goimports issues (cherry picked from commit ae568b6f261df246197084261b39fc381495b39b) --- core/state_transition.go | 5 +++-- metrics/chunked_associative_array.go | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 9f8e797d2c9b..0a612cdb0ec0 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -461,9 +461,10 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { // Arbitrum: record self destructs if st.evm.Config.Debug { - for _, address := range st.evm.StateDB.GetSuicides() { + suicides := st.evm.StateDB.GetSuicides() + for i, address := range suicides { balance := st.evm.StateDB.GetBalance(address) - st.evm.Config.Tracer.CaptureArbitrumTransfer(st.evm, &address, nil, balance, false, "selfDestruct") + st.evm.Config.Tracer.CaptureArbitrumTransfer(st.evm, &suicides[i], nil, balance, false, "selfDestruct") } } diff --git a/metrics/chunked_associative_array.go b/metrics/chunked_associative_array.go index caaa1af4b1c4..6197c68c5c3d 100644 --- a/metrics/chunked_associative_array.go +++ b/metrics/chunked_associative_array.go @@ -4,10 +4,11 @@ package metrics // https://github.com/dropwizard/metrics/blob/release/4.2.x/metrics-core/src/main/java/com/codahale/metrics/ChunkedAssociativeLongArray.java import ( - "github.com/gammazero/deque" "sort" "strconv" "strings" + + "github.com/gammazero/deque" ) const ( From 7737b8a078f75e778998b542c15534cb2bfeb157 Mon Sep 17 00:00:00 2001 From: Cara Wang Date: Tue, 21 Mar 2023 13:25:24 +0800 Subject: [PATCH 2/7] *: fix S1009, S1023, and SA4023 lint issues (cherry picked from commit 1eee4fec17377f6ddb1e329a7ca9cd03b5b9d05a) --- arbitrum/apibackend.go | 4 ++-- arbitrum/recordingdb.go | 4 +--- internal/ethapi/api.go | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arbitrum/apibackend.go b/arbitrum/apibackend.go index b690a990e770..39637df7b2b5 100644 --- a/arbitrum/apibackend.go +++ b/arbitrum/apibackend.go @@ -68,7 +68,7 @@ func CreateFallbackClient(fallbackClientUrl string, fallbackClientTimeout time.D var fallbackClient types.FallbackClient var err error fallbackClient, err = rpc.Dial(fallbackClientUrl) - if fallbackClient == nil || err != nil { + if err != nil { return nil, fmt.Errorf("failed creating fallback connection: %w", err) } if fallbackClientTimeout != 0 { @@ -160,7 +160,7 @@ func (a *APIBackend) SyncProgressMap() map[string]interface{} { func (a *APIBackend) SyncProgress() ethereum.SyncProgress { progress := a.sync.SyncProgressMap() - if progress == nil || len(progress) == 0 { + if len(progress) == 0 { return ethereum.SyncProgress{} } return ethereum.SyncProgress{ diff --git a/arbitrum/recordingdb.go b/arbitrum/recordingdb.go index 970b19070798..ade89b079521 100644 --- a/arbitrum/recordingdb.go +++ b/arbitrum/recordingdb.go @@ -113,9 +113,7 @@ func (db *RecordingKV) Close() error { return nil } -func (db *RecordingKV) Release() { - return -} +func (db *RecordingKV) Release() {} func (db *RecordingKV) GetRecordedEntries() map[common.Hash][]byte { return db.readDbEntries diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 72978180bf20..b88e98a30d22 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -132,7 +132,7 @@ func (s *EthereumAPI) FeeHistory(ctx context.Context, blockCount math.HexOrDecim func (s *EthereumAPI) Syncing() (interface{}, error) { progress := s.b.SyncProgressMap() - if progress == nil || len(progress) == 0 { + if len(progress) == 0 { return false, nil } return progress, nil From 4658cb3debac2e3429aa8b67a1bbc811fb70dd74 Mon Sep 17 00:00:00 2001 From: Cara Wang Date: Wed, 22 Mar 2023 12:15:13 +0800 Subject: [PATCH 3/7] core/state: check amount object existence (cherry picked from commit 3017631e6a15114a1a28eee3d733ebfa90b20ef8) --- core/state/statedb.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index b4874fb7bfec..f8dc8647a118 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -430,9 +430,11 @@ func (s *StateDB) SubBalance(addr common.Address, amount *big.Int) { func (s *StateDB) SetBalance(addr common.Address, amount *big.Int) { stateObject := s.GetOrNewStateObject(addr) if stateObject != nil { - prevBalance := stateObject.Balance() - s.unexpectedBalanceDelta.Add(s.unexpectedBalanceDelta, amount) - s.unexpectedBalanceDelta.Sub(s.unexpectedBalanceDelta, prevBalance) + if amount != nil { + prevBalance := stateObject.Balance() + s.unexpectedBalanceDelta.Add(s.unexpectedBalanceDelta, amount) + s.unexpectedBalanceDelta.Sub(s.unexpectedBalanceDelta, prevBalance) + } stateObject.SetBalance(amount) } From 585143aed61abf43db094040754d1cf10d3125fe Mon Sep 17 00:00:00 2001 From: Cara Wang Date: Wed, 22 Mar 2023 02:05:54 +0800 Subject: [PATCH 4/7] eth/tracers: pass config to callTracer (cherry picked from commit e6e6f4dc9adc8e54db5fdf19a6c9e6078ead2616) --- eth/tracers/native/call.go | 1 + 1 file changed, 1 insertion(+) diff --git a/eth/tracers/native/call.go b/eth/tracers/native/call.go index d73d013b81c1..f4a04fac196f 100644 --- a/eth/tracers/native/call.go +++ b/eth/tracers/native/call.go @@ -133,6 +133,7 @@ func newCallTracer(ctx *tracers.Context, cfg json.RawMessage) (tracers.Tracer, e // and is populated on start and end. return &callTracer{ callstack: make([]callFrame, 1), + config: config, beforeEVMTransfers: []arbitrumTransfer{}, afterEVMTransfers: []arbitrumTransfer{}, }, nil From e58f822090b692fd0b9085035ee02f568b676304 Mon Sep 17 00:00:00 2001 From: Cara Wang Date: Tue, 21 Mar 2023 12:05:53 +0800 Subject: [PATCH 5/7] *: fix misspelling and unnecessary conversion (cherry picked from commit e994cec799736a67fa95142993f0262f542d6298) Reapplied with some conflict resolution around transaction_marshalling.go --- arbitrum/apibackend.go | 2 +- arbitrum/recordingdb.go | 2 +- core/types/transaction_marshalling.go | 4 ++-- core/vm/logger.go | 2 +- eth/tracers/native/call.go | 2 +- internal/ethapi/api.go | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arbitrum/apibackend.go b/arbitrum/apibackend.go index 39637df7b2b5..3ec872a0afe5 100644 --- a/arbitrum/apibackend.go +++ b/arbitrum/apibackend.go @@ -218,7 +218,7 @@ func (a *APIBackend) FeeHistory( // use the most recent average compute rate for all blocks // note: while we could query this value for each block, it'd be prohibitively expensive - state, _, err := a.StateAndHeaderByNumber(ctx, rpc.BlockNumber(newestBlock)) + state, _, err := a.StateAndHeaderByNumber(ctx, newestBlock) if err != nil { return common.Big0, nil, nil, nil, err } diff --git a/arbitrum/recordingdb.go b/arbitrum/recordingdb.go index ade89b079521..b90239c5dcd3 100644 --- a/arbitrum/recordingdb.go +++ b/arbitrum/recordingdb.go @@ -320,7 +320,7 @@ func (r *RecordingDatabase) GetOrRecreateState(ctx context.Context, header *type } err = r.addStateVerify(stateDb, block.Root()) if err != nil { - return nil, fmt.Errorf("failed commiting state for block %d : %w", blockToRecreate, err) + return nil, fmt.Errorf("failed committing state for block %d : %w", blockToRecreate, err) } r.dereferenceRoot(lastRoot) lastRoot = block.Root() diff --git a/core/types/transaction_marshalling.go b/core/types/transaction_marshalling.go index 6e598cbd9f3b..e9b5fbc77fda 100644 --- a/core/types/transaction_marshalling.go +++ b/core/types/transaction_marshalling.go @@ -145,7 +145,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) { enc.Value = (*hexutil.Big)(itx.Value) enc.To = tx.To() case *ArbitrumUnsignedTx: - enc.From = (*common.Address)(&itx.From) + enc.From = &itx.From enc.ChainID = (*hexutil.Big)(itx.ChainId) enc.Nonce = (*hexutil.Uint64)(&itx.Nonce) enc.Gas = (*hexutil.Uint64)(&itx.Gas) @@ -163,7 +163,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) { enc.Data = (*hexutil.Bytes)(&itx.Data) enc.To = tx.To() case *ArbitrumRetryTx: - enc.From = (*common.Address)(&itx.From) + enc.From = &itx.From enc.TicketId = &itx.TicketId enc.RefundTo = &itx.RefundTo enc.ChainID = (*hexutil.Big)(itx.ChainId) diff --git a/core/vm/logger.go b/core/vm/logger.go index 3b3384b85953..f430575671fe 100644 --- a/core/vm/logger.go +++ b/core/vm/logger.go @@ -28,7 +28,7 @@ import ( // Note that reference types are actual VM data structures; make copies // if you need to retain them beyond the current call. type EVMLogger interface { - // Arbitrum: capture a transfer, mint, or burn that happens outside of EVM exectuion + // Arbitrum: capture a transfer, mint, or burn that happens outside of EVM execution CaptureArbitrumTransfer(env *EVM, from, to *common.Address, value *big.Int, before bool, purpose string) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) diff --git a/eth/tracers/native/call.go b/eth/tracers/native/call.go index f4a04fac196f..febe796cd35e 100644 --- a/eth/tracers/native/call.go +++ b/eth/tracers/native/call.go @@ -103,7 +103,7 @@ type callFrameMarshaling struct { } type callTracer struct { - // Arbitrum: capture transfers occuring outside of evm execution + // Arbitrum: capture transfers occurring outside of evm execution beforeEVMTransfers []arbitrumTransfer afterEVMTransfers []arbitrumTransfer diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index b88e98a30d22..08c3301cadf0 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1409,7 +1409,7 @@ func (s *BlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inc if err != nil { log.Error("error trying to fill legacy l1BlockNumber", "err", err) } else { - fields["l1BlockNumber"] = hexutil.Uint64(l1BlockNumber) + fields["l1BlockNumber"] = l1BlockNumber } } return fields, err From 018bc8d4a27bfd9c260aa719cb705bee2306af83 Mon Sep 17 00:00:00 2001 From: Cara Wang Date: Tue, 21 Mar 2023 12:02:59 +0800 Subject: [PATCH 6/7] *: fix unnecessary leading newline (cherry picked from commit a75a204c18fbcdaeb411f3ac692d86d19fad4ea6) Resolved minor conflict --- arbitrum/apibackend.go | 2 -- core/state_transition.go | 1 - core/vm/instructions.go | 1 - 3 files changed, 4 deletions(-) diff --git a/arbitrum/apibackend.go b/arbitrum/apibackend.go index 3ec872a0afe5..3d64ff6efe78 100644 --- a/arbitrum/apibackend.go +++ b/arbitrum/apibackend.go @@ -179,7 +179,6 @@ func (a *APIBackend) FeeHistory( newestBlock rpc.BlockNumber, rewardPercentiles []float64, ) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) { - if core.GetArbOSSpeedLimitPerSecond == nil { return nil, nil, nil, nil, errors.New("ArbOS not installed") } @@ -284,7 +283,6 @@ func (a *APIBackend) FeeHistory( fullnessAnalogue = 1.0 } gasUsed[block-oldestBlock] = fullnessAnalogue - } if newestBlock == latestBlock { basefees[blocks] = basefees[blocks-1] // guess the basefee won't change diff --git a/core/state_transition.go b/core/state_transition.go index 0a612cdb0ec0..acc4d7f42d0d 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -478,7 +478,6 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { } func (st *StateTransition) refundGas(refundQuotient uint64) { - st.gasRemaining += st.evm.ProcessingHook.ForceRefundGas() nonrefundable := st.evm.ProcessingHook.NonrefundableGas() diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 4b91b25990e4..fb5f2423a355 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -428,7 +428,6 @@ func opExtCodeHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) } func opGasprice(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { - // Arbitrum: provide an opportunity to remove the tip from the gas price gasPrice := interpreter.evm.ProcessingHook.GasPriceOp(interpreter.evm) From a66027da6fe0244ac34f7f476442232a84c1a2d0 Mon Sep 17 00:00:00 2001 From: Tristan Wilson Date: Wed, 7 Jun 2023 09:53:32 -0700 Subject: [PATCH 7/7] Use zero amount if unset in statedb.SetBalance --- core/state/statedb.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index f8dc8647a118..36c7c0567ee6 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -430,12 +430,12 @@ func (s *StateDB) SubBalance(addr common.Address, amount *big.Int) { func (s *StateDB) SetBalance(addr common.Address, amount *big.Int) { stateObject := s.GetOrNewStateObject(addr) if stateObject != nil { - if amount != nil { - prevBalance := stateObject.Balance() - s.unexpectedBalanceDelta.Add(s.unexpectedBalanceDelta, amount) - s.unexpectedBalanceDelta.Sub(s.unexpectedBalanceDelta, prevBalance) + if amount == nil { + amount = big.NewInt(0) } - + prevBalance := stateObject.Balance() + s.unexpectedBalanceDelta.Add(s.unexpectedBalanceDelta, amount) + s.unexpectedBalanceDelta.Sub(s.unexpectedBalanceDelta, prevBalance) stateObject.SetBalance(amount) } }