Skip to content

Commit

Permalink
feat: introduce the drippie-mon service (#2687)
Browse files Browse the repository at this point in the history
* feat(ctp): minor Drippie client-side tweaks

Tweaks Drippie to make the client-side a bit simpler. Adds a separate
function "executable" that can be queried to see if a given drip is
currently executable. Updates events so that the name will be properly
emitted but can still be indexed.

* feat: introduce the drippie-mon service

Introduces drippie-mon, a basic service for monitoring Drippie
deployments. drippie-mon will increment a metric whenever a drip is
currently executable. Clients of drippie-mon can watch for this metric
to see if a drip has been executable for a while but has not yet been
executed.
  • Loading branch information
smartcontracts committed Jun 7, 2022
1 parent c258acd commit 982cb98
Show file tree
Hide file tree
Showing 21 changed files with 467 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-ants-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/contracts-periphery': patch
---

Tweaks Drippie contract for client-side ease
5 changes: 5 additions & 0 deletions .changeset/slow-numbers-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/drippie-mon': minor
---

Release drippie-mon
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jobs:
- packages/contracts-periphery/node_modules
- packages/core-utils/node_modules
- packages/data-transport-layer/node_modules
- packages/drippie-mon/node_modules
- packages/fault-detector/node_modules
- packages/message-relayer/node_modules
- packages/replica-healthcheck/node_modules
Expand Down Expand Up @@ -538,6 +539,11 @@ workflows:
package_name: fault-detector
requires:
- yarn-monorepo
- js-lint-test:
name: drippie-mon-tests
package_name: drippie-mon
requires:
- yarn-monorepo
- js-lint-test:
name: message-relayer-tests
package_name: message-relayer
Expand Down Expand Up @@ -628,6 +634,14 @@ workflows:
target: fault-detector
context:
- optimism
- docker-publish:
name: drippie-mon-release
docker_file: ops/docker/Dockerfile.packages
docker_tags: ethereumoptimism/drippie-mon:nightly
docker_context: .
target: drippie-mon
context:
- optimism
- docker-publish:
name: message-relayer-release
docker_file: ops/docker/Dockerfile.packages
Expand Down
1 change: 1 addition & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- 'packages/contracts/**/*'
- 'packages/contracts-periphery/**/*'
- 'packages/data-transport-layer/**/*'
- 'packages/drippie-mon/**/*'
- 'packages/message-relayer/**/*'
- 'packages/fault-detector/**/*'
- 'patches/**/*'
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/publish-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
l2geth: ${{ steps.packages.outputs.l2geth }}
message-relayer: ${{ steps.packages.outputs.message-relayer }}
fault-detector: ${{ steps.packages.outputs.fault-detector }}
drippie-mon: ${{ steps.packages.outputs.drippie-mon }}
data-transport-layer: ${{ steps.packages.outputs.data-transport-layer }}
contracts: ${{ steps.packages.outputs.contracts }}
gas-oracle: ${{ steps.packages.outputs.gas-oracle }}
Expand Down Expand Up @@ -229,6 +230,33 @@ jobs:
push: true
tags: ethereumoptimism/fault-detector:${{ needs.canary-publish.outputs.canary-docker-tag }}

drippie-mon:
name: Publish Drippie Monitor Version ${{ needs.canary-publish.outputs.canary-docker-tag }}
needs: canary-publish
if: needs.canary-publish.outputs.drippie-mon != ''
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_ACCESS_TOKEN_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN_SECRET }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./ops/docker/Dockerfile.packages
target: relayer
push: true
tags: ethereumoptimism/drippie-mon:${{ needs.canary-publish.outputs.canary-docker-tag }}

data-transport-layer:
name: Publish Data Transport Layer Version ${{ needs.canary-publish.outputs.canary-docker-tag }}
needs: canary-publish
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
l2geth: ${{ steps.packages.outputs.l2geth }}
message-relayer: ${{ steps.packages.outputs.message-relayer }}
fault-detector: ${{ steps.packages.outputs.fault-detector }}
drippie-mon: ${{ steps.packages.outputs.drippie-mon }}
data-transport-layer: ${{ steps.packages.outputs.data-transport-layer }}
contracts: ${{ steps.packages.outputs.contracts }}
gas-oracle: ${{ steps.packages.outputs.gas-oracle }}
Expand Down Expand Up @@ -372,6 +373,33 @@ jobs:
push: true
tags: ethereumoptimism/fault-detector:${{ needs.release.outputs.fault-detector }},ethereumoptimism/fault-detector:latest

