diff --git a/lib/trie/hash.go b/lib/trie/hash.go index 0122d410d3e..d0a70c934ee 100644 --- a/lib/trie/hash.go +++ b/lib/trie/hash.go @@ -240,22 +240,37 @@ func encodeChild(child node, buffer *bytes.Buffer) (err error) { func encodeLeaf(l *leaf, buffer *bytes.Buffer) (err error) { if !l.dirty && l.encoding != nil { _, err = buffer.Write(l.encoding) - return err + if err != nil { + return fmt.Errorf("cannot write stored encoding to buffer: %w", err) + } + return nil } encoding, err := l.header() if err != nil { - return err + return fmt.Errorf("cannot encode header: %w", err) + } + + _, err = buffer.Write(encoding) + if err != nil { + return fmt.Errorf("cannot write encoded header to buffer: %w", err) } - _, _ = buffer.Write(encoding) _, _ = buffer.Write(nibblesToKeyLE(l.key)) + _, err = buffer.Write(nibblesToKeyLE(l.key)) + if err != nil { + return fmt.Errorf("cannot write LE key to buffer: %w", err) + } bytes, err := scale.Marshal(l.value) // TODO scale encoder to write to buffer if err != nil { return err } - _, _ = buffer.Write(bytes) + _, err = buffer.Write(bytes) + if err != nil { + return fmt.Errorf("cannot write scale encoded value to buffer: %w", err) + } + return nil }