Understanding the mechanics and day-to-day implication of Proof-of-Stake

Wrong. For the purpose of PoS minting, coin age is an integer number of coin days. It is true that the time is measured in seconds, but after multiplication by the coin value, the coin age is rounded to an integer.

[tt]CBigNum bnCoinDayWeight = CBigNum(nValueIn) * nTimeWeight / COIN / (24 * 60 * 60);[/tt]

Currently this is indeed the only available approach, since there are no other detailed descriptions of how PPC works. However I’m not happy with that situation. Reading the code is difficult and time consuming. Many people who are interested in PPC simply do not have this ability. I’m glad to see initiatives by Ben and masterOfDisaster to build a better understanding of the mechanisms behind PPC, but I think we still have a long way to go.

Q: Today, you need to manually turn on Proof-of-Stake minting via ppcoin.conf and setting ppcoin-qt into server=1. Assuming I shut down my computer, but didn’t remember to rerun my ‘start.sh’ bash script that I added, does the ppcoin-qt client still age coins? I imagine that if the wallet isn’t unlocked for minting, that I wouldn’t be able to solve blocks, but I don’t see a (logical) reason that coins wouldn’t age – whether or not I’m ready to mint.

Is this a correct assumption, as the Peercoin client stands, today?

Yes, aging of coins continues as long as you don’t transfer them, whether or not your software is running.
PoS minting only happens while your ppcoin software is running. I’m not sure what you mean by unlocked.

Note that this means you lose minting opportunities whenever your software is not running. It is a little bit like having a nice PoW mining gear but not turning it on, especially if you have coins at maximum age in your wallet. The average PoS return of 1% per year assumes that you run the ppcoin software all the time.

This is what I mean about being “unlocked for minting”:

It’s when your wallet is configured so that it is encrypted, but unlocked for block minting, only. Right now that’s a manual process, and if you don’t take the steps to set it up and run it separately, after you’ve started ppcoin-qt, you won’t be able to utilize PoS. I believe this only affects wallets have been encrypted (which everyone should be doing)

Currently it says “Unlocked for minting only” but in fact it’s not locked at all then. Just try sending a coin, you will not be prompted for the password. This is a really big issue which I hope will be fixed in the upcoming merge with bitcoin 0.8

I also hope to get a GUI-way to unlock the wallet for PoS minting. Because those two are PPC´s biggest technical problems.

You are right. I just tried it and was not prompted for my password.

That’s a good catch, and something everyone should be aware about. Thanks for the heads, up, MUTO.

Wrong. For the purpose of PoS minting, coin age is an integer number of coin days. It is true that the time is measured in seconds, but after multiplication by the coin value, the coin age is rounded to an integer.

[tt]CBigNum bnCoinDayWeight = CBigNum(nValueIn) * nTimeWeight / COIN / (24 * 60 * 60);[/tt][/quote]

Thanks for your input.

BTW, I am wondering how the 1% is kept. It is obviously many randomness, including such a roundness, involved in PoS minting, so is the 1% “interest” kept from the point view of theoretical statistical expectation, or is there any drift in this system? Any code segment related to this 1% and any interpretation?

Thanks.

[quote=“Ben, post:26, topic:849”]You are right. I just tried it and was not prompted for my password.

That’s a good catch, and something everyone should be aware about. Thanks for the heads, up, MUTO.[/quote]

How did you unlock your wallet for minting?
If you did it by

ppcoind walletpassphrase $passphrase $timeInSeconds true

your wallet should only have been unlocked for minting (by using the optinal parameter “true”).
Can you confirm that it is possible to send Peercoins even if the wallet is unlocked with the code mentioned above?

That would be bad, because in the file ppcoin-0.3.0-linux/src/src/bitcoinrpc.cpp there is code which I read as unlocking the wallet only for stake minting:

