Skip to content

Commit

Permalink
fix(indexer): fix dedupe to allow multiple stakees in same transaction (
Browse files Browse the repository at this point in the history
#637)

* fix(indexer): fix dedupe to allow multiple stakees in same transaction

* fix: merge migrations to skip erroneous dedupe constraint
  • Loading branch information
lucianHymer authored Jul 17, 2024
1 parent 27bd5a0 commit fb7d185
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.6 on 2024-07-02 21:30
# Generated by Django 4.2.6 on 2024-07-17 16:59

from django.db import migrations, models

Expand Down Expand Up @@ -43,7 +43,7 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name="stakeevent",
unique_together={("tx_hash", "chain")},
unique_together={("tx_hash", "chain", "stakee")},
),
migrations.AddConstraint(
model_name="reindexrequest",
Expand Down
5 changes: 3 additions & 2 deletions api/stake/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from account.models import EthAddressField
from django.db import models

from account.models import EthAddressField


# Stores the current summary for each (chain, staker, stakee) combo
class Stake(models.Model):
Expand Down Expand Up @@ -74,7 +75,7 @@ class StakeEventType(models.TextChoices):
unlock_time = models.DateTimeField(null=True, blank=True)

class Meta:
unique_together = ["tx_hash", "chain"]
unique_together = ["tx_hash", "chain", "stakee"]


class ReindexRequest(models.Model):
Expand Down
4 changes: 2 additions & 2 deletions indexer/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl PostgresClient {
// rollback transaction
client.execute("ROLLBACK", &[]).await?;
// continue if duplicate key error
if format!("{:?}", e).contains(&format!("Key (tx_hash, chain)=({}, {}) already exists.", tx_hash, chain_id)) {
if format!("{:?}", e).contains(&format!("Key (tx_hash, chain, stakee)=({}, {}, {}) already exists.", tx_hash, chain_id, stakee)) {
return Ok(());
}
return Err(e);
Expand Down Expand Up @@ -225,7 +225,7 @@ impl PostgresClient {
// rollback transaction
client.execute("ROLLBACK", &[]).await?;
// continue if duplicate key error
if format!("{:?}", e).contains(&format!("Key (tx_hash, chain)=({}, {}) already exists.", tx_hash, chain_id)) {
if format!("{:?}", e).contains(&format!("Key (tx_hash, chain, stakee)=({}, {}, {}) already exists.", tx_hash, chain_id, stakee)) {
return Ok(());
}
return Err(e);
Expand Down

0 comments on commit fb7d185

Please sign in to comment.