Skip to content

Commit

Permalink
set usdt-asset use same cfgs(dustlimt/feebase/FeeRate/minhtlc) with btc
Browse files Browse the repository at this point in the history
  • Loading branch information
wxf4150 committed May 12, 2022
1 parent 4eaf33f commit 9697d1a
Show file tree
Hide file tree
Showing 35 changed files with 570 additions and 321 deletions.
20 changes: 12 additions & 8 deletions chainreg/chainregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const (
// DefaultLtcChannelConstraints is the default set of channel constraints that
// are meant to be used when initially funding a Litecoin channel.
var DefaultLtcChannelConstraints = channeldb.ChannelConstraints{
DustLimit: DefaultLitecoinDustLimit,
DustLimit: uint64(DefaultLitecoinDustLimit),
MaxAcceptedHtlcs: input.MaxHTLCNumber / 2,
}

Expand Down Expand Up @@ -240,7 +240,7 @@ func GenDefaultBtcConstraints() channeldb.ChannelConstraints {
dustLimit := lnwallet.DustLimitForSize(input.UnknownWitnessSize)

return channeldb.ChannelConstraints{
DustLimit: dustLimit,
DustLimit: uint64(dustLimit),
MaxAcceptedHtlcs: input.MaxHTLCNumber / 2,
}
}
Expand All @@ -264,9 +264,11 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
switch cfg.PrimaryChain() {
case BitcoinChain:
cc.RoutingPolicy = htlcswitch.ForwardingPolicy{
MinHTLCOut: uint64( cfg.Bitcoin.MinHTLCOut),
BaseFee: cfg.Bitcoin.BaseFee,
FeeRate: cfg.Bitcoin.FeeRate,
Cfg: htlcswitch.ForwardingPolicyCfg{
MinHTLCOut: cfg.Bitcoin.MinHTLCOut,
BaseFee: cfg.Bitcoin.BaseFee,

This comment has been minimized.

Copy link
@neocarmack

neocarmack May 16, 2022

Member

//Ben, Wu: for assets, the basefee is not required.

This comment has been minimized.

Copy link
@neocarmack

neocarmack May 16, 2022

Member

//Ben, We: in config file, asset should has default MinHTLCOut, and a default feerate, which is the same to BTC.

This comment has been minimized.

Copy link
@neocarmack

neocarmack May 16, 2022

Member

//Ben, Wu: typedef MinHTLCOut omniUnit, which is uint64,when asset is BTC, it is msatoshi. Must write functions for numerical comparison, and arithmatic operations.

FeeRate: cfg.Bitcoin.FeeRate,
},
TimeLockDelta: cfg.Bitcoin.TimeLockDelta,
}
cc.MinHtlcIn = cfg.Bitcoin.MinHTLCIn
Expand All @@ -276,9 +278,11 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
)
case LitecoinChain:
cc.RoutingPolicy = htlcswitch.ForwardingPolicy{
MinHTLCOut: uint64(cfg.Litecoin.MinHTLCOut),
BaseFee: cfg.Litecoin.BaseFee,
FeeRate: cfg.Litecoin.FeeRate,
Cfg: htlcswitch.ForwardingPolicyCfg{
MinHTLCOut: cfg.Litecoin.MinHTLCOut,
BaseFee: cfg.Litecoin.BaseFee,
FeeRate: cfg.Litecoin.FeeRate,
},
TimeLockDelta: cfg.Litecoin.TimeLockDelta,
}
cc.MinHtlcIn = cfg.Litecoin.MinHTLCIn
Expand Down
14 changes: 8 additions & 6 deletions chanacceptor/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/lnwire"
)

