Skip to content

Commit

Permalink
Merge pull request ethereum#56 from OffchainLabs/l2-tips
Browse files Browse the repository at this point in the history
Allow Tips in L2
  • Loading branch information
hkalodner authored Feb 23, 2022
2 parents b34151e + e55e631 commit edf6a19
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 39 deletions.
12 changes: 5 additions & 7 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,6 @@ func (st *StateTransition) transitionDbImpl() (*ExecutionResult, error) {
// 5. there is no overflow when calculating intrinsic gas
// 6. caller has enough balance to cover asset transfer for **topmost** call

// There are no tips in L2
if st.evm.ChainConfig().IsArbitrum() && st.gasPrice.Cmp(st.evm.Context.BaseFee) > 0 {
st.gasPrice = st.evm.Context.BaseFee
}

// Check clauses 1-3, buy gas if everything is correct
if err := st.preCheck(); err != nil {
return nil, err
Expand All @@ -320,7 +315,7 @@ func (st *StateTransition) transitionDbImpl() (*ExecutionResult, error) {
}
st.gas -= gas

err = st.evm.ProcessingHook.GasChargingHook(&st.gas)
tipRecipient, err := st.evm.ProcessingHook.GasChargingHook(&st.gas)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -357,7 +352,10 @@ func (st *StateTransition) transitionDbImpl() (*ExecutionResult, error) {
if london {
effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
}
st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip))
if tipRecipient == nil {
tipRecipient = &st.evm.Context.Coinbase
}
st.state.AddBalance(*tipRecipient, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip))

return &ExecutionResult{
UsedGas: st.gasUsed(),
Expand Down
13 changes: 0 additions & 13 deletions core/types/arb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,3 @@ func (d *ArbitrumInternalTx) rawSignatureValues() (v, r, s *big.Int) {
func (d *ArbitrumInternalTx) setSignatureValues(chainID, v, r, s *big.Int) {

}

type ArbitrumWrappedTx struct {
l1Calldata uint64
TxData
}

func (tx *ArbitrumWrappedTx) copy() TxData {
cpy := &ArbitrumWrappedTx{
l1Calldata: tx.l1Calldata,
TxData: tx.TxData.copy(),
}
return cpy
}
18 changes: 2 additions & 16 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const (
ArbitrumDepositTxType = 100
ArbitrumUnsignedTxType = 101
ArbitrumContractTxType = 102
ArbitrumWrappedTxType = 103
ArbitrumRetryTxType = 104
ArbitrumSubmitRetryableTxType = 105
ArbitrumInternalTxType = 106
Expand Down Expand Up @@ -99,7 +98,7 @@ type TxData interface {

// EncodeRLP implements rlp.Encoder
func (tx *Transaction) EncodeRLP(w io.Writer) error {
if tx.realType() == LegacyTxType {
if tx.Type() == LegacyTxType {
return rlp.Encode(w, tx.inner)
}
// It's an EIP-2718 typed TX envelope.
Expand All @@ -114,7 +113,7 @@ func (tx *Transaction) EncodeRLP(w io.Writer) error {

// encodeTyped writes the canonical encoding of a typed transaction to w.
func (tx *Transaction) encodeTyped(w *bytes.Buffer) error {
w.WriteByte(tx.realType())
w.WriteByte(tx.Type())
return rlp.Encode(w, tx.inner)
}

Expand Down Expand Up @@ -205,10 +204,6 @@ func (tx *Transaction) decodeTyped(b []byte, arbParsing bool) (TxData, error) {
var inner ArbitrumContractTx
err := rlp.DecodeBytes(b[1:], &inner)
return &inner, err
case ArbitrumWrappedTxType:
var inner ArbitrumWrappedTx
err := rlp.DecodeBytes(b[1:], &inner)
return &inner, err
case ArbitrumRetryTxType:
var inner ArbitrumRetryTx
err := rlp.DecodeBytes(b[1:], &inner)
Expand Down Expand Up @@ -296,15 +291,6 @@ func (tx *Transaction) Type() uint8 {
return tx.inner.txType()
}

func (tx *Transaction) realType() uint8 {
_, isArbWrapped := tx.inner.(*ArbitrumWrappedTx)
if isArbWrapped {
return ArbitrumWrappedTxType
} else {
return tx.Type()
}
}

func (tx *Transaction) GetInner() TxData {
return tx.inner.copy()
}
Expand Down
6 changes: 3 additions & 3 deletions core/vm/evm_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (evm *EVM) Depth() int {

type TxProcessingHook interface {
StartTxHook() (bool, uint64, error, []byte) // return 4-tuple rather than *struct to avoid an import cycle
GasChargingHook(gasRemaining *uint64) error
GasChargingHook(gasRemaining *uint64) (*common.Address, error)
PushCaller(addr common.Address)
PopCaller()
ForceRefundGas() uint64
Expand All @@ -45,8 +45,8 @@ func (p DefaultTxProcessor) StartTxHook() (bool, uint64, error, []byte) {
return false, 0, nil, nil
}

func (p DefaultTxProcessor) GasChargingHook(gasRemaining *uint64) error {
return nil
func (p DefaultTxProcessor) GasChargingHook(gasRemaining *uint64) (*common.Address, error) {
return nil, nil
}

func (p DefaultTxProcessor) PushCaller(addr common.Address) {
Expand Down

0 comments on commit edf6a19

Please sign in to comment.