Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(indexer): better logs, skipping already-indexed events, adding ReindexRequest #625

Merged
merged 7 commits into from
Jul 2, 2024
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
Loading