Skip to content

Commit

Permalink
Remove unused parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Mar 12, 2024
1 parent c85df85 commit 8fac1d0
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 22 deletions.
1 change: 0 additions & 1 deletion consensus/polybft/consensus_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ func (c *consensusRuntime) initStakeManager(logger hcf.Logger, dbTx *bolt.Tx) er
func (c *consensusRuntime) initGovernanceManager(logger hcf.Logger, dbTx *bolt.Tx) error {
governanceManager, err := newGovernanceManager(
c.config.genesisParams,
c.config.GenesisConfig,
logger.Named("governance-manager"),
c.state,
c.config.blockchain,
Expand Down
8 changes: 4 additions & 4 deletions consensus/polybft/governance_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type governanceManager struct {
}

// newGovernanceManager is a constructor function for governance manager
func newGovernanceManager(genesisParams *chain.Params, genesisConfig *PolyBFTConfig,
func newGovernanceManager(genesisParams *chain.Params,
logger hclog.Logger,
state *State,
blockhain blockchainBackend,
Expand Down Expand Up @@ -459,7 +459,7 @@ func isForkParamsEvent(event contractsapi.EventAbi) (types.Hash, *big.Int, bool)
}

// parseGovernanceEvent parses provided log to correct governance event
func parseGovernanceEvent(h *types.Header, log *ethgo.Log) (contractsapi.EventAbi, bool, error) {
func parseGovernanceEvent(log *ethgo.Log) (contractsapi.EventAbi, bool, error) {
var (
checkpointIntervalEvent contractsapi.NewCheckpointBlockIntervalEvent
epochSizeEvent contractsapi.NewEpochSizeEvent
Expand Down Expand Up @@ -546,7 +546,7 @@ func (g *governanceManager) GetLogFilters() map[types.Address][]types.Hash {
}

func (g *governanceManager) ProcessLog(header *types.Header, log *ethgo.Log, dbTx *bolt.Tx) error {
event, isGovernanceEvent, err := parseGovernanceEvent(header, log)
event, isGovernanceEvent, err := parseGovernanceEvent(log)
if err != nil {
return err
}
Expand All @@ -567,7 +567,7 @@ func (g *governanceManager) ProcessLog(header *types.Header, log *ethgo.Log, dbT
)

return g.state.GovernanceStore.insertGovernanceEvent(
extra.Checkpoint.EpochNumber, header.Number, event, dbTx)
extra.Checkpoint.EpochNumber, event, dbTx)
}

// unmarshalGovernanceEvent unmarshals given raw event to desired type
Expand Down
10 changes: 5 additions & 5 deletions consensus/polybft/governance_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func TestGovernanceManager_PostEpoch(t *testing.T) {
baseFeeChangeDenomEvent := &contractsapi.NewBaseFeeChangeDenomEvent{BaseFeeChangeDenom: big.NewInt(100)}
epochRewardEvent := &contractsapi.NewEpochRewardEvent{Reward: big.NewInt(10000)}

require.NoError(t, state.GovernanceStore.insertGovernanceEvent(1, 7, baseFeeChangeDenomEvent, nil))
require.NoError(t, state.GovernanceStore.insertGovernanceEvent(1, 7, epochRewardEvent, nil))
require.NoError(t, state.GovernanceStore.insertGovernanceEvent(1, baseFeeChangeDenomEvent, nil))
require.NoError(t, state.GovernanceStore.insertGovernanceEvent(1, epochRewardEvent, nil))

// no initial config was saved, so we expect an error
require.ErrorIs(t, governanceManager.PostEpoch(&PostEpochRequest{
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestGovernanceManager_PostBlock(t *testing.T) {
})

chainParams := &chain.Params{Engine: map[string]interface{}{ConsensusName: genesisPolybftConfig}}
governanceManager, err := newGovernanceManager(chainParams, genesisPolybftConfig,
governanceManager, err := newGovernanceManager(chainParams,
hclog.NewNullLogger(), state, blockchainMock, nil)
require.NoError(t, err)

Expand Down Expand Up @@ -122,14 +122,14 @@ func TestGovernanceManager_PostBlock(t *testing.T) {
})

chainParams := &chain.Params{Engine: map[string]interface{}{ConsensusName: genesisPolybftConfig}}
governanceManager, err := newGovernanceManager(chainParams, genesisPolybftConfig,
governanceManager, err := newGovernanceManager(chainParams,
hclog.NewNullLogger(), state, blockchainMock, nil)
require.NoError(t, err)

// this cheats that we have this fork in code
governanceManager.allForksHashes[newForkHash] = newForkName

require.NoError(t, state.GovernanceStore.insertGovernanceEvent(1, newForkBlock.Uint64(),
require.NoError(t, state.GovernanceStore.insertGovernanceEvent(1,
&contractsapi.NewFeatureEvent{
Feature: newForkHash, Block: newForkBlock,
}, nil))
Expand Down
3 changes: 1 addition & 2 deletions consensus/polybft/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/consensus/polybft/wallet"
"github.com/0xPolygon/polygon-edge/types"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -155,7 +154,7 @@ func newTestState(tb testing.TB) *State {
tb.Fatal(err)
}

state, err := newState(path.Join(dir, "my.db"), hclog.NewNullLogger(), make(chan struct{}))
state, err := newState(path.Join(dir, "my.db"), make(chan struct{}))
if err != nil {
tb.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/polybft/polybft.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func (p *Polybft) Initialize() error {
return fmt.Errorf("failed to create data directory. Error: %w", err)
}

stt, err := newState(filepath.Join(p.dataDir, stateFileName), p.logger, p.closeCh)
stt, err := newState(filepath.Join(p.dataDir, stateFileName), p.closeCh)
if err != nil {
return fmt.Errorf("failed to create state instance. Error: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions consensus/polybft/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/hashicorp/go-hclog"
bolt "go.etcd.io/bbolt"
)

Expand Down Expand Up @@ -47,7 +46,7 @@ type State struct {
}

// newState creates new instance of State
func newState(path string, logger hclog.Logger, closeCh chan struct{}) (*State, error) {
func newState(path string, closeCh chan struct{}) (*State, error) {
db, err := bolt.Open(path, 0666, nil)
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions consensus/polybft/state_store_governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ func (g *GovernanceStore) initialize(tx *bolt.Tx) error {

// insertGovernanceEvent inserts governance event to bolt db
// each epoch has a list of events that happened in it
func (g *GovernanceStore) insertGovernanceEvent(epoch, block uint64,
event contractsapi.EventAbi, dbTx *bolt.Tx) error {
func (g *GovernanceStore) insertGovernanceEvent(epoch uint64, event contractsapi.EventAbi, dbTx *bolt.Tx) error {
insertFn := func(tx *bolt.Tx) error {
if forkHash, forkBlock, isForkEvent := isForkParamsEvent(event); isForkEvent {
forkParamsBucket := tx.Bucket(forkParamsEventsBucket)
Expand Down
7 changes: 3 additions & 4 deletions consensus/polybft/state_store_governance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func TestGovernanceStore_InsertAndGetEvents(t *testing.T) {
t.Parallel()

epoch := uint64(11)
block := uint64(111)
state := newTestState(t)

// NetworkParams events
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestGovernanceStore_InsertAndGetEvents(t *testing.T) {
allEvents = append(allEvents, forkParamsEvents...)

for _, e := range allEvents {
require.NoError(t, state.GovernanceStore.insertGovernanceEvent(epoch, block, e, nil))
require.NoError(t, state.GovernanceStore.insertGovernanceEvent(epoch, e, nil))
}

// test for an epoch that didn't have any events
Expand All @@ -87,8 +86,8 @@ func TestGovernanceStore_InsertAndGetEvents(t *testing.T) {
newFeatureEventTwo := &contractsapi.UpdatedFeatureEvent{Feature: types.BytesToHash([]byte("OxSomeFeature3")),
Block: big.NewInt(130_000)}

require.NoError(t, state.GovernanceStore.insertGovernanceEvent(epoch, block+1, sprintSizeEvent, nil))
require.NoError(t, state.GovernanceStore.insertGovernanceEvent(epoch, block+1, newFeatureEventTwo, nil))
require.NoError(t, state.GovernanceStore.insertGovernanceEvent(epoch, sprintSizeEvent, nil))
require.NoError(t, state.GovernanceStore.insertGovernanceEvent(epoch, newFeatureEventTwo, nil))

eventsRaw, err = state.GovernanceStore.getNetworkParamsEvents(epoch, nil)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion e2e-polybft/e2e/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func TestE2E_Consensus_EIP1559Check(t *testing.T) {

client := cluster.Servers[0].JSONRPC().Eth()

waitUntilBalancesChanged := func(acct ethgo.Address, initialBalance *big.Int) error {
waitUntilBalancesChanged := func(_ ethgo.Address, initialBalance *big.Int) error {
err := cluster.WaitUntil(30*time.Second, 1*time.Second, func() bool {
balance, err := client.GetBalance(recipient, ethgo.Latest)
if err != nil {
Expand Down

0 comments on commit 8fac1d0

Please sign in to comment.