lnrpc+itest: implement MuSig2Cleanup RPC

This commit is contained in:
Oliver Gugger 2022-05-04 18:31:47 +02:00
parent 7e11f64650
commit 52e42fc107
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 41 additions and 1 deletions

View File

@ -92,6 +92,10 @@ var (
Entity: "signer",
Action: "generate",
}},
"/signrpc.Signer/MuSig2Cleanup": {{
Entity: "signer",
Action: "generate",
}},
}
// DefaultSignerMacFilename is the default name of the signer macaroon
@ -940,6 +944,24 @@ func (s *Server) MuSig2CombineSig(_ context.Context,
}, nil
}
// MuSig2Cleanup removes a session from memory to free up resources.
func (s *Server) MuSig2Cleanup(_ context.Context,
in *MuSig2CleanupRequest) (*MuSig2CleanupResponse, error) {
// Check session ID length.
sessionID, err := parseMuSig2SessionID(in.SessionId)
if err != nil {
return nil, fmt.Errorf("error parsing session ID: %v", err)
}
err = s.cfg.Signer.MuSig2Cleanup(sessionID)
if err != nil {
return nil, fmt.Errorf("error cleaning up session: %v", err)
}
return &MuSig2CleanupResponse{}, nil
}
// parseRawKeyBytes checks that the provided raw public key is valid and returns
// the public key. A nil public key is returned if the length of the rawKeyBytes
// is zero.

View File

@ -906,11 +906,29 @@ func testTaprootMuSig2CombinedLeafKeySpend(ctxt context.Context, t *harnessTest,
ctxt, &signrpc.MuSig2SignRequest{
SessionId: sessResp3.SessionId,
MessageDigest: sigHash,
Cleanup: true,
},
)
require.NoError(t.t, err)
// We manually clean up session 3, just to make sure that works as well.
_, err = alice.SignerClient.MuSig2Cleanup(
ctxt, &signrpc.MuSig2CleanupRequest{
SessionId: sessResp3.SessionId,
},
)
require.NoError(t.t, err)
// A second call to that cleaned up session should now fail with a
// specific error.
_, err = alice.SignerClient.MuSig2Sign(
ctxt, &signrpc.MuSig2SignRequest{
SessionId: sessResp3.SessionId,
MessageDigest: sigHash,
},
)
require.Error(t.t, err)
require.Contains(t.t, err.Error(), "not found")
// Luckily only one of the signers needs to combine the signature, so
// let's do that now.
combineReq1, err := alice.SignerClient.MuSig2CombineSig(