@ -93,7 +93,7 @@ func TestEth2AssembleBlock(t *testing.T) {
blockParams := beacon . PayloadAttributesV1 {
blockParams := beacon . PayloadAttributesV1 {
Timestamp : blocks [ 9 ] . Time ( ) + 5 ,
Timestamp : blocks [ 9 ] . Time ( ) + 5 ,
}
}
execData , err := api . assembleBlock ( blocks [ 9 ] . Hash ( ) , & blockParams )
execData , err := assembleBlock ( api , blocks [ 9 ] . Hash ( ) , & blockParams )
if err != nil {
if err != nil {
t . Fatalf ( "error producing block, err=%v" , err )
t . Fatalf ( "error producing block, err=%v" , err )
}
}
@ -114,7 +114,7 @@ func TestEth2AssembleBlockWithAnotherBlocksTxs(t *testing.T) {
blockParams := beacon . PayloadAttributesV1 {
blockParams := beacon . PayloadAttributesV1 {
Timestamp : blocks [ 8 ] . Time ( ) + 5 ,
Timestamp : blocks [ 8 ] . Time ( ) + 5 ,
}
}
execData , err := api . assembleBlock ( blocks [ 8 ] . Hash ( ) , & blockParams )
execData , err := assembleBlock ( api , blocks [ 8 ] . Hash ( ) , & blockParams )
if err != nil {
if err != nil {
t . Fatalf ( "error producing block, err=%v" , err )
t . Fatalf ( "error producing block, err=%v" , err )
}
}
@ -273,7 +273,7 @@ func TestEth2NewBlock(t *testing.T) {
tx , _ := types . SignTx ( types . NewContractCreation ( nonce , new ( big . Int ) , 1000000 , big . NewInt ( 2 * params . InitialBaseFee ) , logCode ) , types . LatestSigner ( ethservice . BlockChain ( ) . Config ( ) ) , testKey )
tx , _ := types . SignTx ( types . NewContractCreation ( nonce , new ( big . Int ) , 1000000 , big . NewInt ( 2 * params . InitialBaseFee ) , logCode ) , types . LatestSigner ( ethservice . BlockChain ( ) . Config ( ) ) , testKey )
ethservice . TxPool ( ) . AddLocal ( tx )
ethservice . TxPool ( ) . AddLocal ( tx )
execData , err := api . assembleBlock ( parent . Hash ( ) , & beacon . PayloadAttributesV1 {
execData , err := assembleBlock ( api , parent . Hash ( ) , & beacon . PayloadAttributesV1 {
Timestamp : parent . Time ( ) + 5 ,
Timestamp : parent . Time ( ) + 5 ,
} )
} )
if err != nil {
if err != nil {
@ -313,7 +313,7 @@ func TestEth2NewBlock(t *testing.T) {
)
)
parent = preMergeBlocks [ len ( preMergeBlocks ) - 1 ]
parent = preMergeBlocks [ len ( preMergeBlocks ) - 1 ]
for i := 0 ; i < 10 ; i ++ {
for i := 0 ; i < 10 ; i ++ {
execData , err := api . assembleBlock ( parent . Hash ( ) , & beacon . PayloadAttributesV1 {
execData , err := assembleBlock ( api , parent . Hash ( ) , & beacon . PayloadAttributesV1 {
Timestamp : parent . Time ( ) + 6 ,
Timestamp : parent . Time ( ) + 6 ,
} )
} )
if err != nil {
if err != nil {
@ -530,3 +530,77 @@ func TestExchangeTransitionConfig(t *testing.T) {
t . Fatalf ( "expected no error on valid config, got %v" , err )
t . Fatalf ( "expected no error on valid config, got %v" , err )
}
}
}
}
func TestEmptyBlocks ( t * testing . T ) {
genesis , preMergeBlocks := generatePreMergeChain ( 10 )
n , ethservice := startEthService ( t , genesis , preMergeBlocks )
ethservice . Merger ( ) . ReachTTD ( )
defer n . Close ( )
var (
api = NewConsensusAPI ( ethservice )
parent = ethservice . BlockChain ( ) . CurrentBlock ( )
// This EVM code generates a log when the contract is created.
logCode = common . Hex2Bytes ( "60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00" )
)
for i := 0 ; i < 10 ; i ++ {
statedb , _ := ethservice . BlockChain ( ) . StateAt ( parent . Root ( ) )
nonce := statedb . GetNonce ( testAddr )
tx , _ := types . SignTx ( types . NewContractCreation ( nonce , new ( big . Int ) , 1000000 , big . NewInt ( 2 * params . InitialBaseFee ) , logCode ) , types . LatestSigner ( ethservice . BlockChain ( ) . Config ( ) ) , testKey )
ethservice . TxPool ( ) . AddLocal ( tx )
params := beacon . PayloadAttributesV1 {
Timestamp : parent . Time ( ) + 1 ,
Random : crypto . Keccak256Hash ( [ ] byte { byte ( i ) } ) ,
SuggestedFeeRecipient : parent . Coinbase ( ) ,
}
fcState := beacon . ForkchoiceStateV1 {
HeadBlockHash : parent . Hash ( ) ,
SafeBlockHash : common . Hash { } ,
FinalizedBlockHash : common . Hash { } ,
}
resp , err := api . ForkchoiceUpdatedV1 ( fcState , & params )
if err != nil {
t . Fatalf ( "error preparing payload, err=%v" , err )
}
if resp . PayloadStatus . Status != beacon . VALID {
t . Fatalf ( "error preparing payload, invalid status: %v" , resp . PayloadStatus . Status )
}
payload , err := api . GetPayloadV1 ( * resp . PayloadID )
if err != nil {
t . Fatalf ( "can't get payload: %v" , err )
}
// TODO(493456442, marius) this test can be flaky since we rely on a 100ms
// allowance for block generation internally.
if len ( payload . Transactions ) == 0 {
t . Fatalf ( "payload should not be empty" )
}
execResp , err := api . NewPayloadV1 ( * payload )
if err != nil {
t . Fatalf ( "can't execute payload: %v" , err )
}
if execResp . Status != beacon . VALID {
t . Fatalf ( "invalid status: %v" , execResp . Status )
}
fcState = beacon . ForkchoiceStateV1 {
HeadBlockHash : payload . BlockHash ,
SafeBlockHash : payload . ParentHash ,
FinalizedBlockHash : payload . ParentHash ,
}
if _ , err := api . ForkchoiceUpdatedV1 ( fcState , nil ) ; err != nil {
t . Fatalf ( "Failed to insert block: %v" , err )
}
if ethservice . BlockChain ( ) . CurrentBlock ( ) . NumberU64 ( ) != payload . Number {
t . Fatalf ( "Chain head should be updated" )
}
parent = ethservice . BlockChain ( ) . CurrentBlock ( )
}
}
func assembleBlock ( api * ConsensusAPI , parentHash common . Hash , params * beacon . PayloadAttributesV1 ) ( * beacon . ExecutableDataV1 , error ) {
block , err := api . eth . Miner ( ) . GetSealingBlockSync ( parentHash , params . Timestamp , params . SuggestedFeeRecipient , params . Random , false )
if err != nil {
return nil , err
}
return beacon . BlockToExecutableData ( block ) , nil
}