-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the limit per fee currency
- Loading branch information
Valentin Rodygin
committed
Oct 30, 2023
1 parent
a59dd19
commit 4e8b821
Showing
6 changed files
with
144 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package core | ||
|
||
import ( | ||
// "fmt" | ||
// "math" | ||
|
||
"github.com/celo-org/celo-blockchain/common" | ||
) | ||
|
||
type FeeCurrency = common.Address | ||
|
||
// MultiGasPool tracks the amount of gas available during execution | ||
// of the transactions in a block per fee currency. The zero value is a pool | ||
// with zero gas available. | ||
type MultiGasPool struct { | ||
pools map[FeeCurrency]*GasPool | ||
defaultPool *GasPool | ||
} | ||
|
||
type FeeCurrencyLimitMapping = map[FeeCurrency]float64 | ||
|
||
func NewMultiGasPool( | ||
block_gas_limit uint64, | ||
whitelist []FeeCurrency, | ||
defaultLimit float64, | ||
limitsMapping FeeCurrencyLimitMapping, | ||
) MultiGasPool { | ||
pools := make(map[FeeCurrency]*GasPool, len(whitelist)) | ||
|
||
for i := range whitelist { | ||
currency := whitelist[i] | ||
fraction, ok := limitsMapping[currency] | ||
if !ok { | ||
fraction = defaultLimit | ||
} | ||
|
||
pools[currency] = new(GasPool).AddGas( | ||
uint64(float64(block_gas_limit) * fraction), | ||
) | ||
} | ||
|
||
// A special case for CELO which doesn't have a limit | ||
celoPool := new(GasPool).AddGas(block_gas_limit) | ||
|
||
return MultiGasPool{ | ||
pools: pools, | ||
defaultPool: celoPool, | ||
} | ||
} | ||
|
||
func (mgp MultiGasPool) PoolFor(feeCurrency *FeeCurrency) *GasPool { | ||
if feeCurrency == nil || mgp.pools[*feeCurrency] == nil { | ||
return mgp.defaultPool | ||
} | ||
|
||
return mgp.pools[*feeCurrency] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters