diff --git a/simplecoin/config.py b/simplecoin/config.py index 4a52e026..22726c4c 100644 --- a/simplecoin/config.py +++ b/simplecoin/config.py @@ -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): diff --git a/simplecoin/models.py b/simplecoin/models.py index 79451118..5f9fa47e 100755 --- a/simplecoin/models.py +++ b/simplecoin/models.py @@ -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 diff --git a/simplecoin/scheduler.py b/simplecoin/scheduler.py index 64ba2b07..69b6f063 100644 --- a/simplecoin/scheduler.py +++ b/simplecoin/scheduler.py @@ -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 @@ -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 cpo = ChainPayout(chainid=id, block=block, + start_slice=start_slice, solve_slice=chain['solve_index'], chain_shares=chain['shares']) cpo.user_shares = {}