• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 12312390362

13 Dec 2024 08:44AM UTC coverage: 57.458% (+8.5%) from 48.92%
12312390362

Pull #9343

github

ellemouton
fn: rework the ContextGuard and add tests

In this commit, the ContextGuard struct is re-worked such that the
context that its new main WithCtx method provides is cancelled in sync
with a parent context being cancelled or with it's quit channel being
cancelled. Tests are added to assert the behaviour. In order for the
close of the quit channel to be consistent with the cancelling of the
derived context, the quit channel _must_ be contained internal to the
ContextGuard so that callers are only able to close the channel via the
exposed Quit method which will then take care to first cancel any
derived context that depend on the quit channel before returning.
Pull Request #9343: fn: expand the ContextGuard and add tests

101853 of 177264 relevant lines covered (57.46%)

24972.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.14
/lntypes/txsize.go
1
package lntypes
2

3
import (
4
        "fmt"
5
        "math"
6
)
7

8
// WeightUnit defines a unit to express the transaction size. One weight unit
9
// is 1/4_000_000 of the max block size. The tx weight is calculated using
10
// `Base tx size * 3 + Total tx size`.
11
//   - Base tx size is size of the transaction serialized without the witness
12
//     data.
13
//   - Total tx size is the transaction size in bytes serialized according
14
//     #BIP144.
15
type WeightUnit uint64
16

17
// ToVB converts a value expressed in weight units to virtual bytes.
18
func (wu WeightUnit) ToVB() VByte {
8✔
19
        // According to BIP141: Virtual transaction size is defined as
8✔
20
        // Transaction weight / 4 (rounded up to the next integer).
8✔
21
        return VByte(math.Ceil(float64(wu) / 4))
8✔
22
}
8✔
23

24
// String returns the string representation of the weight unit.
25
func (wu WeightUnit) String() string {
×
26
        return fmt.Sprintf("%d wu", wu)
×
27
}
×
28

29
// VByte defines a unit to express the transaction size. One virtual byte is
30
// 1/4th of a weight unit. The tx virtual bytes is calculated using `TxWeight /
31
// 4`.
32
type VByte uint64
33

34
// ToWU converts a value expressed in virtual bytes to weight units.
35
func (vb VByte) ToWU() WeightUnit {
20✔
36
        return WeightUnit(vb * 4)
20✔
37
}
20✔
38

39
// String returns the string representation of the virtual byte.
40
func (vb VByte) String() string {
×
41
        return fmt.Sprintf("%d vb", vb)
×
42
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc