Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 9c081d6

Browse files
committed
Bump to 1.19 + a2.1
1 parent dfbbf21 commit 9c081d6

File tree

1 file changed

+59
-37
lines changed

1 file changed

+59
-37
lines changed

internal/ethapi/api.go

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"github.com/ethereum/go-ethereum/common"
3535
"github.com/ethereum/go-ethereum/common/hexutil"
3636
"github.com/ethereum/go-ethereum/common/math"
37-
"github.com/ethereum/go-ethereum/consensus/clique"
3837
"github.com/ethereum/go-ethereum/consensus/ethash"
3938
"github.com/ethereum/go-ethereum/consensus/misc"
4039
"github.com/ethereum/go-ethereum/core"
@@ -509,7 +508,7 @@ func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args Transactio
509508
}
510509

511510
// Sign calculates an Ethereum ECDSA signature for:
512-
// keccack256("\x19Ethereum Signed Message:\n" + len(message) + message))
511+
// keccack256("\x19Ethereum Signed Message:\n" + len(message) + message))S
513512
//
514513
// Note, the produced signature conforms to the secp256k1 curve R, S and V values,
515514
// where the V value will be 27 or 28 for legacy reasons.
@@ -949,6 +948,41 @@ func (diff *StateOverride) Apply(state *state.StateDB) error {
949948
return nil
950949
}
951950

951+
// BlockOverrides is a set of header fields to override.
952+
type BlockOverrides struct {
953+
Number *hexutil.Big
954+
Difficulty *hexutil.Big
955+
Time *hexutil.Big
956+
GasLimit *hexutil.Uint64
957+
Coinbase *common.Address
958+
Random *common.Hash
959+
}
960+
961+
// Apply overrides the given header fields into the given block context.
962+
func (diff *BlockOverrides) Apply(blockCtx *vm.BlockContext) {
963+
if diff == nil {
964+
return
965+
}
966+
if diff.Number != nil {
967+
blockCtx.BlockNumber = diff.Number.ToInt()
968+
}
969+
if diff.Difficulty != nil {
970+
blockCtx.Difficulty = diff.Difficulty.ToInt()
971+
}
972+
if diff.Time != nil {
973+
blockCtx.Time = diff.Time.ToInt()
974+
}
975+
if diff.GasLimit != nil {
976+
blockCtx.GasLimit = uint64(*diff.GasLimit)
977+
}
978+
if diff.Coinbase != nil {
979+
blockCtx.Coinbase = *diff.Coinbase
980+
}
981+
if diff.Random != nil {
982+
blockCtx.Random = diff.Random
983+
}
984+
}
985+
952986
func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, timeout time.Duration, globalGasCap uint64) (*core.ExecutionResult, error) {
953987
defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
954988

@@ -1359,7 +1393,7 @@ type RPCTransaction struct {
13591393
// newRPCTransaction returns a transaction that will serialize to the RPC
13601394
// representation, with the given location metadata set (if available).
13611395
func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64, baseFee *big.Int, config *params.ChainConfig) *RPCTransaction {
1362-
signer := types.MakeSigner(config, big.NewInt(0).SetUint64(blockNumber))
1396+
signer := types.MakeSigner(config, new(big.Int).SetUint64(blockNumber))
13631397
from, _ := types.Sender(signer, tx)
13641398
v, r, s := tx.RawSignatureValues()
13651399
result := &RPCTransaction{
@@ -1913,7 +1947,7 @@ func (s *PublicTransactionPoolAPI) SendPrivateRawTransaction(ctx context.Context
19131947
}
19141948

19151949
// Sign calculates an ECDSA signature for:
1916-
// keccack256("\x19Ethereum Signed Message:\n" + len(message) + message).
1950+
// keccak256("\x19Ethereum Signed Message:\n" + len(message) + message).
19171951
//
19181952
// Note, the produced signature conforms to the secp256k1 curve R, S and V values,
19191953
// where the V value will be 27 or 28 for legacy reasons.
@@ -2081,43 +2115,31 @@ func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (hexu
20812115
return rlp.EncodeToBytes(block)
20822116
}
20832117

2084-
// TestSignCliqueBlock fetches the given block number, and attempts to sign it as a clique header with the
2085-
// given address, returning the address of the recovered signature
2086-
//
2087-
// This is a temporary method to debug the externalsigner integration,
2088-
// TODO: Remove this method when the integration is mature
2089-
func (api *PublicDebugAPI) TestSignCliqueBlock(ctx context.Context, address common.Address, number uint64) (common.Address, error) {
2090-
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
2091-
if block == nil {
2092-
return common.Address{}, fmt.Errorf("block #%d not found", number)
2093-
}
2094-
header := block.Header()
2095-
header.Extra = make([]byte, 32+65)
2096-
encoded := clique.CliqueRLP(header)
2097-
2098-
// Look up the wallet containing the requested signer
2099-
account := accounts.Account{Address: address}
2100-
wallet, err := api.b.AccountManager().Find(account)
2101-
if err != nil {
2102-
return common.Address{}, err
2118+
// GetRawReceipts retrieves the binary-encoded raw receipts of a single block.
2119+
func (api *PublicDebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]hexutil.Bytes, error) {
2120+
var hash common.Hash
2121+
if h, ok := blockNrOrHash.Hash(); ok {
2122+
hash = h
2123+
} else {
2124+
block, err := api.b.BlockByNumberOrHash(ctx, blockNrOrHash)
2125+
if err != nil {
2126+
return nil, err
2127+
}
2128+
hash = block.Hash()
21032129
}
2104-
2105-
signature, err := wallet.SignData(account, accounts.MimetypeClique, encoded)
2130+
receipts, err := api.b.GetReceipts(ctx, hash)
21062131
if err != nil {
2107-
return common.Address{}, err
2132+
return nil, err
21082133
}
2109-
sealHash := clique.SealHash(header).Bytes()
2110-
log.Info("test signing of clique block",
2111-
"Sealhash", fmt.Sprintf("%x", sealHash),
2112-
"signature", fmt.Sprintf("%x", signature))
2113-
pubkey, err := crypto.Ecrecover(sealHash, signature)
2114-
if err != nil {
2115-
return common.Address{}, err
2134+
result := make([]hexutil.Bytes, len(receipts))
2135+
for i, receipt := range receipts {
2136+
b, err := receipt.MarshalBinary()
2137+
if err != nil {
2138+
return nil, err
2139+
}
2140+
result[i] = b
21162141
}
2117-
var signer common.Address
2118-
copy(signer[:], crypto.Keccak256(pubkey[1:])[12:])
2119-
2120-
return signer, nil
2142+
return result, nil
21212143
}
21222144

21232145
// PrintBlock retrieves a block and returns its pretty printed form.

0 commit comments

Comments
 (0)