channeldb: rename Encode/Decode to serializeLogUpdate/deserializeLogUpdate

To more easily use different version of it post-/pre-migration, we
rename the method and make it take the LogUpdate as an argument.
This commit is contained in:
Johan T. Halseth 2021-02-19 14:37:48 +01:00
parent 7569cca19b
commit 90d36dbdd4
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 15 additions and 10 deletions

@ -1791,14 +1791,19 @@ type LogUpdate struct {
UpdateMsg lnwire.Message UpdateMsg lnwire.Message
} }
// Encode writes a log update to the provided io.Writer. // serializeLogUpdate writes a log update to the provided io.Writer.
func (l *LogUpdate) Encode(w io.Writer) error { func serializeLogUpdate(w io.Writer, l *LogUpdate) error {
return WriteElements(w, l.LogIndex, l.UpdateMsg) return WriteElements(w, l.LogIndex, l.UpdateMsg)
} }
// Decode reads a log update from the provided io.Reader. // deserializeLogUpdate reads a log update from the provided io.Reader.
func (l *LogUpdate) Decode(r io.Reader) error { func deserializeLogUpdate(r io.Reader) (*LogUpdate, error) {
return ReadElements(r, &l.LogIndex, &l.UpdateMsg) l := &LogUpdate{}
if err := ReadElements(r, &l.LogIndex, &l.UpdateMsg); err != nil {
return nil, err
}
return l, nil
} }
// CircuitKey is used by a channel to uniquely identify the HTLCs it receives // CircuitKey is used by a channel to uniquely identify the HTLCs it receives

@ -487,7 +487,7 @@ func (*ChannelPackager) AddFwdPkg(tx kvdb.RwTx, fwdPkg *FwdPkg) error {
// putLogUpdate writes an htlc to the provided `bkt`, using `index` as the key. // putLogUpdate writes an htlc to the provided `bkt`, using `index` as the key.
func putLogUpdate(bkt kvdb.RwBucket, idx uint16, htlc *LogUpdate) error { func putLogUpdate(bkt kvdb.RwBucket, idx uint16, htlc *LogUpdate) error {
var b bytes.Buffer var b bytes.Buffer
if err := htlc.Encode(&b); err != nil { if err := serializeLogUpdate(&b, htlc); err != nil {
return err return err
} }
@ -541,7 +541,7 @@ func loadChannelFwdPkgs(tx kvdb.RTx, source lnwire.ShortChannelID) ([]*FwdPkg, e
return fwdPkgs, nil return fwdPkgs, nil
} }
// loadFwPkg reads the packager's fwd pkg at a given height, and determines the // loadFwdPkg reads the packager's fwd pkg at a given height, and determines the
// appropriate FwdState. // appropriate FwdState.
func loadFwdPkg(fwdPkgBkt kvdb.RBucket, source lnwire.ShortChannelID, func loadFwdPkg(fwdPkgBkt kvdb.RBucket, source lnwire.ShortChannelID,
height uint64) (*FwdPkg, error) { height uint64) (*FwdPkg, error) {
@ -652,12 +652,12 @@ func loadFwdPkg(fwdPkgBkt kvdb.RBucket, source lnwire.ShortChannelID,
func loadHtlcs(bkt kvdb.RBucket) ([]LogUpdate, error) { func loadHtlcs(bkt kvdb.RBucket) ([]LogUpdate, error) {
var htlcs []LogUpdate var htlcs []LogUpdate
if err := bkt.ForEach(func(_, v []byte) error { if err := bkt.ForEach(func(_, v []byte) error {
var htlc LogUpdate htlc, err := deserializeLogUpdate(bytes.NewReader(v))
if err := htlc.Decode(bytes.NewReader(v)); err != nil { if err != nil {
return err return err
} }
htlcs = append(htlcs, htlc) htlcs = append(htlcs, *htlc)
return nil return nil
}); err != nil { }); err != nil {