Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Add replacement_hash field to dag_token_locks

ALTER TABLE dag_token_locks
ADD COLUMN replacement_hash varchar NULL;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: naming -- snapshot-streaming PR #114 creates this column as replace_token_lock_ref in its SQL schema (sql/snapshot.sql:358), not replacement_hash. Whichever name we pick, both repos need to agree on it or the block_explorer won't be able to read data that snapshot-streaming writes.

I'd suggest replace_token_lock_ref since it matches the tessellation Scala type field name (TokenLock.replaceTokenLockRef at tokenLock.scala:90 on feature/increase-delegated-stake).

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Add current_token_lock_hash and current_amount fields to delegate_stake_create_events

ALTER TABLE delegate_stake_create_events
ADD COLUMN current_token_lock_hash varchar NULL,
ADD COLUMN current_amount int8 NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Add current_token_lock_hash and current_amount fields to delegate_stake_withdraw_events

ALTER TABLE delegate_stake_withdraw_events
ADD COLUMN current_token_lock_hash varchar NULL,
ADD COLUMN current_amount int8 NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE delegate_stake_create_events ADD COLUMN created_at_epoch int8 NULL;
25 changes: 16 additions & 9 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ model dag_token_locks {
round_id String @db.Uuid
snapshot_hash String @db.VarChar
parent_hash String? @db.VarChar
currency_id String? @db.VarChar
currency_id String? @db.VarChar
replacement_hash String? @db.VarChar
addresses addresses @relation(fields: [source_addr], references: [address], onDelete: Cascade, onUpdate: Restrict, map: "dag_token_locks_source_addr_fk")
global_snapshot global_snapshots @relation(fields: [snapshot_hash], references: [hash], onDelete: Cascade, onUpdate: Restrict, map: "dag_token_lock_global_snapshot_fk")
dag_token_unlock dag_token_unlocks?
Expand Down Expand Up @@ -600,9 +601,12 @@ model delegate_stake_create_events {
lock_reference_hash String @db.VarChar
parent_hash String @db.VarChar
global_snapshot_hash String @db.VarChar
transfer_from_hash String? @unique @db.VarChar
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @default(now()) @db.Timestamp(6)
transfer_from_hash String? @unique @db.VarChar
current_token_lock_hash String? @db.VarChar
current_amount BigInt?
created_at_epoch BigInt?
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @default(now()) @db.Timestamp(6)

global_snapshot global_snapshots @relation(fields: [global_snapshot_hash], references: [hash], onDelete: Cascade, onUpdate: Restrict)
addresses addresses @relation(fields: [source_addr], references: [address], onDelete: Cascade, onUpdate: Restrict)
Expand All @@ -624,10 +628,13 @@ model delegate_stake_withdraw_events {
source_addr String @db.VarChar
stake_create_hash String @unique @db.VarChar
global_snapshot_hash String @db.VarChar
unlock_epoch BigInt
is_completed Boolean
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @default(now()) @db.Timestamp(6)
created_at_epoch BigInt
unlock_epoch BigInt
is_completed Boolean
current_token_lock_hash String? @db.VarChar
current_amount BigInt?
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @default(now()) @db.Timestamp(6)

global_snapshot global_snapshots @relation(fields: [global_snapshot_hash], references: [hash], onDelete: Cascade, onUpdate: Restrict)
addresses addresses @relation(fields: [source_addr], references: [address], onDelete: Cascade, onUpdate: Restrict)
Expand Down Expand Up @@ -662,4 +669,4 @@ model token_lock_total_rewards_view {
total_rewards BigInt

delegate_stake_create_events delegate_stake_create_events[]
}
}
4 changes: 4 additions & 0 deletions src/handlers/delegatedStakingHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const delegateStakeCreateResponse = (event) => ({
timestamp: event.created_at,
globalSnapshotHash: event.global_snapshot_hash,
globalSnapshotOrdinal: event.global_snapshot?.ordinal,
currentTokenLockHash: event.lock_reference_hash,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses event.lock_reference_hash instead of event.current_token_lock_hash. The lock_reference_hash is the original token lock ref from the Create event (UpdateDelegatedStake.Create.tokenLockRef in tessellation), not the current/replacement one. So this will always return the original hash even when a stake has been increased.

Should be:

currentTokenLockHash: event.current_token_lock_hash,

(The previous review flagged this too -- just confirming with the tessellation type reference: DelegatedStakeRecord.currentTokenLockRef at delegatedStake.scala:127 on the feature/increase-delegated-stake branch is an Option[Hash] that's None for original stakes and Some(newLockHash) for increased stakes.)

currentAmount: event.current_amount,
});

const delegateStakeCreateResponses = (txs) =>
Expand All @@ -70,6 +72,8 @@ const delegateStakeWithdrawResponse = (event) => ({
timestamp: event.created_at,
globalSnapshotHash: event.global_snapshot_hash,
globalSnapshotOrdinal: event.global_snapshot?.ordinal,
currentTokenLockHash: event.lock_reference_hash,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same bug here -- event.lock_reference_hash should be event.current_token_lock_hash. The withdraw events table also has the current_token_lock_hash column (added in your migration 03_add_current_fields_to_delegate_stake_withdraw_events.sql), so we should be reading from it.

currentAmount: event.current_amount,
});

const delegateStakeWithdrawResponses = (txs) =>
Expand Down
1 change: 1 addition & 0 deletions src/handlers/tokenLocksHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const dagTokenLockResponse = (transaction) => ({
transaction.dag_token_unlock?.global_snapshot.ordinal ?? null,
globalSnapshotHash: transaction.snapshot_hash,
globalSnapshotOrdinal: transaction.global_snapshot.ordinal,
replacementHash: transaction.replacement_hash,
});

const dagTokenLockResponses = (txs) => txs.map(dagTokenLockResponse);
Expand Down
Loading