-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/limits' into 'dev'
feat: limits Closes #81 See merge request ergo/rosen-bridge/rosenet!40
- Loading branch information
Showing
6 changed files
with
99 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rosen-bridge/rosenet-node': minor | ||
--- | ||
|
||
Add pubsub limits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rosen-bridge/rosenet-node': minor | ||
--- | ||
|
||
Add timeout for handling incoming direct messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,39 @@ | ||
import { Libp2p, PubSub } from '@libp2p/interface'; | ||
import { bulkhead, isBulkheadRejectedError } from 'cockatiel'; | ||
|
||
import RoseNetNodeContext from '../context/RoseNetNodeContext'; | ||
|
||
import { | ||
MAX_OUTBOUND_PUBSUB_QUEUE_SIZE, | ||
MAX_OUTBOUND_PUBSUB_THROUGHPUT, | ||
} from '../constants'; | ||
|
||
const textEncoder = new TextEncoder(); | ||
|
||
const bulkheadPolicy = bulkhead( | ||
MAX_OUTBOUND_PUBSUB_THROUGHPUT, | ||
MAX_OUTBOUND_PUBSUB_QUEUE_SIZE, | ||
); | ||
|
||
/** | ||
* factory for libp2p publish | ||
*/ | ||
const publishFactory = | ||
(node: Libp2p<{ pubsub: PubSub }>) => | ||
async (topic: string, message: string) => { | ||
node.services.pubsub.publish(topic, textEncoder.encode(message)); | ||
try { | ||
await bulkheadPolicy.execute(() => | ||
node.services.pubsub.publish(topic, textEncoder.encode(message)), | ||
); | ||
} catch (error) { | ||
if (isBulkheadRejectedError(error)) { | ||
RoseNetNodeContext.logger.warn('Maximum publish threshold reached'); | ||
} else { | ||
RoseNetNodeContext.logger.warn('Message publish failed', { | ||
message, | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
export default publishFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters