-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: main
Are you sure you want to change the base?
Conversation
df39d25
to
ea6b386
Compare
ea6b386
to
4f9b01c
Compare
Quality Gate failedFailed conditions See analysis details on SonarQube Cloud Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE |
|
||
replace github.com/libsv/go-p2p => github.com/arkadiuszos4chain/go-p2p v0.0.0-20241108223608-ded470665895 |
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.
Just a reminder - to be removed and replaced with go-p2p v2
// GetPeersNmber returns a list of connected and a list of disconnected peers | ||
func (p *Processor) GetPeersNmber() uint { | ||
return p.pm.CountConnectedPeers() | ||
} |
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.
I don't know if it was on purpose, but just in case 😄
// 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() | |
} |
// 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()) | ||
// } | ||
// } |
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.
It's not my call, but IMO we can remove it
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.
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
// // 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())) | ||
// } | ||
|
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.
If you're using IncrementRetriesForMany
, this comment can be removed, right?
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_handlerinternal/metamorph/processor.go
- updates inStartProcessExpiredTransactions()
, now sending/requesting transactions in batchesinternal/metamorph/store/postgresql/postgres
- introducesIncrementRetriesForMany()
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.
Checklist:
CHANGELOG.md
with my changes