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

Monitorism Global_events is module a that listen events onchain. #20

Merged
merged 35 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e5d592c
feat: global_events listen on the logs of each blocks.
Ethnical May 20, 2024
606a422
feat: Yaml template + logs fitering
Ethnical May 21, 2024
44cd9ca
chore: add current block infos + ChainId to ensure we are on the corr…
Ethnical May 21, 2024
c27a107
chore: move the rules into a dedicated folders
Ethnical May 21, 2024
9c1c1a5
chore: rename the param
Ethnical May 21, 2024
b0f020c
feat: add logging and infos to ensure no mistake when running
Ethnical May 21, 2024
c12d2a2
feat: add the possibilities or reading of the rules at once.
Ethnical May 21, 2024
24efca4
feat: add a new general structure that hold the addresses and events.
Ethnical May 21, 2024
27e34ca
feat: add the feature to monitore the empty addresses (all the addres…
Ethnical May 21, 2024
a261b4a
feat: Insert the `common.Address` type
Ethnical May 21, 2024
851b96c
feat: Monitore all the events when the addresses are empty.
Ethnical May 21, 2024
25cc44e
feat: add the `common.hash()` to have a more robust check.
Ethnical May 21, 2024
392b7bc
chore: add the `globalconfig.yml` this is file is NOT NECESSARY but j…
Ethnical May 22, 2024
6c6d2ec
feat: add the types tests
Ethnical May 22, 2024
f813c16
feat: changes the current struct to a better `GlobalConfiguration`.
Ethnical May 22, 2024
8977046
feat: adds metrics + clean the codes
Ethnical May 22, 2024
67ed2fe
readme: add a short readme during the creation
Ethnical May 22, 2024
d652177
chore: update the test
Ethnical May 22, 2024
ab5f2ee
Rename README.md to README.md
Ethnical May 22, 2024
a0ca940
chore: fix bugs + added the comments for the events 1 signer
Ethnical May 24, 2024
4fd4456
feat: small git clone to fetch from github embeeded into the binary
Ethnical May 24, 2024
09daa19
chore: fix the name of the env
Ethnical May 24, 2024
fe3eef4
bump: version git
Ethnical May 25, 2024
c757978
readme fix the `-`
Ethnical May 25, 2024
4bd2bb3
chore: errors handling + rpc message error logs.
Ethnical May 25, 2024
60a16e6
chore: fix comments + add the rules
Ethnical May 25, 2024
fe4d937
Update README.md
Ethnical May 25, 2024
e8740fe
Update README.md
Ethnical May 25, 2024
d7e4d62
Update README.md
Ethnical May 27, 2024
fbeab19
chore: remove the useless comments + comment the `cloneRepo()` if nee…
Ethnical May 28, 2024
3330522
Merge branch 'ethni/globalevents' of github.com:ethereum-optimism/mon…
Ethnical May 28, 2024
67756ad
chore: remove the `SignerCanBeRemove()`
Ethnical May 28, 2024
f9fa27c
chore: comment the dependencies for `cloneRepo()` if we need to use i…
Ethnical May 28, 2024
261c416
chore: remove not necessary function.
Ethnical May 28, 2024
16ec7d2
chore: remove the `CloneRepo()` function.
Ethnical May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions op-monitorism/cmd/monitorism/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
monitorism "github.com/ethereum-optimism/monitorism/op-monitorism"
"github.com/ethereum-optimism/monitorism/op-monitorism/balances"
"github.com/ethereum-optimism/monitorism/op-monitorism/fault"
"github.com/ethereum-optimism/monitorism/op-monitorism/global_events"
"github.com/ethereum-optimism/monitorism/op-monitorism/multisig"
"github.com/ethereum-optimism/monitorism/op-monitorism/withdrawals"

Expand Down Expand Up @@ -60,6 +61,13 @@ func newCli(GitCommit string, GitDate string) *cli.App {
Flags: append(balances.CLIFlags("BALANCE_MON"), defaultFlags...),
Action: cliapp.LifecycleCmd(BalanceMain),
},
{
Name: "global_events",
Usage: "Monitors global events with YAML configuration",
Description: "Monitors global events with YAML configuration",
Flags: append(global_events.CLIFlags("GLOBAL_EVENT_MON"), defaultFlags...),
Action: cliapp.LifecycleCmd(global_eventsMain),
},
{
Name: "version",
Usage: "Show version",
Expand All @@ -73,6 +81,21 @@ func newCli(GitCommit string, GitDate string) *cli.App {
}
}

func global_eventsMain(ctx *cli.Context, closeApp context.CancelCauseFunc) (cliapp.Lifecycle, error) {
log := oplog.NewLogger(oplog.AppOut(ctx), oplog.ReadCLIConfig(ctx))
cfg, err := global_events.ReadCLIFlags(ctx)
if err != nil {
return nil, fmt.Errorf("failed to parse global_events config from flags: %w", err)
}

metricsRegistry := opmetrics.NewRegistry()
monitor, err := global_events.NewMonitor(ctx.Context, log, opmetrics.With(metricsRegistry), cfg)
if err != nil {
return nil, fmt.Errorf("failed to create global_events monitor: %w", err)
}

return monitorism.NewCliApp(ctx, log, metricsRegistry, monitor)
}
func MultisigMain(ctx *cli.Context, closeApp context.CancelCauseFunc) (cliapp.Lifecycle, error) {
log := oplog.NewLogger(oplog.AppOut(ctx), oplog.ReadCLIConfig(ctx))
cfg, err := multisig.ReadCLIFlags(ctx)
Expand Down
17 changes: 17 additions & 0 deletions op-monitorism/cmd/monitorism/globalconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
configuration:
- version: "1.0"
name: Safe Watcher
priority: P0
addresses: []
events:
- keccak256_signature: 0x23428b18acfb3ea64b08dc0c1d296ea9c09702c09083ca5272e64d115b687d23
signature: ExecutionFailure(bytes32,uint256)
- keccak256_signature: 0x442e715f626346e8c54381002da614f62bee8d27386535b2521ec8540898556e
signature: ExecutionSuccess(bytes32,uint256)
- version: "1.0"
name: SystemConfig Config Updates
priority: P2
addresses: []
events:
- keccak256_signature: 0x82f8cc4439cd78202f3081cd05a23d895e011595628770738fc5ba8ecba469ed
signature: ConfigUpdate(uint256 indexed version, UpdateType indexed updateType, bytes data)
10 changes: 10 additions & 0 deletions op-monitorism/cmd/rules/SafeExecution.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This watches all contacts for OP, Mode, and Base mainnets for two logs.
# These logs are emitted by Safes, so this effectively watches for all
# transactions from any Safe on these chains.
version: 1.0
name: Safe Watcher
priority: P0
addresses: # /!\ We are not supporting EIP 3770 yet, if the address is not starting by `0x`, this will panic by safety measure.
events:
- signature: ExecutionFailure(bytes32,uint256)
- signature: ExecutionSuccess(bytes32,uint256)
11 changes: 11 additions & 0 deletions op-monitorism/cmd/rules/SystemConfigUpdate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This watches the L1 SystemConfig for OP Mainnet for config updates.
# - eth/op/SystemConfig
version: 1.0
name: SystemConfig Config Updates
priority: P2
addresses: # /!\ We are not supporting EIP 3770 yet, if the address is not starting by 0x, this will panic by safety measure.
events:
- signature: ConfigUpdate(uint256 indexed version, UpdateType indexed updateType, bytes data)
# Notice that the above signature is not normalized. The normalized version is:
# ConfigUpdate(uint256,uint8,bytes)
# But for UX
52 changes: 52 additions & 0 deletions op-monitorism/global_events/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## Global Events monitoring

This monitoring modules for the yaml rules added with the format ⚠️ This readme will be move into the global readme in the future.

CLI and Docs:
```bash
NAME:
Monitorism global_events - Monitors global events with YAML configuration

USAGE:
Monitorism global_events [command options] [arguments...]

DESCRIPTION:
Monitors global events with YAML configuration

OPTIONS:
--l1.node.url value Node URL of L1 peer (default: "http://127.0.0.1:8545") [$GLOBAL_EVENT_MON_L1_NODE_URL]
--nickname value Nickname of chain being monitored [$GLOBAL_EVENT_MON_NICKNAME]
--PathYamlRules value Path to the yaml file containing the events to monitor [$GLOBAL_EVENT_MON_PATH_YAML]
--log.level value The lowest log level that will be output (default: INFO) [$MONITORISM_LOG_LEVEL]
--log.format value Format the log output. Supported formats: 'text', 'terminal', 'logfmt', 'json', 'json-pretty', (default: text) [$MONITORISM_LOG_FORMAT]
--log.color Color the log output if in terminal mode (default: false) [$MONITORISM_LOG_COLOR]
--metrics.enabled Enable the metrics server (default: false) [$MONITORISM_METRICS_ENABLED]
--metrics.addr value Metrics listening address (default: "0.0.0.0") [$MONITORISM_METRICS_ADDR]
--metrics.port value Metrics listening port (default: 7300) [$MONITORISM_METRICS_PORT]
--loop.interval.msec value Loop interval of the monitor in milliseconds (default: 60000) [$MONITORISM_LOOP_INTERVAL_MSEC]
--help, -h show help

```

The rules are located here: `op-monitorism/global_events/rules/` then we have multiples folders depending the networks you want to monitore (`mainnet` or `sepolia`) for now.
```yaml
# This is a TEMPLATE file please copy this one
# This watches all contacts for OP, Mode, and Base mainnets for two logs.
version: 1.0
name: Template SafeExecution Events (Success/Failure) L1 # Please put the L1 or L2 at the end of the name.
priority: P5 # This is a test, so it is a P5
#If addresses is empty like below it will watch all addresses otherwise you can address specific addresses.
addresses:
# - 0xbEb5Fc579115071764c7423A4f12eDde41f106Ed # Specific Addresses /!\ We are not supporting EIP 3770 yet, if the address is not starting by 0x, this will panic by safety measure.
events:
- signature: ExecutionFailure(bytes32,uint256) # List of the events to watch for the addresses.
- signature: ExecutionSuccess(bytes32,uint256) # List of the events to watch for the addresses.
```

To run it:

```bash

go run ../cmd/monitorism global_events --nickname MySuperNickName --l1.node.url https://localhost:8545 --PathYamlRules /tmp/Monitorism/op-monitorism/global_events/rules/rules_mainnet_L1 --loop.interval.msec 12000

```
58 changes: 58 additions & 0 deletions op-monitorism/global_events/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package global_events

import (
// "fmt"

opservice "github.com/ethereum-optimism/optimism/op-service"

// "github.com/ethereum/go-ethereum/common"

"github.com/urfave/cli/v2"
)

// args in CLI have to be standardized and clean.
const (
L1NodeURLFlagName = "l1.node.url"
NicknameFlagName = "nickname"
PathYamlRulesFlagName = "PathYamlRules"
)

type CLIConfig struct {
L1NodeURL string
Nickname string
PathYamlRules string
// Optional
}

func ReadCLIFlags(ctx *cli.Context) (CLIConfig, error) {
cfg := CLIConfig{
L1NodeURL: ctx.String(L1NodeURLFlagName),
Nickname: ctx.String(NicknameFlagName),
PathYamlRules: ctx.String(PathYamlRulesFlagName),
}

return cfg, nil
}

func CLIFlags(envVar string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: L1NodeURLFlagName,
Usage: "Node URL of L1 peer",
Value: "http://127.0.0.1:8545",
EnvVars: opservice.PrefixEnvVar(envVar, "L1_NODE_URL"),
},
&cli.StringFlag{
Name: NicknameFlagName,
Usage: "Nickname of chain being monitored",
EnvVars: opservice.PrefixEnvVar(envVar, "NICKNAME"), //need to change the name to BLOCKCHAIN_NAME
Required: true,
},
&cli.StringFlag{
Name: PathYamlRulesFlagName,
Usage: "Path to the yaml file containing the events to monitor",
EnvVars: opservice.PrefixEnvVar(envVar, "PATH_YAML"), //need to change the name to BLOCKCHAIN_NAME
Required: true,
},
}
}
Loading