Skip to content

Commit

Permalink
update btcAssetId=0
Browse files Browse the repository at this point in the history
  • Loading branch information
wxf4150 committed Dec 7, 2022
1 parent 172f047 commit 1c037c4
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 51 deletions.
4 changes: 2 additions & 2 deletions channeldb/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1764,9 +1764,9 @@ func (c *OpenChannel) ActiveHtlcs() []HTLC {
return activeHtlcs
}
func(h *HTLC) GetAmt(assetId uint32) lnwire.UnitPrec11{
if assetId>1{
if assetId > lnwire.BtcAssetId {
return lnwire.UnitPrec11(h.AssetAmt)
}else{
} else {
return lnwire.UnitPrec11(h.BtcAmt)
}
}
Expand Down
6 changes: 3 additions & 3 deletions funding/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
"pendingId=%x) from peer(%x)", btcAmt, msg.PushBtcAmount,
msg.CsvDelay, msg.PendingChannelID,
peer.IdentityKey().SerializeCompressed())
if msg.AssetId > 0 {
if msg.AssetId > lnwire.BtcAssetId {
log.Infof("Recv'd fundingRequest(asset_id=%v asset_amt=%v, AssetPush=%v)",
msg.AssetId, assetAmt, msg.PushAssetAmount)
}
Expand Down Expand Up @@ -1468,7 +1468,7 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
"amt=%v, push_amt=%v, committype=%v, upfrontShutdown=%x", numConfsReq,
msg.PendingChannelID, btcAmt, msg.PushBtcAmount,
commitType, msg.UpfrontShutdownScript)
if msg.AssetId > 0 {
if msg.AssetId > lnwire.BtcAssetId {
log.Infof("Requiring pendingChan(%x) Asset: "+
"amt=%v, push_amt=%v", msg.PendingChannelID, assetAmt, msg.PushAssetAmount)
}
Expand Down Expand Up @@ -3341,7 +3341,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
"(subtract_fees=%v), push_amt=%v, chain_hash=%v, peer=%x, "+
"min_confs=%v)", localBtcAmt, msg.SubtractFees, msg.PushBtcAmt,
msg.ChainHash, peerKey.SerializeCompressed(), msg.MinConfs)
if assetId > 0 {
if assetId > lnwire.BtcAssetId {
log.Infof("Initiating fundingRequest(asset_id=%v local_asset_amt=%v push_asset_amt=%v)",
assetId, localAssetAmt, msg.PushAssetAmt)
}
Expand Down
4 changes: 2 additions & 2 deletions funding/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,8 @@ func TestFundingManagerNormalWorkflow(t *testing.T) {
// Make sure both fundingManagers send the expected channel
// announcements.
cap:=lnwire.UnitPrec8(capacity)
if assetId>1{
cap=lnwire.UnitPrec8(localAssetAmt)
if assetId > lnwire.BtcAssetId {
cap = lnwire.UnitPrec8(localAssetAmt)
}
assertChannelAnnouncements(t,assetId, alice, bob, cap, nil, nil)

Expand Down
2 changes: 1 addition & 1 deletion lnwallet/addsettle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func testAddSettleWorkflow(t *testing.T, tweakless bool) {
// commitment height two, with the revocation window extended by 1 (5).
//mSatTransferred := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)
mSatTransferred := lnwire.MilliSatoshi(htlcAmt)
if aliceChannel.channelState.AssetID > 1 {
if aliceChannel.channelState.AssetID > lnwire.BtcAssetId {
mSatTransferred = lnwire.NewMSatFromSatoshis(lnwire.OmniGas * 3)
}
if aliceChannel.channelState.TotalMSatSent != mSatTransferred {
Expand Down
3 changes: 2 additions & 1 deletion lnwallet/btcwallet/btcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
"github.com/lightningnetwork/lnd/lnwallet/omnicore/op"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/omnicore"
"math"
"strings"
Expand Down Expand Up @@ -991,7 +992,7 @@ func (b *BtcWallet) CreateSimpleTxForSelectedCoins(toAddress btcutil.Address, se
}
txout := wire.NewTxOut(int64(amt), payToScirpt)
fundingTx.AddTxOut(txout)
if assetId > 0 {
if assetId > lnwire.BtcAssetId {
pksAmt := op.NewPksAmounts(assetId)
pksAmt.Add(txout.PkScript, assetAmt)
if err := op.AddOpReturnToTx(fundingTx, pksAmt); err != nil {
Expand Down
16 changes: 8 additions & 8 deletions lnwallet/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2914,11 +2914,11 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBtcBalance,
}

/*obd update wxf*/
if lc.channelState.AssetID>1{//asset
cap:=lc.BtcCapacity
cap= cap-btcutil.Amount((len(newView.theirUpdates)+len(newView.theirUpdates)) * int(3*lnwire.OmniGas))
*ourBtcBalance=lnwire.NewMSatFromSatoshis(cap)
*theirBtcBalance=lnwire.NewMSatFromSatoshis(cap)
if lc.channelState.AssetID > lnwire.BtcAssetId { //asset
cap := lc.BtcCapacity
cap = cap - btcutil.Amount((len(newView.theirUpdates)+len(newView.theirUpdates))*int(3*lnwire.OmniGas))
*ourBtcBalance = lnwire.NewMSatFromSatoshis(cap)
*theirBtcBalance = lnwire.NewMSatFromSatoshis(cap)
}
return newView, nil
}
Expand Down Expand Up @@ -5348,10 +5348,10 @@ func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC,
func (lc *LightningChannel) validateAddHtlc(pd *PaymentDescriptor) error {
/*obd update wxf
todo validate asset*/
if pd.AssetID>1{
if pd.AssetID > lnwire.BtcAssetId {
return nil
}
if pd.AssetAmount>0 && pd.AssetID<2{
if pd.AssetAmount > 0 && pd.AssetID == lnwire.BtcAssetId {
return fmt.Errorf("LightningChannel validateAddHtlc err: miss AssetID")
}

Expand Down Expand Up @@ -7157,7 +7157,7 @@ func (lc *LightningChannel) StateSnapshot() *channeldb.ChannelSnapshot {
// and a new commitment is created (which evaluates this fee), then the
// initiator of the channel does not dip below their reserve.
func (lc *LightningChannel) validateFeeRate(feePerKw chainfee.SatPerKWeight) error {
if lc.channelState.AssetID>1{
if lc.channelState.AssetID > lnwire.BtcAssetId {
return nil
}
// We'll ensure that we can accommodate this new fee change, yet still
Expand Down
20 changes: 10 additions & 10 deletions lnwallet/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,17 +595,17 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBtcBalance,
commitFeeMSat := lnwire.NewMSatFromSatoshis(commitFee)

/*obd wxf update assetBalanceUpdate*/
if cb.chanState.AssetID>1{
if cb.chanState.IsInitiator{
theirBtcBalance=0
if theirAssetBalance>0{
theirBtcBalance=lnwire.NewMSatFromSatoshis(lnwire.OmniGas)
if cb.chanState.AssetID > lnwire.BtcAssetId {
if cb.chanState.IsInitiator {
theirBtcBalance = 0
if theirAssetBalance > 0 {
theirBtcBalance = lnwire.NewMSatFromSatoshis(lnwire.OmniGas)
}
ourBtcBalance=lnwire.NewMSatFromSatoshis(cb.chanState.BtcCapacity)
ourBtcBalance-=theirBtcBalance
ourBtcBalance-=commitFeeMSat
ourBtcBalance-=lnwire.NewMSatFromSatoshis(lnwire.OmniGas*3* btcutil.Amount(numHTLCs))
if ourBtcBalance<0{
ourBtcBalance = lnwire.NewMSatFromSatoshis(cb.chanState.BtcCapacity)
ourBtcBalance -= theirBtcBalance
ourBtcBalance -= commitFeeMSat
ourBtcBalance -= lnwire.NewMSatFromSatoshis(lnwire.OmniGas * 3 * btcutil.Amount(numHTLCs))
if ourBtcBalance < 0 {
ourBtcBalance=0
}
}else{
Expand Down
28 changes: 14 additions & 14 deletions lnwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1585,14 +1585,14 @@ func (l *LightningWallet) handleChanPointReady(req *continueContributionMsg) {
remoteBalance := pendingReservation.partialState.LocalCommitment.RemoteBtcBalance.ToSatoshis()

/*obd update wxf*/
if (chanState.AssetID>1){
if chanState.AssetID > lnwire.BtcAssetId {
//asset mode: all the btcBalance belong to Initiator
if chanState.IsInitiator{
remoteBalance=lnwire.OmniGas
localBalance=chanState.BtcCapacity-remoteBalance
}else{
localBalance=lnwire.OmniGas
remoteBalance=chanState.BtcCapacity-localBalance
if chanState.IsInitiator {
remoteBalance = lnwire.OmniGas
localBalance = chanState.BtcCapacity - remoteBalance
} else {
localBalance = lnwire.OmniGas
remoteBalance = chanState.BtcCapacity - localBalance
}
}

Expand Down Expand Up @@ -1986,14 +1986,14 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
remoteBalance := pendingReservation.partialState.LocalCommitment.RemoteBtcBalance.ToSatoshis()

/*obd update wxf*/
if (chanState.AssetID>1){
if chanState.AssetID > lnwire.BtcAssetId {
//asset mode: all the btcBalance belong to Initiator
if chanState.IsInitiator{
remoteBalance=lnwire.OmniGas
localBalance=chanState.BtcCapacity-remoteBalance
}else{
localBalance=lnwire.OmniGas
remoteBalance=chanState.BtcCapacity-localBalance
if chanState.IsInitiator {
remoteBalance = lnwire.OmniGas
localBalance = chanState.BtcCapacity - remoteBalance
} else {
localBalance = lnwire.OmniGas
remoteBalance = chanState.BtcCapacity - localBalance
}
}

Expand Down
6 changes: 3 additions & 3 deletions lnwire/msat.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func (i UnitPrec11) ToSat() btcutil.Amount {
return btcutil.Amount(i/1000)
}

const OmniGas= btcutil.Amount(546)
const BtcAssetId= 1
const AssetMinHtlc= UnitPrec11(10000)
const OmniGas = btcutil.Amount(546)
const BtcAssetId = 0
const AssetMinHtlc = UnitPrec11(10000)
func LoadDefaultMinHtlc(assetId uint32,minHtlc lnwire.MilliSatoshi) UnitPrec11 {
if assetId==BtcAssetId{
return UnitPrec11(minHtlc)
Expand Down
2 changes: 1 addition & 1 deletion record/mpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type MPP struct {
paymentAddr [32]byte

/*obd update wxf
AssetId >0 the unit is lnwire.MilliSatoshi, else omnicore.Amount
AssetId >lnwire.BtcAssetId the unit is lnwire.MilliSatoshi, else omnicore.Amount

This comment has been minimized.

Copy link
@neocarmack

neocarmack Dec 7, 2022

Member

is it correct? AssetId == lnwire.BtcAssetId the unit is lnwire.MilliSatoshi, else omnicore.Amount

*/
// totalMsat is the total value of the payment, potentially spread
// across more than one HTLC.
Expand Down
2 changes: 1 addition & 1 deletion routing/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ type ChannelEdgeUpdate struct {
ChanPoint wire.OutPoint

/*obd update wxf
AssetId >0 the unit is btcutil.Amount, else omnicore.Amount
AssetId >lnwire.BtcAssetId the unit is btcutil.Amount, else omnicore.Amount
*/
// Capacity is the capacity of the newly created channel.
Capacity lnwire.UnitPrec8
Expand Down
7 changes: 4 additions & 3 deletions routing/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type Hop struct {
OutgoingTimeLock uint32

/*obd update wxf
AssetId >0 the unit is lnwire.MilliSatoshi, else omnicore.Amount
AssetId >lnwire.BtcAssetId the unit is lnwire.MilliSatoshi, else omnicore.Amount
*/
// AmtToForward is the amount that this hop will forward to the next
// hop. This value is less than the value that the incoming HTLC
Expand Down Expand Up @@ -291,7 +291,7 @@ type Route struct {
TotalTimeLock uint32

/*obd update wxf
AssetId >0 the unit is lnwire.MilliSatoshi, else omnicore.Amount
AssetId >lnwire.BtcAssetId the unit is lnwire.MilliSatoshi, else omnicore.Amount
*/
// TotalAmount is the total amount of funds required to complete a
// payment over this route. This value includes the cumulative fees at
Expand Down Expand Up @@ -322,8 +322,9 @@ func (r *Route) Copy() *Route {

return &c
}

/*obd update wxf
AssetId >1 the unit is lnwire.MilliSatoshi, else omnicore.Amount
AssetId >lnwire.BtcAssetId the unit is lnwire.MilliSatoshi, else omnicore.Amount
*/
// HopFee returns the fee charged by the route hop indicated by hopIndex.
func (r *Route) HopFee(hopIndex int) lnwire.UnitPrec11 {
Expand Down
4 changes: 2 additions & 2 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,14 +1140,14 @@ func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64,
}
func (r *rpcServer) SendCoinsFrom(ctx context.Context,
in *lnrpc.SendCoinsFromRequest) (*lnrpc.SendCoinsResponse, error) {
if in.AssetId > 0 { //asset transfer
if in.AssetId > lnwire.BtcAssetId { //asset transfer
if in.AssetAmount == 0 {
return nil, fmt.Errorf("asset_amount argument missing")
}
if in.Amount == 0 {
in.Amount = 546

This comment has been minimized.

Copy link
@neocarmack

neocarmack Dec 7, 2022

Member

is it legal? what if there is no satoshi? how can it suddenly be 546?

}
} else if in.AssetId == 0 { //for btc
} else if in.AssetId == lnwire.BtcAssetId { //for btc
if in.Amount == 0 {
return nil, fmt.Errorf("amt argument missing")
}
Expand Down

0 comments on commit 1c037c4

Please sign in to comment.