Value walletpassphrase(const Array& params, bool fHelp)
{
    if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 3))
        throw runtime_error(
            "walletpassphrase <passphrase> <timeout> [mintonly]\n"
            "Stores the wallet decryption key in memory for <timeout> seconds.\n"
            "mintonly is optional true/false allowing only block minting.");

Unfortunately I’m no coder and that’s why I only tried to sum up what I understand about Peercoin so far without having read that from the code.
I’d be glad if someone with appropriate skills could dig though the code to answer some of the questions or prove some of the assumptions in this thread.
It might be crucial for the success of Peercoin (especially PoS, because that’s the innovation of Peercoin!) to understand how it works - not only on a “management level” but on a “technical level” as well; if you know what I mean.
I have little time these days, but this needs follow-up!

The 1% is indeed the average amount that you can expect if you have many coins and never transfer them.
If you transfer coins, you lose coin age and end up with less than 1%.
If you have only a small amount of coins, you can still expect 1% on average but the variance will be significant because it takes a long time to find a PoS block.

“Show me the code”, I hear you say. Excellent, let’s do that!
(I must warn, though, that there is a certain risk involved in drawing conclusions from a few code snippets here and there. Every line of code in the software can potentially put this snippet in a completely different context.)

[tt]int64 GetProofOfStakeReward(int64 nCoinAge) {
static int64 nRewardCoinYear = CENT; // creation amount per coin-year
int64 nSubsidy = nCoinAge * 33 / ( 365 * 33 + 8 ) * nRewardCoinYear;
return nSubsidy;
}[/tt]

This function computes the reward for finding a PoS block. As you can see, it gives one cent in return for every 365 coin days you put into the stake transaction. For example, if you have owned 100 PPC for exactly one year and find a PoS block, your reward is (36500 coin days / 365.24 * 0.01 PPC) = 1 PPC.
Note that in this computation, the coin age is NOT limited to 90 days. Every coin counts for exactly the number of days you owned it (30 days minimum).
Note also that the PoS reward is rounded down to an integer number of cents.

Using the [font=courier]GetProofOfStakeReward [/font] calculation below, I put together a simple spreadsheet to show what your expected payout is for a given incoming (credit) transaction.

You can play with the “Transaction Amount” field and it will update the Coin Age and PPC Reward fields below.

Assumptions:

[ul][li]Coin Age is accumulated between d1 and d29, but no reward is possible because Proof-of-Stake minting hasn’t started yet[/li]
[li]Between d30 and d90, the transaction’s coin age is increased, and the potential reward if the a Proof-of-Stake block is increased based on the [font=courier]GetProofOfStakeReward[/font] calculation[/li]
[li]After d90, the coin age for the transaction is frozen, and while Proof-of-Stake validation continues until the block is solved, the reward does not get any bigger[/li][/ul]

Could the community please review this model to make sure that I’m representing it accurately? Thanks!

https://db.tt/yRJsAbzb
(Dropbox link, because I still can’t attach things to posts, for some reason.)

@Ben

any news regarding the unlock function of the wallet?
I refer to my second last post in this thread: http://www.peercointalk.org/index.php?topic=979.msg8749#msg8749

@MoD:

I’ll test it right now and post the results.

Attempts to send PPC to an address from an encrypted wallet (ppcoin-qt v0.3.0, Mac OS X 10.9):

[ol][li]Encrypted wallet, ppcoind not running, “Minting suspended due to locked wallet”: Passphrase required to send funds[/li]
[li]Encrypted wallet, ppcoind running, “unlocked for block minting only”[1]: No passphrase required to send funds[/li]
[li]Encrypted wallet, ppcoind running, “unlocked for block minting only”[2]: No passphrase required to send funds[/li][/ol]

[1] Unlocked using command line string [font=courier]./ppcoind walletpassphrase 999999 true[/font]
[2] Unlocked using a custom start.sh bash script, run from the command line:

#!/bin/bash
echo "make sure you've started ppcoin-qt first."
read -s -p "Enter ppcoin wallet passphrase  : " passphrase
echo "starting ppcoind with stake mining enabled"
./ppcoind walletpassphrase $passphrase 9999999 true

