From 7ecd3f35774e53bcf8d18863e4c7e23697290428 Mon Sep 17 00:00:00 2001 From: parketh Date: Thu, 18 Jul 2024 14:24:54 +0100 Subject: [PATCH 1/6] fix merge conflicts --- go.mod | 6 ++++-- go.sum | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 3141dc41..5976a36a 100644 --- a/go.mod +++ b/go.mod @@ -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 ( @@ -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 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 @@ -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 @@ -437,6 +438,7 @@ 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.20240717112351-36562c701716 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/go-ethereum => github.com/ethereum-optimism/op-geth v1.101315.1-rc.5 diff --git a/go.sum b/go.sum index 03aa3e88..78cbedec 100644 --- a/go.sum +++ b/go.sum @@ -296,8 +296,8 @@ 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.20240717112351-36562c701716 h1:APKL8yLL1vs1UciEbq5tCoBBGZLSVc6OZ3nnzxO2uGw= +github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240717112351-36562c701716/go.mod h1:jzTCknX0PH2tczi6FPqGmWftums3uej5y6ZmEDjOIPw= 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= @@ -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= From 34897630536747f21d172ee37098e63b7f5d36a3 Mon Sep 17 00:00:00 2001 From: parketh Date: Thu, 18 Jul 2024 14:31:48 +0100 Subject: [PATCH 2/6] fix: use latest branch of dep `babylon/optimism` --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5976a36a..9145cf42 100644 --- a/go.mod +++ b/go.mod @@ -440,7 +440,7 @@ replace ( 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.20240717112351-36562c701716 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 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 diff --git a/go.sum b/go.sum index 78cbedec..50aad59c 100644 --- a/go.sum +++ b/go.sum @@ -304,8 +304,8 @@ github.com/babylonchain/babylon-sdk/demo v0.0.0-20240705194516-4e2c5650cde8 h1:V 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= From 6f3ef5a9ee044b614d2be48362d69c5f047ec6ab Mon Sep 17 00:00:00 2001 From: parketh Date: Fri, 26 Jul 2024 12:13:23 +0800 Subject: [PATCH 3/6] test: add verifier daemon e2e test --- Makefile | 4 ++ go.mod | 4 +- go.sum | 4 +- itest/opstackl2/op_e2e_test.go | 92 ++++++++++++++++++++++++++++++ itest/opstackl2/op_test_manager.go | 21 +++++++ 5 files changed, 121 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3c4b23e3..8f8b19fd 100644 --- a/Makefile +++ b/Makefile @@ -109,6 +109,10 @@ 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)$ + DEVNET_REPO_URL := https://github.com/babylonchain/op-e2e-devnet TARGET_DIR := ./itest/opstackl2/devnet-data diff --git a/go.mod b/go.mod index 9145cf42..ec8a2821 100644 --- a/go.mod +++ b/go.mod @@ -247,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 + github.com/fergusstrange/embedded-postgres v1.10.0 // indirect 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 @@ -438,7 +438,7 @@ 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.20240717112351-36562c701716 + github.com/babylonchain/babylon-finality-gadget => github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726034118-1a197c140f14 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.20240717131100-fa941f083b02 github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101315.1-rc.5 diff --git a/go.sum b/go.sum index 50aad59c..6d5308ad 100644 --- a/go.sum +++ b/go.sum @@ -296,8 +296,8 @@ 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.20240717112351-36562c701716 h1:APKL8yLL1vs1UciEbq5tCoBBGZLSVc6OZ3nnzxO2uGw= -github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240717112351-36562c701716/go.mod h1:jzTCknX0PH2tczi6FPqGmWftums3uej5y6ZmEDjOIPw= +github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726034118-1a197c140f14 h1:WGfybiONeKXAiaUXwBzhRxYIZicqAjHpbXSqOj7xeP0= +github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726034118-1a197c140f14/go.mod h1:jzTCknX0PH2tczi6FPqGmWftums3uej5y6ZmEDjOIPw= 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= diff --git a/itest/opstackl2/op_e2e_test.go b/itest/opstackl2/op_e2e_test.go index 561d97a6..4461ca22 100644 --- a/itest/opstackl2/op_e2e_test.go +++ b/itest/opstackl2/op_e2e_test.go @@ -4,7 +4,11 @@ package e2etest_op import ( + "context" "encoding/hex" + "fmt" + "io/ioutil" + "net/http" "testing" "time" @@ -174,3 +178,91 @@ func TestFinalityStuckAndRecover(t *testing.T) { "OP chain fianlity is recovered, the latest finalized block height %d", ), nextFinalizedHeight) } + +func TestOpVerifierDaemon(t *testing.T) { + ctm := StartOpL2ConsumerManager(t) + 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 the public randomness is committed + 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) + // stop the first FP instance + fpStopErr := fpList[0].Stop() + require.NoError(t, fpStopErr) + + ctm.WaitForFpVoteAtHeight(t, fpList[1], targetBlockHeight) + + testBlock, err := ctm.OpL2ConsumerCtrl.QueryBlock(targetBlockHeight) + require.NoError(t, err) + queryParams := cwclient.L2Block{ + BlockHeight: testBlock.Height, + BlockHash: hex.EncodeToString(testBlock.Hash), + BlockTimestamp: 12345, // doesn't matter b/c the BTC client is mocked + } + finalized, err := ctm.SdkClient.QueryIsBlockBabylonFinalized(queryParams) + require.NoError(t, err) + require.Equal(t, true, finalized) + t.Logf(log.Prefix("Test case 1: block %d is finalized"), testBlock.Height) + + // === another test case only for the last FP instance sign === + // first make sure the first FP is stopped + require.Eventually(t, func() bool { + return !fpList[0].IsRunning() + }, e2eutils.EventuallyWaitTimeOut, e2eutils.EventuallyPollTime) + t.Logf(log.Prefix("Stopped the first FP instance")) + + // select a block that the first FP has not processed yet to give to the second FP to sign + testNextBlockHeight := fpList[0].GetLastVotedHeight() + 1 + t.Logf(log.Prefix("Test next block height %d"), testNextBlockHeight) + ctm.WaitForFpVoteAtHeight(t, fpList[1], testNextBlockHeight) + + testNextBlock, err := ctm.OpL2ConsumerCtrl.QueryBlock(testNextBlockHeight) + require.NoError(t, err) + queryNextParams := cwclient.L2Block{ + BlockHeight: testNextBlock.Height, + BlockHash: hex.EncodeToString(testNextBlock.Hash), + BlockTimestamp: 12345, // doesn't matter b/c the BTC client is mocked + } + // testNextBlock only have 1/4 total voting power + nextFinalized, err := ctm.SdkClient.QueryIsBlockBabylonFinalized(queryNextParams) + require.NoError(t, err) + require.Equal(t, false, nextFinalized) + t.Logf(log.Prefix("Test case 2: block %d is not finalized"), testNextBlock.Height) + + // run the verifier daemon + err = ctm.verifier.ProcessNBlocks(context.Background(), 1) + require.NoError(t, err) +} + +func getLatestConsecutivelyFinalizedBlock(t *testing.T) { + // Make the GET request + resp, err := http.Get("http://localhost:8080/getLatest") + if err != nil { + t.Fatalf("GET /getLatest error: %v", err) + return + } + defer resp.Body.Close() + + // Read the response body + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Fatalf("GET /getLatest error: %v", err) + return + } + + fmt.Printf("Response body: %s\n", body) +} diff --git a/itest/opstackl2/op_test_manager.go b/itest/opstackl2/op_test_manager.go index ba504b49..00d467ad 100644 --- a/itest/opstackl2/op_test_manager.go +++ b/itest/opstackl2/op_test_manager.go @@ -5,6 +5,7 @@ package e2etest_op import ( "bytes" + "context" "encoding/hex" "encoding/json" "fmt" @@ -18,6 +19,7 @@ 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/verifier" bbncfg "github.com/babylonchain/babylon/client/config" bbntypes "github.com/babylonchain/babylon/types" bbncc "github.com/babylonchain/finality-provider/clientcontroller/babylon" @@ -57,6 +59,7 @@ type OpL2ConsumerTestManager struct { OpL2ConsumerCtrl *opstackl2.OPStackL2ConsumerController BaseDir string SdkClient *sdkclient.SdkClient + verifier *verifier.Verifier OpSystem *ope2e.System } @@ -190,6 +193,23 @@ func StartOpL2ConsumerManager(t *testing.T) *OpL2ConsumerTestManager { }) require.NoError(t, err) + // Create new embedded postgres db instance for testing verifier daemon + // epg.NewDatabase(epg.DefaultConfig().Username("postgres").Password("postgres").Database("babylon")) + + // create verifier daemon + vf, err := verifier.NewVerifier(context.Background(), &verifier.Config{ + L2RPCHost: opL2ConsumerConfig.OPStackL2RPCAddress, + BitcoinRPCHost: trimLeadingHttp(opSysCfg.DeployConfig.BabylonFinalityGadgetBitcoinRpc), + PGConnectionString: "postgresql://parkyeung:parkyeung@localhost:5432/babylon", + FGContractAddress: cwContractAddress, + BBNChainID: opSysCfg.DeployConfig.BabylonFinalityGadgetChainID, + BBNRPCAddress: cwConfig.RPCAddr, + PollInterval: time.Second * time.Duration(10), + }) + if err != nil { + t.Fatalf("failed to create verifier daemon: %v", err) + } + ctm := &OpL2ConsumerTestManager{ BaseTestManager: BaseTestManager{BBNClient: bc, CovenantPrivKeys: covenantPrivKeys}, BabylonHandler: bh, @@ -199,6 +219,7 @@ func StartOpL2ConsumerManager(t *testing.T) *OpL2ConsumerTestManager { OpL2ConsumerCtrl: opcc, BaseDir: testDir, SdkClient: sdkClient, + verifier: vf, OpSystem: opSys, } From ca9e87167924c91491cd88560d349f63cc5d2034 Mon Sep 17 00:00:00 2001 From: parketh Date: Fri, 26 Jul 2024 13:09:26 +0800 Subject: [PATCH 4/6] test: update verifier daemon e2e test for merge changes --- itest/opstackl2/op_e2e_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/itest/opstackl2/op_e2e_test.go b/itest/opstackl2/op_e2e_test.go index 4c920bea..20144824 100644 --- a/itest/opstackl2/op_e2e_test.go +++ b/itest/opstackl2/op_e2e_test.go @@ -183,7 +183,7 @@ func TestFinalityStuckAndRecover(t *testing.T) { } func TestOpVerifierDaemon(t *testing.T) { - ctm := StartOpL2ConsumerManager(t) + ctm := StartOpL2ConsumerManager(t, 2) defer ctm.Stop(t) // register, get BTC delegations, and start FPs @@ -194,7 +194,8 @@ func TestOpVerifierDaemon(t *testing.T) { {e2eutils.StakingTime, e2eutils.StakingAmount}, }) - // check the public randomness is committed + // 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]) } @@ -209,7 +210,7 @@ func TestOpVerifierDaemon(t *testing.T) { ctm.WaitForFpVoteAtHeight(t, fpList[1], targetBlockHeight) - testBlock, err := ctm.OpL2ConsumerCtrl.QueryBlock(targetBlockHeight) + testBlock, err := ctm.getOpCCAtIndex(1).QueryBlock(targetBlockHeight) require.NoError(t, err) queryParams := cwclient.L2Block{ BlockHeight: testBlock.Height, @@ -233,7 +234,7 @@ func TestOpVerifierDaemon(t *testing.T) { t.Logf(log.Prefix("Test next block height %d"), testNextBlockHeight) ctm.WaitForFpVoteAtHeight(t, fpList[1], testNextBlockHeight) - testNextBlock, err := ctm.OpL2ConsumerCtrl.QueryBlock(testNextBlockHeight) + testNextBlock, err := ctm.getOpCCAtIndex(1).QueryBlock(testNextBlockHeight) require.NoError(t, err) queryNextParams := cwclient.L2Block{ BlockHeight: testNextBlock.Height, @@ -249,6 +250,9 @@ func TestOpVerifierDaemon(t *testing.T) { // run the verifier daemon err = ctm.verifier.ProcessNBlocks(context.Background(), 1) require.NoError(t, err) + + // fetch latest consecutively finalized block + getLatestConsecutivelyFinalizedBlock(t) } func getLatestConsecutivelyFinalizedBlock(t *testing.T) { @@ -267,5 +271,5 @@ func getLatestConsecutivelyFinalizedBlock(t *testing.T) { return } - fmt.Printf("Response body: %s\n", body) + fmt.Printf("GET /getLatest Response body: %s\n", body) } From ee3bff5e9973851ac547acabed1063bb492d6de5 Mon Sep 17 00:00:00 2001 From: parketh Date: Fri, 26 Jul 2024 15:04:44 +0800 Subject: [PATCH 5/6] test: complete verifier daemon e2e test --- go.mod | 4 +- go.sum | 4 +- itest/opstackl2/op_e2e_test.go | 80 +++++------------------------- itest/opstackl2/op_test_manager.go | 24 +++++++++ 4 files changed, 41 insertions(+), 71 deletions(-) diff --git a/go.mod b/go.mod index ec8a2821..cde404a3 100644 --- a/go.mod +++ b/go.mod @@ -247,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 @@ -438,7 +438,7 @@ 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.20240726034118-1a197c140f14 + github.com/babylonchain/babylon-finality-gadget => github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726071303-ed98fb9349be 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.20240717131100-fa941f083b02 github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101315.1-rc.5 diff --git a/go.sum b/go.sum index 6d5308ad..7d01e3df 100644 --- a/go.sum +++ b/go.sum @@ -296,8 +296,8 @@ 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.20240726034118-1a197c140f14 h1:WGfybiONeKXAiaUXwBzhRxYIZicqAjHpbXSqOj7xeP0= -github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726034118-1a197c140f14/go.mod h1:jzTCknX0PH2tczi6FPqGmWftums3uej5y6ZmEDjOIPw= +github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726071303-ed98fb9349be h1:B70jTqYRiaWbghWN5LP+v4jaROrBo9FCgEqRaH9iSwA= +github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726071303-ed98fb9349be/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= diff --git a/itest/opstackl2/op_e2e_test.go b/itest/opstackl2/op_e2e_test.go index 20144824..7d6d534e 100644 --- a/itest/opstackl2/op_e2e_test.go +++ b/itest/opstackl2/op_e2e_test.go @@ -7,8 +7,6 @@ import ( "context" "encoding/hex" "fmt" - "io/ioutil" - "net/http" "testing" "time" @@ -183,6 +181,7 @@ func TestFinalityStuckAndRecover(t *testing.T) { } func TestOpVerifierDaemon(t *testing.T) { + // start the consumer manager ctm := StartOpL2ConsumerManager(t, 2) defer ctm.Stop(t) @@ -202,74 +201,21 @@ func TestOpVerifierDaemon(t *testing.T) { // both FP will sign the first block targetBlockHeight := ctm.WaitForTargetBlockPubRand(t, fpList) - ctm.WaitForFpVoteAtHeight(t, fpList[0], targetBlockHeight) - // stop the first FP instance - fpStopErr := fpList[0].Stop() - require.NoError(t, fpStopErr) - ctm.WaitForFpVoteAtHeight(t, fpList[1], targetBlockHeight) + t.Logf(log.Prefix("Both FP instances signed the first block")) - testBlock, err := ctm.getOpCCAtIndex(1).QueryBlock(targetBlockHeight) - require.NoError(t, err) - queryParams := cwclient.L2Block{ - BlockHeight: testBlock.Height, - BlockHash: hex.EncodeToString(testBlock.Hash), - BlockTimestamp: 12345, // doesn't matter b/c the BTC client is mocked - } - finalized, err := ctm.SdkClient.QueryIsBlockBabylonFinalized(queryParams) - require.NoError(t, err) - require.Equal(t, true, finalized) - t.Logf(log.Prefix("Test case 1: block %d is finalized"), testBlock.Height) - - // === another test case only for the last FP instance sign === - // first make sure the first FP is stopped - require.Eventually(t, func() bool { - return !fpList[0].IsRunning() - }, e2eutils.EventuallyWaitTimeOut, e2eutils.EventuallyPollTime) - t.Logf(log.Prefix("Stopped the first FP instance")) - - // select a block that the first FP has not processed yet to give to the second FP to sign - testNextBlockHeight := fpList[0].GetLastVotedHeight() + 1 - t.Logf(log.Prefix("Test next block height %d"), testNextBlockHeight) - ctm.WaitForFpVoteAtHeight(t, fpList[1], testNextBlockHeight) - - testNextBlock, err := ctm.getOpCCAtIndex(1).QueryBlock(testNextBlockHeight) - require.NoError(t, err) - queryNextParams := cwclient.L2Block{ - BlockHeight: testNextBlock.Height, - BlockHash: hex.EncodeToString(testNextBlock.Hash), - BlockTimestamp: 12345, // doesn't matter b/c the BTC client is mocked - } - // testNextBlock only have 1/4 total voting power - nextFinalized, err := ctm.SdkClient.QueryIsBlockBabylonFinalized(queryNextParams) - require.NoError(t, err) - require.Equal(t, false, nextFinalized) - t.Logf(log.Prefix("Test case 2: block %d is not finalized"), testNextBlock.Height) + // 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 - err = ctm.verifier.ProcessNBlocks(context.Background(), 1) + // 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) - // fetch latest consecutively finalized block - getLatestConsecutivelyFinalizedBlock(t) -} - -func getLatestConsecutivelyFinalizedBlock(t *testing.T) { - // Make the GET request - resp, err := http.Get("http://localhost:8080/getLatest") - if err != nil { - t.Fatalf("GET /getLatest error: %v", err) - return - } - defer resp.Body.Close() - - // Read the response body - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Fatalf("GET /getLatest error: %v", err) - return - } - - fmt.Printf("GET /getLatest Response body: %s\n", body) -} + // get latest finalized block via API and check response + fmt.Printf("targetBlockHeight: %d\n", targetBlockHeight) + checkLatestConsecutivelyFinalizedBlock(t, 2) +} \ No newline at end of file diff --git a/itest/opstackl2/op_test_manager.go b/itest/opstackl2/op_test_manager.go index 7375462d..747a07d3 100644 --- a/itest/opstackl2/op_test_manager.go +++ b/itest/opstackl2/op_test_manager.go @@ -8,6 +8,8 @@ import ( "encoding/hex" "encoding/json" "fmt" + "io/ioutil" + "net/http" "os" "path/filepath" "strings" @@ -18,6 +20,7 @@ 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" @@ -905,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 := ioutil.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 From ba0d50a889d3eda5176effa03eb47033b4376ad7 Mon Sep 17 00:00:00 2001 From: parketh Date: Fri, 26 Jul 2024 15:42:22 +0800 Subject: [PATCH 6/6] chore: fix lint errors --- go.mod | 2 +- go.sum | 4 ++-- itest/opstackl2/op_test_manager.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index cde404a3..c25f0ee6 100644 --- a/go.mod +++ b/go.mod @@ -438,7 +438,7 @@ 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.20240726071303-ed98fb9349be + 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.20240717131100-fa941f083b02 github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101315.1-rc.5 diff --git a/go.sum b/go.sum index 7d01e3df..6f0ffc94 100644 --- a/go.sum +++ b/go.sum @@ -296,8 +296,8 @@ 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.20240726071303-ed98fb9349be h1:B70jTqYRiaWbghWN5LP+v4jaROrBo9FCgEqRaH9iSwA= -github.com/babylonchain/babylon-finality-gadget v0.1.3-alpha.0.20240726071303-ed98fb9349be/go.mod h1:LgEqT5oHGpqRLVMc/qwB9TM99biKYZQDdyrb7Xw6HWI= +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= diff --git a/itest/opstackl2/op_test_manager.go b/itest/opstackl2/op_test_manager.go index 747a07d3..6f6cfafe 100644 --- a/itest/opstackl2/op_test_manager.go +++ b/itest/opstackl2/op_test_manager.go @@ -8,7 +8,7 @@ import ( "encoding/hex" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" "path/filepath" @@ -915,7 +915,7 @@ func checkLatestConsecutivelyFinalizedBlock(t *testing.T, exp uint64) { defer resp.Body.Close() // Read the response body - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) require.NoError(t, err) // Unmarshal the response.