drippie-mon:
name: Publish Drippie Monitor Version ${{ needs.release.outputs.drippie-mon }}
needs: release
if: needs.release.outputs.drippie-mon != ''
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_ACCESS_TOKEN_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN_SECRET }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./ops/docker/Dockerfile.packages
target: drippie-mon
push: true
tags: ethereumoptimism/drippie-mon:${{ needs.release.outputs.drippie-mon }},ethereumoptimism/drippie-mon:latest

data-transport-layer:
name: Publish Data Transport Layer Version ${{ needs.release.outputs.data-transport-layer }}
needs: release
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{"directory": "packages/contracts", "changeProcessCWD": true },
{"directory": "packages/contracts-periphery", "changeProcessCWD": true },
{"directory": "packages/data-transport-layer", "changeProcessCWD": true },
{"directory": "packages/drippie-mon", "changeProcessCWD": true },
{"directory": "packages/batch-submitter", "changeProcessCWD": true },
{"directory": "packages/message-relayer", "changeProcessCWD": true },
{"directory": "packages/fault-detector", "changeProcessCWD": true },
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ root
│ ├── <a href="./packages/contracts-periphery">contracts-periphery</a>: Peripheral contracts for Optimism
│ ├── <a href="./packages/core-utils">core-utils</a>: Low-level utilities that make building Optimism easier
│ ├── <a href="./packages/data-transport-layer">data-transport-layer</a>: Service for indexing Optimism-related L1 data
│ ├── <a href="./packages/fault-detector">fault-detector</a>:
│ ├── <a href="./packages/drippie-mon">drippie-mon</a>: Service for monitoring Drippie instances
│ ├── <a href="./packages/fault-detector">fault-detector</a>: Service for detecting Sequencer faults
│ ├── <a href="./packages/integration-tests-bedrock">integration-tests-bedrock</a> (BEDROCK upgrade): Bedrock integration tests.
│ ├── <a href="./packages/message-relayer">message-relayer</a>: Tool for automatically relaying L1<>L2 messages in development
│ ├── <a href="./packages/replica-healthcheck">replica-healthcheck</a>: Service for monitoring the health of a replica node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,39 @@ contract Drippie is AssetReceiver {
DripStatus status;
DripConfig config;
uint256 last;
uint256 count;
}

/**
* Emitted when a new drip is created.
*/
event DripCreated(string indexed name, DripConfig config);
event DripCreated(
// Emit name twice because indexed version is hashed.
string indexed nameref,
string name,
DripConfig config
);

/**
* Emitted when a drip status is updated.
*/
event DripStatusUpdated(string indexed name, DripStatus status);
event DripStatusUpdated(
// Emit name twice because indexed version is hashed.
string indexed nameref,
string name,
DripStatus status
);

/**
* Emitted when a drip is executed.
*/
event DripExecuted(string indexed name, address indexed executor, uint256 timestamp);
event DripExecuted(
// Emit name twice because indexed version is hashed.
string indexed nameref,
string name,
address executor,
uint256 timestamp
);

