mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-21 19:20:39 +00:00
Fix missing uncles in new block downloader
This commit is contained in:
parent
8c10b47d0c
commit
3ec01ab133
@ -245,7 +245,7 @@ func (e *EngineBlockDownloader) insertHeadersAndBodies(tx kv.Tx, fromBlock uint6
|
||||
if body == nil {
|
||||
return fmt.Errorf("missing body at block=%d", number)
|
||||
}
|
||||
blocksBatch = append(blocksBatch, types.NewBlockFromStorage(hash, header, body.Transactions, nil, body.Withdrawals))
|
||||
blocksBatch = append(blocksBatch, types.NewBlockFromStorage(hash, header, body.Transactions, body.Uncles, body.Withdrawals))
|
||||
if number%uint64(blockWrittenLogSize) == 0 {
|
||||
e.logger.Info("[insertHeadersAndBodies] Written blocks", "progress", number, "to", toBlock)
|
||||
}
|
||||
|
@ -93,7 +93,11 @@ func (c ChainReaderWriterEth1) GetBlockByHash(hash libcommon.Hash) *types.Block
|
||||
if resp == nil || resp.Body == nil {
|
||||
return nil
|
||||
}
|
||||
body := eth1_utils.ConvertRawBlockBodyFromRpc(resp.Body)
|
||||
body, err := eth1_utils.ConvertRawBlockBodyFromRpc(resp.Body)
|
||||
if err != nil {
|
||||
log.Error("GetBlockByHash failed", "err", err)
|
||||
return nil
|
||||
}
|
||||
txs, err := types.DecodeTransactions(body.Transactions)
|
||||
if err != nil {
|
||||
log.Error("GetBlockByHash failed", "err", err)
|
||||
@ -118,7 +122,11 @@ func (c ChainReaderWriterEth1) GetBlockByNumber(number uint64) *types.Block {
|
||||
if resp == nil || resp.Body == nil {
|
||||
return nil
|
||||
}
|
||||
body := eth1_utils.ConvertRawBlockBodyFromRpc(resp.Body)
|
||||
body, err := eth1_utils.ConvertRawBlockBodyFromRpc(resp.Body)
|
||||
if err != nil {
|
||||
log.Error("GetBlockByNumber failed", "err", err)
|
||||
return nil
|
||||
}
|
||||
txs, err := types.DecodeTransactions(body.Transactions)
|
||||
if err != nil {
|
||||
log.Error("GetBlockByNumber failed", "err", err)
|
||||
@ -195,7 +203,10 @@ func (c ChainReaderWriterEth1) GetBodiesByHashes(hashes []libcommon.Hash) ([]*ty
|
||||
}
|
||||
ret := make([]*types.RawBody, len(resp.Bodies))
|
||||
for i := range ret {
|
||||
ret[i] = eth1_utils.ConvertRawBlockBodyFromRpc(resp.Bodies[i])
|
||||
ret[i], err = eth1_utils.ConvertRawBlockBodyFromRpc(resp.Bodies[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
@ -210,7 +221,10 @@ func (c ChainReaderWriterEth1) GetBodiesByRange(start, count uint64) ([]*types.R
|
||||
}
|
||||
ret := make([]*types.RawBody, len(resp.Bodies))
|
||||
for i := range ret {
|
||||
ret[i] = eth1_utils.ConvertRawBlockBodyFromRpc(resp.Bodies[i])
|
||||
ret[i], err = eth1_utils.ConvertRawBlockBodyFromRpc(resp.Bodies[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
@ -65,7 +65,10 @@ func HeaderToHeaderRPC(header *types.Header) *execution.Header {
|
||||
}
|
||||
|
||||
func HeadersToHeadersRPC(headers []*types.Header) []*execution.Header {
|
||||
ret := []*execution.Header{}
|
||||
if headers == nil {
|
||||
return nil
|
||||
}
|
||||
ret := make([]*execution.Header, 0, len(headers))
|
||||
for _, header := range headers {
|
||||
ret = append(ret, HeaderToHeaderRPC(header))
|
||||
}
|
||||
@ -136,6 +139,21 @@ func HeaderRpcToHeader(header *execution.Header) (*types.Header, error) {
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func HeadersRpcToHeaders(headers []*execution.Header) ([]*types.Header, error) {
|
||||
if headers == nil {
|
||||
return nil, nil
|
||||
}
|
||||
out := make([]*types.Header, 0, len(headers))
|
||||
for _, h := range headers {
|
||||
header, err := HeaderRpcToHeader(h)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, header)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func ConvertWithdrawalsFromRpc(in []*types2.Withdrawal) []*types.Withdrawal {
|
||||
if in == nil {
|
||||
return nil
|
||||
@ -177,6 +195,7 @@ func ConvertRawBlockBodyToRpc(in *types.RawBody, blockNumber uint64, blockHash l
|
||||
BlockNumber: blockNumber,
|
||||
BlockHash: gointerfaces.ConvertHashToH256(blockHash),
|
||||
Transactions: in.Transactions,
|
||||
Uncles: HeadersToHeadersRPC(in.Uncles),
|
||||
Withdrawals: ConvertWithdrawalsToRpc(in.Withdrawals),
|
||||
}
|
||||
}
|
||||
@ -190,14 +209,19 @@ func ConvertRawBlockBodiesToRpc(in []*types.RawBody, blockNumbers []uint64, bloc
|
||||
return ret
|
||||
}
|
||||
|
||||
func ConvertRawBlockBodyFromRpc(in *execution.BlockBody) *types.RawBody {
|
||||
func ConvertRawBlockBodyFromRpc(in *execution.BlockBody) (*types.RawBody, error) {
|
||||
if in == nil {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
uncles, err := HeadersRpcToHeaders(in.Uncles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &types.RawBody{
|
||||
Transactions: in.Transactions,
|
||||
Uncles: uncles,
|
||||
Withdrawals: ConvertWithdrawalsFromRpc(in.Withdrawals),
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ConvertBigIntFromRpc(in *types2.H256) *big.Int {
|
||||
|
@ -76,7 +76,10 @@ func TestBlockRpcConversion(t *testing.T) {
|
||||
|
||||
// body conversions
|
||||
rpcBlock := ConvertBlockToRPC(testBlock)
|
||||
roundTripBody := ConvertRawBlockBodyFromRpc(rpcBlock.Body)
|
||||
roundTripBody, err := ConvertRawBlockBodyFromRpc(rpcBlock.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
testBlockRaw := testBlock.RawBody()
|
||||
require.Greater(len(testBlockRaw.Transactions), 0)
|
||||
require.Greater(len(testBlockRaw.Uncles), 0)
|
||||
|
@ -28,7 +28,10 @@ func (e *EthereumExecutionModule) InsertBlocks(ctx context.Context, req *executi
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ethereumExecutionModule.InsertBlocks: cannot convert headers: %s", err)
|
||||
}
|
||||
body := eth1_utils.ConvertRawBlockBodyFromRpc(block.Body)
|
||||
body, err := eth1_utils.ConvertRawBlockBodyFromRpc(block.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ethereumExecutionModule.InsertBlocks: cannot convert body: %s", err)
|
||||
}
|
||||
height := header.Number.Uint64()
|
||||
// Parent's total difficulty
|
||||
parentTd, err := rawdb.ReadTd(tx, header.ParentHash, height-1)
|
||||
|
Loading…
Reference in New Issue
Block a user