Skip to content

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Oct 9, 2023
1 parent 8546f0a commit f9bfc50
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
18 changes: 11 additions & 7 deletions consensus/polybft/consensus_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func newConsensusRuntime(log hcf.Logger, config *runtimeConfig) (*consensusRunti

proposerCalculator, err := NewProposerCalculator(config, log.Named("proposer_calculator"), dbTx)
if err != nil {
dbTx.Rollback()
_ = dbTx.Rollback()

return nil, fmt.Errorf("failed to create consensus runtime, error while creating proposer calculator %w", err)
}
Expand All @@ -149,27 +149,27 @@ func newConsensusRuntime(log hcf.Logger, config *runtimeConfig) (*consensusRunti
}

if err := runtime.initStateSyncManager(log); err != nil {
dbTx.Rollback()
_ = dbTx.Rollback()

return nil, err
}

if err := runtime.initCheckpointManager(log); err != nil {
dbTx.Rollback()
_ = dbTx.Rollback()

return nil, err
}

if err := runtime.initStakeManager(log, dbTx); err != nil {
dbTx.Rollback()
_ = dbTx.Rollback()

return nil, err
}

// we need to call restart epoch on runtime to initialize epoch state
runtime.epoch, err = runtime.restartEpoch(runtime.lastBuiltBlock, dbTx)
if err != nil {
dbTx.Rollback()
_ = dbTx.Rollback()

return nil, fmt.Errorf("consensus runtime creation - restart epoch failed: %w", err)
}
Expand Down Expand Up @@ -336,15 +336,17 @@ func (c *consensusRuntime) OnBlockInserted(fullBlock *types.FullBlock) {

lastProcessedEventsBlock, err := c.state.getLastProcessedEventsBlock(dbTx)
if err != nil {
dbTx.Rollback()
_ = dbTx.Rollback()

c.logger.Error("failed to get last processed events block on block finalization",
"block", fullBlock.Block.Number(), "err", err)

return
}

if err := c.eventProvider.GetEventsFromBlocks(lastProcessedEventsBlock, fullBlock, dbTx); err != nil {
dbTx.Rollback()
_ = dbTx.Rollback()

c.logger.Error("failed to process events on block finalization", "block", fullBlock.Block.Number(), "err", err)

return
Expand Down Expand Up @@ -385,6 +387,7 @@ func (c *consensusRuntime) OnBlockInserted(fullBlock *types.FullBlock) {
// update proposer priorities
if err := c.proposerCalculator.PostBlock(postBlock); err != nil {
c.logger.Error("Could not update proposer calculator", "err", err)

return err
}

Expand All @@ -395,6 +398,7 @@ func (c *consensusRuntime) OnBlockInserted(fullBlock *types.FullBlock) {
// handle transfer events that happened in block
if err := c.stakeManager.PostBlock(postBlock); err != nil {
c.logger.Error("failed to post block in stake manager", "err", err)

return err
}

Expand Down
3 changes: 2 additions & 1 deletion consensus/polybft/proposer_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ type ProposerCalculator struct {
}

// NewProposerCalculator creates a new proposer calculator object
func NewProposerCalculator(config *runtimeConfig, logger hclog.Logger, dbTx DBTransaction) (*ProposerCalculator, error) {
func NewProposerCalculator(config *runtimeConfig, logger hclog.Logger,
dbTx DBTransaction) (*ProposerCalculator, error) {
snap, err := NewProposerSnapshotFromState(config, dbTx)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion consensus/polybft/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func newState(path string, logger hclog.Logger, closeCh chan struct{}) (*State,
func (s *State) initStorages() error {
// init the buckets
return s.db.Update(func(tx *bolt.Tx) error {

if err := s.StateSyncStore.initialize(tx); err != nil {
return err
}
Expand Down Expand Up @@ -156,6 +155,7 @@ func (s *State) getLastProcessedEventsBlock(dbTx DBTransaction) (uint64, error)

if dbTx == nil {
var lastProcessed uint64

err := s.db.View(func(tx *bolt.Tx) error {
lastProcessed = getFn(tx)

Expand Down
6 changes: 6 additions & 0 deletions consensus/polybft/state_store_epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (s *EpochStore) getLastSnapshot(dbTx DBTransaction) (*validatorSnapshot, er
getFn := func(tx DBTransaction) error {
c := tx.Bucket(validatorSnapshotsBucket).Cursor()
k, v := c.Last()

if k == nil {
// we have no snapshots in db
return nil
Expand Down Expand Up @@ -130,6 +131,7 @@ func (s *EpochStore) insertEpoch(epoch uint64, dbTx DBTransaction) error {
if err != nil {
return err
}

_, err = epochBucket.CreateBucketIfNotExists(messageVotesBucket)
if err != nil {
return err
Expand Down Expand Up @@ -172,6 +174,7 @@ func (s *EpochStore) cleanEpochsFromDB(dbTx DBTransaction) error {
if err := tx.DeleteBucket(epochsBucket); err != nil {
return err
}

_, err := tx.CreateBucket(epochsBucket)

return err
Expand All @@ -195,12 +198,15 @@ func (s *EpochStore) cleanValidatorSnapshotsFromDB(epoch uint64, dbTx DBTransact
// paired list
keys := make([][]byte, 0)
values := make([][]byte, 0)

for i := 0; i < numberOfSnapshotsToLeaveInDB; i++ { // exclude the last inserted we already appended
key := common.EncodeUint64ToBytes(epoch)
value := bucket.Get(key)

if value == nil {
continue
}

keys = append(keys, key)
values = append(values, value)
epoch--
Expand Down
3 changes: 3 additions & 0 deletions consensus/polybft/state_store_state_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (s *StateSyncStore) getStateSyncEventsForCommitment(

if dbTx == nil {
var events []*contractsapi.StateSyncedEvent

err := s.db.View(func(tx *bolt.Tx) error {
ev, err := getFn(tx)
// we need to return all the events we can
Expand Down Expand Up @@ -244,6 +245,7 @@ func (s *StateSyncStore) insertMessageVote(epoch uint64, key []byte,

if dbTx == nil {
var numOfSignatures int

err := s.db.Update(func(tx *bolt.Tx) error {
numOfSig, err := insertFn(tx)
if err != nil {
Expand Down Expand Up @@ -307,6 +309,7 @@ func (s *StateSyncStore) getMessageVotesLocked(tx DBTransaction, epoch uint64,
func (s *StateSyncStore) insertStateSyncProofs(stateSyncProof []*StateSyncProof, dbTx DBTransaction) error {
insertFn := func(tx DBTransaction) error {
bucket := tx.Bucket(stateSyncProofsBucket)

for _, ssp := range stateSyncProof {
raw, err := json.Marshal(ssp)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion consensus/polybft/validators_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ func (v *validatorsSnapshotCache) cleanup(dbTx DBTransaction) error {

// getLastCachedSnapshot gets the latest snapshot cached
// If it doesn't have snapshot cached for desired epoch, it will return the latest one it has
func (v *validatorsSnapshotCache) getLastCachedSnapshot(currentEpoch uint64, dbTx DBTransaction) (*validatorSnapshot, error) {
func (v *validatorsSnapshotCache) getLastCachedSnapshot(currentEpoch uint64,
dbTx DBTransaction) (*validatorSnapshot, error) {
cachedSnapshot := v.snapshots[currentEpoch]
if cachedSnapshot != nil {
return cachedSnapshot, nil
Expand Down

0 comments on commit f9bfc50

Please sign in to comment.