Skip to content

Commit

Permalink
Fixes for PR review.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Sep 20, 2023
1 parent 689ed5f commit ed876be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion go/enclave/components/batch_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ func (executor *batchExecutor) payL1Fees(stateDB *state.StateDB, context *BatchE
}
accBalance := stateDB.GetBalance(*sender)

cost, err := executor.gasOracle.GetGasCostForTx(tx, block)
cost, err := executor.gasOracle.EstimateL1StorageGasCost(tx, block)
if err != nil {
executor.logger.Warn("Unable to get gas cost for tx", log.TxKey, tx.Hash(), log.ErrKey, err)
continue
}

// Transactions that are created inside the enclave can have no GasPrice set.
// External transactions are always required to have a gas price set. Thus we filter
// those transactions for separate processing than the normal ones and we run them through the EVM
// with a flag that disables the baseFee logic and wont fail them for having price lower than the base fee.
isFreeTransaction := tx.GasFeeCap().Cmp(gethcommon.Big0) == 0
isFreeTransaction = isFreeTransaction && tx.GasPrice().Cmp(gethcommon.Big0) == 0

Expand All @@ -96,6 +100,7 @@ func (executor *batchExecutor) payL1Fees(stateDB *state.StateDB, context *BatchE
}
stateDB.SubBalance(*sender, cost)
stateDB.AddBalance(context.Creator, cost)
//todo - add refund logic.

transactions = append(transactions, tx)
}
Expand Down
9 changes: 5 additions & 4 deletions go/enclave/gas/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ func (gp *ObscuroGasPool) ForTransaction(tx *types.Transaction) (*gethcore.GasPo

// CalculateL1GasUsed - calculates the gas cost of having a transaction on the l1.
func CalculateL1GasUsed(data []byte, overhead *big.Int) *big.Int {
zeroes, ones := zeroesAndOnes(data)
zeroesGas := zeroes * params.TxDataZeroGas
onesGas := (ones + 68) * params.TxDataNonZeroGasEIP2028
l1Gas := new(big.Int).SetUint64(zeroesGas + onesGas)
reducedTxSize := uint64(len(data))
reducedTxSize = (reducedTxSize * 75) / 100
reducedTxSize = reducedTxSize * params.TxDataNonZeroGasEIP2028

l1Gas := new(big.Int).SetUint64(reducedTxSize)
return new(big.Int).Add(l1Gas, overhead)
}

Expand Down
6 changes: 3 additions & 3 deletions go/enclave/gas/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// which will expose necessary l1 information.
type Oracle interface {
ProcessL1Block(block *types.Block)
GetGasCostForTx(tx *types.Transaction, block *types.Block) (*big.Int, error)
EstimateL1StorageGasCost(tx *types.Transaction, block *types.Block) (*big.Int, error)
}

type oracle struct {
Expand All @@ -34,8 +34,8 @@ func (o *oracle) ProcessL1Block(block *types.Block) {
}
}

// GetGasCostForTx - Returns the expected l1 gas cost for a transaction at a given l1 block.
func (o *oracle) GetGasCostForTx(tx *types.Transaction, block *types.Block) (*big.Int, error) {
// EstimateL1StorageGasCost - Returns the expected l1 gas cost for a transaction at a given l1 block.
func (o *oracle) EstimateL1StorageGasCost(tx *types.Transaction, block *types.Block) (*big.Int, error) {
encodedTx, err := rlp.EncodeToBytes(tx)
if err != nil {
return nil, err
Expand Down

0 comments on commit ed876be

Please sign in to comment.