Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANV Computation #52

Merged
merged 24 commits into from
Sep 8, 2017
Merged

Conversation

mempko
Copy link
Member

@mempko mempko commented Sep 1, 2017

Prototype PoG mining.
This PR specifically targets prototyping algorithm and getting ANV to work with actual referrals.

  1. We will compute ANV.
  2. Compute distribution per wallet
  3. use latest block hash as random number to sample from distribution.
  4. repeat by hashing block hash and sample wallet id to sample N winners.
  5. compute reward for N winners.

#29

@mempko mempko added the WIP label Sep 1, 2017
@mempko mempko changed the base branch from master to feature/latest-bitcore-indexing September 1, 2017 19:38
This version constructs a discrete distribution using the ANVs of the wallets
and uses Inverse Transform Sampling to sample from the distribution.

A WalletSelected can return N winners by sampling the distribution based
on the input hash. The sampling is deterministic and returns the same winners
given an input hash.

This version samples in memory.
@adilwali
Copy link
Contributor

adilwali commented Sep 2, 2017

This is solid. I like the flow, generally speaking. It all makes sense.

Couple thoughts on my mind, in no specific order:

  • How computationally intensive will it be to get and sort all of the ANVs?
  • When do we expect the sampling to be run, specifically? Will it be when miners begin mining a new block?
  • If a block gets submitted to the network, I presume that all peers will have to validate that the sampling was fair. How will we do this?
    • Is it possible for someone to insert their own wallet as a beneficiary in an illicit way? (So long as it is above the threshold value?)
  • I presume we won't include mempool in the ANV calculator. More likely, we'll probably have a block confirmation (aka, ANV as of 5 blocks ago..)
  • What is the input hash that we are using? Is is the hash of the block minus the coinbase? There is a recursive nature to changing the coinbase transaction, which would subsequently change the hash of the block, so I'm guessing that's not it.
    • Want to make sure we have a clear consensus for how these blocks get approved.

tl;dr is that this is the right direction. All my open questions will be answered as we continue to implement.

Maxim Khailo and others added 13 commits September 5, 2017 06:51
WIP, this commit does not compile
refdb compiles now. Onward to referrals.
Now we have a tree structure in multiple ways. Next is to add a aggregated
ANV tree.
We need to cache ANV so that getting an ANV for a particular
key is O(logn) time. Updates also cost O(logn).
1. Renamed wallet to key.
2. Moved KeyANV to anv.h
3. Created Stub function to get all ANVs.
Added a function to ReferralsViewDB to get all ANVs into memory.
The vector of KeyANVs is used by the selection algorithm to choose N winners.

In the future we should store a heap on disk of KeyANVs and change the selection
algorithm to use the disk instead. Alternatively we can store a heap as an mmap
file and change the selection algorithm to index using pointer arithmatic.
@mempko mempko changed the title ANV Computation and PoG Mining ANV Computation Sep 8, 2017
@adilwali
Copy link
Contributor

adilwali commented Sep 8, 2017

Pairing with Max. This is solid.

Copy link
Contributor

@adilwali adilwali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go.

samples.push_back(sampled);
}

return samples;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my C++ learning, since this method is defined on std::vector<WalletAnv>, if we call it on that vector, will we mutate it to get back the trimmed vector? Or do we get back a new vector? Trying to understand where the return goes.

src/pog/anv.cpp Outdated
* wallet_id specified and aggregating each child's ANV.
*
* This is the naive version that computes whole tree every time. We need an
* accumulated version instead where ANV is cached and gets updated for every
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree on the accumulated version. With that said, I think the naive version is fine for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a crazy thought the other day around actually just computing ANV diffs when blocks get mined. Basically, any txn is an opportunity to crawl up the tree and understand whose ANV went up and whose went down.

In theory, if no new users are added to the network, ANV is a zero sum game.

src/pog/anv.cpp Outdated

auto children = GetReferredIds(wallet_id);
for(const auto& child: children)
wallets.push(child);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thing about this is that this list can be operated against in a flattened way, like you are doing here. Keeps things simple (and impossible to game.)

src/pog/anv.cpp Outdated
namespace pog
{
using wallet_stack = std::stack<uint256>;
using wallet_ids = std::vector<uint256>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this represent? All wallet IDs? Or any vector of wallet IDs? Something else?

{
assert(m_inverted.empty() == false);

//TODO: Should we loop over whole hash?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we gain if we do?

@adilwali adilwali merged commit 1e1888b into feature/latest-bitcore-indexing Sep 8, 2017
@adilwali adilwali deleted the feature/anv-mining branch September 8, 2017 20:09
mempko pushed a commit that referenced this pull request Sep 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants