func (db *DB) SynchronizeRoutingDB(bitcoinCLient *bitcoindwrapper.Bitcoind, lnClient *lndwrapper.Lnd) {

	var registered bool
	var neighbourPubKey [33]byte
	var neighbourAddress [4]byte
	var localChannels []*lnrpc.Channel

	for {

		//Get the local channels
		localChannels = GetLocalChannels(lnClient)

		//Get all the routing entries
		routingEntries := db.routingEntriesStack.peekFromBlock(genesisBlock)

		//Iterate thourgh all the active channels of this node
		//Add routing entries for neighbours that are registered in the protocol
		for _, localChannel := range localChannels {

			neighbourPubKey = PubKeyStringToArray(localChannel.RemotePubkey)
			neighbourAddress, registered = db.GetNodeAddress(neighbourPubKey)

			//IF the channel is not registered we an skip it
			if !registered {
				continue
			}

			//Update routing entries whose next hop is the other end of this channel
			for n, routingEntry := range routingEntries {
				if routingEntry.nextHop == neighbourAddress && routingEntry.capacity > localChannel.LocalBalance {
					fmt.Println("Updated Entry #:", n)
					fmt.Println("Destination:", net.IP(routingEntry.destination[:]).String())
					fmt.Println("Next Hop:", net.IP(routingEntry.nextHop[:]).String())
					fmt.Println("Old Capacity:", routingEntry.capacity)
					fmt.Println("New Capacity:", localChannel.LocalBalance)
					routingEntry.capacity = localChannel.LocalBalance
				}
			}

			//Add destination to DB
			db.addNewDestinationToDB(&destination{address: neighbourAddress, capacity: localChannel.LocalBalance}, neighbourPubKey, lnClient)
		}

		//Update routing DB every minute
		time.Sleep(time.Minute)
	}
}
//SynchronizeRoutingDB updates the routing DB according to changes in the local channel balances
SynchronizeRoutingDB updates the routing DB according to changes in the local channel balances
// SynchronizeRoutingDB updates the routing DB according to changes in the local channel balances
func (db *DB) SynchronizeRoutingDB(bitcoinCLient *bitcoindwrapper.Bitcoind, lnClient *lndwrapper.Lnd) {
	var registered bool
	var neighbourPubKey [33]byte
	var neighbourAddress [4]byte
	var localChannels []*lnrpc.Channel
	for {
		localChannels = GetLocalChannels(lnClient)
		routingEntries := db.routingEntriesStack.peekFromBlock(genesisBlock)
		for _, localChannel := range localChannels {
			neighbourPubKey = PubKeyStringToArray(localChannel.RemotePubkey)
			neighbourAddress, registered = db.GetNodeAddress(neighbourPubKey)
			if !registered {
				continue
			}
			for n, routingEntry := range routingEntries {
				if routingEntry.nextHop == neighbourAddress && routingEntry.capacity > localChannel.LocalBalance {
					fmt.Println("Updated Entry #:", n)
					fmt.Println("Destination:", net.IP(routingEntry.destination[:]).String())
					fmt.Println("Next Hop:", net.IP(routingEntry.nextHop[:]).String())
					fmt.Println("Old Capacity:", routingEntry.capacity)
					fmt.Println("New Capacity:", localChannel.LocalBalance)
					routingEntry.capacity = localChannel.LocalBalance
				}
			}
			db.addNewDestinationToDB(&destination{address: neighbourAddress, capacity: localChannel.LocalBalance}, neighbourPubKey, lnClient)
		}
		time.Sleep(time.Minute)
	}
}
func ( db * DB ) SynchronizeRoutingDB ( bitcoinCLient * bitcoindwrapper . Bitcoind , lnClient * lndwrapper . Lnd ) { var registered bool var neighbourPubKey [ 33 ] byte var neighbourAddress [ 4 ] byte var localChannels [ ] * lnrpc . Channel for { localChannels = GetLocalChannels ( lnClient ) routingEntries := db . routingEntriesStack . peekFromBlock ( genesisBlock ) for _ , localChannel := range localChannels { neighbourPubKey = PubKeyStringToArray ( localChannel . RemotePubkey ) neighbourAddress , registered = db . GetNodeAddress ( neighbourPubKey ) if ! registered { continue } for n , routingEntry := range routingEntries { if routingEntry . nextHop == neighbourAddress && routingEntry . capacity > localChannel . LocalBalance { fmt . Println ( " " , n ) fmt . Println ( " " , net . IP ( routingEntry . destination [ : ] ) . String ( ) ) fmt . Println ( " " , net . IP ( routingEntry . nextHop [ : ] ) . String ( ) ) fmt . Println ( " " , routingEntry . capacity ) fmt . Println ( " " , localChannel . LocalBalance ) routingEntry . capacity = localChannel . LocalBalance } } db . addNewDestinationToDB ( & destination { address : neighbourAddress , capacity : localChannel . LocalBalance } , neighbourPubKey , lnClient ) } time . Sleep ( time . Minute ) } }
SynchronizeRoutingDB updates the routing DB according to changes in the local channel balances
SynchronizeRoutingDB updates the routing DB according to changes in the local channel balances
//Get the local channels //Get all the routing entries //Iterate thourgh all the active channels of this node //Add routing entries for neighbours that are registered in the protocol //IF the channel is not registered we an skip it //Update routing entries whose next hop is the other end of this channel //Add destination to DB //Update routing DB every minute