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

kaiax/gov: Rename getters #184

Merged
merged 12 commits into from
Dec 26, 2024
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type dummyGovModule struct {
chainConfig *params.ChainConfig
}

func (d *dummyGovModule) EffectiveParamSet(blockNum uint64) gov.ParamSet {
func (d *dummyGovModule) GetParamSet(blockNum uint64) gov.ParamSet {
return gov.ParamSet{UnitPrice: d.chainConfig.UnitPrice}
}

Expand Down
6 changes: 3 additions & 3 deletions blockchain/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (config *TxPoolConfig) sanitize() TxPoolConfig {
}

type GovModule interface {
EffectiveParamSet(blockNum uint64) gov.ParamSet
GetParamSet(blockNum uint64) gov.ParamSet
}

// TxPool contains all currently known transactions. Transactions
Expand Down Expand Up @@ -233,7 +233,7 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
// Sanitize the input to ensure no vulnerable gas prices are set
config = (&config).sanitize()

pset := govModule.EffectiveParamSet(chain.CurrentBlock().NumberU64() + 1)
pset := govModule.GetParamSet(chain.CurrentBlock().NumberU64() + 1)

// Create the transaction pool with its initial settings
pool := &TxPool{
Expand Down Expand Up @@ -502,7 +502,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {

// It needs to update gas price of tx pool since magma hardfork
if pool.rules.IsMagma {
pset := pool.govModule.EffectiveParamSet(newHead.Number.Uint64() + 1)
pset := pool.govModule.GetParamSet(newHead.Number.Uint64() + 1)
pool.gasPrice = misc.NextMagmaBlockBaseFee(newHead, pset.ToKip71Config())
}
}
Expand Down
2 changes: 1 addition & 1 deletion blockchain/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type dummyGovModule struct {
chainConfig *params.ChainConfig
}

func (m *dummyGovModule) EffectiveParamSet(blockNum uint64) gov.ParamSet {
func (m *dummyGovModule) GetParamSet(blockNum uint64) gov.ParamSet {
return gov.ParamSet{UnitPrice: m.chainConfig.UnitPrice}
}

Expand Down
2 changes: 1 addition & 1 deletion blockchain/types/derivesha/derive_sha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var testGovSchedule = map[uint64]int{
8: types.ImplDeriveShaConcat,
}

func (e *testGov) EffectiveParamSet(num uint64) gov.ParamSet {
func (e *testGov) GetParamSet(num uint64) gov.ParamSet {
return gov.ParamSet{
DeriveShaImpl: uint64(testGovSchedule[num]),
}
Expand Down
4 changes: 2 additions & 2 deletions blockchain/types/derivesha/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type IDeriveSha interface {
}

type GovModule interface {
EffectiveParamSet(num uint64) gov.ParamSet
GetParamSet(num uint64) gov.ParamSet
}

var (
Expand Down Expand Up @@ -85,7 +85,7 @@ func getType(num *big.Int) int {
// and unit tests. govModule != nil if blockchain.InitDeriveShaWithGov is used,
// in ordinary blockchain processing.
if govModule != nil {
pset := govModule.EffectiveParamSet(num.Uint64())
pset := govModule.GetParamSet(num.Uint64())
implType = int(pset.DeriveShaImpl)
}

Expand Down
6 changes: 3 additions & 3 deletions consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (sb *backend) verifyHeader(chain consensus.ChainReader, header *types.Heade
if chain.Config().IsMagmaForkEnabled(header.Number) {
// the kip71Config used when creating the block number is a previous block config.
blockNum := header.Number.Uint64()
pset := sb.govModule.EffectiveParamSet(blockNum)
pset := sb.govModule.GetParamSet(blockNum)
kip71 := pset.ToKip71Config()
if err := misc.VerifyMagmaHeader(parents[len(parents)-1], header, kip71); err != nil {
return err
Expand Down Expand Up @@ -427,7 +427,7 @@ func (sb *backend) Prepare(chain consensus.ChainReader, header *types.Header) er
header.BlockScore = defaultBlockScore

// If it reaches the Epoch, governance config will be added to block header
pset := sb.govModule.EffectiveParamSet(number)
pset := sb.govModule.GetParamSet(number)
if number%pset.Epoch == 0 {
if g := sb.governance.GetGovernanceChange(); g != nil {
if data, err := json.Marshal(g); err != nil {
Expand Down Expand Up @@ -778,7 +778,7 @@ func (sb *backend) initSnapshot(chain consensus.ChainReader) (*Snapshot, error)
return nil, err
}

pset := sb.govModule.EffectiveParamSet(0)
pset := sb.govModule.GetParamSet(0)
valSet := validator.NewValidatorSet(istanbulExtra.Validators, nil,
istanbul.ProposerPolicy(pset.ProposerPolicy),
pset.CommitteeSize, chain)
Expand Down
18 changes: 9 additions & 9 deletions consensus/istanbul/backend/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,8 @@ func TestRewardDistribution(t *testing.T) {
chain.RegisterExecutionModule(engine.govModule)
defer engine.Stop()

assert.Equal(t, uint64(testEpoch), engine.govModule.EffectiveParamSet(0).Epoch)
assert.Equal(t, mintAmount, engine.govModule.EffectiveParamSet(0).MintingAmount.Uint64())
assert.Equal(t, uint64(testEpoch), engine.govModule.GetParamSet(0).Epoch)
assert.Equal(t, mintAmount, engine.govModule.GetParamSet(0).MintingAmount.Uint64())

var previousBlock, currentBlock *types.Block = nil, chain.Genesis()

Expand Down Expand Up @@ -1744,7 +1744,7 @@ func TestGovernance_Votes(t *testing.T) {
chain.RegisterExecutionModule(engine.valsetModule, engine.govModule)

// test initial governance items
pset := engine.govModule.EffectiveParamSet(chain.CurrentHeader().Number.Uint64() + 1)
pset := engine.govModule.GetParamSet(chain.CurrentHeader().Number.Uint64() + 1)
assert.Equal(t, uint64(3), pset.Epoch)
assert.Equal(t, "single", pset.GovernanceMode)
assert.Equal(t, uint64(21), pset.CommitteeSize)
Expand Down Expand Up @@ -1787,7 +1787,7 @@ func TestGovernance_Votes(t *testing.T) {
if blockNumber == 0 {
blockNumber = chain.CurrentBlock().NumberU64()
}
partialParamSet := engine.govModule.(*gov_impl.GovModule).Hgm.EffectiveParamsPartial(blockNumber + 1)
partialParamSet := engine.govModule.(*gov_impl.GovModule).Hgm.GetPartialParamSet(blockNumber + 1)
switch val := partialParamSet[gov.ParamName(item.key)]; v := val.(type) {
case *big.Int:
require.Equal(t, item.value, v.String())
Expand All @@ -1802,7 +1802,7 @@ func TestGovernance_Votes(t *testing.T) {
}

func TestGovernance_GovModule(t *testing.T) {
// Test that ReaderEngine (CurrentParams(), EffectiveParamSet(), UpdateParams()) works.
// Test that ReaderEngine (CurrentParams(), GetParamSet(), UpdateParams()) works.
type vote struct {
name string
value interface{}
Expand Down Expand Up @@ -1856,7 +1856,7 @@ func TestGovernance_GovModule(t *testing.T) {
for num := 0; num <= tc.length; num++ {
// Validate current params with CurrentParams() and CurrentSetCopy().
// Check that both returns the expected result.
pset := engine.govModule.EffectiveParamSet(uint64(num + 1))
pset := engine.govModule.GetParamSet(uint64(num + 1))
assertMapSubset(t, tc.expected[num+1], pset.ToGovParamSet().StrMap())

// Place a vote if a vote is scheduled in upcoming block
Expand All @@ -1874,14 +1874,14 @@ func TestGovernance_GovModule(t *testing.T) {
assert.NoError(t, err)
}

// Validate historic parameters with EffectiveParamSet() and EffectiveParamsPartial().
// Validate historic parameters with GetParamSet() and GetPartialParamSet().
// Check that both returns the expected result.
for num := 0; num <= tc.length; num++ {
pset := engine.govModule.EffectiveParamSet(uint64(num))
pset := engine.govModule.GetParamSet(uint64(num))
assertMapSubset(t, tc.expected[num], pset.ToGovParamSet().StrMap())

partialParamSet := make(map[string]any)
for k, v := range engine.govModule.(*gov_impl.GovModule).Hgm.EffectiveParamsPartial(uint64(num + 1)) {
for k, v := range engine.govModule.(*gov_impl.GovModule).Hgm.GetPartialParamSet(uint64(num + 1)) {
partialParamSet[string(k)] = v
}
assertMapSubset(t, tc.expected[num+1], partialParamSet)
Expand Down
6 changes: 3 additions & 3 deletions consensus/istanbul/backend/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Snapshot struct {
}

func effectiveParams(g gov.GovModule, number uint64) (epoch uint64, policy uint64, committeeSize uint64) {
pset := g.EffectiveParamSet(number)
pset := g.GetParamSet(number)
epoch = pset.Epoch
policy = pset.ProposerPolicy
committeeSize = pset.CommitteeSize
Expand Down Expand Up @@ -194,7 +194,7 @@ func (s *Snapshot) apply(headers []*types.Header, gov governance.Engine, govModu
// Refresh proposers in Snapshot_N using previous proposersUpdateInterval block for N+1, if not updated yet.

// because snapshot(num)'s ValSet = validators for num+1
pset := govModule.EffectiveParamSet(number + 1)
pset := govModule.GetParamSet(number + 1)

isSingle := (pset.GovernanceMode == "single")
govNode := pset.GoverningNode
Expand Down Expand Up @@ -456,7 +456,7 @@ func (sb *backend) snapshot(chain consensus.ChainReader, number uint64, hash com
return nil, err
}

pset := sb.govModule.EffectiveParamSet(snap.Number)
pset := sb.govModule.GetParamSet(snap.Number)
snap, err = snap.apply(headers, sb.governance, sb.govModule, sb.address, pset.ProposerPolicy, chain, sb.stakingModule, writable)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion consensus/istanbul/backend/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (sb *backend) GetCommitteeStateByRound(num uint64, round uint64) (*istanbul
return nil, err
}

committeeSize := sb.govModule.EffectiveParamSet(num).CommitteeSize
committeeSize := sb.govModule.GetParamSet(num).CommitteeSize
return istanbul.NewRoundCommitteeState(blockValSet, committeeSize, committee, proposer), nil
}

Expand Down
14 changes: 7 additions & 7 deletions kaiax/gov/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ It's essentially a setting that can be adjusted to fine-tune how the network ope
These parameters could control stuff like transaction fees, inflation rate, reward distribution, etc.
A governance parameter has a name and a value; see [./param.go](./param.go).

`EffectiveParamSet(blockNum)` returns the governance parameter set that are used for mining the given block.
For example, if `EffectiveParamSet(10000)` is `{UnitPrice: 25 kei, ...}`, it indicates that the unit price will be 25 kei when mining the 10000th block.
`GetParamSet(blockNum)` returns the governance parameter set that are used for mining the given block.
For example, if `GetParamSet(10000)` is `{UnitPrice: 25 kei, ...}`, it indicates that the unit price will be 25 kei when mining the 10000th block.

Here are the list of governance parameters:

Expand Down Expand Up @@ -45,12 +45,12 @@ reward.useginicoeff: true
This module utilizes [header governance](./headergov/README.md) and [contract governance](./contractgov/README.md) underneath to fetch the parameter set and to handle governance parameter updates.

```
EffectiveParamSet(blockNum):
GetParamSet(blockNum):
ret := defaultParamSet()
merge ret with fallback (ChainConfig)
merge ret with HeaderGov.EffectiveParamSet(blockNum)
merge ret with HeaderGov.GetParamSet(blockNum)
if blockNum is post-Kore-HF:
merge ret with ContractGov.EffectiveParamSet(blockNum)
merge ret with ContractGov.GetParamSet(blockNum)
return ret
```

Expand Down Expand Up @@ -218,7 +218,7 @@ curl "http://localhost:8551" -X POST -H 'Content-Type: application/json' --data

## Getters

- `EffectiveParamSet(num)`: Returns the effective parameter set at the block `num`.
- `GetParamSet(num)`: Returns the effective parameter set at the block `num`.
```
EffectiveParamSet(num) -> ParamSet
GetParamSet(num) -> ParamSet
```
11 changes: 6 additions & 5 deletions kaiax/gov/contractgov/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# kaiax/gov/contractgov

This module is responsible for providing the governance parameter set from **contract governance** at a given block number.
This module is not meant to be used by any modules except for gov.

## Concepts

Expand All @@ -9,7 +10,7 @@ Please read [gov module](../README.md) and [header governance](../headergov/READ
### Key Concepts

- _GovParam contract_: a contract that stores the governance parameters.
- _effective parameter set at blockNum_: the governance parameter set that are effective when mining the given block.
- _parameter set at blockNum_: the governance parameter set that are effective when mining the given block.

### Contract governance

Expand Down Expand Up @@ -84,13 +85,13 @@ curl "http://localhost:8551" -X POST -H 'Content-Type: application/json' --data

## Getters

- `EffectiveParamSet(num)`: Returns the effective parameter set at the block `num`. Those not specified in the contract are filled with defaults (defined [here](../param.go)).
- `GetParamSet(num)`: Returns the effective parameter set at the block `num`. Those not specified in the contract are filled with defaults (defined [here](../param.go)).

```
EffectiveParamSet(num) -> ParamSet
GetParamSet(num) -> ParamSet
```

- `EffectiveParamsPartial(num)`: Returns only the parameters effective by GovParam contract at the block `num`. It is used for assembling parameters in a gov module.
- `GetPartialParamSet(num)`: Returns only the parameters effective by GovParam contract at the block `num`. It is used for assembling parameters in a gov module.
```
EffectiveParamsPartial(num) -> PartialParamSet
GetPartialParamSet(num) -> PartialParamSet
```
2 changes: 1 addition & 1 deletion kaiax/gov/contractgov/impl/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (api *contractGovAPI) GetContractParams(num rpc.BlockNumber, govParam *comm
govParamAddr = *govParam
} else {
// Use default GovParam address from headergov
govParamAddr = api.c.Hgm.EffectiveParamSet(blockNum).GovParamContract
govParamAddr = api.c.Hgm.GetParamSet(blockNum).GovParamContract
}

params, err := api.c.contractGetAllParamsAtFromAddr(blockNum, govParamAddr)
Expand Down
2 changes: 1 addition & 1 deletion kaiax/gov/contractgov/impl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

var (
ErrNotReady = errors.New("ContractEngine is not ready")
ErrHeaderGovFail = errors.New("headerGov EffectiveParamSet() failed")
ErrHeaderGovFail = errors.New("headerGov GetParamSet() failed")
)

func errInitNil(msg string) error {
Expand Down
8 changes: 4 additions & 4 deletions kaiax/gov/contractgov/impl/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/kaiachain/kaia/kaiax/gov"
)

// EffectiveParamSet returns default parameter set in case of the following errors:
// GetParamSet returns default parameter set in case of the following errors:
// (1) contractgov is disabled (i.e., pre-Kore or GovParam address is zero)
// (2) GovParam address is not set
// (3) Contract call to GovParam failed
// Invalid parameters in the contract (i.e., invalid parameter name or non-canonical value) are ignored.
func (c *contractGovModule) EffectiveParamSet(blockNum uint64) gov.ParamSet {
func (c *contractGovModule) GetParamSet(blockNum uint64) gov.ParamSet {
m, err := c.contractGetAllParamsAt(blockNum)
if err != nil {
return *gov.GetDefaultGovernanceParamSet()
Expand All @@ -31,7 +31,7 @@ func (c *contractGovModule) EffectiveParamSet(blockNum uint64) gov.ParamSet {
return ret
}

func (c *contractGovModule) EffectiveParamsPartial(blockNum uint64) gov.PartialParamSet {
func (c *contractGovModule) GetPartialParamSet(blockNum uint64) gov.PartialParamSet {
m, err := c.contractGetAllParamsAt(blockNum)
if err != nil {
return nil
Expand Down Expand Up @@ -85,7 +85,7 @@ func (c *contractGovModule) contractGetAllParamsAtFromAddr(blockNum uint64, addr
}

func (c *contractGovModule) contractAddrAt(blockNum uint64) (common.Address, error) {
headerParams := c.Hgm.EffectiveParamSet(blockNum)
headerParams := c.Hgm.GetParamSet(blockNum)
return headerParams.GovParamContract, nil
}

Expand Down
8 changes: 4 additions & 4 deletions kaiax/gov/contractgov/impl/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func prepareContractGovModule(t *testing.T, bc *blockchain.BlockChain, addr comm
Hgm: mockHGM,
})
require.Nil(t, err)
mockHGM.EXPECT().EffectiveParamSet(gomock.Any()).Return(gov.ParamSet{GovParamContract: addr}).AnyTimes()
mockHGM.EXPECT().GetParamSet(gomock.Any()).Return(gov.ParamSet{GovParamContract: addr}).AnyTimes()
return cgm
}

func TestEffectiveParamSet(t *testing.T) {
func TestGetParamSet(t *testing.T) {
log.EnableLogForTest(log.LvlCrit, log.LvlError)
paramName := string(gov.GovernanceUnitPrice)
accounts, sim, addr, gp := createSimulateBackend(t)
Expand All @@ -86,7 +86,7 @@ func TestEffectiveParamSet(t *testing.T) {
require.NotNil(t, receipt)
require.Equal(t, types.ReceiptStatusSuccessful, receipt.Status)

ps := cgm.EffectiveParamSet(activation.Uint64())
ps := cgm.GetParamSet(activation.Uint64())
assert.NotNil(t, ps)
assert.Equal(t, uint64(25), ps.UnitPrice)
}
Expand All @@ -102,7 +102,7 @@ func TestEffectiveParamSet(t *testing.T) {
require.NotNil(t, receipt)
require.Equal(t, types.ReceiptStatusSuccessful, receipt.Status)

ps := cgm.EffectiveParamSet(activation.Uint64())
ps := cgm.GetParamSet(activation.Uint64())
assert.NotNil(t, ps)
assert.Equal(t, uint64(125), ps.UnitPrice)
}
Expand Down
4 changes: 2 additions & 2 deletions kaiax/gov/contractgov/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ type ContractGovModule interface {
kaiax.BaseModule
kaiax.JsonRpcModule

EffectiveParamSet(blockNum uint64) gov.ParamSet
EffectiveParamsPartial(blockNum uint64) gov.PartialParamSet
GetParamSet(blockNum uint64) gov.ParamSet
GetPartialParamSet(blockNum uint64) gov.PartialParamSet
}
Loading
Loading