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

Add cache-based duplicate log detection to SafeEthClient #180

Merged
merged 8 commits into from
May 24, 2024

Conversation

Hyodar
Copy link
Contributor

@Hyodar Hyodar commented May 24, 2024

Currently, we are using simple block logic to skip possibly duplicate blocks. This is enough for our uses, since the log rate for the events should be 1 per block at most in a real scenario, but it's not a full solution. This PR introduces an LRU cache of log hashes (defined by ourselves) that is used to detect whether a log has been relayed yet or not. It also makes it so our log filtering starts from the last block, since we now can detect duplicate blocks - so if, e.g. there were 2 block emissions on lastBlock and we'd only gotten 1 before filtering logs, we don't lose the second one.

@Hyodar Hyodar self-assigned this May 24, 2024
@Hyodar Hyodar marked this pull request as ready for review May 24, 2024 16:29
@Hyodar Hyodar force-pushed the feat/improve-log-skipping branch from 1420d57 to e978a5f Compare May 24, 2024 16:31
@Hyodar Hyodar requested review from taco-paco and emlautarom1 and removed request for taco-paco May 24, 2024 16:47
@Hyodar Hyodar force-pushed the feat/improve-log-skipping branch from d8010ef to 837b176 Compare May 24, 2024 17:06
@Hyodar Hyodar force-pushed the feat/improve-log-skipping branch from 837b176 to f47114d Compare May 24, 2024 17:21
Copy link
Contributor

@emlautarom1 emlautarom1 left a comment

Choose a reason for hiding this comment

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

Implementation looks fine (client.go) but the tests seem quite complicated to follow. I'm approving now to merge ASAP as requested

@@ -187,7 +200,7 @@ func (c *SafeEthClient) SubscribeFilterLogs(ctx context.Context, q ethereum.Filt
rangeStartBlock = 0
}

fromBlock := max(lastBlock, rangeStartBlock) + 1
fromBlock := max(lastBlock, rangeStartBlock+1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a bugfix?

Copy link
Contributor Author

@Hyodar Hyodar May 24, 2024

Choose a reason for hiding this comment

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

More or less, this is related to this part of the description:

It also makes it so our log filtering starts from the last block, since we now can detect duplicate blocks - so if, e.g. there were 2 block emissions on lastBlock and we'd only gotten 1 before filtering logs, we don't lose the second one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So if our log range start is based on the last block, then it's from lastBlock -> end instead of lastBlock + 1 -> end

Copy link
Contributor Author

@Hyodar Hyodar May 24, 2024

Choose a reason for hiding this comment

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

In practical terms this doesn't happen to us, but it is a fix overall now that we can detect duplicates

@Hyodar Hyodar merged commit ac7bf86 into main May 24, 2024
4 checks passed
@Hyodar Hyodar deleted the feat/improve-log-skipping branch October 3, 2024 17:24
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.

2 participants