/**
* Maps from drip names to drip states.
Expand Down Expand Up @@ -109,7 +126,7 @@ contract Drippie is AssetReceiver {
}

// Tell the world!
emit DripCreated(_name, _config);
emit DripCreated(_name, _name, _config);
}

/**
Expand Down Expand Up @@ -163,20 +180,16 @@ contract Drippie is AssetReceiver {

// If we made it here then we can safely update the status.
drips[_name].status = _status;
emit DripStatusUpdated(_name, drips[_name].status);
emit DripStatusUpdated(_name, _name, drips[_name].status);
}

/**
* Triggers a drip. This function is deliberately left as a public function because the
* assumption being made here is that setting the drip to ACTIVE is an affirmative signal that
* the drip should be executable according to the drip parameters, drip check, and drip
* interval. Note that drip parameters are read entirely from the state and are not supplied as
* user input, so there should not be any way for a non-authorized user to influence the
* behavior of the drip.
* Checks if a given drip is executable.
*
* @param _name Name of the drip to trigger.
* @param _name Drip to check.
* @return True if the drip is executable, false otherwise.
*/
function drip(string memory _name) external {
function executable(string memory _name) public view returns (bool) {
DripState storage state = drips[_name];

// Only allow active drips to be executed, an obvious security measure.
Expand All @@ -201,6 +214,29 @@ contract Drippie is AssetReceiver {
"Drippie: dripcheck failed so drip is not yet ready to be triggered"
);

// Alright, we're good to execute.
return true;
}

/**
* Triggers a drip. This function is deliberately left as a public function because the
* assumption being made here is that setting the drip to ACTIVE is an affirmative signal that
* the drip should be executable according to the drip parameters, drip check, and drip
* interval. Note that drip parameters are read entirely from the state and are not supplied as
* user input, so there should not be any way for a non-authorized user to influence the
* behavior of the drip.
*
* @param _name Name of the drip to trigger.
*/
function drip(string memory _name) external {
DripState storage state = drips[_name];

// Make sure the drip can be executed.
require(
executable(_name) == true,
"Drippie: drip cannot be executed at this time, try again later"
);

// Update the last execution time for this drip before the call. Note that it's entirely
// possible for a drip to be executed multiple times per block or even multiple times
// within the same transaction (via re-entrancy) if the drip interval is set to zero. Users
Expand Down Expand Up @@ -240,6 +276,7 @@ contract Drippie is AssetReceiver {
);
}

emit DripExecuted(_name, msg.sender, block.timestamp);
state.count++;
emit DripExecuted(_name, _name, msg.sender, block.timestamp);
}
}
7 changes: 5 additions & 2 deletions packages/contracts-periphery/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const config: HardhatUserConfig = {
},
},
},
opkovan: {
'optimism-kovan': {
chainId: 69,
url: 'https://kovan.optimism.io',
verify: {
Expand Down Expand Up @@ -97,7 +97,10 @@ const config: HardhatUserConfig = {
},
},
namedAccounts: {
deployer: `ledger://${getenv('LEDGER_ADDRESS')}`,
deployer: {
default: `ledger://${getenv('LEDGER_ADDRESS')}`,
hardhat: 0,
},
},
}

Expand Down
13 changes: 13 additions & 0 deletions packages/drippie-mon/.depcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ignores: [
"@babel/eslint-parser",
"@typescript-eslint/parser",
"eslint-plugin-import",
"eslint-plugin-unicorn",
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow",
"eslint-plugin-react",
"@typescript-eslint/eslint-plugin",
"eslint-config-prettier",
"eslint-plugin-prettier",
"chai"
]
5 changes: 5 additions & 0 deletions packages/drippie-mon/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# RPC pointing to network where Drippie is deployed
DRIPPIE_MON__RPC=

# Address of the Drippie contract
DRIPPIE_MON__DRIPPIE_ADDRESS=
3 changes: 3 additions & 0 deletions packages/drippie-mon/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: '../../.eslintrc.js',
}
2 changes: 2 additions & 0 deletions packages/drippie-mon/.lintstagedrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"*.{ts,js}":
- eslint
3 changes: 3 additions & 0 deletions packages/drippie-mon/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../../.prettierrc.js'),
};
22 changes: 22 additions & 0 deletions packages/drippie-mon/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright 2020-2021 Optimism

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 changes: 22 additions & 0 deletions packages/drippie-mon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# @eth-optimism/drippie-mon

`drippie-mon` is a simple service for monitoring Drippie contracts.

## Installation

Clone, install, and build the Optimism monorepo:

```
git clone https://github.com/ethereum-optimism/optimism.git
yarn install
yarn build
```

## Running the service

Copy `.env.example` into a new file named `.env`, then set the environment variables listed there.
Once your environment variables have been set, run via:

```
yarn start
```

0 comments on commit 982cb98

Please sign in to comment.