What changed, and why it matters
This commit simply moves two helper functions that convert time values to and from a binary format from one file to another within the same package. There is no change to what the code does, no bug fix, and no security-relevant behavior.
No security action needed. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit relocates deserializeTime and serializeTime from channeldb/mp_payment.go to channeldb/codec.go. The implementations are copied verbatim, with only the addition of the time import in codec.go. This is a pure refactor in preparation for moving payment-related code into its own package. No logic, semantics, or security properties are altered.
Changed components
channeldb/codec.gochanneldb/mp_payment.goInspect captured patch +34 / −33
diff --git a/channeldb/codec.go b/channeldb/codec.go
index 8c39f4d..95434a5 100644
--- a/channeldb/codec.go
+++ b/channeldb/codec.go
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net"
+ "time"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
@@ -466,3 +467,36 @@ func ReadElements(r io.Reader, elements ...interface{}) error {
}
return nil
}
+
+// deserializeTime deserializes time as unix nanoseconds.
+func deserializeTime(r io.Reader) (time.Time, error) {
+ var scratch [8]byte
+ if _, err := io.ReadFull(r, scratch[:]); err != nil {
+ return time.Time{}, err
+ }
+
+ // Convert to time.Time. Interpret unix nano time zero as a zero
+ // time.Time value.
+ unixNano := byteOrder.Uint64(scratch[:])
+ if unixNano == 0 {
+ return time.Time{}, nil
+ }
+
+ return time.Unix(0, int64(unixNano)), nil
+}
+
+// serializeTime serializes time as unix nanoseconds.
+func serializeTime(w io.Writer, t time.Time) error {
+ var scratch [8]byte
+
+ // Convert to unix nano seconds, but only if time is non-zero. Calling
+ // UnixNano() on a zero time yields an undefined result.
+ var unixNano int64
+ if !t.IsZero() {
+ unixNano = t.UnixNano()
+ }
+
+ byteOrder.PutUint64(scratch[:], uint64(unixNano))
+ _, err := w.Write(scratch[:])
+ return err
+}
diff --git a/channeldb/mp_payment.go b/channeldb/mp_payment.go
index f75357a..f4467b7 100644
--- a/channeldb/mp_payment.go
+++ b/channeldb/mp_payment.go
@@ -654,39 +654,6 @@ func deserializeHTLCFailInfo(r io.Reader) (*HTLCFailInfo, error) {
return f, nil
}
-// deserializeTime deserializes time as unix nanoseconds.
-func deserializeTime(r io.Reader) (time.Time, error) {
- var scratch [8]byte
- if _, err := io.ReadFull(r, scratch[:]); err != nil {
- return time.Time{}, err
- }
-
- // Convert to time.Time. Interpret unix nano time zero as a zero
- // time.Time value.
- unixNano := byteOrder.Uint64(scratch[:])
- if unixNano == 0 {
- return time.Time{}, nil
- }
-
- return time.Unix(0, int64(unixNano)), nil
-}
-
-// serializeTime serializes time as unix nanoseconds.
-func serializeTime(w io.Writer, t time.Time) error {
- var scratch [8]byte
-
- // Convert to unix nano seconds, but only if time is non-zero. Calling
- // UnixNano() on a zero time yields an undefined result.
- var unixNano int64
- if !t.IsZero() {
- unixNano = t.UnixNano()
- }
-
- byteOrder.PutUint64(scratch[:], uint64(unixNano))
- _, err := w.Write(scratch[:])
- return err
-}
-
// generateSphinxPacket generates then encodes a sphinx packet which encodes
// the onion route specified by the passed layer 3 route. The blob returned
// from this function can immediately be included within an HTLC add packet to
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.