No bueno.

I tried to narrow down the scope of what could be the problem, so I tested out different configurations of the addresses that I was sending to. It didn’t seem to make a difference if the address was already one that you had sent to (and you included from the ppcoin-qt address book) or if this was a totally new address that you had never sent to before.

I tried the same on Windows 7 64 bit with Peercoin 0.3.0

Scenario 1:
ppcoin-qt.exe running
ppcoind.exe used for minting unlock (ppcoind.exe walletpassphrase true)

Tried to execute a transaction with ppcoind.exe.
Result:
error: {“code”:-4,“message”:“Error: Wallet unlocked for block minting only, unable to create transaction.”}

Tried to execute a transaction with ppcoin-qt.exe (“Wallet is encrypted and currently unlocked for block minting only” says the mouse-over of the lock symbol)
Result:
successfully executed the transaction

WTF?

[size=12pt]It looks like the ppcoin-qt.exe doesn’t handle the unlock properly (at least the MacOS and the Windows version). ppcoind.exe being used for enabling stake minting only unlocks the ppcoin-qt.exe for more than just stake minting.[/size]

Scenario 2:
ppcoin-qt.exe NOT running
ppcoind.exe running as daemon and used for minting unlock (ppcoind.exe walletpassphrase true)

Tried to execute a transaction with ppcoind.exe
Result:
error: {“code”:-4,“message”:“Error: Wallet unlocked for block minting only, unable to create transaction.”}

Tried to create a new address
Result:
Success. This should not work as well with a wallet that is unlocked for stake minting only, but at least I don’t see a security issue here…

[size=12pt]I highly recommend not not have ppcoin-qt.exe running in parallel while ppcoind.exe was used for minting unlock!
If you want to enable stake minting, let solely ppcoind.exe be running.[/size]

Start ppcoind.exe as daemon:

ppcoind.exe -daemon

Open another command prompt to enable stake minting

ppcoind.exe walletpassphrase <passphrase> <timeout> true
$ ./ppcoind -daemon
ppcoin server starting

$ ./ppcoind walletpassphrase <passphrase> 9999999 true
error: couldn't connect to server

$ ./ppcoind -watch
PPCoin: Cannot obtain a lock on data directory /Users/benrossi/Library/Application Support/PPCoin.  PPCoin is probably already running.

I tried it a few ways, but all with the same result. It may be a ppcoin.conf setting issue, so is there anything that I need to set to get the daemon to allow local connections?

I have a “ppcoin.conf” with some config lines:

server=1
rpcuser=GfGegBdWj3Tkzo5Q7Fxn
rpcpassword=4o7z7Ej65lMB3f1qCFdm
rpcallowip=127.0.0.1
rpcallowip=192.168.1.*

where 192.168.1.0/24 is my local subnet.
Give it a try! :wink:

Current rpcallowip configruations:

rpcallowip=127.0.0.1
rpcallowip=192.168.2.*
rpcallowip=10.0.0.*

The second one may be a typo on my part. I’ll make a change to [font=courier]192.168.1.*[/font] and see if that fixes it.

[quote=“Ben, post:36, topic:849”][code]
$ ./ppcoind -daemon
ppcoin server starting

$ ./ppcoind walletpassphrase 9999999 true
error: couldn’t connect to server
[/code][/quote]

In my experience, you cannot send commands to ppcoind until it has established multiple peer node connections and caught up to the block chain a little bit to verify their authenticity.

Even on linux, if I start ppcoind and immediately start throwing commands at it, they won’t work, until a few minutes have passed.

No dice. I started it and waited 20 minutes before trying to connect to the server with [font=courier]./ppcoind walletpassphrase 999999 true[/font], but I’m still getting the “error: couldn’t connect to server”.

I’ll make sure that my ppcoin.conf file is pared down to the bare minimum for troubleshooting.