@@ -1821,7 +1821,7 @@ func TestGetClientVersion(t *testing.T) {
1821
1821
}
1822
1822
}
1823
1823
1824
- func TestNewPayloadWithInclusionList (t * testing.T ) {
1824
+ func TestInclusionList (t * testing.T ) {
1825
1825
genesis , blocks := generateMergeChain (100 , false )
1826
1826
1827
1827
// Set cancun time to last block + 5 seconds
@@ -1867,144 +1867,39 @@ func TestNewPayloadWithInclusionList(t *testing.T) {
1867
1867
// Add `validTx1` to the pool.
1868
1868
ethservice .TxPool ().Add ([]* types.Transaction {validTx1 }, true , true )
1869
1869
1870
- for i , tt := range []* struct {
1871
- name string
1872
- inclusionList * engine.InclusionListV1
1873
- expectedStatus string
1874
- }{
1875
- {
1876
- name : "Block contains all transactions in the inclusion list" ,
1877
- inclusionList : engine .TransactionsToInclusionList ([]* types.Transaction {validTx1 }),
1878
- expectedStatus : engine .VALID ,
1879
- },
1880
- {
1881
- name : "Block misses one transaction in the inclusion list, which could have been included" ,
1882
- inclusionList : engine .TransactionsToInclusionList ([]* types.Transaction {validTx1 , validTx2 }),
1883
- expectedStatus : engine .INVALID_INCLUSION_LIST ,
1884
- },
1885
- {
1886
- name : "Block misses only invalid transactions in the inclusion list" ,
1887
- inclusionList : engine .TransactionsToInclusionList ([]* types.Transaction {validTx1 , invalidTx }),
1888
- expectedStatus : engine .VALID ,
1889
- },
1890
- } {
1891
- t .Run (tt .name , func (t * testing.T ) {
1892
- // Build Shanghai block.
1893
- blockParams := engine.PayloadAttributes {
1894
- Timestamp : parent .Time + 5 + uint64 (i ),
1895
- Random : crypto .Keccak256Hash ([]byte {byte (0 )}),
1896
- SuggestedFeeRecipient : parent .Coinbase ,
1897
- Withdrawals : make ([]* types.Withdrawal , 0 ),
1898
- BeaconRoot : & common.Hash {42 },
1899
- }
1900
- fcState := engine.ForkchoiceStateV1 {
1901
- HeadBlockHash : parent .Hash (),
1902
- SafeBlockHash : common.Hash {},
1903
- FinalizedBlockHash : common.Hash {},
1904
- }
1905
-
1906
- var (
1907
- payload * engine.ExecutionPayloadEnvelope
1908
- resp engine.ForkChoiceResponse
1909
- err error
1910
- )
1911
-
1912
- // Start building the payload.
1913
- if resp , err = api .ForkchoiceUpdatedV3 (fcState , & blockParams ); err != nil {
1914
- t .Fatalf ("error preparing payload, err=%v" , err )
1915
- }
1916
- if resp .PayloadStatus .Status != engine .VALID {
1917
- t .Fatalf ("error preparing payload, invalid status=%v" , resp .PayloadStatus .Status )
1918
- }
1919
-
1920
- // Get the payload.
1921
- if payload , err = api .getPayload (* resp .PayloadID , true ); err != nil {
1922
- t .Fatalf ("error getting payload, err=%v" , err )
1923
- }
1924
- // The payload is expected to have 1 transaction, which is `validTx1`.
1925
- if len (payload .ExecutionPayload .Transactions ) != 1 {
1926
- t .Fatalf ("expected 1 transaction but got %d" , len (payload .ExecutionPayload .Transactions ))
1927
- }
1928
-
1929
- // Verify if the block satisfies the inclusion list constraints.
1930
- status , err := api .newPayload (* payload .ExecutionPayload , []common.Hash {}, & common.Hash {42 }, nil , tt .inclusionList , false )
1931
- if err != nil {
1932
- t .Fatalf ("error validating payload, err=%v" , err )
1933
- }
1934
- if status .Status != tt .expectedStatus {
1935
- t .Fatalf ("expected status %v but got %v" , tt .expectedStatus , status .Status )
1936
- }
1937
- })
1938
- }
1939
- }
1940
-
1941
- func TestUpdatePayloadWithInclusionList (t * testing.T ) {
1942
- genesis , blocks := generateMergeChain (100 , false )
1943
-
1944
- // Set cancun time to last block + 5 seconds
1945
- time := blocks [len (blocks )- 1 ].Time () + 5
1946
- genesis .Config .ShanghaiTime = & time
1947
- genesis .Config .CancunTime = & time
1948
-
1949
- n , ethservice := startEthService (t , genesis , blocks )
1950
- defer n .Close ()
1951
-
1952
- api := NewConsensusAPI (ethservice )
1953
- parent := ethservice .BlockChain ().CurrentHeader ()
1954
- statedb , _ := ethservice .BlockChain ().StateAt (parent .Root )
1955
-
1956
- // Prepare transactions.
1957
- signer := types .LatestSigner (ethservice .BlockChain ().Config ())
1958
- testUserKey , _ := crypto .GenerateKey ()
1959
- testUserAddress := crypto .PubkeyToAddress (testUserKey .PublicKey )
1960
- validTx1 := types .MustSignNewTx (testKey , signer , & types.LegacyTx {
1961
- Nonce : statedb .GetNonce (testAddr ),
1962
- To : & testUserAddress ,
1963
- Value : big .NewInt (1000 ),
1964
- Gas : params .TxGas ,
1965
- GasPrice : big .NewInt (params .InitialBaseFee ),
1966
- })
1967
- validTx2 := types .MustSignNewTx (testKey , signer , & types.AccessListTx {
1968
- ChainID : ethservice .BlockChain ().Config ().ChainID ,
1969
- Nonce : statedb .GetNonce (testAddr ) + 1 ,
1970
- To : & testUserAddress ,
1971
- Value : big .NewInt (1000 ),
1972
- Gas : params .TxGas ,
1973
- GasPrice : big .NewInt (params .InitialBaseFee ),
1974
- })
1975
- invalidTx := types .MustSignNewTx (testUserKey , signer , & types.AccessListTx {
1976
- ChainID : ethservice .BlockChain ().Config ().ChainID ,
1977
- Nonce : statedb .GetNonce (testUserAddress ),
1978
- To : & testAddr ,
1979
- Value : big .NewInt (1000 ),
1980
- Gas : params .TxGas ,
1981
- GasPrice : big .NewInt (params .InitialBaseFee ),
1982
- }) // This tx is invalid as `testUserAddress` has insufficient funds for `gas` * `price` + `value`.
1983
-
1984
- // There is no transaction in the pool. The payload will contain only valid transactions in the inclusion list.
1985
-
1986
1870
for i , tt := range []* struct {
1987
1871
name string
1988
1872
inclusionList * engine.InclusionListV1
1873
+ updateInclusionList bool
1989
1874
expectedTransactions int
1990
1875
expectedStatus string
1991
1876
}{
1992
1877
{
1993
- name : "Block contains all transactions in the inclusion list" ,
1878
+ name : "Payload misses one transaction in the inclusion list, which could have been included" ,
1879
+ inclusionList : engine .TransactionsToInclusionList ([]* types.Transaction {validTx1 , validTx2 }),
1880
+ updateInclusionList : false ,
1881
+ expectedTransactions : 1 ,
1882
+ expectedStatus : engine .INVALID_INCLUSION_LIST ,
1883
+ },
1884
+ {
1885
+ name : "All transactions in the inclusion list are already included in the payload before update" ,
1994
1886
inclusionList : engine .TransactionsToInclusionList ([]* types.Transaction {validTx1 }),
1887
+ updateInclusionList : true ,
1995
1888
expectedTransactions : 1 ,
1996
1889
expectedStatus : engine .VALID ,
1997
1890
},
1998
1891
{
1999
- name : "Block contains all transactions in the inclusion list" ,
2000
- inclusionList : engine .TransactionsToInclusionList ([]* types.Transaction {validTx1 , validTx2 }),
2001
- expectedTransactions : 2 ,
1892
+ name : "All transactions in the inclusion list that are not included in the payload before update" ,
1893
+ inclusionList : engine .TransactionsToInclusionList ([]* types.Transaction {validTx2 }),
1894
+ updateInclusionList : true ,
1895
+ expectedTransactions : 2 , // `validTx1` from the pool and `validTx2` from the inclusion list
2002
1896
expectedStatus : engine .VALID ,
2003
1897
},
2004
1898
{
2005
- name : "Block misses only invalid transactions in the inclusion list" ,
2006
- inclusionList : engine .TransactionsToInclusionList ([]* types.Transaction {validTx1 , invalidTx }),
2007
- expectedTransactions : 1 ,
1899
+ name : "Payload includes all valid transactions in the inclusion list" ,
1900
+ inclusionList : engine .TransactionsToInclusionList ([]* types.Transaction {validTx1 , validTx2 , invalidTx }),
1901
+ updateInclusionList : true ,
1902
+ expectedTransactions : 2 ,
2008
1903
expectedStatus : engine .VALID ,
2009
1904
},
2010
1905
} {
@@ -2037,8 +1932,10 @@ func TestUpdatePayloadWithInclusionList(t *testing.T) {
2037
1932
t .Fatalf ("error preparing payload, invalid status=%v" , resp .PayloadStatus .Status )
2038
1933
}
2039
1934
2040
- // Update the payload with the inclusion list.
2041
- api .UpdatePayloadWithInclusionListV1 (* resp .PayloadID , * tt .inclusionList )
1935
+ if tt .updateInclusionList {
1936
+ // Update the payload with the inclusion list.
1937
+ api .UpdatePayloadWithInclusionListV1 (* resp .PayloadID , * tt .inclusionList )
1938
+ }
2042
1939
2043
1940
// Get the payload.
2044
1941
if payload , err = api .getPayload (* resp .PayloadID , true ); err != nil {
0 commit comments