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

fix: tx interrupted #82

Closed
wants to merge 21 commits into from
Closed
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
Prev Previous commit
Next Next commit
fix: fix test
egonspace committed May 16, 2024

Verified

This commit was signed with the committer’s verified signature.
Girgias Gina Peter Banyard
commit 8402eed731778ae336b9a8955adf684e404757f2
7 changes: 4 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
@@ -436,7 +436,7 @@ type BriocheConfig struct {
HalvingPeriod *big.Int `json:"halvingPeriod,omitempty"` // nil - halving is not work
NoRewardHereafter *big.Int `json:"noRewardHereafter,omitempty"` // nil - block reward goes on endlessly
HalvingTimes uint64 `json:"halvingTimes,omitempty"` // 0 - no halving
HalvingRate uint32 `json:"halvingRate,omitempty"` // 0<=HalvingRate<=100; 0 - no reward on halving; 100 - no halving
HalvingRate uint32 `json:"halvingRate,omitempty"` // 0 - no reward on halving; 100 - no halving; >100 - increasing reward
}

func (bc *BriocheConfig) GetBriocheBlockReward(defaultReward *big.Int, num *big.Int) *big.Int {
@@ -464,7 +464,7 @@ func (bc *BriocheConfig) halveRewards(baseReward *big.Int, num *big.Int) *big.In
past.Sub(past, bc.FirstHalvingBlock)
halvingTimes := bc.HalvingTimes
for ; halvingTimes > 0; halvingTimes-- {
result = result.Mul(result, big.NewInt(int64(bc.HalvingRate)))
result = result.Mul(result, big.NewInt(int64(bc.HalvingRate))) // `HalvingRate` may be greater than 100 theoretically
result = result.Div(result, big.NewInt(100))
if past.Cmp(bc.HalvingPeriod) < 0 {
break
@@ -807,7 +807,7 @@ type Rules struct {
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon bool
IsMerge bool
IsPangyo, IsApplepie bool
IsPangyo, IsApplepie, IsBrioche bool
}

// Rules ensures c's ChainID is not nil.
@@ -831,5 +831,6 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool) Rules {
IsMerge: isMerge,
IsPangyo: c.IsPangyo(num),
IsApplepie: c.IsApplepie(num),
IsBrioche: c.IsBrioche(num),
}
}
3 changes: 2 additions & 1 deletion params/config_test.go
Original file line number Diff line number Diff line change
@@ -125,6 +125,7 @@ func TestHalveRewards(t *testing.T) {
{big.NewInt(1e18), big.NewInt(100), big.NewInt(100), 2, 20, big.NewInt(4e16)},
{big.NewInt(1e18), big.NewInt(100), big.NewInt(100), 2, 30, big.NewInt(9e16)},
{big.NewInt(1e18), big.NewInt(100), big.NewInt(100), 2, 90, big.NewInt(81e16)},
{big.NewInt(1e18), big.NewInt(100), big.NewInt(100), 2, 200, big.NewInt(4e18)},

// brioche halving test
{big.NewInt(1e18), big.NewInt(63115200), big.NewInt(0), 16, 50, big.NewInt(5e17)},
@@ -156,7 +157,7 @@ func TestHalveRewards(t *testing.T) {
HalvingTimes: tc.times,
HalvingRate: tc.rate,
}
halved := brioche.halveRewards(tc.reward, tc.period)
halved := brioche.halveRewards(tc.reward, tc.past)
if tc.expected.Cmp(halved) != 0 {
t.Errorf("halveRewards mismatched (expected=%v, actual=%v)", tc.expected, halved)
}

Unchanged files with check annotations Beta

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Call the distributeRewards function
rewards, err := distributeRewards(tt.height, tt.rp, big.NewInt(defaultBriocheBlockReward), tt.fees)

Check failure on line 138 in wemix/rewards_test.go

GitHub Actions / lint_test (1.18)

cannot use defaultBriocheBlockReward (variable of type *big.Int) as int64 value in argument to big.NewInt (typecheck)

Check failure on line 138 in wemix/rewards_test.go

GitHub Actions / lint_test (1.17)

cannot use defaultBriocheBlockReward (variable of type *big.Int) as int64 value in argument to big.NewInt (typecheck)

Check failure on line 138 in wemix/rewards_test.go

GitHub Actions / lint_test (1.19)

cannot use defaultBriocheBlockReward (variable of type *big.Int) as type int64 in argument to big.NewInt (typecheck)

Check failure on line 138 in wemix/rewards_test.go

GitHub Actions / unit_test

cannot use defaultBriocheBlockReward (variable of type *big.Int) as type int64 in argument to big.NewInt
rewardsString, _ := json.Marshal(rewards)
if string(rewardsString) != tt.want {
t.Errorf("distributeRewards() failed: %v, %v <-> %v", err, tt.want, string(rewardsString))