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

feat(ARCO-299): merge register and request transactions in blocktx #687

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kuba-4chain
Copy link
Collaborator

@kuba-4chain kuba-4chain commented Dec 2, 2024

Description of Changes

Previously, there were separate goroutines for registering and requesting transactions in blocktx.

This caused an issue - when a transaction was not registered for some reason (e.g. nats queue temporarily down), we wouldn't get it back when requesting from metamorph, even though the transaction was mined and existing in blocktx database.

Now, with this PR, they are merged together, so that even if transaction would not be registered in the first call, it would be registered in any of the subsequent calls to request-tx topic.

Linked Issues / Tickets

Reference any related issues or tickets, e.g. "Closes #123".

Testing Procedure

Describe the tests you've added or any testing steps you've taken.

  • I have added new unit tests
  • All tests pass locally
  • I have tested manually in my local environment

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have updated CHANGELOG.md with my changes

@@ -102,7 +102,7 @@ blocktx:
maxOpenConns: 80 # maximum open connections
sslMode: disable
recordRetentionDays: 28 # number of days for which data integrity is ensured
registerTxsInterval: 10s # time interval to read from the channel registered transactions
requestTxsInterval: 10s # time interval to register and request mined transactions
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should keep here the name registerTxsInterval and also topic RegisterTxTopic = "register-tx" and drop requestTxsInterval instead because a new tx is always registered. So that is kind a core functionality.

The functionality for requesting a tx because it wasn't mined for too long is rather an exception in case that e.g. blocktx was failing for some reason. So that is like an auxiliary functionality.

@@ -681,92 +679,8 @@ func TestPostgresStore_UpsertBlockTransactions_CompetingBlocks(t *testing.T) {
require.NoError(t, err)

// then
actual, err := sut.GetMinedTransactions(ctx, []*chainhash.Hash{txHash})
actual, err := sut.UpsertAndGetMinedTransactions(ctx, [][]byte{txHash[:]})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this really cover all of the test cases from TestPostgresStore_RegisterTransactions ?

Maybe we should keep and adapt TestPostgresStore_RegisterTransactions to TestPostgresStore_UpsertAndGetMinedTransactions

@boecklim boecklim assigned boecklim and kuba-4chain and unassigned boecklim Dec 2, 2024
func (p *Processor) StartProcessRequestTxs() {
p.waitGroup.Add(1)

txHashes := make([]*chainhash.Hash, 0, p.registerRequestTxsBatchSize)
txHashes := make([][]byte, 0, p.requestTxsBatchSize)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@@ -355,8 +305,8 @@ func (p *Processor) StartProcessRequestTxs() {
continue // retry, don't clear the txHashes slice
}

txHashes = make([]*chainhash.Hash, 0, p.registerRequestTxsBatchSize)
ticker.Reset(p.registerRequestTxsInterval)
txHashes = make([][]byte, 0, p.requestTxsBatchSize)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
txHashes = make([][]byte, 0, p.requestTxsBatchSize)
txHashes = txHashes [:0]

for _, minedTx := range minedTxs {
txBlock := &blocktx_api.TransactionBlock{
TransactionHash: minedTx.TxHash,
BlockHash: minedTx.BlockHash,
BlockHeight: minedTx.BlockHeight,
MerklePath: minedTx.MerklePath,
}

err = p.mqClient.PublishMarshal(p.ctx, MinedTxsTopic, txBlock)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
err = p.mqClient.PublishMarshal(p.ctx, MinedTxsTopic, txBlock)
publishErr = p.mqClient.PublishMarshal(p.ctx, MinedTxsTopic, txBlock)

@arkadiuszos4chain
Copy link
Collaborator

I have doubts about this solution. It might be beneficial to reduce one goroutine in blocktx , in exchange place the more costly SQL statement in the remaining one - I don't know. However, the problem lies with NATS itself.

In the current code, even if we fail to register a transaction and blocktx doesn't publish some transactions during its processing, metamorph will request them through our fallback goroutine (processor.StartRequestingSeenOnNetworkTxs()) via the message queue. As a result, these transactions should be received via the message queue, marked as MINED, and callbacks will be sent.

So, we don't need to add any new steps, fallbacks etc. to the current solution. Instead, we need to handle NATS connection errors.

@boecklim boecklim marked this pull request as draft January 7, 2025 14:57
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.

3 participants