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

Introduce RewardBase #3065

Merged
merged 20 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 22 additions & 4 deletions Lib9c/Delegation/Delegatee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,25 +535,43 @@ record = Repository.GetLumpSumRewardsRecord(this, lastStartHeight)
records.Reverse();

RewardBase? rewardBase = null;
RewardBase? newRewardBase = null;
foreach (var recordEach in records)
{
if (rewardBase is null)
{
rewardBase = new RewardBase(
RewardBaseAddress(recordEach.StartHeight),
CurrentRewardBaseAddress(),
recordEach.TotalShares,
recordEach.LumpSumRewards.Keys,
recordEach.StartHeight);
recordEach.LumpSumRewards.Keys);
}
else
{
newRewardBase = rewardBase.UpdateTotalShares(recordEach.TotalShares);
if (Repository.GetRewardBase(this, recordEach.StartHeight) is not null)
{
Repository.SetRewardBase(newRewardBase);
}
Comment on lines +560 to +563
Copy link
Member

Choose a reason for hiding this comment

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

Then, is this migration running at the end of blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, this migration is run on the delegation.
(Will be held on the Stake action)
So, I expect two staking take place for proper migration.

else
{
Address archiveAddress = RewardBaseAddress(recordEach.StartHeight);
var archivedRewardBase = rewardBase.AttachHeight(archiveAddress, recordEach.StartHeight);
Repository.SetRewardBase(archivedRewardBase);
}

rewardBase = newRewardBase;
}

foreach (var r in recordEach.LumpSumRewards)
{
rewardBase = rewardBase.AddReward(r.Value);
Repository.TransferAsset(recordEach.Address, RewardPoolAddress, Repository.GetBalance(recordEach.Address, r.Key));
Repository.TransferAsset(recordEach.Address, DistributionPoolAddress(), Repository.GetBalance(recordEach.Address, r.Key));
}

Repository.RemoveLumpSumRewardsRecord(recordEach);
}

Repository.SetRewardBase(rewardBase!);
}
}
}
16 changes: 8 additions & 8 deletions Lib9c/Delegation/DelegationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ public DelegationRepository(

public Address DelegatorAccountAddress { get; }

private Address DelegateeMetadataAccountAddress { get; }
public Address DelegateeMetadataAccountAddress { get; }

private Address DelegatorMetadataAccountAddress { get; }
public Address DelegatorMetadataAccountAddress { get; }

private Address BondAccountAddress { get; }
public Address BondAccountAddress { get; }

private Address UnbondLockInAccountAddress { get; }
public Address UnbondLockInAccountAddress { get; }

private Address RebondGraceAccountAddress { get; }
public Address RebondGraceAccountAddress { get; }

private Address UnbondingSetAccountAddress { get; }
public Address UnbondingSetAccountAddress { get; }

private Address RewardBaseAccountAddress { get; }
public Address RewardBaseAccountAddress { get; }

private Address LumpSumRewardsRecordAccountAddress { get; }
public Address LumpSumRewardsRecordAccountAddress { get; }

public abstract IDelegatee GetDelegatee(Address address);

Expand Down