From 921c83498b15eb30366638ffa7b285ab2faf992d Mon Sep 17 00:00:00 2001 From: avalonche Date: Fri, 9 Aug 2024 10:20:48 +1000 Subject: [PATCH] account for fee recipient to be same as coinbase --- core/blockchain.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 9eeca47ec..0a60f3125 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2545,13 +2545,7 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad if feeRecipientBalanceDelta.Cmp(uint256ExpectedProfit) > 0 { log.Warn("builder claimed profit is lower than calculated profit", "expected", expectedProfit, "actual", feeRecipientBalanceDelta) } - trueBlockValue := new(big.Int).Add(builderBalanceDelta, feeRecipientBalanceDelta.ToBig()) - uint256TrueBlockValue, overflow := uint256.FromBig(trueBlockValue) - if overflow { - log.Warn("true block value overflow when converting to uint256", "value", trueBlockValue) - return nil, nil - } - return uint256TrueBlockValue, nil + return bc.calculateTrueBlockValue(builderBalanceDelta, feeRecipientBalanceDelta.ToBig(), feeRecipient == header.Coinbase) } log.Warn("proposer payment not enough, trying last tx payment validation", "expected", expectedProfit, "actual", feeRecipientBalanceDelta) } @@ -2600,13 +2594,24 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad return nil, fmt.Errorf("malformed proposer payment, unexpected gas fee cap") } - trueBlockValue := new(big.Int).Add(builderBalanceDelta, paymentTx.Value()) + return bc.calculateTrueBlockValue(builderBalanceDelta, paymentTx.Value(), feeRecipient == header.Coinbase) +} + +func (bc *BlockChain) calculateTrueBlockValue(builderBalanceDelta, proposerPaymentValue *big.Int, feeRecipientIsCoinbase bool) (*uint256.Int, error) { + if feeRecipientIsCoinbase { + uint256ProposerPaymentValue, overflow := uint256.FromBig(proposerPaymentValue) + if overflow { + log.Warn("proposer payment value overflow when converting to uint256", "value", proposerPaymentValue) + return nil, nil + } + return uint256ProposerPaymentValue, nil + } + trueBlockValue := new(big.Int).Add(builderBalanceDelta, proposerPaymentValue) uint256TrueBlockValue, overflow := uint256.FromBig(trueBlockValue) if overflow { log.Warn("true block value overflow when converting to uint256", "value", trueBlockValue) return nil, nil } - return uint256TrueBlockValue, nil }