Skip to content

Commit

Permalink
config fix + support post london free txs
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Mar 6, 2024
1 parent 4f94872 commit fb7fbb2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
6 changes: 0 additions & 6 deletions consensus/aura/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,6 @@ func (s *ValidatorSafeContract) onEpochBegin(firstInEpoch bool, header *types.He
}

func (s *ValidatorSafeContract) signalEpochEnd(firstInEpoch bool, header *types.Header, r types.Receipts) ([]byte, error) {
if header.Number.Uint64() >= DEBUG_LOG_FROM {
fmt.Printf("signalEpochEnd: %d,%t\n", header.Number.Uint64(), firstInEpoch)
}
// transition to the first block of a contract requires finality but has no log event.
if firstInEpoch {
/*
Expand All @@ -695,9 +692,6 @@ func (s *ValidatorSafeContract) signalEpochEnd(firstInEpoch bool, header *types.

_, ok := s.extractFromEvent(header, r)
if !ok {
if header.Number.Uint64() >= DEBUG_LOG_FROM {
fmt.Printf("signalEpochEnd: no-no-no %d,%d\n", header.Number.Uint64(), len(r))
}
return nil, nil
}
proof, err := rlp.EncodeToBytes(ValidatorSetProof{Header: header, Receipts: r})
Expand Down
2 changes: 1 addition & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
return common.Hash{}, fmt.Errorf("commit aborted due to earlier error: %v", s.dbErr)
}
// Finalize any pending changes and merge everything into the tries
s.IntermediateRoot(deleteEmptyObjects)
s.IntermediateRoot(false)

// Commit objects to the trie, measuring the elapsed time
var (
Expand Down
27 changes: 24 additions & 3 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
}
statedb.SetTxContext(tx.Hash(), i)
receipt, err := applyTransaction(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv)
receipt, err := applyTransaction(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv, p.engine)
if err != nil {
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
}
Expand All @@ -136,7 +136,28 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
return receipts, allLogs, *usedGas, nil
}

func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, error) {
func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM, engine consensus.Engine) (*types.Receipt, error) {
if config.IsLondon(blockNumber) {
switch engine := engine.(type) {
case *beacon.Beacon:
if a, ok := engine.InnerEngine().(*aura.AuRa); ok && msg.GasFeeCap.BitLen() == 0 {
if a.IsServiceTransaction(msg.From) {
msg.SetFree()
}
}
case *aura.AuRa:
if msg.GasFeeCap.BitLen() == 0 {
if engine.IsServiceTransaction(msg.From) {
msg.SetFree()
}
}
}
if a, ok := engine.(*aura.AuRa); engine != nil && msg.GasFeeCap.BitLen() == 0 && ok {
if a.IsServiceTransaction(msg.From) {
msg.SetFree()
}
}
}
// Create a new context to be used in the EVM environment.
txContext := NewEVMTxContext(msg)
evm.Reset(txContext, statedb)
Expand Down Expand Up @@ -199,7 +220,7 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
blockContext := NewEVMBlockContext(header, bc, author)
txContext := NewEVMTxContext(msg)
vmenv := vm.NewEVM(blockContext, txContext, statedb, config, cfg)
return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv)
return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv, nil)
}

// ProcessBeaconBlockRoot applies the EIP-4788 system call to the beacon block root
Expand Down
16 changes: 13 additions & 3 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ type Message struct {
// account nonce in state. It also disables checking that the sender is an EOA.
// This field will be set to true for operations like RPC eth_call.
SkipAccountChecks bool

isFree bool
}

func (msg *Message) SetFree() {
msg.isFree = true
}

func (msg *Message) IsFree() bool {
return msg.isFree
}

// TransactionToMessage converts a transaction into a Message.
Expand Down Expand Up @@ -307,7 +317,7 @@ func (st *StateTransition) preCheck() error {
}
// This will panic if baseFee is nil, but basefee presence is verified
// as part of header validation.
if msg.GasFeeCap.Cmp(st.evm.Context.BaseFee) < 0 {
if msg.GasFeeCap.Cmp(st.evm.Context.BaseFee) < 0 && !msg.IsFree() {
return fmt.Errorf("%w: address %v, maxFeePerGas: %s, baseFee: %s", ErrFeeCapTooLow,
msg.From.Hex(), msg.GasFeeCap, st.evm.Context.BaseFee)
}
Expand Down Expand Up @@ -429,7 +439,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
gasRefund = st.refundGas(params.RefundQuotientEIP3529)
}
effectiveTip := msg.GasPrice
if rules.IsLondon {
if rules.IsLondon && !msg.IsFree() {
effectiveTip = cmath.BigMin(msg.GasTipCap, new(big.Int).Sub(msg.GasFeeCap, st.evm.Context.BaseFee))
}

Expand All @@ -442,7 +452,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
// are 0. This avoids a negative effectiveTip being applied to
// the coinbase when simulating calls.
} else {
if rules.IsLondon {
if rules.IsLondon && !msg.IsFree() {
burntContractAddress := *st.evm.ChainConfig().Aura.Eip1559FeeCollector
burnAmount := new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.evm.Context.BaseFee)
st.state.AddBalance(burntContractAddress, burnAmount)
Expand Down
2 changes: 1 addition & 1 deletion params/chainspecs/gnosis.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
}
},
"eip1559FeeCollectorTransition": 19040000,
"eip1559FeeCollector": "0x6BBe78ee9e474842Dbd4AB4987b3CeFE88426A92",
"eip1559FeeCollector": "0x6BBe78ee9e474842Dbd4AB4987b3CeFE88426A92"
}
}

0 comments on commit fb7fbb2

Please sign in to comment.