Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Refactored Invariant Registry & Added Fault Detector Implementation #104

Merged
merged 49 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0fc0b4f
[epociask/no-issue-refactored-invariant] Refactored Invariant Registry
Jul 3, 2023
f7cae5c
[epociask/no-issue-refactored-invariant] Subsystem tests
Jul 4, 2023
5a1d5f5
[epociask/no-issue-refactored-invariant] Updated docs
Jul 4, 2023
0c9f719
[epociask/no-issue-refactored-invariant] Engine manager eventLoop test
Jul 5, 2023
afb0cbb
[epociask/no-issue-refactored-invariant] Added coverage-report
Jul 6, 2023
b7fc902
[epociask/no-issue-refactored-invariant] Removed coverage file
Jul 6, 2023
3a4cfca
[epociask/no-issue-refactored-invariant] Updated workflow
Jul 6, 2023
c741cf7
[epociask/no-issue-refactored-invariant] Updated workflow
Jul 6, 2023
dea396b
[epociask/no-issue-refactored-invariant] Updated test
Jul 6, 2023
307f26b
[epociask/no-issue-refactored-invariant] testing actions
Jul 6, 2023
45a4ea5
[epociask/no-issue-refactored-invariant] testing actions
Jul 6, 2023
3f9143b
[epociask/no-issue-refactored-invariant] testing
Jul 6, 2023
31db1fc
[epociask/no-issue-refactored-invariant] debugging test
Jul 6, 2023
61d6ece
[epociask/no-issue-refactored-invariant] debugging test
Jul 6, 2023
f91413b
[epociask/no-issue-refactored-invariant] Fixed workflow formatting bugs
Jul 6, 2023
3ac6af3
[epociask/no-issue-refactored-invariant] Coverage works
Jul 6, 2023
f31a3ee
[epociask/no-issue-refactored-invariant] Updated output
Jul 6, 2023
1fe8964
[epociask/no-issue-refactored-invariant] Updated output script
Jul 6, 2023
5ea2996
[epociask/no-issue-refactored-invariant] codeflow config
Jul 6, 2023
99345bd
[epociask/no-issue-refactored-invariant] testing script update
Jul 6, 2023
473be5e
[epociask/no-issue-refactored-invariant] testing script update
Jul 6, 2023
5cdff0e
[epociask/no-issue-refactored-invariant] Debugging test action
Jul 6, 2023
43e504f
[epociask/no-issue-refactored-invariant] Fixed formatting bug
Jul 6, 2023
601b0d2
[epociask/no-issue-refactored-invariant] Pass lint
Jul 6, 2023
7db54d6
[epociask/no-issue-refactored-invariant] Updated spacing error
Jul 6, 2023
1f11275
[epociask/no-issue-refactored-invariant] Coverage check
Jul 6, 2023
05ce036
[epociask/no-issue-refactored-invariant] rm coverage
Jul 6, 2023
c7afc6a
[epociask/no-issue-refactored-invariant] Externalized script
Jul 6, 2023
1084a33
[epociask/no-issue-refactored-invariant] Externalized script
Jul 6, 2023
0419ada
[epociask/no-issue-refactored-invariant] Update script logic
Jul 6, 2023
168e131
[epociask/no-issue-refactored-invariant] Core tests
Jul 6, 2023
1f0898e
[epociask/no-issue-refactored-invariant] Removed configure routine
Jul 6, 2023
1405781
[epociask/no-issue-refactored-invariant] More subsystem tests
Jul 6, 2023
bae28e6
[epociask/no-issue-refactored-invariant] More tests
Jul 6, 2023
825006b
[epociask/no-issue-refactored-invariant] Added common test
Jul 6, 2023
d90c975
[epociask/no-issue-refactored-invariant] model tests
Jul 6, 2023
bb352b4
[epociask/no-issue-refactored-invariant] Update coverage command
Jul 6, 2023
5d215b7
[epociask/no-issue-refactored-invariant] Update coverage command
Jul 6, 2023
e0cbe1b
[epociask/no-issue-refactored-invariant] Update coverage command
Jul 6, 2023
2535791
[epociask/no-issue-refactored-invariant] Update
Jul 6, 2023
5356a21
[epociask/no-issue-refactored-invariant] Fault Detector Implementation
Jul 7, 2023
f640af2
[epociask/no-issue-refactored-invariant] Removed configure routine
Jul 8, 2023
b58c57c
[epociask/no-issue-refactored-invariant] Updated fault-detector
Jul 10, 2023
dbb1fad
[epociask/no-issue-refactored-invariant] go tool cover -func=…
Jul 10, 2023
5f4d792
[epociask/no-issue-refactored-invariant] Passing lint
Jul 10, 2023
09cf1c1
[epociask/no-issue-refactored-invariant] Fix typos
Jul 10, 2023
07c06a4
[epociask/no-issue-refactored-invariant] Fixed debug logs
Jul 10, 2023
98da7b8
[epociask/no-issue-refactored-invariant] Fixed coverage CMD
Jul 10, 2023
722ba1b
[epociask/no-issue-refactored-invariant] Fault detection documentation
Jul 10, 2023
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
5 changes: 5 additions & 0 deletions .codeflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
secure:
required_reviews: 1
upstream_repository: base-org/pessimism

