Skip to content

Commit 860fefd

Browse files
authored
Merge branch 'master' into fixTest
2 parents 2ca9a58 + d660979 commit 860fefd

File tree

10 files changed

+194
-86
lines changed

10 files changed

+194
-86
lines changed

.github/workflows/build-linux-binaries.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
jobs:
1414
build-x86_64-binaries-tarball:
1515
runs-on: ubuntu-20.04
16+
permissions:
17+
id-token: write
18+
contents: read
1619

1720
steps:
1821
- uses: actions/checkout@v4
@@ -72,6 +75,9 @@ jobs:
7275
7376
build-arm64-binaries-tarball:
7477
runs-on: custom-arm64-focal
78+
permissions:
79+
id-token: write
80+
contents: read
7581

7682
steps:
7783
- uses: actions/checkout@v4

.github/workflows/build-macos-release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
build-mac:
2020
# The type of runner that the job will run on
2121
runs-on: macos-12
22+
permissions:
23+
id-token: write
24+
contents: read
2225

2326
# Steps represent a sequence of tasks that will be executed as part of the job
2427
steps:

.github/workflows/build-public-ami.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
build-public-ami-and-upload:
1919
runs-on: ubuntu-22.04
2020
timeout-minutes: 45
21+
permissions:
22+
id-token: write
23+
contents: read
2124

2225
steps:
2326
- uses: actions/checkout@v4

.github/workflows/build-ubuntu-amd64-release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
jobs:
1414
build-jammy-amd64-package:
1515
runs-on: ubuntu-22.04
16+
permissions:
17+
id-token: write
18+
contents: read
1619

1720
steps:
1821
- uses: actions/checkout@v4
@@ -70,6 +73,9 @@ jobs:
7073
7174
build-focal-amd64-package:
7275
runs-on: ubuntu-20.04
76+
permissions:
77+
id-token: write
78+
contents: read
7379

7480
steps:
7581
- uses: actions/checkout@v4

.github/workflows/build-ubuntu-arm64-release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
jobs:
1414
build-jammy-arm64-package:
1515
runs-on: custom-arm64-jammy
16+
permissions:
17+
id-token: write
18+
contents: read
1619

1720
steps:
1821
- uses: actions/checkout@v4
@@ -70,6 +73,9 @@ jobs:
7073
7174
build-focal-arm64-package:
7275
runs-on: custom-arm64-focal
76+
permissions:
77+
id-token: write
78+
contents: read
7379

7480
steps:
7581
- uses: actions/checkout@v4

.github/workflows/build-win-release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ jobs:
1919
build-win:
2020
# The type of runner that the job will run on
2121
runs-on: windows-2019
22+
permissions:
23+
id-token: write
24+
contents: read
25+
2226
# Steps represent a sequence of tasks that will be executed as part of the job
2327
steps:
2428
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it

proto/pb/sdk/sdk.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/sdk/sdk.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ message SignatureRequest {
2727
bytes justification = 2;
2828
}
2929

30-
// SignatureRespnose is an AppResponse message type for providing
30+
// SignatureResponse is an AppResponse message type for providing
3131
// a requested BLS signature over a Warp message, as defined in ACP-118:
3232
// https://github.com/avalanche-foundation/ACPs/tree/main/ACPs/118-warp-signature-request
3333
message SignatureResponse {

vms/platformvm/validators/fee/fee.go

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (s State) AdvanceTime(target gas.Gas, seconds uint64) State {
4343
}
4444

4545
// CostOf calculates how much to charge based on the dynamic fee mechanism for
46-
// [seconds].
46+
// seconds.
4747
//
4848
// This implements the ACP-77 cost over time formula:
4949
func (s State) CostOf(c Config, seconds uint64) uint64 {
@@ -91,77 +91,46 @@ func (s State) CostOf(c Config, seconds uint64) uint64 {
9191
return cost
9292
}
9393

94-
// SecondsUntil calculates the number of seconds that it would take to charge at
95-
// least [targetCost] based on the dynamic fee mechanism. The result is capped
96-
// at [maxSeconds].
97-
func (s State) SecondsUntil(c Config, maxSeconds uint64, targetCost uint64) uint64 {
94+
// SecondsRemaining calculates the maximum number of seconds that a validator
95+
// can pay fees before their fundsRemaining would be exhausted based on the
96+
// dynamic fee mechanism. The result is capped at maxSeconds.
97+
func (s State) SecondsRemaining(c Config, maxSeconds uint64, fundsRemaining uint64) uint64 {
9898
// Because this function can divide by prices, we need to sanity check the
9999
// parameters to avoid division by 0.
100100
if c.MinPrice == 0 {
101-
if targetCost == 0 {
102-
return 0
103-
}
104101
return maxSeconds
105102
}
106103

107104
// If the current and target are the same, the price is constant.
108105
if s.Current == c.Target {
109-
price := gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant)
110-
return secondsUntil(
111-
uint64(price),
112-
maxSeconds,
113-
targetCost,
114-
)
106+
price := uint64(gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant))
107+
seconds := fundsRemaining / price
108+
return min(seconds, maxSeconds)
115109
}
116110

117-
var (
118-
cost uint64
119-
seconds uint64
120-
err error
121-
)
122-
for cost < targetCost && seconds < maxSeconds {
111+
for seconds := uint64(0); seconds < maxSeconds; seconds++ {
123112
s = s.AdvanceTime(c.Target, 1)
124113

125114
// Advancing the time is going to either hold excess constant,
126115
// monotonically increase it, or monotonically decrease it. If it is
127116
// equal to 0 after performing one of these operations, it is guaranteed
128117
// to always remain 0.
129118
if s.Excess == 0 {
130-
zeroExcessCost := targetCost - cost
131-
secondsWithZeroExcess := secondsUntil(
132-
uint64(c.MinPrice),
133-
maxSeconds,
134-
zeroExcessCost,
135-
)
136-
119+
secondsWithZeroExcess := fundsRemaining / uint64(c.MinPrice)
137120
totalSeconds, err := safemath.Add(seconds, secondsWithZeroExcess)
138-
if err != nil || totalSeconds >= maxSeconds {
121+
if err != nil {
122+
// This is technically unreachable, but makes the code more
123+
// clearly correct.
139124
return maxSeconds
140125
}
141-
return totalSeconds
126+
return min(totalSeconds, maxSeconds)
142127
}
143128

144-
seconds++
145-
price := gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant)
146-
cost, err = safemath.Add(cost, uint64(price))
147-
if err != nil {
129+
price := uint64(gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant))
130+
if price > fundsRemaining {
148131
return seconds
149132
}
133+
fundsRemaining -= price
150134
}
151-
return seconds
152-
}
153-
154-
// Calculate the number of seconds that it would take to charge at least [cost]
155-
// at [price] every second. The result is capped at [maxSeconds].
156-
func secondsUntil(price uint64, maxSeconds uint64, cost uint64) uint64 {
157-
// Directly rounding up could cause an overflow. Instead we round down and
158-
// then check if we should have rounded up.
159-
secondsRoundedDown := cost / price
160-
if secondsRoundedDown >= maxSeconds {
161-
return maxSeconds
162-
}
163-
if cost%price == 0 {
164-
return secondsRoundedDown
165-
}
166-
return secondsRoundedDown + 1
135+
return maxSeconds
167136
}

0 commit comments

Comments
 (0)