mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 14:11:04 +02:00
channeldb+htlcswitch: write wire messages using length prefix
In this commit, we modify the way we write wire messages across the entire database. We'll now ensure that we always write wire messages with a length prefix. We update the `codec.go` file to always write a 2 byte length prefix, this affects the way we write the `CommitDiff` and `LogUpdates` struct to disk, and the network results bucket in the switch as it includes a wire message.
This commit is contained in:
@@ -61,28 +61,15 @@ type networkResult struct {
|
||||
|
||||
// serializeNetworkResult serializes the networkResult.
|
||||
func serializeNetworkResult(w io.Writer, n *networkResult) error {
|
||||
if _, err := lnwire.WriteMessage(w, n.msg, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return channeldb.WriteElements(w, n.unencrypted, n.isResolution)
|
||||
return channeldb.WriteElements(w, n.msg, n.unencrypted, n.isResolution)
|
||||
}
|
||||
|
||||
// deserializeNetworkResult deserializes the networkResult.
|
||||
func deserializeNetworkResult(r io.Reader) (*networkResult, error) {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
n := &networkResult{}
|
||||
|
||||
n.msg, err = lnwire.ReadMessage(r, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := channeldb.ReadElements(r,
|
||||
&n.unencrypted, &n.isResolution,
|
||||
&n.msg, &n.unencrypted, &n.isResolution,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user