Suggesting an additional sync option "--balance"

From my experiments when running a first time sync on an empty spynode folder such as for adding a new shareholder wallet, I determined I need to have a sync --balance option (without nostop) which quits as soon as it does the processing indicated by these 4 lines from the debugging messages:
Make Exploratory Auto stop sync:
until it finds "Contract address : " in the log:
2020/08/08 17:27:21.374203 [Main] wallet.go:155 Info - Loaded unspent output 0.00004317 : 48f8a5d81d0cb386abdf8d6d50b01332179e867b05288d44de66aeae88f72a8e:0
2020/08/08 17:27:21.377027 [Main] wallet.go:155 Info - Loaded unspent output 0.00077717 : 996248da1e381de87e8303eae3ee6818848f3513a97bdccb06bf7caae01c3d61:2
2020/08/08 17:27:21.377095 [Main] wallet.go:161 Info - Loaded wallet with 9 outputs, 2 unspent, and balance of 0.00082034
2020/08/08 17:27:21.377156 [Main] wallet.go:164 Info - Wallet address : 16GgqN2sWSTZAZobNkR6uLVUUmD8LnnSPM
2020/08/08 17:27:21.377194 [Main] node.go:114 Info - Contract address : 1QAinrbEfjv46jdpwZcqc1nB4tWH9AE8in

sync --balance (without --nostop) needs to stop here because otherwise it drags on for hours because no peers have been found yet.
NOTE (GOTCHA): peers can only be found by using the --nostop option.

So next we have to run sync --nostop because now the wallet balance info has been discovered and saved by tokenized into the contract state and that wallet balance determination can only happen on a regular sync (without --nostop) ONLY on a first time run of sync on an empty spynode folder.

Finally we can run the regular sync (without any option flags) and it will terminate quickly (in less than 2 minutes typically) because now there are peers found to satisfy necessary queries.

The regular sync will process all confirmed transactions that effect bitcoin balance, since it stops after processing blocks, but does not keep running to process the mempool. It also doesn’t find peers because spynode only talks to other peers after it is in sync with the dedicated node.

If you want to process unconfirmed transactions just run sync --nostop for like 10 seconds and then stop it with CTRL-C.

If I get a chance I will upgrade the standard sync to stay alive for a while to process the mempool. It is just less discrete because it is difficult to determine when your mempool is in sync.

No that is not the behavior I am observing.
plain sync does NOT stop in the case of no peers - it gets hung up if there are no peers, such as when on a fresh empty spynode folder for a new client wallet.
But before it hangs up it correctly finds the balance and records it.
From what you told me before it is essential that the balance be found and recorded on the very first sync run on an empty folder.
So it does do that and then hangs for me.
So I made a workaround Bash script #1 to watch for the log message that says it found the Balance
and then my special scripts kills the sync process.
THEN the next step is I run sync --nostop to find peers for a few hours in a special Bash script that looks for some messages I found by experiments that indicate it is done enough and so my Bash script kills it. So I created a Bash script #2 that does sort of “sync --nostop that autostops”.
THEN I do one more run of plain sync and it automatically stops after a few minutes and all is good.

I just don’t understand what is happening. Maybe there is an issue with the script you have on top. Plain “sync” should not even look for peers. It just talks to the trusted node until it stops getting headers and has processed all the blocks after the start hash. Ensure you are on the latest software. I will hopefully be releasing a new version with some stability improvements soon.