Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the performance of eth_getLogs #583

Merged
merged 13 commits into from
Aug 3, 2024

Conversation

JukLee0ira
Copy link

@JukLee0ira JukLee0ira commented Jul 15, 2024

Proposed changes

Continuation of PR #569 and resolved the issue #560 .From the below data,when not returning logs, performance improved by over 70% after optimization

Performance Comparison

The time taken by the eth_getLogs method to query logs within different block ranges before and after optimization is shown below.After optimization, the performance of XDC and other chain queries to logs is as follows (network delay not excluded):

  • XDC1 is the dev-upgrade branch,XDC2 is the dev-upgrade branch with this PR
  • 2nd means considering the effect of cached data.
  • The times are measured in seconds.
Range XDC1
1st
XDC2
1st
ETH
1st
BSC
1st
MATIC
1st
XDC1
2nd
XDC2
2nd
ETH
2nd
BSC
2nd
MATIC
2nd
1M - 2M 5.198 0.758 0.226 0.204 0.230 0.086 0.062 0.231 0.195 0.226
2M - 3M 3.965 0.652 0.232 0.210 0.244 0.092 0.068 0.217 0.252 0.229
3M - 4M 4.451 0.569 0.225 0.216 0.267 0.082 0.076 0.218 0.210 0.264
4M - 5M 3.858 0.642 0.217 0.221 0.247 0.071 0.065 0.228 0.207 0.223
5M - 6M 4.781 0.681 0.231 0.220 0.237 0.081 0.071 0.215 0.217 0.245
6M - 7M 4.692 0.557 0.194 0.237 0.247 0.090 0.067 0.226 0.203 0.230
7M - 8M 3.625 0.672 0.207 0.228 0.243 0.074 0.075 0.214 0.235 0.234
8M - 9M 3.944 0.641 0.244 0.226 0.269 0.081 0.067 0.209 0.213 0.250
9M - 10M 4.148 0.667 0.201 0.203 0.247 0.081 0.080 0.230 0.215 0.242
10M - 11M 4.143 0.626 0.199 0.206 0.196 0.069 0.067 0.202 0.222 0.246
11M - 12M 4.548 0.634 0.216 0.227 0.294 0.073 0.069 0.211 0.211 0.237
12M - 13M 4.647 0.663 0.223 0.219 0.219 0.087 0.068 0.214 0.237 0.195
  • The script used to query Logs is as follows:
#!/bin/bash

getLogs() {
	fromBlock=$1
	toBlock=$2
	address=$3
	node_url=$4

	# Convert decimal block numbers to hexadecimal
	fromBlockHex=$(printf "0x%x" $fromBlock)
	toBlockHex=$(printf "0x%x" $toBlock)

	start=$(date +%s.%N)

	# Capture time and curl output
	output=$(
		{ curl -s -m 30 -X POST -H "Content-Type: application/json" --data '{
        "method": "eth_getLogs",
        "params": [{
            "fromBlock": "'$fromBlockHex'",
            "toBlock": "'$toBlockHex'",
            "address": "'$address'",
            "topics": []
        }],
        "id": 1,
        "jsonrpc": "2.0"
        }' $node_url | jq '.result | length'; }
	)
	end=$(date +%s.%N)
	if [ $? -ne 0 ]; then
		echo "Curl request failed"
		return
	fi

	# Extract real time
	real_time=$(echo "$end - $start" | bc)

	# Output real time and result array length
	printf "%.3f\t" "$real_time"
}

queryLogsForBlockRange() {
	END=$((BEGIN + 1000000))
	echo "block range from ${BEGIN} to ${END}"
	printf "XDC\tXDC\tETH\tETH\tBSC\tBSC\tMATIC\tMATIC\n"

	getLogs $BEGIN $END "0x4425f6eD1A919cB977484C84FeFD5c13884b47E3" "http://127.0.0.1:8545"
	getLogs $BEGIN $END "0x4425f6eD1A919cB977484C84FeFD5c13884b47E3" "http://127.0.0.1:8545"

	getLogs $BEGIN $END "0xDa4A7cB168362eE4A8e19129bc2283503196d1Bb" "https://eth-pokt.nodies.app"
	getLogs $BEGIN $END "0xDa4A7cB168362eE4A8e19129bc2283503196d1Bb" "https://eth-pokt.nodies.app"

	getLogs $BEGIN $END "0xF7A203e8eCecb3d944015820C212168bb722Bf84" "https://bsc-pokt.nodies.app"
	getLogs $BEGIN $END "0xF7A203e8eCecb3d944015820C212168bb722Bf84" "https://bsc-pokt.nodies.app"

	getLogs $BEGIN $END "0xc2132D05D31c914a87C6611C10748AEb04B58e8F" "https://polygon-bor-rpc.publicnode.com"
	getLogs $BEGIN $END "0xc2132D05D31c914a87C6611C10748AEb04B58e8F" "https://polygon-bor-rpc.publicnode.com"

	echo
}

