From 879d2cb27f929bf1c1f173ed8f931a2775c076fd Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 23 Jun 2014 10:09:42 -0500 Subject: [PATCH] Do not save to disk whether UTXOs are locked. The lockunspent RPC is volatile, that is, it only locks unspent transaction outputs from being used as inputs for the duration of the wallet process, or until the UTXO is unlocked with a later call to lockunspent. Therefore, remove the serialization of the lockedness when writing txstore Credits. The space which used to contain the locked flag is now unused and may be used for other flags in the future. --- txstore/serialization.go | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/txstore/serialization.go b/txstore/serialization.go index 3a4b842..dbc6780 100644 --- a/txstore/serialization.go +++ b/txstore/serialization.go @@ -521,8 +521,13 @@ func (t *txRecord) ReadFrom(r io.Reader) (int64, error) { return n64, err } - // Read single byte that specifies whether this credit - // is locked. + // Read single byte. This was previously used to + // specify whether an unspent credit was locked or not, + // but this was removed as lockedness is volatile and + // should not be saved. + // + // This space can be used for additional flags in the + // future. n, err = io.ReadFull(r, singleByte) n64 += int64(n) if err != nil { @@ -531,10 +536,6 @@ func (t *txRecord) ReadFrom(r io.Reader) (int64, error) { } return n64, err } - locked, err := byteAsBool(singleByte[0]) - if err != nil { - return n64, err - } // Read identifier for a valid pointer. n, err = io.ReadFull(r, singleByte) @@ -565,7 +566,7 @@ func (t *txRecord) ReadFrom(r io.Reader) (int64, error) { } } - c := &credit{change, locked, spentBy} + c := &credit{change, false, spentBy} credits = append(credits, c) } @@ -678,24 +679,15 @@ func (t *txRecord) WriteTo(w io.Writer) (int64, error) { } // Write a single byte to specify whether this credit - // was added as change. + // was added as change, plus an extra empty byte which + // used to specify whether the credit was locked. This + // extra byte is currently unused and may be used for + // other flags in the future. changeByte := falseByte if c.change { changeByte = trueByte } - n, err = w.Write([]byte{changeByte}) - n64 += int64(n) - if err != nil { - return n64, err - } - - // Write a single byte to specify whether this credit - // is locked. - lockByte := falseByte - if c.change { - lockByte = trueByte - } - n, err = w.Write([]byte{lockByte}) + n, err = w.Write([]byte{changeByte, 0}) n64 += int64(n) if err != nil { return n64, err