From ac7c93f5448175a5db3046411b620805d9479ff4 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Sat, 28 Sep 2019 08:23:38 +0200 Subject: [PATCH] channeldb: fail migration for accepted hodl invoices --- channeldb/migration_11_invoices.go | 5 +++++ channeldb/migration_11_invoices_test.go | 26 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/channeldb/migration_11_invoices.go b/channeldb/migration_11_invoices.go index e242309b..b4e60733 100644 --- a/channeldb/migration_11_invoices.go +++ b/channeldb/migration_11_invoices.go @@ -69,6 +69,11 @@ func migrateInvoices(tx *bbolt.Tx) error { return err } + if invoice.Terms.State == ContractAccepted { + return fmt.Errorf("cannot upgrade with invoice(s) " + + "in accepted state, see release notes") + } + // Try to decode the payment request for every possible net to // avoid passing a the active network to channeldb. This would // be a layering violation, while this migration is only running diff --git a/channeldb/migration_11_invoices_test.go b/channeldb/migration_11_invoices_test.go index b8518a35..34cb1a92 100644 --- a/channeldb/migration_11_invoices_test.go +++ b/channeldb/migration_11_invoices_test.go @@ -127,6 +127,32 @@ func TestMigrateInvoices(t *testing.T) { false) } +// TestMigrateInvoicesHodl checks that a hodl invoice in the accepted state +// fails the migration. +func TestMigrateInvoicesHodl(t *testing.T) { + t.Parallel() + + payReqBtc, err := getPayReq(&bitcoinCfg.MainNetParams) + if err != nil { + t.Fatal(err) + } + + invoices := []Invoice{ + { + PaymentRequest: []byte(payReqBtc), + Terms: ContractTerm{ + State: ContractAccepted, + }, + }, + } + + applyMigration(t, + func(d *DB) { beforeMigrationFuncV11(t, d, invoices) }, + func(d *DB) {}, + migrateInvoices, + true) +} + // signDigestCompact generates a test signature to be used in the generation of // test payment requests. func signDigestCompact(hash []byte) ([]byte, error) {