Skip to content

Commit 28a3dcf

Browse files
metachrisababino
andauthored
fix: builder profit (#69)
* fix: builder profit * Apply suggestion from @ababino Co-authored-by: Andrés Babino <ababino@gmail.com> * vars * fixed * final fixes --------- Co-authored-by: Andrés Babino <ababino@gmail.com>
1 parent 3aa5172 commit 28a3dcf

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

cmd/core/check-payload-value.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ func startUpdateWorker(wg *sync.WaitGroup, db *database.DatabaseService, client,
319319
// check for transactions to/from proposer feeRecipient
320320
if checkTx {
321321
log.Infof("checking %d tx...", len(txs))
322+
322323
for i, tx := range txs {
324+
if tx.ChainId().Uint64() == 0 {
325+
continue
326+
}
323327
txFrom, _ := types.Sender(types.LatestSignerForChainID(tx.ChainId()), tx)
324328
if txFrom.Hex() == entry.ProposerFeeRecipient {
325329
_log.Infof("- tx %d from feeRecipient with value %s", i, tx.Value().String())
@@ -369,12 +373,35 @@ func startUpdateWorker(wg *sync.WaitGroup, db *database.DatabaseService, client,
369373
}).Info("value check done")
370374

371375
if !coinbaseIsProposer {
372-
// Get builder balance diff
376+
// Get builder profit/subsidy, taking into account possible tx from coinbase to builder-owned address
377+
// First, get the overall balance diff
373378
builderBalanceDiffWei, err := getBalanceDiff(block.Coinbase(), block.Number())
374379
if err != nil {
375380
_log.WithError(err).Fatalf("couldn't get balance diff")
376381
}
377-
// fmt.Println("builder diff", block.Miner, builderBalanceDiffWei)
382+
383+
// Second, adjust for any tx from coinbase to builder-owned address.
384+
builderOwnedAddresses := vars.BuilderAddresses[strings.ToLower(block.Coinbase().Hex())]
385+
_log.Infof("builderOwnedAddresses for %s: %+v (slot %d)", block.Coinbase().Hex(), builderOwnedAddresses, entry.Slot)
386+
for _, tx := range txs {
387+
if tx.ChainId().Uint64() == 0 {
388+
continue
389+
}
390+
391+
txFrom, _ := types.Sender(types.LatestSignerForChainID(tx.ChainId()), tx)
392+
isFromBuilderCoinbase := txFrom.Hex() == block.Coinbase().Hex()
393+
isToBuilderOwnedAddress := false
394+
if builderOwnedAddresses != nil && tx.To() != nil && builderOwnedAddresses[strings.ToLower(tx.To().Hex())] {
395+
isToBuilderOwnedAddress = true
396+
}
397+
398+
if isFromBuilderCoinbase && isToBuilderOwnedAddress {
399+
_log.Infof("- Tx from coinbase to builder address found: %s -- adjusting value by +%s ETH", tx.Hash().Hex(), common.WeiToEth(tx.Value()).String())
400+
builderBalanceDiffWei = new(big.Int).Add(builderBalanceDiffWei, tx.Value())
401+
}
402+
}
403+
404+
// save
378405
entry.CoinbaseDiffWei = database.NewNullString(builderBalanceDiffWei.String())
379406
entry.CoinbaseDiffEth = database.NewNullString(common.WeiToEth(builderBalanceDiffWei).String())
380407
}

vars/builder_addresses.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package vars
2+
3+
var BuilderAddresses = map[string]map[string]bool{ // coinbase: owned addresses
4+
"0xdadb0d80178819f2319190d340ce9a924f783711": {
5+
"0x59cadf9199248b50d40a6891c9e329ea13a88d31": true,
6+
},
7+
}

0 commit comments

Comments
 (0)