-
Notifications
You must be signed in to change notification settings - Fork 20
Make accounter schedule transactions explicitly #17
Conversation
Pull Request Test Coverage Report for Build 164
💛 - Coveralls |
5aa6b9a
to
f29dfbf
Compare
lastAddresses [2]uint32 | ||
derivedAddrCount uint32 | ||
processedAddrCount uint32 | ||
seenTxCount uint32 |
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.
we could use a single sync.Wg for all the backend channels here. Increment it before we write to any channel, decrement it when we read data.
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.
Would this give us anything useful? We keep generating more addresses, so at some point WaitGroup can be done, but there might be more data in-flight. Maybe there's an elegant solution I cannot yet see 🤔
for _, txHash := range resp.TxHashes { | ||
if _, exists := a.transactions[txHash]; !exists { | ||
a.backend.TxRequest(txHash) | ||
a.seenTxCount++ |
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.
you want to increment a.seenTxCount
before making the request?
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.
yes. sloppy coding 😅
eb.txRequests <- txHash | ||
return err | ||
} | ||
height, err := eb.getTxHeight(txHash) | ||
if err != nil { | ||
// a transaction thas is being asked for is not in the cache, yet (most likely) |
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.
Have you figured out why this could happen? For now we can have a panic() here if the cache is inconsistent and I can debug later.
@@ -27,6 +27,7 @@ import ( | |||
type Backend interface { |
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.
we'll have to eventually update the comment above this.
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.
you mostly addressed the comment for the Backend interface in other PRs, right?
backend/backend.go
Outdated
@@ -27,6 +27,7 @@ import ( | |||
type Backend interface { | |||
AddrRequest(addr *deriver.Address) | |||
AddrResponses() <-chan *AddrResponse | |||
TxRequest(txHash string) | |||
TxResponses() <-chan *TxResponse | |||
|
|||
Finish() |
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.
Finish() should no longer be needed?
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.
We could get rid off it, but it feels weird to me that we're not closing resources properly. I think backend should have a proper Close()
method if someone wanted to use a backend API outside of beancounter.
f29dfbf
to
f99aad3
Compare
This should: a) simplify backend logic. There are now AddrRequest<->AddrResponses and TxRequest<->TxResponses pipelines. Backends don't have to track transactions that are seen in order to avoid sending duplicate entries to the accounter. b) make sure accounter stops when all the transactions are received from the backend. The accounter keeps track of derived and processed addresses. It can now see how many transactions each address has and then schedule those transactions accordingly with the backend. Then it knows, how many (non-duplicate) transactions it has to receive before completing the fetchTransactions step and moving to processing all the transaction information.
959d5a0
to
27a8002
Compare
This should:
a) simplify backend logic. There are now AddrRequest<->AddrResponses and
TxRequest<->TxResponses pipelines. Backends don't have to track
transactions that are seen in order to avoid sending duplicate
entries to the accounter.
b) make sure accounter stops when all the transactions are received
from the backend. The accounter keeps track of derived and processed
addresses. It can now see how many transactions each address has
and then schedule those transactions accordingly with the backend.
Then it knows, how many (non-duplicate) transactions it has to receive
before completing the fetchTransactions step and moving to
processing all the transaction information.