Compare commits

...

2 commits

Author SHA1 Message Date
Thomas Zarebczan
1b2ea4eb80 Fix: missed one + test
fix
2019-07-18 18:35:52 -04:00
Thomas Zarebczan
a408b113bc fix: effective amount calc
We don't care what the activate height is..that's kept track of separately. We may want to change the name of effective amount, but this doesn't change the understanding of it. If the takeover time had passed, the effective amount is set correctly. It's effective regardless of activation.
2019-07-18 16:19:12 -04:00
2 changed files with 10 additions and 14 deletions

View file

@ -534,15 +534,10 @@ class SQLDB:
""", claim_hashes)
def _update_effective_amount(self, height, claim_hashes=None):
self.execute(
f"UPDATE claim SET effective_amount = amount + support_amount "
f"WHERE activation_height = {height}"
)
if claim_hashes:
self.execute(
f"UPDATE claim SET effective_amount = amount + support_amount "
f"WHERE activation_height < {height} "
f" AND claim_hash IN ({','.join('?' for _ in claim_hashes)})",
f"WHERE claim_hash IN ({','.join('?' for _ in claim_hashes)})",
claim_hashes
)
@ -570,12 +565,13 @@ class SQLDB:
claimtrie.claim_hash AS current_winner,
MAX(winner.effective_amount)
FROM (
SELECT normalized, claim_hash, effective_amount FROM claim
SELECT normalized, claim_hash, effective_amount, activation_height FROM claim
WHERE normalized IN (
SELECT normalized FROM claim WHERE activation_height={height} {claim_hashes_sql}
) {deleted_names_sql}
ORDER BY effective_amount DESC, height ASC, tx_position ASC
) AS winner LEFT JOIN claimtrie USING (normalized)
WHERE winner.activation_height<={height}
GROUP BY winner.normalized
HAVING current_winner IS NULL OR current_winner <> winner.claim_hash
""", changed_claim_hashes+deleted_names)

View file

@ -167,35 +167,35 @@ class TestClaimtrie(TestSQLDB):
state(
controlling=('Claim A', 10*COIN, 10*COIN, 13),
active=[],
accepted=[('Claim B', 20*COIN, 0, 1031)]
accepted=[('Claim B', 20*COIN, 20*COIN, 1031)]
)
advance(1010, [self.get_support(stream, 14*COIN)])
state(
controlling=('Claim A', 10*COIN, 24*COIN, 13),
active=[],
accepted=[('Claim B', 20*COIN, 0, 1031)]
accepted=[('Claim B', 20*COIN, 20*COIN, 1031)]
)
advance(1020, [self.get_stream('Claim C', 50*COIN)])
state(
controlling=('Claim A', 10*COIN, 24*COIN, 13),
active=[],
accepted=[
('Claim B', 20*COIN, 0, 1031),
('Claim C', 50*COIN, 0, 1051)]
('Claim B', 20*COIN, 20*COIN, 1031),
('Claim C', 50*COIN, 50*COIN, 1051)]
)
advance(1031, [])
state(
controlling=('Claim A', 10*COIN, 24*COIN, 13),
active=[('Claim B', 20*COIN, 20*COIN, 1031)],
accepted=[('Claim C', 50*COIN, 0, 1051)]
accepted=[('Claim C', 50*COIN, 50*COIN, 1051)]
)
advance(1040, [self.get_stream('Claim D', 300*COIN)])
state(
controlling=('Claim A', 10*COIN, 24*COIN, 13),
active=[('Claim B', 20*COIN, 20*COIN, 1031)],
accepted=[
('Claim C', 50*COIN, 0, 1051),
('Claim D', 300*COIN, 0, 1072)]
('Claim C', 50*COIN, 50*COIN, 1051),
('Claim D', 300*COIN, 300*COIN, 1072)]
)
advance(1051, [])
state(