rpc: modify VerifyChanBackup to take either a Single or Multi

This commit is contained in:
Wilmer Paulino committed 2019-04-05 12:51:16 -07:00
1 parent 3a19afe46d
commit b71bb9400a
5 files changed
+669 -705

No files matched your search

+2 -7
View File
@@ -13250,15 +13250,10 @@ func testChannelBackupUpdates(net *lntest.NetworkHarness, t *harnessTest) {
MultiChanBackup: backup, MultiChanBackup: backup,
}, },
} }
resp, err := carol.VerifyChanBackup(ctxb, snapshot) _, err := carol.VerifyChanBackup(ctxb, snapshot)
if err != nil { if err != nil {
return fmt.Errorf("unable to verify "+ return fmt.Errorf("unable to verify "+
"back up: %v", err) "backup #%d: %v", i, err)
}
if !resp.SinglesValid || !resp.MultiValid {
return fmt.Errorf("backup #%v is "+
"invalid", i)
} }
} }
+624 -643
View File
File diff suppressed because it is too large. Load diff
+3 -6
View File
@@ -733,10 +733,9 @@ service Lightning {
}; };
/** /**
VerifyChanBackup allows a caller to verify the integrity of a channel VerifyChanBackup allows a caller to verify the integrity of a channel backup
backup snapshot. This method will accept both a packed Single, and also a snapshot. This method will accept either a packed Single or a packed Multi.
Packed multi. Two bools are returned which indicate if the passed Single Specifying both will result in an error.
(if present) is valid and also if the passed Multi (if present) is valid.
*/ */
rpc VerifyChanBackup(ChanBackupSnapshot) returns (VerifyChanBackupResponse) { rpc VerifyChanBackup(ChanBackupSnapshot) returns (VerifyChanBackupResponse) {
option (google.api.http) = { option (google.api.http) = {
@@ -2365,6 +2364,4 @@ message RestoreBackupResponse {}
message ChannelBackupSubscription {} message ChannelBackupSubscription {}
message VerifyChanBackupResponse { message VerifyChanBackupResponse {
bool singles_valid = 1 [ json_name = "singles_valid"];
bool multi_valid = 2 [ json_name = "multi_valid"];
} }
+2 -12
View File
@@ -226,7 +226,7 @@
}, },
"/v1/channels/backup/verify": { "/v1/channels/backup/verify": {
"post": { "post": {
"summary": "*\nVerifyChanBackup allows a caller to verify the integrity of a channel\nbackup snapshot. This method will accept both a packed Single, and also a\nPacked multi. Two bools are returned which indicate if the passed Single\n(if present) is valid and also if the passed Multi (if present) is valid.", "summary": "*\nVerifyChanBackup allows a caller to verify the integrity of a channel backup\nsnapshot. This method will accept either a packed Single or a packed Multi.\nSpecifying both will result in an error.",
"operationId": "VerifyChanBackup", "operationId": "VerifyChanBackup",
"responses": { "responses": {
"200": { "200": {
@@ -3370,17 +3370,7 @@
} }
}, },
"lnrpcVerifyChanBackupResponse": { "lnrpcVerifyChanBackupResponse": {
"type": "object", "type": "object"
"properties": {
"singles_valid": {
"type": "boolean",
"format": "boolean"
},
"multi_valid": {
"type": "boolean",
"format": "boolean"
}
}
}, },
"lnrpcVerifyMessageRequest": { "lnrpcVerifyMessageRequest": {
"type": "object", "type": "object",
+38 -37
View File
@@ -4766,63 +4766,64 @@ func (r *rpcServer) ExportChannelBackup(ctx context.Context,
}, nil }, nil
} }
// VerifyChanBackup allows a caller to verify the integrity of a channel // VerifyChanBackup allows a caller to verify the integrity of a channel backup
// backup snapshot. This method will accept both a packed Single, and also a // snapshot. This method will accept both either a packed Single or a packed
// Packed multi. Two bools are returned which indicate if the passed Single // Multi. Specifying both will result in an error.
// (if present) is valid and also if the passed Multi (if present) is valid.
func (r *rpcServer) VerifyChanBackup(ctx context.Context, func (r *rpcServer) VerifyChanBackup(ctx context.Context,
in *lnrpc.ChanBackupSnapshot) (*lnrpc.VerifyChanBackupResponse, error) { in *lnrpc.ChanBackupSnapshot) (*lnrpc.VerifyChanBackupResponse, error) {
// If neither a Single or Multi has been specified, then we have switch {
// nothing to verify. // If neither a Single or Multi has been specified, then we have nothing
if in.GetSingleChanBackups() == nil && in.GetMultiChanBackup() == nil { // to verify.
return nil, fmt.Errorf("either a Single or Multi channel " + case in.GetSingleChanBackups() == nil && in.GetMultiChanBackup() == nil:
return nil, errors.New("either a Single or Multi channel " +
"backup must be specified") "backup must be specified")
}
// Either a Single or a Multi must be specified, but not both.
case in.GetSingleChanBackups() != nil && in.GetMultiChanBackup() != nil:
return nil, errors.New("either a Single or Multi channel " +
"backup must be specified, but not both")
// If a Single is specified then we'll only accept one of them to allow // If a Single is specified then we'll only accept one of them to allow
// the caller to map the valid/invalid state for each individual // the caller to map the valid/invalid state for each individual Single.
// Single. case in.GetSingleChanBackups() != nil:
if in.GetSingleChanBackups() != nil &&
len(in.GetSingleChanBackups().ChanBackups) != 1 {
return nil, fmt.Errorf("only one Single is accepted at a time")
}
// By default, we'll assume that both backups are valid.
resp := lnrpc.VerifyChanBackupResponse{
SinglesValid: true,
MultiValid: true,
}
if in.GetSingleChanBackups() != nil {
// First, we'll convert the raw byte sliice into a type we can
// work with a bit better.
chanBackupsProtos := in.GetSingleChanBackups().ChanBackups chanBackupsProtos := in.GetSingleChanBackups().ChanBackups
if len(chanBackupsProtos) != 1 {
return nil, errors.New("only one Single is accepted " +
"at a time")
}
// First, we'll convert the raw byte slice into a type we can
// work with a bit better.
chanBackup := chanbackup.PackedSingles( chanBackup := chanbackup.PackedSingles(
[][]byte{chanBackupsProtos[0].ChanBackup}, [][]byte{chanBackupsProtos[0].ChanBackup},
) )
// With our PackedSingles created, we'll attempt to unpack the // With our PackedSingles created, we'll attempt to unpack the
// backup. If this fails, then we know the backup is invalid // backup. If this fails, then we know the backup is invalid for
// for some reason. // some reason.
_, err := chanBackup.Unpack(r.server.cc.keyRing) _, err := chanBackup.Unpack(r.server.cc.keyRing)
resp.SinglesValid = err == nil if err != nil {
} return nil, fmt.Errorf("invalid single channel "+
"backup: %v", err)
}
if in.GetMultiChanBackup() != nil { case in.GetMultiChanBackup() != nil:
// Similarly, we'll convert the raw byte slice into a // We'll convert the raw byte slice into a PackedMulti that we
// PackedMulti that we can easily work with. // can easily work with.
packedMultiBackup := in.GetMultiChanBackup().MultiChanBackup packedMultiBackup := in.GetMultiChanBackup().MultiChanBackup
packedMulti := chanbackup.PackedMulti(packedMultiBackup) packedMulti := chanbackup.PackedMulti(packedMultiBackup)
// We'll now attempt to unpack the Multi. If this fails, then // We'll now attempt to unpack the Multi. If this fails, then we
// we know it's invalid. // know it's invalid.
_, err := packedMulti.Unpack(r.server.cc.keyRing) _, err := packedMulti.Unpack(r.server.cc.keyRing)
resp.MultiValid = err == nil if err != nil {
return nil, fmt.Errorf("invalid multi channel backup: "+
"%v", err)
}
} }
return &resp, nil return &lnrpc.VerifyChanBackupResponse{}, nil
} }
// createBackupSnapshot converts the passed Single backup into a snapshot which // createBackupSnapshot converts the passed Single backup into a snapshot which