Skip to content

Commit

Permalink
Merge pull request #2609 from gobitfly/BIDS-2561/use_eth_getblockreci…
Browse files Browse the repository at this point in the history
…epts

BIDS-2561/use_eth_getblockreciepts
  • Loading branch information
recy21 authored Oct 16, 2023
2 parents f75efec + 2220042 commit 1df9709
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion local-deployment/network-params.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"deneb_fork_epoch": 999999999
},
"global_client_log_level": "info",
"start_tx_spammer": false,
"start_tx_spammer": true,
"start_blob_spammer": false
}

44 changes: 13 additions & 31 deletions rpc/erigon.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ func NewErigonClient(endpoint string) (*ErigonClient, error) {

rpcClient, err := geth_rpc.Dial(client.endpoint)
if err != nil {
return nil, fmt.Errorf("error dialing rpc node: %v", err)
return nil, fmt.Errorf("error dialing rpc node: %w", err)
}
client.rpcClient = rpcClient

ethClient, err := ethclient.Dial(client.endpoint)
if err != nil {
return nil, fmt.Errorf("error dialing rpc node: %v", err)
return nil, fmt.Errorf("error dialing rpc node: %w", err)
}
client.ethClient = ethClient

client.multiChecker, err = NewBalance(common.HexToAddress("0xb1F8e55c7f64D203C1400B9D8555d050F94aDF39"), client.ethClient)
if err != nil {
return nil, fmt.Errorf("error initiation balance checker contract: %v", err)
return nil, fmt.Errorf("error initiation balance checker contract: %w", err)
}

return client, nil
Expand Down Expand Up @@ -144,7 +144,6 @@ func (client *ErigonClient) GetBlock(number int64, traceMode string) (*types.Eth
}

receipts := make([]*geth_types.Receipt, len(block.Transactions()))
reqs := make([]geth_rpc.BatchElem, len(block.Transactions()))

if len(block.Withdrawals()) > 0 {
withdrawalsIndexed := make([]*types.Eth1Withdrawal, 0, len(block.Withdrawals()))
Expand Down Expand Up @@ -217,7 +216,7 @@ func (client *ErigonClient) GetBlock(number int64, traceMode string) (*types.Eth

if err != nil {
if traceMode == "parity" {
return fmt.Errorf("error tracing block via parity style traces (%v), %v: %v", block.Number(), block.Hash(), err)
return fmt.Errorf("error tracing block via parity style traces (%v), %v: %w", block.Number(), block.Hash(), err)
} else {
logger.Errorf("error tracing block via parity style traces (%v), %v: %v", block.Number(), block.Hash(), err)

Expand Down Expand Up @@ -280,7 +279,7 @@ func (client *ErigonClient) GetBlock(number int64, traceMode string) (*types.Eth
gethTraceData, err := client.TraceGeth(block.Hash())

if err != nil {
return fmt.Errorf("error tracing block via geth style traces (%v), %v: %v", block.Number(), block.Hash(), err)
return fmt.Errorf("error tracing block via geth style traces (%v), %v: %w", block.Number(), block.Hash(), err)
}

// logger.Infof("retrieved %v calls via geth", len(gethTraceData))
Expand Down Expand Up @@ -331,31 +330,14 @@ func (client *ErigonClient) GetBlock(number int64, traceMode string) (*types.Eth
return nil
})

for i := range reqs {
reqs[i] = geth_rpc.BatchElem{
Method: "eth_getTransactionReceipt",
Args: []interface{}{txs[i].Hash().String()},
Result: &receipts[i],
}
if err = client.rpcClient.CallContext(ctx, &receipts, "eth_getBlockReceipts", fmt.Sprintf("0x%x", block.NumberU64())); err != nil {
return nil, nil, fmt.Errorf("error retrieving receipts for block %v: %w", block.Number(), err)
}

if len(reqs) > 0 {
if err := client.rpcClient.BatchCallContext(ctx, reqs); err != nil {
return nil, nil, fmt.Errorf("error retrieving receipts for block %v: %v", block.Number(), err)
}
}
timings.Receipts = time.Since(start)
start = time.Now()

for i := range reqs {
if reqs[i].Error != nil {
return nil, nil, fmt.Errorf("error retrieving receipt %v for block %v: %v", i, block.Number(), reqs[i].Error)
}
if receipts[i] == nil {
return nil, nil, fmt.Errorf("got null value for receipt %d of block %v", i, block.Number())
}

r := receipts[i]
for i, r := range receipts {
c.Transactions[i].ContractAddress = r.ContractAddress[:]
c.Transactions[i].CommulativeGasUsed = r.CumulativeGasUsed
c.Transactions[i].GasUsed = r.GasUsed
Expand Down Expand Up @@ -406,7 +388,7 @@ func (client *ErigonClient) GetLatestEth1BlockNumber() (uint64, error) {

latestBlock, err := client.ethClient.BlockByNumber(ctx, nil)
if err != nil {
return 0, fmt.Errorf("error getting latest block: %v", err)
return 0, fmt.Errorf("error getting latest block: %w", err)
}

return latestBlock.NumberU64(), nil
Expand Down Expand Up @@ -565,7 +547,7 @@ func (client *ErigonClient) GetBalances(pairs []*types.Eth1AddressBalance, addre

err := client.rpcClient.BatchCall(batchElements)
if err != nil {
return nil, fmt.Errorf("error during batch request: %v", err)
return nil, fmt.Errorf("error during batch request: %w", err)
}

for i, el := range batchElements {
Expand Down Expand Up @@ -660,7 +642,7 @@ func (client *ErigonClient) GetERC20TokenMetadata(token []byte) (*types.ERC20Met
return nil
}

return fmt.Errorf("error retrieving symbol: %v", err)
return fmt.Errorf("error retrieving symbol: %w", err)
}

ret.Symbol = symbol
Expand All @@ -670,7 +652,7 @@ func (client *ErigonClient) GetERC20TokenMetadata(token []byte) (*types.ERC20Met
g.Go(func() error {
totalSupply, err := contract.TotalSupply(nil)
if err != nil {
return fmt.Errorf("error retrieving total supply: %v", err)
return fmt.Errorf("error retrieving total supply: %w", err)
}
ret.TotalSupply = totalSupply.Bytes()
return nil
Expand All @@ -679,7 +661,7 @@ func (client *ErigonClient) GetERC20TokenMetadata(token []byte) (*types.ERC20Met
g.Go(func() error {
decimals, err := contract.Decimals(nil)
if err != nil {
return fmt.Errorf("error retrieving decimals: %v", err)
return fmt.Errorf("error retrieving decimals: %w", err)
}
ret.Decimals = big.NewInt(int64(decimals)).Bytes()
return nil
Expand Down

0 comments on commit 1df9709

Please sign in to comment.