-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: base/consumer-chain-support
Are you sure you want to change the base?
Changes from all commits
7ecd3f3
3489763
6f3ef5a
f886acd
ca9e871
ee3bff5
ba0d50a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does it work since v0.1.3 doesn't exist? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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,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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
package e2etest_op | ||
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
// 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when run normally, Particularly, in L215 we specify There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 so in this way, we don't need to create a special function only for testing purpose |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,12 @@ | |
package e2etest_op | ||
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
@@ -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" | ||
|
@@ -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" | ||
|
@@ -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 { | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -120,6 +148,8 @@ func StartOpL2ConsumerManager(t *testing.T, numOfConsumerFPs uint8) *OpL2Consume | |
ConsumerFpApps: consumerFpApps, | ||
BaseDir: testDir, | ||
SdkClient: sdkClient, | ||
verifier: vf, | ||
PostgresDB: postgres, | ||
OpSystem: opSys, | ||
} | ||
|
||
|
@@ -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 | ||
|
@@ -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) | ||
} |
There was a problem hiding this comment.
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?
I am also curious why make didn't complain since you didn't add
test-e2e-op-single
to.PHONY
in Line 84