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

Blockchain monitor component #15

Merged
merged 15 commits into from
Aug 22, 2023
Merged

Blockchain monitor component #15

merged 15 commits into from
Aug 22, 2023

Conversation

ross-weir
Copy link
Member

@ross-weir ross-weir commented Aug 16, 2023

closes #13

@arobsn this PR is getting a bit large, I have a issue tracking todos/fixes that I'll do in a follow up PR #16

Pipeline is going to be red but feel free to review & merge anyway

@@ -12,4 +12,6 @@ export interface BlockchainClient {
getBoxesByTokenId<T extends AmountType = string>(
tokenId: TokenId,
): AsyncGenerator<Box<T>[]>;

getMempool(): Promise<SignedTransaction[]>;
Copy link
Member Author

Choose a reason for hiding this comment

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

@arobsn do you have any feelings on adding the methods needed by the monitoring component to the blockchain client used by plugins?

I was on the fence on if it should be separate so plugin devs are guided into implementing the on* methods instead of calling the APIs manually - decided on it probably not being a big deal for now

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that exposing such a heavy endpoint is something good, on the other side, bots must be able to check the the mempool.

What do you think about holding the last mempool snapshot as an in-memory store? This way we avoid new calls if plugins need it the the mempool.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep this is a good idea, will do this

@ross-weir ross-weir mentioned this pull request Aug 17, 2023
6 tasks
@ross-weir ross-weir marked this pull request as ready for review August 17, 2023 09:30
@ross-weir ross-weir requested a review from arobsn August 17, 2023 09:32
src/blockchain/blockchain_monitor.ts Outdated Show resolved Hide resolved
async #monitor() {
this.logger.debug("Gathering blockchain state");

const mempool = await this.#blockchainClient.getMempool();
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to check if the mempool has changed before to download it. The /info/ endpoint returns a property called lastSeenMessageTime which returns the lest time the node received a p2p message. If I'm right, this can be used for such check.

@@ -12,4 +12,6 @@ export interface BlockchainClient {
getBoxesByTokenId<T extends AmountType = string>(
tokenId: TokenId,
): AsyncGenerator<Box<T>[]>;

getMempool(): Promise<SignedTransaction[]>;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that exposing such a heavy endpoint is something good, on the other side, bots must be able to check the the mempool.

What do you think about holding the last mempool snapshot as an in-memory store? This way we avoid new calls if plugins need it the the mempool.

src/blockchain/clients/node.ts Outdated Show resolved Hide resolved
@arobsn
Copy link
Member

arobsn commented Aug 17, 2023

Feel free to merge or continue from here )

// if a tx is not included in a block in dropChecks * `n` seconds,
// then it's probably dropped from the mempool
if (this.#state.mempoolTxChecks[txId] > this.#maxMempoolTxChecks) {
// TODO raise mempool dropped, so we still need to keep track of txns not just the id?
Copy link
Member Author

@ross-weir ross-weir Aug 18, 2023

Choose a reason for hiding this comment

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

@arobsn when a tx is dropped from mempool should we include the transaction when raising the event for plugins or do you think txId be enough?

Copy link
Member

Choose a reason for hiding this comment

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

Good question, I would go with the full transaction to keep hooks homogeneous and avoid more code on plugins side (IMO plugins must be as concise as possible to make auditing process easier).

@ross-weir ross-weir requested a review from arobsn August 18, 2023 08:56
// if a tx is not included in a block in dropChecks * `n` seconds,
// then it's probably dropped from the mempool
if (this.#state.mempoolTxChecks[txId] > this.#maxMempoolTxChecks) {
// TODO raise mempool dropped, so we still need to keep track of txns not just the id?
Copy link
Member

Choose a reason for hiding this comment

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

Good question, I would go with the full transaction to keep hooks homogeneous and avoid more code on plugins side (IMO plugins must be as concise as possible to make auditing process easier).

@ross-weir ross-weir merged commit cfe47f4 into main Aug 22, 2023
3 of 5 checks passed
@ross-weir ross-weir deleted the blockchain-monitor-component branch August 22, 2023 02:12
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.

Monitoring component
2 participants