mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-11 05:20:05 +00:00
cc74e74a60
This request is extending the devnet functionality to more fully handle contract processing by adding support for the following calls: * trace_call, * trace_transaction * debug_accountAt, * eth_getCode * eth_estimateGas * eth_gasPrice It also contains an initial rationalization of the devnet subscription code to use the erigon client code directly rather than using its own intermediate subscription management. This is used to implement a general purpose block waiter - which can be used in any scenario step - rather than being specific to transaction processing. This pull also contains an end to end tested sync processor for bor and associated support services: * Heimdall (supports sync event transfer) * Faucet - allows the creation and funding of arbitary test specific accounts (cross chain) Notes and Caveats: * Code generation for contracts requires `--evm-version paris`. For chains which don't support push0 for solc over 0.8.19 * The bor log processing post the application of sync events causes a panic - this will be the subject of a seperate smaller push as it is not devnet specific * The bor code seems to make repeated calls for the same sync events and also reverts requests - this needs further investigation. This is the behaviour of the current implementation and may be required - although it does seem to generate repeat processing - which could be avoided.
124 lines
4.1 KiB
Go
124 lines
4.1 KiB
Go
package requests
|
|
|
|
import (
|
|
"fmt"
|
|
"math/big"
|
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
|
"github.com/ledgerwatch/erigon/common/hexutil"
|
|
)
|
|
|
|
type EthBalance struct {
|
|
CommonResponse
|
|
Balance hexutil.Big `json:"result"`
|
|
}
|
|
|
|
type EthCode struct {
|
|
CommonResponse
|
|
Code hexutility.Bytes `json:"result"`
|
|
}
|
|
|
|
type DebugAccountAt struct {
|
|
CommonResponse
|
|
Result AccountResult `json:"result"`
|
|
}
|
|
|
|
// AccountResult is the result struct for GetProof
|
|
type AccountResult struct {
|
|
Address libcommon.Address `json:"address"`
|
|
AccountProof []string `json:"accountProof"`
|
|
Balance *hexutil.Big `json:"balance"`
|
|
CodeHash libcommon.Hash `json:"codeHash"`
|
|
Code hexutility.Bytes `json:"code"`
|
|
Nonce hexutil.Uint64 `json:"nonce"`
|
|
StorageHash libcommon.Hash `json:"storageHash"`
|
|
StorageProof []StorageResult `json:"storageProof"`
|
|
}
|
|
|
|
type StorageResult struct {
|
|
Key string `json:"key"`
|
|
Value *hexutil.Big `json:"value"`
|
|
Proof []string `json:"proof"`
|
|
}
|
|
|
|
func (reqGen *requestGenerator) GetCode(address libcommon.Address, blockRef BlockNumber) (hexutility.Bytes, error) {
|
|
var b EthCode
|
|
|
|
method, body := reqGen.getCode(address, blockRef)
|
|
if res := reqGen.call(method, body, &b); res.Err != nil {
|
|
return hexutility.Bytes{}, fmt.Errorf("failed to get code: %w", res.Err)
|
|
}
|
|
|
|
if b.Error != nil {
|
|
return hexutility.Bytes{}, fmt.Errorf("Failed to get code: rpc failed: %w", b.Error)
|
|
}
|
|
|
|
return b.Code, nil
|
|
}
|
|
|
|
func (req *requestGenerator) getCode(address libcommon.Address, blockRef BlockNumber) (RPCMethod, string) {
|
|
const template = `{"jsonrpc":"2.0","method":%q,"params":["0x%x","%s"],"id":%d}`
|
|
return Methods.ETHGetCode, fmt.Sprintf(template, Methods.ETHGetCode, address, blockRef, req.reqID)
|
|
}
|
|
|
|
func (reqGen *requestGenerator) GetBalance(address libcommon.Address, blockNum BlockNumber) (*big.Int, error) {
|
|
var b EthBalance
|
|
|
|
method, body := reqGen.getBalance(address, blockNum)
|
|
if res := reqGen.call(method, body, &b); res.Err != nil {
|
|
return &big.Int{}, fmt.Errorf("failed to get balance: %w", res.Err)
|
|
}
|
|
|
|
if b.Error != nil {
|
|
return &big.Int{}, fmt.Errorf("Failed to get balance: rpc failed: %w", b.Error)
|
|
}
|
|
|
|
return b.Balance.ToInt(), nil
|
|
}
|
|
|
|
func (req *requestGenerator) getBalance(address libcommon.Address, blockNum BlockNumber) (RPCMethod, string) {
|
|
const template = `{"jsonrpc":"2.0","method":%q,"params":["0x%x","%v"],"id":%d}`
|
|
return Methods.ETHGetBalance, fmt.Sprintf(template, Methods.ETHGetBalance, address, blockNum, req.reqID)
|
|
}
|
|
|
|
func (reqGen *requestGenerator) GetTransactionCount(address libcommon.Address, blockNum BlockNumber) (*big.Int, error) {
|
|
var b EthGetTransactionCount
|
|
|
|
method, body := reqGen.getTransactionCount(address, blockNum)
|
|
if res := reqGen.call(method, body, &b); res.Err != nil {
|
|
return nil, fmt.Errorf("error getting transaction count: %w", res.Err)
|
|
}
|
|
|
|
if b.Error != nil {
|
|
return nil, fmt.Errorf("error populating response object: %w", b.Error)
|
|
}
|
|
|
|
return big.NewInt(int64(b.Result)), nil
|
|
}
|
|
|
|
func (req *requestGenerator) getTransactionCount(address libcommon.Address, blockNum BlockNumber) (RPCMethod, string) {
|
|
const template = `{"jsonrpc":"2.0","method":%q,"params":["0x%x","%v"],"id":%d}`
|
|
return Methods.ETHGetTransactionCount, fmt.Sprintf(template, Methods.ETHGetTransactionCount, address, blockNum, req.reqID)
|
|
}
|
|
|
|
func (reqGen *requestGenerator) DebugAccountAt(blockHash libcommon.Hash, txIndex uint64, account libcommon.Address) (*AccountResult, error) {
|
|
var b DebugAccountAt
|
|
|
|
method, body := reqGen.debugAccountAt(blockHash, txIndex, account)
|
|
if res := reqGen.call(method, body, &b); res.Err != nil {
|
|
return nil, fmt.Errorf("failed to get account: %v", res.Err)
|
|
}
|
|
|
|
if b.Error != nil {
|
|
return nil, fmt.Errorf("failed to get account: rpc failed: %w", b.Error)
|
|
}
|
|
|
|
return &b.Result, nil
|
|
}
|
|
|
|
func (req *requestGenerator) debugAccountAt(blockHash libcommon.Hash, txIndex uint64, account libcommon.Address) (RPCMethod, string) {
|
|
const template = `{"jsonrpc":"2.0","method":%q,"params":["0x%x",%d, "0x%x"],"id":%d}`
|
|
return Methods.DebugAccountAt, fmt.Sprintf(template, Methods.DebugAccountAt, blockHash, txIndex, account, req.reqID)
|
|
}
|