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

feat: chain watcher #47

Merged
merged 9 commits into from
Sep 26, 2023
Merged

feat: chain watcher #47

merged 9 commits into from
Sep 26, 2023

Conversation

mfw78
Copy link
Contributor

@mfw78 mfw78 commented Sep 21, 2023

Description

As we are removing Tenderly, we need to handle our own run loops for watching blocks / transaction logs.

Changes

  • Add warmUp to initialise state from genesis, or last processed block.
  • Used rebuild logic from feat: state rebuilder #29 for warmUp
  • Once warmUp is complete, flag as inSync, and commence block watching.
  • Implemented all in ChainWatcher, which runs per-chain, but we can handle many RPCs
  • All chains watched from the same instance.

How to test

No unit tests available, however can observe functionality, such as with:

yarn ts-node ./src/watchtower.ts run --rpc http://erigon.dappnode:8545 --rpc http://nethermind-xdai.dappnode:8545 --deployment-block 17883049 --deployment-block 29389123 --page-size 0

NOTE: Substitute the above RPCs with the RPCs of your choice for the chains.

Observe synchronising of state. If Ctrl+C, observe SIGINT is caught, database is saved. Restart, and node resumes from last known synced block.

Todo

  • Check for TODOs / dead code.

Related Issues

Closes #46

@mfw78 mfw78 added the enhancement New feature or request label Sep 21, 2023
@mfw78 mfw78 requested review from anxolin and a team September 21, 2023 22:43
@mfw78 mfw78 self-assigned this Sep 21, 2023
@mfw78 mfw78 linked an issue Sep 21, 2023 that may be closed by this pull request
@mfw78 mfw78 marked this pull request as ready for review September 22, 2023 05:22
src/addContract.ts Outdated Show resolved Hide resolved
src/modes/run.ts Outdated Show resolved Hide resolved
src/modes/run.ts Show resolved Hide resolved
src/modes/run.ts Show resolved Hide resolved
src/modes/run.ts Show resolved Hide resolved
src/modes/run.ts Outdated Show resolved Hide resolved
src/modes/run.ts Show resolved Hide resolved
src/modes/run.ts Show resolved Hide resolved
src/modes/run.ts Show resolved Hide resolved
@@ -253,10 +254,7 @@ export class ChainContext {
this.chainId = chainId;
}

public static async create(
storage: DBService,
Copy link
Contributor

Choose a reason for hiding this comment

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

in my oppinion here the logic is inverted. The model should not receive a DB and persist itself. The model should expose plain data and the persistance layer persist it

Otherwise you couple the model to the persistance layer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a little strange as I show:

  public static async create(url: string): Promise<ChainContext> {
    const provider = new ethers.providers.JsonRpcProvider(url);
    const chainId = (await provider.getNetwork()).chainId;
    return new ChainContext(provider, apiUrl(chainId), chainId);
  }

Around this function. Nonetheless, can be added in a later PR to get over the waterfall 🐃

src/modes/run.ts Show resolved Hide resolved
Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

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

Worked great

@mfw78 mfw78 changed the base branch from feat-leveldb to standalone September 26, 2023 05:30
@mfw78 mfw78 mentioned this pull request Sep 26, 2023
9 tasks
@mfw78 mfw78 merged commit 8047243 into standalone Sep 26, 2023
2 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 26, 2023
@alfetopito alfetopito deleted the feat-chainwatcher branch September 26, 2023 14:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: implement own event watcher / block watcher
3 participants