Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding correct miner address on API at the RPC level (POS-553) #435

Merged
merged 11 commits into from
Jun 29, 2022
Merged
4 changes: 4 additions & 0 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ func New(
// Author implements consensus.Engine, returning the Ethereum address recovered
// from the signature in the header's extra-data section.
func (c *Bor) Author(header *types.Header) (common.Address, error) {
if header.Number.Uint64() == 0 {
add := common.HexToAddress("0x0000000000000000000000000000000000000000")
return add, nil
}
return ecrecover(header, c.signatures, c.config)
}

Expand Down
4 changes: 4 additions & 0 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func New(config *params.CliqueConfig, db ethdb.Database) *Clique {
// Author implements consensus.Engine, returning the Ethereum address recovered
// from the signature in the header's extra-data section.
func (c *Clique) Author(header *types.Header) (common.Address, error) {
if header.Number.Uint64() == 0 {
add := common.HexToAddress("0x0000000000000000000000000000000000000000")
return add, nil
}
return ecrecover(header, c.signatures)
}

Expand Down
30 changes: 30 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,18 @@ func (s *PublicBlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.H
return nil
}

// getAuthor: returns the author of the Block
func (s *PublicBlockChainAPI) getAuthor(head *types.Header) (*common.Address, error) {
// get author using Author() function from: /consensus/clique/clique.go
// In Production: get author using Author() function from: /consensus/bor/bor.go
author, err := s.b.Engine().Author(head)
if err != nil {
return nil, err
}
// change the coinbase (0x0) with the miner address
return &author, nil
}

// GetBlockByNumber returns the requested canonical block.
// * When blockNr is -1 the chain head is returned.
// * When blockNr is -2 the pending chain head is returned.
Expand All @@ -822,6 +834,7 @@ func (s *PublicBlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.H
func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) {
block, err := s.b.BlockByNumber(ctx, number)
if block != nil && err == nil {

response, err := s.rpcMarshalBlock(ctx, block, true, fullTx)
if err == nil && number == rpc.PendingBlockNumber {
// Pending blocks need to nil out a few fields
Expand All @@ -830,6 +843,15 @@ func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.B
}
}

if err == nil && number != rpc.PendingBlockNumber {
author, err := s.getAuthor(block.Header())
if err != nil {
return nil, err
}

response["miner"] = author
}

// append marshalled bor transaction
if err == nil && response != nil {
response = s.appendRPCMarshalBorTransaction(ctx, block, response, fullTx)
Expand All @@ -848,6 +870,14 @@ func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Ha
response, err := s.rpcMarshalBlock(ctx, block, true, fullTx)
// append marshalled bor transaction
if err == nil && response != nil {

author, err := s.getAuthor(block.Header())
if err != nil {
return nil, err
manav2401 marked this conversation as resolved.
Show resolved Hide resolved
}

response["miner"] = author

return s.appendRPCMarshalBorTransaction(ctx, block, response, fullTx), err
}
return response, err
Expand Down