mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
12cde41772
* Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
230 lines
10 KiB
Go
230 lines
10 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"math/big"
|
|
"sync"
|
|
|
|
"github.com/holiman/uint256"
|
|
rpcfilters "github.com/ledgerwatch/turbo-geth/cmd/rpcdaemon/filters"
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/common/hexutil"
|
|
"github.com/ledgerwatch/turbo-geth/common/math"
|
|
"github.com/ledgerwatch/turbo-geth/core"
|
|
"github.com/ledgerwatch/turbo-geth/core/rawdb"
|
|
"github.com/ledgerwatch/turbo-geth/core/types"
|
|
"github.com/ledgerwatch/turbo-geth/eth/filters"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
"github.com/ledgerwatch/turbo-geth/internal/ethapi"
|
|
"github.com/ledgerwatch/turbo-geth/params"
|
|
"github.com/ledgerwatch/turbo-geth/rpc"
|
|
"github.com/ledgerwatch/turbo-geth/turbo/rpchelper"
|
|
)
|
|
|
|
// EthAPI is a collection of functions that are exposed in the
|
|
type EthAPI interface {
|
|
// Block related (proposed file: ./eth_blocks.go)
|
|
GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error)
|
|
GetBlockByHash(ctx context.Context, hash rpc.BlockNumberOrHash, fullTx bool) (map[string]interface{}, error)
|
|
GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*hexutil.Uint, error)
|
|
GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) (*hexutil.Uint, error)
|
|
|
|
// Transaction related (see ./eth_txs.go)
|
|
GetTransactionByHash(ctx context.Context, hash common.Hash) (*RPCTransaction, error)
|
|
GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, txIndex hexutil.Uint64) (*RPCTransaction, error)
|
|
GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, txIndex hexutil.Uint) (*RPCTransaction, error)
|
|
|
|
// Receipt related (see ./eth_receipts.go)
|
|
GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error)
|
|
GetLogs(ctx context.Context, crit filters.FilterCriteria) ([]*types.Log, error)
|
|
GetBlockReceipts(ctx context.Context, number rpc.BlockNumber) ([]map[string]interface{}, error)
|
|
|
|
// Uncle related (see ./eth_uncles.go)
|
|
GetUncleByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) (map[string]interface{}, error)
|
|
GetUncleByBlockHashAndIndex(ctx context.Context, hash common.Hash, index hexutil.Uint) (map[string]interface{}, error)
|
|
GetUncleCountByBlockNumber(ctx context.Context, number rpc.BlockNumber) (*hexutil.Uint, error)
|
|
GetUncleCountByBlockHash(ctx context.Context, hash common.Hash) (*hexutil.Uint, error)
|
|
|
|
// Filter related (see ./eth_filters.go)
|
|
NewPendingTransactionFilter(_ context.Context) (hexutil.Uint64, error)
|
|
NewBlockFilter(_ context.Context) (hexutil.Uint64, error)
|
|
NewFilter(_ context.Context, filter interface{}) (hexutil.Uint64, error)
|
|
UninstallFilter(_ context.Context, index hexutil.Uint64) (bool, error)
|
|
GetFilterChanges(_ context.Context, index hexutil.Uint64) ([]interface{}, error)
|
|
|
|
// Account related (see ./eth_accounts.go)
|
|
Accounts(ctx context.Context) ([]common.Address, error)
|
|
GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error)
|
|
GetTransactionCount(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Uint64, error)
|
|
GetStorageAt(ctx context.Context, address common.Address, index string, blockNrOrHash rpc.BlockNumberOrHash) (string, error)
|
|
GetCode(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error)
|
|
|
|
// System related (see ./eth_system.go)
|
|
BlockNumber(ctx context.Context) (hexutil.Uint64, error)
|
|
Syncing(ctx context.Context) (interface{}, error)
|
|
ChainId(ctx context.Context) (hexutil.Uint64, error) /* called eth_protocolVersion elsewhere */
|
|
ProtocolVersion(_ context.Context) (hexutil.Uint, error)
|
|
GasPrice(_ context.Context) (*hexutil.Big, error)
|
|
|
|
// Sending related (see ./eth_call.go)
|
|
Call(ctx context.Context, args ethapi.CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *map[common.Address]ethapi.Account) (hexutil.Bytes, error)
|
|
EstimateGas(ctx context.Context, args ethapi.CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error)
|
|
SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error)
|
|
SendTransaction(_ context.Context, txObject interface{}) (common.Hash, error)
|
|
Sign(ctx context.Context, _ common.Address, _ hexutil.Bytes) (hexutil.Bytes, error)
|
|
SignTransaction(_ context.Context, txObject interface{}) (common.Hash, error)
|
|
GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNr rpc.BlockNumber) (*interface{}, error)
|
|
|
|
// Mining related (see ./eth_mining.go)
|
|
Coinbase(ctx context.Context) (common.Address, error)
|
|
Hashrate(ctx context.Context) (uint64, error)
|
|
Mining(ctx context.Context) (bool, error)
|
|
GetWork(ctx context.Context) ([4]string, error)
|
|
SubmitWork(ctx context.Context, nonce types.BlockNonce, powHash, digest common.Hash) (bool, error)
|
|
SubmitHashrate(ctx context.Context, hashRate hexutil.Uint64, id common.Hash) (bool, error)
|
|
|
|
// Deprecated commands in eth_ (proposed file: ./eth_deprecated.go)
|
|
GetCompilers(_ context.Context) ([]string, error)
|
|
CompileLLL(_ context.Context, _ string) (hexutil.Bytes, error)
|
|
CompileSolidity(ctx context.Context, _ string) (hexutil.Bytes, error)
|
|
CompileSerpent(ctx context.Context, _ string) (hexutil.Bytes, error)
|
|
}
|
|
|
|
type BaseAPI struct {
|
|
_chainConfig *params.ChainConfig
|
|
_genesis *types.Block
|
|
_genesisSetOnce sync.Once
|
|
}
|
|
|
|
func (api *BaseAPI) chainConfig(tx ethdb.Tx) (*params.ChainConfig, error) {
|
|
cfg, _, err := api.chainConfigWithGenesis(tx)
|
|
return cfg, err
|
|
}
|
|
|
|
//nolint:unused
|
|
func (api *BaseAPI) genesis(tx ethdb.Tx) (*types.Block, error) {
|
|
_, genesis, err := api.chainConfigWithGenesis(tx)
|
|
return genesis, err
|
|
}
|
|
|
|
func (api *BaseAPI) chainConfigWithGenesis(tx ethdb.Tx) (*params.ChainConfig, *types.Block, error) {
|
|
if api._chainConfig != nil {
|
|
return api._chainConfig, api._genesis, nil
|
|
}
|
|
|
|
genesisBlock, err := rawdb.ReadBlockByNumber(ethdb.NewRoTxDb(tx), 0)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
cc, err := rawdb.ReadChainConfig(tx, genesisBlock.Hash())
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
if cc != nil && genesisBlock != nil {
|
|
api._genesisSetOnce.Do(func() {
|
|
api._genesis = genesisBlock
|
|
api._chainConfig = cc
|
|
})
|
|
}
|
|
return cc, genesisBlock, nil
|
|
}
|
|
|
|
// APIImpl is implementation of the EthAPI interface based on remote Db access
|
|
type APIImpl struct {
|
|
*BaseAPI
|
|
ethBackend core.ApiBackend
|
|
db ethdb.RoKV
|
|
GasCap uint64
|
|
filters *rpcfilters.Filters
|
|
pending *rpchelper.Pending
|
|
}
|
|
|
|
// NewEthAPI returns APIImpl instance
|
|
func NewEthAPI(db ethdb.RoKV, eth core.ApiBackend, gascap uint64, filters *rpcfilters.Filters, pending *rpchelper.Pending) *APIImpl {
|
|
if gascap == 0 {
|
|
gascap = uint64(math.MaxUint64 / 2)
|
|
}
|
|
|
|
return &APIImpl{
|
|
BaseAPI: &BaseAPI{},
|
|
db: db,
|
|
ethBackend: eth,
|
|
GasCap: gascap,
|
|
filters: filters,
|
|
pending: pending,
|
|
}
|
|
}
|
|
|
|
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
|
|
type RPCTransaction struct {
|
|
BlockHash *common.Hash `json:"blockHash"`
|
|
BlockNumber *hexutil.Big `json:"blockNumber"`
|
|
From common.Address `json:"from"`
|
|
Gas hexutil.Uint64 `json:"gas"`
|
|
GasPrice *hexutil.Big `json:"gasPrice,omitempty"`
|
|
Tip *hexutil.Big `json:"tip,omitempty"`
|
|
FeeCap *hexutil.Big `json:"feeCap,omitempty"`
|
|
Hash common.Hash `json:"hash"`
|
|
Input hexutil.Bytes `json:"input"`
|
|
Nonce hexutil.Uint64 `json:"nonce"`
|
|
To *common.Address `json:"to"`
|
|
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
|
|
Value *hexutil.Big `json:"value"`
|
|
Type hexutil.Uint64 `json:"type"`
|
|
Accesses *types.AccessList `json:"accessList,omitempty"`
|
|
ChainID *hexutil.Big `json:"chainId,omitempty"`
|
|
V *hexutil.Big `json:"v"`
|
|
R *hexutil.Big `json:"r"`
|
|
S *hexutil.Big `json:"s"`
|
|
}
|
|
|
|
// newRPCTransaction returns a transaction that will serialize to the RPC
|
|
// representation, with the given location metadata set (if available).
|
|
func newRPCTransaction(tx types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64) *RPCTransaction {
|
|
// Determine the signer. For replay-protected transactions, use the most permissive
|
|
// signer, because we assume that signers are backwards-compatible with old
|
|
// transactions. For non-protected transactions, the homestead signer signer is used
|
|
// because the return value of ChainId is zero for those transactions.
|
|
var chainId *uint256.Int
|
|
result := &RPCTransaction{
|
|
Type: hexutil.Uint64(tx.Type()),
|
|
Gas: hexutil.Uint64(tx.GetGas()),
|
|
Hash: tx.Hash(),
|
|
Input: hexutil.Bytes(tx.GetData()),
|
|
Nonce: hexutil.Uint64(tx.GetNonce()),
|
|
To: tx.GetTo(),
|
|
Value: (*hexutil.Big)(tx.GetValue().ToBig()),
|
|
}
|
|
switch t := tx.(type) {
|
|
case *types.LegacyTx:
|
|
chainId = types.DeriveChainId(&t.V)
|
|
result.GasPrice = (*hexutil.Big)(t.GasPrice.ToBig())
|
|
result.V = (*hexutil.Big)(t.V.ToBig())
|
|
result.R = (*hexutil.Big)(t.R.ToBig())
|
|
result.S = (*hexutil.Big)(t.S.ToBig())
|
|
case *types.AccessListTx:
|
|
result.ChainID = (*hexutil.Big)(t.ChainID.ToBig())
|
|
result.GasPrice = (*hexutil.Big)(t.GasPrice.ToBig())
|
|
result.V = (*hexutil.Big)(t.V.ToBig())
|
|
result.R = (*hexutil.Big)(t.R.ToBig())
|
|
result.S = (*hexutil.Big)(t.S.ToBig())
|
|
result.Accesses = &t.AccessList
|
|
case *types.DynamicFeeTransaction:
|
|
result.ChainID = (*hexutil.Big)(t.ChainID.ToBig())
|
|
result.Tip = (*hexutil.Big)(t.Tip.ToBig())
|
|
result.FeeCap = (*hexutil.Big)(t.FeeCap.ToBig())
|
|
result.V = (*hexutil.Big)(t.V.ToBig())
|
|
result.R = (*hexutil.Big)(t.R.ToBig())
|
|
result.S = (*hexutil.Big)(t.S.ToBig())
|
|
result.Accesses = &t.AccessList
|
|
}
|
|
signer := types.LatestSignerForChainID(chainId.ToBig())
|
|
result.From, _ = tx.Sender(*signer)
|
|
if blockHash != (common.Hash{}) {
|
|
result.BlockHash = &blockHash
|
|
result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber))
|
|
result.TransactionIndex = (*hexutil.Uint64)(&index)
|
|
}
|
|
return result
|
|
}
|