From 8fac1d0a6581c4be3a5d5a8f9b423bb1b68d5896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Tue, 12 Mar 2024 08:30:57 +0100 Subject: [PATCH] Remove unused parameters --- consensus/polybft/consensus_runtime.go | 1 - consensus/polybft/governance_manager.go | 8 ++++---- consensus/polybft/governance_manager_test.go | 10 +++++----- consensus/polybft/helpers_test.go | 3 +-- consensus/polybft/polybft.go | 2 +- consensus/polybft/state.go | 3 +-- consensus/polybft/state_store_governance.go | 3 +-- consensus/polybft/state_store_governance_test.go | 7 +++---- e2e-polybft/e2e/consensus_test.go | 2 +- 9 files changed, 17 insertions(+), 22 deletions(-) diff --git a/consensus/polybft/consensus_runtime.go b/consensus/polybft/consensus_runtime.go index 5b480f51a4..334bc4e82e 100644 --- a/consensus/polybft/consensus_runtime.go +++ b/consensus/polybft/consensus_runtime.go @@ -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, diff --git a/consensus/polybft/governance_manager.go b/consensus/polybft/governance_manager.go index c3ed393b1e..e779e79404 100644 --- a/consensus/polybft/governance_manager.go +++ b/consensus/polybft/governance_manager.go @@ -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, @@ -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 @@ -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 } @@ -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 diff --git a/consensus/polybft/governance_manager_test.go b/consensus/polybft/governance_manager_test.go index 128b8caff6..ca27cd48b8 100644 --- a/consensus/polybft/governance_manager_test.go +++ b/consensus/polybft/governance_manager_test.go @@ -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{ @@ -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) @@ -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)) diff --git a/consensus/polybft/helpers_test.go b/consensus/polybft/helpers_test.go index 26dab96b76..22e038b8af 100644 --- a/consensus/polybft/helpers_test.go +++ b/consensus/polybft/helpers_test.go @@ -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" ) @@ -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) } diff --git a/consensus/polybft/polybft.go b/consensus/polybft/polybft.go index a9f2d5328d..c08ccfeb42 100644 --- a/consensus/polybft/polybft.go +++ b/consensus/polybft/polybft.go @@ -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) } diff --git a/consensus/polybft/state.go b/consensus/polybft/state.go index 2028bbeb1e..b341f59e1d 100644 --- a/consensus/polybft/state.go +++ b/consensus/polybft/state.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/0xPolygon/polygon-edge/helper/common" - "github.com/hashicorp/go-hclog" bolt "go.etcd.io/bbolt" ) @@ -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 diff --git a/consensus/polybft/state_store_governance.go b/consensus/polybft/state_store_governance.go index 586f4655f2..325c7bddd7 100644 --- a/consensus/polybft/state_store_governance.go +++ b/consensus/polybft/state_store_governance.go @@ -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) diff --git a/consensus/polybft/state_store_governance_test.go b/consensus/polybft/state_store_governance_test.go index 28ce92df4a..0b71e3ecb7 100644 --- a/consensus/polybft/state_store_governance_test.go +++ b/consensus/polybft/state_store_governance_test.go @@ -18,7 +18,6 @@ func TestGovernanceStore_InsertAndGetEvents(t *testing.T) { t.Parallel() epoch := uint64(11) - block := uint64(111) state := newTestState(t) // NetworkParams events @@ -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 @@ -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) diff --git a/e2e-polybft/e2e/consensus_test.go b/e2e-polybft/e2e/consensus_test.go index 0115d6bcb1..d2441a4769 100644 --- a/e2e-polybft/e2e/consensus_test.go +++ b/e2e-polybft/e2e/consensus_test.go @@ -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 {