func (db *DB) addNewDestinationToDB(destination *destination, neighbourPubKey [33]byte, lnClient *lndwrapper.Lnd) {

	//If we are trying to add information about ourselves, skip
	if destination.address == db.getLocalAddress() {
		return
	}

	//Get the routing address of the peer and the block Height so we can add new routing entries to the DB
	peerAddress, _ := db.GetNodeAddress(neighbourPubKey)
	blockHeight := db.getBlockHeight()

	//Build the new routing entry
	newEntry := &routingEntry{destination: destination.address, nextHop: peerAddress,
		capacity: destination.capacity, height: blockHeight}

	//Limit the new enrty capacities to the channel capacity
	localChannels := GetLocalChannels(lnClient)
	neighbourPubKeyString := PubKeyArrayToString(neighbourPubKey)
	for _, localChannel := range localChannels {
		//Found the channel shared with the next hop neighbour
		if localChannel.RemotePubkey == neighbourPubKeyString {
			if localChannel.LocalBalance < newEntry.capacity {
				newEntry.capacity = localChannel.LocalBalance
			}
		}
	}

	//Get the existing routing entry for this destination
	entry := db.getRoutingEntry(destination.address)

	//If there is no entry for this destination we just add a new one
	if entry == nil {
		db.addRoutingEntryToDB(newEntry)
		return
	}

	//If the destination shared with us by the neighbour has a worse capacity than the one we already have we do nothing
	if newEntry.capacity < entry.capacity {
		log.Println("Didn't update destination's next hop shared by", peerAddress)
		log.Println("Shared: Destination:", newEntry.destination, "Capacity:", newEntry.capacity)
		log.Println("Got: Destination:", entry.destination, "Capacity:", entry.capacity)
		return
	}

	//Add the new ypdated routing entry, it will replace the old one
	db.addRoutingEntryToDB(newEntry)
}
//Adds a new destination (shared by a peer) to the DB if it's better than the entry we have stored
Adds a new destination (shared by a peer) to the DB if it's better than the entry we have stored
// Adds a new destination ( shared by a peer ) to the DB if it ' s better than the entry we have stored
func (db *DB) addNewDestinationToDB(destination *destination, neighbourPubKey [33]byte, lnClient *lndwrapper.Lnd) {
	if destination.address == db.getLocalAddress() {
		return
	}
	peerAddress, _ := db.GetNodeAddress(neighbourPubKey)
	blockHeight := db.getBlockHeight()
	newEntry := &routingEntry{destination: destination.address, nextHop: peerAddress,
		capacity: destination.capacity, height: blockHeight}
	localChannels := GetLocalChannels(lnClient)
	neighbourPubKeyString := PubKeyArrayToString(neighbourPubKey)
	for _, localChannel := range localChannels {
		if localChannel.RemotePubkey == neighbourPubKeyString {
			if localChannel.LocalBalance < newEntry.capacity {
				newEntry.capacity = localChannel.LocalBalance
			}
		}
	}
	entry := db.getRoutingEntry(destination.address)
	if entry == nil {
		db.addRoutingEntryToDB(newEntry)
		return
	}
	if newEntry.capacity < entry.capacity {
		log.Println("Didn't update destination's next hop shared by", peerAddress)
		log.Println("Shared: Destination:", newEntry.destination, "Capacity:", newEntry.capacity)
		log.Println("Got: Destination:", entry.destination, "Capacity:", entry.capacity)
		return
	}
	db.addRoutingEntryToDB(newEntry)
}
func ( db * DB ) addNewDestinationToDB ( destination * destination , neighbourPubKey [ 33 ] byte , lnClient * lndwrapper . Lnd ) { if destination . address == db . getLocalAddress ( ) { return } peerAddress , _ := db . GetNodeAddress ( neighbourPubKey ) blockHeight := db . getBlockHeight ( ) newEntry := & routingEntry { destination : destination . address , nextHop : peerAddress , capacity : destination . capacity , height : blockHeight } localChannels := GetLocalChannels ( lnClient ) neighbourPubKeyString := PubKeyArrayToString ( neighbourPubKey ) for _ , localChannel := range localChannels { if localChannel . RemotePubkey == neighbourPubKeyString { if localChannel . LocalBalance < newEntry . capacity { newEntry . capacity = localChannel . LocalBalance } } } entry := db . getRoutingEntry ( destination . address ) if entry == nil { db . addRoutingEntryToDB ( newEntry ) return } if newEntry . capacity < entry . capacity { log . Println ( " " , peerAddress ) log . Println ( " " , newEntry . destination , " " , newEntry . capacity ) log . Println ( " " , entry . destination , " " , entry . capacity ) return } db . addRoutingEntryToDB ( newEntry ) }
Adds a new destination (shared by a peer) to the DB if it's better than the entry we have stored
Adds a new destination ( shared by a peer ) to the DB if it ' s better than the entry we have stored
//If we are trying to add information about ourselves, skip //Get the routing address of the peer and the block Height so we can add new routing entries to the DB //Build the new routing entry //Limit the new enrty capacities to the channel capacity //Found the channel shared with the next hop neighbour //Get the existing routing entry for this destination //If there is no entry for this destination we just add a new one //If the destination shared with us by the neighbour has a worse capacity than the one we already have we do nothing //Add the new ypdated routing entry, it will replace the old one