channeldb: update ChannelConstraints+OpenChannel to use lnwire.MilliSatoshi
This commit is contained in:
parent
251f8d650f
commit
74470cf7d0
@ -127,18 +127,15 @@ const (
|
|||||||
// constraints is static for the duration of the channel, meaning the channel
|
// constraints is static for the duration of the channel, meaning the channel
|
||||||
// must be teared down for them to change.
|
// must be teared down for them to change.
|
||||||
type ChannelConstraints struct {
|
type ChannelConstraints struct {
|
||||||
// DustLimit is the min satoshis/kilo-weight that should be paid within
|
// DustLimit is the threhsold (in satoshis) below which any outputs
|
||||||
// the commitment transaction for the entire duration of the channel's
|
// should be trimmed. When an output is trimmed, it isn't materialized
|
||||||
// lifetime. This field may be updated during normal operation of the
|
// as an actual output, but is instead burned to miner's fees.
|
||||||
// channel as on-chain conditions change.
|
|
||||||
DustLimit btcutil.Amount
|
DustLimit btcutil.Amount
|
||||||
|
|
||||||
// MaxPendingAmount is the maximum pending HTLC value that can be
|
// MaxPendingAmount is the maximum pending HTLC value that can be
|
||||||
// present within the channel at a particular time. This value is set
|
// present within the channel at a particular time. This value is set
|
||||||
// by the initiator of the channel and must be upheld at all times.
|
// by the initiator of the channel and must be upheld at all times.
|
||||||
//
|
MaxPendingAmount lnwire.MilliSatoshi
|
||||||
// TODO(roasbeef): in mSAT
|
|
||||||
MaxPendingAmount btcutil.Amount
|
|
||||||
|
|
||||||
// ChanReserve is an absolute reservation on the channel for this
|
// ChanReserve is an absolute reservation on the channel for this
|
||||||
// particular node. This means that the current settled balance for
|
// particular node. This means that the current settled balance for
|
||||||
@ -154,9 +151,7 @@ type ChannelConstraints struct {
|
|||||||
// If any HTLC's below this amount are offered, then the HTLC will be
|
// If any HTLC's below this amount are offered, then the HTLC will be
|
||||||
// rejected. This, in tandem with the dust limit allows a node to
|
// rejected. This, in tandem with the dust limit allows a node to
|
||||||
// regulate the smallest HTLC that it deems economically relevant.
|
// regulate the smallest HTLC that it deems economically relevant.
|
||||||
//
|
MinHTLC lnwire.MilliSatoshi
|
||||||
// TODO(roasbeef): in mSAT
|
|
||||||
MinHTLC btcutil.Amount
|
|
||||||
|
|
||||||
// MaxAcceptedHtlcs is the maximum amount of HTLC's that are to be
|
// MaxAcceptedHtlcs is the maximum amount of HTLC's that are to be
|
||||||
// accepted by the owner of this set of constraints. This allows each
|
// accepted by the owner of this set of constraints. This allows each
|
||||||
@ -275,11 +270,11 @@ type OpenChannel struct {
|
|||||||
|
|
||||||
// LocalBalance is the current available settled balance within the
|
// LocalBalance is the current available settled balance within the
|
||||||
// channel directly spendable by us.
|
// channel directly spendable by us.
|
||||||
LocalBalance btcutil.Amount
|
LocalBalance lnwire.MilliSatoshi
|
||||||
|
|
||||||
// RemoteBalance is the current available settled balance within the
|
// RemoteBalance is the current available settled balance within the
|
||||||
// channel directly spendable by the remote node.
|
// channel directly spendable by the remote node.
|
||||||
RemoteBalance btcutil.Amount
|
RemoteBalance lnwire.MilliSatoshi
|
||||||
|
|
||||||
// CommitFee is the amount calculated to be paid in fees for the
|
// CommitFee is the amount calculated to be paid in fees for the
|
||||||
// current set of commitment transactions. The fee amount is persisted
|
// current set of commitment transactions. The fee amount is persisted
|
||||||
@ -330,13 +325,13 @@ type OpenChannel struct {
|
|||||||
// channel.
|
// channel.
|
||||||
NumUpdates uint64
|
NumUpdates uint64
|
||||||
|
|
||||||
// TotalSatoshisSent is the total number of satoshis we've sent within
|
// TotalMSatSent is the total number of milli-satoshis we've sent
|
||||||
// this channel.
|
|
||||||
TotalSatoshisSent uint64
|
|
||||||
|
|
||||||
// TotalSatoshisReceived is the total number of satoshis we've received
|
|
||||||
// within this channel.
|
// within this channel.
|
||||||
TotalSatoshisReceived uint64
|
TotalMSatSent lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// TotalMSatReceived is the total number of milli-satoshis we've
|
||||||
|
// received within this channel.
|
||||||
|
TotalMSatReceived lnwire.MilliSatoshi
|
||||||
|
|
||||||
// Htlcs is the list of active, uncleared HTLCs currently pending
|
// Htlcs is the list of active, uncleared HTLCs currently pending
|
||||||
// within the channel.
|
// within the channel.
|
||||||
@ -523,8 +518,8 @@ type HTLC struct {
|
|||||||
// RHash is the payment hash of the HTLC.
|
// RHash is the payment hash of the HTLC.
|
||||||
RHash [32]byte
|
RHash [32]byte
|
||||||
|
|
||||||
// Amt is the amount of satoshis this HTLC escrows.
|
// Amt is the amount of milli-satoshis this HTLC escrows.
|
||||||
Amt btcutil.Amount
|
Amt lnwire.MilliSatoshi
|
||||||
|
|
||||||
// RefundTimeout is the absolute timeout on the HTLC that the sender
|
// RefundTimeout is the absolute timeout on the HTLC that the sender
|
||||||
// must wait before reclaiming the funds in limbo.
|
// must wait before reclaiming the funds in limbo.
|
||||||
@ -562,11 +557,11 @@ func (h *HTLC) Copy() HTLC {
|
|||||||
type ChannelDelta struct {
|
type ChannelDelta struct {
|
||||||
// LocalBalance is our current balance at this particular update
|
// LocalBalance is our current balance at this particular update
|
||||||
// number.
|
// number.
|
||||||
LocalBalance btcutil.Amount
|
LocalBalance lnwire.MilliSatoshi
|
||||||
|
|
||||||
// RemoteBalanceis the balance of the remote node at this particular
|
// RemoteBalanceis the balance of the remote node at this particular
|
||||||
// update number.
|
// update number.
|
||||||
RemoteBalance btcutil.Amount
|
RemoteBalance lnwire.MilliSatoshi
|
||||||
|
|
||||||
// CommitFee is the fee that has been subtracted from the channel
|
// CommitFee is the fee that has been subtracted from the channel
|
||||||
// initiator's balance at this point in the commitment chain.
|
// initiator's balance at this point in the commitment chain.
|
||||||
@ -927,13 +922,13 @@ type ChannelSnapshot struct {
|
|||||||
ChannelPoint *wire.OutPoint
|
ChannelPoint *wire.OutPoint
|
||||||
|
|
||||||
Capacity btcutil.Amount
|
Capacity btcutil.Amount
|
||||||
LocalBalance btcutil.Amount
|
LocalBalance lnwire.MilliSatoshi
|
||||||
RemoteBalance btcutil.Amount
|
RemoteBalance lnwire.MilliSatoshi
|
||||||
|
|
||||||
NumUpdates uint64
|
NumUpdates uint64
|
||||||
|
|
||||||
TotalSatoshisSent uint64
|
TotalMilliSatoshisSent lnwire.MilliSatoshi
|
||||||
TotalSatoshisReceived uint64
|
TotalMilliSatoshisReceived lnwire.MilliSatoshi
|
||||||
|
|
||||||
Htlcs []HTLC
|
Htlcs []HTLC
|
||||||
}
|
}
|
||||||
@ -946,14 +941,14 @@ func (c *OpenChannel) Snapshot() *ChannelSnapshot {
|
|||||||
defer c.RUnlock()
|
defer c.RUnlock()
|
||||||
|
|
||||||
snapshot := &ChannelSnapshot{
|
snapshot := &ChannelSnapshot{
|
||||||
RemoteIdentity: *c.IdentityPub,
|
RemoteIdentity: *c.IdentityPub,
|
||||||
ChannelPoint: &c.FundingOutpoint,
|
ChannelPoint: &c.FundingOutpoint,
|
||||||
Capacity: c.Capacity,
|
Capacity: c.Capacity,
|
||||||
LocalBalance: c.LocalBalance,
|
LocalBalance: c.LocalBalance,
|
||||||
RemoteBalance: c.RemoteBalance,
|
RemoteBalance: c.RemoteBalance,
|
||||||
NumUpdates: c.NumUpdates,
|
NumUpdates: c.NumUpdates,
|
||||||
TotalSatoshisSent: c.TotalSatoshisSent,
|
TotalMilliSatoshisSent: c.TotalMSatSent,
|
||||||
TotalSatoshisReceived: c.TotalSatoshisReceived,
|
TotalMilliSatoshisReceived: c.TotalMSatReceived,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy over the current set of HTLCs to ensure the caller can't
|
// Copy over the current set of HTLCs to ensure the caller can't
|
||||||
@ -1308,11 +1303,11 @@ func fetchChanCapacity(openChanBucket *bolt.Bucket, channel *OpenChannel) error
|
|||||||
|
|
||||||
copy(keyPrefix[:3], selfBalancePrefix)
|
copy(keyPrefix[:3], selfBalancePrefix)
|
||||||
selfBalanceBytes := openChanBucket.Get(keyPrefix)
|
selfBalanceBytes := openChanBucket.Get(keyPrefix)
|
||||||
channel.LocalBalance = btcutil.Amount(byteOrder.Uint64(selfBalanceBytes))
|
channel.LocalBalance = lnwire.MilliSatoshi(byteOrder.Uint64(selfBalanceBytes))
|
||||||
|
|
||||||
copy(keyPrefix[:3], theirBalancePrefix)
|
copy(keyPrefix[:3], theirBalancePrefix)
|
||||||
theirBalanceBytes := openChanBucket.Get(keyPrefix)
|
theirBalanceBytes := openChanBucket.Get(keyPrefix)
|
||||||
channel.RemoteBalance = btcutil.Amount(byteOrder.Uint64(theirBalanceBytes))
|
channel.RemoteBalance = lnwire.MilliSatoshi(byteOrder.Uint64(theirBalanceBytes))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -1408,13 +1403,13 @@ func putChanAmountsTransferred(openChanBucket *bolt.Bucket, channel *OpenChannel
|
|||||||
copy(keyPrefix[3:], b.Bytes())
|
copy(keyPrefix[3:], b.Bytes())
|
||||||
|
|
||||||
copy(keyPrefix[:3], satSentPrefix)
|
copy(keyPrefix[:3], satSentPrefix)
|
||||||
byteOrder.PutUint64(scratch1, channel.TotalSatoshisSent)
|
byteOrder.PutUint64(scratch1, uint64(channel.TotalMSatSent))
|
||||||
if err := openChanBucket.Put(keyPrefix, scratch1); err != nil {
|
if err := openChanBucket.Put(keyPrefix, scratch1); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(keyPrefix[:3], satReceivedPrefix)
|
copy(keyPrefix[:3], satReceivedPrefix)
|
||||||
byteOrder.PutUint64(scratch2, channel.TotalSatoshisReceived)
|
byteOrder.PutUint64(scratch2, uint64(channel.TotalMSatReceived))
|
||||||
return openChanBucket.Put(keyPrefix, scratch2)
|
return openChanBucket.Put(keyPrefix, scratch2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1442,11 +1437,11 @@ func fetchChanAmountsTransferred(openChanBucket *bolt.Bucket, channel *OpenChann
|
|||||||
|
|
||||||
copy(keyPrefix[:3], satSentPrefix)
|
copy(keyPrefix[:3], satSentPrefix)
|
||||||
totalSentBytes := openChanBucket.Get(keyPrefix)
|
totalSentBytes := openChanBucket.Get(keyPrefix)
|
||||||
channel.TotalSatoshisSent = byteOrder.Uint64(totalSentBytes)
|
channel.TotalMSatSent = lnwire.MilliSatoshi(byteOrder.Uint64(totalSentBytes))
|
||||||
|
|
||||||
copy(keyPrefix[:3], satReceivedPrefix)
|
copy(keyPrefix[:3], satReceivedPrefix)
|
||||||
totalReceivedBytes := openChanBucket.Get(keyPrefix)
|
totalReceivedBytes := openChanBucket.Get(keyPrefix)
|
||||||
channel.TotalSatoshisReceived = byteOrder.Uint64(totalReceivedBytes)
|
channel.TotalMSatReceived = lnwire.MilliSatoshi(byteOrder.Uint64(totalReceivedBytes))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -2208,11 +2203,11 @@ func deserializeChannelDelta(r io.Reader) (*ChannelDelta, error) {
|
|||||||
if _, err := r.Read(scratch[:]); err != nil {
|
if _, err := r.Read(scratch[:]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
delta.LocalBalance = btcutil.Amount(byteOrder.Uint64(scratch[:]))
|
delta.LocalBalance = lnwire.MilliSatoshi(byteOrder.Uint64(scratch[:]))
|
||||||
if _, err := r.Read(scratch[:]); err != nil {
|
if _, err := r.Read(scratch[:]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
delta.RemoteBalance = btcutil.Amount(byteOrder.Uint64(scratch[:]))
|
delta.RemoteBalance = lnwire.MilliSatoshi(byteOrder.Uint64(scratch[:]))
|
||||||
|
|
||||||
if _, err := r.Read(scratch[:]); err != nil {
|
if _, err := r.Read(scratch[:]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -131,9 +131,9 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
|||||||
localCfg := ChannelConfig{
|
localCfg := ChannelConfig{
|
||||||
ChannelConstraints: ChannelConstraints{
|
ChannelConstraints: ChannelConstraints{
|
||||||
DustLimit: btcutil.Amount(rand.Int63()),
|
DustLimit: btcutil.Amount(rand.Int63()),
|
||||||
MaxPendingAmount: btcutil.Amount(rand.Int63()),
|
MaxPendingAmount: lnwire.MilliSatoshi(rand.Int63()),
|
||||||
ChanReserve: btcutil.Amount(rand.Int63()),
|
ChanReserve: btcutil.Amount(rand.Int63()),
|
||||||
MinHTLC: btcutil.Amount(rand.Int63()),
|
MinHTLC: lnwire.MilliSatoshi(rand.Int63()),
|
||||||
MaxAcceptedHtlcs: uint16(rand.Int31()),
|
MaxAcceptedHtlcs: uint16(rand.Int31()),
|
||||||
},
|
},
|
||||||
CsvDelay: uint16(rand.Int31()),
|
CsvDelay: uint16(rand.Int31()),
|
||||||
@ -145,9 +145,9 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
|||||||
remoteCfg := ChannelConfig{
|
remoteCfg := ChannelConfig{
|
||||||
ChannelConstraints: ChannelConstraints{
|
ChannelConstraints: ChannelConstraints{
|
||||||
DustLimit: btcutil.Amount(rand.Int63()),
|
DustLimit: btcutil.Amount(rand.Int63()),
|
||||||
MaxPendingAmount: btcutil.Amount(rand.Int63()),
|
MaxPendingAmount: lnwire.MilliSatoshi(rand.Int63()),
|
||||||
ChanReserve: btcutil.Amount(rand.Int63()),
|
ChanReserve: btcutil.Amount(rand.Int63()),
|
||||||
MinHTLC: btcutil.Amount(rand.Int63()),
|
MinHTLC: lnwire.MilliSatoshi(rand.Int63()),
|
||||||
MaxAcceptedHtlcs: uint16(rand.Int31()),
|
MaxAcceptedHtlcs: uint16(rand.Int31()),
|
||||||
},
|
},
|
||||||
CsvDelay: uint16(rand.Int31()),
|
CsvDelay: uint16(rand.Int31()),
|
||||||
@ -172,8 +172,8 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
|||||||
CommitFee: btcutil.Amount(rand.Int63()),
|
CommitFee: btcutil.Amount(rand.Int63()),
|
||||||
FeePerKw: btcutil.Amount(5000),
|
FeePerKw: btcutil.Amount(5000),
|
||||||
Capacity: btcutil.Amount(10000),
|
Capacity: btcutil.Amount(10000),
|
||||||
LocalBalance: btcutil.Amount(3000),
|
LocalBalance: lnwire.MilliSatoshi(3000),
|
||||||
RemoteBalance: btcutil.Amount(9000),
|
RemoteBalance: lnwire.MilliSatoshi(9000),
|
||||||
CommitTx: *testTx,
|
CommitTx: *testTx,
|
||||||
CommitSig: bytes.Repeat([]byte{1}, 71),
|
CommitSig: bytes.Repeat([]byte{1}, 71),
|
||||||
NumConfsRequired: 4,
|
NumConfsRequired: 4,
|
||||||
@ -182,9 +182,9 @@ func createTestChannelState(cdb *DB) (*OpenChannel, error) {
|
|||||||
RevocationProducer: producer,
|
RevocationProducer: producer,
|
||||||
RevocationStore: store,
|
RevocationStore: store,
|
||||||
NumUpdates: 0,
|
NumUpdates: 0,
|
||||||
TotalSatoshisSent: 8,
|
TotalMSatSent: 8,
|
||||||
TotalSatoshisReceived: 2,
|
TotalMSatReceived: 2,
|
||||||
Db: cdb,
|
Db: cdb,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +339,7 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
// Half of the HTLCs are incoming, while the other half are outgoing.
|
// Half of the HTLCs are incoming, while the other half are outgoing.
|
||||||
var (
|
var (
|
||||||
htlcs []*HTLC
|
htlcs []*HTLC
|
||||||
htlcAmt btcutil.Amount
|
htlcAmt lnwire.MilliSatoshi
|
||||||
)
|
)
|
||||||
for i := uint32(0); i < 10; i++ {
|
for i := uint32(0); i < 10; i++ {
|
||||||
var incoming bool
|
var incoming bool
|
||||||
@ -368,8 +368,8 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
newTx := channel.CommitTx.Copy()
|
newTx := channel.CommitTx.Copy()
|
||||||
newTx.TxIn[0].Sequence = newSequence
|
newTx.TxIn[0].Sequence = newSequence
|
||||||
delta := &ChannelDelta{
|
delta := &ChannelDelta{
|
||||||
LocalBalance: btcutil.Amount(1e8),
|
LocalBalance: lnwire.MilliSatoshi(1e8),
|
||||||
RemoteBalance: btcutil.Amount(1e8),
|
RemoteBalance: lnwire.MilliSatoshi(1e8),
|
||||||
Htlcs: htlcs,
|
Htlcs: htlcs,
|
||||||
UpdateNum: 1,
|
UpdateNum: 1,
|
||||||
}
|
}
|
||||||
@ -684,8 +684,8 @@ func TestFetchClosedChannels(t *testing.T) {
|
|||||||
ClosingTXID: rev,
|
ClosingTXID: rev,
|
||||||
RemotePub: state.IdentityPub,
|
RemotePub: state.IdentityPub,
|
||||||
Capacity: state.Capacity,
|
Capacity: state.Capacity,
|
||||||
SettledBalance: state.LocalBalance,
|
SettledBalance: state.LocalBalance.ToSatoshis(),
|
||||||
TimeLockedBalance: state.LocalBalance + 10000,
|
TimeLockedBalance: state.LocalBalance.ToSatoshis() + 10000,
|
||||||
CloseType: ForceClose,
|
CloseType: ForceClose,
|
||||||
IsPending: true,
|
IsPending: true,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user