forked from ethereum-optimism/op-geth
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modifications to support snap sync (#152)
* Add code to handle block receipts Add code to handle the extra block receipt added by celo to the list of receipts in a block and also adds the GetBlockReceipt rpc api which was an additional api added by celo to allow retrieveal of the block receipt. * Ensure non nil difficulty in pre-gingerbread blocks Nil difficulty in headers causes problems because it is assumed by the go-ethereum codebase that difficulty is non nil. The specific problem requiring this fix was a NPE in Downloader.processHeaders where the total difficulty (td) is calculated by adding individual header difficulty values. Rather than try to fix this specific case it seems safer to ensure blocks have a non nil Difficulty which should help future proof our code since it upholds the assumptions of the go-ethereum codebase. * Skip uncle hash check for pre gingerbread headers Pre gingerbread headers do not have a valid uncle hash because they have no notion of uncles. * Handle choosing the cel2 transition block base fee If the parent block has a base fee then we use that, otherwise we use the initial base fee.
- Loading branch information
Showing
8 changed files
with
118 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ethapi | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
// GetBlockReceipt returns "system calls" receipt for the block with the given block hash. | ||
func (s *BlockChainAPI) GetBlockReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) { | ||
block, err := s.b.BlockByHash(ctx, hash) | ||
if block == nil || err != nil { | ||
// If no header with that hash is found, err gives "header for hash not found". | ||
// But we return nil with no error, to match the behavior of eth_getBlockByHash and eth_getTransactionReceipt in these cases. | ||
return nil, nil | ||
} | ||
index := block.Transactions().Len() | ||
blockNumber := block.NumberU64() | ||
receipts, err := s.b.GetReceipts(ctx, block.Hash()) | ||
// GetReceipts() doesn't return an error if things go wrong, so we also check len(receipts) | ||
if err != nil || len(receipts) < index { | ||
return nil, err | ||
} | ||
|
||
var receipt *types.Receipt | ||
if len(receipts) == index { | ||
// The block didn't have any logs from system calls and no receipt was created. | ||
// So we create an empty receipt to return, similarly to how system receipts are created. | ||
receipt = types.NewReceipt(nil, false, 0) | ||
receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) | ||
} else { | ||
receipt = receipts[index] | ||
} | ||
return marshalBlockReceipt(receipt, hash, blockNumber, index), nil | ||
} | ||
|
||
// marshalBlockReceipt marshals a Celo block receipt into a JSON object. See https://docs.celo.org/developer/migrate/from-ethereum#core-contract-calls | ||
func marshalBlockReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, index int) map[string]interface{} { | ||
fields := map[string]interface{}{ | ||
"blockHash": blockHash, | ||
"blockNumber": hexutil.Uint64(blockNumber), | ||
"transactionHash": blockHash, | ||
"transactionIndex": hexutil.Uint64(index), | ||
"from": common.Address{}, | ||
"to": nil, | ||
"gasUsed": hexutil.Uint64(0), | ||
"cumulativeGasUsed": hexutil.Uint64(0), | ||
"contractAddress": nil, | ||
"logs": receipt.Logs, | ||
"logsBloom": receipt.Bloom, | ||
"type": hexutil.Uint(0), | ||
"status": hexutil.Uint(types.ReceiptStatusSuccessful), | ||
} | ||
if receipt.Logs == nil { | ||
fields["logs"] = []*types.Log{} | ||
} | ||
return fields | ||
} |