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: dvm v2 monitor bots #4317

Merged
merged 58 commits into from
Jan 10, 2023
Merged

feat: dvm v2 monitor bots #4317

merged 58 commits into from
Jan 10, 2023

Conversation

Reinis-FRP
Copy link
Contributor

@Reinis-FRP Reinis-FRP commented Dec 16, 2022

Signed-off-by: Reinis Martinsons reinis@umaproject.org

Motivation

Improve DVMv2 monitoring.

Summary

Adds DVMv2 monitor bots.

Details

Following monitor bot modules have been added to emit logs when:

  • large amount of UMA requests unstake
  • large amount of UMA is staked
  • every time a governance proposal is submitted
  • every time a price request is deleted
  • every time an emergency proposal is created
  • if a vote rolls
  • large UMA transfers out from governor
  • outsized UMA mints

Testing

Check a box to describe how you tested these changes and list the steps for reviewers to test.

  • Ran end-to-end test, running the code as in production
  • New unit tests created
  • Existing tests adequate, no new tests required
  • All existing tests pass
  • Untested

@Reinis-FRP Reinis-FRP changed the title feat: implement dvm v2 unstake monitor feat: dvm v2 monitor bots Dec 17, 2022
@Reinis-FRP Reinis-FRP marked this pull request as ready for review December 27, 2022 22:45
@Reinis-FRP Reinis-FRP marked this pull request as draft December 27, 2022 22:47
@Reinis-FRP Reinis-FRP marked this pull request as ready for review December 28, 2022 00:12
Reinis-FRP and others added 22 commits December 28, 2022 12:02
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
* feat: update dvm2.0 upgrade script

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* feat: update starting index

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* refactor: update comments

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* feat: update starting index and starting id

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* fix: governor starting id

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* fix: add previous voting contracts events

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* fix: add previous voting contracts events docs

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