Expand Down Expand Up @@ -46,18 +45,21 @@ type ChannelAcceptResponse struct {

// Reserve is the amount that require the remote peer hold in reserve
// on the channel.
Reserve btcutil.Amount

This comment has been minimized.

Copy link
@neocarmack

neocarmack May 16, 2022

Member

For example: define OmniAssetUtile.Amount to handle number calculation, when asset is btc, execute milliSatoshi, for other asset, execute uint64。

//Reserve btcutil.Amount
Reserve uint64

// InFlightTotal is the maximum amount that we allow the remote peer to
// hold in outstanding htlcs.
InFlightTotal lnwire.MilliSatoshi
//InFlightTotal lnwire.MilliSatoshi
InFlightTotal uint64

// HtlcLimit is the maximum number of htlcs that we allow the remote
// peer to offer us.
HtlcLimit uint16

// MinHtlcIn is the minimum incoming htlc value allowed on the channel.
MinHtlcIn lnwire.MilliSatoshi
//MinHtlcIn lnwire.MilliSatoshi
MinHtlcIn uint64

// MinAcceptDepth is the minimum depth that the initiator of the
// channel should wait before considering the channel open.
Expand All @@ -71,8 +73,8 @@ type ChannelAcceptResponse struct {
// error.
func NewChannelAcceptResponse(accept bool, acceptErr error,
upfrontShutdown lnwire.DeliveryAddress, csvDelay, htlcLimit,
minDepth uint16, reserve btcutil.Amount, inFlight,

This comment has been minimized.

Copy link
@neocarmack

neocarmack May 16, 2022

Member

replace to OmniUtile, for clear context.

minHtlcIn lnwire.MilliSatoshi) *ChannelAcceptResponse {
minDepth uint16, reserve uint64, inFlight,
minHtlcIn uint64) *ChannelAcceptResponse {

resp := &ChannelAcceptResponse{
UpfrontShutdown: upfrontShutdown,
Expand Down
5 changes: 2 additions & 3 deletions chanacceptor/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"

"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/lnwire"
)

Expand Down Expand Up @@ -48,7 +47,7 @@ func mergeInt64(name string, current, new int64) (int64, error) {
// mergeMillisatoshi merges two msat values, failing if they have different
// non-zero values.
func mergeMillisatoshi(name string, current,
new lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
new uint64) (uint64, error) {

switch {
case current == 0:
Expand Down Expand Up @@ -123,7 +122,7 @@ func mergeResponse(current, new ChannelAcceptResponse) (ChannelAcceptResponse,
if err != nil {
return current, err
}
current.Reserve = btcutil.Amount(reserve)
current.Reserve = uint64(reserve)

current.MinHtlcIn, err = mergeMillisatoshi(
fieldMinIn, current.MinHtlcIn, new.MinHtlcIn,
Expand Down
11 changes: 5 additions & 6 deletions chanacceptor/rpcacceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwallet/chancloser"
Expand Down Expand Up @@ -350,9 +349,9 @@ func (r *RPCAcceptor) sendAcceptRequests(errChan chan error,
uint16(resp.CsvDelay),
uint16(resp.MaxHtlcCount),
uint16(resp.MinAcceptDepth),
btcutil.Amount(resp.ReserveSat),
lnwire.MilliSatoshi(resp.InFlightMaxMsat),
lnwire.MilliSatoshi(resp.MinHtlcIn),
resp.ReserveSat,
resp.InFlightMaxMsat,
resp.MinHtlcIn,
)

// Delete the channel from the acceptRequests map.
Expand All @@ -373,7 +372,7 @@ func (r *RPCAcceptor) sendAcceptRequests(errChan chan error,
// validateAcceptorResponse validates the response we get from the channel
// acceptor, returning a boolean indicating whether to accept the channel, an
// error to send to the peer, and any validation errors that occurred.
func (r *RPCAcceptor) validateAcceptorResponse(dustLimit btcutil.Amount,
func (r *RPCAcceptor) validateAcceptorResponse(dustLimit uint64,
req *lnrpc.ChannelAcceptResponse) (bool, error, lnwire.DeliveryAddress,
error) {

Expand All @@ -393,7 +392,7 @@ func (r *RPCAcceptor) validateAcceptorResponse(dustLimit btcutil.Amount,
// Ensure that the reserve that has been proposed, if it is set, is at
// least the dust limit that was proposed by the remote peer. This is
// required by BOLT 2.
reserveSat := btcutil.Amount(req.ReserveSat)
reserveSat := req.ReserveSat
if reserveSat != 0 && reserveSat < dustLimit {
log.Errorf("Remote reserve: %v sat for channel: %v must be "+
"at least equal to proposed dust limit: %v",
Expand Down
56 changes: 45 additions & 11 deletions channeldb/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,21 @@ func (c ChannelType) HasLeaseExpiration() bool {
return c&LeaseExpirationBit == LeaseExpirationBit
}

// ChannelConstraints represents a set of constraints meant to allow a node to
// limit their exposure, enact flow control and ensure that all HTLCs are
// economically relevant. This struct will be mirrored for both sides of the
// channel, as each side will enforce various constraints that MUST be adhered
// to for the life time of the channel. The parameters for each of these
// constraints are static for the duration of the channel, meaning the channel
// must be torn down for them to change.
type ChannelConstraints struct {
func (ccc *ChannelConstraints)LoadCfg(assetId uint32){

This comment has been minimized.

Copy link
@neocarmack

neocarmack May 16, 2022

Member

//Wu, Ben: MUST not take price into coding, never hardcode any price.

// get usdt value,btc/usdt ~ 30000
ccc.DustLimit=30* uint64(ccc.Cfg.DustLimit)
ccc.ChanReserve=30* uint64(ccc.Cfg.ChanReserve)
if assetId==omnicore.BtcAssetId{
ccc.DustLimit=uint64(ccc.Cfg.DustLimit)
ccc.ChanReserve=uint64(ccc.Cfg.ChanReserve)
}
ccc.MaxPendingAmount=lnwire.MstatCfgToI64(assetId,ccc.Cfg.MaxPendingAmount)
ccc.MinHTLC=lnwire.MstatCfgToI64(assetId,ccc.Cfg.MinHTLC)
}

type ChannelConstraintsCfg struct {

// DustLimit is the threshold (in satoshis) below which any outputs
// should be trimmed. When an output is trimmed, it isn't materialized
// as an actual output, but is instead burned to miner's fees.
Expand All @@ -343,6 +350,33 @@ type ChannelConstraints struct {
// tandem with the dust limit allows a node to regulate the
// smallest HTLC that it deems economically relevant.
MinHTLC lnwire.MilliSatoshi
}
type ChannelConstraints struct {
Cfg ChannelConstraintsCfg

// DustLimit is the threshold (in satoshis) below which any outputs
// should be trimmed. When an output is trimmed, it isn't materialized
// as an actual output, but is instead burned to miner's fees.
DustLimit uint64

// ChanReserve is an absolute reservation on the channel for the
// owner of this set of constraints. This means that the current
// settled balance for this node CANNOT dip below the reservation
// amount. This acts as a defense against costless attacks when
// either side no longer has any skin in the game.
ChanReserve uint64

// MaxPendingAmount is the maximum pending HTLC value that the
// owner of these constraints can offer the remote node at a
// particular time.
MaxPendingAmount uint64

// MinHTLC is the minimum HTLC value that the owner of these
// constraints can offer the remote node. If any HTLCs below this
// amount are offered, then the HTLC will be rejected. This, in
// tandem with the dust limit allows a node to regulate the
// smallest HTLC that it deems economically relevant.
MinHTLC uint64

// MaxAcceptedHtlcs is the maximum number of HTLCs that the owner of
// this set of constraints can offer the remote node. This allows each
Expand Down Expand Up @@ -594,17 +628,17 @@ func (c ChannelStatus) String() string {
return statusStr
}
func (ch *OpenChannel) GetMsgCapForHtlc() uint64{
if ch.AssetID==1{
if ch.AssetID==omnicore.BtcAssetId{
return uint64(ch.BtcCapacity)*1000
}else if ch.AssetID>1 {
return uint64(ch.AssetCapacity)
}
return 0
}
func (ch *OpenChannel) GetMsgCap() uint64{
if ch.AssetID==1{
if ch.AssetID==omnicore.BtcAssetId{
return uint64(ch.BtcCapacity)
}else if ch.AssetID>1{
}else if ch.AssetID>omnicore.BtcAssetId{
return uint64(ch.AssetCapacity)
}
return 0
Expand Down
1 change: 1 addition & 0 deletions channeldb/graph_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type CachedEdgePolicy struct {
func (c *CachedEdgePolicy) ComputeFee(
amt uint64) uint64{

This comment has been minimized.

Copy link
@neocarmack

neocarmack May 16, 2022

Member

//ben, Wu: context



return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
}

Expand Down
6 changes: 4 additions & 2 deletions contractcourt/htlc_incoming_contest_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,11 @@ func (h *htlcIncomingContestResolver) Resolve() (ContractResolver, error) {
HtlcID: h.htlc.HtlcIndex,
}

/*obd update wxf
todo check htlcIncomingContestResolver.Resolver*/
resolution, err := h.Registry.NotifyExitHopHtlc(
h.htlc.RHash, h.htlc.BtcAmt, h.htlcExpiry, currentHeight,
circuitKey, hodlChan, payload,
h.htlc.RHash, h.htlc.GetAmt(h.htlc.AssetId), h.htlcExpiry, currentHeight,
circuitKey, hodlChan, payload, h.htlc.AssetId,
)
if err != nil {
return nil, err
Expand Down
5 changes: 2 additions & 3 deletions contractcourt/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/sweep"
)

Expand All @@ -25,10 +24,10 @@ type Registry interface {
// invoices are never fully settled. The return value describes how the
// htlc should be resolved. If the htlc cannot be resolved immediately,
// the resolution is sent on the passed in hodlChan later.
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi,
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount uint64,
expiry uint32, currentHeight int32,
circuitKey channeldb.CircuitKey, hodlChan chan<- interface{},
payload invoices.Payload) (invoices.HtlcResolution, error)
payload invoices.Payload,assetId uint32) (invoices.HtlcResolution, error)

// HodlUnsubscribeAll unsubscribes from all htlc resolutions.
HodlUnsubscribeAll(subscriber chan<- interface{})
Expand Down
3 changes: 2 additions & 1 deletion discovery/gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnpeer"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/omnicore"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/multimutex"
"github.com/lightningnetwork/lnd/netann"
Expand Down Expand Up @@ -1399,7 +1400,7 @@ func (d *AuthenticatedGossiper) retransmitStaleAnns(now time.Time) error {
// not already present.
edge.MessageFlags |= lnwire.ChanUpdateOptionMaxHtlc
amt:=info.Capacity
if info.AssetId==1{
if info.AssetId==omnicore.BtcAssetId{
amt*=1000
}
edge.MaxHTLC = amt
Expand Down
Loading

0 comments on commit 9697d1a

Please sign in to comment.