Skip to content

Commit

Permalink
Merge branch 'master' into fixTest
Browse files Browse the repository at this point in the history
  • Loading branch information
yacovm authored Sep 18, 2024
2 parents 2ca9a58 + d660979 commit 860fefd
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 86 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-linux-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
jobs:
build-x86_64-binaries-tarball:
runs-on: ubuntu-20.04
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -72,6 +75,9 @@ jobs:
build-arm64-binaries-tarball:
runs-on: custom-arm64-focal
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-macos-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
build-mac:
# The type of runner that the job will run on
runs-on: macos-12
permissions:
id-token: write
contents: read

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-public-ami.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
build-public-ami-and-upload:
runs-on: ubuntu-22.04
timeout-minutes: 45
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/build-ubuntu-amd64-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
jobs:
build-jammy-amd64-package:
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -70,6 +73,9 @@ jobs:
build-focal-amd64-package:
runs-on: ubuntu-20.04
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/build-ubuntu-arm64-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
jobs:
build-jammy-arm64-package:
runs-on: custom-arm64-jammy
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -70,6 +73,9 @@ jobs:
build-focal-arm64-package:
runs-on: custom-arm64-focal
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build-win-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
build-win:
# The type of runner that the job will run on
runs-on: windows-2019
permissions:
id-token: write
contents: read

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand Down
2 changes: 1 addition & 1 deletion proto/pb/sdk/sdk.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/sdk/sdk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ message SignatureRequest {
bytes justification = 2;
}

// SignatureRespnose is an AppResponse message type for providing
// SignatureResponse is an AppResponse message type for providing
// a requested BLS signature over a Warp message, as defined in ACP-118:
// https://github.com/avalanche-foundation/ACPs/tree/main/ACPs/118-warp-signature-request
message SignatureResponse {
Expand Down
67 changes: 18 additions & 49 deletions vms/platformvm/validators/fee/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s State) AdvanceTime(target gas.Gas, seconds uint64) State {
}

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

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

// If the current and target are the same, the price is constant.
if s.Current == c.Target {
price := gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant)
return secondsUntil(
uint64(price),
maxSeconds,
targetCost,
)
price := uint64(gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant))
seconds := fundsRemaining / price
return min(seconds, maxSeconds)
}

var (
cost uint64
seconds uint64
err error
)
for cost < targetCost && seconds < maxSeconds {
for seconds := uint64(0); seconds < maxSeconds; seconds++ {
s = s.AdvanceTime(c.Target, 1)

// Advancing the time is going to either hold excess constant,
// monotonically increase it, or monotonically decrease it. If it is
// equal to 0 after performing one of these operations, it is guaranteed
// to always remain 0.
if s.Excess == 0 {
zeroExcessCost := targetCost - cost
secondsWithZeroExcess := secondsUntil(
uint64(c.MinPrice),
maxSeconds,
zeroExcessCost,
)

secondsWithZeroExcess := fundsRemaining / uint64(c.MinPrice)
totalSeconds, err := safemath.Add(seconds, secondsWithZeroExcess)
if err != nil || totalSeconds >= maxSeconds {
if err != nil {
// This is technically unreachable, but makes the code more
// clearly correct.
return maxSeconds
}
return totalSeconds
return min(totalSeconds, maxSeconds)
}

seconds++
price := gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant)
cost, err = safemath.Add(cost, uint64(price))
if err != nil {
price := uint64(gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant))
if price > fundsRemaining {
return seconds
}
fundsRemaining -= price
}
return seconds
}

// Calculate the number of seconds that it would take to charge at least [cost]
// at [price] every second. The result is capped at [maxSeconds].
func secondsUntil(price uint64, maxSeconds uint64, cost uint64) uint64 {
// Directly rounding up could cause an overflow. Instead we round down and
// then check if we should have rounded up.
secondsRoundedDown := cost / price
if secondsRoundedDown >= maxSeconds {
return maxSeconds
}
if cost%price == 0 {
return secondsRoundedDown
}
return secondsRoundedDown + 1
return maxSeconds
}
Loading

0 comments on commit 860fefd

Please # to comment.