Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Pull starting slice from redis instead of extrapolating #154

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions simplecoin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,19 +482,7 @@ def calc_shares(self, block_payout):
class PropChain(Chain):
def calc_shares(self, block_payout):
assert block_payout.chainid == self.id
curr_block = block_payout.block
last_block = (m.Block.query.filter_by(algo=curr_block.algo,
merged=curr_block.merged,
currency=curr_block.currency).
filter(m.Block.hash != curr_block.hash).
order_by(m.Block.found_at.desc())).first()
stop_slice = 0
if last_block:
bps = [bp for bp in last_block.chain_payouts if bp.chainid == self.id]
if len(bps) > 0:
last_block_payout = bps[0]
stop_slice = last_block_payout.solve_slice
return self._calc_shares(block_payout.solve_slice, stop_slice=stop_slice)
return self._calc_shares(block_payout.solve_slice, stop_slice=block_payout.start_slice)


class ChainKeeper(Keeper):
Expand Down
1 change: 1 addition & 0 deletions simplecoin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class ChainPayout(base):
chainid = db.Column(db.Integer, primary_key=True)
block_id = db.Column(db.Integer, db.ForeignKey('block.id'), primary_key=True)
block = db.relationship('Block', foreign_keys=[block_id], backref='chain_payouts')
start_slice = db.Column(db.Integer)
# Placeholder for the point at which the block was solved in this share chain.
solve_slice = db.Column(db.Integer)
# Shares on this chain. Used to get portion of total block
Expand Down
4 changes: 4 additions & 0 deletions simplecoin/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ def credit_block(redis_key, simulate=False):
value = Decimal(value)
elif key == "solve_index":
value = int(value)
elif key == "start_index":
value = int(value)
# XXX: Could do extra check for setting duplicate data (overrite) here
chain[key] = value

Expand All @@ -569,8 +571,10 @@ def credit_block(redis_key, simulate=False):
for id, chain in chain_data.iteritems():
if chain['shares'] == 0:
continue
start_slice = chain['start_index'] if chain.has_key('start_index') else chain['solve_index'] - 1
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure about the correctness of this. In scenarios involving merge-mined blocks this will definitely be wrong at certain times. Effectively, something can occur where "slice 0" has most of the shares, and was rotated by a merge mined block solve. "slice 1" has a small number of shares, and was rotated due to a main network block solve.

The simplest fix is to require the "start_index" value if there are other blocks solved on the same chain already. This has it's own problems tho if the redis database gets wiped.

I'll keep thinking on this. For the large majority of cases tho this should work fine. Thanks for the work!

cpo = ChainPayout(chainid=id,
block=block,
start_slice=start_slice,
solve_slice=chain['solve_index'],
chain_shares=chain['shares'])
cpo.user_shares = {}
Expand Down