Skip to content
This repository has been archived by the owner on Mar 2, 2023. It is now read-only.

Make accounter schedule transactions explicitly #17

Merged
merged 1 commit into from
Oct 16, 2018

Conversation

mbyczkowski
Copy link
Collaborator

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.

@coveralls
Copy link

coveralls commented Oct 13, 2018

Pull Request Test Coverage Report for Build 164

  • 44 of 144 (30.56%) changed or added relevant lines in 5 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.8%) to 38.612%

Changes Missing Coverage Covered Lines Changed/Added Lines %
backend/recorder_backend.go 0 4 0.0%
backend/electrum_backend.go 0 23 0.0%
backend/btcd_backend.go 0 73 0.0%
Files with Coverage Reduction New Missed Lines %
backend/electrum_backend.go 1 0.0%
Totals Coverage Status
Change from base Build 155: 0.8%
Covered Lines: 434
Relevant Lines: 1124

💛 - Coveralls

lastAddresses [2]uint32
derivedAddrCount uint32
processedAddrCount uint32
seenTxCount uint32
Copy link
Contributor

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.

Copy link
Collaborator Author

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++
Copy link
Contributor

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?

Copy link
Collaborator Author

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)
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Collaborator Author

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?

@@ -27,6 +27,7 @@ import (
type Backend interface {
AddrRequest(addr *deriver.Address)
AddrResponses() <-chan *AddrResponse
TxRequest(txHash string)
TxResponses() <-chan *TxResponse

Finish()
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

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.
@mbyczkowski mbyczkowski merged commit 2b1e6a1 into master Oct 16, 2018
@mbyczkowski mbyczkowski deleted the simplify-backends branch October 16, 2018 19:50
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