Skip to content

Commit ce6040d

Browse files
authored
fix(ledger): use mark snapshot for stake distribution (#1434)
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
1 parent d9cef59 commit ce6040d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

ledger/view.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,14 @@ type StakeDistribution struct {
570570
}
571571

572572
// GetStakeDistribution returns the stake distribution for leader election.
573-
// Uses the "go" snapshot which represents stake from 2 epochs ago.
573+
// Uses the "mark" snapshot at the given epoch. Callers pass currentEpoch-2
574+
// so the epoch offset already accounts for the Mark→Set→Go rotation.
574575
func (lv *LedgerView) GetStakeDistribution(
575576
epoch uint64,
576577
) (*StakeDistribution, error) {
577578
snapshots, err := lv.ls.db.Metadata().GetPoolStakeSnapshotsByEpoch(
578579
epoch,
579-
"go",
580+
"mark",
580581
(*lv.txn).Metadata(),
581582
)
582583
if err != nil {
@@ -598,15 +599,16 @@ func (lv *LedgerView) GetStakeDistribution(
598599
return dist, nil
599600
}
600601

601-
// GetPoolStake returns the stake for a specific pool from the "go" snapshot.
602-
// Returns 0 if the pool has no stake in the snapshot.
602+
// GetPoolStake returns the stake for a specific pool from the snapshot.
603+
// Returns 0 if the pool has no stake in the snapshot. Callers pass
604+
// currentEpoch-2 so the epoch offset accounts for Mark→Set→Go rotation.
603605
func (lv *LedgerView) GetPoolStake(
604606
epoch uint64,
605607
poolKeyHash []byte,
606608
) (uint64, error) {
607609
snapshot, err := lv.ls.db.Metadata().GetPoolStakeSnapshot(
608610
epoch,
609-
"go",
611+
"mark",
610612
poolKeyHash,
611613
(*lv.txn).Metadata(),
612614
)
@@ -619,11 +621,12 @@ func (lv *LedgerView) GetPoolStake(
619621
return uint64(snapshot.TotalStake), nil
620622
}
621623

622-
// GetTotalActiveStake returns the total active stake from the "go" snapshot.
624+
// GetTotalActiveStake returns the total active stake from the snapshot.
625+
// Callers pass currentEpoch-2 so the epoch offset accounts for rotation.
623626
func (lv *LedgerView) GetTotalActiveStake(epoch uint64) (uint64, error) {
624627
return lv.ls.db.Metadata().GetTotalActiveStake(
625628
epoch,
626-
"go",
629+
"mark",
627630
(*lv.txn).Metadata(),
628631
)
629632
}

0 commit comments

Comments
 (0)