Skip to content

Commit

Permalink
Add HybridRelayer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Nov 18, 2024
1 parent 9176710 commit 7b0e4a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion data/txHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ type TxHandlerOpts struct {
Config config.Local
}

// HybridRelayer is an interface for relaying p2p transactions to WS network
type HybridRelayer interface {
BridgeP2PToWS(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except network.Peer) error
}

// MakeTxHandler makes a new handler for transaction messages
func MakeTxHandler(opts TxHandlerOpts) (*TxHandler, error) {

Expand Down Expand Up @@ -859,7 +864,9 @@ func (handler *TxHandler) validateIncomingTxMessage(rawmsg network.IncomingMessa
logging.Base().Infof("unable to pin transaction: %v", err)
}

_ = handler.net.Relay(handler.ctx, protocol.TxnTag, reencoded, false, wi.rawmsg.Sender)
if hybridNet, ok := handler.net.(HybridRelayer); ok {
_ = hybridNet.BridgeP2PToWS(handler.ctx, protocol.TxnTag, reencoded, false, wi.rawmsg.Sender)

Check warning on line 868 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L868

Added line #L868 was not covered by tests
}

return network.OutgoingMessage{
Action: network.Accept,
Expand Down
5 changes: 5 additions & 0 deletions network/hybridNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ func (n *HybridP2PNetwork) Relay(ctx context.Context, tag protocol.Tag, data []b
})
}

// BridgeP2PToWS skips Relay/Broadcast to both networks and only sends to WS
func (n *HybridP2PNetwork) BridgeP2PToWS(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error {
return n.wsNetwork.Relay(ctx, tag, data, wait, except)

Check warning on line 130 in network/hybridNetwork.go

View check run for this annotation

Codecov / codecov/patch

network/hybridNetwork.go#L129-L130

Added lines #L129 - L130 were not covered by tests
}

// Disconnect implements GossipNode
func (n *HybridP2PNetwork) Disconnect(badnode DisconnectablePeer) {
net := badnode.GetNetwork()
Expand Down

0 comments on commit 7b0e4a0

Please sign in to comment.