Compare commits
2 commits
master
...
fix-eff-am
Author | SHA1 | Date | |
---|---|---|---|
|
1b2ea4eb80 | ||
|
a408b113bc |
2 changed files with 10 additions and 14 deletions
|
@ -534,15 +534,10 @@ class SQLDB:
|
||||||
""", claim_hashes)
|
""", claim_hashes)
|
||||||
|
|
||||||
def _update_effective_amount(self, height, claim_hashes=None):
|
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:
|
if claim_hashes:
|
||||||
self.execute(
|
self.execute(
|
||||||
f"UPDATE claim SET effective_amount = amount + support_amount "
|
f"UPDATE claim SET effective_amount = amount + support_amount "
|
||||||
f"WHERE activation_height < {height} "
|
f"WHERE claim_hash IN ({','.join('?' for _ in claim_hashes)})",
|
||||||
f" AND claim_hash IN ({','.join('?' for _ in claim_hashes)})",
|
|
||||||
claim_hashes
|
claim_hashes
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -570,12 +565,13 @@ class SQLDB:
|
||||||
claimtrie.claim_hash AS current_winner,
|
claimtrie.claim_hash AS current_winner,
|
||||||
MAX(winner.effective_amount)
|
MAX(winner.effective_amount)
|
||||||
FROM (
|
FROM (
|
||||||
SELECT normalized, claim_hash, effective_amount FROM claim
|
SELECT normalized, claim_hash, effective_amount, activation_height FROM claim
|
||||||
WHERE normalized IN (
|
WHERE normalized IN (
|
||||||
SELECT normalized FROM claim WHERE activation_height={height} {claim_hashes_sql}
|
SELECT normalized FROM claim WHERE activation_height={height} {claim_hashes_sql}
|
||||||
) {deleted_names_sql}
|
) {deleted_names_sql}
|
||||||
ORDER BY effective_amount DESC, height ASC, tx_position ASC
|
ORDER BY effective_amount DESC, height ASC, tx_position ASC
|
||||||
) AS winner LEFT JOIN claimtrie USING (normalized)
|
) AS winner LEFT JOIN claimtrie USING (normalized)
|
||||||
|
WHERE winner.activation_height<={height}
|
||||||
GROUP BY winner.normalized
|
GROUP BY winner.normalized
|
||||||
HAVING current_winner IS NULL OR current_winner <> winner.claim_hash
|
HAVING current_winner IS NULL OR current_winner <> winner.claim_hash
|
||||||
""", changed_claim_hashes+deleted_names)
|
""", changed_claim_hashes+deleted_names)
|
||||||
|
|
|
@ -167,35 +167,35 @@ class TestClaimtrie(TestSQLDB):
|
||||||
state(
|
state(
|
||||||
controlling=('Claim A', 10*COIN, 10*COIN, 13),
|
controlling=('Claim A', 10*COIN, 10*COIN, 13),
|
||||||
active=[],
|
active=[],
|
||||||
accepted=[('Claim B', 20*COIN, 0, 1031)]
|
accepted=[('Claim B', 20*COIN, 20*COIN, 1031)]
|
||||||
)
|
)
|
||||||
advance(1010, [self.get_support(stream, 14*COIN)])
|
advance(1010, [self.get_support(stream, 14*COIN)])
|
||||||
state(
|
state(
|
||||||
controlling=('Claim A', 10*COIN, 24*COIN, 13),
|
controlling=('Claim A', 10*COIN, 24*COIN, 13),
|
||||||
active=[],
|
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)])
|
advance(1020, [self.get_stream('Claim C', 50*COIN)])
|
||||||
state(
|
state(
|
||||||
controlling=('Claim A', 10*COIN, 24*COIN, 13),
|
controlling=('Claim A', 10*COIN, 24*COIN, 13),
|
||||||
active=[],
|
active=[],
|
||||||
accepted=[
|
accepted=[
|
||||||
('Claim B', 20*COIN, 0, 1031),
|
('Claim B', 20*COIN, 20*COIN, 1031),
|
||||||
('Claim C', 50*COIN, 0, 1051)]
|
('Claim C', 50*COIN, 50*COIN, 1051)]
|
||||||
)
|
)
|
||||||
advance(1031, [])
|
advance(1031, [])
|
||||||
state(
|
state(
|
||||||
controlling=('Claim A', 10*COIN, 24*COIN, 13),
|
controlling=('Claim A', 10*COIN, 24*COIN, 13),
|
||||||
active=[('Claim B', 20*COIN, 20*COIN, 1031)],
|
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)])
|
advance(1040, [self.get_stream('Claim D', 300*COIN)])
|
||||||
state(
|
state(
|
||||||
controlling=('Claim A', 10*COIN, 24*COIN, 13),
|
controlling=('Claim A', 10*COIN, 24*COIN, 13),
|
||||||
active=[('Claim B', 20*COIN, 20*COIN, 1031)],
|
active=[('Claim B', 20*COIN, 20*COIN, 1031)],
|
||||||
accepted=[
|
accepted=[
|
||||||
('Claim C', 50*COIN, 0, 1051),
|
('Claim C', 50*COIN, 50*COIN, 1051),
|
||||||
('Claim D', 300*COIN, 0, 1072)]
|
('Claim D', 300*COIN, 300*COIN, 1072)]
|
||||||
)
|
)
|
||||||
advance(1051, [])
|
advance(1051, [])
|
||||||
state(
|
state(
|
||||||
|
|
Loading…
Reference in a new issue