The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/internal/configs/sharding/partner.go

99 lines
3.4 KiB

package shardingconfig
import (
"math/big"
"github.com/harmony-one/harmony/numeric"
"github.com/harmony-one/harmony/internal/genesis"
"github.com/harmony-one/harmony/internal/params"
)
// PartnerSchedule is the long-running public partner sharding
// configuration schedule.
var PartnerSchedule partnerSchedule
core, internal/configs: HIP28-v2 fee collection (#4410) * core, internal/configs: HIP28-v2 fee collection Based on the Snapshot vote that has passed, collect 50% of the fee to a community maintained account and the remainder to an account used to pay for infrastructure costs. Note that these accounts need to be decided and set in the code at this moment, and the feature needs to be activated by setting the `FeeCollectEpoch` of the `ChainConfig` object. The implementation for devnet is a bit different than compared to others because the feature was activated on devnet with 100% collection to an account. I have handled this case separately in `devnet.go`. * test: add test for StateTransition.ApplyMessage The objective of this unit test is to check that the fees of a transaction are appropriately credited to the fee collectors that are set. This means, for a transaction of 21,000 gas limit and 100 gwei gas price, two equal fee collectors get 10,500 * 100 gwei each. In addition, to be clear that the refund mechanism (in case a transaction with extra gas comes in) works, the tested transaction has a 50,000 gas limit of which only 21,000 gas limit is actually consumed. * sharding/config: clarify local fee collector pk * sharding/config: set testnet fee collector same as devnet * test: add test for truncated fee distribution * sharding/config: set fee collector addresses * test: hardcode the expected fee collected * goimports * params/config: set testnet fee collect epoch Schedule testnet hard fork epoch to be 1296, which begins around the time 2023-04-28 07:14:20+00:00 * params/config: schedule devnee fee collection Signed-off-by: MaxMustermann2 <82761650+MaxMustermann2@users.noreply.github.com>
2 years ago
var feeCollectEpochV1 = big.NewInt(574)
var feeCollectorsDevnet = []FeeCollectors{
FeeCollectors{
mustAddress("0xb728AEaBF60fD01816ee9e756c18bc01dC91ba5D"): numeric.OneDec(),
},
FeeCollectors{
mustAddress("0xb728AEaBF60fD01816ee9e756c18bc01dC91ba5D"): numeric.MustNewDecFromStr("0.5"),
mustAddress("0xb41B6B8d9e68fD44caC8342BC2EEf4D59531d7d7"): numeric.MustNewDecFromStr("0.5"),
},
}
type partnerSchedule struct{}
const (
// 12 hours per epoch (at 2s/block)
partnerBlocksPerEpoch = 21600
partnerVdfDifficulty = 10000 // This takes about 20s to finish the vdf
// PartnerHTTPPattern is the http pattern for partner.
PartnerHTTPPattern = "https://api.s%d.ps.hmny.io"
// PartnerWSPattern is the websocket pattern for partner.
PartnerWSPattern = "wss://ws.s%d.ps.hmny.io"
)
func (ps partnerSchedule) InstanceForEpoch(epoch *big.Int) Instance {
switch {
case params.PartnerChainConfig.IsFeeCollectEpoch(epoch):
core, internal/configs: HIP28-v2 fee collection (#4410) * core, internal/configs: HIP28-v2 fee collection Based on the Snapshot vote that has passed, collect 50% of the fee to a community maintained account and the remainder to an account used to pay for infrastructure costs. Note that these accounts need to be decided and set in the code at this moment, and the feature needs to be activated by setting the `FeeCollectEpoch` of the `ChainConfig` object. The implementation for devnet is a bit different than compared to others because the feature was activated on devnet with 100% collection to an account. I have handled this case separately in `devnet.go`. * test: add test for StateTransition.ApplyMessage The objective of this unit test is to check that the fees of a transaction are appropriately credited to the fee collectors that are set. This means, for a transaction of 21,000 gas limit and 100 gwei gas price, two equal fee collectors get 10,500 * 100 gwei each. In addition, to be clear that the refund mechanism (in case a transaction with extra gas comes in) works, the tested transaction has a 50,000 gas limit of which only 21,000 gas limit is actually consumed. * sharding/config: clarify local fee collector pk * sharding/config: set testnet fee collector same as devnet * test: add test for truncated fee distribution * sharding/config: set fee collector addresses * test: hardcode the expected fee collected * goimports * params/config: set testnet fee collect epoch Schedule testnet hard fork epoch to be 1296, which begins around the time 2023-04-28 07:14:20+00:00 * params/config: schedule devnee fee collection Signed-off-by: MaxMustermann2 <82761650+MaxMustermann2@users.noreply.github.com>
2 years ago
return partnerV3
case epoch.Cmp(feeCollectEpochV1) >= 0:
return partnerV2
case epoch.Cmp(params.PartnerChainConfig.StakingEpoch) >= 0:
return partnerV1
default: // genesis
return partnerV0
}
}
func (ps partnerSchedule) BlocksPerEpoch() uint64 {
return partnerBlocksPerEpoch
}
func (ps partnerSchedule) CalcEpochNumber(blockNum uint64) *big.Int {
epoch := blockNum / ps.BlocksPerEpoch()
return big.NewInt(int64(epoch))
}
func (ps partnerSchedule) IsLastBlock(blockNum uint64) bool {
return (blockNum+1)%ps.BlocksPerEpoch() == 0
}
func (ps partnerSchedule) EpochLastBlock(epochNum uint64) uint64 {
return ps.BlocksPerEpoch()*(epochNum+1) - 1
}
func (ps partnerSchedule) VdfDifficulty() int {
return partnerVdfDifficulty
}
func (ps partnerSchedule) GetNetworkID() NetworkID {
return Partner
}
// GetShardingStructure is the sharding structure for partner.
func (ps partnerSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} {
return genShardingStructure(numShard, shardID, PartnerHTTPPattern, PartnerWSPattern)
}
// IsSkippedEpoch returns if an epoch was skipped on shard due to staking epoch
func (ps partnerSchedule) IsSkippedEpoch(shardID uint32, epoch *big.Int) bool {
return false
}
var partnerReshardingEpoch = []*big.Int{
big.NewInt(0),
params.PartnerChainConfig.StakingEpoch,
}
core, internal/configs: HIP28-v2 fee collection (#4410) * core, internal/configs: HIP28-v2 fee collection Based on the Snapshot vote that has passed, collect 50% of the fee to a community maintained account and the remainder to an account used to pay for infrastructure costs. Note that these accounts need to be decided and set in the code at this moment, and the feature needs to be activated by setting the `FeeCollectEpoch` of the `ChainConfig` object. The implementation for devnet is a bit different than compared to others because the feature was activated on devnet with 100% collection to an account. I have handled this case separately in `devnet.go`. * test: add test for StateTransition.ApplyMessage The objective of this unit test is to check that the fees of a transaction are appropriately credited to the fee collectors that are set. This means, for a transaction of 21,000 gas limit and 100 gwei gas price, two equal fee collectors get 10,500 * 100 gwei each. In addition, to be clear that the refund mechanism (in case a transaction with extra gas comes in) works, the tested transaction has a 50,000 gas limit of which only 21,000 gas limit is actually consumed. * sharding/config: clarify local fee collector pk * sharding/config: set testnet fee collector same as devnet * test: add test for truncated fee distribution * sharding/config: set fee collector addresses * test: hardcode the expected fee collected * goimports * params/config: set testnet fee collect epoch Schedule testnet hard fork epoch to be 1296, which begins around the time 2023-04-28 07:14:20+00:00 * params/config: schedule devnee fee collection Signed-off-by: MaxMustermann2 <82761650+MaxMustermann2@users.noreply.github.com>
2 years ago
var partnerV0 = MustNewInstance(2, 5, 5, 0, numeric.OneDec(), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, nil, partnerReshardingEpoch, PartnerSchedule.BlocksPerEpoch())
var partnerV1 = MustNewInstance(2, 5, 4, 0, numeric.MustNewDecFromStr("0.9"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, nil, partnerReshardingEpoch, PartnerSchedule.BlocksPerEpoch())
var partnerV2 = MustNewInstance(2, 5, 4, 0, numeric.MustNewDecFromStr("0.9"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, feeCollectorsDevnet[0], partnerReshardingEpoch, PartnerSchedule.BlocksPerEpoch())
var partnerV3 = MustNewInstance(2, 5, 4, 0, numeric.MustNewDecFromStr("0.9"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, feeCollectorsDevnet[1], partnerReshardingEpoch, PartnerSchedule.BlocksPerEpoch())