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

refactor: sample impl with new p2p #636

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arkadiuszos4chain
Copy link
Collaborator

@arkadiuszos4chain arkadiuszos4chain commented Nov 7, 2024

Description of Changes

Sample implementation using the new experimental P2P functionality.

Several files have been modified due to a package name change in go-p2p, but the most significant changes are in:

  • internal/blocktx/p2p - includes all P2P logic, a new message handler (equivalent to the previous peer_handler), initialization, etc.
  • internal/metamorph/p2p - new message handler, also equivalent to the previous peer_handler
  • internal/metamorph/processor.go - updates in StartProcessExpiredTransactions(), now sending/requesting transactions in batches
  • internal/metamorph/store/postgresql/postgres - introduces IncrementRetriesForMany()

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

@arkadiuszos4chain arkadiuszos4chain self-assigned this Nov 7, 2024
@arkadiuszos4chain arkadiuszos4chain force-pushed the refactor-p2p-experimental branch 2 times, most recently from df39d25 to ea6b386 Compare November 12, 2024 16:48
Copy link

sonarcloud bot commented Nov 13, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
10.5% Coverage on New Code (required ≥ 80%)
E Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@arkadiuszos4chain arkadiuszos4chain marked this pull request as ready for review November 13, 2024 17:21
Comment on lines +170 to +171

replace github.com/libsv/go-p2p => github.com/arkadiuszos4chain/go-p2p v0.0.0-20241108223608-ded470665895
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a reminder - to be removed and replaced with go-p2p v2

Comment on lines +672 to 675
// GetPeersNmber returns a list of connected and a list of disconnected peers
func (p *Processor) GetPeersNmber() uint {
return p.pm.CountConnectedPeers()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know if it was on purpose, but just in case 😄

Suggested change
// GetPeersNmber returns a list of connected and a list of disconnected peers
func (p *Processor) GetPeersNmber() uint {
return p.pm.CountConnectedPeers()
}
// GetPeersNumber returns a list of connected and a list of disconnected peers
func (p *Processor) GetPeersNumber() uint {
return p.pm.CountConnectedPeers()
}

Comment on lines +129 to +141
// TODO: do we need this kind of info? do we check it?

peersConnected := make([]string, 0, len(peers))
peersDisconnected := make([]string, 0, len(peers))
for _, peer := range peers {
if peer.Connected() {
peersConnected = append(peersConnected, peer.String())
} else {
peersDisconnected = append(peersDisconnected, peer.String())
}
}
// peers := s.processor.GetPeers()

// peersConnected := make([]string, 0, len(peers))
// peersDisconnected := make([]string, 0, len(peers))
// for _, peer := range peers {
// if peer.Connected() {
// peersConnected = append(peersConnected, peer.String())
// } else {
// peersDisconnected = append(peersDisconnected, peer.String())
// }
// }
Copy link
Collaborator

@kuba-4chain kuba-4chain Nov 14, 2024

Choose a reason for hiding this comment

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

It's not my call, but IMO we can remove it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the new implementation, there is no need to distinguish between a connected peer and a healthy one. If the peer is connected, it is healthy. If it becomes unhealthy (error, ping-pong failed), it will disconnect and wait for the client(owner) to initiate a reconnect

Comment on lines +614 to 618
// // mark that we retried processing this transaction once more
// if err = p.store.IncrementRetries(ctx, tx.Hash); err != nil {
// p.logger.Error("Failed to increment retries in database", slog.String("err", err.Error()))
// }

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you're using IncrementRetriesForMany, this comment can be removed, right?

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.

2 participants