|
2 | 2 | use crate::{ |
3 | 3 | api::exec::OpContextTr, |
4 | 4 | constants::{BASE_FEE_RECIPIENT, L1_FEE_RECIPIENT, OPERATOR_FEE_RECIPIENT}, |
5 | | - sgt::{add_sgt_balance, deduct_sgt_balance, read_sgt_balance}, |
| 5 | + sgt::{add_sgt_balance, collect_native_balance, deduct_sgt_balance, read_sgt_balance}, |
6 | 6 | transaction::{deposit::DEPOSIT_TRANSACTION_TYPE, OpTransactionError, OpTxTr}, |
7 | 7 | L1BlockInfo, OpHaltReason, OpSpecId, |
8 | 8 | }; |
@@ -430,7 +430,32 @@ where |
430 | 430 | return Ok(()); |
431 | 431 | } |
432 | 432 |
|
433 | | - self.mainnet.reward_beneficiary(evm, frame_result)?; |
| 433 | + // Call post_execution::reward_beneficiary directly to get the coinbase fee amount |
| 434 | + let coinbase_fee = post_execution::reward_beneficiary(evm.ctx(), frame_result.gas()) |
| 435 | + .map_err(|e| ERROR::from(ContextError::Db(e)))?; |
| 436 | + |
| 437 | + let is_sgt = evm.ctx().cfg().is_sgt_enabled(); |
| 438 | + let is_native_backed = evm.ctx().cfg().is_sgt_native_backed(); |
| 439 | + |
| 440 | + // SGT: burn the non-native portion of the coinbase fee |
| 441 | + if is_sgt { |
| 442 | + let chain = evm.ctx().chain_mut(); |
| 443 | + let actual = collect_native_balance( |
| 444 | + coinbase_fee, |
| 445 | + is_native_backed, |
| 446 | + &mut chain.sgt_amount_deducted, |
| 447 | + &mut chain.sgt_native_deducted, |
| 448 | + ); |
| 449 | + let burned = coinbase_fee.saturating_sub(actual); |
| 450 | + if !burned.is_zero() { |
| 451 | + let beneficiary = evm.ctx().block().beneficiary(); |
| 452 | + evm.ctx() |
| 453 | + .journal_mut() |
| 454 | + .load_account_mut(beneficiary)? |
| 455 | + .decr_balance(burned); |
| 456 | + } |
| 457 | + } |
| 458 | + |
434 | 459 | let basefee = evm.ctx().block().basefee() as u128; |
435 | 460 |
|
436 | 461 | // If the transaction is not a deposit transaction, fees are paid out |
@@ -458,13 +483,24 @@ where |
458 | 483 | }; |
459 | 484 | let base_fee_amount = U256::from(basefee.saturating_mul(frame_result.gas().used() as u128)); |
460 | 485 |
|
461 | | - // Send fees to their respective recipients |
| 486 | + // Send fees to their respective recipients, applying SGT burning if enabled |
462 | 487 | for (recipient, amount) in [ |
463 | 488 | (L1_FEE_RECIPIENT, l1_cost), |
464 | 489 | (BASE_FEE_RECIPIENT, base_fee_amount), |
465 | 490 | (OPERATOR_FEE_RECIPIENT, operator_fee_cost), |
466 | 491 | ] { |
467 | | - ctx.journal_mut().balance_incr(recipient, amount)?; |
| 492 | + let actual = if is_sgt { |
| 493 | + let chain = ctx.chain_mut(); |
| 494 | + collect_native_balance( |
| 495 | + amount, |
| 496 | + is_native_backed, |
| 497 | + &mut chain.sgt_amount_deducted, |
| 498 | + &mut chain.sgt_native_deducted, |
| 499 | + ) |
| 500 | + } else { |
| 501 | + amount |
| 502 | + }; |
| 503 | + ctx.journal_mut().balance_incr(recipient, actual)?; |
468 | 504 | } |
469 | 505 |
|
470 | 506 | Ok(()) |
|
0 commit comments