auto_assign_reviewers: true
32 changes: 32 additions & 0 deletions .github/scripts/comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
This script will create a comment on the pull request with the current test coverage.
If the comment already exists, it will update the existing comment.

This script is called from the .github/workflows/test.yml workflow file. It is very difficult to debug
given the way GitHub Actions works.

*/
module.exports = async ({github, context, core}) => {
const fs = require('fs');
const coverage = fs.readFileSync('out.txt', 'utf8');
const reportBody = '### Current Test Coverage\n' + '```' + coverage + '```';

if (process.env.DATA == null || process.env.DATA == ''){
// Create a comment on pull request
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: reportBody
})

} else {
// Update existing comment on pull request
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: process.env.DATA,
body: '### Current Test Coverage\n' + '```' + coverage + '```'
})
}
}
30 changes: 29 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
run: make build-app

go-test:
outputs:
COVERAGE: ${{ steps.unit.outputs.coverage }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -32,7 +34,32 @@ jobs:
go-version: 1.19

- name: Run Unit Tests
run: make test
id: unit
run: |
go test -coverprofile=coverage.out ./internal/... >> out.txt

- name: Generate Coverage
run: |
go tool cover -func=coverage.out | grep total | awk '{print $3}' >> out.txt
echo "::set-output name=coverage::$(cat out.txt)"

- name: Find Coverage Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '### Current Test Coverage'

- name: Add Coverage Comment
uses: actions/github-script@v6
env:
DATA: ${{ steps.fc.outputs.comment-id }}

with:
script: |
const script = require('./.github/scripts/comment.js')
await script({github, context, core})

e2e-test:
runs-on: ubuntu-latest
Expand All @@ -46,3 +73,4 @@ jobs:

- name: Run E2E Integration Tests
run: make e2e-test

5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ gosec:
@echo "$(GREEN) Running security scan with gosec...$(COLOR_END)"
gosec ./...

.PHONY: metric-docs
metric-docs: build-app
@echo "$(GREEN) Generating metric documentation...$(COLOR_END)"
@./bin/$(APP_NAME) doc metrics

.PHONY: docker-build
docker-build:
@echo "$(GREEN) Building docker image...$(COLOR_END)"
Expand Down
12 changes: 9 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ func RunPessimism(_ *cli.Context) error {
return err
}

l2Geth, err := client.NewGethClient(cfg.L2RpcEndpoint)
if err != nil {
logger.Fatal("Error creating L2 GETH client", zap.Error(err))
return err
}

ss := state.NewMemState()

ctx = app.InitializeContext(ctx, ss, l1Client, l2Client)
ctx = app.InitializeContext(ctx, ss, l1Client, l2Client, l2Geth)

pessimism, shutDown, err := app.NewPessimismApp(ctx, cfg)

Expand Down Expand Up @@ -113,7 +119,7 @@ func RunPessimism(_ *cli.Context) error {
}

// fetchBootSessions ... Loads the bootstrap file
func fetchBootSessions(path string) ([]app.BootSession, error) {
func fetchBootSessions(path string) ([]*app.BootSession, error) {
if !strings.HasSuffix(path, extJSON) {
return nil, fmt.Errorf("invalid bootstrap file format; expected %s", extJSON)
}
Expand All @@ -123,7 +129,7 @@ func fetchBootSessions(path string) ([]app.BootSession, error) {
return nil, err
}

data := []app.BootSession{}
data := []*app.BootSession{}

err = json.Unmarshal(file, &data)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docs/etl.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ _Only send output at the update of a single ingress stream_

Single Value Subscription refers to a synchronization policy where a bucketed multi-data tuple is submitted every time there’s an update to a single input data queue.

For example we can have an invariant that subscribes to blocks from two heterogenous chains (layer1, layer2) or `{ChainA, ChainB}`, let's assume `BLOCK_TIME(ChainA)> BLOCK_TIME(ChainB)`.
For example we can have an invariant that subscribes to blocks from two heterogenous chains (layer1, layer2) or `{ChainA, ChainB}`, let's assume `BLOCK_TIME(ChainA) > BLOCK_TIME(ChainB)`.

We can either specify that the invariant will run every-time there's an update or a new block from `ChainA`:
```
Expand Down
40 changes: 36 additions & 4 deletions docs/invariants.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ The hardcoded `withdrawal_enforcement` invariant scans for active `WithdrawalPro
### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| l1_portal | string | The address of the L1Portal contract |
| l2_messager | string | The address of the L2ToL1MessagePasser contract |
| l1_portal_address | string | The address of the L1Portal contract |
| l2_to_l1_address | string | The address of the L2ToL1MessagePasser contract |


### Example Deploy Request
Expand All @@ -89,8 +89,40 @@ curl --location --request POST 'http://localhost:8080/v0/invariant' \
"start_height": null,
"alert_destination": "slack",
"invariant_params": {
"l1_portal": "0x111",
"l2_messager": "0x333",
"l1_portal_address": "0x111",
"l2_to_l1_address": "0x333",
},
}'
```

## Fault Detection
**NOTE:** This invariant requires an active RPC connection to both L1 and L2 networks. Furthermore, the Pessimism implementation of fault-detector assumes that a submitted L2 output on L1 will correspond to a canonical block on L2.

The hardcoded `fault_detector` invariant scans for active `OutputProposed` events on an L1 Output Oracle contract. Once an event is detected, the invariant implementation proceeds to reconstruct a local state output for the corresponding L2 block. If there is a mismatch between the L1 output and the local state output, the invariant alerts.


### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| l2_output_address | string | The address of the L1 output oracle |
| l2_to_l1_address | string | The address of the L2ToL1MessagePasser contract |


### Example Deploy Request
```
curl --location --request POST 'http://localhost:8080/v0/invariant' \
--header 'Content-Type: text/plain' \
--data-raw '{
"method": "run",
"params": {
"network": "layer1",
"pipeline_type": "live",
"type": "fault_detector",
"start_height": null,
"alert_destination": "slack",
"invariant_params": {
"l2_output_address": "0x111",
"l2_to_l1_address": "0x333",
},
}'
```
15 changes: 10 additions & 5 deletions e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"time"

"github.com/base-org/pessimism/internal/api/server"
"github.com/base-org/pessimism/internal/api/service"
"github.com/base-org/pessimism/internal/app"
"github.com/base-org/pessimism/internal/client"
"github.com/base-org/pessimism/internal/config"
"github.com/base-org/pessimism/internal/logging"
"github.com/base-org/pessimism/internal/metrics"
"github.com/base-org/pessimism/internal/state"
"github.com/base-org/pessimism/internal/subsystem"
op_e2e "github.com/ethereum-optimism/optimism/op-e2e"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -59,8 +60,7 @@ func CreateL2TestSuite(t *testing.T) *L2TestSuite {
}

ss := state.NewMemState()

ctx = app.InitializeContext(ctx, ss, node.L2Client, node.L2Client)
ctx = app.InitializeContext(ctx, ss, node.L2Client, node.L2Client, nil)

appCfg := DefaultTestConfig()

Expand Down Expand Up @@ -105,10 +105,15 @@ func CreateSysTestSuite(t *testing.T) *SysTestSuite {
t.Fatal(err)
}

gethClient, err := client.NewGethClient(sys.Nodes["sequencer"].HTTPEndpoint())
if err != nil {
t.Fatal(err)
}

ss := state.NewMemState()
ctx = app.InitializeContext(ctx, ss,
sys.Clients["l1"],
sys.Clients["sequencer"])
sys.Clients["sequencer"], gethClient)

appCfg := DefaultTestConfig()

Expand Down Expand Up @@ -151,7 +156,7 @@ func DefaultTestConfig() *config.Config {
return &config.Config{
Environment: config.Development,
BootStrapPath: "",
SvcConfig: &service.Config{
SystemConfig: &subsystem.Config{
L2PollInterval: l2PollInterval,
L1PollInterval: l1PollInterval,
},
Expand Down
Loading
Loading