Skip to content

Commit

Permalink
feat(indexer): better logs, skipping already-indexed events, adding R…
Browse files Browse the repository at this point in the history
…eindexRequest (#625)

* feat(indexer): adding logs and manual indexing - WIP

* feat(indexer,api): skip already-indexed events, added ReindexRequest

* updating help text

* feat(indexer): remove condition that prevents updating summary from previous block

* fix(indexer,api): event unique on tx_hash+chain, prevent overwrite newer info

* fix: added back last_updated_in_block

* chore(indexer): changing if/else to match
  • Loading branch information
lucianHymer authored and larisa17 committed Jul 4, 2024
1 parent 5fe4be1 commit adfadac
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 98 deletions.
19 changes: 18 additions & 1 deletion api/stake/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from scorer.scorer_admin import ScorerModelAdmin
from stake.models import Stake, StakeEvent
from stake.models import Stake, StakeEvent, ReindexRequest


@admin.register(Stake)
Expand Down Expand Up @@ -51,3 +51,20 @@ class StakeEventAdmin(ScorerModelAdmin):
"tx_hash",
]
search_help_text = "Search by: " + ", ".join(search_fields)


@admin.register(ReindexRequest)
class ReindexRequestAdmin(admin.ModelAdmin):
list_display = [
"pending",
"chain",
"start_block_number",
"created_at",
]

list_filter = [
"chain",
"pending",
]

readonly_fields = ("pending",)
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 4.2.6 on 2024-07-02 21:30

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("stake", "0005_alter_stake_current_amount_alter_stakeevent_amount"),
]

operations = [
migrations.CreateModel(
name="ReindexRequest",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
(
"chain",
models.IntegerField(
db_index=True,
help_text="Decimal chain ID. Ethereum: 1, Optimism: 10, Arbitrum: 42161",
),
),
(
"start_block_number",
models.DecimalField(decimal_places=0, max_digits=78),
),
("pending", models.BooleanField(db_index=True, default=True)),
],
),
migrations.AlterField(
model_name="stakeevent",
name="block_number",
field=models.DecimalField(db_index=True, decimal_places=0, max_digits=78),
),
migrations.AlterUniqueTogether(
name="stakeevent",
unique_together={("tx_hash", "chain")},
),
migrations.AddConstraint(
model_name="reindexrequest",
constraint=models.UniqueConstraint(
condition=models.Q(("pending", True)),
fields=("chain",),
name="unique_only_one_pending_per_chain",
),
),
]
32 changes: 31 additions & 1 deletion api/stake/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,40 @@ class StakeEventType(models.TextChoices):
)

block_number = models.DecimalField(
decimal_places=0, null=False, blank=False, max_digits=78
decimal_places=0, null=False, blank=False, max_digits=78, db_index=True
)

tx_hash = models.CharField(max_length=66, null=False, blank=False)

# Only applies to SelfStake and CommunityStake events
unlock_time = models.DateTimeField(null=True, blank=True)

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


class ReindexRequest(models.Model):
created_at = models.DateTimeField(auto_now_add=True)

chain = models.IntegerField(
null=False,
blank=False,
db_index=True,
help_text="Decimal chain ID. Ethereum: 1, Optimism: 10, Arbitrum: 42161",
)

start_block_number = models.DecimalField(
decimal_places=0, null=False, blank=False, max_digits=78
)

pending = models.BooleanField(null=False, blank=False, default=True, db_index=True)

class Meta:
# Only one reindex request can be pending at a time for a chain
constraints = [
models.UniqueConstraint(
fields=["chain"],
name="unique_only_one_pending_per_chain",
condition=models.Q(pending=True),
),
]
2 changes: 1 addition & 1 deletion indexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> Result<()> {
let contract_address_op_mainnet = get_env("STAKING_CONTRACT_ADDRESS_OP_MAINNET")
.parse::<Address>()
.unwrap();

let contract_address_op_sepolia = get_env("STAKING_CONTRACT_ADDRESS_OP_SEPOLIA")
.parse::<Address>()
.unwrap();
Expand Down
Loading

0 comments on commit adfadac

Please sign in to comment.