* refator: improve comment

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
Co-authored-by: Pablo Maldonado <pablo@umaproject.org>
Co-authored-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Co-authored-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
…s-v2 (#4318)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
* feat: new release

Captures MerkleTree util change to match across-protocol/contracts-v2

* Update CHANGELOG.md

* Update CHANGELOG.md

* lint

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
… and implementation (#4324)

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Co-authored-by: Pablo Maldonado <pablo@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
This reverts commit e674408.

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
@Reinis-FRP Reinis-FRP force-pushed the reinis-frp/dvm-monitor branch from 548b5e3 to 406b345 Compare December 28, 2022 12:03
@Reinis-FRP Reinis-FRP requested a review from daywiss as a code owner December 28, 2022 12:03
Copy link
Contributor

@daywiss daywiss left a comment

Choose a reason for hiding this comment

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

very cool, nice design, couple small nits

spamRequestIndices: event.args.spamRequestIndices,
}));
deletionProposals.forEach((proposal) => {
logDeletionProposed(logger, proposal, params.chainId);
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit but not sure why you have the .map, you could just change it to a .forEach and log with one iteration and less code, alternatively you could chain the map into the for each without needing to store the extra variable deletionProposals

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 was not able to reduce lines of code as significant part of this deals with passing proposal parameters to logDeletionProposed.

- `UNSTAKES_ENABLED` is boolean enabling/disabling monitoring large unstake attempts (disabled by default).
- `UNSTAKE_THRESHOLD` is UMA amount threshold to use when `UNSTAKES_ENABLED=true` (defaults to `"0"`).
- `STAKES_ENABLED` is boolean enabling/disabling monitoring large amount of UMA staked (disabled by default).
- `STAKE_THRESHOLD` is UMA amount threshold to use when `STAKES_ENABLED=true` (defaults to `"0"`).
Copy link
Contributor

Choose a reason for hiding this comment

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

need to specify units

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 201b24c

- `POLLING_DELAY` is value in seconds for delay between consecutive runs, defaults to 1 minute. If set to 0 then running in serverless mode will exit after the loop.
- `STARTING_BLOCK_NUMBER` and `ENDING_BLOCK_NUMBER` defines block range to look for events on L1 network. These are mandatory when `POLLING_DELAY=0`.
- `UNSTAKES_ENABLED` is boolean enabling/disabling monitoring large unstake attempts (disabled by default).
- `UNSTAKE_THRESHOLD` is UMA amount threshold to use when `UNSTAKES_ENABLED=true` (defaults to `"0"`).
Copy link
Contributor

Choose a reason for hiding this comment

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

what units?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 201b24c

botModes: BotModes;
}

export const initCommonEnvVars = async (env: NodeJS.ProcessEnv): Promise<MonitoringParams> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

i really like this pattern, but prefer you would have parsed and validated all values here rather than leaving out UNSTAKE_THRESHOLD and others to be referenced in the functions rather than the monitoring params

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 228982d

import type { MonitoringParams } from "./common";

export async function monitorMints(logger: typeof Logger, params: MonitoringParams): Promise<void> {
const mintsThreshold = utils.parseEther(process.env.MINTS_THRESHOLD || "0");
Copy link
Contributor

Choose a reason for hiding this comment

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

i would either turn this into a parameter or add it to monitoring params, same with all the other envs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 228982d

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Copy link
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

Looks great! A few minor comments

const identifiers = proposal.spamRequestIndices
.map((range) => (range[0].eq(range[1]) ? range[0].toString() : `${range[0]}-${range[1]}`))
.join(", ");
logger.warn({
Copy link
Member

Choose a reason for hiding this comment

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

nit: should this be an error log since it's so rare?

},
roundId: BigNumber
): void => {
logger.warn({
Copy link
Member

Choose a reason for hiding this comment

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

nit: similarly, I think this is rare enough to be an error log, no?

Comment on lines 87 to 88
params.startingBlock = params.endingBlock + 1;
params.endingBlock = latestBlockNumber;
Copy link
Member

Choose a reason for hiding this comment

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

nit: not a huge deal, but it can sometimes be confusing to modify POD that's passed into a method rather than returning the values to update or returning an updated copy. This is because readers often assume simple structs are considered immutable, especially in a method that's named "wait*" (which sounds like it just waits a certain amount of time based on the inputs!).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree, in 13108bb I updated waitNextBlockRange method to return new block range and it is updated within params only in index.ts

Comment on lines +53 to +62
const botModes = {
unstakesEnabled: env.UNSTAKES_ENABLED === "true",
stakesEnabled: env.STAKES_ENABLED === "true",
governanceEnabled: env.GOVERNANCE_ENABLED === "true",
deletionEnabled: env.DELETION_ENABLED === "true",
emergencyEnabled: env.EMERGENCY_ENABLED === "true",
rolledEnabled: env.ROLLED_ENABLED === "true",
governorTransfersEnabled: env.GOVERNOR_TRANSFERS_ENABLED === "true",
mintsEnabled: env.MINTS_ENABLED === "true",
};
Copy link
Member

Choose a reason for hiding this comment

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

I could see us wanting to make some of these errors rather than warnings. Have you considered adding a config element to configure the log level? It also might just be obvious which ones should be errors, so configuration may be overkill, but I definitely think some are error-worthy events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree, for now I just updated hard-coded log levels in b7cd55c. Now emergency proposal, spam deletion, rolled votes, large governor transfers and outsized UMA mints will error.

Comment on lines 9 to 11
```
yarn ts-node packages/scripts/src/monitor-dvm/index.ts
```
Copy link
Member

Choose a reason for hiding this comment

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

nit: This is just my opinion, but I think we should prefer using tsc + node over ts-node in production:

  • tsc is the official typescript implementation built by the typescript team. ts-node is a separate application maintained by a different group as far as I can tell.
  • It ensures that all these files are compiled and checked by tsc in our build process. With ts-node, it's possible that we skip building these files entirely in ci or partially build them. If that were the case, we would not get the advantage of typescript checking the types automatically as a part of our development process.
  • Performance reasons: see here and here.

IMO, it's totally fine to encourage ts-node for development purposes in the docs, but I think the default should always be tsc + node.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree, fixed

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
@Reinis-FRP Reinis-FRP requested a review from daywiss December 29, 2022 12:32
Copy link
Contributor

@daywiss daywiss left a comment

Choose a reason for hiding this comment

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

lgtm

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Copy link
Contributor

@md0x md0x left a comment

Choose a reason for hiding this comment

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

LGTM

@Reinis-FRP Reinis-FRP merged commit 5a6602e into master Jan 10, 2023
@Reinis-FRP Reinis-FRP deleted the reinis-frp/dvm-monitor branch January 10, 2023 21:01
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.

6 participants