Skip to content

Commit f1a9e24

Browse files
committed
internal/ethapi: use correct signer when serving old blocks ethereum#23683
1 parent 4650e3d commit f1a9e24

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

eth/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ type BadBlockArgs struct {
333333
RLP string `json:"rlp"`
334334
}
335335

336-
// GetBadBLocks returns a list of the last 'bad blocks' that the client has seen on the network
336+
// GetBadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
337337
// and returns them as a JSON list of block-hashes
338338
func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
339339
blocks := api.eth.BlockChain().BadBlocks()
@@ -349,7 +349,7 @@ func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error)
349349
} else {
350350
results[i].RLP = fmt.Sprintf("0x%x", rlpBytes)
351351
}
352-
if results[i].Block, err = ethapi.RPCMarshalBlock(block, true, true); err != nil {
352+
if results[i].Block, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.ApiBackend.ChainConfig()); err != nil {
353353
results[i].Block = map[string]interface{}{"error": err.Error()}
354354
}
355355
}

internal/ethapi/api.go

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} {
14431443
// RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
14441444
// returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
14451445
// transaction hashes.
1446-
func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
1446+
func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) (map[string]interface{}, error) {
14471447
fields := RPCMarshalHeader(block.Header())
14481448
fields["size"] = hexutil.Uint64(block.Size())
14491449

@@ -1453,7 +1453,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool) (map[string]i
14531453
}
14541454
if fullTx {
14551455
formatTx = func(tx *types.Transaction) (interface{}, error) {
1456-
return newRPCTransactionFromBlockHash(block, tx.Hash()), nil
1456+
return newRPCTransactionFromBlockHash(block, tx.Hash(), config), nil
14571457
}
14581458
}
14591459
txs := block.Transactions()
@@ -1478,7 +1478,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool) (map[string]i
14781478
// rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires
14791479
// a `BlockChainAPI`.
14801480
func (s *BlockChainAPI) rpcMarshalBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
1481-
fields, err := RPCMarshalBlock(b, inclTx, fullTx)
1481+
fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig())
14821482
if err != nil {
14831483
return nil, err
14841484
}
@@ -1659,17 +1659,8 @@ type RPCTransaction struct {
16591659

16601660
// newRPCTransaction returns a transaction that will serialize to the RPC
16611661
// representation, with the given location metadata set (if available).
1662-
func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64, baseFee *big.Int) *RPCTransaction {
1663-
// Determine the signer. For replay-protected transactions, use the most permissive
1664-
// signer, because we assume that signers are backwards-compatible with old
1665-
// transactions. For non-protected transactions, the homestead signer signer is used
1666-
// because the return value of ChainId is zero for those transactions.
1667-
var signer types.Signer
1668-
if tx.Protected() {
1669-
signer = types.LatestSignerForChainID(tx.ChainId())
1670-
} else {
1671-
signer = types.HomesteadSigner{}
1672-
}
1662+
func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64, baseFee *big.Int, config *params.ChainConfig) *RPCTransaction {
1663+
signer := types.MakeSigner(config, big.NewInt(0).SetUint64(blockNumber))
16731664
from, _ := types.Sender(signer, tx)
16741665
v, r, s := tx.RawSignatureValues()
16751666
result := &RPCTransaction{
@@ -1724,16 +1715,16 @@ func newRPCPendingTransaction(tx *types.Transaction, current *types.Header, conf
17241715
if current != nil {
17251716
baseFee = eip1559.CalcBaseFee(config, current)
17261717
}
1727-
return newRPCTransaction(tx, common.Hash{}, 0, 0, baseFee)
1718+
return newRPCTransaction(tx, common.Hash{}, 0, 0, baseFee, config)
17281719
}
17291720

17301721
// newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation.
1731-
func newRPCTransactionFromBlockIndex(b *types.Block, index uint64) *RPCTransaction {
1722+
func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig) *RPCTransaction {
17321723
txs := b.Transactions()
17331724
if index >= uint64(len(txs)) {
17341725
return nil
17351726
}
1736-
return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index, b.BaseFee())
1727+
return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index, b.BaseFee(), config)
17371728
}
17381729

17391730
// newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.
@@ -1747,10 +1738,10 @@ func newRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.By
17471738
}
17481739

17491740
// newRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation.
1750-
func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash) *RPCTransaction {
1741+
func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash, config *params.ChainConfig) *RPCTransaction {
17511742
for idx, tx := range b.Transactions() {
17521743
if tx.Hash() == hash {
1753-
return newRPCTransactionFromBlockIndex(b, uint64(idx))
1744+
return newRPCTransactionFromBlockIndex(b, uint64(idx), config)
17541745
}
17551746
}
17561747
return nil
@@ -1911,15 +1902,15 @@ func (s *TransactionAPI) GetBlockTransactionCountByHash(ctx context.Context, blo
19111902
// GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.
19121903
func (s *TransactionAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction {
19131904
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
1914-
return newRPCTransactionFromBlockIndex(block, uint64(index))
1905+
return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig())
19151906
}
19161907
return nil
19171908
}
19181909

19191910
// GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index.
19201911
func (s *TransactionAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction {
19211912
if block, _ := s.b.GetBlock(ctx, blockHash); block != nil {
1922-
return newRPCTransactionFromBlockIndex(block, uint64(index))
1913+
return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig())
19231914
}
19241915
return nil
19251916
}
@@ -1968,7 +1959,7 @@ func (s *TransactionAPI) GetTransactionByHash(ctx context.Context, hash common.H
19681959
if err != nil {
19691960
return nil, err
19701961
}
1971-
return newRPCTransaction(tx, blockHash, blockNumber, index, header.BaseFee), nil
1962+
return newRPCTransaction(tx, blockHash, blockNumber, index, header.BaseFee, s.b.ChainConfig()), nil
19721963
}
19731964
// No finalized transaction, try to retrieve it from the pool
19741965
if tx := s.b.GetPoolTransaction(hash); tx != nil {

0 commit comments

Comments
 (0)