@@ -69,7 +69,7 @@ func TestValidateBuilderSubmissionV1(t *testing.T) {
6969 ethservice .Merger ().ReachTTD ()
7070 defer n .Close ()
7171
72- api := NewBlockValidationAPI (ethservice , nil , true )
72+ api := NewBlockValidationAPI (ethservice , nil , true , true )
7373 parent := preMergeBlocks [len (preMergeBlocks )- 1 ]
7474
7575 api .eth .APIBackend .Miner ().SetEtherbase (testValidatorAddr )
@@ -179,7 +179,7 @@ func TestValidateBuilderSubmissionV2(t *testing.T) {
179179 ethservice .Merger ().ReachTTD ()
180180 defer n .Close ()
181181
182- api := NewBlockValidationAPI (ethservice , nil , true )
182+ api := NewBlockValidationAPI (ethservice , nil , true , true )
183183 parent := preMergeBlocks [len (preMergeBlocks )- 1 ]
184184
185185 api .eth .APIBackend .Miner ().SetEtherbase (testBuilderAddr )
@@ -623,7 +623,7 @@ func TestValidateBuilderSubmissionV2_CoinbasePaymentDefault(t *testing.T) {
623623 ethservice .Merger ().ReachTTD ()
624624 defer n .Close ()
625625
626- api := NewBlockValidationAPI (ethservice , nil , true )
626+ api := NewBlockValidationAPI (ethservice , nil , true , true )
627627
628628 baseFee := misc .CalcBaseFee (ethservice .BlockChain ().Config (), lastBlock .Header ())
629629 txs := make (types.Transactions , 0 )
@@ -735,8 +735,8 @@ func TestValidateBuilderSubmissionV2_Blocklist(t *testing.T) {
735735 },
736736 }
737737
738- apiWithBlock := NewBlockValidationAPI (ethservice , accessVerifier , true )
739- apiNoBlock := NewBlockValidationAPI (ethservice , nil , true )
738+ apiWithBlock := NewBlockValidationAPI (ethservice , accessVerifier , true , true )
739+ apiNoBlock := NewBlockValidationAPI (ethservice , nil , true , true )
740740
741741 baseFee := misc .CalcBaseFee (ethservice .BlockChain ().Config (), lastBlock .Header ())
742742 blockedTxs := make (types.Transactions , 0 )
@@ -782,3 +782,101 @@ func TestValidateBuilderSubmissionV2_Blocklist(t *testing.T) {
782782 })
783783 }
784784}
785+
786+ // This tests payment when the proposer fee recipient receives CL withdrawal.
787+ func TestValidateBuilderSubmissionV2_ExcludeWithdrawals (t * testing.T ) {
788+ genesis , preMergeBlocks := generatePreMergeChain (20 )
789+ lastBlock := preMergeBlocks [len (preMergeBlocks )- 1 ]
790+ time := lastBlock .Time () + 5
791+ genesis .Config .ShanghaiTime = & time
792+ n , ethservice := startEthService (t , genesis , preMergeBlocks )
793+ ethservice .Merger ().ReachTTD ()
794+ defer n .Close ()
795+
796+ api := NewBlockValidationAPI (ethservice , nil , true , true )
797+
798+ baseFee := misc .CalcBaseFee (ethservice .BlockChain ().Config (), lastBlock .Header ())
799+ txs := make (types.Transactions , 0 )
800+
801+ statedb , _ := ethservice .BlockChain ().StateAt (lastBlock .Root ())
802+ nonce := statedb .GetNonce (testAddr )
803+ signer := types .LatestSigner (ethservice .BlockChain ().Config ())
804+
805+ expectedProfit := uint64 (0 )
806+
807+ tx1 , _ := types .SignTx (types .NewTransaction (nonce , common.Address {0x16 }, big .NewInt (10 ), 21000 , big .NewInt (2 * baseFee .Int64 ()), nil ), signer , testKey )
808+ txs = append (txs , tx1 )
809+ expectedProfit += 21000 * baseFee .Uint64 ()
810+
811+ // this tx will use 56996 gas
812+ tx2 , _ := types .SignTx (types .NewContractCreation (nonce + 1 , new (big.Int ), 1000000 , big .NewInt (2 * baseFee .Int64 ()), logCode ), signer , testKey )
813+ txs = append (txs , tx2 )
814+ expectedProfit += 56996 * baseFee .Uint64 ()
815+
816+ tx3 , _ := types .SignTx (types .NewTransaction (nonce + 2 , testAddr , big .NewInt (10 ), 21000 , baseFee , nil ), signer , testKey )
817+ txs = append (txs , tx3 )
818+
819+ // this transaction sends 7 wei to the proposer fee recipient, this should count as a profit
820+ tx4 , _ := types .SignTx (types .NewTransaction (nonce + 3 , testValidatorAddr , big .NewInt (7 ), 21000 , baseFee , nil ), signer , testKey )
821+ txs = append (txs , tx4 )
822+ expectedProfit += 7
823+
824+ withdrawals := []* types.Withdrawal {
825+ {
826+ Index : 0 ,
827+ Validator : 1 ,
828+ Amount : 100 ,
829+ Address : testAddr ,
830+ },
831+ {
832+ Index : 1 ,
833+ Validator : 1 ,
834+ Amount : 17 ,
835+ Address : testValidatorAddr ,
836+ },
837+ {
838+ Index : 1 ,
839+ Validator : 1 ,
840+ Amount : 21 ,
841+ Address : testValidatorAddr ,
842+ },
843+ }
844+ withdrawalsRoot := types .DeriveSha (types .Withdrawals (withdrawals ), trie .NewStackTrie (nil ))
845+
846+ buildBlockArgs := buildBlockArgs {
847+ parentHash : lastBlock .Hash (),
848+ parentRoot : lastBlock .Root (),
849+ feeRecipient : testValidatorAddr ,
850+ txs : txs ,
851+ random : common.Hash {},
852+ number : lastBlock .NumberU64 () + 1 ,
853+ gasLimit : lastBlock .GasLimit (),
854+ timestamp : lastBlock .Time () + 5 ,
855+ extraData : nil ,
856+ baseFeePerGas : baseFee ,
857+ withdrawals : withdrawals ,
858+ }
859+
860+ execData , err := buildBlock (buildBlockArgs , ethservice .BlockChain ())
861+ require .NoError (t , err )
862+
863+ value := big .NewInt (int64 (expectedProfit ))
864+
865+ req , err := executableDataToBlockValidationRequest (execData , testValidatorAddr , value , withdrawalsRoot )
866+ require .NoError (t , err )
867+ require .NoError (t , api .ValidateBuilderSubmissionV2 (req ))
868+
869+ // try to claim less profit than expected, should work
870+ value .SetUint64 (expectedProfit - 1 )
871+
872+ req , err = executableDataToBlockValidationRequest (execData , testValidatorAddr , value , withdrawalsRoot )
873+ require .NoError (t , err )
874+ require .NoError (t , api .ValidateBuilderSubmissionV2 (req ))
875+
876+ // try to claim more profit than expected, should fail
877+ value .SetUint64 (expectedProfit + 1 )
878+
879+ req , err = executableDataToBlockValidationRequest (execData , testValidatorAddr , value , withdrawalsRoot )
880+ require .NoError (t , err )
881+ require .ErrorContains (t , api .ValidateBuilderSubmissionV2 (req ), "payment" )
882+ }
0 commit comments