Skip to content

Commit

Permalink
feat: sqlite reorgdetector (#160)
Browse files Browse the repository at this point in the history
* wip

* implementation

* fix tests

* wip

* mdbx is gone

* increase coverage

* remove ifElseChain from golangci

* remove ifElseChain from golangci

* remove ifElseChain from golangci

* increase coverage

* increase coverage

* identation

* identation

* identation

* fix kurtosis config
  • Loading branch information
arnaubennassar authored Nov 7, 2024
1 parent d7d9947 commit d9aa92a
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 136 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ linters-settings:
gocritic:
enabled-checks:
- ruleguard
disabled-checks:
- ifElseChain
revive:
rules:
- name: exported
Expand Down
1 change: 0 additions & 1 deletion aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ func (a *Aggregator) validateEligibleFinalProof(
batchNumberToVerify := lastVerifiedBatchNum + 1

if proof.BatchNumber != batchNumberToVerify {
//nolint:gocritic
if proof.BatchNumber < batchNumberToVerify &&
proof.BatchNumberFinal >= batchNumberToVerify {
// We have a proof that contains some batches below the last batch verified, anyway can be eligible as final proof
Expand Down
32 changes: 32 additions & 0 deletions bridgesync/claimcalldata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err := client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "direct call to claim asset",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -155,6 +156,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "indirect call to claim asset",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -188,6 +190,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "indirect call to claim asset bytes",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -215,6 +218,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "direct call to claim message",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -243,6 +247,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "indirect call to claim message",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -276,6 +281,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "indirect call to claim message bytes",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -309,6 +315,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
log.Infof("%+v", r.Logs)

reverted := [2]bool{false, false}
Expand Down Expand Up @@ -357,6 +364,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim message 1 (same globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -414,6 +422,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim message 1 (diff globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -473,6 +482,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim message (same globalIndex) (1 ok, 1 reverted)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -524,6 +534,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim message (diff globalIndex) (1 ok, 1 reverted)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -577,6 +588,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim message (same globalIndex) (reverted,ok)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -628,6 +640,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim message (diff globalIndex) (reverted,ok)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -681,6 +694,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim asset 1 (same globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -738,6 +752,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim asset 1 (diff globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -797,6 +812,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim asset (same globalIndex) (1 ok, 1 reverted)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -848,6 +864,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim asset (diff globalIndex) (1 ok, 1 reverted)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -901,6 +918,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim asset (same globalIndex) (reverted,ok)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -952,6 +970,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect call claim asset (diff globalIndex) (reverted,ok)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -985,6 +1004,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "indirect + indirect call to claim message bytes",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1038,6 +1058,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 indirect + indirect call claim message 1 (same globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1115,6 +1136,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "3 ok (indirectx2, indirect, indirectx2) call claim message 1 (same globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1196,6 +1218,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "3 ok (indirectx2, indirect, indirectx2) call claim message 1 (diff globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1279,6 +1302,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "1 ko 2 ok (indirectx2, indirect, indirectx2) call claim message 1 (diff globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1356,6 +1380,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "1 ko 2 ok (indirectx2, indirect, indirectx2) call claim message 1 (diff globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1433,6 +1458,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "1 ok 1 ok 1 ko (indirectx2, indirect, indirectx2) call claim message 1 (diff globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1510,6 +1536,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "1 ko 2 ok (indirectx2, indirect, indirectx2) call claim message 1 (same globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1587,6 +1614,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "1 ko 2 ok (indirectx2, indirect, indirectx2) call claim message 1 (same globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1664,6 +1692,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "1 ok 1 ok 1 ko (indirectx2, indirect, indirectx2) call claim message 1 (same globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1741,6 +1770,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "2 ko 1 ok (indirectx2, indirect, indirectx2) call claim message 1 (same globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1812,6 +1842,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "1 ok 2 ko (indirectx2, indirect, indirectx2) call claim message 1 (same globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down Expand Up @@ -1883,6 +1914,7 @@ func TestClaimCalldata(t *testing.T) {
require.NoError(t, err)
time.Sleep(1 * time.Second)
r, err = client.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
testCases = append(testCases, testCase{
description: "1 ko 1 ok 1 ko (indirectx2, indirect, indirectx2) call claim message 1 (same globalIndex)",
bridgeAddr: bridgeAddr,
Expand Down
2 changes: 1 addition & 1 deletion bridgesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
func TestBridgeEventE2E(t *testing.T) {
ctx := context.Background()
dbPathSyncer := path.Join(t.TempDir(), "file::memory:?cache=shared")
dbPathReorg := t.TempDir()
dbPathReorg := path.Join(t.TempDir(), "file::memory:?cache=shared")

client, setup := helpers.SimulatedBackend(t, nil, 0)
rd, err := reorgdetector.New(client.Client(), reorgdetector.Config{DBPath: dbPathReorg})
Expand Down
5 changes: 2 additions & 3 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ SyncModeOnlyEnabled = false
NumRequests = 1000
Interval = "1s"
[ReorgDetectorL1]
DBPath = "{{PathRWData}}/reorgdetectorl1"
DBPath = "{{PathRWData}}/reorgdetectorl1.sqlite"
[ReorgDetectorL2]
DBPath = "{{PathRWData}}/reorgdetectorl2"
DBPath = "{{PathRWData}}/reorgdetectorl2.sqlite"
[L1InfoTreeSync]
DBPath = "{{PathRWData}}/L1InfoTreeSync.sqlite"
Expand Down Expand Up @@ -316,7 +316,6 @@ WaitForNewBlocksPeriod = "3s"
OriginNetwork=1
[LastGERSync]
# MDBX database path
DBPath = "{{PathRWData}}/lastgersync.sqlite"
BlockFinality = "LatestBlock"
InitialBlockNum = 0
Expand Down
9 changes: 0 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ require (
github.com/knadh/koanf/parsers/toml v0.1.0
github.com/knadh/koanf/providers/rawbytes v0.1.0
github.com/knadh/koanf/v2 v2.1.1
github.com/ledgerwatch/erigon-lib v1.0.0
github.com/mattn/go-sqlite3 v1.14.23
github.com/mitchellh/mapstructure v1.5.0
github.com/pelletier/go-toml/v2 v2.2.2
Expand All @@ -46,13 +45,11 @@ require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/VictoriaMetrics/metrics v1.23.1 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.14.2 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 // indirect
Expand All @@ -70,7 +67,6 @@ require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/didip/tollbooth/v6 v6.1.2 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erigontech/mdbx-go v0.27.14 // indirect
github.com/ethereum/c-kzg-4844 v1.0.3 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -81,7 +77,6 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-pkgz/expirable-cache v0.0.3 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand Down Expand Up @@ -109,7 +104,6 @@ require (
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/ledgerwatch/log/v3 v3.9.0 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -125,7 +119,6 @@ require (
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/gomega v1.27.10 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down Expand Up @@ -154,8 +147,6 @@ require (
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
Expand Down
Loading

0 comments on commit d9aa92a

Please sign in to comment.