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

governance: APIs override deprecated parameters #92

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
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
46 changes: 45 additions & 1 deletion governance/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,32 @@ func getParams(governance Engine, num *rpc.BlockNumber) (map[string]interface{},
if err != nil {
return nil, err
}
return pset.StrMap(), nil
sm := pset.StrMap()

// To avoid confusion, override some parameters that are deprecated after hardforks.
// e.g., stakingupdateinterval is shown as 86400 but actually irrelevant (i.e. updated every block)
rule := governance.BlockChain().Config().Rules(new(big.Int).SetUint64(blockNumber))
if rule.IsKore {
// Gini option deprecated since Kore, as All committee members have an equal chance
// of being elected block proposers.
if _, ok := sm["reward.useginicoeff"]; ok {
sm["reward.useginicoeff"] = false
}
}
if rule.IsRandao {
// Block proposer is randomly elected at every block with Randao,
// no more precalculated proposer list.
if _, ok := sm["reward.proposerupdateinterval"]; ok {
sm["reward.proposerupdateinterval"] = 1
}
}
if rule.IsKaia {
// Staking information updated every block since Kaia.
if _, ok := sm["reward.stakingupdateinterval"]; ok {
sm["reward.stakingupdateinterval"] = 1
}
}
return sm, nil
}

func (api *GovernanceAPI) GetStakingInfo(num *rpc.BlockNumber) (*reward.StakingInfo, error) {
Expand Down Expand Up @@ -448,6 +473,7 @@ func getChainConfig(governance Engine, num *rpc.BlockNumber) *params.ChainConfig
return nil
}

// Fill in the non-governance-parameter fields of ChainConfig
latestConfig := governance.BlockChain().Config()
config := pset.ToChainConfig()
config.ChainID = latestConfig.ChainID
Expand All @@ -465,6 +491,24 @@ func getChainConfig(governance Engine, num *rpc.BlockNumber) *params.ChainConfig
config.Kip160ContractAddress = latestConfig.Kip160ContractAddress
config.RandaoCompatibleBlock = latestConfig.RandaoCompatibleBlock

// To avoid confusion, override some parameters that are deprecated after hardforks.
// e.g., stakingupdateinterval is shown as 86400 but actually irrelevant (i.e. updated every block)
rule := governance.BlockChain().Config().Rules(new(big.Int).SetUint64(blocknum))
if rule.IsKore {
// Gini option deprecated since Kore, as All committee members have an equal chance
// of being elected block proposers.
config.Governance.Reward.UseGiniCoeff = false
}
if rule.IsRandao {
// Block proposer is randomly elected at every block with Randao,
// no more precalculated proposer list.
config.Governance.Reward.ProposerUpdateInterval = 1
}
if rule.IsKaia {
// Staking information updated every block since Kaia.
config.Governance.Reward.StakingUpdateInterval = 1
}

return config
}

Expand Down
Loading