diff --git a/clientcontroller/babylon.go b/clientcontroller/babylon.go index 121c1f4..97f4432 100644 --- a/clientcontroller/babylon.go +++ b/clientcontroller/babylon.go @@ -158,13 +158,13 @@ func (bc *BabylonController) reliablySendMsgs(msgs []sdk.Msg) (*provider.Relayer // SubmitCovenantSigs submits the Covenant signature via a MsgAddCovenantSig to Babylon if the daemon runs in Covenant mode // it returns tx hash and error -func (bc *BabylonController) SubmitCovenantSigs(covSigs []*types.CovenantSigs) (*types.TxResponse, error) { +func (bc *BabylonController) SubmitCovenantSigs(covSigs []types.CovenantSigs) (*types.TxResponse, error) { msgs := make([]sdk.Msg, 0, len(covSigs)) for _, covSig := range covSigs { - bip340UnbondingSig := bbntypes.NewBIP340SignatureFromBTCSig(covSig.UnbondingSig) + bip340UnbondingSig := bbntypes.NewBIP340SignatureFromBTCSig(&covSig.UnbondingSig) msgs = append(msgs, &btcstakingtypes.MsgAddCovenantSigs{ Signer: bc.mustGetTxSigner(), - Pk: bbntypes.NewBIP340PubKeyFromBTCPK(covSig.PublicKey), + Pk: bbntypes.NewBIP340PubKeyFromBTCPK(&covSig.PublicKey), StakingTxHash: covSig.StakingTxHash.String(), SlashingTxSigs: covSig.SlashingSigs, UnbondingTxSig: bip340UnbondingSig, diff --git a/clientcontroller/interface.go b/clientcontroller/interface.go index 7d15314..dfcd8c5 100644 --- a/clientcontroller/interface.go +++ b/clientcontroller/interface.go @@ -18,7 +18,7 @@ type ClientController interface { // SubmitCovenantSigs submits Covenant signatures to the consumer chain, each corresponding to // a finality provider that the delegation is (re-)staked to // it returns tx hash and error - SubmitCovenantSigs(covSigMsgs []*types.CovenantSigs) (*types.TxResponse, error) + SubmitCovenantSigs(covSigMsgs []types.CovenantSigs) (*types.TxResponse, error) // QueryPendingDelegations queries BTC delegations that are in status of pending QueryPendingDelegations(limit uint64) ([]*types.Delegation, error) diff --git a/covenant/covenant_test.go b/covenant/covenant_test.go index 795f4b5..78f57da 100644 --- a/covenant/covenant_test.go +++ b/covenant/covenant_test.go @@ -33,6 +33,7 @@ var net = &chaincfg.SimNetParams func FuzzAddCovenantSig(f *testing.F) { testutil.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Log("Seed", seed) r := rand.New(rand.NewSource(seed)) params := testutil.GenRandomParams(r, t) @@ -40,6 +41,8 @@ func FuzzAddCovenantSig(f *testing.F) { // create a Covenant key pair in the keyring covenantConfig := covcfg.DefaultConfig() + covenantConfig.BabylonConfig.KeyDirectory = t.TempDir() + covKeyPair, err := keyring.CreateCovenantKey( covenantConfig.BabylonConfig.KeyDirectory, covenantConfig.BabylonConfig.ChainID, @@ -58,7 +61,7 @@ func FuzzAddCovenantSig(f *testing.F) { require.NoError(t, err) numDels := datagen.RandomInt(r, 3) + 1 - covSigsSet := make([]*types.CovenantSigs, 0, numDels) + covSigsSet := make([]types.CovenantSigs, 0, numDels) btcDels := make([]*types.Delegation, 0, numDels) for i := 0; uint64(i) < numDels; i++ { // generate BTC delegation @@ -176,11 +179,11 @@ func FuzzAddCovenantSig(f *testing.F) { require.NoError(t, err) unbondingCovSlashingSigs = append(unbondingCovSlashingSigs, covenantSig.MustMarshal()) } - covSigsSet = append(covSigsSet, &types.CovenantSigs{ - PublicKey: covKeyPair.PublicKey, + covSigsSet = append(covSigsSet, types.CovenantSigs{ + PublicKey: *covKeyPair.PublicKey, StakingTxHash: testInfo.StakingTx.TxHash(), SlashingSigs: covSigs, - UnbondingSig: unbondingCovSig, + UnbondingSig: *unbondingCovSig, SlashingUnbondingSigs: unbondingCovSlashingSigs, }) } @@ -191,9 +194,10 @@ func FuzzAddCovenantSig(f *testing.F) { } btcDels = append(btcDels, invalidDelegation) + sortedCovSigs := covenant.SortCovenantSigs(covSigsSet) // check the sigs are expected expectedTxHash := testutil.GenRandomHexStr(r, 32) - mockClientController.EXPECT().SubmitCovenantSigs(covSigsSet). + mockClientController.EXPECT().SubmitCovenantSigs(sortedCovSigs). Return(&types.TxResponse{TxHash: expectedTxHash}, nil).AnyTimes() res, err := ce.AddCovenantSignatures(btcDels) require.NoError(t, err) diff --git a/testutil/mocks/babylon.go b/testutil/mocks/babylon.go index 6fd3173..879169f 100644 --- a/testutil/mocks/babylon.go +++ b/testutil/mocks/babylon.go @@ -79,7 +79,7 @@ func (mr *MockClientControllerMockRecorder) QueryStakingParamsByVersion(version } // SubmitCovenantSigs mocks base method. -func (m *MockClientController) SubmitCovenantSigs(covSigMsgs []*types.CovenantSigs) (*types.TxResponse, error) { +func (m *MockClientController) SubmitCovenantSigs(covSigMsgs []types.CovenantSigs) (*types.TxResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SubmitCovenantSigs", covSigMsgs) ret0, _ := ret[0].(*types.TxResponse) diff --git a/types/sigs.go b/types/sigs.go index c324ca7..cb39247 100644 --- a/types/sigs.go +++ b/types/sigs.go @@ -7,9 +7,9 @@ import ( ) type CovenantSigs struct { - PublicKey *btcec.PublicKey + PublicKey btcec.PublicKey StakingTxHash chainhash.Hash SlashingSigs [][]byte - UnbondingSig *schnorr.Signature + UnbondingSig schnorr.Signature SlashingUnbondingSigs [][]byte }