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

RewardValidatorTx cleanup #1891

Merged
merged 33 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
68570c7
rewardValidatorTx cleanup
abi87 Aug 22, 2023
337a54f
fix + nit
abi87 Aug 22, 2023
133a58d
another fix
abi87 Aug 22, 2023
49d1af7
Merge branch 'dev' into reward_tx_refactoring
abi87 Aug 22, 2023
a26b0a1
Merge branch 'dev' into reward_tx_refactoring
abi87 Aug 22, 2023
40cfa75
nit
abi87 Aug 22, 2023
0366a0e
Merge branch 'dev' into reward_tx_refactoring
abi87 Aug 23, 2023
96f8992
Merge branch 'dev' into reward_tx_refactoring
abi87 Aug 24, 2023
8734305
Merge branch 'dev' into reward_tx_refactoring
abi87 Aug 25, 2023
d1697c1
Merge branch 'dev' into reward_tx_refactoring
abi87 Aug 29, 2023
ca776e3
Merge branch 'dev' into reward_tx_refactoring
abi87 Aug 30, 2023
fa0515e
nits
abi87 Aug 30, 2023
213e85f
Merge branch 'dev' into reward_tx_refactoring
abi87 Aug 31, 2023
57ff17b
reverted utxos offset handling
abi87 Aug 31, 2023
b51c42a
Merge branch 'dev' into reward_tx_refactoring
abi87 Sep 2, 2023
99ae9d6
Merge branch 'dev' into reward_tx_refactoring
abi87 Sep 6, 2023
bffc7e9
Merge branch 'dev' into reward_tx_refactoring
abi87 Sep 8, 2023
50b8bdf
exported SplitByShare
abi87 Sep 8, 2023
9c09354
moved Split to reward package
abi87 Sep 8, 2023
d6c9e23
nits
abi87 Sep 8, 2023
1956046
Merge branch 'dev' into reward_tx_refactoring
abi87 Sep 8, 2023
599afa6
Merge branch 'dev' into reward_tx_refactoring
abi87 Sep 11, 2023
1f7f4be
Merge branch 'dev' into reward_tx_refactoring
abi87 Sep 12, 2023
5460cbd
Merge branch 'dev' into reward_tx_refactoring
abi87 Sep 14, 2023
d618dcf
Merge branch 'dev' into reward_tx_refactoring
abi87 Sep 15, 2023
8e05def
Merge branch 'dev' into reward_tx_refactoring
abi87 Sep 18, 2023
8c2814f
nits
abi87 Sep 18, 2023
1848bb1
fixed comment
abi87 Sep 18, 2023
e6e5d35
Add tests
StephenButtolph Sep 19, 2023
b09c989
merged
StephenButtolph Sep 19, 2023
4fc4710
nits
StephenButtolph Sep 19, 2023
1f396e1
cleanup
StephenButtolph Sep 19, 2023
5808629
cleanup
StephenButtolph Sep 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions vms/platformvm/blocks/executor/proposal_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func TestApricotProposalBlockTimeVerification(t *testing.T) {
NodeID: utx.NodeID(),
SubnetID: utx.SubnetID(),
StartTime: utx.StartTime(),
NextTime: chainTime,
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
EndTime: chainTime,
}).Times(2)
currentStakersIt.EXPECT().Release()
Expand All @@ -104,6 +105,7 @@ func TestApricotProposalBlockTimeVerification(t *testing.T) {
NodeID: utx.NodeID(),
SubnetID: utx.SubnetID(),
StartTime: utx.StartTime(),
NextTime: chainTime,
EndTime: chainTime,
}, nil)
onParentAccept.EXPECT().GetTx(addValTx.ID()).Return(addValTx, status.Committed, nil)
Expand Down
15 changes: 15 additions & 0 deletions vms/platformvm/reward/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package reward
import (
"math/big"
"time"

safemath "github.com/ava-labs/avalanchego/utils/math"
abi87 marked this conversation as resolved.
Show resolved Hide resolved
)

var _ Calculator = (*calculator)(nil)
Expand Down Expand Up @@ -67,3 +69,16 @@ func (c *calculator) Calculate(stakedDuration time.Duration, stakedAmount, curre

return finalReward
}

func Split(totalAmount uint64, shares uint32) (uint64, uint64) {
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
remainderShares := PercentDenominator - uint64(shares)
remainderAmount := remainderShares * (totalAmount / PercentDenominator)

// Delay rounding as long as possible for small numbers
if optimisticReward, err := safemath.Mul64(remainderShares, totalAmount); err == nil {
remainderAmount = optimisticReward / PercentDenominator
}

amountFromShares := totalAmount - remainderAmount
return remainderAmount, amountFromShares
}