Skip to content

Commit 0a2e73e

Browse files
authored
Allow negative coinbase profit in Order::Tx and Order::Bundle (#233)
When disallowed for all `Order` varients, the coinbase account has no way to spend funds when rbuilder is building all blocks for a chain. Instead of using saturating_sub, I also tried changing `coinbase_profit` from a `U256` to an `I256`, but ran into issues where a `U256` is required to calculate stuff like `mev_gas_price` in later logic. I'd prefer that approach if anyone knows if it is feasible.
1 parent e79af73 commit 0a2e73e

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

crates/rbuilder/src/building/order_commit.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,16 +1011,11 @@ impl<'a, 'b, Tracer: SimulationTracer> PartialBlockFork<'a, 'b, Tracer> {
10111011
)?;
10121012
match res {
10131013
Ok(ok) => {
1014+
// Builder does not sign txs in this code path, so allow negative coinbase
1015+
// profit.
10141016
let coinbase_balance_after = self.state.balance(ctx.block_env.coinbase)?;
1015-
let coinbase_profit = match coinbase_profit(
1016-
coinbase_balance_before,
1017-
coinbase_balance_after,
1018-
) {
1019-
Ok(profit) => profit,
1020-
Err(err) => {
1021-
return Ok(Err(err));
1022-
}
1023-
};
1017+
let coinbase_profit =
1018+
coinbase_balance_after.saturating_sub(coinbase_balance_before);
10241019
Ok(Ok(OrderOk {
10251020
coinbase_profit,
10261021
gas_used: ok.gas_used,
@@ -1049,16 +1044,11 @@ impl<'a, 'b, Tracer: SimulationTracer> PartialBlockFork<'a, 'b, Tracer> {
10491044
)?;
10501045
match res {
10511046
Ok(ok) => {
1047+
// Builder does not sign txs in this code path, so allow negative coinbase
1048+
// profit.
10521049
let coinbase_balance_after = self.state.balance(ctx.block_env.coinbase)?;
1053-
let coinbase_profit = match coinbase_profit(
1054-
coinbase_balance_before,
1055-
coinbase_balance_after,
1056-
) {
1057-
Ok(profit) => profit,
1058-
Err(err) => {
1059-
return Ok(Err(err));
1060-
}
1061-
};
1050+
let coinbase_profit =
1051+
coinbase_balance_after.saturating_sub(coinbase_balance_before);
10621052
Ok(Ok(OrderOk {
10631053
coinbase_profit,
10641054
gas_used: ok.gas_used,
@@ -1088,6 +1078,8 @@ impl<'a, 'b, Tracer: SimulationTracer> PartialBlockFork<'a, 'b, Tracer> {
10881078
match res {
10891079
Ok(ok) => {
10901080
let coinbase_balance_after = self.state.balance(ctx.block_env.coinbase)?;
1081+
// Builder does sign txs in this code path, so do not allow negative coinbase
1082+
// profit.
10911083
let coinbase_profit = match coinbase_profit(
10921084
coinbase_balance_before,
10931085
coinbase_balance_after,

0 commit comments

Comments
 (0)