Skip to content

Commit

Permalink
Merge pull request #92 from blukat29/override-deprecated-gov-params
Browse files Browse the repository at this point in the history
governance: APIs override deprecated parameters
  • Loading branch information
blukat29 authored Sep 19, 2024
2 parents a1aef81 + 8f0d18c commit 9537d89
Showing 1 changed file with 45 additions and 1 deletion.
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

0 comments on commit 9537d89

Please sign in to comment.