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

test: op e2e verifier daemon itest #533

Open
wants to merge 7 commits into
base: base/consumer-chain-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ test-e2e-wasmd: clean-e2e install-babylond install-wasmd
test-e2e-op: clean-e2e install-babylond
@go test -race -mod=readonly -timeout=25m -v $(PACKAGES_E2E_OP) -count=1 --tags=e2e_op

TEST_NAME ?= .
test-e2e-op-single: clean-e2e install-babylond
@go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E_OP) -count=1 --tags=e2e_op --run ^$(TEST_NAME)$
Comment on lines 115 to +120
Copy link
Contributor

Choose a reason for hiding this comment

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

ncie change! but can we merge w the above command instead of adding a new one?

FILTER ?= .
test-e2e-op: clean-e2e install-babylond
	@go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E_OP) -count=1 --tags=e2e_op --run ^$(FILTER)$

I am also curious why make didn't complain since you didn't add test-e2e-op-single to .PHONY in Line 84

test-e2e-op-ci: clean-e2e install-babylond
go test -list . ./itest/opstackl2 --tags=e2e_op | grep Test \
| circleci tests run --command \
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ require (
require (
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
github.com/jackc/pgx/v5 v5.6.0 // indirect
)

require (
Expand Down Expand Up @@ -195,7 +196,7 @@ require (
github.com/aead/siphash v1.0.1 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/aws/aws-sdk-go v1.44.312 // indirect
github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240716025522-a7f8cd19f44f
github.com/babylonchain/babylon-finality-gadget v0.1.3
Copy link
Contributor

Choose a reason for hiding this comment

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

how does it work since v0.1.3 doesn't exist?

Copy link
Author

Choose a reason for hiding this comment

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

added a replace later in the same file. There was some dependency bug when specifying the version directly here

github.com/babylonchain/babylon-sdk/x v0.0.0-20240705194516-4e2c5650cde8 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
Expand Down Expand Up @@ -246,7 +247,7 @@ require (
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fergusstrange/embedded-postgres v1.10.0 // indirect
github.com/fergusstrange/embedded-postgres v1.10.0
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
Expand Down Expand Up @@ -437,8 +438,9 @@ replace (
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/babylonchain/babylon => github.com/babylonchain/babylon-private v0.9.0-rc.2.0.20240717044248-3d8f190c9b0c
github.com/babylonchain/babylon-finality-gadget => github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726073429-afbaa4560ee5
github.com/cockroachdb/pebble => github.com/cockroachdb/pebble v0.0.0-20231018212520-f6cde3fc2fa4
github.com/ethereum-optimism/optimism => github.com/babylonchain/optimism v1.7.5-0.20240717115935-8fad1ec9aa03
github.com/ethereum-optimism/optimism => github.com/babylonchain/optimism v1.7.5-0.20240717131100-fa941f083b02
Copy link
Contributor

Choose a reason for hiding this comment

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

could you update it to latest commit on feat/babylon-rfc branch? I just merged the latest PR there

github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101315.1-rc.5
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
13 changes: 9 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,16 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX
github.com/aws/aws-sdk-go v1.44.312 h1:llrElfzeqG/YOLFFKjg1xNpZCFJ2xraIi3PqSuP+95k=
github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240716025522-a7f8cd19f44f h1:FykJmDmmw5CypzzNBskqDugs9HvIXpJ+vxa0J0jzPlA=
github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240716025522-a7f8cd19f44f/go.mod h1:UkRb1walvNDdEF4fcJVz+M1t7Ok62PkayI40BtxYOGI=
github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726073429-afbaa4560ee5 h1:6jMw0fTzWSuRIVFhmqjf6nb0xNc7djfk54GjqsySjvg=
github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726073429-afbaa4560ee5/go.mod h1:LgEqT5oHGpqRLVMc/qwB9TM99biKYZQDdyrb7Xw6HWI=
github.com/babylonchain/babylon-private v0.9.0-rc.2.0.20240717044248-3d8f190c9b0c h1:Q8vNr512o6zxxTg1rC41j+s5IS13B1c5kduQmps6pho=
github.com/babylonchain/babylon-private v0.9.0-rc.2.0.20240717044248-3d8f190c9b0c/go.mod h1:eVovUiLvCvHRpXV7f8KzC4FND1UryaZmZc3bEdBvB8w=
github.com/babylonchain/babylon-sdk/demo v0.0.0-20240705194516-4e2c5650cde8 h1:VzLjjsynyYaOsIiLwVwMQDXbh1nsQWVpLYLi09R0mh0=
github.com/babylonchain/babylon-sdk/demo v0.0.0-20240705194516-4e2c5650cde8/go.mod h1:X4QovCWMwqMjoTriu18w4gfqX1sYqOWRnZwXGYD8bnE=
github.com/babylonchain/babylon-sdk/x v0.0.0-20240705194516-4e2c5650cde8 h1:W8jr9BHOLD9RJviI6TmnWPwZpMSjliQNIbNuflBx6vo=
github.com/babylonchain/babylon-sdk/x v0.0.0-20240705194516-4e2c5650cde8/go.mod h1:Ojrlnwh9z7fvmTUzYH4Tk+8hWSctCrZYWiC5+t4X32I=
github.com/babylonchain/optimism v1.7.5-0.20240717115935-8fad1ec9aa03 h1:vKQCvOfbZLGQjMynEmlN+zeHkadN0g/8mQ6kYtnypIE=
github.com/babylonchain/optimism v1.7.5-0.20240717115935-8fad1ec9aa03/go.mod h1:W23NXCxf6fqmYeg3YRvbnBFD9lCqrYyUoRR0mK3WZtg=
github.com/babylonchain/optimism v1.7.5-0.20240717131100-fa941f083b02 h1:5YRcTxaQmVFhurqavmuhUnF05ygR0fqPCajGljwkL4U=
github.com/babylonchain/optimism v1.7.5-0.20240717131100-fa941f083b02/go.mod h1:W23NXCxf6fqmYeg3YRvbnBFD9lCqrYyUoRR0mK3WZtg=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down Expand Up @@ -1014,10 +1014,15 @@ github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQ
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
github.com/jackc/pgx/v4 v4.18.2 h1:xVpYkNR5pk5bMCZGfClbO962UIqVABcAGt7ha1s/FeU=
github.com/jackc/pgx/v4 v4.18.2/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw=
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
Expand Down
42 changes: 42 additions & 0 deletions itest/opstackl2/op_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package e2etest_op

import (
"context"
"encoding/hex"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -177,3 +179,43 @@ func TestFinalityStuckAndRecover(t *testing.T) {
"OP chain fianlity is recovered, the latest finalized block height %d",
), nextFinalizedHeight)
}

func TestOpVerifierDaemon(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

since a new test is added. let's also modify .circleci/config.yml to increase parallelism to 4 on Line 146 for our job so each our test will run on a separate container

// start the consumer manager
ctm := StartOpL2ConsumerManager(t, 2)
defer ctm.Stop(t)

// register, get BTC delegations, and start FPs
n := 2
fpList := ctm.SetupFinalityProviders(t, n, []stakingParam{
// for the first FP, we give it more power b/c it will be used later
{e2eutils.StakingTime, 3 * e2eutils.StakingAmount},
{e2eutils.StakingTime, e2eutils.StakingAmount},
})

// check both FPs have committed their first public randomness
// TODO: we might use go routine to do this in parallel
for i := 0; i < n; i++ {
e2eutils.WaitForFpPubRandCommitted(t, fpList[i])
}

// both FP will sign the first block
targetBlockHeight := ctm.WaitForTargetBlockPubRand(t, fpList)
ctm.WaitForFpVoteAtHeight(t, fpList[0], targetBlockHeight)
ctm.WaitForFpVoteAtHeight(t, fpList[1], targetBlockHeight)
t.Logf(log.Prefix("Both FP instances signed the first block"))

// both FP will sign the second block
ctm.WaitForFpVoteAtHeight(t, fpList[0], targetBlockHeight+1)
ctm.WaitForFpVoteAtHeight(t, fpList[1], targetBlockHeight+1)
t.Logf(log.Prefix("Both FP instances signed the second block"))

// run the verifier daemon and process 2 blocks
t.Logf(log.Prefix("Starting verifier daemon"))
err := ctm.verifier.ProcessNBlocks(context.Background(), 2)
require.NoError(t, err)

// get latest finalized block via API and check response
fmt.Printf("targetBlockHeight: %d\n", targetBlockHeight)
checkLatestConsecutivelyFinalizedBlock(t, 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

so 2 mean latest finalized block with consecutive quorom is block at height 2? then where do we need targetBlockHeight? I am a bit confused

Copy link
Author

@parketh parketh Jul 27, 2024

Choose a reason for hiding this comment

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

when run normally, ctm.verifier.ProcessBlocks() will process blocks indefinitely, polling for and handling new blocks at a fixed interval. However, for testing purposes we call a modified function ctm.verifier.ProcessNBlocks() which terminates after processing N blocks, meaning it has a finite execution time.

Particularly, in L215 we specify ProcessNBlocks to terminate after processing N = 2 blocks, so we expect the DB to return the latest consecutively finalized block as N = 2.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just thought of it again. I think a better way is just to use the require.Eventually loop to wait for checkLatestConsecutivelyFinalizedBlock(targetBlockHeight+1) to return true. you can see many examples in this file or the test manager

so in this way, we don't need to create a special function only for testing purpose

}
55 changes: 54 additions & 1 deletion itest/opstackl2/op_test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
package e2etest_op

import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
Expand All @@ -17,6 +20,8 @@ import (
"github.com/babylonchain/babylon-finality-gadget/sdk/btcclient"
sdkclient "github.com/babylonchain/babylon-finality-gadget/sdk/client"
sdkcfg "github.com/babylonchain/babylon-finality-gadget/sdk/config"
"github.com/babylonchain/babylon-finality-gadget/verifier/db"
"github.com/babylonchain/babylon-finality-gadget/verifier/verifier"
bbncfg "github.com/babylonchain/babylon/client/config"
bbntypes "github.com/babylonchain/babylon/types"
api "github.com/babylonchain/finality-provider/clientcontroller/api"
Expand All @@ -37,6 +42,7 @@ import (
ope2e "github.com/ethereum-optimism/optimism/op-e2e"
optestlog "github.com/ethereum-optimism/optimism/op-service/testlog"
gethlog "github.com/ethereum/go-ethereum/log"
epg "github.com/fergusstrange/embedded-postgres"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand All @@ -58,7 +64,9 @@ type OpL2ConsumerTestManager struct {
EOTSServerHandler *e2eutils.EOTSServerHandler
BaseDir string
SdkClient *sdkclient.SdkClient
OpSystem *ope2e.System
verifier *verifier.Verifier
PostgresDB *epg.EmbeddedPostgres
OpSystem *ope2e.System
}

func StartOpL2ConsumerManager(t *testing.T, numOfConsumerFPs uint8) *OpL2ConsumerTestManager {
Expand Down Expand Up @@ -109,6 +117,26 @@ func StartOpL2ConsumerManager(t *testing.T, numOfConsumerFPs uint8) *OpL2Consume
require.NoError(t, err)
t.Logf(log.Prefix("Register consumer %s to Babylon"), opConsumerId)

// Create new embedded postgres db instance for testing verifier daemon
postgres := epg.NewDatabase(epg.DefaultConfig().Username("postgres").Password("postgres").Database("babylon").Port(5433))
err = postgres.Start()
require.NoError(t, err)
Comment on lines +121 to +123
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make it optional so tests that don't need to run verifier won't need to start a db?

actually I guess we won't need to to worry about it once we changed babylonchain/babylon-finality-gadget#62 to use https://github.com/etcd-io/bbolt?

Copy link
Author

Choose a reason for hiding this comment

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

yes i think this will be superseded by the db refactor. what we can do is start a db only if db configs are provided (ie make it optional)


// create verifier daemon
bap2pecs marked this conversation as resolved.
Show resolved Hide resolved
vf, err := verifier.NewVerifier(context.Background(), &verifier.Config{
L2RPCHost: opL2ConsumerConfig.OPStackL2RPCAddress,
BitcoinRPCHost: trimLeadingHttp(opSys.Cfg.DeployConfig.BabylonFinalityGadgetBitcoinRpc),
PGConnectionString: "postgresql://postgres:postgres@localhost:5433/babylon",
FGContractAddress: opSys.Cfg.DeployConfig.BabylonFinalityGadgetContractAddress,
BBNChainID: opSys.Cfg.DeployConfig.BabylonFinalityGadgetChainID,
BBNRPCAddress: opL2ConsumerConfig.RPCAddr,
ServerPort: "8080",
PollInterval: time.Second * time.Duration(10),
})
if err != nil {
t.Fatalf("failed to create verifier daemon: %v", err)
}

ctm := &OpL2ConsumerTestManager{
BaseTestManager: BaseTestManager{
BBNClient: babylonClient,
Expand All @@ -120,6 +148,8 @@ func StartOpL2ConsumerManager(t *testing.T, numOfConsumerFPs uint8) *OpL2Consume
ConsumerFpApps: consumerFpApps,
BaseDir: testDir,
SdkClient: sdkClient,
verifier: vf,
PostgresDB: postgres,
OpSystem: opSys,
}

Expand Down Expand Up @@ -878,6 +908,27 @@ func queryFirstPublicRandCommit(
return resp, nil
}

func checkLatestConsecutivelyFinalizedBlock(t *testing.T, exp uint64) {
// Make the GET request
resp, err := http.Get("http://localhost:8080/getLatest")
require.NoError(t, err)
defer resp.Body.Close()

// Read the response body
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)

// Unmarshal the response.
var block db.Block
err = json.Unmarshal(body, &block)
require.NoError(t, err)

// Check the response.
require.Equal(t, block.BlockHeight, exp)
require.Equal(t, block.IsFinalized, true)
t.Logf(log.Prefix("Checked block at height %d is finalized"), block.BlockHeight)
}

func (ctm *OpL2ConsumerTestManager) Stop(t *testing.T) {
t.Log("Stopping test manager")
var err error
Expand All @@ -899,4 +950,6 @@ func (ctm *OpL2ConsumerTestManager) Stop(t *testing.T) {
ctm.EOTSServerHandler.Stop()
err = os.RemoveAll(ctm.BaseDir)
require.NoError(t, err)
err = ctm.PostgresDB.Stop()
require.NoError(t, err)
}