echo "geting Logs..."
END_BLOCK=$((100 * 100 * 100))

for i in {1..12}; do
	BEGIN=$((i * 1000000))
	queryLogsForBlockRange ${BEGIN}
done

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement
  • Performance

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

@JukLee0ira JukLee0ira force-pushed the lazy-block branch 2 times, most recently from 379bf46 to 573c1a4 Compare July 15, 2024 03:23
@JukLee0ira JukLee0ira marked this pull request as ready for review July 15, 2024 03:24
@JukLee0ira JukLee0ira force-pushed the lazy-block branch 3 times, most recently from 319f631 to 3f663d2 Compare July 15, 2024 07:12
@JukLee0ira JukLee0ira changed the title Improve the performance of eth_getLog [WIP]Improve the performance of eth_getLog Jul 18, 2024
@JukLee0ira JukLee0ira changed the title [WIP]Improve the performance of eth_getLog Improve the performance of eth_getLog Jul 22, 2024
miner/worker.go Outdated Show resolved Hide resolved
eth/backend.go Outdated Show resolved Hide resolved
@gzliudan
Copy link
Collaborator

Please rearrange the commits in the following order:

2019-12-10 12:39:14: eth/filters: remove use of event.TypeMux for pending logs (#20312)
2021-01-21 12:17:10: eth/filters: fix potential deadlock in filter timeout loop (#22178)
2021-06-28 16:16:32: eth/gasprice: implement feeHistory API (#23033)
2021-09-28 12:54:49: core/rawdb: avoid unnecessary receipt processing for log filtering (#23147)
2022-04-29 10:07:52: eth/filters: remove unused struct fields (#24782)
2022-06-07 08:31:19: eth/filters: fix getLogs for pending block (#24949)
2022-06-21 12:05:43: all: remove concept of public/private API definitions (#25053)
2022-08-19 11:14:59: eth/filters: add global block logs cache (#25459)
2022-09-07 20:21:59: all: cleanup tests (#25641)
2022-11-14 15:41:56: common/lru: add generic LRU implementation (#26162)
2023-02-13 10:59:27: eth/filters: avoid block body retrieval when no matching logs (#25199)

@JukLee0ira JukLee0ira force-pushed the lazy-block branch 5 times, most recently from b34e545 to 060607c Compare July 23, 2024 03:33
@gzliudan
Copy link
Collaborator

The function SendTransaction should return pending receipts in commit eth/filters: fix pending for getLogs.

@JukLee0ira JukLee0ira force-pushed the lazy-block branch 2 times, most recently from 6843c76 to 51ce95a Compare July 23, 2024 07:32
@JukLee0ira JukLee0ira marked this pull request as draft July 23, 2024 07:39
@JukLee0ira JukLee0ira force-pushed the lazy-block branch 4 times, most recently from 8a930e0 to 7469de4 Compare July 23, 2024 08:25
@JukLee0ira JukLee0ira marked this pull request as ready for review July 23, 2024 08:25
@gzliudan
Copy link
Collaborator

please share the performance data about this PR.

Copy link
Collaborator

@gzliudan gzliudan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct typo:

eth: remove ChainDb filed in FilterAPI

les/backend.go Outdated Show resolved Hide resolved
@gzliudan gzliudan requested review from s1na and gzliudan July 29, 2024 01:26
@gzliudan gzliudan requested review from liam-lai and wjrjerome and removed request for s1na July 29, 2024 03:38
@JukLee0ira JukLee0ira force-pushed the lazy-block branch 2 times, most recently from fa4c4c6 to 09e45c6 Compare August 3, 2024 01:24
@gzliudan gzliudan merged commit 9a40c26 into XinFinOrg:dev-upgrade Aug 3, 2024
17 checks passed
@JukLee0ira JukLee0ira mentioned this pull request Aug 7, 2024
20 tasks
@JukLee0ira JukLee0ira mentioned this pull request Aug 26, 2024
20 tasks
@gzliudan gzliudan changed the title Improve the performance of eth_getLog Improve the performance of eth_getLogs Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants