Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Fix for issue #146 #158

Merged
merged 4 commits into from
Oct 28, 2019
Merged

Fix for issue #146 #158

merged 4 commits into from
Oct 28, 2019

Conversation

i-norden
Copy link
Collaborator

@i-norden i-norden commented Oct 10, 2019

Mark header checked for contract if it doesn't have any logs at that header but other contracts do.

Test added.

@i-norden i-norden force-pushed the missed_marked_checked_headers branch 2 times, most recently from 7ed1432 to 20adcc6 Compare October 15, 2019 19:02
@i-norden i-norden changed the title [WIP] Potential fix for issue #146 Fix for issue #146 Oct 15, 2019
@i-norden i-norden force-pushed the missed_marked_checked_headers branch from 20adcc6 to cd92056 Compare October 24, 2019 18:12
Copy link
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

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

Thanks for putting in work on this! Dig all the linter fixes 👍

Wondering if we could potentially simplify things by just marking all header fields checked after we iterated through all the logs we got back from the fetcher.

@@ -126,6 +128,7 @@ func (tr *Transformer) Init() error {
firstBlock, retrieveErr := tr.Retriever.RetrieveFirstBlock()
if retrieveErr != nil {
if retrieveErr == sql.ErrNoRows {
logrus.Error(retrieveErr)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Maybe worth adding some context with an Errorf?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, will do!

@@ -249,19 +253,32 @@ func (tr *Transformer) Execute() error {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What if just moved all the stuff in this guard to the bottom of the loop that's iterating through missing headers? Seems like the below loops through allLogs and sortedLogs would be a no-op and we could delete some code

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A bit frazzled at the moment but I think I see what you mean and if I'm understanding correctly then the only thing that gives me pause is what to do if we run into an error for a header. We still want to mark the headers processed up until that point as checked which is why I was marking them as we go, but the much better approach would be to keep track of which index in the headers we are at when the error occurs and mark all those below it as checked in a single batch call. Looks like I've introduced quite a bit of unnecessary complexity here, thanks for catching that!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I mean my thought was just that we'd call MarkHeaderChecked once per header, after we've iterated through all of its logs. [not proposing that we try to mark multiple headers checked at once, though I'm interested to check it out if it seems preferable]

I guess the likely objection would be making sure we preserve the ability to handle new contracts/logs being watched later on, but I think that would work fine? Assuming that a new checked column gets added and defaults to false...

Copy link
Collaborator Author

@i-norden i-norden Oct 28, 2019

Choose a reason for hiding this comment

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

So after taking a closer look again, the issue there is that the header is normally checked marked in the same transaction that is used to persist logs in this call. So what we have currently are calls to mark the header checked in the cases where that call is never reached.

It's a quick change though, and one that will remove some excess code- making it now.

@i-norden i-norden force-pushed the missed_marked_checked_headers branch from 0fa42db to 41ed9a0 Compare October 28, 2019 14:08
@i-norden i-norden force-pushed the missed_marked_checked_headers branch from 41ed9a0 to af5b6cc Compare October 28, 2019 14:41
Copy link
Contributor

@m0ar m0ar left a comment

Choose a reason for hiding this comment

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

Nice 😎

for _, log := range allLogs {
addr := strings.ToLower(log.Address.Hex())
sortedLogs[addr] = append(sortedLogs[addr], log)
}

// Process logs for each contract
for conAddr, logs := range sortedLogs {
if logs == nil {
con := tr.Contracts[conAddr]
if len(logs) < 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any potential consequences with removing the nil check?

Copy link
Collaborator Author

@i-norden i-norden Oct 28, 2019

Choose a reason for hiding this comment

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

The len(logs) substitutes for it and covers both the nil and empty slice case, but there is no situation where the logs will be length 0 without being nil so I can revert it back.

Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, TIL! Thought that'd lead to a NPE :)

if err != nil {
return "", fmt.Errorf("call to getSupportsInterface failed: %v", err)
if err != nil || !supports {
return ""
Copy link
Contributor

@m0ar m0ar Oct 28, 2019

Choose a reason for hiding this comment

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

Passing on the error makes it possible to differentiate between the call to the client failing and !supports. The empty string makes for a confusing error in the test :)

@@ -47,8 +47,7 @@ var _ = Describe("Interface Getter", func() {
transactionConverter := rpc2.NewRpcTransactionConverter(ethClient)
blockChain := eth.NewBlockChain(blockChainClient, rpcClient, node, transactionConverter)
interfaceGetter := getter.NewInterfaceGetter(blockChain)
abi, err := interfaceGetter.GetABI(constants.PublicResolverAddress, blockNumber)
Expect(err).NotTo(HaveOccurred())
abi := interfaceGetter.GetABI(constants.PublicResolverAddress, blockNumber)
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't I recently add this error propagation? If running the tests without the mainnet infura key set, the error is very confusing. This passed along the error from geth instead of making that abi just the empty string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My mistake, that makes sense- reverting back.

@i-norden i-norden force-pushed the missed_marked_checked_headers branch from af5b6cc to a2d249c Compare October 28, 2019 16:40
@i-norden i-norden merged commit b767531 into staging Oct 28, 2019
@m0ar m0ar deleted the missed_marked_checked_headers branch October 29, 2019 08:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants