-
Notifications
You must be signed in to change notification settings - Fork 33
Conversation
7ed1432
to
20adcc6
Compare
20adcc6
to
cd92056
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 { | |||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
0fa42db
to
41ed9a0
Compare
any logs at that header but other contracts do; test
41ed9a0
to
af5b6cc
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 "" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
af5b6cc
to
a2d249c
Compare
Mark header checked for contract if it doesn't have any logs at that header but other contracts do.
Test added.