Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
account for fee recipient to be same as coinbase
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Aug 9, 2024
1 parent 40c98f6 commit 921c834
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 921c834

Please sign in to comment.