channeldb: store optional invoice fields as variable length byte arrays

This commit modifies the on-disk storage of invoices to stop the
optional fields (memo+receipt) on-disk as variable length byte arrays.
This change saves space as the optional fields now only take up as much
space as is strictly needed, rather than always being padded out to max
size (1KB).
This commit is contained in:
Olaoluwa Osuntokun
2016-09-23 15:15:22 -07:00
parent 6ff11ba65c
commit 0b841ec686
3 changed files with 26 additions and 12 deletions

View File

@@ -613,12 +613,12 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
i := &channeldb.Invoice{
CreationDate: time.Now(),
Memo: []byte(invoice.Memo),
Receipt: invoice.Receipt,
Terms: channeldb.ContractTerm{
Value: btcutil.Amount(invoice.Value),
},
}
copy(i.Memo[:], invoice.Memo)
copy(i.Receipt[:], invoice.Receipt)
copy(i.Terms.PaymentPreimage[:], preImage)
if err := r.server.invoices.AddInvoice(i); err != nil {